Replace ecomp references
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / EPFusionBaseControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
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
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
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
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
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.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38 package org.onap.portalapp.portal.controller;
39
40 import static org.junit.Assert.*;
41
42 import java.util.HashMap;
43 import java.util.HashSet;
44 import java.util.Map;
45 import java.util.Set;
46
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49 import javax.servlet.http.HttpSession;
50
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;
72
73 @RunWith(PowerMockRunner.class)
74 @PrepareForTest({EPUserUtils.class, SystemProperties.class, EPCommonSystemProperties.class, EcompPortalUtils.class})
75 public class EPFusionBaseControllerTest {
76
77         @Mock
78         DashboardSearchService searchService = new DashboardSearchServiceImpl();
79         
80         @InjectMocks
81         EPFusionBaseController epFusionBaseController = new EPFusionBaseController() {
82         };
83
84
85         @Before
86         public void setup() {
87                 MockitoAnnotations.initMocks(this);
88         }
89
90         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
91
92         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
93         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
94
95         NullPointerException nullPointerException = new NullPointerException();
96         
97         MockEPUser mockUser = new MockEPUser();
98         
99         @Test
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();
111                 Mockito.when(session
112                                 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult);
113                 actualData = epFusionBaseController.messages(mockedRequest);
114                 assertEquals(expectedData,actualData );
115                 System.out.println();
116                 
117         }
118         
119         @Test
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);
126
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();
135                 Mockito.when(session
136                                 .getAttribute(SystemProperties.getProperty(SystemProperties.APPLICATION_MENU_ATTRIBUTE_NAME))).thenReturn(menuResult);
137                 actualData = epFusionBaseController.messages(mockedRequest);
138                 assertEquals(actualData.size(), 2);
139         }
140         
141         @Test
142         public void isAccessibleTest()
143         {
144                 assertTrue(epFusionBaseController.isAccessible());
145         }
146         @Test
147         public void isRESTfulCallTest()
148         {
149                 assertTrue(epFusionBaseController.isRESTfulCall());
150         }
151 }