2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.portalapp.portal.service;
22 import java.util.ArrayList;
23 import java.util.HashSet;
24 import java.util.LinkedHashMap;
25 import java.util.List;
29 import org.json.JSONArray;
30 import org.json.JSONObject;
31 import org.junit.Assert;
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.portalapp.portal.framework.MockitoTestSuite;
41 import org.onap.portalsdk.core.domain.MenuData;
42 import org.onap.portalsdk.core.service.DataAccessService;
43 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
45 public class EPLeftMenuServiceImplTest extends MockitoTestSuite{
48 DataAccessService dataAccessService = new DataAccessServiceImpl();
51 ExternalAccessRolesService externalAccessRolesService;
55 MockitoAnnotations.initMocks(this);
59 EPLeftMenuServiceImpl epLeftMenuServiceImpl = new EPLeftMenuServiceImpl() {
61 String getLeftMenuValue() {
67 public void getLeftMenuItemsTest() {
68 Map<String, JSONObject> defaultNavMap = new LinkedHashMap<String, JSONObject>();
69 Set<MenuData> fullMenuSet = new HashSet<>();
70 Set<String> roleFunctionSet = new HashSet<>();
71 defaultNavMap.clear();
72 JSONObject navItemsDetails1 = new JSONObject();
73 navItemsDetails1.put("name", "test");
74 navItemsDetails1.put("state", "demo");
75 navItemsDetails1.put("imageSrc", "img");
76 defaultNavMap.put("root.applicationsHome", navItemsDetails1);
78 JSONObject navItemsDetails2 = new JSONObject();
79 navItemsDetails2.put("name", "test1");
80 navItemsDetails2.put("state", "demo1");
81 navItemsDetails2.put("imageSrc", "img1");
82 defaultNavMap.put("root.appCatalog", navItemsDetails2);
84 JSONObject navItemsDetails3 = new JSONObject();
85 navItemsDetails3.put("name", "test2");
86 navItemsDetails3.put("state", "demo2");
87 navItemsDetails3.put("imageSrc", "img2");
88 defaultNavMap.put("root.widgetCatalog", navItemsDetails3);
90 List<CentralizedApp> applicationsList = new ArrayList<>();
91 EPUser epUser = new EPUser();
92 epUser.setOrgUserId("userId");
93 Mockito.when((List<CentralizedApp>)externalAccessRolesService.getCentralizedAppsOfUser("userId")).thenReturn(applicationsList);
95 MenuData data = new MenuData();
96 data.setLabel("labelTest");
97 data.setImageSrc("imgTest");
98 data.setAction("actionTest");
99 JSONObject navItemsDetails = new JSONObject();
100 navItemsDetails.put("name", "labelTest");
101 navItemsDetails.put("state", "actionTest");
102 navItemsDetails.put("imageSrc", "imgTest");
103 defaultNavMap.put("actionTest", navItemsDetails);
105 JSONObject sidebarModel = new JSONObject();
106 JSONArray navItems = new JSONArray();
108 navItems.put(navItemsDetails3);
109 sidebarModel.put("label", "ECOMP portal");
110 sidebarModel.put("navItems", navItems);
113 String menuStr = epLeftMenuServiceImpl.getLeftMenuItems(epUser, fullMenuSet, roleFunctionSet);
114 Assert.assertTrue(!menuStr.contains("root"));
115 Assert.assertEquals("{\"navItems\":[{\"name\":\"Home\",\"imageSrc\":\"home\",\"state\":\"applicationsHome\"},{\"name\":\"Application Catalog\",\"imageSrc\":\"apps\",\"state\":\"appCatalog\"},{\"name\":\"Widget Catalog\",\"imageSrc\":\"apps\",\"state\":\"widgetCatalog\"}],\"label\":\"Portal\"}", menuStr);