diff options
Diffstat (limited to 'portal-BE/src/test/java')
5 files changed, 318 insertions, 13 deletions
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 2f9f4235..3dd1fc2f 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 @@ -1,3 +1,43 @@ +/* + * ============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.controller; import static org.junit.jupiter.api.Assertions.*; 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 8c2adc9d..c04f50e4 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 @@ -1,17 +1,57 @@ +/* + * ============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.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; import java.time.LocalDateTime; import java.util.Collections; import java.util.HashSet; import java.util.List; import javax.transaction.Transactional; -import org.hibernate.Hibernate; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.portal.dao.fn.EpWidgetCatalogDao; import org.onap.portal.domain.db.ep.EpMicroserviceParameter; import org.onap.portal.domain.db.ep.EpWidgetCatalog; import org.onap.portal.domain.db.ep.EpWidgetCatalogParameter; @@ -22,7 +62,6 @@ 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; @@ -40,8 +79,6 @@ public class WidgetsCatalogControllerTest { @Autowired FnLanguageService fnLanguageService; @Autowired - FnUserService fnUserService; - @Autowired EpWidgetCatalogParameterService epWidgetCatalogParameterService; @Autowired EpMicroserviceParameterService epMicroserviceParameterService; @@ -95,7 +132,6 @@ public class WidgetsCatalogControllerTest { public void getUserParameterById() { //Given EpWidgetCatalog widget = EpWidgetCatalog.builder() - .widgetId(54L) .wdgName("Name") .wdgFileLoc("loc") .allUserFlag(true) @@ -119,7 +155,32 @@ public class WidgetsCatalogControllerTest { } @Test + @Transactional public void deleteUserParameterById() { + //Given + EpWidgetCatalog widget = EpWidgetCatalog.builder() + .wdgName("Name") + .wdgFileLoc("loc") + .allUserFlag(true) + .build(); + 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); + EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() + .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); + //When + assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size()); + epWidgetCatalogParameterService.saveUserParameter(data); + //Then assert + assertEquals(1, widgetsCatalogController.getUserParameterById(parameter.getId()).size()); + assertTrue(widgetsCatalogController.deleteUserParameterById(parameter.getId())); + assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size()); + } @Test diff --git a/portal-BE/src/test/java/org/onap/portal/service/ep/EpMicroserviceParameterServiceTest.java b/portal-BE/src/test/java/org/onap/portal/service/ep/EpMicroserviceParameterServiceTest.java new file mode 100644 index 00000000..b4427ef3 --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/service/ep/EpMicroserviceParameterServiceTest.java @@ -0,0 +1,68 @@ +/* + * ============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.ep; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.onap.portal.domain.db.ep.EpMicroserviceParameter; +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 +@TestPropertySource(locations = "classpath:test.properties") +class EpMicroserviceParameterServiceTest { + + @Autowired + EpMicroserviceParameterService epMicroserviceParameterService; + + @Test + void deleteMicroserviceParameterById() { + EpMicroserviceParameter parameter = EpMicroserviceParameter.builder() + .build(); + epMicroserviceParameterService.save(parameter); + assertTrue(epMicroserviceParameterService.deleteMicroserviceParameterById(parameter.getId())); + } +}
\ No newline at end of file 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 new file mode 100644 index 00000000..f123f95a --- /dev/null +++ b/portal-BE/src/test/java/org/onap/portal/service/ep/EpWidgetCatalogParameterServiceTest.java @@ -0,0 +1,128 @@ +/* + * ============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.ep; + +import static org.junit.jupiter.api.Assertions.*; + +import java.time.LocalDateTime; +import java.util.Collections; +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.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.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") +class EpWidgetCatalogParameterServiceTest { + private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", + "demo123"); + @Autowired + private EpWidgetCatalogParameterService epWidgetCatalogParameterService; + @Autowired + private WidgetsCatalogController widgetsCatalogController; + @Autowired + private + FnLanguageService fnLanguageService; + @Autowired + private EpMicroserviceParameterService epMicroserviceParameterService; + @Autowired + private + EpWidgetCatalogService epWidgetCatalogService; + + @Test + void deleteUserParameterById() { + } + + @Test + @Transactional + void deleteByParamId() { + //Given + EpWidgetCatalog widget = EpWidgetCatalog.builder() + .wdgName("Name") + .wdgFileLoc("loc") + .allUserFlag(true) + .build(); + 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); + EpWidgetCatalogParameter data = EpWidgetCatalogParameter.builder() + .widgetId(widget).userId(user).paramId(parameter).userValue("TestData").build(); + //When + assertEquals(0, widgetsCatalogController.getUserParameterById(parameter.getId()).size()); + epWidgetCatalogParameterService.saveUserParameter(data); + //Then + assertEquals(1, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size()); + epWidgetCatalogParameterService.deleteByParamId(parameter.getId()); + assertEquals(0, epWidgetCatalogParameterService.getUserParameterById(parameter.getId()).size()); + //Clean + + + } + + private FnUser buildFnUser(){ + return FnUser.builder() + .lastLoginDate(LocalDateTime.now()) + .activeYn(true) + .modifiedDate(LocalDateTime.now()) + .createdDate(LocalDateTime.now()) + .isInternalYn(true) + .guest(false) + .build(); + } +}
\ 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 4f960b46..e4083881 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 @@ -73,29 +73,37 @@ class FnUserServiceTest { @Test void saveUser(){ - FnUser actual = fnUserService.getUser(1L).get(); + //Given + //FnLuTimezone fnLuTimezone = fnLuTimezoneService.getById(10L).get(); + FnLanguage language = fnLanguageService.findById(1L).get(); FnUser expected = FnUser.builder().build(); - expected.setUserId(123L); expected.setFirstName("Demo"); expected.setLastName("User"); expected.setEmail("demo@openecomp.org"); expected.setOrgUserId("demo"); - expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone())); - expected.setLoginId("demo"); + //expected.setTimezone(fnLuTimezone); + expected.setLoginId("demoTest"); 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"); - expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage())); + expected.setLanguageId(language); expected.setGuest(false); + + //fnLuTimezone.getFnUsers().add(expected); + language.getFnUsers().add(expected); + + //When fnUserService.saveFnUser(principal, expected); - System.out.println(expected.getActiveYn()); + FnUser actual = fnUserService.getUser(expected.getUserId()).get(); + //Then + assertEquals(expected.getUserId(), actual.getUserId()); + assertEquals(expected.getLoginPwd(), actual.getLoginPwd()); //Clean up fnUserService.deleteUser(expected); } |