diff options
author | Dominik Mizyn <d.mizyn@samsung.com> | 2019-08-22 17:33:03 +0200 |
---|---|---|
committer | Dominik Mizyn <d.mizyn@samsung.com> | 2019-08-22 17:33:11 +0200 |
commit | 8c6ccfe62953f28f704891c76258d595dc9d0b03 (patch) | |
tree | 2d626040c4e4f3a15e206bedf312f436ca5c4a7c /portal-BE | |
parent | 88db33c6a8e2a03e72a0c676f51937418ee84912 (diff) |
LanguageController tests up
LanguageController tests up
Issue-ID: PORTAL-710
Change-Id: I1236e3ee62aca3d07cc6d0f6c61a410a8847f281
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE')
13 files changed, 443 insertions, 50 deletions
diff --git a/portal-BE/pom.xml b/portal-BE/pom.xml index a7e8588f..51e831eb 100644 --- a/portal-BE/pom.xml +++ b/portal-BE/pom.xml @@ -41,10 +41,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs </dependency> <dependency> <groupId>org.springframework.boot</groupId> - <artifactId>spring-boot-starter-aop</artifactId> - </dependency> - <dependency> - <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> @@ -107,11 +103,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs </dependency> <dependency> <groupId>org.onap.portal.sdk</groupId> - <artifactId>epsdk-logger</artifactId> - <version>2.6.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.onap.portal.sdk</groupId> <artifactId>epsdk-core</artifactId> <version>2.6.0-SNAPSHOT</version> </dependency> diff --git a/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java b/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java index 250a6e2d..db8e0699 100644 --- a/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java +++ b/portal-BE/src/main/java/org/onap/portal/aop/service/FnLanguageServiceAOP.java @@ -63,15 +63,22 @@ public class FnLanguageServiceAOP { @Before("execution(* org.onap.portal.service.fn.FnLanguageService.save(..)) && args(principal, fnLanguage)") public void save(final Principal principal, final FnLanguage fnLanguage) { if (fnLanguage == null) { - LOGGER.error("User " + principal.getName() + " try to save NULL fnLanguage"); + LOGGER.info("User " + principal.getName() + " try to save NULL fnLanguage"); throw new NullPointerException("FnLanguage cannot be null or empty"); } if (!dataValidator.isValid(fnLanguage)) { String violations = dataValidator.getConstraintViolations(fnLanguage).stream() .map(ConstraintViolation::getMessage) .collect(Collectors.joining(", ")); - LOGGER.error("User " + principal.getName() + " try to save not valid fnLanguage: " + violations); + LOGGER.info("User " + principal.getName() + " try to save not valid fnLanguage: " + violations); throw new IllegalArgumentException("FnLanguage is not valid, " + violations); } } + + @Before("execution(* org.onap.portal.service.fn.FnLanguageService.getLanguageList(..)) && args(principal)") + public void getLanguageList(final Principal principal) { + LOGGER.info("User " + principal.getName() + " try requested for all language list"); + } + + } diff --git a/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java b/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java new file mode 100644 index 00000000..0cb17cc6 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/aop/service/FnUserServiceAOP.java @@ -0,0 +1,37 @@ +package org.onap.portal.aop.service; + +import java.security.Principal; +import java.util.stream.Collectors; +import javax.validation.ConstraintViolation; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.onap.portal.domain.db.fn.FnUser; +import org.onap.portal.validation.DataValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Aspect +@Component +public class FnUserServiceAOP { + private static final Logger LOGGER = LoggerFactory.getLogger(FnLanguageServiceAOP.class); + + @Autowired + private DataValidator dataValidator; + + @Before("execution(* org.onap.portal.service.fn.FnUserService.saveFnUser(..)) && args(principal, fnUser)") + public void save(final Principal principal, final FnUser fnUser) { + if (fnUser == null) { + LOGGER.error("User " + principal.getName() + " try to save NULL fnUser"); + throw new NullPointerException("FnUser cannot be null or empty"); + } + if (!dataValidator.isValid(fnUser)) { + String violations = dataValidator.getConstraintViolations(fnUser).stream() + .map(ConstraintViolation::getMessage) + .collect(Collectors.joining(", ")); + LOGGER.error("User " + principal.getName() + " try to save not valid fnUser: " + violations); + throw new IllegalArgumentException("FnUser is not valid, " + violations); + } + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java index 97fe03da..adee349b 100644 --- a/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java +++ b/portal-BE/src/main/java/org/onap/portal/controller/LanguageController.java @@ -42,9 +42,7 @@ package org.onap.portal.controller; import java.security.Principal; import java.util.List; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.onap.portal.aop.service.FnLanguageServiceAOP; +import java.util.Optional; import org.onap.portal.domain.db.fn.FnLanguage; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.PortalRestResponse; @@ -60,12 +58,12 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/auxapi") public class LanguageController { + private static final Logger LOGGER = LoggerFactory.getLogger(LanguageController.class); private final FnLanguageService languageService; @@ -78,39 +76,49 @@ public class LanguageController { this.fnUserService = fnUserService; } - @GetMapping(value = "/language", produces = "application/json;charset=UTF-8") - public List<FnLanguage> getLanguageList() { - return languageService.getLanguages(); + @GetMapping(value = "/language", produces = MediaType.APPLICATION_JSON_VALUE) + public List<FnLanguage> getLanguageList(final Principal principal) { + return languageService.getLanguages(principal); } @PostMapping(value = "/languageSetting/user/{loginId}") - public void setUpUserLanguage(@RequestBody FnLanguage fnLanguage, - @PathVariable("loginId") Long loginId) { - if (fnUserService.getUser(loginId).isPresent()){ - FnUser user = fnUserService.getUser(loginId).get(); - user.setLanguage_id(fnLanguage.getLanguageId()); - fnUserService.saveFnUser(user); + public PortalRestResponse<String> setUpUserLanguage(Principal principal, @RequestBody FnLanguage fnLanguage, + @PathVariable("loginId") Long userId) { + PortalRestResponse<String> response = new PortalRestResponse<>(); + try { + if (fnUserService.getUser(userId).isPresent()) { + FnUser user = fnUserService.getUser(userId).get(); + user.setLanguageId(fnLanguage); + fnUserService.saveFnUser(principal, user); + } + response.setMessage("SUCCESS"); + response.setStatus(PortalRestStatusEnum.OK); + } catch (Exception e) { + response.setMessage("FAILURE"); + response.setResponse(e.getMessage()); + response.setStatus(PortalRestStatusEnum.ERROR); + return response; } + return response; } - @GetMapping(value = "/languageSetting/user/{loginId}") - public FnLanguage getUserLanguage(HttpServletRequest request, HttpServletResponse response, - @PathVariable("loginId") Long loginId) { - if (fnUserService.getUser(loginId).isPresent()){ - Long languageId = fnUserService.getUser(loginId).get().getLanguage_id(); - return languageService.findById(languageId).orElse(new FnLanguage()); + @GetMapping(value = "/languageSetting/user/{loginId}", produces = MediaType.APPLICATION_JSON_VALUE) + public FnLanguage getUserLanguage(@PathVariable("loginId") final Long loginId) { + if (fnUserService.getUser(loginId).isPresent()) { + return Optional.of(fnUserService.getUser(loginId).get().getLanguageId()).orElse(new FnLanguage()); } return new FnLanguage(); } @PostMapping(value = "/language", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) - public PortalRestResponse<String> saveLanguage(final Principal principal, @RequestBody final FnLanguage fnLanguage){ + public PortalRestResponse<String> saveLanguage(final Principal principal, + @RequestBody final FnLanguage fnLanguage) { PortalRestResponse<String> response = new PortalRestResponse<>(); try { response.setMessage("SUCCESS"); response.setResponse(languageService.save(principal, fnLanguage).toString()); response.setStatus(PortalRestStatusEnum.OK); - } catch (Exception e){ + } catch (Exception e) { response.setMessage("FAILURE"); response.setResponse(e.getMessage()); response.setStatus(PortalRestStatusEnum.ERROR); diff --git a/portal-BE/src/main/java/org/onap/portal/dao/fn/FnLuTimezoneDao.java b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnLuTimezoneDao.java new file mode 100644 index 00000000..eca61ddd --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/dao/fn/FnLuTimezoneDao.java @@ -0,0 +1,52 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.dao.fn; + +import org.onap.portal.domain.db.fn.FnLuTimezone; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; + +@Repository +@Transactional +public interface FnLuTimezoneDao extends JpaRepository<FnLuTimezone, Integer> { + +} diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java index 996929e7..d9aff94c 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnLanguage.java @@ -41,11 +41,16 @@ package org.onap.portal.domain.db.fn; import com.fasterxml.jackson.annotation.JsonInclude; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; +import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; +import javax.persistence.OneToMany; import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.validation.constraints.Digits; @@ -74,7 +79,7 @@ CREATE TABLE `fn_language` ( @Setter @Entity @JsonInclude() -@SequenceGenerator(name="seq", initialValue=3, allocationSize=100) +@SequenceGenerator(name="seq", initialValue=1000, allocationSize=100000) public class FnLanguage { @Id @@ -92,5 +97,12 @@ public class FnLanguage { @NotNull(message = "languageAlias must not be null") @SafeHtml private String languageAlias; + @OneToMany( + targetEntity = FnUser.class, + mappedBy = "languageId", + cascade = CascadeType.ALL, + fetch = FetchType.EAGER + ) + private List<FnUser> fnUsers = new ArrayList<>(); } diff --git a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java index 8a778bfa..4747cdf8 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/db/fn/FnUser.java @@ -59,6 +59,8 @@ import javax.persistence.ManyToOne; import javax.persistence.NamedNativeQueries; import javax.persistence.NamedNativeQuery; import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import javax.persistence.SequenceGenerator; import javax.persistence.Table; import javax.persistence.UniqueConstraint; import javax.validation.Valid; @@ -68,9 +70,11 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.PastOrPresent; import javax.validation.constraints.Size; import lombok.AllArgsConstructor; +import lombok.Builder.Default; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import lombok.ToString; import org.hibernate.validator.constraints.SafeHtml; import org.onap.portal.domain.db.cr.CrReportFileHistory; import org.onap.portal.domain.db.ep.EpPersUserWidgetPlacement; @@ -172,10 +176,11 @@ CREATE TABLE `fn_user` ( @Getter @Setter @Entity -public class FnUser extends DomainVo implements UserDetails { +@SequenceGenerator(name="seq", initialValue=1000, allocationSize=100000) +public class FnUser implements UserDetails { @Id - @GeneratedValue(strategy = GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "seq") @Column(name = "user_id", length = 11, nullable = false) @Digits(integer = 11, fraction = 0) private Long userId; @@ -248,7 +253,7 @@ public class FnUser extends DomainVo implements UserDetails { @Column(name = "active_yn", length = 1, columnDefinition = "character varying(1) default 'y'", nullable = false) @Size(max = 1) @SafeHtml - @NotNull + //@NotNull(message = "activeYn must not be null") private String activeYn; @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "created_id") @@ -267,7 +272,7 @@ public class FnUser extends DomainVo implements UserDetails { @Column(name = "is_internal_yn", length = 1, columnDefinition = "character varying(1) default 'n'", nullable = false) @Size(max = 1) @SafeHtml - @NotNull + //@NotNull(message = "isInternalYn must not be null") private String isInternalYn; @Column(name = "address_line_1", length = 100, columnDefinition = "varchar(100) DEFAULT NULL") @Size(max = 100) @@ -341,12 +346,13 @@ public class FnUser extends DomainVo implements UserDetails { @Size(max = 10) @SafeHtml private String siloStatus; - @Column(name = "language_id", length = 2, columnDefinition = "int(2) default 1", nullable = false) - @Digits(integer = 2, fraction = 0) - @NotNull - private Long language_id; + @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @JoinColumn(name = "language_id", nullable = false, columnDefinition = "int(11) DEFAULT 1") + @Valid + //@NotNull(message = "languageId must not be null") + private FnLanguage languageId; @Column(name = "is_guest", columnDefinition = "boolean default 0", nullable = false) - @NotNull + @NotNull(message = "guest must not be null") private boolean guest; @ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "fnUserList") private List<CrReportFileHistory> crReportFileHistorie = new ArrayList<>(); diff --git a/portal-BE/src/main/java/org/onap/portal/domain/dto/DomainVo.java b/portal-BE/src/main/java/org/onap/portal/domain/dto/DomainVo.java index 6006a1b2..305af8e6 100644 --- a/portal-BE/src/main/java/org/onap/portal/domain/dto/DomainVo.java +++ b/portal-BE/src/main/java/org/onap/portal/domain/dto/DomainVo.java @@ -19,7 +19,7 @@ import org.onap.portalsdk.core.domain.FusionVo; @Getter @Setter -@EqualsAndHashCode(callSuper = true) +@EqualsAndHashCode @NoArgsConstructor @AllArgsConstructor @Inheritance(strategy = InheritanceType.JOINED) diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnLanguageService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnLanguageService.java index da9c0482..c58bf098 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/fn/FnLanguageService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnLanguageService.java @@ -46,9 +46,13 @@ import java.util.Optional; import org.onap.portal.dao.fn.FnLanguageDao; import org.onap.portal.domain.db.fn.FnLanguage; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@EnableAspectJAutoProxy +@Transactional public class FnLanguageService { private final FnLanguageDao fnLanguageDao; @@ -60,7 +64,7 @@ public class FnLanguageService { public Optional<FnLanguage> findById(final Long id){ return fnLanguageDao.findById(id); } - public List<FnLanguage> getLanguages(){ + public List<FnLanguage> getLanguages(Principal principal){ return fnLanguageDao.findAll(); } public FnLanguage save(final Principal principal, final FnLanguage fnLanguage){ diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnLuTimezoneService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnLuTimezoneService.java new file mode 100644 index 00000000..ea3dd386 --- /dev/null +++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnLuTimezoneService.java @@ -0,0 +1,63 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.fn; + +import java.util.Optional; +import org.onap.portal.dao.fn.FnLuTimezoneDao; +import org.onap.portal.domain.db.fn.FnLuTimezone; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional +public class FnLuTimezoneService { + private final FnLuTimezoneDao fnLuTimezoneDao; + + @Autowired + public FnLuTimezoneService(final FnLuTimezoneDao fnLuTimezoneDao) { + this.fnLuTimezoneDao = fnLuTimezoneDao; + } + + public Optional<FnLuTimezone> getById(Integer id){ + return fnLuTimezoneDao.findById(id); + } +} diff --git a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java index 91873139..b06abfb5 100644 --- a/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java +++ b/portal-BE/src/main/java/org/onap/portal/service/fn/FnUserService.java @@ -40,6 +40,7 @@ package org.onap.portal.service.fn; +import java.security.Principal; import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -47,21 +48,25 @@ import java.util.stream.Collectors; import org.onap.portal.dao.fn.FnUserDao; import org.onap.portal.domain.db.fn.FnUser; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.EnableAspectJAutoProxy; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service +@EnableAspectJAutoProxy +@Transactional public class FnUserService implements UserDetailsService { - private FnUserDao fnUserDao; + private final FnUserDao fnUserDao; @Autowired public FnUserService(FnUserDao fnUserDao) { this.fnUserDao = fnUserDao; } - public FnUser saveFnUser(FnUser fnUser) { + public FnUser saveFnUser(final Principal principal, final FnUser fnUser) { return fnUserDao.save(fnUser); } @@ -99,4 +104,8 @@ public class FnUserService implements UserDetailsService { List<FnUser> etActiveUsers(){ return fnUserDao.findAll().stream().filter(fnUser -> "Y".equals(fnUser.getActiveYn())).collect(Collectors.toList()); } + + public void deleteUser(FnUser fnUser){ + fnUserDao.delete(fnUser); + } } diff --git a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java index 0015c00b..5d89cd0c 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/LanguageControllerTest.java @@ -40,24 +40,27 @@ package org.onap.portal.controller; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.onap.portal.dao.fn.FnLanguageDao; import org.onap.portal.domain.db.fn.FnLanguage; +import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.PortalRestResponse; import org.onap.portal.domain.dto.PortalRestStatusEnum; +import org.onap.portal.service.fn.FnUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; -import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; @RunWith(SpringRunner.class) @SpringBootTest @TestPropertySource(locations="classpath:test.properties") +@Transactional class LanguageControllerTest { private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); @@ -65,6 +68,8 @@ class LanguageControllerTest { private LanguageController languageController; @Autowired private FnLanguageDao fnLanguageDao; + @Autowired + private FnUserService fnUserService; @Test void saveLanguage() { @@ -75,9 +80,9 @@ class LanguageControllerTest { //When PortalRestResponse<String> expected = new PortalRestResponse<>(); expected.setMessage("SUCCESS"); - expected.setResponse("FnLanguage(languageId=3, languageName=Polish, languageAlias=PL)"); + expected.setResponse("FnLanguage(languageId=101001, languageName=Polish, languageAlias=PL, fnUsers=[])"); expected.setStatus(PortalRestStatusEnum.OK); - PortalRestResponse<String> actual = languageController.saveLanguage(principal, fnLanguage); + PortalRestResponse<String> actual = languageController.saveLanguage(principal, fnLanguage); //Then assertEquals(expected, actual); @@ -104,4 +109,34 @@ class LanguageControllerTest { fnLanguageDao.delete(fnLanguage); } + @Test + void getLanguageListTest(){ + assertEquals(languageController.getLanguageList(principal).size(), 2); + } + + @Test + void setUpUserLanguage(){ + //Given + FnLanguage fnLanguage = new FnLanguage(); + fnLanguage.setLanguageName("Polish"); + fnLanguage.setLanguageAlias("PL"); + + PortalRestResponse<String> expected = new PortalRestResponse<>(); + expected.setMessage("SUCCESS"); + expected.setStatus(PortalRestStatusEnum.OK); + + languageController.saveLanguage(principal, fnLanguage); + FnUser fnUser = fnUserService.getUser(1L).get(); + PortalRestResponse<String> actual = languageController.setUpUserLanguage(principal, fnLanguage, fnUser.getUserId()); + + assertEquals(expected, actual); + assertEquals(fnUser.getLanguageId(), fnLanguage); + + + //Clean up + fnLanguageDao.delete(fnLanguage); + } + + + }
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java new file mode 100644 index 00000000..fef9187f --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserServiceTest.java @@ -0,0 +1,169 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * Modifications Copyright (c) 2019 Samsung + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +package org.onap.portal.service.fn; + +import static org.junit.jupiter.api.Assertions.*; + +import java.time.LocalDateTime; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.onap.portal.domain.db.fn.FnLanguage; +import org.onap.portal.domain.db.fn.FnLuTimezone; +import org.onap.portal.domain.db.fn.FnUser; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest +@TestPropertySource(locations="classpath:test.properties") +@Transactional +class FnUserServiceTest { + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + @Autowired + private FnUserService fnUserService; + @Autowired + private FnLuTimezoneService fnLuTimezoneService; + @Autowired + private FnLanguageService fnLanguageService; + + @Test + void saveUser(){ + FnUser actual = fnUserService.getUser(1L).get(); + + FnUser expected = new FnUser(); + expected.setUserId(123L); + expected.setFirstName("Demo"); + expected.setLastName("User"); + expected.setEmail("demo@openecomp.org"); + expected.setOrgUserId("demo"); + expected.setTimezone(fnLuTimezoneService.getById(10).orElse(new FnLuTimezone())); + expected.setLoginId("demo"); + expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17")); + expected.setActiveYn("Y"); + expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00")); + expected.setModifiedId(actual); + expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); + expected.setIsInternalYn("N"); + expected.setStateCd("NJ"); + expected.setCountryCd("US"); + expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage())); + + fnUserService.saveFnUser(principal, expected); + + //Clean up + fnUserService.deleteUser(expected); + } + + @Test + void getUser() { + FnUser actual = fnUserService.getUser(1L).get(); + + + FnUser expected = new FnUser(); + expected.setUserId(1L); + expected.setFirstName("Demo"); + expected.setLastName("User"); + expected.setEmail("demo@openecomp.org"); + expected.setOrgUserId("demo"); + expected.setLoginId("demo"); + expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17")); + expected.setActiveYn("Y"); + expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00")); + expected.setModifiedId(actual); + expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); + expected.setIsInternalYn("N"); + expected.setStateCd("NJ"); + expected.setCountryCd("US"); + expected.setTimezone(fnLuTimezoneService.getById(10).orElse(new FnLuTimezone())); + expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage())); + + + assertEquals(expected.getUserId(), actual.getUserId()); + assertEquals(expected.getOrgId(), actual.getOrgId()); + assertEquals(expected.getManagerId(), actual.getManagerId()); + assertEquals(expected.getFirstName(), actual.getFirstName()); + assertEquals(expected.getMiddleName(), actual.getMiddleName()); + assertEquals(expected.getLastName(), actual.getLastName()); + assertEquals(expected.getPhone(), actual.getPhone()); + assertEquals(expected.getFax(), actual.getFax()); + assertEquals(expected.getCellular(), actual.getCellular()); + assertEquals(expected.getEmail(), actual.getEmail()); + assertEquals(expected.getAddressId(), actual.getAddressId()); + assertEquals(expected.getAlertMethodCd(), actual.getAlertMethodCd()); + assertEquals(expected.getHrid(), actual.getHrid()); + assertEquals(expected.getOrgUserId(), actual.getOrgUserId()); + assertEquals(expected.getOrg_code(), actual.getOrg_code()); + assertEquals(expected.getLoginId(), actual.getLoginId()); + assertEquals(expected.getLoginPwd(), actual.getLoginPwd()); + assertEquals(expected.getLastLoginDate(), actual.getLastLoginDate()); + assertEquals(expected.getActiveYn(), actual.getActiveYn()); + assertEquals(expected.getCreatedId(), actual.getCreatedId()); + assertEquals(expected.getCreatedDate(), actual.getCreatedDate()); + assertEquals(expected.getModifiedId(), actual.getModifiedId()); + assertEquals(expected.getModifiedDate(), actual.getModifiedDate()); + assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn()); + assertEquals(expected.getAddressLine1(), actual.getAddressLine1()); + assertEquals(expected.getAddressLine2(), actual.getAddressLine2()); + assertEquals(expected.getCity(), actual.getCity()); + assertEquals(expected.getStateCd(), actual.getStateCd()); + assertEquals(expected.getZipCode(), actual.getZipCode()); + assertEquals(expected.getCountryCd(), actual.getCountryCd()); + assertEquals(expected.getLocationClli(), actual.getLocationClli()); + assertEquals(expected.getOrgManagerUserId(), actual.getOrgManagerUserId()); + assertEquals(expected.getCompany(), actual.getCompany()); + assertEquals(expected.getDepartmentName(), actual.getDepartmentName()); + assertEquals(expected.getJobTitle(), actual.getJobTitle()); + assertEquals(expected.getTimezone().getTimezoneId(), actual.getTimezone().getTimezoneId()); + assertEquals(expected.getDepartment(), actual.getDepartment()); + assertEquals(expected.getBusinessUnit(), actual.getBusinessUnit()); + assertEquals(expected.getBusinessUnitName(), actual.getBusinessUnitName()); + assertEquals(expected.getCost_center(), actual.getCost_center()); + assertEquals(expected.getFinLocCode(), actual.getFinLocCode()); + assertEquals(expected.getSiloStatus(), actual.getSiloStatus()); + assertEquals(expected.getLanguageId(), actual.getLanguageId()); + } +}
\ No newline at end of file |