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/onap/portal/controller/UserControllerTest.java | |
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/onap/portal/controller/UserControllerTest.java')
-rw-r--r-- | portal-BE/src/test/java/org/onap/portal/controller/UserControllerTest.java | 44 |
1 files changed, 38 insertions, 6 deletions
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 |