summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java63
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java21
2 files changed, 49 insertions, 35 deletions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java
index fc926eb8..4de10d9f 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java
@@ -78,6 +78,12 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
private ExternalAccessRolesService externalAccessRolesService;
@Autowired
private DataAccessService dataAccessService;
+
+ public final String appHome = "applicationsHome";
+ public final String appCatalog = "appCatalog";
+ public final String widCatalog = "widgetCatalog";
+ public final String users = "users";
+
/*
* (non-Javadoc)
@@ -176,7 +182,7 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
for (JSONObject navItemsDetail : jsonObjs)
navItems.put(navItemsDetail);
- sidebarModel.put("label", "ECOMP portal");
+ sidebarModel.put("label", "Portal");
sidebarModel.put("navItems", navItems);
return sidebarModel.toString();
}
@@ -188,38 +194,27 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
*/
private void loadDefaultNavMap(Map<String, JSONObject> defaultNavMap) {
String leftMenuRootValue = getLeftMenuPrefixValue();
+
JSONObject navItemsDetails1 = new JSONObject();
navItemsDetails1.put("name", "Home");
- navItemsDetails1.put("state",
- (isLeftMenuHasRoot(leftMenuRootValue))
- ? leftMenuRootValue+".applicationsHome"
- : "applicationsHome");
- navItemsDetails1.put("imageSrc", isLeftMenuHasRoot(leftMenuRootValue) ? "icon-building-home" : "home");
- defaultNavMap.put("applicationsHome", navItemsDetails1);
+ navItemsDetails1.put("state",leftMenuRootValue+appHome);
+ navItemsDetails1.put("imageSrc", "home");
+ defaultNavMap.put(appHome, navItemsDetails1);
JSONObject navItemsDetails2 = new JSONObject();
navItemsDetails2.put("name", "Application Catalog");
- navItemsDetails2.put("state",
- (isLeftMenuHasRoot(leftMenuRootValue))
- ? leftMenuRootValue+".appCatalog"
- : "appCatalog");
- navItemsDetails2.put("imageSrc", isLeftMenuHasRoot(leftMenuRootValue) ? "icon-apps-marketplace" : "apps");
- defaultNavMap.put("appCatalog", navItemsDetails2);
+ navItemsDetails2.put("state",leftMenuRootValue+appCatalog);
+ navItemsDetails2.put("imageSrc", "apps");
+ defaultNavMap.put(appCatalog, navItemsDetails2);
JSONObject navItemsDetails3 = new JSONObject();
navItemsDetails3.put("name", "Widget Catalog");
- navItemsDetails3.put("state",
- isLeftMenuHasRoot(leftMenuRootValue)
- ? leftMenuRootValue+".widgetCatalog"
- : "widgetCatalog");
- navItemsDetails3.put("imageSrc", isLeftMenuHasRoot(leftMenuRootValue) ? "icon-apps-marketplace" : "apps");
- defaultNavMap.put("widgetCatalog", navItemsDetails3);
+ navItemsDetails3.put("state",leftMenuRootValue+widCatalog);
+ navItemsDetails3.put("imageSrc", "apps");
+ defaultNavMap.put(widCatalog, navItemsDetails3);
}
- private boolean isLeftMenuHasRoot(String leftMenuRootValue) {
- return (leftMenuRootValue != "" || leftMenuRootValue.isEmpty()) && leftMenuRootValue.equals("root");
- }
@SuppressWarnings("unchecked")
private void loadNavMapByUserAdminRole(Map<String, JSONObject> defaultNavMap, EPUser user) {
@@ -231,16 +226,26 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
if (applicationsList.size() > 0) {
JSONObject navItemsDetails = new JSONObject();
navItemsDetails.put("name", "Users");
- navItemsDetails.put("state",
- ((leftMenuRootValue != "" || !leftMenuRootValue.isEmpty()) && leftMenuRootValue.equals("root")) ? leftMenuRootValue+".users"
- : "users");
- navItemsDetails.put("imageSrc", isLeftMenuHasRoot(leftMenuRootValue) ? "person" : "icon-user");
- defaultNavMap.put("users", navItemsDetails);
+ navItemsDetails.put("state",leftMenuRootValue+users);
+ navItemsDetails.put("imageSrc", "person");
+ defaultNavMap.put(users, navItemsDetails);
+ }
+ }
+
+ protected String getLeftMenuPrefixValue() {
+ String leftMenuRootValue = getLeftMenuValue();
+ if (leftMenuRootValue != null) {
+ leftMenuRootValue += ".";
+ } else {
+ leftMenuRootValue = "";
}
+
+ return leftMenuRootValue;
+
}
- private String getLeftMenuPrefixValue() {
- return EPCommonSystemProperties.getProperty(EPCommonSystemProperties.PORTAL_LEFT_MENU);
+ String getLeftMenuValue() {
+ return EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.PORTAL_LEFT_MENU) ? EPCommonSystemProperties.getProperty(EPCommonSystemProperties.PORTAL_LEFT_MENU):null;
}
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java
index 9a2568d8..258bf99d 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImplTest.java
@@ -20,7 +20,6 @@
package org.onap.portalapp.portal.service;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -29,6 +28,7 @@ import java.util.Set;
import org.json.JSONArray;
import org.json.JSONObject;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -37,16 +37,18 @@ import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.onap.portalapp.portal.domain.CentralizedApp;
import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.framework.MockitoTestSuite;
import org.onap.portalsdk.core.domain.MenuData;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.service.DataAccessServiceImpl;
-public class EPLeftMenuServiceImplTest {
+public class EPLeftMenuServiceImplTest extends MockitoTestSuite{
@Mock
DataAccessService dataAccessService = new DataAccessServiceImpl();
+
@Mock
- ExternalAccessRolesService externalAccessRolesService;
+ ExternalAccessRolesService externalAccessRolesService;
@Before
public void setup() {
@@ -54,7 +56,12 @@ public class EPLeftMenuServiceImplTest {
}
@InjectMocks
- EPLeftMenuServiceImpl epLeftMenuServiceImpl = new EPLeftMenuServiceImpl();
+ EPLeftMenuServiceImpl epLeftMenuServiceImpl = new EPLeftMenuServiceImpl() {
+
+ String getLeftMenuValue() {
+ return null;
+ }
+ };
@Test
public void getLeftMenuItemsTest() {
@@ -97,13 +104,15 @@ public class EPLeftMenuServiceImplTest {
JSONObject sidebarModel = new JSONObject();
JSONArray navItems = new JSONArray();
- Collection<JSONObject> jsonObjs = defaultNavMap.values();
+
navItems.put(navItemsDetails3);
sidebarModel.put("label", "ECOMP portal");
sidebarModel.put("navItems", navItems);
- epLeftMenuServiceImpl.getLeftMenuItems(epUser, fullMenuSet, roleFunctionSet);
+ String menuStr = epLeftMenuServiceImpl.getLeftMenuItems(epUser, fullMenuSet, roleFunctionSet);
+ Assert.assertTrue(!menuStr.contains("root"));
+ 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);
}
}