diff options
author | 2018-02-07 17:12:02 -0500 | |
---|---|---|
committer | 2018-02-07 17:12:02 -0500 | |
commit | 558eb8fc1392428dbabc4d6016713bff99d6425f (patch) | |
tree | 7ff7952210e824aaf4697e6792527debc125c7a5 /ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core | |
parent | 0127650b2fd9b2846aabf8f955bb7e2cfb983f22 (diff) |
Added Junits
Issue-ID: PORTAL-136, PORTAL-188
Includes FW mode central changes
Change-Id: Iba6c0d48ed768e32d1fe4700d0044eb7f3fdc482
Signed-off-by: Hima Elisetty <hbindu@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core')
11 files changed, 1743 insertions, 0 deletions
diff --git a/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/AngularAdminControllerTest.java b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/AngularAdminControllerTest.java new file mode 100644 index 00000000..2ae922aa --- /dev/null +++ b/ecomp-sdk/epsdk-app-common/src/test/java/org/onap/portalapp/controller/core/AngularAdminControllerTest.java @@ -0,0 +1,94 @@ +/* + * ============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.util.HashMap; +import java.util.Map; + +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.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; +import org.springframework.web.servlet.ModelAndView; + +public class AngularAdminControllerTest { + + @InjectMocks + AngularAdminController angularAdminController = new AngularAdminController(); + + @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 viewTest() { + ModelAndView modelandView = new ModelAndView("user_profile_list"); + ModelAndView expectedModelandView = angularAdminController.view(); + assertEquals(expectedModelandView.getViewName(), modelandView.getViewName()); + } + + @Test + public void adminViewTest() { + ModelAndView expectedModelandView = angularAdminController.adminView(); + assertNull(expectedModelandView.getViewName()); + } +} + 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()); + } +} |