diff options
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service')
7 files changed, 524 insertions, 3 deletions
diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java new file mode 100644 index 00000000..efdc3d0d --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/AccessConfigurationTest.java @@ -0,0 +1,95 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Test; + +public class AccessConfigurationTest { + + AccessConfiguration accessConfiguration = new AccessConfiguration(); + + @Test + public void roleServiceImplTest(){ + accessConfiguration.roleServiceImpl(); + } + + @Test + public void roleServiceCentralizedAccessTest(){ + accessConfiguration.roleServiceCentralizedAccess(); + } + + @Test + public void loginServiceImplTest(){ + accessConfiguration.loginServiceImpl(); + } + + @Test + public void loginServiceCEntralizedImplTest(){ + accessConfiguration.loginServiceCEntralizedImpl(); + } + + @Test + public void userServiceImplTest(){ + accessConfiguration.userServiceImpl(); + } + + @Test + public void profileServiceImplTest(){ + accessConfiguration.profileServiceImpl(); + } + + @Test + public void profileServiceCentralizedImplTest(){ + accessConfiguration.profileServiceCentralizedImpl(); + } + + @Test + public void restApiRequestBuilderTest(){ + accessConfiguration.restApiRequestBuilder(); + } + + @Test + public void functionalMenuListServiceTest(){ + accessConfiguration.functionalMenuListService(); + } + + @Test + public void functionalMenuListServiceCentralizedImplTest(){ + accessConfiguration.functionalMenuListServiceCentralizedImpl(); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.java new file mode 100644 index 00000000..a328033b --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/CentralAccessConditionTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.context.annotation.ConditionContext; +import org.springframework.core.type.AnnotatedTypeMetadata; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({PortalApiProperties.class}) +public class CentralAccessConditionTest { + + @InjectMocks + private CentralAccessCondition cntrlAccessCondition; + + @Test + public void matchesFalseTest() { + ConditionContext context = Mockito.mock(ConditionContext.class); + AnnotatedTypeMetadata metadata = Mockito.mock(AnnotatedTypeMetadata.class); + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED)).thenReturn(null); + boolean isRemote = cntrlAccessCondition.matches(context, metadata); + Assert.assertFalse(isRemote); + } + + @Test + public void matchesTrueTest() { + ConditionContext context = Mockito.mock(ConditionContext.class); + AnnotatedTypeMetadata metadata = Mockito.mock(AnnotatedTypeMetadata.class); + PowerMockito.mockStatic(PortalApiProperties.class); + Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.ROLE_ACCESS_CENTRALIZED)).thenReturn("remote"); + boolean isRemote = cntrlAccessCondition.matches(context, metadata); + Assert.assertTrue(isRemote); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java index f7bb3108..565142d0 100644 --- a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserProfileServiceImplTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START========================================== * ONAP Portal SDK * =================================================================== - * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * =================================================================== * * Unless otherwise specified, all software contained herein is licensed @@ -68,7 +68,15 @@ public class UserProfileServiceImplTest { Assert.assertTrue(true); } - + /*public void getUserByLoginId(){ + String loginId = "123"; + List<User> users = new ArrayList<>(); + User user = new User(); + users.add(user); + Mockito.when(dataAccessService.getList(Mockito.any(), Mockito.any(), Mockito.anyList(), Mockito.any())).thenReturn(users); + User retrunUser = userProfileServiceImpl.getUserByLoginId(loginId); + Assert.assertNotNull(retrunUser); + }*/ @Test public void saveUserTest(){ @@ -88,4 +96,4 @@ public class UserProfileServiceImplTest { Mockito.when(mockClass.getAllUserName()).thenReturn(onlineUsers); userProfileServiceImpl.findAllUserWithOnOffline(originOrgUserId); }*/ -} +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java new file mode 100644 index 00000000..82b4a6e0 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceCentalizedImplTest.java @@ -0,0 +1,84 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.core.domain.User; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class UserServiceCentalizedImplTest { + + @InjectMocks + private UserServiceCentalizedImpl userServiceCentalizedImpl; + + @Mock + private RestApiRequestBuilder restApiRequestBuilder; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getUserTest() throws Exception { + String id = "123"; + + String orgUserId = "123"; + List<String> orgUsreIds = new ArrayList<>(); + orgUsreIds.add(orgUserId); + + Map<String, Long> params = new HashMap<>(); + params.put("user_id", new Long(id)); + Mockito.when(dataAccessService.executeNamedQuery("getUserByProfileId", params, null)).thenReturn(orgUsreIds); + String responseString = " { \"id\": 2, \"userApps\":[{\"app\":{\"id\":1},\"role\":{\"active\":true, \"roleFunctions\":[{\"id\":1}] } } ] }"; + Mockito.when(restApiRequestBuilder.getViaREST("/user/" + orgUserId, true, id)).thenReturn(responseString); + + User user = userServiceCentalizedImpl.getUser(id); + Assert.assertNotNull(user); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java new file mode 100644 index 00000000..0cb7ac6c --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/UserServiceImplTest.java @@ -0,0 +1,68 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class UserServiceImplTest { + + @InjectMocks + private UserServiceImpl userServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Test + public void getUserTest() { + String id = "123"; + userServiceImpl.getUser(id); + Assert.assertTrue(true); + } + + @Test(expected = UnsupportedOperationException.class) + public void userMapperTest() { + String response = "Dummy Response"; + userServiceImpl.userMapper(response); + } +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java new file mode 100644 index 00000000..03eeea77 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/WebServiceCallServiceImplTest.java @@ -0,0 +1,127 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.onboarding.util.CipherUtil; +import org.onap.portalsdk.core.util.SystemProperties; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({CipherUtil.class, SystemProperties.class}) +public class WebServiceCallServiceImplTest { + + @InjectMocks + private WebServiceCallServiceImpl webServiceCallServiceImpl; + + @Mock + private DataAccessService dataAccessService; + + @Mock + private AppService appService; + + + @Test + public void verifyRESTCredentialTrueTest() throws Exception { + String secretKey = "Key"; + String requestAppName = "App"; + String requestPassword = "Password"; + App app = new App(); + app.setAppPassword(requestPassword); + app.setUsername(requestAppName); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn(secretKey); + Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn(requestPassword); + webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword); + Assert.assertTrue(true); + } + + @Test + public void verifyRESTCredentialFalseTest() throws Exception { + String secretKey = "Key"; + String requestAppName = "App"; + String requestPassword = "Password"; + App app = new App(); + app.setAppPassword("Password"); + app.setUsername("USER"); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + PowerMockito.mockStatic(CipherUtil.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(SystemProperties.Decryption_Key)).thenReturn("Key"); + Mockito.when(CipherUtil.decryptPKC(Mockito.anyString(), Mockito.anyString())).thenReturn("Key"); + webServiceCallServiceImpl.verifyRESTCredential(secretKey, requestAppName, requestPassword); + Assert.assertFalse(false); + } + + @Test + public void findAppWithNullTest() { + App app = webServiceCallServiceImpl.findApp(); + Assert.assertNull(app); + } + + @Test + public void findAppWithEmptyTest() { + Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(new ArrayList()); + App app = webServiceCallServiceImpl.findApp(); + Assert.assertNull(app); + } + + @Test + public void findAppTest() { + List list = new ArrayList(); + App app = new App(); + list.add(app); + Mockito.when(dataAccessService.getList(App.class, " where id = 1", null, null)).thenReturn(list); + App returnApp = webServiceCallServiceImpl.findApp(); + Assert.assertNotNull(returnApp); + } + +} diff --git a/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.java b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.java new file mode 100644 index 00000000..53664c64 --- /dev/null +++ b/ecomp-sdk/epsdk-core/src/test/java/org/onap/portalsdk/core/service/support/ServiceLocatorImplTest.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * 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============================================ + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.portalsdk.core.service.support; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ServiceLocatorImplTest { + + @InjectMocks + private ServiceLocatorImpl serviceLocatorImpl; + + @Test + public void getDirContextTest() { + String initialContextFactory ="Initial Context"; + String providerUrl = "URL"; + String securityPrincipal ="Security"; + serviceLocatorImpl.getDirContext(initialContextFactory, providerUrl, securityPrincipal); + Assert.assertTrue(true); + } +} |