2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
38 package org.onap.portalapp.portal.controller;
40 import static org.junit.Assert.*;
42 import java.util.HashMap;
43 import java.util.HashSet;
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49 import javax.servlet.http.HttpSession;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.junit.runner.RunWith;
54 import org.mockito.InjectMocks;
55 import org.mockito.Mock;
56 import org.mockito.Mockito;
57 import org.mockito.MockitoAnnotations;
58 import org.onap.portalapp.controller.EPFusionBaseController;
59 import org.onap.portalapp.portal.core.MockEPUser;
60 import org.onap.portalapp.portal.domain.EPUser;
61 import org.onap.portalapp.portal.framework.MockitoTestSuite;
62 import org.onap.portalapp.portal.service.DashboardSearchService;
63 import org.onap.portalapp.portal.service.DashboardSearchServiceImpl;
64 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
65 import org.onap.portalapp.portal.utils.EcompPortalUtils;
66 import org.onap.portalapp.util.EPUserUtils;
67 import org.onap.portalsdk.core.domain.MenuData;
68 import org.onap.portalsdk.core.util.SystemProperties;
69 import org.powermock.api.mockito.PowerMockito;
70 import org.powermock.core.classloader.annotations.PrepareForTest;
71 import org.powermock.modules.junit4.PowerMockRunner;
73 @RunWith(PowerMockRunner.class)
74 @PrepareForTest({EPUserUtils.class, SystemProperties.class, EPCommonSystemProperties.class, EcompPortalUtils.class})
75 public class EPFusionBaseControllerTest {
78 DashboardSearchService searchService = new DashboardSearchServiceImpl();
81 EPFusionBaseController epFusionBaseController = new EPFusionBaseController() {
87 MockitoAnnotations.initMocks(this);
90 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
92 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
93 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
95 NullPointerException nullPointerException = new NullPointerException();
97 MockEPUser mockUser = new MockEPUser();
100 public void messagesExceptionTest(){
101 Map<String, Object> expectedData = new HashMap<String, Object>();
102 Map<String, Object> actualData = null;
103 PowerMockito.mockStatic(SystemProperties.class);
104 PowerMockito.mockStatic(EPCommonSystemProperties.class);
105 PowerMockito.mockStatic(EcompPortalUtils.class);
106 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)).thenReturn("test");
107 EPUser user = mockUser.mockEPUser();
108 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
109 Set<MenuData> menuResult = null;
110 HttpSession session = mockedRequest.getSession();
112 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult);
113 actualData = epFusionBaseController.messages(mockedRequest);
114 assertEquals(expectedData,actualData );
115 System.out.println();
120 public void messagesTest(){
121 Map<String, Object> expectedData = new HashMap<String, Object>();
122 Map<String, Object> actualData = null;
123 PowerMockito.mockStatic(SystemProperties.class);
124 PowerMockito.mockStatic(EPCommonSystemProperties.class);
125 PowerMockito.mockStatic(EcompPortalUtils.class);
127 Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME)).thenReturn("test");
128 EPUser user = mockUser.mockEPUser();
129 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
130 Set<MenuData> menuResult = new HashSet<>();
131 MenuData menuData= new MenuData();
132 menuResult.add(menuData);
133 menuData.setChildMenus(menuResult);
134 HttpSession session = mockedRequest.getSession();
136 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult);
137 actualData = epFusionBaseController.messages(mockedRequest);
138 assertEquals(actualData.size(), 2);
142 public void isAccessibleTest()
144 assertTrue(epFusionBaseController.isAccessible());
147 public void isRESTfulCallTest()
149 assertTrue(epFusionBaseController.isRESTfulCall());