diff options
Diffstat (limited to 'portal-BE/src/test/java')
10 files changed, 168 insertions, 112 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 622acb90..e00dc5ca 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 @@ -64,7 +64,7 @@ import org.springframework.transaction.annotation.Transactional; @TestPropertySource(locations="classpath:test.properties") @Transactional class LanguageControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); + private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); @Autowired private LanguageController languageController; 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 c950fb41..0316683f 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 @@ -60,7 +60,7 @@ import org.springframework.test.context.junit4.SpringRunner; @TestPropertySource(locations = "classpath:test.properties") class UserControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); private final FnUserService userService; diff --git a/portal-BE/src/test/java/org/onap/portal/controller/UserRolesControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/UserRolesControllerTest.java index b2048e8f..e83c2470 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/UserRolesControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/UserRolesControllerTest.java @@ -42,49 +42,20 @@ package org.onap.portal.controller; import static org.junit.jupiter.api.Assertions.*; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileReader; -import java.sql.Connection; -import java.sql.SQLException; -import java.time.LocalDateTime; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import javax.persistence.EntityManager; -import javax.persistence.EntityManagerFactory; -import javax.persistence.Persistence; -import javax.sql.DataSource; -import org.h2.tools.RunScript; -import org.hibernate.Session; -import org.hibernate.jdbc.Work; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; -import org.onap.portal.domain.db.fn.FnApp; -import org.onap.portal.domain.db.fn.FnLanguage; -import org.onap.portal.domain.db.fn.FnRole; -import org.onap.portal.domain.db.fn.FnUser; -import org.onap.portal.domain.db.fn.FnUserRole; +import org.onap.portal.domain.dto.ecomp.ExternalSystemAccess; import org.onap.portal.service.fn.FnAppService; import org.onap.portal.service.fn.FnLanguageService; -import org.onap.portal.service.fn.FnLuTimezoneService; import org.onap.portal.service.fn.FnRoleService; import org.onap.portal.service.fn.FnUserRoleService; import org.onap.portal.service.fn.FnUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; -import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.context.WebApplicationContext; @RunWith(SpringRunner.class) @SpringBootTest @@ -117,14 +88,11 @@ class UserRolesControllerTest { } @Test - void checkIfUserIsSuperAdminTrue() { - UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", - "demo123"); - //Given - boolean expected = true; - //When - boolean actual = userRolesController.checkIfUserIsSuperAdmin(principal); - //Then - assertEquals(expected, actual); + void readExternalRequestAccess() { + ExternalSystemAccess expected = new ExternalSystemAccess("external_access_enable", false); + ExternalSystemAccess actual = userRolesController.readExternalRequestAccess(); + + assertEquals(expected.getAccessValue(), actual.getAccessValue()); + assertEquals(expected.getKey(), actual.getKey()); } }
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java index 3dd1fc2f..9a1a96a7 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetMSControllerTest.java @@ -62,10 +62,10 @@ class WidgetMSControllerTest { @Autowired WidgetMSController widgetMSController; - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + final MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - HttpServletRequest request = mockitoTestSuite.getMockedRequest(); - HttpServletResponse response = mockitoTestSuite.getMockedResponse(); + final HttpServletRequest request = mockitoTestSuite.getMockedRequest(); + final HttpServletResponse response = mockitoTestSuite.getMockedResponse(); @Test void getServiceLocation() { diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java index b82ac2f7..27ce3484 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsCatalogControllerTest.java @@ -41,7 +41,6 @@ package org.onap.portal.controller; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -49,21 +48,21 @@ import java.time.LocalDateTime; import java.util.Collections; import java.util.HashSet; import java.util.List; -import javax.servlet.http.HttpServletRequest; import javax.transaction.Transactional; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.portal.dao.fn.FnLanguageDao; import org.onap.portal.domain.db.ep.EpMicroserviceParameter; import org.onap.portal.domain.db.ep.EpWidgetCatalog; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; import org.onap.portal.domain.db.fn.FnLanguage; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.domain.dto.ecomp.WidgetCatalog; -import org.onap.portal.framework.MockitoTestSuite; import org.onap.portal.service.ep.EpMicroserviceParameterService; import org.onap.portal.service.ep.EpWidgetCatalogParameterService; import org.onap.portal.service.ep.EpWidgetCatalogService; import org.onap.portal.service.fn.FnLanguageService; +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; @@ -75,11 +74,13 @@ import org.springframework.test.context.junit4.SpringRunner; @Transactional @TestPropertySource(locations = "classpath:test.properties") public class WidgetsCatalogControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); @Autowired private WidgetsCatalogController widgetsCatalogController; @Autowired + private FnUserService fnUserService; + @Autowired private FnLanguageService fnLanguageService; @Autowired private EpWidgetCatalogParameterService epWidgetCatalogParameterService; @@ -87,6 +88,8 @@ public class WidgetsCatalogControllerTest { private EpMicroserviceParameterService epMicroserviceParameterService; @Autowired private EpWidgetCatalogService epWidgetCatalogService; + @Autowired + private FnLanguageDao fnLanguageDao; @Test public void getUserWidgetCatalog() { @@ -142,10 +145,11 @@ public class WidgetsCatalogControllerTest { EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); + fnLanguageService.save(language); FnUser user = buildFnUser(); language.setFnUsers(new HashSet<>(Collections.singleton(user))); user.setLanguageId(language); + fnUserService.saveFnUser(user); EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); //When @@ -167,11 +171,10 @@ public class WidgetsCatalogControllerTest { epWidgetCatalogService.save(widget); EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); - FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); FnUser user = buildFnUser(); - language.setFnUsers(new HashSet<>(Collections.singleton(user))); + FnLanguage language = fnLanguageDao.getByLanguageAlias("EN"); user.setLanguageId(language); + fnUserService.saveFnUser(user); EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); //When @@ -200,7 +203,7 @@ public class WidgetsCatalogControllerTest { EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); + fnLanguageService.save(language); FnUser user = buildFnUser(); language.setFnUsers(new HashSet<>(Collections.singleton(user))); user.setLanguageId(language); @@ -228,10 +231,12 @@ public class WidgetsCatalogControllerTest { EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); + fnLanguageService.save(language); FnUser user = buildFnUser(); language.setFnUsers(new HashSet<>(Collections.singleton(user))); user.setLanguageId(language); + fnUserService.saveFnUser(user); + EpWidgetCatalogParameter old = EpWidgetCatalogParameter.builder() .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); @@ -265,6 +270,7 @@ public class WidgetsCatalogControllerTest { .modifiedDate(LocalDateTime.now()) .createdDate(LocalDateTime.now()) .isInternalYn(true) + .isSystemUser(true) .guest(false) .build(); } diff --git a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java index ebc0d9fa..168fcc7a 100644 --- a/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java +++ b/portal-BE/src/test/java/org/onap/portal/controller/WidgetsControllerTest.java @@ -50,6 +50,7 @@ import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.portal.dao.fn.FnLanguageDao; @@ -62,6 +63,7 @@ import org.onap.portal.domain.dto.transport.OnboardingWidget; import org.onap.portal.domain.dto.transport.WidgetCatalogPersonalization; import org.onap.portal.framework.MockitoTestSuite; import org.onap.portal.service.WidgetService; +import org.onap.portal.service.fn.FnLanguageService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -76,13 +78,13 @@ import org.springframework.transaction.annotation.Transactional; @Transactional public class WidgetsControllerTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); - MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + final MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); - HttpServletRequest request = mockitoTestSuite.getMockedRequest(); - HttpServletResponse response = mockitoTestSuite.getMockedResponse(); + final HttpServletRequest request = mockitoTestSuite.getMockedRequest(); + final HttpServletResponse response = mockitoTestSuite.getMockedResponse(); @Autowired private WidgetsController widgetsController; @@ -92,10 +94,20 @@ public class WidgetsControllerTest { private FnLanguageDao fnLanguageDao; @Autowired private WidgetService widgetService; + @Autowired + private FnLanguageService fnLanguageService; + + private FnLanguage language; + private FnUser questUser; + private FnUser notQuestUser; + + @Before + public void init(){ + this.language = getFnLanguage(); + this.questUser = getQuestUser(); + this.notQuestUser = getNotQuestUser(); + } - private FnLanguage language = getFnLanguage(); - private FnUser questUser = getQuestUser(); - private FnUser notQuestUser = getNotQuestUser(); @Test(expected = UsernameNotFoundException.class) public void getOnboardingWidgetsNullUserTest() { @@ -364,6 +376,7 @@ public class WidgetsControllerTest { .modifiedDate(LocalDateTime.now()) .isInternalYn(true) .languageId(language) + .isSystemUser(true) .guest(true) .build(); } @@ -377,12 +390,16 @@ public class WidgetsControllerTest { .createdDate(LocalDateTime.now()) .modifiedDate(LocalDateTime.now()) .isInternalYn(true) + .isSystemUser(true) .languageId(language) .guest(false) .build(); } + private FnLanguage getFnLanguage() { - return FnLanguage.builder().languageName("Polish").languageAlias("Pl").build(); + FnLanguage tmp = FnLanguage.builder().languageName("Polish").languageAlias("Pl").build(); + fnLanguageService.save(tmp); + return tmp; } }
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java index 492c1795..1825e401 100644 --- a/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java +++ b/portal-BE/src/test/java/org/onap/portal/framework/MockitoTestSuite.java @@ -50,9 +50,9 @@ import org.mockito.runners.MockitoJUnitRunner; public class MockitoTestSuite { - public MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( + public final MockHttpServletRequestWrapper mockedRequest = new MockHttpServletRequestWrapper( Mockito.mock(HttpServletRequest.class)); - public HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); + public final HttpServletResponse mockedResponse = Mockito.mock(HttpServletResponse.class); public HttpServletResponse getMockedResponse() { return mockedResponse; @@ -64,7 +64,7 @@ public class MockitoTestSuite { public class MockHttpServletRequestWrapper extends HttpServletRequestWrapper { - HttpSession session = Mockito.mock(HttpSession.class); + final HttpSession session = Mockito.mock(HttpSession.class); public MockHttpServletRequestWrapper(HttpServletRequest request) { super(request); diff --git a/portal-BE/src/test/java/org/onap/portal/service/ep/EpWidgetCatalogParameterServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/ep/EpWidgetCatalogParameterServiceTest.java index 6a6c06b9..ad1ee60d 100644 --- a/portal-BE/src/test/java/org/onap/portal/service/ep/EpWidgetCatalogParameterServiceTest.java +++ b/portal-BE/src/test/java/org/onap/portal/service/ep/EpWidgetCatalogParameterServiceTest.java @@ -48,12 +48,14 @@ import java.util.HashSet; import org.junit.jupiter.api.Test; import org.junit.runner.RunWith; import org.onap.portal.controller.WidgetsCatalogController; +import org.onap.portal.dao.fn.FnLanguageDao; import org.onap.portal.domain.db.ep.EpMicroserviceParameter; import org.onap.portal.domain.db.ep.EpWidgetCatalog; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; import org.onap.portal.domain.db.fn.FnLanguage; import org.onap.portal.domain.db.fn.FnUser; import org.onap.portal.service.fn.FnLanguageService; +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; @@ -67,27 +69,29 @@ import org.springframework.transaction.annotation.Transactional; @TestPropertySource(locations = "classpath:test.properties") class EpWidgetCatalogParameterServiceTest { - private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + private final UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "demo123"); - private EpWidgetCatalogParameterService epWidgetCatalogParameterService; - private WidgetsCatalogController widgetsCatalogController; - private FnLanguageService fnLanguageService; - private EpMicroserviceParameterService epMicroserviceParameterService; - private EpWidgetCatalogService epWidgetCatalogService; + private final EpWidgetCatalogParameterService epWidgetCatalogParameterService; + private final WidgetsCatalogController widgetsCatalogController; + private final FnUserService fnUserService; + private final EpMicroserviceParameterService epMicroserviceParameterService; + private final EpWidgetCatalogService epWidgetCatalogService; + private final FnLanguageDao fnLanguageDao; @Autowired public EpWidgetCatalogParameterServiceTest( - EpWidgetCatalogParameterService epWidgetCatalogParameterService, - WidgetsCatalogController widgetsCatalogController, - FnLanguageService fnLanguageService, - EpMicroserviceParameterService epMicroserviceParameterService, - EpWidgetCatalogService epWidgetCatalogService) { + EpWidgetCatalogParameterService epWidgetCatalogParameterService, + WidgetsCatalogController widgetsCatalogController, + FnUserService fnUserService, + EpMicroserviceParameterService epMicroserviceParameterService, + EpWidgetCatalogService epWidgetCatalogService, FnLanguageDao fnLanguageDao) { this.epWidgetCatalogParameterService = epWidgetCatalogParameterService; this.widgetsCatalogController = widgetsCatalogController; - this.fnLanguageService = fnLanguageService; + this.fnUserService = fnUserService; this.epMicroserviceParameterService = epMicroserviceParameterService; this.epWidgetCatalogService = epWidgetCatalogService; + this.fnLanguageDao = fnLanguageDao; } @Test @@ -105,11 +109,8 @@ class EpWidgetCatalogParameterServiceTest { epWidgetCatalogService.save(widget); EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); - FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); FnUser user = buildFnUser(); - language.setFnUsers(new HashSet<>(Collections.singleton(user))); - user.setLanguageId(language); + fnUserService.saveFnUser(user); EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); //When @@ -134,11 +135,8 @@ class EpWidgetCatalogParameterServiceTest { epWidgetCatalogService.save(widget); EpMicroserviceParameter parameter = new EpMicroserviceParameter(); epMicroserviceParameterService.save(parameter); - FnLanguage language = FnLanguage.builder().languageAlias("TS").languageName("TEST").build(); - fnLanguageService.save(principal, language); FnUser user = buildFnUser(); - language.setFnUsers(new HashSet<>(Collections.singleton(user))); - user.setLanguageId(language); + fnUserService.saveFnUser(user); EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); //When @@ -146,7 +144,7 @@ class EpWidgetCatalogParameterServiceTest { epWidgetCatalogParameterService.saveUserParameter(data); Long id = data.getId(); assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size()); - EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getUserParamById(widget.getWidgetId(), user.getUserId(), parameter.getId()); + EpWidgetCatalogParameter actual = epWidgetCatalogParameterService.getUserParamById(widget.getWidgetId(), user.getId(), parameter.getId()); //Then assertEquals(id, actual.getId()); assertEquals(data.getUserValue(), actual.getUserValue()); @@ -156,13 +154,16 @@ class EpWidgetCatalogParameterServiceTest { } private FnUser buildFnUser() { + FnLanguage language = fnLanguageDao.getByLanguageAlias("EN"); return FnUser.builder() .lastLoginDate(LocalDateTime.now()) .activeYn(true) .modifiedDate(LocalDateTime.now()) .createdDate(LocalDateTime.now()) .isInternalYn(true) + .isSystemUser(true) .guest(false) + .languageId(language) .build(); } }
\ No newline at end of file diff --git a/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserRoleServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserRoleServiceTest.java new file mode 100644 index 00000000..fbb09e15 --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/service/fn/FnUserRoleServiceTest.java @@ -0,0 +1,79 @@ +/* + * ============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.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import javax.transaction.Transactional; +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.ecomp.EPUserAppCatalogRoles; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +@TestPropertySource(locations = "classpath:test.properties") +class FnUserRoleServiceTest { + @Autowired + private FnUserRoleService fnUserRoleService; + @Autowired + private FnUserService fnUserService; + + @Test + void getUserAppCatalogRoles() { + FnUser user = fnUserService.loadUserByUsername("demo"); + + List<EPUserAppCatalogRoles> actual = fnUserRoleService.getUserAppCatalogRoles(user, "appName"); + + List<EPUserAppCatalogRoles> expected = new ArrayList<>(); + + assertEquals(expected, actual); + } + + +}
\ 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 e4083881..56cbe815 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 @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.List; 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.FnLuTimezone; import org.onap.portal.domain.db.fn.FnUser; @@ -70,12 +71,12 @@ class FnUserServiceTest { private FnLuTimezoneService fnLuTimezoneService; @Autowired private FnLanguageService fnLanguageService; + @Autowired + private FnLanguageDao fnLanguageDao; @Test void saveUser(){ //Given - //FnLuTimezone fnLuTimezone = fnLuTimezoneService.getById(10L).get(); - FnLanguage language = fnLanguageService.findById(1L).get(); FnUser expected = FnUser.builder().build(); expected.setFirstName("Demo"); @@ -91,18 +92,18 @@ class FnUserServiceTest { expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); expected.setIsInternalYn(false); expected.setStateCd("NJ"); + expected.setIsSystemUser(true); expected.setCountryCd("US"); - expected.setLanguageId(language); + expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage())); expected.setGuest(false); - - //fnLuTimezone.getFnUsers().add(expected); - language.getFnUsers().add(expected); + FnLanguage language = fnLanguageDao.getByLanguageAlias("EN"); + expected.setLanguageId(language); //When - fnUserService.saveFnUser(principal, expected); - FnUser actual = fnUserService.getUser(expected.getUserId()).get(); + fnUserService.saveFnUser(expected); + FnUser actual = fnUserService.getUser(expected.getId()).get(); //Then - assertEquals(expected.getUserId(), actual.getUserId()); + assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getLoginPwd(), actual.getLoginPwd()); //Clean up fnUserService.deleteUser(expected); @@ -110,22 +111,16 @@ class FnUserServiceTest { @Test void getUser() { - FnUser actual = fnUserService.getUser(1L).get(); - + FnUser actual = fnUserService.loadUserByUsername("demo"); FnUser expected = FnUser.builder().build(); - expected.setUserId(1L); expected.setFirstName("Demo"); expected.setLastName("User"); expected.setEmail("demo@openecomp.org"); expected.setOrgUserId("demo"); expected.setLoginId("demo"); expected.setLoginPwd("demo123"); - expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17")); expected.setActiveYn(true); - expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00")); - expected.setModifiedId(actual); - expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17")); expected.setIsInternalYn(false); expected.setStateCd("NJ"); expected.setCountryCd("US"); @@ -133,9 +128,6 @@ class FnUserServiceTest { 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()); @@ -150,11 +142,7 @@ class FnUserServiceTest { 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.getModifiedDate(), actual.getModifiedDate()); assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn()); assertEquals(expected.getAddressLine1(), actual.getAddressLine1()); assertEquals(expected.getAddressLine2(), actual.getAddressLine2()); @@ -167,14 +155,11 @@ class FnUserServiceTest { 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()); } @Test |