diff options
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/test')
26 files changed, 3206 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularSinglePageControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularSinglePageControllerTest.java new file mode 100644 index 00000000..68aa06ef --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularSinglePageControllerTest.java @@ -0,0 +1,73 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.AngularSinglePageController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class AngularSinglePageControllerTest { + + @InjectMocks + AngularSinglePageController angularSinglePageController = new AngularSinglePageController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void welcomeTest() { + ModelAndView expectedResluts = angularSinglePageController.view(mockedRequest); + assertEquals(expectedResluts.getViewName(),"single_page_sample"); + } + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastControllerTest.java new file mode 100644 index 00000000..a2068ea9 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastControllerTest.java @@ -0,0 +1,160 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; + +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.onap.portalapp.controller.sample.BroadcastController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.BroadcastMessage; +import org.onap.portalsdk.core.service.BroadcastService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.servlet.ModelAndView; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, AppUtils.class }) +public class BroadcastControllerTest { + + @InjectMocks + BroadcastController broadcastController = new BroadcastController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Mock + BroadcastService broadcastService; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void broadcastTest() { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(broadcastService.getBroadcastMessage(mockedRequest)).thenReturn(new BroadcastMessage()); + Mockito.when(SystemProperties.getProperty(SystemProperties.CLUSTERED)).thenReturn("true"); + Mockito.when(AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", "broadcast_site_descr", "", + "broadcast_site_descr")).thenReturn(new ArrayList<>()); + ModelAndView expectedResult = broadcastController.broadcast(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void broadcastExceptionTest() { + Mockito.when(broadcastService.getBroadcastMessage(mockedRequest)).thenThrow(new NullPointerException()); + ModelAndView expectedResult = broadcastController.broadcast(mockedRequest); + assertNull(expectedResult.getViewName()); + + } + + @Test + public void broadcastIfCLusterIsFalseTest() { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(broadcastService.getBroadcastMessage(mockedRequest)).thenReturn(new BroadcastMessage()); + Mockito.when(SystemProperties.getProperty(SystemProperties.CLUSTERED)).thenReturn("false"); + Mockito.when(AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", "broadcast_site_descr", "", + "broadcast_site_descr")).thenReturn(new ArrayList<>()); + ModelAndView expectedResult = broadcastController.broadcast(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void getBroadcastTest() throws IOException { + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(broadcastService.getBroadcastMessage(mockedRequest)).thenReturn(new BroadcastMessage()); + Mockito.when(SystemProperties.getProperty(SystemProperties.CLUSTERED)).thenReturn("true"); + Mockito.when(AppUtils.getLookupList("fn_lu_broadcast_site", "broadcast_site_cd", "broadcast_site_descr", "", + "broadcast_site_descr")).thenReturn(new ArrayList<>()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + broadcastController.getBroadcast(mockedRequest, mockedResponse); + } + + @Test + public void getBroadcastExcptionTest() throws IOException { + Mockito.when(broadcastService.getBroadcastMessage(mockedRequest)).thenThrow(new NullPointerException()); + broadcastController.getBroadcast(mockedRequest, mockedResponse); + } + + @Test + public void saveTest() throws Exception { + + String json = "{\"broadcastMessage\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"messageText\":null,\"locationId\":null,\"startDate\":null,\"endDate\":null,\"sortOrder\":null,\"active\":true,\"siteCd\":null}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastController.save(mockedRequest, mockedResponse)); + } + + @Test + public void saveExceptionTest() throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastController.save(mockedRequest, mockedResponse)); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastListControllerTest.java new file mode 100644 index 00000000..14f4ab0a --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/BroadcastListControllerTest.java @@ -0,0 +1,142 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.HashMap; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.BroadcastListController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.service.BroadcastService; +import org.springframework.web.servlet.ModelAndView; + +public class BroadcastListControllerTest { + + @InjectMocks + BroadcastListController broadcastListController = new BroadcastListController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Mock + BroadcastService broadcastService; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + + @Test + public void broadcastListTest() { + Mockito.when(broadcastService.getBcModel(mockedRequest)).thenReturn(new HashMap<>()); + ModelAndView expectedResult = broadcastListController.broadcastList(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void getBroadcastTest() throws IOException { + Mockito.when(broadcastService.getBcModel(mockedRequest)).thenReturn(new HashMap<>()); + Mockito.when(broadcastService.getBcModel(mockedRequest).get("messagesList")).thenReturn(new HashMap<>()); + Mockito.when(broadcastService.getBcModel(mockedRequest).get("messageLocations")).thenReturn(new HashMap<>()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + broadcastListController.getBroadcast(mockedRequest, mockedResponse); + } + + @Test + public void getBroadcastExceptionTest() throws IOException { + Mockito.when(broadcastService.getBcModel(mockedRequest)).thenThrow(nullPointerException); + broadcastListController.getBroadcast(mockedRequest, mockedResponse); + } + + @Test + public void removeTest() throws Exception { + String json = "{\"broadcastMessage\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"messageText\":null,\"locationId\":null,\"startDate\":null,\"endDate\":null,\"sortOrder\":null,\"active\":true,\"siteCd\":null}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastListController.remove(mockedRequest, mockedResponse)); + } + + @Test + public void removeExceptionTest() throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastListController.remove(mockedRequest, mockedResponse)); + } + + + @Test + public void toggleActiveTest() throws Exception { + String json = "{\"broadcastMessage\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"messageText\":null,\"locationId\":null,\"startDate\":null,\"endDate\":null,\"sortOrder\":null,\"active\":true,\"siteCd\":null}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastListController.toggleActive(mockedRequest, mockedResponse)); + } + + @Test + public void toggleActiveExceptionTest() throws Exception { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(broadcastListController.toggleActive(mockedRequest, mockedResponse)); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CallflowControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CallflowControllerTest.java new file mode 100644 index 00000000..047e16f5 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CallflowControllerTest.java @@ -0,0 +1,64 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.CallflowController; +import org.springframework.web.servlet.ModelAndView; + +public class CallflowControllerTest { + + @InjectMocks + CallflowController callflowController = new CallflowController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void welcomeTest() { + ModelAndView expectedResluts = callflowController.plot(); + assertNull(expectedResluts.getViewName()); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CamundaCockpitControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CamundaCockpitControllerTest.java new file mode 100644 index 00000000..4aee7752 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CamundaCockpitControllerTest.java @@ -0,0 +1,91 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; + +import java.util.Map; + +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.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.CamundaCockpitController; +import org.onap.portalapp.framework.MockitoTestSuite; +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({ SystemProperties.class}) +public class CamundaCockpitControllerTest { + + @InjectMocks + CamundaCockpitController camundaCockpitController = new CamundaCockpitController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void getCamundaCockpitLinkTest() { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.containsProperty("camunda_cockpit_link")).thenReturn(true); + Map expectedresult = camundaCockpitController.getCamundaCockpitLink(mockedRequest, mockedResponse); + assertEquals(expectedresult.size(), 2); + } + + @Test + public void getCamundaCockpitLinkFalseTest() { + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.containsProperty("camunda_cockpit_link")).thenReturn(false); + Map expectedresult = camundaCockpitController.getCamundaCockpitLink(mockedRequest, mockedResponse); + assertEquals(expectedresult.size(), 2); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborateListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborateListControllerTest.java new file mode 100644 index 00000000..7346aeab --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborateListControllerTest.java @@ -0,0 +1,142 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.CollaborateListController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.service.UserProfileService; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.web.servlet.ModelAndView; + +public class CollaborateListControllerTest { + + + @InjectMocks + CollaborateListController collaborateListController = new CollaborateListController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + UserProfileService service; + + @Mock + UserUtils userUtils = new UserUtils(); + + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + + @Test + public void profileSearchTest() + { + List<User> userList = new ArrayList<>(); + User user = new User(); + user.setOrgUserId("test12"); + userList.add(user); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenReturn(userList); + ModelAndView expectedResult = collaborateListController.ProfileSearch(mockedRequest); + assertEquals(expectedResult.getModel().size(), userList.size()); + } + + @Test + public void profileSearchExceptionTest() + { + List<User> userList = new ArrayList<>(); + User user = new User(); + user.setOrgUserId("test12"); + userList.add(user); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenThrow(nullPointerException); + ModelAndView expectedResult = collaborateListController.ProfileSearch(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void getCollaborateListTest() throws IOException + { + List<User> userList = new ArrayList<>(); + User user = new User(); + user.setOrgUserId("test12"); + userList.add(user); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenReturn(userList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + collaborateListController.getCollaborateList(mockedRequest,mockedResponse); + + } + + @Test + public void getCollaborateListExceptionTest() throws IOException + { + List<User> userList = new ArrayList<>(); + User user = new User(); + user.setOrgUserId("test12"); + userList.add(user); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(service.findAllUserWithOnOffline(user.getOrgUserId())).thenThrow(nullPointerException); + collaborateListController.getCollaborateList(mockedRequest,mockedResponse); + + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java new file mode 100644 index 00000000..f91082c8 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/CollaborationControllerTest.java @@ -0,0 +1,114 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.CollaborationController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.web.servlet.ModelAndView; + +public class CollaborationControllerTest { + + @InjectMocks + CollaborationController collaborationController = new CollaborationController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Test + public void viewTest() { + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + ModelAndView expectedResult = collaborationController.view(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void viewUserLastTest() { + User user = new User(); + user.setOrgUserId("test12"); + user.setLastName("test"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + ModelAndView expectedResult = collaborationController.view(mockedRequest); + assertNull(expectedResult.getViewName()); + } + + @Test + public void openCollaborationTest() { + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + ModelAndView expectedResult = collaborationController.openCollaboration(mockedRequest); + assertEquals(expectedResult.getViewName(),"openCollaboration"); + } + + @Test + public void openCollaborationLastNameTest() { + User user = new User(); + user.setOrgUserId("test12"); + user.setLastName("test"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + ModelAndView expectedResult = collaborationController.openCollaboration(mockedRequest); + assertEquals(expectedResult.getViewName(),"openCollaboration"); + } + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/DS2SampleControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/DS2SampleControllerTest.java new file mode 100644 index 00000000..a81aab48 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/DS2SampleControllerTest.java @@ -0,0 +1,77 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.DS2SampleController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.service.ProfileService; +import org.springframework.web.servlet.ModelAndView; + +public class DS2SampleControllerTest { + + @InjectMocks + DS2SampleController dS2SampleController = new DS2SampleController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + NullPointerException nullPointerException = new NullPointerException(); + + @Mock + ProfileService service; + + @Test + public void profileSearchTest() + { + ModelAndView expectedResult = dS2SampleController.ProfileSearch(mockedRequest); + assertEquals(expectedResult.getViewName(), "ds2_sample"); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElasticSearchControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElasticSearchControllerTest.java new file mode 100644 index 00000000..7a0d47cd --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElasticSearchControllerTest.java @@ -0,0 +1,145 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +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.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.ElasticSearchController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalapp.model.Result; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.servlet.ModelAndView; + +import com.google.gson.Gson; + +import io.searchbox.core.SearchResult; + +import io.searchbox.client.JestClient; +import io.searchbox.client.JestClientFactory; +import io.searchbox.client.config.HttpClientConfig; +import io.searchbox.client.http.JestHttpClient; + + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ JestClientFactory.class, JestClient.class }) +public class ElasticSearchControllerTest { + + @InjectMocks + ElasticSearchController elasticSearchController = new ElasticSearchController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @Mock + JestClientFactory factory; + @Mock + JestClient client ; + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void searchTest() + { + ModelAndView expectedResult = elasticSearchController.search(); + assertEquals(expectedResult.getViewName(), "es_search_demo"); + } + + @Test + public void suggestTest() + { + ModelAndView expectedResult = elasticSearchController.suggest(); + assertEquals(expectedResult.getViewName(), "es_suggest_demo"); + } + +// @Test +// public void doSuggestTest() throws IOException +// { +// PowerMockito.mockStatic(JestClient.class); +// PowerMockito.mockStatic(JestClientFactory.class); +// SearchResult result = new SearchResult(new Gson()); +// Mockito.when(factory.getObject()).thenReturn(client); +// Mockito.when(client.execute(Matchers.anyObject())).thenReturn(result); +//// Mockito.doNothing().when(factory).setHttpClientConfig(new HttpClientConfig +//// .Builder(Matchers.anyString()) +//// .multiThreaded(Matchers.anyBoolean()) +//// .build()); +// +// JestClientFactory factory = Mockito.spy(new JestClientFactory()); +// HttpClientConfig httpClientConfig = Mockito.spy(new HttpClientConfig.Builder("http://localhost:9200") +// .discoveryEnabled(true) +// .build()); +// factory.setHttpClientConfig(httpClientConfig); +// JestHttpClient jestClient = (JestHttpClient) factory.getObject(); +// +// elasticSearchController.doSearch("{\"data\":\"1\",\"size\":\"1\"}"); +// } + + @Test + public void sendResultTest() + { + ResponseEntity<Result> result = elasticSearchController.sendResult(null); + assertEquals(result.getStatusCode(), HttpStatus.OK); + } + + @Test + public void isRestFultest() + { + assertTrue(elasticSearchController.isRESTfulCall()); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElementModelControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElementModelControllerTest.java new file mode 100644 index 00000000..63d10f7d --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ElementModelControllerTest.java @@ -0,0 +1,117 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.ServletContext; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.io.FilenameUtils; +import org.apache.xmlbeans.SystemProperties; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.ElementModelController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.service.ElementMapService; +import org.onap.portalsdk.core.util.YamlUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({FilenameUtils.class, YamlUtils.class, SystemProperties.class}) +public class ElementModelControllerTest { + + @InjectMocks + ElementModelController elementModelController = new ElementModelController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + ElementMapService elementMapService = new ElementMapService(); + + + @Test + public void layoutTest() throws Exception { + PowerMockito.mockStatic(FilenameUtils.class); + PowerMockito.mockStatic(YamlUtils.class); + Mockito.when(FilenameUtils.normalize(mockedRequest.getParameter(Matchers.anyString()))).thenReturn("test"); + ServletContext servletContext = Mockito.mock(ServletContext.class); + Mockito.when(mockedRequest.getServletContext()).thenReturn(servletContext); + Mockito.when(YamlUtils.readYamlFile(Matchers.anyString(), Matchers.anyString())).thenReturn(new HashMap<>()); + System.out.println(elementModelController.layout(mockedRequest, mockedResponse)); + assertTrue(elementModelController.layout(mockedRequest, mockedResponse).contains("domainList")); + } + + @Test + public void callflowTest() throws Exception { + PowerMockito.mockStatic(FilenameUtils.class); + PowerMockito.mockStatic(YamlUtils.class); + PowerMockito.mockStatic(SystemProperties.class); + Mockito.when(SystemProperties.getProperty(Matchers.anyString())).thenReturn("customTest"); + Mockito.when(FilenameUtils.normalize(mockedRequest.getParameter(Matchers.anyString()))).thenReturn("test"); + ServletContext servletContext = Mockito.mock(ServletContext.class); + Mockito.when(mockedRequest.getServletContext()).thenReturn(servletContext); + Mockito.when(FilenameUtils.normalize("test")).thenReturn("test"); + Map<String, Object> callflow = new HashMap<>(); + callflow.put("callSequenceSteps", new Object()); + callflow.put("callSequenceSteps", new ArrayList<>()); + Mockito.when(YamlUtils.readYamlFile(Matchers.anyString(), Matchers.anyString())).thenReturn(callflow); + assertEquals(elementModelController.callflow(mockedRequest, mockedResponse), ""); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/LeafletMapContollerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/LeafletMapContollerTest.java new file mode 100644 index 00000000..0139102c --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/LeafletMapContollerTest.java @@ -0,0 +1,70 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.LeafletMapContoller; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class LeafletMapContollerTest { + + @InjectMocks + LeafletMapContoller leafletMapContoller = new LeafletMapContoller(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void plotTest() { + ModelAndView expectedResluts = leafletMapContoller.plot(); + assertNull(expectedResluts.getViewName()); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapControllerTest.java new file mode 100644 index 00000000..1072e5d5 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/NetMapControllerTest.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.portalapp.controller; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.NetMapController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class NetMapControllerTest { + + + @InjectMocks + NetMapController netMapController = new NetMapController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void plotTest() { + ModelAndView expectedResluts = netMapController.plot(mockedRequest); + assertEquals(expectedResluts.getViewName(),"frame_insert"); + } + + @Test + public void plot2Test() { + ModelAndView expectedResluts = netMapController.plot2(); + assertNull(expectedResluts.getViewName()); + } + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/PostDroolsControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/PostDroolsControllerTest.java new file mode 100644 index 00000000..0fe919f7 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/PostDroolsControllerTest.java @@ -0,0 +1,141 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.PostDroolsController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.command.PostDroolsBean; +import org.onap.portalsdk.core.service.PostDroolsService; +import org.springframework.web.servlet.ModelAndView; + +public class PostDroolsControllerTest { + + @InjectMocks + PostDroolsController postDroolsController = new PostDroolsController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Mock + PostDroolsService postDroolsService; + + @Test + public void droolsTest() { + ModelAndView expectedResluts = postDroolsController.drools(mockedRequest); + assertNull(expectedResluts.getViewName()); + } + + @Test + public void getDroolsTest() throws IOException { + List<PostDroolsBean> beanList = new ArrayList<>(); + Mockito.when(postDroolsService.fetchDroolBeans()).thenReturn(beanList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + postDroolsController.getDrools(mockedRequest,mockedResponse); + } + + @Test + public void getDroolsExceptionTest() throws IOException { + Mockito.when(postDroolsService.fetchDroolBeans()).thenThrow(new NullPointerException()); + postDroolsController.getDrools(mockedRequest,mockedResponse); + } + + + @Test + public void getDroolDetailsTest() throws IOException { + Mockito.when(mockedRequest.getParameter("selectedFile")).thenReturn("test"); + Mockito.when(postDroolsService.retrieveClass("test")).thenReturn("result"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + postDroolsController.getDroolDetails(mockedRequest,mockedResponse); + } + @Test + public void getDroolDetailsExceptionTest() throws IOException { + Mockito.when(mockedRequest.getParameter("selectedFile")).thenReturn("test"); + Mockito.when(postDroolsService.retrieveClass("test")).thenThrow(new NullPointerException()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + postDroolsController.getDroolDetails(mockedRequest,mockedResponse); + } + + @Test + public void searchTest() throws Exception { + String json = "{\"postDroolsBean\": {\"droolsFile\":\"test\",\"className\":null,\"selectedRules\":null}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json))); + Mockito.when(postDroolsService.execute(Matchers.anyString(), + Matchers.anyString(), Matchers.anyString())).thenReturn("result"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(postDroolsController.search(mockedRequest,mockedResponse)); + } + + @Test + public void searchExceptionTest() throws Exception { + assertNull(postDroolsController.search(mockedRequest,mockedResponse)); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ReportDashboardControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ReportDashboardControllerTest.java new file mode 100644 index 00000000..05c921c7 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/ReportDashboardControllerTest.java @@ -0,0 +1,70 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.ReportDashboardController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class ReportDashboardControllerTest { + + @InjectMocks + ReportDashboardController reportDashboardController = new ReportDashboardController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + @Test + public void adminViewTest() + { + ModelAndView expectedResult = reportDashboardController.adminView(mockedRequest); + assertNull(expectedResult.getViewName()); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/SamplePageControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/SamplePageControllerTest.java new file mode 100644 index 00000000..0d36b95f --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/SamplePageControllerTest.java @@ -0,0 +1,71 @@ +/* + * ============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.portalapp.controller; + +import static org.junit.Assert.assertEquals; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.sample.SamplePageController; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class SamplePageControllerTest { + + @InjectMocks + SamplePageController samplePageController = new SamplePageController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + + @Test + public void adminViewTest() + { + ModelAndView expectedResult = samplePageController.plot(mockedRequest); + assertEquals(expectedResult.getViewName(),"samplePage"); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularAdminControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/AngularAdminControllerTest.java index 02755b4a..2ae922aa 100644 --- a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/AngularAdminControllerTest.java +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/AngularAdminControllerTest.java @@ -50,6 +50,7 @@ import org.junit.Test; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.onap.portalapp.controller.core.AngularAdminController; import org.onap.portalapp.framework.MockitoTestSuite; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.web.support.UserUtils; diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FnMenuControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FnMenuControllerTest.java new file mode 100644 index 00000000..1f1d2db3 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FnMenuControllerTest.java @@ -0,0 +1,229 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.Menu; +import org.onap.portalsdk.core.domain.MenuData; +import org.onap.portalsdk.core.domain.RoleFunction; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.service.FnMenuService; +import org.onap.portalsdk.core.service.FunctionalMenuListService; +import org.onap.portalsdk.core.web.support.UserUtils; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class FnMenuControllerTest { + + @InjectMocks + FnMenuController fnMenuController = new FnMenuController(); + + @Mock + FnMenuService fnMenuService; + + @Mock + FunctionalMenuListService functionalMenuListService; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Mock + ObjectMapper mapper = new ObjectMapper(); + + @Test + public void getParentListTest() throws Exception{ + @SuppressWarnings("rawtypes") + List<List> list = new ArrayList<>(); + Mockito.when(fnMenuService.getParentList()).thenReturn(list); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + fnMenuController.getParentList(mockedRequest, mockedResponse); + } + + @Test + public void getParentListExceptionTest() throws Exception{ + Mockito.when(fnMenuService.getParentList()).thenThrow(nullPointerException); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + fnMenuController.getParentList(mockedRequest, mockedResponse); + } + + @Test + public void getFunctionCDListTest() throws Exception{ + List<RoleFunction> roleFunctionList = new ArrayList<RoleFunction>(); + Mockito.when(functionalMenuListService.getFunctionCDList(mockedRequest)).thenReturn(roleFunctionList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + fnMenuController.getFunctionCDList(mockedRequest, mockedResponse); + } + + @Test + public void getFunctionCDListExceptionTest() throws Exception{ + Mockito.when(functionalMenuListService.getFunctionCDList(mockedRequest)).thenThrow(nullPointerException); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + fnMenuController.getFunctionCDList(mockedRequest, mockedResponse); + } + + @Test + public void getFnMenuListTest() throws IOException{ + List<MenuData> menuList = new ArrayList<>(); + MenuData menudata = new MenuData(); + menudata.setId((long) 1); + menudata.setLabel("test"); + menudata.setParentMenu(menudata); + menuList.add(menudata); + Mockito.when(fnMenuService.getFnMenuItems()).thenReturn(menuList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + fnMenuController.getFnMenuList(mockedRequest, mockedResponse); + } + + @Test + public void getFnMenuListExceptionTest() throws IOException{ + List<MenuData> menuList = new ArrayList<>(); + MenuData menudata = new MenuData(); + menudata.setId((long) 1); + menudata.setLabel("test"); + menudata.setParentMenu(menudata); + menuList.add(menudata); + Mockito.when(fnMenuService.getFnMenuItems()).thenThrow(nullPointerException); + fnMenuController.getFnMenuList(mockedRequest, mockedResponse); + } + + @Test + public void updateFnMenuTest() throws Exception{ + + String fnMenuItem = "{\"availableFnMenuItem\":{\"id\":9,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\"" + + ":null,\"auditTrail\":null,\"menuLevel\":null,\"label\":\"Profile\",\"parentId\":1,\"action\":\"userProfile\",\"functionCd\":\"menu_profile\"," + + "\"sortOrder\":90,\"servlet\":\"N/A\",\"queryString\":\"N/A\",\"externalUrl\":\"test\",\"target\":\"N/A\",\"active\":true,\"menuSetCode\":\"APP\"," + + "\"separator\":false,\"imageSrc\":\"icon-people-oneperson\",\"parentMenu\":null,\"childMenus\":[],\"activeAsString\":\"true\"," + + "\"parentIdAsString\":\"1\",\"separatorAsString\":\"false\",\"active_yn\":false,\"$$hashKey\":\"object:99\"}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(fnMenuItem))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(fnMenuController.updateFnMenu(mockedRequest, mockedResponse)); + } + + @Test + public void updateFnMenuExceptionTest() throws Exception{ + Menu fnMenuItemObj = new Menu(); + fnMenuItemObj.setLabel("test"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(fnMenuController.updateFnMenu(mockedRequest, mockedResponse)); + } + + @Test + public void removeFnMenuTest() throws Exception{ + String fnMenuItem = "{\"fnMenuItem\":{\"id\":9,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\"" + + ":null,\"auditTrail\":null,\"menuLevel\":null,\"label\":\"Profile\",\"parentId\":1,\"action\":\"userProfile\",\"functionCd\":\"menu_profile\"," + + "\"sortOrder\":90,\"servlet\":\"N/A\",\"queryString\":\"N/A\",\"externalUrl\":\"test\",\"target\":\"N/A\",\"active\":true,\"menuSetCode\":\"APP\"," + + "\"separator\":false,\"imageSrc\":\"icon-people-oneperson\",\"parentMenu\":null,\"childMenus\":[],\"activeAsString\":\"true\"," + + "\"parentIdAsString\":\"1\",\"separatorAsString\":\"false\",\"active_yn\":false,\"$$hashKey\":\"object:99\"}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(fnMenuItem))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(fnMenuController.removeFnMenu(mockedRequest, mockedResponse)); + } + + @Test + public void removeFnMenuExceptionTest() throws Exception{ + String fnMenuItem = "{\"availableFnMenuItem\":{\"id\":9,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\"" + + ":null,\"auditTrail\":null,\"menuLevel\":null,\"label\":\"Profile\",\"parentId\":1,\"action\":\"userProfile\",\"functionCd\":\"menu_profile\"," + + "\"sortOrder\":90,\"servlet\":\"N/A\",\"queryString\":\"N/A\",\"externalUrl\":\"test\",\"target\":\"N/A\",\"active\":true,\"menuSetCode\":\"APP\"," + + "\"separator\":false,\"imageSrc\":\"icon-people-oneperson\",\"parentMenu\":null,\"childMenus\":[],\"activeAsString\":\"true\"," + + "\"parentIdAsString\":\"1\",\"separatorAsString\":\"false\",\"active_yn\":false,\"$$hashKey\":\"object:99\"}}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(fnMenuItem))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(fnMenuController.removeFnMenu(mockedRequest, mockedResponse)); + } + + @Test + public void getViewNameTest() { + String expectedResult = "test"; + fnMenuController.setViewName(expectedResult); + String actualResult = fnMenuController.getViewName(); + assertEquals(expectedResult, actualResult); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FuncMenuControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FuncMenuControllerTest.java new file mode 100644 index 00000000..d1d3f741 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/FuncMenuControllerTest.java @@ -0,0 +1,176 @@ +/* + * ============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.portalapp.controller.core; + + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; + +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.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.App; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.onboarding.ueb.UebException; +import org.onap.portalsdk.core.onboarding.ueb.UebManager; +import org.onap.portalsdk.core.onboarding.ueb.UebMsg; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.service.AppService; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({UebManager.class, PortalApiProperties.class, PortalApiConstants.class}) +public class FuncMenuControllerTest { + + @InjectMocks + FuncMenuController funcMenuController = new FuncMenuController(); + + @Mock + AppService appService; + + @Mock + UebManager uebManager; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Mock + ObjectMapper mapper = new ObjectMapper(); + + @Test + public void functionalMenuUserExistsTest() throws IOException, UebException{ + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + PowerMockito.mockStatic(UebManager.class); + + Mockito.when(UebManager.getInstance()).thenReturn(uebManager); + Mockito.when(uebManager.requestReply(Matchers.anyObject())).thenReturn(new UebMsg()); + funcMenuController.functionalMenu(mockedRequest, mockedResponse); + } + + @Test + public void functionalMenuUserNotExistsTest() throws IOException, UebException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + + funcMenuController.functionalMenu(mockedRequest, mockedResponse); + } + + @Test + public void functionalMenuViaRestTest() throws IOException, UebException{ + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + PowerMockito.mockStatic(UebManager.class); + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.USE_REST_FOR_FUNCTIONAL_MENU)).thenReturn("test"); + Mockito.when(UebManager.getInstance()).thenReturn(uebManager); + funcMenuController.functionalMenu(mockedRequest, mockedResponse); + } + + @Test + public void functionalMenuViaRestAppNullTest() throws IOException, UebException{ + App app = new App(); + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(appService.getDefaultApp()).thenReturn(app); + PowerMockito.mockStatic(UebManager.class); + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.USE_REST_FOR_FUNCTIONAL_MENU)).thenReturn("test"); + Mockito.when(UebManager.getInstance()).thenReturn(uebManager); + funcMenuController.functionalMenu(mockedRequest, mockedResponse); + } + + @Test + public void functionalMenuExceptionTest() throws IOException{ + User user = new User(); + user.setOrgUserId("test12"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + funcMenuController.functionalMenu(mockedRequest, mockedResponse); + } + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java new file mode 100644 index 00000000..954103d2 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/LogoutControllerTest.java @@ -0,0 +1,156 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +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.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.onboarding.ueb.UebManager; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.service.AppService; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.servlet.ModelAndView; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({PortalApiProperties.class, PortalApiConstants.class, PortalApiConstants.class,RequestContextHolder.class}) +public class LogoutControllerTest { + + @InjectMocks + LogoutController logoutController = new LogoutController(); + + @Mock + AppService appService; + + @Mock + UebManager uebManager; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Mock + ObjectMapper mapper = new ObjectMapper(); + + @Test + public void globalLogoutTest(){ + ModelAndView modelView = null; + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + PowerMockito.mockStatic(RequestContextHolder.class); + ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest); + Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + logoutController.globalLogout(mockedRequest); + } + + @Test + public void globalLogoutExceptionTest(){ + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + assertNull(logoutController.globalLogout(mockedRequest)); + } + + @Test + public void appLogoutTest(){ + ModelAndView actualModelView = new ModelAndView("redirect:https://portal.openecomp.org/ecompportal/process_csp"); + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + PowerMockito.mockStatic(RequestContextHolder.class); + ServletRequestAttributes ServletRequestAttributes = new ServletRequestAttributes(mockedRequest); + Mockito.when(RequestContextHolder.currentRequestAttributes()).thenReturn(ServletRequestAttributes); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + ModelAndView expectedModelView = logoutController.appLogout(mockedRequest); + assertEquals(actualModelView.getViewName(), expectedModelView.getViewName()); + } + + @Test + public void appLogoutExceptionTest(){ + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + assertNull(logoutController.appLogout(mockedRequest)); + } + + @Test + public void getUserTest(){ + User expectedUser = new User(); + expectedUser.setActive(false); + user.setActive(false); + logoutController.setUser(user); + User actualUser = logoutController.getUser(); + assertEquals(expectedUser.getActive(), actualUser.getActive()); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/MenuListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/MenuListControllerTest.java new file mode 100644 index 00000000..655cccb4 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/MenuListControllerTest.java @@ -0,0 +1,241 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.MenuData; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.onboarding.util.PortalApiConstants; +import org.onap.portalsdk.core.onboarding.util.PortalApiProperties; +import org.onap.portalsdk.core.restful.client.SharedContextRestClient; +import org.onap.portalsdk.core.service.FnMenuService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({PortalApiProperties.class, PortalApiConstants.class, SystemProperties.class}) +public class MenuListControllerTest { + + @InjectMocks + MenuListController menuListController = new MenuListController(); + + @Mock + FnMenuService fnMenuService; + + @Mock + private SharedContextRestClient sharedContextRestClient; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Test + public void getMenuTest() throws IOException{ + List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>(); + List<MenuData> parentList = new ArrayList<MenuData>(); + Set<MenuData> menuResult = new HashSet<MenuData>(); + Mockito.doThrow(new NullPointerException()).when(fnMenuService).setMenuDataStructure(childItemList, parentList, menuResult); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + + menuListController.getMenu(mockedRequest, mockedResponse); + } + + @SuppressWarnings("unchecked") + @Test + public void getMenuExceptionTest() throws IOException{ + Mockito.doThrow(new NullPointerException()).when(fnMenuService).setMenuDataStructure(Matchers.anyList(), Matchers.anyList(), (Set<MenuData>) Matchers.anySet()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.getMenu(mockedRequest, mockedResponse); + } + + @Test + public void getAppNameTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.getAppName(mockedRequest, mockedResponse); + } + + @Test + public void getAppNameExceptionTest(){ + menuListController.getAppName(mockedRequest, mockedResponse); + } + + @Test + public void getLeftMenuJSPTest() throws IOException{ + Map<String, Object> actualResult = new HashMap<>(); + List<String> list = new ArrayList<String>(); + Map<String, Object> expectedResult = new HashMap<>(); + expectedResult.put("childItemList", list); + expectedResult.put("parentList", list); + List<List<MenuData>> childItemList = new ArrayList<List<MenuData>>(); + List<MenuData> parentList = new ArrayList<MenuData>(); + Set<MenuData> menuResult = new HashSet<MenuData>(); + Mockito.doThrow(new NullPointerException()).when(fnMenuService).setMenuDataStructure(childItemList, parentList, menuResult); + actualResult = menuListController.getLeftMenuJSP(mockedRequest); + assertEquals(actualResult.size(), expectedResult.size()); + } + + @SuppressWarnings("unchecked") + @Test + public void getLeftMenuJSPExceptionTest() throws IOException{ + Mockito.doThrow(new NullPointerException()).when(fnMenuService).setMenuDataStructure(Matchers.anyList(), Matchers.anyList(), Matchers.anySet()); + menuListController.getLeftMenuJSP(mockedRequest); + } + + @Test + public void getUserInfoTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.getUserInfo(mockedRequest, mockedResponse); + } + + @Test + public void getUserInfoExceptionTest() throws IOException{ + menuListController.getUserInfo(mockedRequest, mockedResponse); + } + + @Test + public void getTopMenuExceptionTest(){ + menuListController.getTopMenu(mockedRequest, mockedResponse); + } + + @Test + public void getTopMenuTest() throws IOException{ + PowerMockito.mockStatic(SystemProperties.class); + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + HttpSession session = mockedRequest.getSession(); + Mockito.when(SystemProperties.getProperty(SystemProperties.USER_NAME)).thenReturn("test"); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_NAME))).thenReturn("userName"); + Mockito.when(session.getAttribute(SystemProperties.FIRST_NAME)).thenReturn("firstName"); + Mockito.when(session.getAttribute(SystemProperties.LAST_NAME)).thenReturn("lastName"); + Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user"); + Mockito.when(session.getAttribute(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME))).thenReturn(user); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.getTopMenu(mockedRequest, mockedResponse); + } + + @Test + public void pageRedirectContactTest() throws IOException{ + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(mockedRequest.getParameter("page")).thenReturn("contact"); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.pageRedirect(mockedRequest, mockedResponse); + } + + @Test + public void pageRedirectAccessTest() throws IOException{ + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(mockedRequest.getParameter("page")).thenReturn("access"); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.pageRedirect(mockedRequest, mockedResponse); + } + + @Test + public void pageRedirectExceptionTest() throws IOException{ + PowerMockito.mockStatic(PortalApiProperties.class); + PowerMockito.mockStatic(PortalApiConstants.class); + Mockito.when(PortalApiProperties + .getProperty(PortalApiConstants.ECOMP_REDIRECT_URL)).thenReturn("https://portal.openecomp.org/ecompportal/process_csp"); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + menuListController.pageRedirect(mockedRequest, mockedResponse); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileControllerTest.java new file mode 100644 index 00000000..41367a16 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileControllerTest.java @@ -0,0 +1,310 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.restful.client.SharedContextRestClient; +import org.onap.portalsdk.core.service.RoleService; +import org.onap.portalsdk.core.service.UserProfileService; +import org.onap.portalsdk.core.service.UserService; +import org.onap.portalsdk.core.util.SystemProperties; +import org.onap.portalsdk.core.web.support.AppUtils; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.junit4.PowerMockRunner; +import org.springframework.web.servlet.ModelAndView; + +@RunWith(PowerMockRunner.class) +@PrepareForTest({ SystemProperties.class, AppUtils.class ,UserUtils.class}) +public class ProfileControllerTest { + + @InjectMocks + ProfileController profileController = new ProfileController(); + + @Mock + UserProfileService service; + + @Mock + UserService userService; + + @Mock + RoleService roleService; + + @Mock + private SharedContextRestClient sharedContextRestClient; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Test + public void profileTest() throws IOException{ + ModelAndView actualModelAndView = new ModelAndView("profile"); + User user = new User(); + user.setOrgUserId("test"); + Long profileId = null; + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(mockedRequest.getRequestURI()).thenReturn("self_profile.htm"); + Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("test"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + Mockito.when(userService.getUser(String.valueOf(profileId))).thenReturn(user); + ModelAndView expectedModelAndView = profileController.profile(mockedRequest); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void profileRequestURITest() throws IOException{ + ModelAndView actualModelAndView = new ModelAndView("profile"); + User user = new User(); + user.setOrgUserId("test"); + int profileId = 1; + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(mockedRequest.getRequestURI()).thenReturn("test"); + Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("1"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUser(String.valueOf(profileId))).thenReturn(user); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + Mockito.when(userService.getUser(String.valueOf(profileId))).thenReturn(user); + ModelAndView expectedModelAndView = profileController.profile(mockedRequest); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void profileExceptionTest() throws IOException{ + ModelAndView actualModelAndView = new ModelAndView("profile"); + User profile = null; + Long profileId = null; + Mockito.when(mockedRequest.getRequestURI()).thenReturn("self_profile.htm"); + Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("test"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(userService.getUser(String.valueOf(profileId))).thenReturn(profile); + ModelAndView expectedModelAndView = profileController.profile(mockedRequest); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void selfProfileTest() throws Exception{ + ModelAndView actualModelAndView = new ModelAndView("profile"); + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + ModelAndView expectedModelAndView = profileController.selfProfile(mockedRequest); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void selfProfileExceptionTest() throws Exception{ + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + profileController.selfProfile(mockedRequest); + } + + @SuppressWarnings("rawtypes") + @Test + public void getStatesTest(){ + List actualList = new ArrayList(); + PowerMockito.mockStatic(AppUtils.class); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + List expectedlist =profileController.getStates(); + assertEquals(actualList.size(), expectedlist.size()); + } + + @Test + public void getSelfProfileTest() throws IOException{ + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.getSelfProfile(mockedRequest, mockedResponse); + } + + @Test + public void getSelfProfileExceptionTest(){ + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + profileController.getSelfProfile(mockedRequest, mockedResponse); + } + + @Test + public void getUserTest() throws IOException{ + User user = new User(); + user.setOrgUserId("test"); + Long profileId = null; + PowerMockito.mockStatic(AppUtils.class); + PowerMockito.mockStatic(UserUtils.class); + Mockito.when(mockedRequest.getRequestURI()).thenReturn("self_profile.htm"); + Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("test"); + Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); + Mockito.when(AppUtils.getLookupList("FN_LU_STATE", "STATE_CD", "STATE", null, "STATE_CD")).thenReturn(new ArrayList<>()); + Mockito.when(userService.getUser(String.valueOf(profileId))).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.getUser(mockedRequest, mockedResponse); + } + + @Test + public void getUserExceptionTest(){ + profileController.getUser(mockedRequest, mockedResponse); + } + + /*@Test + public void saveProfileTest() throws IOException{ + String json = "{\"role\":{\"id\":1,\"created\":null,\"modified\":null,\"createdId\":null,\"modifiedId\":null,\"rowNum\":null,\"auditUserId\":null,\"auditTrail\":null,\"name\":\"test1\",\"active\":false,\"priority\":\"1\",\"roleFunctions\":[],\"childRoles\":[],\"editUrl\":\"/role.htm?role_id=1\",\"toggleActiveImage\":\"/static/fusion/images/inactive.png\",\"toggleActiveAltText\":\"Click to Activate Role\"},\"childRoles\":[],\"roleFunctions\":[]}"; + Mockito.when(mockedRequest.getReader()).thenReturn(new BufferedReader(new StringReader(json))); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(profileController.saveProfile(mockedRequest, mockedResponse)); + }*/ + + @Test + public void saveProfilePrintWriterExceptionTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + assertNull(profileController.saveProfile(mockedRequest, mockedResponse)); + } + + /*@SuppressWarnings("unchecked") + @Test + public void saveProfileExceptionTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenThrow(IOException.class); + profileController.saveProfile(mockedRequest, mockedResponse); + }*/ + + /*@Test + public void removeRoleTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.removeRole(mockedRequest, mockedResponse); + }*/ + + @Test + public void removeRolePrintWriterExceptionTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.removeRole(mockedRequest, mockedResponse); + } + + /*@SuppressWarnings("unchecked") + @Test + public void removeRoleExceptionTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenThrow(IOException.class); + profileController.removeRole(mockedRequest, mockedResponse); + }*/ + + /*@Test + public void addNewRoleTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.addNewRole(mockedRequest, mockedResponse); + }*/ + + @Test + public void addNewRoleExceptionTest() throws IOException{ + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileController.addNewRole(mockedRequest, mockedResponse); + } + + @Test + public void getViewNameTest(){ + String actualResult = null; + profileController.setViewName(null); + String expectedResult = profileController.getViewName(); + assertEquals(actualResult, expectedResult); + } + + @SuppressWarnings({ "rawtypes", "null", "unchecked" }) + @Test + public void getAvailableRolesTest() throws IOException{ + List actualList = null; + List list = null; + Mockito.when(roleService.getAvailableRoles(null)).thenReturn(list); + List expectedList = profileController.getAvailableRoles(null); + assertEquals(actualList, expectedList); + } +}
\ No newline at end of file diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileSearchControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileSearchControllerTest.java new file mode 100644 index 00000000..c4b6e5a0 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/ProfileSearchControllerTest.java @@ -0,0 +1,171 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.drools.core.command.assertion.AssertEquals; +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.User; +import org.onap.portalsdk.core.restful.client.SharedContextRestClient; +import org.onap.portalsdk.core.service.RoleService; +import org.onap.portalsdk.core.service.UserProfileService; +import org.onap.portalsdk.core.service.UserService; +import org.onap.portalsdk.core.web.support.UserUtils; +import org.springframework.web.servlet.ModelAndView; + +public class ProfileSearchControllerTest { + + @InjectMocks + ProfileSearchController profileSearchController = new ProfileSearchController(); + + @Mock + UserProfileService service; + + @Mock + UserService userService; + + @Mock + RoleService roleService; + + @Mock + private SharedContextRestClient sharedContextRestClient; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + NullPointerException nullPointerException = new NullPointerException(); + + User user = new User(); + + @Mock + UserUtils userUtils = new UserUtils(); + + @Test + public void profileSearchTest(){ + ModelAndView actualModelAndView = new ModelAndView(); + List<User> userList = new ArrayList<User>(); + Mockito.when(service.findAll()).thenReturn(userList); + ModelAndView expectedModelAndView = profileSearchController.profileSearch(mockedRequest); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void profileSearchExceptionTest(){ + ModelAndView actualModelAndView = new ModelAndView(); + List<User> userList = new ArrayList<User>(); + Mockito.when(service.findAll()).thenThrow(nullPointerException); + profileSearchController.profileSearch(mockedRequest); + } + + @Test + public void getUserTest() throws IOException{ + List<User> profileList = null; + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + Mockito.when(service.findAll()).thenReturn(profileList); + profileSearchController.getUser(mockedRequest, mockedResponse); + } + + @Test + public void getUserExceptionTest(){ + List<User> profileList = null; + Mockito.when(service.findAll()).thenReturn(profileList); + profileSearchController.getUser(mockedRequest, mockedResponse); + } + + @Test + public void getUserPaginationTest() throws IOException{ + List<User> profileList = new ArrayList<User>(); + Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1"); + Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1"); + Mockito.when(service.findAll()).thenReturn(profileList); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileSearchController.getUserPagination(mockedRequest, mockedResponse); + } + + @Test + public void getUserPaginationExceptionTest(){ + List<User> profileList = null; + Mockito.when(mockedRequest.getParameter("pageNum")).thenReturn("1"); + Mockito.when(mockedRequest.getParameter("viewPerPage")).thenReturn("1"); + Mockito.when(service.findAll()).thenReturn(profileList); + profileSearchController.getUserPagination(mockedRequest, mockedResponse); + } + + @Test + public void toggleProfileActiveTest() throws IOException{ + User user = new User(); + Mockito.when(mockedRequest.getParameter("profile_id")).thenReturn("1"); + Mockito.when(userService.getUser("1")).thenReturn(user); + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + Mockito.when(mockedResponse.getWriter()).thenReturn(writer); + profileSearchController.toggleProfileActive(mockedRequest, mockedResponse); + } + + @Test + public void toggleProfileActiveExceptionTest() throws IOException{ + profileSearchController.toggleProfileActive(mockedRequest, mockedResponse); + } +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SDKLoginControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SDKLoginControllerTest.java new file mode 100644 index 00000000..045f3823 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/SDKLoginControllerTest.java @@ -0,0 +1,135 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.*; + +import java.io.IOException; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.auth.LoginStrategy; +import org.onap.portalsdk.core.service.LoginService; +import org.onap.portalsdk.core.service.RoleService; +import org.springframework.web.servlet.ModelAndView; + +public class SDKLoginControllerTest { + + @InjectMocks + SDKLoginController sdkLoginController = new SDKLoginController(); + + @Mock + RoleService roleService; + + @Mock + LoginService loginService; + + @Mock + LoginStrategy loginStrategy; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + + @Test + public void loginTest(){ + ModelAndView actualModelAndView = new ModelAndView("login"); + ModelAndView expectedModelAndView = sdkLoginController.login(); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void externalLogon(){ + ModelAndView actualModelAndView = new ModelAndView("login_external"); + ModelAndView expectedModelAndView = sdkLoginController.externalLogin(); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void doexternalLoginTest() throws IOException{ + ModelAndView actualModelAndView = new ModelAndView(); + Mockito.when(loginStrategy.doExternalLogin(mockedRequest, mockedResponse)).thenReturn(actualModelAndView); + ModelAndView expectedModelAndView = sdkLoginController.doexternalLogin(mockedRequest, mockedResponse); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void doLoginTest() throws Exception{ + ModelAndView actualModelAndView = new ModelAndView(); + Mockito.when(loginStrategy.doLogin(mockedRequest, mockedResponse)).thenReturn(actualModelAndView); + ModelAndView expectedModelAndView = sdkLoginController.doLogin(mockedRequest, mockedResponse); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } + + @Test + public void getJessionIdTest(){ + String expectedResult = null; + String actualResult = sdkLoginController.getJessionId(mockedRequest); + assertEquals(expectedResult, actualResult); + } + + @Test + public void getViewNameTest(){ + String actualResult ="test"; + sdkLoginController.setViewName("test"); + String expectedResult = sdkLoginController.getViewName(); + assertEquals(expectedResult, actualResult); + } + + @Test + public void getLoginServiceTest(){ + sdkLoginController.setLoginService(loginService); + LoginService expectedResult = sdkLoginController.getLoginService(); + assertEquals(expectedResult.getClass(), sdkLoginController.getLoginService().getClass()); + } + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UsageListControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UsageListControllerTest.java new file mode 100644 index 00000000..98a23e8f --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UsageListControllerTest.java @@ -0,0 +1,69 @@ +/* + * ============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.portalapp.controller.core; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.service.ProfileService; + +public class UsageListControllerTest { + + @InjectMocks + UsageListController usageListController = new UsageListController(); + + @Mock + ProfileService service; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + +} diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UserProfileControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UserProfileControllerTest.java new file mode 100644 index 00000000..8d0a5a91 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/UserProfileControllerTest.java @@ -0,0 +1,88 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.onap.portalsdk.core.domain.Profile; +import org.onap.portalsdk.core.service.ProfileService; +import org.springframework.web.servlet.ModelAndView; + +public class UserProfileControllerTest { + + @InjectMocks + UserProfileController userProfileController = new UserProfileController(); + + @Mock + ProfileService service; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void userProfileTest() throws IOException{ + ModelAndView actualModelAndView = new ModelAndView("user_profile"); + List<Profile> profileList = new ArrayList<Profile>(); + Mockito.when(service.findAll()).thenReturn(profileList); + ModelAndView expectedModelAndView = userProfileController.userProfile(); + assertEquals(actualModelAndView.getViewName(), expectedModelAndView.getViewName()); + } +} + diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/WelcomeControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/WelcomeControllerTest.java new file mode 100644 index 00000000..4c49e3d2 --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/WelcomeControllerTest.java @@ -0,0 +1,74 @@ +/* + * ============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.portalapp.controller.core; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.MockitoAnnotations; +import org.onap.portalapp.framework.MockitoTestSuite; +import org.springframework.web.servlet.ModelAndView; + +public class WelcomeControllerTest { + + @InjectMocks + WelcomeController welcomeController = new WelcomeController(); + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + + MockitoTestSuite mockitoTestSuite = new MockitoTestSuite(); + + HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest(); + HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse(); + NullPointerException nullPointerException = new NullPointerException(); + + @Test + public void welcomeTest(){ + ModelAndView expectedResult = null; + expectedResult = welcomeController.welcome(); + assertNull(expectedResult.getViewName()); + } +} |