2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 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============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalapp.controller.core;
41 import java.io.IOException;
42 import java.io.PrintWriter;
43 import java.io.StringWriter;
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
48 import org.junit.Before;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.mockito.InjectMocks;
52 import org.mockito.Matchers;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalapp.framework.MockitoTestSuite;
57 import org.onap.portalsdk.core.domain.App;
58 import org.onap.portalsdk.core.domain.User;
59 import org.onap.portalsdk.core.onboarding.ueb.UebException;
60 import org.onap.portalsdk.core.onboarding.ueb.UebManager;
61 import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
62 import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
63 import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
64 import org.onap.portalsdk.core.service.AppService;
65 import org.onap.portalsdk.core.web.support.UserUtils;
66 import org.powermock.api.mockito.PowerMockito;
67 import org.powermock.core.classloader.annotations.PrepareForTest;
68 import org.powermock.modules.junit4.PowerMockRunner;
70 import com.fasterxml.jackson.databind.ObjectMapper;
72 @RunWith(PowerMockRunner.class)
73 @PrepareForTest({UebManager.class, PortalApiProperties.class, PortalApiConstants.class})
74 public class FuncMenuControllerTest {
77 FuncMenuController funcMenuController = new FuncMenuController();
80 AppService appService;
83 UebManager uebManager;
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 User user = new User();
100 UserUtils userUtils = new UserUtils();
103 ObjectMapper mapper = new ObjectMapper();
106 public void functionalMenuUserExistsTest() throws IOException, UebException{
107 User user = new User();
108 user.setOrgUserId("test12");
109 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
110 StringWriter sw = new StringWriter();
111 PrintWriter writer = new PrintWriter(sw);
112 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
113 PowerMockito.mockStatic(UebManager.class);
115 Mockito.when(UebManager.getInstance()).thenReturn(uebManager);
116 Mockito.when(uebManager.requestReply(Matchers.anyObject())).thenReturn(new UebMsg());
117 funcMenuController.functionalMenu(mockedRequest, mockedResponse);
121 public void functionalMenuUserNotExistsTest() throws IOException, UebException{
122 StringWriter sw = new StringWriter();
123 PrintWriter writer = new PrintWriter(sw);
124 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
126 funcMenuController.functionalMenu(mockedRequest, mockedResponse);
130 public void functionalMenuViaRestTest() throws IOException, UebException{
131 User user = new User();
132 user.setOrgUserId("test12");
133 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
134 StringWriter sw = new StringWriter();
135 PrintWriter writer = new PrintWriter(sw);
136 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
137 PowerMockito.mockStatic(UebManager.class);
138 PowerMockito.mockStatic(PortalApiProperties.class);
139 PowerMockito.mockStatic(PortalApiConstants.class);
140 Mockito.when(PortalApiProperties
141 .getProperty(PortalApiConstants.USE_REST_FOR_FUNCTIONAL_MENU)).thenReturn("test");
142 Mockito.when(UebManager.getInstance()).thenReturn(uebManager);
143 funcMenuController.functionalMenu(mockedRequest, mockedResponse);
147 public void functionalMenuViaRestAppNullTest() throws IOException, UebException{
149 User user = new User();
150 user.setOrgUserId("test12");
151 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
152 StringWriter sw = new StringWriter();
153 PrintWriter writer = new PrintWriter(sw);
154 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
155 Mockito.when(appService.getDefaultApp()).thenReturn(app);
156 PowerMockito.mockStatic(UebManager.class);
157 PowerMockito.mockStatic(PortalApiProperties.class);
158 PowerMockito.mockStatic(PortalApiConstants.class);
159 Mockito.when(PortalApiProperties
160 .getProperty(PortalApiConstants.USE_REST_FOR_FUNCTIONAL_MENU)).thenReturn("test");
161 Mockito.when(UebManager.getInstance()).thenReturn(uebManager);
162 funcMenuController.functionalMenu(mockedRequest, mockedResponse);
166 public void functionalMenuExceptionTest() throws IOException{
167 User user = new User();
168 user.setOrgUserId("test12");
169 Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user);
170 StringWriter sw = new StringWriter();
171 PrintWriter writer = new PrintWriter(sw);
172 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
173 funcMenuController.functionalMenu(mockedRequest, mockedResponse);