From e977510f26b63b1955bae683bbf348dbbc157f80 Mon Sep 17 00:00:00 2001 From: Dominik Mizyn Date: Tue, 27 Aug 2019 12:06:34 +0200 Subject: Tests Coverage up Tests Coverage up Issue-ID: PORTAL-710 Change-Id: Iac9e4203613930b905779b45bab83ddfe82bea74 Signed-off-by: Dominik Mizyn --- .../portal/controller/LanguageControllerTest.java | 46 ++++++++++++++++++++++ .../onap/portal/controller/UserControllerTest.java | 44 ++++++++++++++++++--- .../onap/portal/service/fn/FnUserServiceTest.java | 21 ++++++++++ 3 files changed, 105 insertions(+), 6 deletions(-) (limited to 'portal-BE/src/test/java') 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 expected = new PortalRestResponse<>(); + expected.setMessage("FAILURE"); + expected.setStatus(PortalRestStatusEnum.ERROR); + expected.setResponse("User for id: 345 do not exist"); + + languageController.saveLanguage(principal, fnLanguage); + PortalRestResponse 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 expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", expectedDetails); + PortalRestResponse expected = new PortalRestResponse<>(PortalRestStatusEnum.OK, "success", + expectedDetails); PortalRestResponse actual = userController.getLoggedinUser(principal); @@ -92,7 +101,8 @@ class UserControllerTest { expectedDetails.setLoginPassword("*****"); PortalRestResponse actual = userController.modifyLoggedinUser(principal, expectedDetails); - PortalRestResponse expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, "lastName must not be blank", null); + PortalRestResponse expected = new PortalRestResponse<>(PortalRestStatusEnum.ERROR, + "lastName must not be blank", null); assertEquals(expected, actual); } @@ -109,4 +119,26 @@ class UserControllerTest { PortalRestResponse 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 actual = userController.modifyLoggedinUser(principal, expectedDetails); + PortalRestResponse 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 ids = new ArrayList<>(Arrays.asList("cs0008", "op0001")); + assertEquals(2, fnUserService.getUsersByOrgIds(ids).size()); + } + } \ No newline at end of file -- cgit 1.2.3-korg