9a2568d86affa7d18012fc8b520c380c24c56609
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / EPLeftMenuServiceImplTest.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP  PORTAL
4 * ================================================================================
5 * Copyright 2018 TechMahindra
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *     http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20 package org.onap.portalapp.portal.service;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.HashSet;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.Set;
29
30 import org.json.JSONArray;
31 import org.json.JSONObject;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.mockito.InjectMocks;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.mockito.MockitoAnnotations;
38 import org.onap.portalapp.portal.domain.CentralizedApp;
39 import org.onap.portalapp.portal.domain.EPUser;
40 import org.onap.portalsdk.core.domain.MenuData;
41 import org.onap.portalsdk.core.service.DataAccessService;
42 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
43
44 public class EPLeftMenuServiceImplTest {
45
46         @Mock
47         DataAccessService dataAccessService = new DataAccessServiceImpl();
48         @Mock
49          ExternalAccessRolesService externalAccessRolesService;
50         
51         @Before
52         public void setup() {
53                 MockitoAnnotations.initMocks(this);
54         }
55         
56         @InjectMocks
57         EPLeftMenuServiceImpl epLeftMenuServiceImpl = new EPLeftMenuServiceImpl();
58         
59         @Test
60         public void getLeftMenuItemsTest() {
61                 Map<String, JSONObject> defaultNavMap = new LinkedHashMap<String, JSONObject>();
62                 Set<MenuData> fullMenuSet = new HashSet<>();
63                 Set<String> roleFunctionSet = new HashSet<>();
64                 defaultNavMap.clear();
65                 JSONObject navItemsDetails1 = new JSONObject();
66                 navItemsDetails1.put("name", "test");
67                 navItemsDetails1.put("state", "demo");
68                 navItemsDetails1.put("imageSrc", "img");
69                 defaultNavMap.put("root.applicationsHome", navItemsDetails1);
70
71                 JSONObject navItemsDetails2 = new JSONObject();
72                 navItemsDetails2.put("name", "test1");
73                 navItemsDetails2.put("state", "demo1");
74                 navItemsDetails2.put("imageSrc", "img1");
75                 defaultNavMap.put("root.appCatalog", navItemsDetails2);
76
77                 JSONObject navItemsDetails3 = new JSONObject();
78                 navItemsDetails3.put("name", "test2");
79                 navItemsDetails3.put("state", "demo2");
80                 navItemsDetails3.put("imageSrc", "img2");
81                 defaultNavMap.put("root.widgetCatalog", navItemsDetails3);
82                 
83                 List<CentralizedApp> applicationsList = new ArrayList<>();
84                 EPUser epUser = new EPUser();
85                 epUser.setOrgUserId("userId");
86                 Mockito.when((List<CentralizedApp>)externalAccessRolesService.getCentralizedAppsOfUser("userId")).thenReturn(applicationsList);
87                 
88                 MenuData data = new MenuData();
89                 data.setLabel("labelTest");
90                 data.setImageSrc("imgTest");
91                 data.setAction("actionTest");
92                 JSONObject navItemsDetails = new JSONObject();
93                 navItemsDetails.put("name", "labelTest");
94                 navItemsDetails.put("state", "actionTest");
95                 navItemsDetails.put("imageSrc", "imgTest");
96                 defaultNavMap.put("actionTest", navItemsDetails);
97                 
98                 JSONObject sidebarModel = new JSONObject();
99                 JSONArray navItems = new JSONArray();
100                 Collection<JSONObject> jsonObjs = defaultNavMap.values();
101                 navItems.put(navItemsDetails3);
102                 sidebarModel.put("label", "ECOMP portal");
103                 sidebarModel.put("navItems", navItems);
104                 
105                 epLeftMenuServiceImpl.getLeftMenuItems(epUser, fullMenuSet, roleFunctionSet);
106                 
107                 
108         }
109 }