diff options
19 files changed, 2097 insertions, 10 deletions
diff --git a/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/config/ConfigLoaderTest.java b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/config/ConfigLoaderTest.java new file mode 100644 index 00000000..025eeec7 --- /dev/null +++ b/ecomp-sdk/epsdk-analytics/src/test/java/org/onap/portalsdk/analytics/config/ConfigLoaderTest.java @@ -0,0 +1,156 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.analytics.config; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import javax.servlet.ServletContext; + +import static org.junit.Assert.assertEquals; + + +import java.lang.reflect.Constructor; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class ConfigLoaderTest { + + ConfigLoader cLoad; + + @Mock + static String configFilesPath; + + @Mock + ServletContext servCont; + + @Mock + Properties prop; + + @Mock + String propertiesfile = "test"; + + @Mock + String systemTypeExtension = ".xml"; + + @Mock + InputStream inpStr; + + @Before + public void init() throws Exception { + + Mockito.when(servCont.getResourceAsStream("test")).thenReturn(inpStr); + + Constructor<ConfigLoader> c = ConfigLoader.class.getDeclaredConstructor(); + c.setAccessible(true); + ConfigLoader cLoad_instance = c.newInstance(); + + cLoad = Mockito.spy(cLoad_instance); + + } + + + @Test + public void test_setConfigFilesPath() { + ConfigLoader.setConfigFilesPath("test"); + assertEquals(null,configFilesPath); + } + + @Test(expected=NullPointerException.class) + public void test_getProperties_null() throws IOException { + + ConfigLoader.getProperties(null,null); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.getProperties(null,null); + + } + + @Test(expected=NullPointerException.class) + public void test_getProperties_args2_null_case2() throws IOException { + + ConfigLoader.getProperties(servCont,null); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.getProperties(servCont,null); + + } + + @Test(expected=NullPointerException.class) + public void test_getProperties_args2_null_case3() throws IOException { + + ConfigLoader.getProperties(null,propertiesfile); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.getProperties(null,propertiesfile); + + } + + + @Test(expected=NullPointerException.class) + public void test_getProperties_args2_value() throws IOException { + + ConfigLoader.getProperties(servCont,propertiesfile); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.getProperties(servCont,propertiesfile); + + } + + @Test(expected=NullPointerException.class) + public void test_getProperties_args3_value() throws IOException { + + ConfigLoader.getProperties(servCont,propertiesfile,systemTypeExtension); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.getProperties(servCont,propertiesfile,systemTypeExtension); + + } + + + @Test + public void test_loadRaptorActionMapping() throws IOException { + + ConfigLoader.loadRaptorActionMapping(servCont); + Mockito.verify(cLoad, Mockito.times(1)); + ConfigLoader.loadRaptorActionMapping(servCont); + + } +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppConfigTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppConfigTest.java new file mode 100644 index 00000000..f4daa339 --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppConfigTest.java @@ -0,0 +1,128 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.conf; + + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalapp.scheduler.RegistryAdapter; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; + +@RunWith(MockitoJUnitRunner.class) +public class ExternalAppConfigTest { + + + @InjectMocks + ExternalAppConfig ExtConfig; + + @Mock (name="schedulerRegistryAdapter") + RegistryAdapter schreg; + + @Mock + ResourceHandlerRegistry registry; + + + @Mock + InterceptorRegistry registry1; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + } + + @Test + public void viewResolver_test() { + + ExtConfig.viewResolver(); + + } + + @Test(expected=NullPointerException.class) + public void addResourceHandlers_test() { + + ExtConfig.addResourceHandlers(registry); + } + + @Test(expected=NullPointerException.class) + public void addResourceHandlers_test_notNull() { + + ExtConfig.addResourceHandlers(registry); + } + + @Test + public void dataAccessService_test() throws Exception { + + ExtConfig.dataAccessService(); + } + + @Test + public void addTileDefinitions_test() { + + ExtConfig.addTileDefinitions(); + } + + @Test(expected=NullPointerException.class) + public void addInterceptors_test() { + + ExtConfig.addInterceptors(registry1); + } + + @Test + public void cacheManager_test() { + + ExtConfig.cacheManager(); + + } + + @Test(expected=NullPointerException.class) + public void schedulerFactoryBean_test() throws Exception { + + ExtConfig.schedulerFactoryBean(); + + } + +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppInitializerTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppInitializerTest.java new file mode 100644 index 00000000..3b80b913 --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/ExternalAppInitializerTest.java @@ -0,0 +1,78 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.conf; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class ExternalAppInitializerTest { + + @InjectMocks + ExternalAppInitializer appInit; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + } + + @Test + public void getRootConfigClasses_test() { + + appInit.getRootConfigClasses(); + } + + @Test + public void getServletConfigClasses_test() { + + appInit.getServletConfigClasses(); + } + + @Test + public void getServletMappings_test() { + + appInit.getServletMappings(); + } + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/HibernateMappingLocationsTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/HibernateMappingLocationsTest.java new file mode 100644 index 00000000..e5216498 --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/conf/HibernateMappingLocationsTest.java @@ -0,0 +1,75 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.conf; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class HibernateMappingLocationsTest { + + @InjectMocks + HibernateMappingLocations hiberMap; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + } + + @Test + public void getMappingLocations_test() { + + hiberMap.getMappingLocations(); + + } + + @Test + public void getPackagesToScan_test() { + + hiberMap.getPackagesToScan(); + } + + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/filter/SecurityXssFilterTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/filter/SecurityXssFilterTest.java new file mode 100644 index 00000000..4d2a34ca --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/filter/SecurityXssFilterTest.java @@ -0,0 +1,150 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.filter; + +import java.io.IOException; +import java.util.Enumeration; +import java.util.Vector; + +import static org.junit.Assert.assertEquals; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +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.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalapp.filter.SecurityXssFilter.RequestWrapper; +import org.onap.portalapp.filter.SecurityXssFilter.RequestWrapper.CachedServletInputStream; +import org.powermock.api.mockito.PowerMockito; + +@RunWith(MockitoJUnitRunner.class) +public class SecurityXssFilterTest { + + @InjectMocks + SecurityXssFilter sec; + + @Mock + Enumeration<String> enum_string; + + Vector<String> vec_String = new Vector<String>(); + + String name; + + @Mock + HttpServletRequest request; + + @Mock + HttpServletResponse response; + + @Mock + FilterChain filterChain; + + @Mock + ServletInputStream inputStream; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + } + + @Test(expected=NullPointerException.class) + public void RequestWrapper_test_case1() throws ServletException, IOException { + + vec_String.add("test1"); + vec_String.add("test2"); + + enum_string = vec_String.elements(); + + Mockito.when(request.getMethod()).thenReturn("POST"); + Mockito.when(request.getParameterNames()).thenReturn(enum_string); + + sec.doFilterInternal(request, response, filterChain); + } + + + @Test(expected=NullPointerException.class) + public void RequestWrapper_test_case2() throws ServletException, IOException { + + vec_String.add("test1"); + vec_String.add("test2"); + + enum_string = vec_String.elements(); + + Mockito.when(request.getMethod()).thenReturn("DELETE"); + Mockito.when(request.getParameterNames()).thenReturn(enum_string); + + sec.doFilterInternal(request, response, filterChain); + } + + @Test + public void getParameter_test() { + + RequestWrapper reqWrap = Mockito.mock(RequestWrapper.class); + Mockito.when(reqWrap.getParameter(name)).thenReturn("testString"); + + assertEquals("testString", reqWrap.getParameter(name)); + + } + + @Test + public void getInputStream_test() throws IOException { + + RequestWrapper reqWrap = PowerMockito.mock(RequestWrapper.class); + + CachedServletInputStream cacheStream = null; + + Mockito.when(reqWrap.getInputStream()).thenReturn(cacheStream); + + assertEquals(null, reqWrap.getInputStream()); + + } + + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/login/LoginStrategyImplTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/login/LoginStrategyImplTest.java new file mode 100644 index 00000000..8d7c09ab --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/login/LoginStrategyImplTest.java @@ -0,0 +1,116 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.login; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import javax.servlet.http.Cookie; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.core.onboarding.exception.PortalAPIException; +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(MockitoJUnitRunner.class) +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class}) +public class LoginStrategyImplTest { + + + @InjectMocks + LoginStrategyImpl logimpl; + + @Mock + HttpServletRequest request; + + @Mock + HttpServletResponse response; + + + Cookie[] cookie = new Cookie[]{new Cookie("EPService", "EPService"), new Cookie("UserId", "UserId")}; + + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + PowerMockito.mockStatic(SystemProperties.class); + } + + @Test(expected=NullPointerException.class) + public void doLogin_test() throws Exception { + + logimpl.doLogin(request, response); + + } + + @Test + public void getUserId_test() throws PortalAPIException { + + Mockito.when(request.getCookies()).thenReturn(cookie); + + logimpl.getUserId(request); + } + + @Test + public void getUserIdFromCookie_test_case1() throws PortalAPIException { + + logimpl.getUserId(request); + } + + @Test + public void getUserIdFromCookie_test_case2() throws PortalAPIException { + + Mockito.when(request.getCookies()).thenReturn(cookie); + + PowerMockito.when(SystemProperties.containsProperty("decryption_key")).thenReturn(false); + + logimpl.getUserId(request); + } + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegisterTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegisterTest.java new file mode 100644 index 00000000..839203e1 --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegisterTest.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.scheduler; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +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; +import org.quartz.CronTrigger; +import org.quartz.Trigger; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({SystemProperties.class,LogRegistry.class}) +public class RegisterTest { + + @InjectMocks + Register reg = new Register(); + + List<Trigger> scheduleTriggers = new ArrayList<>(); + + CronTrigger cron; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + PowerMockito.mockStatic(SystemProperties.class); + + } + + + @Test + public void SetregisterTriggers_test() { + + reg.setScheduleTriggers(scheduleTriggers); + } + + @Test + public void registerTriggers_test() { + + + + reg.registerTriggers(); + } + + @Test(expected=NullPointerException.class) + public void registerTriggers_test_case1() { + + PowerMockito.when(SystemProperties.containsProperty(SystemProperties.LOG_CRON)).thenReturn(true); + + LogRegistry log = PowerMockito.mock(LogRegistry.class); + + PowerMockito.when(log.getTrigger()).thenReturn(cron); + + reg.registerTriggers(); + } + + + @Test + public void getTriggers_test() { + + reg.getTriggers(); + } + + + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegistryAdapterTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegistryAdapterTest.java new file mode 100644 index 00000000..6047329d --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/scheduler/RegistryAdapterTest.java @@ -0,0 +1,121 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.scheduler; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.core.scheduler.Registerable; +import org.onap.portalsdk.workflow.services.WorkflowScheduleService; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.quartz.Trigger; +import org.springframework.scheduling.quartz.SchedulerFactoryBean; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({Registerable.class,Trigger.class}) +public class RegistryAdapterTest { + + @InjectMocks + RegistryAdapter regAdapt = new RegistryAdapter(); + + Registerable registry; + + WorkflowScheduleService workflowScheduleService; + + SchedulerFactoryBean schedulerBean; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + } + + @Test(expected=NullPointerException.class) + public void getTriggers_test() { + + regAdapt.getTriggers(); + } + + @Test + public void getSchedulerBean_test() { + + regAdapt.getSchedulerBean(); + } + + @Test + public void getRegistry_test() { + + regAdapt.getRegistry(); + } + + @Test + public void getWorkflowScheduleService_test() { + + regAdapt.getWorkflowScheduleService(); + } + + + @Test + public void setRegistry_test() { + + regAdapt.setRegistry(registry); + } + + @Test + public void setWorkflowScheduleService_test() { + + regAdapt.setWorkflowScheduleService(workflowScheduleService); + } + + @Test + public void setSchedulerBean_test() { + + regAdapt.setSchedulerBean(schedulerBean); + } + + @Test(expected=NullPointerException.class) + public void addCoreTriggers_test() { + + regAdapt.addCoreTriggers(); + } + +} diff --git a/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/service/AdminAuthExtensionTest.java b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/service/AdminAuthExtensionTest.java new file mode 100644 index 00000000..c5ebec7a --- /dev/null +++ b/ecomp-sdk/epsdk-app-os/src/main/test/org/onap/portalapp/service/AdminAuthExtensionTest.java @@ -0,0 +1,93 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalapp.service; + +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.domain.Role; +import org.onap.portalsdk.core.domain.User; + +@RunWith(MockitoJUnitRunner.class) +public class AdminAuthExtensionTest { + + @InjectMocks + AdminAuthExtension adminAuth; + + @Mock + User user; + + @Mock + Set<Role> role; + + @Before + public void init( ) { + + MockitoAnnotations.initMocks(this); + + } + + @Test + public void saveUserExtension_test() { + + adminAuth.saveUserExtension(user); + + } + + @Test + public void editUserExtension_test() { + + adminAuth.editUserExtension(user); + + } + + @Test + public void saveUserRoleExtension_test() { + + adminAuth.saveUserRoleExtension(role,user); + + } + +} diff --git a/ecomp-sdk/epsdk-fw/pom.xml b/ecomp-sdk/epsdk-fw/pom.xml index e1da0300..5b1f5d7b 100644 --- a/ecomp-sdk/epsdk-fw/pom.xml +++ b/ecomp-sdk/epsdk-fw/pom.xml @@ -18,6 +18,7 @@ <!-- properties are inherited from parent --> <properties> <resteasy.version>3.0.18.Final</resteasy.version> + <powermock.version>1.6.4</powermock.version> </properties> <!-- repositories are inherited from parent --> @@ -193,16 +194,18 @@ <scope>test</scope> <version>${jacoco.version}</version> </dependency> - <dependency> - <groupId>commons-fileupload</groupId> - <artifactId>commons-fileupload</artifactId> - <version>1.3.3</version> - </dependency> - <dependency> - <groupId>commons-beanutils</groupId> - <artifactId>commons-beanutils</artifactId> - <version>1.9.3</version> - </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>${powermock.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>${powermock.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java new file mode 100644 index 00000000..3b223e52 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/PortalAPIResponseTest.java @@ -0,0 +1,87 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + + +package org.onap.portalsdk.core.onboarding.crossapi; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class PortalAPIResponseTest { + + PortalAPIResponse portalApi = new PortalAPIResponse(true,"Status ok"); + + String status = "ok Message"; + + String message = "Status ok"; + + @Before + public void init() { + + //MockitoAnnotations.initMocks(this); + + } + + @Test + public void getStatus_test() { + + portalApi.getStatus(); + } + + @Test + public void setStatus_test() { + + portalApi.setStatus(status); + } + + + @Test + public void getMessage() { + + portalApi.getMessage(); + } + + @Test + public void setMessage() { + + portalApi.setMessage(message); + } +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java new file mode 100644 index 00000000..80728904 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/crossapi/SessionCommunicationServiceTest.java @@ -0,0 +1,81 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.crossapi; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +public class SessionCommunicationServiceTest { + + @InjectMocks + SessionCommunicationService sessComm; + + String ecompRestURL = "http://portal.onap.org:50580/ecompportal/auxapi"; + + String userName, password; + + String sessionTimeoutMap = "test"; + + String uebKey = "REPLACE-ME-UEB-APP-KEY-EPSDK-APP-OS"; + + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + } + + @Test + public void getSessionSlotCheckIntervalTest() { + + SessionCommunicationService.getSessionSlotCheckInterval(ecompRestURL, userName, password, uebKey); + } + + + @Test + public void requestPortalSessionTimeoutExtensionTest() { + + SessionCommunicationService.requestPortalSessionTimeoutExtension(ecompRestURL, userName, password, uebKey,sessionTimeoutMap); + } +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java new file mode 100644 index 00000000..e26b6086 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutBindingListenerTest.java @@ -0,0 +1,111 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.listener; + +import javax.servlet.http.HttpSessionBindingEvent; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; + + +@RunWith(MockitoJUnitRunner.class) +public class PortalTimeoutBindingListenerTest { + + PortalTimeoutBindingListener port; + + @Mock + HttpSessionBindingEvent event; + + @Mock + HttpSession session; + + @Before + public void init() { + + port = Mockito.spy(PortalTimeoutBindingListener.class); + + Mockito.when(event.getSession()).thenReturn(session); + + + } + + @Test(expected=NullPointerException.class) + public void valueBound_Test_null() { + + port.valueBound(event); + Mockito.verify(port, Mockito.times(1)).valueBound(event); + + + } + + @Test(expected=NullPointerException.class) + public void valueUnBound_Test_null() { + + port.valueBound(event); + Mockito.verify(port, Mockito.times(1)).valueBound(event); + } + + @Test + public void valueBound_Test_Notnull() { + + Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test"); + + port.valueBound(event); + Mockito.verify(port, Mockito.times(1)).valueBound(event); + + } + + @Test + public void valueUnBound_Test_Notnull() { + + Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test"); + port.valueUnbound(event); + Mockito.verify(port, Mockito.times(1)).valueUnbound(event); + + + } + + +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java new file mode 100644 index 00000000..3027cbee --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/PortalTimeoutHandlerTest.java @@ -0,0 +1,227 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.listener; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.*; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.onboarding.listener.PortalTimeoutHandler.SessionCommInf; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; + + +import com.fasterxml.jackson.core.JsonProcessingException; + +@RunWith(MockitoJUnitRunner.class) +public class PortalTimeoutHandlerTest { + + + @InjectMocks + PortalTimeoutHandler port; + + String portalJSessionId = "phrase"; + + String jSessionId = "test"; + + String ecompRestURL,userName,pwd,uebKey; + + @Mock + HttpServletRequest request; + + @Mock + ServletContext servCont; + + @Mock + Object servlettest; + + @Mock + SessionCommInf _sessionComm; + + @Mock + HttpSession session; + + String jSessionKey; + + + String sessionTimeoutMapStr; + + @Mock (name="sessionMap") + Map<String, HttpSession> sessionMap; + + @Mock + Set<String> test_set = new HashSet<String>(Arrays.asList("test1", "test2")); + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + //port = Mockito.spy(PortalTimeoutHandler.class); + + Mockito.when(session.getAttribute(PortalApiConstants.PORTAL_JSESSION_ID)).thenReturn("test-Phrase"); + + session.setAttribute("test1","test2"); + + Mockito.when(request.getSession()).thenReturn(session); + + Mockito.when(request.getSession(false)).thenReturn(session); + + Mockito.when(sessionMap.get(jSessionKey)).thenReturn(session); + + Mockito.when(sessionMap.keySet()).thenReturn(test_set); + + long lastAccessedTimeMilliSec = 200; + long previousToLastAccessTime = 256; + + Mockito.when(session.getAttribute(PortalApiConstants.SESSION_PREVIOUS_ACCESS_TIME)).thenReturn(previousToLastAccessTime); + Mockito.when(session.getLastAccessedTime()).thenReturn(lastAccessedTimeMilliSec); + Mockito.when(session.getMaxInactiveInterval()).thenReturn(1); + + + } + + @Test + public void getInstance_test() { + + port.getInstance(); + + } + + @Test + public void sessionCreated_test() { + + PortalTimeoutHandler.sessionCreated(portalJSessionId, jSessionId, session); + } + + @Test + public void sessionDestroyed_test() { + + port.sessionDestroyed(session); + } + + @Test + public void invalidateSession_test() { + + assertEquals(false,port.invalidateSession(portalJSessionId)); + } + + @Test + public void gatherSessionExtensions_test() { + + port.gatherSessionExtensions(); + + + } + + @Test + public void updateSessionExtensions_test() { + + PortalTimeoutHandler.updateSessionExtensions(sessionTimeoutMapStr); + } + + @Test(expected=NullPointerException.class) + public void synchronizeSessionForLastMinuteRequests_test_null() throws JsonProcessingException { + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + } + + @Test(expected=NumberFormatException.class) + public void synchronizeSessionForLastMinuteRequests_test_notnull() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(servlettest); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case2() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(null); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case3() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + + //Mockito.when(session.getAttribute(PortalApiConstants.SESSION_PREVIOUS_ACCESS_TIME)).thenReturn(previousToLastAccessTime); + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(null); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + @Test + public void synchronizeSessionForLastMinuteRequests_test_notnull_case4() throws JsonProcessingException { + Mockito.when(session.getServletContext()).thenReturn(servCont); + + + + + + + Mockito.when(session.getServletContext().getAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK)).thenReturn(2000); + + //session.setAttribute(PortalApiConstants.PORTAL_SESSION_SLOT_CHECK,2000); + + port.synchronizeSessionForLastMinuteRequests(request, ecompRestURL, userName, pwd, uebKey, _sessionComm); + + } + + +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java new file mode 100644 index 00000000..2b350e9d --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserContextListenerTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.listener; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; + +@RunWith(MockitoJUnitRunner.class) +public class UserContextListenerTest { + + + @InjectMocks + UserContextListener Ulist; + + @Mock + ServletContextEvent event; + + @Mock + ServletContext context; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + Mockito.when(event.getServletContext()).thenReturn(context); + + } + + @Test + public void contextInitialized_test() { + + Ulist.contextInitialized(event); + + } + +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java new file mode 100644 index 00000000..e371ebd9 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/listener/UserSessionListenerTest.java @@ -0,0 +1,114 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.listener; + +import java.util.HashMap; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpSessionEvent; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; + +@RunWith(MockitoJUnitRunner.class) +public class UserSessionListenerTest { + + @InjectMocks + UserSessionListener Ulist; + + @Mock + HttpSessionEvent event; + + @Mock + HttpSession session; + + @Mock + ServletContext context; + + @Mock + HashMap<String, HttpSession> activeUsers; + + @Before + public void init() { + + MockitoAnnotations.initMocks(this); + + Mockito.when(event.getSession()).thenReturn(session); + + } + + @Test(expected=NullPointerException.class) + public void sessionCreated_test_null() { + + Ulist.sessionCreated(event); + + } + + @Test + public void sessionCreated_test_notNull_case1() { + + Mockito.when(session.getServletContext()).thenReturn(context); + + Mockito.when(context.getAttribute(PortalApiConstants.ACTIVE_USERS_NAME)).thenReturn(activeUsers); + + Mockito.when(session.getId()).thenReturn("id1"); + + Ulist.sessionCreated(event); + + } + + @Test + public void sessionDestroyed_test_null() { + + Mockito.when(session.getServletContext()).thenReturn(context); + + Mockito.when(context.getAttribute(PortalApiConstants.ACTIVE_USERS_NAME)).thenReturn(activeUsers); + + Ulist.sessionDestroyed(event); + } + +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java new file mode 100644 index 00000000..9309b8f8 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FavoritesClientTest.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.rest; + +import java.io.IOException; +import java.net.HttpURLConnection; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({RestWebServiceClient.class}) +public class FavoritesClientTest { + + FavoritesClient favClient; + + String userId, appName,requestId, appUserName, appPassword; + + @Mock + HttpURLConnection con; + + @Mock + RestWebServiceClient restClient; + + int resCode; + + @Before + public void init() throws Exception { + + PowerMockito.mockStatic(RestWebServiceClient.class); + + PowerMockito.when(RestWebServiceClient.getInstance()).thenReturn(restClient); + + PowerMockito.when(restClient.getPortalContent("/getFavorites", userId, appName, requestId, appUserName, + appPassword,true)).thenReturn("test"); + + favClient = Mockito.spy(FavoritesClient.class); + + } + + @Test + public void getFavorites_test_notNull() throws IOException { + + System.out.println(FavoritesClient.getFavorites(userId, appName, requestId, appUserName, appPassword)); + + + + } + +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java new file mode 100644 index 00000000..29ab5e6e --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/FunctionalMenuClientTest.java @@ -0,0 +1,85 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.rest; + +import java.io.IOException; +import java.net.ConnectException; +import java.net.SocketTimeoutException; + +import javax.servlet.ServletException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.onboarding.util.SSOFilter; +import org.onap.portalsdk.core.onboarding.crossapi.IPortalRestAPIService; + +@RunWith(MockitoJUnitRunner.class) +public class FunctionalMenuClientTest { + + @InjectMocks + FunctionalMenuClient funcMenu; + + String userId, appName, requestId, appUserName, appPassword; + + @Before + public void init() throws ServletException { + + MockitoAnnotations.initMocks(this); + + + } + + @Test(expected=ConnectException.class) + public void getFunctionalMenu_test() throws IOException { + + FunctionalMenuClient.getFunctionalMenu(userId, appName, requestId, appUserName, appPassword); + } + + + + +} diff --git a/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java new file mode 100644 index 00000000..eb2493e5 --- /dev/null +++ b/ecomp-sdk/epsdk-fw/src/test/java/org/onap/portalsdk/core/onboarding/rest/RestWebServiceClientTest.java @@ -0,0 +1,173 @@ +/* + * ============LICENSE_START========================================== + * ONAP Portal SDK + * =================================================================== + * Copyright © 2018 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============================================ + * + * + */ + +package org.onap.portalsdk.core.onboarding.rest; + +import java.io.IOException; +import java.io.InputStream; +import java.net.ConnectException; +import java.net.HttpURLConnection; +import java.net.URL; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.onap.portalsdk.core.onboarding.rest.RestWebServiceClient; +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; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({URL.class,HttpURLConnection.class,PortalApiProperties.class}) +public class RestWebServiceClientTest { + + String restPath, userId, appName, requestId, appUserName, appPassword, contentType,content ; + + String url = "http://localhost:9000/"; + + String loginId; + + String appUebKey; + + Boolean isBasicAuth = true; + + InputStream inputStream; + + RestWebServiceClient restclient; + + @Before + public void init() throws IOException { + + restclient = RestWebServiceClient.getInstance(); + + PowerMockito.mockStatic(PortalApiProperties.class); + + MockitoAnnotations.initMocks(this); + } + + + + @Test(expected=ConnectException.class) + public void get_test_notNull() throws IOException { + + RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword); + + } + + @Test(expected=ConnectException.class) + public void get_test_notNull_case1() throws IOException { + + RestWebServiceClient.getInstance().get(url, loginId, appName, requestId, appUebKey, appUserName, appPassword); + + } + + + @Test(expected=NumberFormatException.class) + public void postPortalContent_test_case1() throws IOException { + + PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/"); + + PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc"); + + PowerMockito.when(PortalApiProperties.getProperty("ext_req_connection_timeout")).thenReturn("test"); + + RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth); + + } + + @Test(expected=IOException.class) + public void postPortalContent_test_case2() throws IOException { + + PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/"); + + RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth); + + } + + @Test(expected=IOException.class) + public void postPortalContent_test_case3() throws IOException { + + RestWebServiceClient.getInstance().postPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, contentType, content, isBasicAuth); + + } + + @Test(expected=IOException.class) + public void getPortalContent_test_case1() throws IOException { + + //Without the rest_url + + RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth); + } + + @Test(expected=IOException.class) + public void getPortalContent_test_case2() throws IOException { + + //Without the Ueb_app_key + + PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/"); + + RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth); + } + + @Test(expected=ConnectException.class) + public void getPortalContent_test_case3() throws IOException { + + PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/"); + + PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc"); + + RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth); + } + + @Test(expected=ConnectException.class) + public void getPortalContent_test_case4() throws IOException { + + //with BasicAuthentication = true + + PowerMockito.when(PortalApiProperties.getProperty("ecomp_rest_url")).thenReturn("http://localhost:55155/"); + + PowerMockito.when(PortalApiProperties.getProperty("ueb_app_key")).thenReturn("123abc"); + + RestWebServiceClient.getInstance().getPortalContent(restPath, userId, appName, requestId, appUserName, appPassword, isBasicAuth); + } + + + +} |