Fixed health check issue
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / uebhandler / FunctionalMenuHandlerTest.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
39 package org.onap.portalapp.uebhandler;
40
41 import static org.junit.Assert.assertFalse;
42 import static org.junit.Assert.assertTrue;
43
44 import java.io.IOException;
45 import java.util.ArrayList;
46 import java.util.List;
47
48 import javax.servlet.http.HttpServletRequest;
49 import javax.servlet.http.HttpServletResponse;
50
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;
65
66 public class FunctionalMenuHandlerTest {
67
68         @InjectMocks
69         FunctionalMenuHandler functionalMenuHandler = new FunctionalMenuHandler();
70         
71         @Mock
72         private AdminRolesService adminRolesService;
73         
74         @Mock
75         private FunctionalMenuService functionalMenuService;
76
77         @Mock
78         private SearchService searchSvc;
79         
80         @Before
81         public void setup() {
82                 MockitoAnnotations.initMocks(this);
83         }
84         
85         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
86
87         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
88         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
89
90         NullPointerException nullPointerException = new NullPointerException();
91         
92         MockEPUser mockUser = new MockEPUser();
93         
94         //@Ignore
95         @Test
96         public void getFunctionalMenuTest() throws IOException {
97                 
98                 UebMsg uebMsg=new UebMsg();
99                 uebMsg.putMsgId("1");
100                 
101                 uebMsg.putMsgType("testType");
102                 
103                 Boolean actualResponse =        functionalMenuHandler.getFunctionalMenu(null);
104                 
105         assertFalse(actualResponse);
106         uebMsg.putSourceTopicName("test");
107          actualResponse =       functionalMenuHandler.getFunctionalMenu(uebMsg);
108         uebMsg.putUserId("123");
109         
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();
116         menu.setUrl("test");
117         menu.setRestrictedApp(true);
118         menuItems.add(menu);
119         
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);
125         
126         uebMsg.putUserId("245");
127         Mockito.when(searchSvc.searchUserByUserId(uebMsg.getUserId())).thenReturn(null);
128          actualResponse =       functionalMenuHandler.getFunctionalMenu(uebMsg);
129         }       
130         
131 }