diff options
author | 2019-08-27 12:06:34 +0200 | |
---|---|---|
committer | 2019-08-27 12:06:43 +0200 | |
commit | e977510f26b63b1955bae683bbf348dbbc157f80 (patch) | |
tree | a6baa521ad6e13906b195f62644f9033115927f8 /portal-BE/src/test/java/org | |
parent | 08cdfa25a5a781673c78f7ec33c23d03164e197a (diff) |
Tests Coverage up
Tests Coverage up
Issue-ID: PORTAL-710
Change-Id: Iac9e4203613930b905779b45bab83ddfe82bea74
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'portal-BE/src/test/java/org')
3 files changed, 105 insertions, 6 deletions
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 0f9f09ad..0977f286 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 @@ -41,6 +41,7 @@ package org.onap.portal.controller; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; @@ -49,6 +50,7 @@ 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.domain.dto.fn.FnLanguageDto; import org.onap.portal.service.fn.FnUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -139,6 +141,50 @@ class LanguageControllerTest { fnLanguageDao.delete(fnLanguage); } + @Test + void setUpUserLanguageWrongUserId(){ + //Given + FnLanguage fnLanguage = new FnLanguage(); + fnLanguage.setLanguageName("Polish"); + fnLanguage.setLanguageAlias("PL"); + + PortalRestResponse<String> expected = new PortalRestResponse<>(); + expected.setMessage("FAILURE"); + expected.setStatus(PortalRestStatusEnum.ERROR); + expected.setResponse("User for id: 345 do not exist"); + + languageController.saveLanguage(principal, fnLanguage); + PortalRestResponse<String> actual = languageController.setUpUserLanguage(principal, fnLanguage, 345L); + + assertEquals(expected.getMessage(), actual.getMessage()); + assertEquals(expected.getStatus(), actual.getStatus()); + assertEquals(expected.getResponse(), actual.getResponse()); + //Clean up + fnLanguageDao.delete(fnLanguage); + } + + + @Test + void getUserLanguage() { + FnLanguageDto expected = new FnLanguageDto(); + expected.setLanguageAlias("EN"); + expected.setLanguageName("English"); + + FnLanguageDto actual = languageController.getUserLanguage(principal, 1L); + + assertEquals(expected.getLanguageAlias(), actual.getLanguageAlias()); + assertEquals(expected.getLanguageName(), actual.getLanguageName()); + } + + @Test + void getUserLanguageNotExistingUser() { + FnLanguageDto expected = new FnLanguageDto(); + + FnLanguageDto actual = languageController.getUserLanguage(principal, 456L); + + assertNull(actual.getLanguageAlias()); + assertNull(actual.getLanguageName()); + } }
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java index b216799f..e3f1f7be 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java @@ -39,13 +39,17 @@ package org.onap.portal.controller; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; -import lombok.AllArgsConstructor; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; +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.domain.dto.ProfileDetail; +import org.onap.portal.service.fn.FnUserService; +import org.onap.portalsdk.core.onboarding.exception.CipherUtilException; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -54,14 +58,18 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -@TestPropertySource(locations="classpath:test.properties") +@TestPropertySource(locations = "classpath:test.properties") class UserControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + "XZa6pS1vC0qKXWtn9wcZWdLx61L0="); + + private final FnUserService userService; private final UserController userController; @Autowired - UserControllerTest(UserController userController) { + UserControllerTest(final FnUserService userService, final UserController userController) { + this.userService = userService; this.userController = userController; } @@ -73,7 +81,8 @@ class UserControllerTest { expectedDetails.setEmail("demo@openecomp.org"); expectedDetails.setLoginId("demo"); expectedDetails.setLoginPassword("*****"); - PortalRestResponse<ProfileDetail> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", expectedDetails); + PortalRestResponse<ProfileDetail> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", + expectedDetails); PortalRestResponse<ProfileDetail> actual = userController.getLoggedinUser(principal); @@ -92,7 +101,8 @@ class UserControllerTest { expectedDetails.setLoginPassword("*****"); PortalRestResponse<String> actual = userController.modifyLoggedinUser(principal, expectedDetails); - PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "lastName must not be blank", null); + PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, + "lastName must not be blank", null); assertEquals(expected, actual); } @@ -109,4 +119,26 @@ class UserControllerTest { PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null); assertEquals(expected, actual); } + + @Test + void modifyLoggedinUserChangePassword() throws CipherUtilException { + ProfileDetail expectedDetails = new ProfileDetail(); + expectedDetails.setFirstName("Demo"); + expectedDetails.setLastName("User"); + expectedDetails.setEmail("demo@openecomp.org"); + expectedDetails.setLoginId("demo"); + expectedDetails.setLoginPassword("123password"); + + FnUser user = userService.loadUserByUsername(principal.getName()); + String oldPassword = user.getLoginPwd(); + + PortalRestResponse<String> actual = userController.modifyLoggedinUser(principal, expectedDetails); + PortalRestResponse<String> expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", null); + + FnUser user2 = userService.loadUserByUsername(principal.getName()); + String newPassword = user2.getLoginPwd(); + + assertEquals(expected, actual); + assertNotEquals(oldPassword, newPassword); + } }
\ 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 index 3f242fb4..26731eac 100644 --- 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 @@ -43,6 +43,10 @@ package org.onap.portal.service.fn; import static org.junit.jupiter.api.Assertions.*; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.onap.portal.domain.db.fn.FnLanguage; @@ -167,4 +171,21 @@ class FnUserServiceTest { assertEquals(expected.getSiloStatus(), actual.getSiloStatus()); assertEquals(expected.getLanguageId(), actual.getLanguageId()); } + + @Test + void getActiveUsers() { + assertEquals(12, fnUserService.getActiveUsers().size()); + } + + @Test + void getUserWithOrgUserId() { + assertEquals(1, fnUserService.getUserWithOrgUserId("cs0008").size()); + } + + @Test + void getUserWithOrgUserIds() { + List<String> ids = new ArrayList<>(Arrays.asList("cs0008", "op0001")); + assertEquals(2, fnUserService.getUsersByOrgIds(ids).size()); + } + }
\ No newline at end of file |