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============================================
39 package org.onap.portalapp.uebhandler;
41 import static org.junit.Assert.assertFalse;
42 import static org.junit.Assert.assertTrue;
44 import java.io.IOException;
45 import java.util.ArrayList;
46 import java.util.List;
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
51 import org.junit.Before;
52 import org.junit.Test;
53 import org.mockito.InjectMocks;
54 import org.mockito.Mock;
55 import org.mockito.Mockito;
56 import org.mockito.MockitoAnnotations;
57 import org.onap.portalapp.portal.core.MockEPUser;
58 import org.onap.portalapp.portal.domain.EPUser;
59 import org.onap.portalapp.portal.framework.MockitoTestSuite;
60 import org.onap.portalapp.portal.service.AdminRolesService;
61 import org.onap.portalapp.portal.service.FunctionalMenuService;
62 import org.onap.portalapp.portal.service.SearchService;
63 import org.onap.portalapp.portal.transport.FunctionalMenuItem;
64 import org.onap.portalsdk.core.onboarding.ueb.UebMsg;
66 public class FunctionalMenuHandlerTest {
69 FunctionalMenuHandler functionalMenuHandler = new FunctionalMenuHandler();
72 private AdminRolesService adminRolesService;
75 private FunctionalMenuService functionalMenuService;
78 private SearchService searchSvc;
82 MockitoAnnotations.initMocks(this);
85 MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
87 HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
88 HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
90 NullPointerException nullPointerException = new NullPointerException();
92 MockEPUser mockUser = new MockEPUser();
96 public void getFunctionalMenuTest() throws IOException {
98 UebMsg uebMsg=new UebMsg();
101 uebMsg.putMsgType("testType");
103 Boolean actualResponse = functionalMenuHandler.getFunctionalMenu(null);
105 assertFalse(actualResponse);
106 uebMsg.putSourceTopicName("test");
107 actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);
108 uebMsg.putUserId("123");
110 EPUser user = new EPUser();
111 user.setOrgUserId("123");
112 user.setFirstName("TestFirstName");
113 user.setLastName("TestLastName");
114 List<FunctionalMenuItem> menuItems=new ArrayList<>();
115 FunctionalMenuItem menu=new FunctionalMenuItem();
117 menu.setRestrictedApp(true);
120 Mockito.when(searchSvc.searchUserByUserId(uebMsg.getUserId())).thenReturn(user);
121 Mockito.when(functionalMenuService.getFunctionalMenuItems()).thenReturn(menuItems);
122 Mockito.when(adminRolesService.isSuperAdmin(user)).thenReturn(true);
123 actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);
124 assertTrue(actualResponse);
126 uebMsg.putUserId("245");
127 Mockito.when(searchSvc.searchUserByUserId(uebMsg.getUserId())).thenReturn(null);
128 actualResponse = functionalMenuHandler.getFunctionalMenu(uebMsg);