summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-BE-common
diff options
context:
space:
mode:
authorkg811t <kg811t@research.att.com>2018-02-08 13:25:08 -0500
committerkg811t <kg811t@research.att.com>2018-02-08 13:25:08 -0500
commit3aa28e9dd68cce134644223505f326378b5d91a8 (patch)
tree863c98fb341cb86c919b9888dded51c98562a62c /ecomp-portal-BE-common
parent08f55be6a0a9708ceeb176d5e1a0a56f885fad59 (diff)
Added Junits
Issue-ID: PORTAL-136, PORTAL-133, PORTAL-111, PORTAL-19 Includes JUNITS, replacement of openecomp to onap, role centralization changes Change-Id: I95fe9d93ccf22e04f81f52aa7ae8c2b760d8c9c4 Signed-off-by: kg811t <kg811t@research.att.com>
Diffstat (limited to 'ecomp-portal-BE-common')
-rw-r--r--ecomp-portal-BE-common/pom.xml14
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java3
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java62
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/SchedulerAuxController.java5
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreference.java6
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreference.java6
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalSystemAccess.java31
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppID.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/SyncUserRolesException.java48
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPErrorCodesEnum.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java3
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppContactUsServiceImpl.java4
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java18
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImpl.java22
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java23
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAuditServiceImpl.java4
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLeftMenuServiceImpl.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLoginServiceImpl.java29
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java3
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java22
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/GetAccessServiceImpl.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ManifestServiceImpl.java2
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PersUserAppServiceImpl.java18
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/SharedContextServiceImpl.java18
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserNotificationServiceImpl.java20
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java52
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EventWidget.java4
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidator.java31
-rw-r--r--ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/CustomLoggingFilter.java2
-rw-r--r--ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml18
-rw-r--r--ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java6
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java2
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java14
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java4
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java30
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java815
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java1060
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java92
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserNotificationServiceImplTest.java209
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java1466
-rw-r--r--ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetParameterServiceImplTest.java129
48 files changed, 3995 insertions, 332 deletions
diff --git a/ecomp-portal-BE-common/pom.xml b/ecomp-portal-BE-common/pom.xml
index d7917795..a728433a 100644
--- a/ecomp-portal-BE-common/pom.xml
+++ b/ecomp-portal-BE-common/pom.xml
@@ -475,6 +475,12 @@
<groupId>org.onap.portal.sdk</groupId>
<artifactId>epsdk-app-common</artifactId>
<version>${epsdk.version}</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.onap.portal.sdk</groupId>
@@ -584,6 +590,12 @@
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.1.0.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>commons-beanutils</groupId>
+ <artifactId>commons-beanutils-core</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
@@ -602,5 +614,7 @@
</dependency>
</dependencies>
+
+
</project>
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
index d8e8aeb0..4b364995 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/DashboardController.java
@@ -171,8 +171,7 @@ public class DashboardController extends EPRestrictedBaseController {
* @return Rest response wrapped around a String; e.g., "success" or "ERROR"
*/
@RequestMapping(value = "/widgetData", method = RequestMethod.POST, produces = "application/json")
- public PortalRestResponse<String> saveWidgetData(@RequestBody CommonWidget commonWidget, HttpServletRequest request,
- HttpServletResponse response) {
+ public PortalRestResponse<String> saveWidgetData(@RequestBody CommonWidget commonWidget, HttpServletRequest request, HttpServletResponse response) {
logger.debug(EELFLoggerDelegate.debugLogger, "saveWidgetData: argument is {}", commonWidget);
EPUser user = EPUserUtils.getUserSession(request);
if (adminRolesService.isSuperAdmin(user)) {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
index 0be015ee..ff254e85 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/ExternalAccessRolesController.java
@@ -39,6 +39,7 @@ package org.onap.portalapp.portal.controller;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -69,10 +70,15 @@ import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalsdk.core.domain.AuditLog;
import org.onap.portalsdk.core.domain.Role;
import org.onap.portalsdk.core.domain.RoleFunction;
+import org.onap.portalsdk.core.domain.User;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.restful.domain.EcompRole;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.onap.portalsdk.core.service.AuditService;
+import org.onap.portalsdk.core.service.UserService;
+import org.onap.portalsdk.core.service.UserServiceCentalizedImpl;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
import org.slf4j.MDC;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -87,6 +93,7 @@ import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.type.TypeFactory;
import io.swagger.annotations.ApiOperation;
@@ -117,6 +124,9 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
@Autowired
private ExternalAccessRolesService externalAccessRolesService;
+ @Autowired
+ private UserService userservice = new UserServiceCentalizedImpl();
+
@ApiOperation(value = "Gets user role for an application.", response = CentralUser.class, responseContainer="List")
@RequestMapping(value = {
"/user/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
@@ -804,4 +814,56 @@ public class ExternalAccessRolesController implements BasicAuthenticationControl
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
}
+
+ @ApiOperation(value = "Gets ecompUser of an application.", response = CentralUser.class, responseContainer = "List")
+ @RequestMapping(value = { "/ecompUser/{loginId}" }, method = RequestMethod.GET, produces = "application/json")
+ public String getEcompUser(HttpServletRequest request, HttpServletResponse response,
+ @PathVariable("loginId") String loginId) throws Exception {
+ EcompUser user = new EcompUser();
+ ObjectMapper mapper = new ObjectMapper();
+ CentralUser answer = null;
+ try {
+ fieldsValidation(request);
+ answer = externalAccessRolesService.getUserRoles(loginId, request.getHeader(UEBKEY));
+ if (answer != null) {
+ String res = mapper.writeValueAsString(answer);
+ User ecompUser = userservice.userMapper(res);
+ user = UserUtils.convertToEcompUser(ecompUser);
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getEcompUser failed", e);
+ throw e;
+ }
+ return mapper.writeValueAsString(user);
+ }
+
+ @ApiOperation(value = "Gets user ecomp role for an application.", response = CentralUser.class, responseContainer = "List")
+ @RequestMapping(value = { "/ecompRoles" }, method = RequestMethod.GET, produces = "application/json")
+ public List<EcompRole> getEcompRolesOfApplication(HttpServletRequest request, HttpServletResponse response)
+ throws Exception {
+ List<EcompRole> ecompRoles = new ArrayList<EcompRole>();
+ ObjectMapper mapper = new ObjectMapper();
+ List<CentralV2Role> cenRole = null;
+ try {
+ fieldsValidation(request);
+ EPApp app = externalAccessRolesService.getApp(request.getHeader(UEBKEY)).get(0);
+ // Sync all roles from external system into Ecomp portal DB
+ logger.debug(EELFLoggerDelegate.debugLogger, "getRolesForApp: Entering into syncApplicationRolesWithEcompDB");
+ externalAccessRolesService.syncApplicationRolesWithEcompDB(app);
+ logger.debug(EELFLoggerDelegate.debugLogger, "getRolesForApp: Finished syncApplicationRolesWithEcompDB");
+ cenRole = externalAccessRolesService.getActiveRoles(request.getHeader(UEBKEY));
+ } catch (Exception e) {
+ sendErrorResponse(response, e);
+ logger.error(EELFLoggerDelegate.errorLogger, "getActiveRoles failed", e);
+ }
+ String res = mapper.writeValueAsString(cenRole);
+ if (res != null) {
+ List<Role> roles = mapper.readValue(res,
+ TypeFactory.defaultInstance().constructCollectionType(List.class, Role.class));
+ for (Role role : roles)
+ ecompRoles.add(UserUtils.convertToEcompRole(role));
+ logger.debug(EELFLoggerDelegate.debugLogger, "Request completed for getEcompRolesOfApplication");
+ }
+ return ecompRoles;
+ }
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/SchedulerAuxController.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/SchedulerAuxController.java
index c676fa98..fce1f387 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/SchedulerAuxController.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/controller/SchedulerAuxController.java
@@ -58,11 +58,6 @@ import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
-/*import org.openecomp.vid.policy.PolicyProperties;
-import org.openecomp.vid.policy.PolicyResponseWrapper;
-import org.openecomp.vid.policy.PolicyRestInterfaceFactory;
-import org.openecomp.vid.policy.PolicyRestInterfaceIfc;
-import org.openecomp.vid.policy.PolicyUtil;*/
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreference.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreference.java
index 4d943f62..b597b9d2 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreference.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreference.java
@@ -42,14 +42,14 @@ import org.onap.portalsdk.core.domain.support.DomainVo;
public class EPUserAppsManualSortPreference extends DomainVo {
private static final long serialVersionUID = -6270136291139278216L;
- private int userId;
+ private Long userId;
private Long appId;
private int appManualSortOrder;
- public int getUserId() {
+ public Long getUserId() {
return userId;
}
- public void setUserId(int userId) {
+ public void setUserId(Long userId) {
this.userId = userId;
}
public Long getAppId() {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreference.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreference.java
index 552e2e0f..9c324047 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreference.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreference.java
@@ -42,17 +42,17 @@ import org.onap.portalsdk.core.domain.support.DomainVo;
public class EPWidgetsManualSortPreference extends DomainVo{
private static final long serialVersionUID = 4607102334801223570L;
- private int userId;
+ private Long userId;
private Long widgetId;
private int widgetRow;
private int widgetCol;
private int widgetWidth;
private int widgetHeight;
- public int getUserId() {
+ public Long getUserId() {
return userId;
}
- public void setUserId(int userId) {
+ public void setUserId(Long userId) {
this.userId = userId;
}
public Long getWidgetId() {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalSystemAccess.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalSystemAccess.java
index 29b4fe35..c7d5d207 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalSystemAccess.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/ExternalSystemAccess.java
@@ -61,6 +61,37 @@ public class ExternalSystemAccess {
public void setAccessValue(Boolean accessValue) {
this.accessValue = accessValue;
}
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((accessValue == null) ? 0 : accessValue.hashCode());
+ result = prime * result + ((key == null) ? 0 : key.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExternalSystemAccess other = (ExternalSystemAccess) obj;
+ if (accessValue == null) {
+ if (other.accessValue != null)
+ return false;
+ } else if (!accessValue.equals(other.accessValue))
+ return false;
+ if (key == null) {
+ if (other.key != null)
+ return false;
+ } else if (!key.equals(other.key))
+ return false;
+ return true;
+ }
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppID.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppID.java
index a9455d61..ecb17875 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppID.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/domain/FunctionalMenuItemWithAppID.java
@@ -47,7 +47,7 @@ import javax.persistence.Id;
import javax.persistence.Transient;
/***
*
- * This class is almost identical to org.openecomp.portalapp.portal.transport.FunctionalMenuItem
+ * This class is almost identical to org.onap.portalapp.portal.transport.FunctionalMenuItem
* The only difference is the appId field. In FunctionMenuItem, we used @Transient as an attribute, and we are using @Column in this class.
* In some sql queries, we need to have appId, but it's not a field in fn_menu_functional table.
*
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/SyncUserRolesException.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/SyncUserRolesException.java
new file mode 100644
index 00000000..f7f19a5f
--- /dev/null
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/exceptions/SyncUserRolesException.java
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.portalapp.portal.exceptions;
+
+@SuppressWarnings("serial")
+public class SyncUserRolesException extends Exception{
+
+ public SyncUserRolesException(String msg) {
+ super(msg);
+ }
+
+}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java
index 5d2f399b..8cf20ba8 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/interceptor/PortalResourceInterceptor.java
@@ -245,7 +245,7 @@ public class PortalResourceInterceptor extends ResourceInterceptor {
BasicAuthCredentials creds;
try {
creds = basicAuthService.getBasicAuthCredentialByUsernameAndPassword(accountNamePassword[0],
- encrypted(accountNamePassword[1]));
+ accountNamePassword[1]);
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "checkBasicAuth failed to get credentials", e);
final String msg = "Failed while getting basic authentication credential: ";
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPErrorCodesEnum.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPErrorCodesEnum.java
index e4cd38e7..b505eedd 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPErrorCodesEnum.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/logging/format/EPErrorCodesEnum.java
@@ -116,6 +116,6 @@ public enum EPErrorCodesEnum implements EELFResolvableErrorEnum {
* Here this application loads messages from three bundles
*/
static {
- EELFResourceManager.loadMessageBundle("org/openecomp/portalapp/portal/logging/format/ApplicationCodes");
+ EELFResourceManager.loadMessageBundle("org/onap/portalapp/portal/logging/format/ApplicationCodes");
}
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java
index 53848e02..3caede7e 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduler/client/HttpsBasicClient.java
@@ -80,7 +80,7 @@ public class HttpsBasicClient{
String methodName = "getClient";
ClientConfig config = new ClientConfig();
//config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- //config.getClasses().add(org.openecomp.aai.util.CustomJacksonJaxBJsonProvider.class);
+ //config.getClasses().add(org.onap.aai.util.CustomJacksonJaxBJsonProvider.class);
SSLContext ctx = null;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
index 678073c8..0a935ae4 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/scheduleraux/SchedulerAuxUtil.java
@@ -43,9 +43,6 @@ import java.util.Date;
import org.glassfish.jersey.client.ClientResponse;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-/*import org.openecomp.vid.policy.PolicyResponseWrapper;
-import org.openecomp.vid.policy.PolicyUtil;
-import org.openecomp.vid.policy.RestObject;*/
import com.fasterxml.jackson.databind.ObjectMapper;
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppContactUsServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppContactUsServiceImpl.java
index edffafc3..67e2ae32 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppContactUsServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/AppContactUsServiceImpl.java
@@ -74,7 +74,7 @@ public class AppContactUsServiceImpl implements AppContactUsService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.AppContactUsService#
+ * @see org.onap.portalapp.portal.service.AppContactUsService#
* getAppContactUs()
*/
@SuppressWarnings("unchecked")
@@ -89,7 +89,7 @@ public class AppContactUsServiceImpl implements AppContactUsService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.AppContactUsService#
+ * @see org.onap.portalapp.portal.service.AppContactUsService#
* getAllAppsAndContacts()
*/
@SuppressWarnings("unchecked")
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
index 18717204..1460a61c 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ApplicationsRestClientServiceImpl.java
@@ -53,7 +53,6 @@ import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.cxf.transport.http.HTTPException;
-import org.onap.portalapp.portal.service.AppsCacheService;
import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.logging.aop.EPAuditLog;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
@@ -252,7 +251,7 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.ApplicationsRestClientService#get(
+ * org.onap.portalapp.portal.service.ApplicationsRestClientService#get(
* java.lang.Class, long, java.lang.String, boolean)
*/
@Override
@@ -354,13 +353,15 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
WebClient client = null;
Response response = null;
T t = null;
-
+ logger.debug(EELFLoggerDelegate.debugLogger, "Entering to createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
client = createClientForApp(appId, restPath);
EcompPortalUtils.logAndSerializeObject(logger, restPath, "POST request =", payload);
-
+ logger.debug(EELFLoggerDelegate.debugLogger, "Finished createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
try {
if (client != null) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Entering to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
response = client.post(payload);
+ logger.debug(EELFLoggerDelegate.debugLogger, "Finished to POST for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
} else {
logger.error(EELFLoggerDelegate.errorLogger,
"Unable to create the Webclient to make the '" + restPath + "' API call.");
@@ -396,12 +397,21 @@ public class ApplicationsRestClientServiceImpl implements ApplicationsRestClient
Response response = null;
T t = null;
+ logger.debug(EELFLoggerDelegate.debugLogger, "Entering to createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
+
client = createClientForApp(appId, restPath);
EcompPortalUtils.logAndSerializeObject(logger, restPath, "PUT request =", payload);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, "Finished createClientForApp method for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
try {
if (client != null) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Entering to PUT for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
+
response = client.put(payload);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, "Finished to PUT for payload: {} and restPath: {} and appId: {}", payload.toString(), restPath, appId);
+
} else {
logger.error(EELFLoggerDelegate.errorLogger,
"Unable to create the Webclient to make the '" + restPath + "' API call.");
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImpl.java
index b50eb391..7241059e 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/BasicAuthenticationCredentialServiceImpl.java
@@ -47,7 +47,10 @@ import org.onap.portalapp.portal.domain.EPEndpoint;
import org.onap.portalapp.portal.domain.EPEndpointAccount;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.util.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Service;
@@ -68,20 +71,31 @@ public class BasicAuthenticationCredentialServiceImpl implements BasicAuthentica
List<Criterion> restrictionsList = new ArrayList<Criterion>();
Criterion contextUserNameCrit = Restrictions.eq("username", username);
restrictionsList.add(contextUserNameCrit);
- Criterion contextPasswordCrit = Restrictions.eq("password", password);
- restrictionsList.add(contextPasswordCrit);
@SuppressWarnings("unchecked")
List<BasicAuthCredentials> credList = (List<BasicAuthCredentials>) dataAccessService
.getList(BasicAuthCredentials.class, null, restrictionsList, null);
- if (credList == null || credList.size() == 0) {
+ if (credList ==null || credList.isEmpty()) {
logger.error(EELFLoggerDelegate.errorLogger,
"getBasicAuthCredentialByAppName: no credential(s) for " + username);
return null;
}
logger.debug(EELFLoggerDelegate.debugLogger,
"getBasicAuthCredentialByAppName: cred list size: " + credList.size());
- BasicAuthCredentials cred = (BasicAuthCredentials) credList.get(0);
+ BasicAuthCredentials cred = null;
+ for (BasicAuthCredentials basicAuthCredentials : credList) {
+ try {
+ final String dbDecryptedPwd = CipherUtil.decryptPKC(basicAuthCredentials.getPassword());
+ if (dbDecryptedPwd.equals(password)) {
+ cred= (BasicAuthCredentials) basicAuthCredentials;
+ break;
+ }
+ } catch (CipherUtilException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getBasicAuthCredentialByUsernameAndPassword() failed", e);
+ }
+
+ }
+ if (cred!=null && cred.getId()!=null)
cred.setEndpoints(getEndpointsByAccountId(cred.getId()));
return cred;
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java
index 8c055b2d..b2e9ebc5 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAppCommonServiceImpl.java
@@ -100,7 +100,6 @@ import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
import com.att.nsa.cambria.client.CambriaClientBuilders;
import com.att.nsa.cambria.client.CambriaIdentityManager;
import com.att.nsa.cambria.client.CambriaTopicManager;
-import com.google.common.primitives.Ints;
public class EPAppCommonServiceImpl implements EPAppService {
@@ -515,8 +514,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.EPAppService#getAppCatalog(
- * org.openecomp.portalapp.portal.domain.EPUser)
+ * org.onap.portalapp.portal.service.EPAppService#getAppCatalog(
+ * org.onap.portalapp.portal.domain.EPUser)
*/
@Override
public List<AppCatalogItem> getUserAppCatalog(EPUser user) {
@@ -532,8 +531,8 @@ public class EPAppCommonServiceImpl implements EPAppService {
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.EPAppService#getAdminAppCatalog(
- * org.openecomp.portalapp.portal.domain.EPUser)
+ * org.onap.portalapp.portal.service.EPAppService#getAdminAppCatalog(
+ * org.onap.portalapp.portal.domain.EPUser)
*/
@Override
public List<AppCatalogItem> getAdminAppCatalog(EPUser user) {
@@ -1404,7 +1403,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
epWidgetsManualSort.setWidgetCol(epWidgetsManPref.getCol());
epWidgetsManualSort.setWidgetWidth(epWidgetsManPref.getSizeX());
epWidgetsManualSort.setWidgetHeight(epWidgetsManPref.getSizeY());
- HashMap<String, Integer> additionalUpdateParam = new HashMap<String, Integer>();
+ HashMap<String, Long> additionalUpdateParam = new HashMap<>();
additionalUpdateParam.put("userId", epWidgetsManualSort.getUserId());
dataAccessService.saveDomainObject(epWidgetsManualSort, additionalUpdateParam);
} else {
@@ -1414,7 +1413,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
epWidgetsManualSort.setWidgetCol(epWidgetsManPref.getCol());
epWidgetsManualSort.setWidgetWidth(epWidgetsManPref.getSizeX());
epWidgetsManualSort.setWidgetHeight(epWidgetsManPref.getSizeY());
- epWidgetsManualSort.setUserId(Ints.checkedCast(user.getId()));
+ epWidgetsManualSort.setUserId(user.getId());
dataAccessService.saveDomainObject(epWidgetsManualSort, null);
}
fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_OK);
@@ -1485,7 +1484,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
EPUserAppsManualSortPreference epAppsManualSort = existingAppIds.get(appid);
epAppsManualSort
.setAppManualSortOrder((epAppsManPref.getCol() + (6 * epAppsManPref.getRow())) + 1);
- HashMap<String, Integer> additionalUpdateParam = new HashMap<String, Integer>();
+ HashMap<String, Long> additionalUpdateParam = new HashMap<>();
additionalUpdateParam.put("userId", epAppsManualSort.getUserId());
dataAccessService.saveDomainObject(epAppsManualSort, additionalUpdateParam);
} else {
@@ -1493,7 +1492,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
epAppsManualSort.setAppId(epAppsManPref.getAppid());
epAppsManualSort
.setAppManualSortOrder((epAppsManPref.getCol() + (6 * epAppsManPref.getRow())) + 1);
- epAppsManualSort.setUserId(Ints.checkedCast(user.getId()));
+ epAppsManualSort.setUserId(user.getId());
dataAccessService.saveDomainObject(epAppsManualSort, null);
}
fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_OK);
@@ -1509,9 +1508,9 @@ public class EPAppCommonServiceImpl implements EPAppService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.EPAppService#
+ * @see org.onap.portalapp.portal.service.EPAppService#
* deleteUserAppSortManual(java.lang.String,
- * org.openecomp.portalapp.portal.domain.EPUser)
+ * org.onap.portalapp.portal.domain.EPUser)
*/
@SuppressWarnings("unchecked")
@Override
@@ -1550,7 +1549,7 @@ public class EPAppCommonServiceImpl implements EPAppService {
epSortTypes = dataAccessService.executeNamedQuery("userAppsSortPreferenceQuery", params, null);
if (epSortTypes.size() == 0) {
usrSortPr = new EPUserAppsSortPreference();
- usrSortPr.setUserId(Ints.checkedCast(user.getId()));
+ usrSortPr.setUserId((int)(long)(user.getId()));
usrSortPr.setSortPref(appsSortPreference.getValue());
dataAccessService.saveDomainObject(usrSortPr, null);
fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_OK);
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAuditServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAuditServiceImpl.java
index 1b3dfade..cb94147c 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAuditServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPAuditServiceImpl.java
@@ -73,7 +73,7 @@ public class EPAuditServiceImpl implements EPAuditService {
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.EPUserService#getGuestLastLogin(
+ * org.onap.portalapp.portal.service.EPUserService#getGuestLastLogin(
* java.lang.String)
*/
public Date getGuestLastLogin(String userId) {
@@ -102,7 +102,7 @@ public class EPAuditServiceImpl implements EPAuditService {
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.EPAuditService#delAuditLogFromDay(
+ * org.onap.portalapp.portal.service.EPAuditService#delAuditLogFromDay(
* )
*/
@Override
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 98d31b16..243b7261 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
@@ -75,7 +75,7 @@ public class EPLeftMenuServiceImpl implements EPLeftMenuService {
* (non-Javadoc)
*
* @see
- * org.openecomp.portalapp.portal.service.EPLeftMenuService#getLeftMenuItems
+ * org.onap.portalapp.portal.service.EPLeftMenuService#getLeftMenuItems
* (java.util.Set)
*/
@Override
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLoginServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLoginServiceImpl.java
index eff297f5..1ec71d78 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLoginServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/EPLoginServiceImpl.java
@@ -44,6 +44,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.apache.commons.lang.StringUtils;
import org.onap.portalapp.command.EPLoginBean;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
@@ -52,6 +53,8 @@ import org.onap.portalapp.portal.logging.logic.EPLogUtil;
import org.onap.portalapp.util.EPUserUtils;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.menu.MenuBuilder;
+import org.onap.portalsdk.core.onboarding.exception.CipherUtilException;
+import org.onap.portalsdk.core.onboarding.util.CipherUtil;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.service.support.FusionService;
import org.onap.portalsdk.core.util.SystemProperties;
@@ -74,7 +77,7 @@ public class EPLoginServiceImpl extends FusionService implements EPLoginService
/*
* (non-Javadoc)
- * @see org.openecomp.portalapp.portal.service.EPLoginService#findUser(org.openecomp.portalapp.command.EPLoginBean, java.lang.String, java.util.HashMap)
+ * @see org.onap.portalapp.portal.service.EPLoginService#findUser(org.openecomp.portalapp.command.EPLoginBean, java.lang.String, java.util.HashMap)
*/
@SuppressWarnings("rawtypes")
public EPLoginBean findUser(EPLoginBean bean, String menuPropertiesFilename, HashMap additionalParams)
@@ -84,7 +87,7 @@ public class EPLoginServiceImpl extends FusionService implements EPLoginService
/*
* (non-Javadoc)
- * @see org.openecomp.portalapp.portal.service.EPLoginService#findUser(org.openecomp.portalapp.command.EPLoginBean, java.lang.String, java.util.HashMap, boolean)
+ * @see org.onap.portalapp.portal.service.EPLoginService#findUser(org.onap.portalapp.command.EPLoginBean, java.lang.String, java.util.HashMap, boolean)
*/
@SuppressWarnings("rawtypes")
public EPLoginBean findUser(EPLoginBean bean, String menuPropertiesFilename_ignored, HashMap additionalParams,
@@ -179,19 +182,31 @@ public class EPLoginServiceImpl extends FusionService implements EPLoginService
* @param password
* @return EPUser object; null on error or if no match.
*/
- @SuppressWarnings("rawtypes")
+ @SuppressWarnings({ "rawtypes", "unchecked" })
private EPUser findUser(String loginId, String password) {
Map<String, String> params = new HashMap<>();
params.put("login_id", loginId);
- params.put("login_pwd", password);
- List list = null;
+ List<EPUser> list = null;
try {
- list = dataAccessService.executeNamedQuery("getEPUserByLoginIdLoginPwd", params, new HashMap());
+ list = dataAccessService.executeNamedQuery("getEPUserByLoginId", params, new HashMap());
+ for (EPUser user : list) {
+ try {
+ if (StringUtils.isNotBlank(user.getLoginPwd())) {
+ final String dbDecryptedPwd = CipherUtil.decryptPKC(user.getLoginPwd());
+ if (dbDecryptedPwd.equals(password)) {
+ return user;
+ }
+ }
+ } catch (CipherUtilException e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "findUser() failed", e);
+ }
+ }
+
} catch (Exception e) {
EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
logger.error(EELFLoggerDelegate.errorLogger, "findUser failed on " + loginId, e);
}
- return (list == null || list.isEmpty()) ? null : (EPUser) list.get(0);
+ return null;
}
@SuppressWarnings("rawtypes")
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
index d65f1152..1d198f76 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesService.java
@@ -49,6 +49,7 @@ import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.domain.EPRole;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.domain.ExternalRoleDetails;
+import org.onap.portalapp.portal.exceptions.InvalidUserException;
import org.onap.portalapp.portal.transport.CentralRole;
import org.onap.portalapp.portal.transport.CentralUser;
import org.onap.portalapp.portal.transport.CentralV2Role;
@@ -100,7 +101,7 @@ public interface ExternalAccessRolesService {
* @return EPUser object
* @throws Exception
*/
- List<EPUser> getUser(String loginId) throws Exception;
+ List<EPUser> getUser(String loginId) throws InvalidUserException;
/**
* It returns complete user information including application roles permissions
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
index e867c3d6..af5b5001 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImpl.java
@@ -122,10 +122,8 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestTemplate;
-import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
@@ -1105,10 +1103,14 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
@Override
@SuppressWarnings("unchecked")
- public List<EPUser> getUser(String loginId){
+ public List<EPUser> getUser(String loginId) throws InvalidUserException{
final Map<String, String> userParams = new HashMap<>();
userParams.put("org_user_id", loginId);
- return (List<EPUser>) dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null);
+ List<EPUser> userList = dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null);
+ if (userList.isEmpty()) {
+ throw new InvalidUserException("User not found");
+ }
+ return userList;
}
@Override
@@ -2777,9 +2779,11 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
extRoleParams.put(APP_ID, app.getId().toString());
roleList = dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, extRoleParams, null);
}
- EPRole updateRoleInactive = roleList.get(0);
- updateRoleInactive.setActive(false);
- dataAccessService.saveDomainObject(updateRoleInactive, null);
+ if(!roleList.isEmpty()) {
+ EPRole updateRoleInactive = roleList.get(0);
+ updateRoleInactive.setActive(false);
+ dataAccessService.saveDomainObject(updateRoleInactive, null);
+ }
}
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger,
@@ -2875,8 +2879,8 @@ public class ExternalAccessRolesServiceImpl implements ExternalAccessRolesServic
EPAppRoleFunction checkRoleFunctionExits = roleFunctionsMap.get(externalpermission.getInstance());
if (checkRoleFunctionExits == null) {
String funcCode = externalpermission.getType().substring(app.getNameSpace().length() + 1)
- + FUNCTION_PIPE + externalAccessPerms.getInstance() + FUNCTION_PIPE
- + externalAccessPerms.getAction();
+ + FUNCTION_PIPE + externalpermission.getInstance() + FUNCTION_PIPE
+ + externalpermission.getAction();
EPAppRoleFunction checkRoleFunctionPipeExits = roleFunctionsMap.get(funcCode);
if (checkRoleFunctionPipeExits == null) {
try {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/GetAccessServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/GetAccessServiceImpl.java
index fb0bf7f7..59385554 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/GetAccessServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/GetAccessServiceImpl.java
@@ -62,7 +62,7 @@ public class GetAccessServiceImpl implements GetAccessService{
/*
* (non-Javadoc)
- * @see org.openecomp.portalapp.portal.service.GetAccessService#getAppAccessList()
+ * @see org.onap.portalapp.portal.service.GetAccessService#getAppAccessList()
*/
@SuppressWarnings("unchecked")
@Override
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ManifestServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ManifestServiceImpl.java
index 6ea66fe1..368c1cf6 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ManifestServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/ManifestServiceImpl.java
@@ -59,7 +59,7 @@ public class ManifestServiceImpl implements ManifestService {
/*
* (non-Javadoc)
- * @see org.openecomp.portalapp.portal.service.ManifestService#getWebappManifest()
+ * @see org.onap.portalapp.portal.service.ManifestService#getWebappManifest()
*/
public Attributes getWebappManifest() throws IOException {
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(ManifestServiceImpl.class);
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PersUserAppServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PersUserAppServiceImpl.java
index 39b88f63..a0b32644 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PersUserAppServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/PersUserAppServiceImpl.java
@@ -38,25 +38,21 @@
package org.onap.portalapp.portal.service;
import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.EnableAspectJAutoProxy;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.onap.portalapp.portal.domain.EPApp;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.domain.EPUserApp;
import org.onap.portalapp.portal.domain.PersUserAppSelection;
-import org.onap.portalapp.portal.domain.PersUserWidgetSelection;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.DataAccessService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
@Service("persUserAppService")
@Transactional
@@ -81,9 +77,9 @@ public class PersUserAppServiceImpl implements PersUserAppService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserAppSelectService#
- * setAppCatalogSelection(org.openecomp.portalapp.portal.domain.EPUser,
- * org.openecomp.portalapp.portal.transport.AppCatalogSelection)
+ * @see org.onap.portalapp.portal.service.UserAppSelectService#
+ * setAppCatalogSelection(org.onap.portalapp.portal.domain.EPUser,
+ * org.onap.portalapp.portal.transport.AppCatalogSelection)
*/
@Override
public void setPersUserAppValue(EPUser user, EPApp app, boolean select, boolean pending) {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/SharedContextServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/SharedContextServiceImpl.java
index a950c5ff..49513525 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/SharedContextServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/SharedContextServiceImpl.java
@@ -71,7 +71,7 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalsdk.core.service.SharedContextService#
+ * @see org.onap.portalsdk.core.service.SharedContextService#
* getSharedContexts()
*/
@Override
@@ -89,7 +89,7 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalsdk.core.service.SharedContextService#
+ * @see org.onap.portalsdk.core.service.SharedContextService#
* getSharedContext(java. lang.String, java.lang.String)
*/
@Override
@@ -112,7 +112,7 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.SharedContextService#
+ * @see org.onap.portalapp.portal.service.SharedContextService#
* addSharedContext(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
@@ -124,8 +124,8 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalsdk.core.service.SharedContextService#
- * saveSharedContext(org.openecomp.portalapp.portal.domain.SharedContext)
+ * @see org.onap.portalsdk.core.service.SharedContextService#
+ * saveSharedContext(org.onap.portalapp.portal.domain.SharedContext)
*/
@Override
public void saveSharedContext(SharedContext context) {
@@ -135,8 +135,8 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalsdk.core.service.SharedContextService#
- * deleteSharedContext(org.openecomp.portalapp.portal.domain.SharedContext)
+ * @see org.onap.portalsdk.core.service.SharedContextService#
+ * deleteSharedContext(org.onap.portalapp.portal.domain.SharedContext)
*/
@Override
public void deleteSharedContext(SharedContext context) {
@@ -146,7 +146,7 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.SharedContextService#
+ * @see org.onap.portalapp.portal.service.SharedContextService#
* deleteSharedContexts(java.lang.String)
*/
@Override
@@ -167,7 +167,7 @@ public class SharedContextServiceImpl implements SharedContextService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.SharedContextService#
+ * @see org.onap.portalapp.portal.service.SharedContextService#
* expireSharedContexts(int)
*/
@Override
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserNotificationServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserNotificationServiceImpl.java
index 130c99e7..aa3a4b12 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserNotificationServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserNotificationServiceImpl.java
@@ -73,7 +73,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* getNotifications(java.lang.Long)
*/
@Override
@@ -93,7 +93,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* getNotificationHistoryVO(java.lang.Long)
*/
@Override
@@ -109,7 +109,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* getAdminNotificationVOS()
*/
@Override
@@ -125,7 +125,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* getNotificationRoles(java.lang.Long)
*/
@Override
@@ -141,7 +141,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* getAppRoleList()
*/
@SuppressWarnings("unchecked")
@@ -155,7 +155,7 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
* setNotificationsRead(java.lang.Long, int)
*/
@Override
@@ -171,8 +171,8 @@ public class UserNotificationServiceImpl implements UserNotificationService {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserNotificationService#
- * saveNotification(org.openecomp.portalapp.portal.transport.
+ * @see org.onap.portalapp.portal.service.UserNotificationService#
+ * saveNotification(org.onap.portalapp.portal.transport.
* EpNotificationItem)
*/
@Override
@@ -196,7 +196,9 @@ public class UserNotificationServiceImpl implements UserNotificationService {
if (notificationItem.getNotificationId() != null) {
EpNotificationItem updateNotificationItem = (EpNotificationItem) getDataAccessService()
.getDomainObject(EpNotificationItem.class, notificationItem.getNotificationId(), null);
- notificationItem.setRoles(updateNotificationItem.getRoles());
+ if(updateNotificationItem != null) {
+ notificationItem.setRoles(updateNotificationItem.getRoles());
+ }
}
if (notificationItem.msgSource == null) {
notificationItem.setMsgSource("EP");
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
index c65b4af9..ab4044d1 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImpl.java
@@ -63,7 +63,6 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.json.JSONArray;
import org.json.JSONObject;
-import org.onap.portalapp.portal.service.SearchService;
import org.onap.portalapp.externalsystemapproval.model.ExternalSystemRoleApproval;
import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
import org.onap.portalapp.portal.domain.EPApp;
@@ -75,6 +74,7 @@ import org.onap.portalapp.portal.domain.EPUserAppRoles;
import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail;
import org.onap.portalapp.portal.domain.ExternalSystemAccess;
+import org.onap.portalapp.portal.exceptions.SyncUserRolesException;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
import org.onap.portalapp.portal.logging.format.EPAppMessagesEnum;
import org.onap.portalapp.portal.logging.logic.EPLogUtil;
@@ -246,7 +246,6 @@ public class UserRolesCommonServiceImpl {
*/
protected void syncUserRoles(SessionFactory sessionFactory, String userId, Long appId,
EcompRole[] userAppRoles, Boolean extRequestValue, String reqType) throws Exception {
- boolean result = false;
Session localSession = null;
Transaction transaction = null;
String roleActive = null;
@@ -361,23 +360,17 @@ public class UserRolesCommonServiceImpl {
}
}
transaction.commit();
- result = true;
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "syncUserRoles failed", e);
EPLogUtil.logEcompError(logger, EPAppMessagesEnum.BeDaoSystemError, e);
EcompPortalUtils.rollbackTransaction(transaction,
"Exception occurred in syncUserRoles, Details: " + e.toString());
if("DELETE".equals(reqType)){
- throw new Exception(e.getMessage());
+ throw new SyncUserRolesException(e.getMessage());
}
} finally {
- if (localSession != null) {
- localSession.close();
- }
- if (!result && !"DELETE".equals(reqType)) {
- throw new Exception(
- "Exception occurred in syncUserRoles while closing database session for app: '" + appId + "'.");
- }
+ if(localSession != null)
+ localSession.close();
}
}
@@ -759,7 +752,7 @@ public class UserRolesCommonServiceImpl {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserRolesService#
+ * @see org.onap.portalapp.portal.service.UserRolesService#
* importRolesFromRemoteApplication(java.lang.Long)
*/
public List<EPRole> importRolesFromRemoteApplication(Long appId) throws HTTPException {
@@ -851,9 +844,9 @@ public class UserRolesCommonServiceImpl {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserRolesService#
- * setAppWithUserRoleStateForUser(org.openecomp.portalapp.portal.domain.
- * EPUser, org.openecomp.portalapp.portal.transport.AppWithRolesForUser)
+ * @see org.onap.portalapp.portal.service.UserRolesService#
+ * setAppWithUserRoleStateForUser(org.onap.portalapp.portal.domain.
+ * EPUser, org.onap.portalapp.portal.transport.AppWithRolesForUser)
*/
public boolean setAppWithUserRoleStateForUser(EPUser user, AppWithRolesForUser newAppRolesForUser) {
boolean result = false;
@@ -1572,7 +1565,7 @@ public class UserRolesCommonServiceImpl {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserRolesService#
+ * @see org.onap.portalapp.portal.service.UserRolesService#
* getAppRolesForUser(java.lang.Long, java.lang.String)
*/
@SuppressWarnings("unchecked")
@@ -1606,7 +1599,7 @@ public class UserRolesCommonServiceImpl {
activeRoleList.add(role);
}
}
-
+
}
EPUser localUser = getUserFromApp(userId, app, applicationsRestClientService);
// If localUser does not exists return roles
@@ -1623,7 +1616,9 @@ public class UserRolesCommonServiceImpl {
EcompRole[] appRoles = null;
List<EcompRole> roles = new ArrayList<>();
if(app.getCentralAuth()){
- List<EPRole> applicationRoles = dataAccessService.getList(EPRole.class, " where app_id = "+app.getId()+ " and active_yn = 'Y'", null, null);;
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ List<EPRole> applicationRoles = dataAccessService.executeNamedQuery("getActiveRolesOfApplication", appParams, null);
for(EPRole role : applicationRoles){
EcompRole ecompRole = new EcompRole();
ecompRole.setId(role.getId());
@@ -1739,10 +1734,11 @@ public class UserRolesCommonServiceImpl {
return result;
}
+ @SuppressWarnings("unchecked")
public FieldsValidator putUserAppRolesRequest(AppWithRolesForUser userAppRolesData, EPUser user) {
FieldsValidator fieldsValidator = new FieldsValidator();
final Map<String, Long> params = new HashMap<>();
- EPUserAppRoles appRole= new EPUserAppRoles();
+ List<EPUserAppRoles> appRole= null;
try {
logger.error(EELFLoggerDelegate.errorLogger,"Should not be reached here, still the endpoint is yet to be defined");
boolean result = postUserRolesToMylogins(userAppRolesData, applicationsRestClientService, userAppRolesData.appId, user.getId());
@@ -1762,13 +1758,15 @@ public class UserRolesCommonServiceImpl {
Boolean isAppliedVal = userAppRoles.isApplied;
params.put("appRoleId", userAppRoles.roleId);
if (isAppliedVal) {
- appRole = (EPUserAppRoles) dataAccessService.executeNamedQuery("appRoles", params, null).get(0);
- EPUserAppRolesRequestDetail epAppRoleDetail = new EPUserAppRolesRequestDetail();
- epAppRoleDetail.setReqRoleId(appRole.getRoleId());
- epAppRoleDetail.setReqType("P");
- epAppRoleDetail.setEpRequestIdData(epAppRolesRequestData);
- dataAccessService.saveDomainObject(epAppRoleDetail, null);
- }
+ appRole = (List<EPUserAppRoles>) dataAccessService.executeNamedQuery("appRoles", params, null);
+ if (!appRole.isEmpty()) {
+ EPUserAppRolesRequestDetail epAppRoleDetail = new EPUserAppRolesRequestDetail();
+ epAppRoleDetail.setReqRoleId(appRole.get(0).getRoleId());
+ epAppRoleDetail.setReqType("P");
+ epAppRoleDetail.setEpRequestIdData(epAppRolesRequestData);
+ dataAccessService.saveDomainObject(epAppRoleDetail, null);
+ }
+ }
}
epAppRolesRequestData.setEpRequestIdDetail(appRoleDetails);
fieldsValidator.httpStatusCode = new Long(HttpServletResponse.SC_OK);
@@ -1831,7 +1829,7 @@ public class UserRolesCommonServiceImpl {
/*
* (non-Javadoc)
*
- * @see org.openecomp.portalapp.portal.service.UserRolesService#
+ * @see org.onap.portalapp.portal.service.UserRolesService#
* getCachedAppRolesForUser(java.lang.Long, java.lang.Long)
*/
public List<EPUserApp> getCachedAppRolesForUser(Long appId, Long userId) {
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EventWidget.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EventWidget.java
index 96562399..d96f1821 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EventWidget.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/EventWidget.java
@@ -36,7 +36,7 @@ package org.onap.portalapp.portal.transport;
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-/*package org.openecomp.portalapp.portal.transport;
+/*package org.onap.portalapp.portal.transport;
import javax.persistence.Column;
import javax.persistence.Entity;
@@ -45,7 +45,7 @@ import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
-import org.openecomp.portalsdk.core.domain.support.DomainVo;
+import org.onap.portalsdk.core.domain.support.DomainVo;
import com.fasterxml.jackson.annotation.JsonInclude;
*//**
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidator.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidator.java
index 75418df5..67dba090 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidator.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/transport/ExternalRequestFieldsValidator.java
@@ -60,6 +60,37 @@ public class ExternalRequestFieldsValidator {
this.detailMessage = detailMessage;
}
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((detailMessage == null) ? 0 : detailMessage.hashCode());
+ result = prime * result + (this.result ? 1231 : 1237);
+ return result;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ExternalRequestFieldsValidator other = (ExternalRequestFieldsValidator) obj;
+ if (detailMessage == null) {
+ if (other.detailMessage != null)
+ return false;
+ } else if (!detailMessage.equals(other.detailMessage))
+ return false;
+ if (result != other.result)
+ return false;
+ return true;
+ }
+
+
+
+
+
}
diff --git a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/CustomLoggingFilter.java b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/CustomLoggingFilter.java
index 0b564eec..4b580e0a 100644
--- a/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/CustomLoggingFilter.java
+++ b/ecomp-portal-BE-common/src/main/java/org/onap/portalapp/portal/utils/CustomLoggingFilter.java
@@ -59,7 +59,7 @@ public class CustomLoggingFilter extends Filter<ILoggingEvent> {
try {
if ((event.getLevel() != Level.ERROR || event.getLevel() != Level.WARN) &&
(event.getThreadName().equalsIgnoreCase("UEBConsumerThread")) &&
- (event.getLoggerName().contains("org.openecomp.nsa") || event.getLoggerName().contains("org.apache.http"))
+ (event.getLoggerName().contains("org.onap.nsa") || event.getLoggerName().contains("org.apache.http"))
) {
return FilterReply.DENY;
} else {
diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
index f82d2cb7..2488a2e5 100644
--- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
+++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/EP.hbm.xml
@@ -1985,6 +1985,15 @@ where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' and fn_role.active_y
;
]]>
</sql-query>
+
+ <!-- Gets all active records from fn_role that is associated with this app-->
+ <sql-query name="getActiveRolesOfApplication">
+ <return alias="activeRolesOfApplication" class="org.onap.portalapp.portal.domain.EPRole" />
+ <![CDATA[
+ select * from fn_role where active_yn = 'Y' and app_id=:appId
+ ;
+ ]]>
+ </sql-query>
<sql-query name="getBulkUserRoles">
<return alias="bulkUserRoles" class="org.onap.portalapp.portal.transport.BulkUploadUserRoles" />
@@ -2318,6 +2327,15 @@ where fn_role.app_id = fn_app.app_id and fn_app.enabled='Y' and fn_role.active_y
;
]]>
</sql-query>
+
+
+ <query name="getBasicauthAccount">
+ select id,password from BasicAuthCredentials
+ </query>
+
+ <query name="getMicroserviceInfo">
+ select id,password from MicroserviceData
+ </query>
<sql-query name="getUserRoleOnUserIdAndRoleIdAndAppId">
<return alias="getUserRoleOnUserIdAndRoleIdAndAppId" class="org.onap.portalapp.portal.domain.EPUserApp" />
diff --git a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml
index 819a5212..d197bc5f 100644
--- a/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml
+++ b/ecomp-portal-BE-common/src/main/webapp/WEB-INF/fusion/orm/Fusion.hbm.xml
@@ -354,4 +354,8 @@ Portal app mappings and features are in EP.hbm.xml.
]]>
</sql-query>
+ <query name="getAppPassword">
+ select id,appPassword from App
+ </query>
+
</hibernate-mapping>
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java
index 522ef7ca..e35d3266 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/AppContactUsControllerTest.java
@@ -306,13 +306,13 @@ public class AppContactUsControllerTest extends MockitoTestSuite{
PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
expectedResponse.setStatus(PortalRestStatusEnum.OK);
expectedResponse.setMessage("success");
- expectedResponse.setResponse("\"ush_ticket_url\":\"http://todo_enter_ush_ticket_url\",\"portal_info_url\":\"https://todo_enter_portal_info_url\",\"feedback_email_address\":\"portal@lists.openecomp.org\"");
+ expectedResponse.setResponse("\"ush_ticket_url\":\"http://todo_enter_ush_ticket_url\",\"portal_info_url\":\"https://todo_enter_portal_info_url\",\"feedback_email_address\":\"portal@lists.onap.org\"");
PowerMockito.mockStatic(SystemProperties.class);
PowerMockito.mockStatic(EPCommonSystemProperties.class);
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL)).thenReturn("http://todo_enter_ush_ticket_url");
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL)).thenReturn("https://todo_enter_portal_info_url");
- Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.openecomp.org");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.onap.org");
actualResponse = appContactUsController.getPortalDetails(mockedRequest);
assertTrue(actualResponse.getStatus().compareTo(PortalRestStatusEnum.OK) == 0);
@@ -330,7 +330,7 @@ public class AppContactUsControllerTest extends MockitoTestSuite{
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.USH_TICKET_URL)).thenThrow(nullPointerException);
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.PORTAL_INFO_URL)).thenReturn("https://todo_enter_portal_info_url");
- Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.openecomp.org");
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.FEEDBACK_EMAIL_ADDRESS)).thenReturn("portal@lists.onap.org");
actualResponse = appContactUsController.getPortalDetails(mockedRequest);
assertEquals(actualResponse, expectedResponse);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
index 37f7f687..54671ad3 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/DashboardControllerTest.java
@@ -242,7 +242,7 @@ public class DashboardControllerTest {
expectedData.setStatus(PortalRestStatusEnum.ERROR);
expectedData.setMessage("ERROR");
expectedData.setResponse("Category cannot be null or empty");
-
+
Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
assertEquals(expectedData,actualResponse);
@@ -258,7 +258,7 @@ public class DashboardControllerTest {
expectedData.setMessage("Invalid category: test");
expectedData.setResponse(null);
Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
- PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget, mockedRequest, mockedResponse);
+ PortalRestResponse<String> actualResponse = dashboardController.saveWidgetData(commonWidget,mockedRequest, mockedResponse);
assertEquals(expectedData,actualResponse);
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java
index 205b2355..84db1496 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/controller/UserControllerTest.java
@@ -135,7 +135,7 @@ public class UserControllerTest extends MockitoTestSuite {
@Test
public void modifyLoggedinUserExceptionTest() {
- EPUser epUser = null;
+ EPUser epUser =null;
PortalRestResponse<String> expectedResponse = new PortalRestResponse<String>();
expectedResponse.setMessage("java.lang.NullPointerException");
expectedResponse.setResponse(null);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java
index e3eeaa54..3a7d4f39 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/PopulateSampleTestData.java
@@ -36,7 +36,7 @@ package org.onap.portalapp.portal.core;
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-//package org.openecomp.portalapp.portal.core;
+//package org.onap.portalapp.portal.core;
//
//import java.sql.Connection;
//import java.sql.SQLException;
@@ -45,7 +45,7 @@ package org.onap.portalapp.portal.core;
//
//import org.junit.Before;
//import org.junit.Test;
-//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite;
+//import org.onap.portalapp.framework.ApplicationCommonContextTestSuite;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.jdbc.datasource.DataSourceUtils;
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java
index 1fa6c7d1..2aedae69 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RemoveSampleTestData.java
@@ -36,7 +36,7 @@ package org.onap.portalapp.portal.core;
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-//package org.openecomp.portalapp.portal.core;
+//package org.onap.portalapp.portal.core;
//
//import java.sql.Connection;
//import java.sql.SQLException;
@@ -45,7 +45,7 @@ package org.onap.portalapp.portal.core;
//
//import org.junit.After;
//import org.junit.Test;
-//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite;
+//import org.onap.portalapp.framework.ApplicationCommonContextTestSuite;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.io.ClassPathResource;
//import org.springframework.jdbc.datasource.DataSourceUtils;
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java
index 8bb21812..9c93790a 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/core/RestURLsTestSuite.java
@@ -36,7 +36,7 @@ package org.onap.portalapp.portal.core;
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-//package org.openecomp.portalapp.portal.core;
+//package org.onap.portalapp.portal.core;
//
//import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertTrue;
@@ -47,12 +47,12 @@ package org.onap.portalapp.portal.core;
//
//import org.junit.Assert;
//import org.junit.Test;
-//import org.openecomp.portalapp.framework.ApplicationCommonContextTestSuite;
-//import org.openecomp.portalapp.portal.domain.EPUser;
-//import org.openecomp.portalapp.portal.test.core.MockEPUser;
-//import org.openecomp.portalapp.portal.transport.AppNameIdIsAdmin;
-//import org.openecomp.portalapp.portal.transport.AppsListWithAdminRole;
-//import org.openecomp.portalsdk.core.util.SystemProperties;
+//import org.onap.portalapp.framework.ApplicationCommonContextTestSuite;
+//import org.onap.portalapp.portal.domain.EPUser;
+//import org.onap.portalapp.portal.test.core.MockEPUser;
+//import org.onap.portalapp.portal.transport.AppNameIdIsAdmin;
+//import org.onap.portalapp.portal.transport.AppsListWithAdminRole;
+//import org.onap.portalsdk.core.util.SystemProperties;
//import org.springframework.http.MediaType;
//import org.springframework.test.web.servlet.ResultActions;
//import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java
index 2923eb2b..0b6a7e13 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPUserAppsManualSortPreferenceTest.java
@@ -46,7 +46,7 @@ public class EPUserAppsManualSortPreferenceTest {
public EPUserAppsManualSortPreference mockEPUserAppsManualSortPreference(){
EPUserAppsManualSortPreference epUserAppsManualSortPreference = new EPUserAppsManualSortPreference();
- epUserAppsManualSortPreference.setUserId(1);
+ epUserAppsManualSortPreference.setUserId(1l);
epUserAppsManualSortPreference.setAppId((long)1);
epUserAppsManualSortPreference.setAppManualSortOrder(1);
@@ -58,7 +58,7 @@ public class EPUserAppsManualSortPreferenceTest {
EPUserAppsManualSortPreference epUserAppsManualSortPreference = mockEPUserAppsManualSortPreference();
- assertEquals(epUserAppsManualSortPreference.getUserId(), 1);
+ assertEquals(epUserAppsManualSortPreference.getUserId(), new Long(1));
assertEquals(epUserAppsManualSortPreference.getAppId(), new Long(1));
assertEquals(epUserAppsManualSortPreference.getAppManualSortOrder(), 1);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java
index b4b4780d..5dbca6eb 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/domain/EPWidgetsManualSortPreferenceTest.java
@@ -47,7 +47,7 @@ public class EPWidgetsManualSortPreferenceTest {
public EPWidgetsManualSortPreference mockEPWidgetsManualSortPreference(){
EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference();
- epWidgetsManualSortPreference.setUserId(1);
+ epWidgetsManualSortPreference.setUserId(1l);
epWidgetsManualSortPreference.setWidgetId((long)1);
epWidgetsManualSortPreference.setWidgetRow(1);
epWidgetsManualSortPreference.setWidgetCol(1);
@@ -62,7 +62,7 @@ public class EPWidgetsManualSortPreferenceTest {
EPWidgetsManualSortPreference epWidgetsManualSortPreference = mockEPWidgetsManualSortPreference();
assertEquals(epWidgetsManualSortPreference.getWidgetId(), new Long(1));
- assertEquals(epWidgetsManualSortPreference.getUserId(), 1);
+ assertEquals(epWidgetsManualSortPreference.getUserId(), new Long(1));
assertEquals(epWidgetsManualSortPreference.getWidgetRow(), 1);
assertEquals(epWidgetsManualSortPreference.getWidgetCol(), 1);
assertEquals(epWidgetsManualSortPreference.getWidgetHeight(), 1);
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java
index 764cebab..96c41729 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/framework/ApplicationCommonContextTestSuite.java
@@ -36,20 +36,20 @@ package org.onap.portalapp.portal.framework;
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-//package org.openecomp.portalapp.portal.framework;
+//package org.onap.portalapp.portal.framework;
//
//import java.io.IOException;
//
//import org.junit.Before;
//import org.junit.runner.RunWith;
-//import org.openecomp.portalsdk.core.conf.AppConfig;
-////import org.openecomp.portalapp.conf.ExternalAppConfig;
-////import org.openecomp.portalapp.conf.HibernateMappingLocations;
-//import org.openecomp.portalsdk.core.conf.HibernateConfiguration;
-//import org.openecomp.portalsdk.core.conf.HibernateMappingLocatable;
-//import org.openecomp.portalsdk.core.objectcache.AbstractCacheManager;
-//import org.openecomp.portalsdk.core.util.CacheManager;
-//import org.openecomp.portalsdk.core.util.SystemProperties;
+//import org.onap.portalsdk.core.conf.AppConfig;
+////import org.onap.portalapp.conf.ExternalAppConfig;
+////import org.onap.portalapp.conf.HibernateMappingLocations;
+//import org.onap.portalsdk.core.conf.HibernateConfiguration;
+//import org.onap.portalsdk.core.conf.HibernateMappingLocatable;
+//import org.onap.portalsdk.core.objectcache.AbstractCacheManager;
+//import org.onap.portalsdk.core.util.CacheManager;
+//import org.onap.portalsdk.core.util.SystemProperties;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.ComponentScan;
@@ -118,14 +118,14 @@ package org.onap.portalapp.portal.framework;
//}
//
//@Configuration
-//@ComponentScan(basePackages = "org.openecomp", excludeFilters = {
+//@ComponentScan(basePackages = "org.onap", excludeFilters = {
// // the following source configurations should not be scanned; instead of
// // using Exclusion filter, we can use the @Profile annotation to exclude
// // them
-// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.LogoutController*"),
-// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalsdk.core.controller.SDKLoginController*"),
-// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.portalapp.conf.ExternalAppConfig*"),
-// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.openecomp.*.*InitUebHandler*") })
+// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.onap.portalsdk.core.controller.LogoutController*"),
+// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.onap.portalsdk.core.controller.SDKLoginController*"),
+// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.onap.portalapp.conf.ExternalAppConfig*"),
+// @ComponentScan.Filter(type = FilterType.REGEX, pattern = "org.onap.*.*InitUebHandler*") })
//@Profile("test")
//class MockAppConfig extends AppConfig {
//
@@ -185,7 +185,7 @@ package org.onap.portalapp.portal.framework;
// }
//
// public String[] getPackagesToScan() {
-// return new String[] { "org.openecomp", "src" };
+// return new String[] { "org.onap", "src" };
// }
//
//}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
new file mode 100644
index 00000000..3bfd7ec4
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/EPAppCommonServiceImplTest.java
@@ -0,0 +1,815 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.AppIdAndNameTransportModel;
+import org.onap.portalapp.portal.domain.AppsResponse;
+import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EPUserAppsManualSortPreference;
+import org.onap.portalapp.portal.domain.EPUserAppsSortPreference;
+import org.onap.portalapp.portal.domain.EPWidgetsManualSortPreference;
+import org.onap.portalapp.portal.domain.EcompApp;
+import org.onap.portalapp.portal.domain.UserRole;
+import org.onap.portalapp.portal.domain.UserRoles;
+import org.onap.portalapp.portal.transport.EPAppsSortPreference;
+import org.onap.portalapp.portal.transport.EPDeleteAppsManualSortPref;
+import org.onap.portalapp.portal.transport.EPWidgetsSortPreference;
+import org.onap.portalapp.portal.transport.FieldsValidator;
+import org.onap.portalapp.portal.transport.FunctionalMenuItem;
+import org.onap.portalapp.portal.transport.LocalRole;
+import org.onap.portalapp.portal.transport.OnboardingApp;
+import org.onap.portalapp.portal.ueb.EPUebHelper;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
+import org.onap.portalsdk.core.onboarding.util.PortalApiProperties;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.service.DataAccessServiceImpl;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.att.nsa.apiClient.credentials.ApiCredential;
+import com.att.nsa.cambria.client.CambriaClientBuilders;
+import com.att.nsa.cambria.client.CambriaIdentityManager;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({ "org.apache.http.conn.ssl.*", "javax.net.ssl.*", "javax.crypto.*" })
+@PrepareForTest({ EcompPortalUtils.class, PortalApiProperties.class, PortalApiConstants.class, SystemProperties.class,
+ PortalConstants.class, EPCommonSystemProperties.class })
+public class EPAppCommonServiceImplTest {
+
+ @Mock
+ DataAccessService dataAccessService = new DataAccessServiceImpl();
+
+ @Mock
+ AdminRolesServiceImpl adminRolesServiceImpl = new AdminRolesServiceImpl();
+
+ @Mock
+ EPUebHelper epUebHelper;
+
+ @Mock
+ SessionFactory sessionFactory;
+
+ @Mock
+ Session session;
+
+ @Mock
+ Transaction transaction;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Mockito.when(session.beginTransaction()).thenReturn(transaction);
+ }
+
+ MockEPUser mockUser = new MockEPUser();
+
+ String ECOMP_APP_ID = "1";
+ String SUPER_ADMIN_ROLE_ID = "1";
+ String ACCOUNT_ADMIN_ROLE_ID = "999";
+ String RESTRICTED_APP_ROLE_ID = "900";
+
+ @InjectMocks
+ EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
+
+ public EPApp mockApp() {
+ EPApp app = new EPApp();
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setDescription("test");
+ app.setNotes("test");
+ app.setUrl("test");
+ app.setId((long) 1);
+ app.setAppRestEndpoint("test");
+ app.setAlternateUrl("test");
+ app.setName("test");
+ app.setMlAppName("test");
+ app.setMlAppAdminId("test");
+ app.setUsername("test");
+ app.setAppPassword("test");
+ app.setOpen(false);
+ app.setEnabled(false);
+ app.setCentralAuth(true);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.setAppType(1);
+ return app;
+ }
+
+ @Test
+ public void getUserAsAdminAppsTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> expected = new ArrayList<>();
+ expected.add(mockApp);
+ expected.add(mockApp2);
+ String sql = "SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID=FN_APP.APP_ID where "
+ + "FN_USER_ROLE.USER_ID=" + user.getId() + " AND FN_USER_ROLE.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND FN_APP.ENABLED = 'Y'";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, EPApp.class, null)).thenReturn(expected);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserAsAdminApps(user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserAsAdminAppsTestException() {
+ EPUser user = mockUser.mockEPUser();
+ String sql = "SELECT * FROM FN_APP join FN_USER_ROLE ON FN_USER_ROLE.APP_ID=FN_APP.APP_ID where "
+ + "FN_USER_ROLE.USER_ID=" + user.getId() + " AND FN_USER_ROLE.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND FN_APP.ENABLED = 'Y'";
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeSQLQuery(sql, EPApp.class, null);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserAsAdminApps(user);
+ assertNull(actual);
+ }
+
+ @Test
+ public void getUserByOrgUserIdAsAdminAppsTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> expected = new ArrayList<>();
+ expected.add(mockApp);
+ expected.add(mockApp2);
+ String format = "SELECT * FROM FN_APP app INNER JOIN FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+ + "INNER JOIN FN_USER user on user.USER_ID = userrole.USER_ID "
+ + "WHERE user.org_user_id = '%s' AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND FN_APP.ENABLED = 'Y'";
+ String sql = String.format(format, user.getOrgUserId());
+ Mockito.when(dataAccessService.executeSQLQuery(sql, EPApp.class, null)).thenReturn(expected);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserByOrgUserIdAsAdminApps(user.getOrgUserId());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserByOrgUserIdAsAdminAppsTestException() {
+ EPUser user = mockUser.mockEPUser();
+ String format = "SELECT * FROM FN_APP app INNER JOIN FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+ + "INNER JOIN FN_USER user on user.USER_ID = userrole.USER_ID "
+ + "WHERE user.org_user_id = '%s' AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND FN_APP.ENABLED = 'Y'";
+ String sql = String.format(format, user.getOrgUserId());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeSQLQuery(sql, EPApp.class, null);
+ List<EPApp> actual = epAppCommonServiceImpl.getUserByOrgUserIdAsAdminApps(user.getOrgUserId());
+ assertNull(actual);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void getAppsFullListTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ List<EPApp> expected = new ArrayList<>();
+ expected.add(mockApp);
+ expected.add(mockApp2);
+ Mockito.when(dataAccessService.getList(EPApp.class, null)).thenReturn(expected);
+ List<EPApp> actual = epAppCommonServiceImpl.getAppsFullList();
+ assertEquals(expected, actual);
+
+ }
+
+ @Test
+ public void getEcompAppAppsFullListTest() {
+ List<EcompApp> expected = new ArrayList<>();
+ List<EcompApp> actual = epAppCommonServiceImpl.getEcompAppAppsFullList();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void transformAppsToEcompAppsTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ List<EPApp> epAppsList = new ArrayList<>();
+ epAppsList.add(mockApp);
+ epAppsList.add(mockApp2);
+ List<EcompApp> expected = new ArrayList<>();
+ EcompApp ecompApp = new EcompApp();
+ ecompApp.setName("test1");
+ EcompApp ecompApp2 = new EcompApp();
+ ecompApp2.setName("test2");
+ expected.add(ecompApp);
+ expected.add(ecompApp2);
+ List<EcompApp> actual = epAppCommonServiceImpl.transformAppsToEcompApps(epAppsList);
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ @Test
+ public void getAllAppsForAllTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ List<EPApp> appsList = new ArrayList<>();
+ appsList.add(mockApp);
+ appsList.add(mockApp2);
+ List<AppsResponse> expected = new ArrayList<>();
+ AppsResponse appResponse1 = new AppsResponse(mockApp.getId(), mockApp.getName(), mockApp.isRestrictedApp(),
+ mockApp.getEnabled());
+ AppsResponse appResponse2 = new AppsResponse(mockApp2.getId(), mockApp2.getName(), mockApp2.isRestrictedApp(),
+ mockApp2.getEnabled());
+ expected.add(appResponse1);
+ expected.add(appResponse2);
+ Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class, " where id != " + ECOMP_APP_ID, "name", null))
+ .thenReturn(appsList);
+ List<AppsResponse> actual = epAppCommonServiceImpl.getAllApps(true);
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings({ "unchecked", "deprecation" })
+ @Test
+ public void getAllAppsIsNotAllTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp2.setId(2l);
+ List<EPApp> appsList = new ArrayList<>();
+ appsList.add(mockApp);
+ appsList.add(mockApp2);
+ List<AppsResponse> expected = new ArrayList<>();
+ AppsResponse appResponse1 = new AppsResponse(mockApp.getId(), mockApp.getName(), mockApp.isRestrictedApp(),
+ mockApp.getEnabled());
+ AppsResponse appResponse2 = new AppsResponse(mockApp2.getId(), mockApp2.getName(), mockApp2.isRestrictedApp(),
+ mockApp2.getEnabled());
+ expected.add(appResponse1);
+ expected.add(appResponse2);
+ Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class,
+ " where ( enabled = 'Y' or id = " + ECOMP_APP_ID + ")", "name", null)).thenReturn(appsList);
+ List<AppsResponse> actual = epAppCommonServiceImpl.getAllApps(false);
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @Test
+ public void getAppTest() {
+ EPApp expected = mockApp();
+ Mockito.when((EPApp) dataAccessService.getDomainObject(EPApp.class, expected.getId(), null))
+ .thenReturn(expected);
+ EPApp actual = epAppCommonServiceImpl.getApp(expected.getId());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppExceptionTest() {
+ EPApp expected = mockApp();
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).getDomainObject(EPApp.class,
+ expected.getId(), null);
+ EPApp actual = epAppCommonServiceImpl.getApp(expected.getId());
+ assertNull(actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppDetailTest() {
+ EPApp expected = mockApp();
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(expected);
+ final Map<String, String> params = new HashMap<String, String>();
+ params.put("appName", expected.getName());
+ Mockito.when((List<EPApp>) dataAccessService.executeNamedQuery("getMyloginAppDetails", params, null))
+ .thenReturn(appList);
+ EPApp actual = epAppCommonServiceImpl.getAppDetail(expected.getName());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAppDetailExceptionTest() {
+ EPApp expected = mockApp();
+ List<EPApp> appList = new ArrayList<>();
+ appList.add(expected);
+ final Map<String, String> params = new HashMap<String, String>();
+ params.put("appName", expected.getName());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery("getMyloginAppDetails",
+ params, null);
+ EPApp actual = epAppCommonServiceImpl.getAppDetail(expected.getName());
+ assertNull(actual);
+ }
+
+ @Test
+ public void getUserProfile() {
+ EPUser user = mockUser.mockEPUser();
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", user.getOrgUserId());
+ List<UserRole> userRoleList = new ArrayList<>();
+ UserRole userRole = new UserRole();
+ userRole.setFirstName("GuestT");
+ userRole.setLastName("GuestT");
+ userRole.setOrgUserId("guestT");
+ userRole.setRoleId(1l);
+ userRole.setRoleName("Test");
+ userRole.setUser_Id(-1l);
+ userRoleList.add(userRole);
+ UserRoles expected = new UserRoles(userRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getUserRoles", params, null)).thenReturn(userRoleList);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfile(user.getOrgUserId());
+ assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
+ }
+
+ @Test
+ public void getUserProfileNullTest() {
+ EPUser user = mockUser.mockEPUser();
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", user.getOrgUserId());
+ List<UserRole> userRoleList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getUserRoles", params, null)).thenReturn(userRoleList);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfile(user.getOrgUserId());
+ assertNull(actual);
+ }
+
+ @Test
+ public void getUserProfileNormalizedTest() {
+ EPUser user = mockUser.mockEPUser();
+ user.setGuest(true);
+ user.setLoginId("guestT");
+ final Map<String, String> params = new HashMap<>();
+ params.put("org_user_id", user.getOrgUserId());
+ List<UserRole> userRoleList = new ArrayList<>();
+ UserRole userRole = new UserRole();
+ userRole.setFirstName("GuestT");
+ userRole.setLastName("GuestT");
+ userRole.setOrgUserId("guestT");
+ userRole.setRoleId(1l);
+ userRole.setRoleName("Test");
+ userRole.setUser_Id(-1l);
+ userRoleList.add(userRole);
+ UserRoles expected = new UserRoles(userRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getUserRoles", params, null)).thenReturn(userRoleList);
+ UserRoles actual = epAppCommonServiceImpl.getUserProfileNormalized(user);
+ assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
+ }
+
+ @Test
+ public void getRestrictedAppRolesTest() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setRestrictedApp(true);
+ user.setLoginId("guestT");
+ List<LocalRole> expected = new ArrayList<>();
+ LocalRole localRole = new LocalRole();
+ localRole.setRoleId(1);
+ localRole.setRolename("test1");
+ expected.add(localRole);
+ String sql = "SELECT ROLE_ID, ROLE_NAME from FN_ROLE where UPPER(ACTIVE_YN) = 'Y' AND ROLE_ID = '"
+ + RESTRICTED_APP_ROLE_ID + "'";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, LocalRole.class, null)).thenReturn(expected);
+ Mockito.when((EPApp) dataAccessService.getDomainObject(EPApp.class, mockApp.getId(), null)).thenReturn(mockApp);
+ List<LocalRole> actual = epAppCommonServiceImpl.getAppRoles(mockApp.getId());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getPoralAppRolesTest() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setRestrictedApp(false);
+ mockApp.setId(1l);
+ user.setLoginId("guestT");
+ List<LocalRole> expected = new ArrayList<>();
+ LocalRole localRole = new LocalRole();
+ localRole.setRoleId(1);
+ localRole.setRolename("test1");
+ expected.add(localRole);
+ String sql = "SELECT ROLE_ID, ROLE_NAME from FN_ROLE where UPPER(ACTIVE_YN) = 'Y' AND APP_ID IS NULL";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, LocalRole.class, null)).thenReturn(expected);
+ Mockito.when((EPApp) dataAccessService.getDomainObject(EPApp.class, mockApp.getId(), null)).thenReturn(mockApp);
+ List<LocalRole> actual = epAppCommonServiceImpl.getAppRoles(mockApp.getId());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getNonPortalAndNonRestrictedAppRolesTest() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setRestrictedApp(false);
+ mockApp.setId(2l);
+ user.setLoginId("guestT");
+ List<LocalRole> expected = new ArrayList<>();
+ LocalRole localRole = new LocalRole();
+ localRole.setRoleId(1);
+ localRole.setRolename("test1");
+ expected.add(localRole);
+ String sql = "SELECT ROLE_ID, ROLE_NAME from FN_ROLE where UPPER(ACTIVE_YN) = 'Y' AND APP_ID = '"
+ + mockApp.getId() + "'";
+ Mockito.when(dataAccessService.executeSQLQuery(sql, LocalRole.class, null)).thenReturn(expected);
+ Mockito.when((EPApp) dataAccessService.getDomainObject(EPApp.class, mockApp.getId(), null)).thenReturn(mockApp);
+ List<LocalRole> actual = epAppCommonServiceImpl.getAppRoles(mockApp.getId());
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAdminAppsTest() {
+ EPUser user = mockUser.mockEPUser();
+ user.setId(1l);
+ List<AppIdAndNameTransportModel> expected = new ArrayList<>();
+ AppIdAndNameTransportModel appIdAndNameTransportModel = new AppIdAndNameTransportModel();
+ appIdAndNameTransportModel.setId(1l);
+ appIdAndNameTransportModel.setName("test1");
+ expected.add(appIdAndNameTransportModel);
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+ + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)";
+ String sql = String.format(format, user.getId());
+ Mockito.when(dataAccessService.executeSQLQuery(sql, AppIdAndNameTransportModel.class, null))
+ .thenReturn(expected);
+ List<AppIdAndNameTransportModel> actual = epAppCommonServiceImpl.getAdminApps(user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getAdminAppsExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ user.setId(1l);
+ List<AppIdAndNameTransportModel> expected = new ArrayList<>();
+ Mockito.when(adminRolesServiceImpl.isAccountAdmin(user)).thenReturn(true);
+ String format = "SELECT app.APP_ID, app.APP_NAME, app.APP_TYPE FROM FN_APP app inner join FN_USER_ROLE userrole ON userrole.APP_ID=app.APP_ID "
+ + "where userrole.USER_ID = %d AND userrole.ROLE_ID=" + ACCOUNT_ADMIN_ROLE_ID
+ + " AND (app.ENABLED = 'Y' OR app.APP_ID=1)";
+ String sql = String.format(format, user.getId());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeSQLQuery(sql,
+ AppIdAndNameTransportModel.class, null);
+ List<AppIdAndNameTransportModel> actual = epAppCommonServiceImpl.getAdminApps(user);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void addOnboardingAppUnKnownHostExceptionTest() throws Exception {
+ PowerMockito.mockStatic(PortalApiConstants.class);
+ PowerMockito.mockStatic(PortalApiProperties.class);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> mockAppList = new ArrayList<>();
+ OnboardingApp onboardApp = new OnboardingApp();
+ onboardApp.setRestrictedApp(false);
+ onboardApp.name = "test1";
+ onboardApp.url = "http://test.com";
+ onboardApp.isOpen = false;
+ onboardApp.isEnabled = true;
+ onboardApp.username = "test123";
+ onboardApp.appPassword = "test123";
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion urlCrit = Restrictions.eq("url", onboardApp.url);
+ Criterion nameCrit = Restrictions.eq("name", onboardApp.name);
+ Criterion orCrit = Restrictions.or(urlCrit, nameCrit);
+ restrictionsList.add(orCrit);
+ List<String> uebList = new ArrayList<>();
+ uebList.add("localhost");
+ com.att.nsa.apiClient.credentials.ApiCredential apiCredential = new ApiCredential(user.getEmail(),
+ "ECOMP Portal Owner");
+ CambriaIdentityManager mockIm = Mockito
+ .spy(new CambriaClientBuilders.IdentityManagerBuilder().usingHosts(uebList).build());
+ Mockito.doReturn(apiCredential).when(mockIm).createApiKey(user.getEmail(), "ECOMP Portal Owner");
+ Mockito.when(PortalApiProperties.getProperty(PortalApiConstants.UEB_URL_LIST)).thenReturn("localhost");
+ Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class, null, restrictionsList, null))
+ .thenReturn(mockAppList);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
+ FieldsValidator actual = epAppCommonServiceImpl.addOnboardingApp(onboardApp, user);
+ assertEquals(expected, actual);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void modifyOnboardingAppTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setName("test1");
+ mockApp.setId(2l);
+ mockApp.setUrl("http://test.com");
+ mockApp.setUsername("test123");
+ mockApp.setAppPassword("test123");
+ mockApp.setRestrictedApp(false);
+ mockApp.setEnabled(true);
+ mockApp.setOpen(false);
+ List<EPApp> mockAppList = new ArrayList<>();
+ mockAppList.add(mockApp);
+ OnboardingApp onboardApp = new OnboardingApp();
+ onboardApp.setRestrictedApp(false);
+ onboardApp.name = "test1";
+ onboardApp.id = 2l;
+ onboardApp.url = "http://test.com";
+ onboardApp.isOpen = false;
+ onboardApp.isEnabled = true;
+ onboardApp.thumbnail = "test123imgthumbnail";
+ onboardApp.username = "test123";
+ onboardApp.appPassword = "test123";
+ List<Criterion> restrictionsList1 = new ArrayList<Criterion>();
+ Criterion idCrit = Restrictions.eq("id", onboardApp.id);
+ Criterion urlCrit = Restrictions.eq("url", onboardApp.url);
+ Criterion nameCrit = Restrictions.eq("name", onboardApp.name);
+ Criterion orCrit = Restrictions.or(idCrit, urlCrit, nameCrit);
+ restrictionsList1.add(orCrit);
+ Mockito.when((List<EPApp>) dataAccessService.getList(EPApp.class, null, restrictionsList1, null))
+ .thenReturn(mockAppList);
+ Mockito.when((EPApp) session.get(EPApp.class, onboardApp.id)).thenReturn(mockApp);
+ String sql = "SELECT m.menu_id, m.column_num, m.text, m.parent_menu_id, m.url, m.active_yn "
+ + "FROM fn_menu_functional m, fn_menu_functional_roles r " + "WHERE m.menu_id = r.menu_id "
+ + " AND r.app_id = '" + onboardApp.id + "' ";
+ List<Integer> roles = new ArrayList<>();
+ roles.add(1);
+ roles.add(2);
+ List<FunctionalMenuItem> menuItems = new ArrayList<>();
+ FunctionalMenuItem functionalMenuItem = new FunctionalMenuItem();
+ functionalMenuItem.setRestrictedApp(false);
+ functionalMenuItem.setUrl("http://test1.com");
+ functionalMenuItem.setRoles(roles);
+ menuItems.add(functionalMenuItem);
+ Mockito.when(dataAccessService.executeSQLQuery(sql, FunctionalMenuItem.class, null)).thenReturn(menuItems);
+ Mockito.when((FunctionalMenuItem) session.get(FunctionalMenuItem.class, functionalMenuItem.menuId))
+ .thenReturn(functionalMenuItem);
+ Mockito.doNothing().when(epUebHelper).addPublisher(mockApp);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ FieldsValidator actual = epAppCommonServiceImpl.modifyOnboardingApp(onboardApp, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveWidgetsSortManualTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<EPWidgetsManualSortPreference> mockEPManualWidgets = new ArrayList<>();
+ EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference();
+ epWidgetsManualSortPreference.setUserId(user.getId());
+ epWidgetsManualSortPreference.setWidgetCol(1);
+ epWidgetsManualSortPreference.setWidgetHeight(1);
+ epWidgetsManualSortPreference.setWidgetId(1l);
+ epWidgetsManualSortPreference.setWidgetRow(1);
+ epWidgetsManualSortPreference.setWidgetWidth(1);
+ mockEPManualWidgets.add(epWidgetsManualSortPreference);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userWidgetManualSortPrfQuery", params, null))
+ .thenReturn(mockEPManualWidgets);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ List<EPWidgetsSortPreference> epWidgetsSortPreferenceList = new ArrayList<>();
+ EPWidgetsSortPreference mockEPWidgetsSortPreference = new EPWidgetsSortPreference();
+ mockEPWidgetsSortPreference.setRow(2);
+ mockEPWidgetsSortPreference.setHeaderText("test");
+ mockEPWidgetsSortPreference.setSizeX(2);
+ mockEPWidgetsSortPreference.setSizeY(2);
+ mockEPWidgetsSortPreference.setWidgetid(2l);
+ mockEPWidgetsSortPreference.setWidgetIdentifier("test");
+ mockEPWidgetsSortPreference.setCol(2);
+ epWidgetsSortPreferenceList.add(mockEPWidgetsSortPreference);
+ FieldsValidator actual = epAppCommonServiceImpl.saveWidgetsSortManual(epWidgetsSortPreferenceList, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveWidgetsSortManualExistingRecordTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<EPWidgetsManualSortPreference> mockEPManualWidgets = new ArrayList<>();
+ EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference();
+ epWidgetsManualSortPreference.setUserId(user.getId());
+ epWidgetsManualSortPreference.setWidgetCol(1);
+ epWidgetsManualSortPreference.setWidgetHeight(1);
+ epWidgetsManualSortPreference.setWidgetId(2l);
+ epWidgetsManualSortPreference.setWidgetRow(1);
+ epWidgetsManualSortPreference.setWidgetWidth(1);
+ mockEPManualWidgets.add(epWidgetsManualSortPreference);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userWidgetManualSortPrfQuery", params, null))
+ .thenReturn(mockEPManualWidgets);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ List<EPWidgetsSortPreference> epWidgetsSortPreferenceList = new ArrayList<>();
+ EPWidgetsSortPreference mockEPWidgetsSortPreference = new EPWidgetsSortPreference();
+ mockEPWidgetsSortPreference.setRow(2);
+ mockEPWidgetsSortPreference.setHeaderText("test");
+ mockEPWidgetsSortPreference.setSizeX(2);
+ mockEPWidgetsSortPreference.setSizeY(2);
+ mockEPWidgetsSortPreference.setWidgetid(2l);
+ mockEPWidgetsSortPreference.setWidgetIdentifier("test");
+ mockEPWidgetsSortPreference.setCol(2);
+ epWidgetsSortPreferenceList.add(mockEPWidgetsSortPreference);
+ FieldsValidator actual = epAppCommonServiceImpl.saveWidgetsSortManual(epWidgetsSortPreferenceList, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteUserWidgetSortPrefTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<EPWidgetsManualSortPreference> mockEPManualWidgets = new ArrayList<>();
+ EPWidgetsManualSortPreference epWidgetsManualSortPreference = new EPWidgetsManualSortPreference();
+ epWidgetsManualSortPreference.setUserId(user.getId());
+ epWidgetsManualSortPreference.setWidgetCol(1);
+ epWidgetsManualSortPreference.setWidgetHeight(1);
+ epWidgetsManualSortPreference.setWidgetId(2l);
+ epWidgetsManualSortPreference.setWidgetRow(1);
+ epWidgetsManualSortPreference.setWidgetWidth(1);
+ mockEPManualWidgets.add(epWidgetsManualSortPreference);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userWidgetManualSortPrfQuery", params, null))
+ .thenReturn(mockEPManualWidgets);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ List<EPWidgetsSortPreference> epWidgetsSortPreferenceList = new ArrayList<>();
+ EPWidgetsSortPreference mockEPWidgetsSortPreference = new EPWidgetsSortPreference();
+ mockEPWidgetsSortPreference.setRow(2);
+ mockEPWidgetsSortPreference.setHeaderText("test");
+ mockEPWidgetsSortPreference.setSizeX(2);
+ mockEPWidgetsSortPreference.setSizeY(2);
+ mockEPWidgetsSortPreference.setWidgetid(2l);
+ mockEPWidgetsSortPreference.setWidgetIdentifier("test");
+ mockEPWidgetsSortPreference.setCol(2);
+ epWidgetsSortPreferenceList.add(mockEPWidgetsSortPreference);
+ FieldsValidator actual = epAppCommonServiceImpl.deleteUserWidgetSortPref(epWidgetsSortPreferenceList, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveAppsSortPreferenceForNewUserTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<EPUserAppsSortPreference> mockEPAppSortPrefList = new ArrayList<>();
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userAppsSortPreferenceQuery", params, null))
+ .thenReturn(mockEPAppSortPrefList);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ EPAppsSortPreference mockEPAppsSortPreference = new EPAppsSortPreference();
+ mockEPAppsSortPreference.setIndex(1);
+ mockEPAppsSortPreference.setTitle("Last Used");
+ mockEPAppsSortPreference.setValue("L");
+ FieldsValidator actual = epAppCommonServiceImpl.saveAppsSortPreference(mockEPAppsSortPreference, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveAppsSortPreferenceUpdateTest() {
+ EPUser user = mockUser.mockEPUser();
+ List<EPUserAppsSortPreference> mockEPAppSortPrefList = new ArrayList<>();
+ EPUserAppsSortPreference mockEPAppSortPref = new EPUserAppsSortPreference();
+ mockEPAppSortPref.setSortPref("L");
+ mockEPAppSortPref.setId(2l);
+ mockEPAppSortPref.setUserId((int) (long) user.getId());
+ mockEPAppSortPrefList.add(mockEPAppSortPref);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userAppsSortPreferenceQuery", params, null))
+ .thenReturn(mockEPAppSortPrefList);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ EPAppsSortPreference mockEPAppsSortPreference = new EPAppsSortPreference();
+ mockEPAppsSortPreference.setIndex(1);
+ mockEPAppsSortPreference.setTitle("Last Used");
+ mockEPAppsSortPreference.setValue("L");
+ FieldsValidator actual = epAppCommonServiceImpl.saveAppsSortPreference(mockEPAppsSortPreference, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getUserAppsSortTypePreferenceTest() {
+ EPUser user = mockUser.mockEPUser();
+ final Map<String, Long> params = new HashMap<>();
+ List<EPUserAppsSortPreference> mockEPAppSortPrefList = new ArrayList<>();
+ EPUserAppsSortPreference mockEPAppSortPref = new EPUserAppsSortPreference();
+ mockEPAppSortPref.setSortPref("L");
+ mockEPAppSortPref.setId(2l);
+ mockEPAppSortPref.setUserId((int) (long) user.getId());
+ mockEPAppSortPrefList.add(mockEPAppSortPref);
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userAppsSortPreferenceQuery", params, null))
+ .thenReturn(mockEPAppSortPrefList);
+ String actual = epAppCommonServiceImpl.getUserAppsSortTypePreference(user);
+ assertEquals(mockEPAppSortPref.getSortPref(), actual);
+ }
+
+ @Test
+ public void getUserAppsSortTypePreferenceExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ final Map<String, Long> params = new HashMap<>();
+ List<EPUserAppsSortPreference> mockEPAppSortPrefList = new ArrayList<>();
+ EPUserAppsSortPreference mockEPAppSortPref = new EPUserAppsSortPreference();
+ mockEPAppSortPref.setSortPref("L");
+ mockEPAppSortPref.setId(2l);
+ mockEPAppSortPref.setUserId((int) (long) user.getId());
+ mockEPAppSortPrefList.add(mockEPAppSortPref);
+ params.put("userId", user.getId());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService)
+ .executeNamedQuery("userAppsSortPreferenceQuery", params, null);
+ String actual = epAppCommonServiceImpl.getUserAppsSortTypePreference(user);
+ assertNull(actual);
+ }
+
+ @Test
+ public void deleteUserAppSortManualTest() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setId(1l);
+ final Map<String, Long> params = new HashMap<>();
+ List<EPUserAppsManualSortPreference> epManualApps = new ArrayList<EPUserAppsManualSortPreference>();
+ EPUserAppsManualSortPreference epManualApp = new EPUserAppsManualSortPreference();
+ epManualApp.setAppId(mockApp.getId());
+ epManualApp.setAppManualSortOrder(1);
+ epManualApp.setId(1l);
+ epManualApp.setUserId(user.getId());
+ epManualApps.add(epManualApp);
+ params.put("userId", user.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userAppsManualSortPrfQuery", params, null)).thenReturn(epManualApps);
+ EPDeleteAppsManualSortPref delAppSortManual = new EPDeleteAppsManualSortPref();
+ delAppSortManual.setAppId(mockApp.getId());
+ delAppSortManual.setPending(false);
+ delAppSortManual.setSelect(false);
+ FieldsValidator actual = epAppCommonServiceImpl.deleteUserAppSortManual(delAppSortManual, user);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(200l);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteUserAppSortManualExceptionTest() {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setId(1l);
+ final Map<String, Long> params = new HashMap<>();
+ List<EPUserAppsManualSortPreference> epManualApps = new ArrayList<EPUserAppsManualSortPreference>();
+ EPUserAppsManualSortPreference epManualApp = new EPUserAppsManualSortPreference();
+ epManualApp.setAppId(mockApp.getId());
+ epManualApp.setAppManualSortOrder(1);
+ epManualApp.setId(1l);
+ epManualApp.setUserId(user.getId());
+ epManualApps.add(epManualApp);
+ params.put("userId", user.getId());
+ Mockito.doThrow(new NullPointerException()).when(dataAccessService).executeNamedQuery("userAppsManualSortPrfQuery", params, null);
+ EPDeleteAppsManualSortPref delAppSortManual = new EPDeleteAppsManualSortPref();
+ delAppSortManual.setAppId(mockApp.getId());
+ delAppSortManual.setPending(false);
+ delAppSortManual.setSelect(false);
+ FieldsValidator actual = epAppCommonServiceImpl.deleteUserAppSortManual(delAppSortManual, user);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(500l);
+ assertEquals(expected, actual);
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
index 66cfdd31..0fe5a2c6 100644
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/ExternalAccessRolesServiceImplTest.java
@@ -45,10 +45,18 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeSet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.json.JSONObject;
+import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -64,11 +72,19 @@ import org.onap.portalapp.portal.domain.EPAppRoleFunction;
import org.onap.portalapp.portal.domain.EPRole;
import org.onap.portalapp.portal.domain.EPUser;
import org.onap.portalapp.portal.exceptions.InactiveApplicationException;
+import org.onap.portalapp.portal.exceptions.InvalidUserException;
import org.onap.portalapp.portal.framework.MockitoTestSuite;
+import org.onap.portalapp.portal.transport.BulkUploadUserRoles;
+import org.onap.portalapp.portal.transport.CentralV2Role;
import org.onap.portalapp.portal.transport.EcompUserRoles;
+import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
+import org.onap.portalapp.portal.transport.GlobalRoleWithApplicationRoleFunction;
+import org.onap.portalapp.portal.transport.LocalRole;
import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.domain.RoleFunction;
import org.onap.portalsdk.core.restful.domain.EcompUser;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.service.DataAccessServiceImpl;
@@ -88,7 +104,7 @@ import org.springframework.web.client.RestTemplate;
@PrepareForTest({ EcompPortalUtils.class, SystemProperties.class, EPCommonSystemProperties.class })
public class ExternalAccessRolesServiceImplTest {
@Mock
- DataAccessService dataAccessService1 = new DataAccessServiceImpl();
+ DataAccessService dataAccessService = new DataAccessServiceImpl();
@Mock
RestTemplate template = new RestTemplate();
@@ -96,10 +112,73 @@ public class ExternalAccessRolesServiceImplTest {
@InjectMocks
ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl();
+ @Mock
+ EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
+
+ @Mock
+ SessionFactory sessionFactory;
+
+ @Mock
+ Session session;
+
+ @Mock
+ Transaction transaction;
+
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Mockito.when(session.beginTransaction()).thenReturn(transaction);
}
+
+ @After
+ public void after() {
+ session.close();
+ }
+
+ private static final String APP_ROLE_NAME_PARAM = "appRoleName";
+
+ private static final String GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM = "getRoletoUpdateInExternalAuthSystem";
+
+ private static final String GET_PORTAL_APP_ROLES_QUERY = "getPortalAppRoles";
+
+ private static final String GET_ROLE_FUNCTION_QUERY = "getRoleFunction";
+
+ private static final String FUNCTION_CODE_PARAMS = "functionCode";
+
+ private static final String AND_FUNCTION_CD_EQUALS = " and function_cd = '";
+
+ private static final String OWNER = ".owner";
+
+ private static final String ADMIN = ".admin";
+
+ private static final String ACCOUNT_ADMINISTRATOR = ".Account_Administrator";
+
+ private static final String FUNCTION_PIPE = "|";
+
+ private static final String IS_NULL_STRING = "null";
+
+ private static final String EXTERNAL_AUTH_PERMS = "perms";
+
+ private static final String EXTERNAL_AUTH_ROLE_DESCRIPTION = "description";
+
+ private static final String IS_EMPTY_JSON_STRING = "{}";
+
+ private static final String CONNECTING_TO_EXTERNAL_AUTH_SYSTEM_LOG_MESSAGE = "Connecting to External Auth system";
+
+ private static final String APP_ROLE_ID = "appRoleId";
+
+ private static final String APP_ID = "appId";
+
+ private static final String PRIORITY = "priority";
+
+ private static final String ACTIVE = "active";
+
+ private static final String ROLE_NAME = "name";
+
+ private static final String ID = "id";
+
+ private static final String APP_ID_EQUALS = " app_id = ";
MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
@@ -113,6 +192,8 @@ public class ExternalAccessRolesServiceImplTest {
EPApp app = new EPApp();
app.setName("Test");
app.setImageUrl("test");
+ app.setNameSpace("com.test.app");
+ app.setCentralAuth(true);
app.setDescription("test");
app.setNotes("test");
app.setUrl("test");
@@ -125,7 +206,7 @@ public class ExternalAccessRolesServiceImplTest {
app.setUsername("test");
app.setAppPassword("test");
app.setOpen(false);
- app.setEnabled(false);
+ app.setEnabled(true);
app.setUebKey("test");
app.setUebSecret("test");
app.setUebTopicName("test");
@@ -133,38 +214,29 @@ public class ExternalAccessRolesServiceImplTest {
return app;
}
+ @SuppressWarnings("deprecation")
@Test
public void getAppRolesIfAppIsPortalTest() throws Exception {
List<EPRole> applicationRoles = new ArrayList<>();
- Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
+ Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 1);
assertEquals(expectedApplicationRoles, applicationRoles);
}
+ @SuppressWarnings("deprecation")
@Test
public void getAppRolesTest() throws Exception {
List<EPRole> applicationRoles = new ArrayList<>();
- Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
+ Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
List<EPRole> expectedApplicationRoles = externalAccessRolesServiceImpl.getAppRoles((long) 10);
assertEquals(expectedApplicationRoles, applicationRoles);
}
- // @SuppressWarnings("null")
- // @Test(expected = java.lang.Exception.class)
- // public void getAppRolesExceptionTest() throws Exception{
- // List<EPRole> applicationRoles = new ArrayList<>();
- // DataAccessService dataAccessService = null ;
- // Mockito.when(dataAccessService.getList(EPRole.class, "where app_id = 10",
- // null, null)).thenThrow(nullPointerException);
- // List<EPRole> expectedApplicationRoles =
- // externalAccessRolesServiceImpl.getAppRoles((long) 10);
- // assertEquals(expectedApplicationRoles,applicationRoles);
- // }
-
+ @SuppressWarnings("deprecation")
@Test
public void getAppExceptionTest() throws Exception {
List<EPApp> app = new ArrayList<>();
- Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
+ Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
.thenReturn(app);
List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
assertEquals(app, expectedapp);
@@ -174,11 +246,12 @@ public class ExternalAccessRolesServiceImplTest {
public void getAppErrorTest() throws Exception {
List<EPApp> appList = new ArrayList<>();
EPApp app = mockApp();
+ app.setEnabled(false);
appList.add(app);
final Map<String, String> appUebkeyParams = new HashMap<>();
appUebkeyParams.put("appKey", "test-ueb-key");
- Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
- .thenReturn(appList);
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
externalAccessRolesServiceImpl.getApp(uebKey);
}
@@ -190,7 +263,7 @@ public class ExternalAccessRolesServiceImplTest {
appList.add(app);
final Map<String, String> appUebkeyParams = new HashMap<>();
appUebkeyParams.put("appKey", "test-ueb-key");
- Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
.thenReturn(appList);
List<EPApp> expectedapp = externalAccessRolesServiceImpl.getApp(uebKey);
assertEquals(appList, expectedapp);
@@ -218,12 +291,13 @@ public class ExternalAccessRolesServiceImplTest {
roleList.add(ePRole);
final Map<String, String> appUebkeyParams = new HashMap<>();
appUebkeyParams.put("appKey", "test-ueb-key");
- Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
.thenReturn(appList);
final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
getPartnerAppRoleParams.put("appRoleId", role.getId());
- getPartnerAppRoleParams.put("appId", app.getId());
- Mockito.when(dataAccessService1.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null)).thenReturn(roleList);
+ getPartnerAppRoleParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
+ .thenReturn(roleList);
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
.thenReturn("Testurl");
ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
@@ -233,7 +307,6 @@ public class ExternalAccessRolesServiceImplTest {
assertTrue(externalAccessRolesServiceImpl.addRole(role, uebKey));
}
-
@Test
public void addRoleMethodNotAllowedTest() throws Exception {
HttpHeaders headers = new HttpHeaders();
@@ -255,12 +328,13 @@ public class ExternalAccessRolesServiceImplTest {
roleList.add(ePRole);
final Map<String, String> appUebkeyParams = new HashMap<>();
appUebkeyParams.put("appKey", "test-ueb-key");
- Mockito.when(dataAccessService1.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
.thenReturn(appList);
final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
getPartnerAppRoleParams.put("appRoleId", role.getId());
- getPartnerAppRoleParams.put("appId", app.getId());
- Mockito.when(dataAccessService1.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null)).thenReturn(roleList);
+ getPartnerAppRoleParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
+ .thenReturn(roleList);
Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_URL))
.thenReturn("Testurl");
ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.METHOD_NOT_ALLOWED);
@@ -303,7 +377,7 @@ public class ExternalAccessRolesServiceImplTest {
CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
domainCentralRoleFunction.setCode("menu_fun_code");
centralRoleFunctionList.add(domainCentralRoleFunction);
- Mockito.when(dataAccessService1.executeNamedQuery("getRoleFunction", params, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
.thenReturn(centralRoleFunctionList);
ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK);
Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
@@ -312,11 +386,12 @@ public class ExternalAccessRolesServiceImplTest {
PowerMockito.mockStatic(EcompPortalUtils.class);
Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
- Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class,
+ Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
"app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
-
+
assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
}
+
@Test
public void deleteCentralRoleFunctionFailTest() throws Exception {
final Map<String, String> params = new HashMap<>();
@@ -328,16 +403,14 @@ public class ExternalAccessRolesServiceImplTest {
domainCentralRoleFunction.setCode("menu_fun_code");
centralRoleFunctionList.add(domainCentralRoleFunction);
HttpClientErrorException httpClientErrorException = new HttpClientErrorException(HttpStatus.NOT_FOUND);
- Mockito.when(dataAccessService1.executeNamedQuery("getRoleFunction", params, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null))
.thenReturn(centralRoleFunctionList);
- ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.NOT_FOUND);
Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenThrow(httpClientErrorException);
HttpHeaders headers = new HttpHeaders();
PowerMockito.mockStatic(EcompPortalUtils.class);
Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
-
- Mockito.doNothing().when(dataAccessService1).deleteDomainObjects(EPAppRoleFunction.class,
+ Mockito.doNothing().when(dataAccessService).deleteDomainObjects(EPAppRoleFunction.class,
"app_id = " + app.getId() + " and function_cd = '" + "menu_fun_code" + "'", null);
boolean returnedValue = externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app);
@@ -354,71 +427,123 @@ public class ExternalAccessRolesServiceImplTest {
CentralV2RoleFunction domainCentralRoleFunction = new CentralV2RoleFunction();
domainCentralRoleFunction.setCode("menu_fun_code");
centralRoleFunctionList.add(domainCentralRoleFunction);
- Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionDetails", params, null))
.thenThrow(nullPointerException);
assertTrue(externalAccessRolesServiceImpl.deleteCentralRoleFunction("menu_fun_code", app));
}
@Test
- public void getUserTest() {
+ public void getUserTest() throws InvalidUserException {
List<EPUser> userList = new ArrayList<>();
EPUser user = mockUser.mockEPUser();
userList.add(user);
final Map<String, String> userParams = new HashMap<>();
userParams.put("org_user_id", "guestT");
- Mockito.when(dataAccessService1.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
+ Mockito.when(dataAccessService.executeNamedQuery("getEPUserByOrgUserId", userParams, null))
.thenReturn(userList);
List<EPUser> expectedUserList = externalAccessRolesServiceImpl.getUser("guestT");
assertEquals(expectedUserList, userList);
}
-
-
- public void saveCentralRoleFunctionTest() throws Exception {
- CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
- centralV2RoleFunction.setCode("menu_test");
+
+ @Test
+ public void saveCentralRoleFunctionNewTestForV2() throws Exception {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
EPApp app = mockApp();
app.setId((long) 1);
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
+ centralV2RoleFunction.setCode("test_code");
+ centralV2RoleFunction.setName("test name");
+ centralV2RoleFunction.setAppId(app.getId());
+ centralV2RoleFunction.setAction("*");
+ centralV2RoleFunction.setType("test_type");
final Map<String, String> params = new HashMap<>();
- params.put("functionCd", "menu_test");
params.put("appId", String.valueOf(1));
+
+ List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
+ appRoleFunc.add(centralV2RoleFunction);
+ params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
+ + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
+ Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ HttpHeaders headers = new HttpHeaders();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ JSONObject mockJsonObjectPerm = new JSONObject();
+ JSONObject mockJsonObjectFinalPerm = new JSONObject();
+ mockJsonObjectPerm.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm.put("instance", "com.test.app.test_code");
+ mockJsonObjectPerm.put("action", "*");
+ mockJsonObjectPerm.put("description", "test name");
+ List<JSONObject> mockJson = new ArrayList<>();
+ mockJson.add(mockJsonObjectPerm);
+ mockJsonObjectFinalPerm.put("perm", mockJson);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
+ Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
+ assertEquals(true, actual);
+ }
+
+ @Test
+ public void saveCentralRoleFunctionUpdateForV2Test() throws Exception {
PowerMockito.mockStatic(EcompPortalUtils.class);
+ EPApp app = mockApp();
+ app.setId((long) 1);
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
+ centralV2RoleFunction.setCode("test_code");
+ centralV2RoleFunction.setName("test name2");
+ centralV2RoleFunction.setAppId(app.getId());
+ centralV2RoleFunction.setAction("*");
+ centralV2RoleFunction.setType("test_type");
+ CentralV2RoleFunction centralV2RoleFunctionExisting = new CentralV2RoleFunction();
+ centralV2RoleFunctionExisting.setCode("test_code");
+ centralV2RoleFunctionExisting.setName("test name");
+ centralV2RoleFunctionExisting.setAppId(app.getId());
+ centralV2RoleFunctionExisting.setAction("*");
+ centralV2RoleFunctionExisting.setType("test_type");
+ final Map<String, String> params = new HashMap<>();
+ params.put("appId", String.valueOf(1));
+ List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
+ appRoleFunc.add(centralV2RoleFunctionExisting);
+ params.put(FUNCTION_CODE_PARAMS, centralV2RoleFunction.getType() + FUNCTION_PIPE
+ + centralV2RoleFunction.getCode() + FUNCTION_PIPE + centralV2RoleFunction.getAction());
+ Mockito.when(dataAccessService.executeNamedQuery("getRoleFunction", params, null)).thenReturn(appRoleFunc);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
HttpHeaders headers = new HttpHeaders();
Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
- List<CentralV2RoleFunction> appRoleFunc = new ArrayList<>();
- appRoleFunc.add(centralV2RoleFunction);
- Mockito.when(dataAccessService1.executeNamedQuery("getAppFunctionDetails", params,
- null)).thenReturn(appRoleFunc);
- ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.OK);
+ JSONObject mockJsonObjectPerm = new JSONObject();
+ JSONObject mockJsonObjectFinalPerm = new JSONObject();
+ mockJsonObjectPerm.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm.put("instance", "test_code");
+ mockJsonObjectPerm.put("action", "*");
+ mockJsonObjectPerm.put("description", "test name");
+ List<JSONObject> mockJson = new ArrayList<>();
+ mockJson.add(mockJsonObjectPerm);
+ mockJsonObjectFinalPerm.put("perm", mockJson);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
- Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> updateResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.PUT),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(updateResponse);
+ Boolean actual = externalAccessRolesServiceImpl.saveCentralRoleFunction(centralV2RoleFunction, app);
+ assertEquals(true, actual);
}
-
-// @Test
-// public void getAllAppUsersIfAppIsPortalTest() throws Exception
-// {
-// List<EPApp> expectedapps = new ArrayList<>();
-// EPApp app = new EPApp();
-// app.setEnabled(true);
-// app.setId((long) 1);
-// expectedapps.add(app);
-// List<EPRole> applicationRoles = new ArrayList<>();
-// Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
-// Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)).thenReturn(expectedapps);
-// externalAccessRolesServiceImpl.getAllAppUsers(uebKey);
-// }
-
-
+
+ @SuppressWarnings("deprecation")
@Test(expected = IndexOutOfBoundsException.class)
- public void getAllAppUsersTest() throws Exception
- {
- List<EPApp> expectedapps = new ArrayList<>();
+ public void getAllAppUsersTest() throws Exception {
+ List<EPApp> expectedapps = new ArrayList<>();
EPApp app = new EPApp();
app.setEnabled(true);
app.setId((long) 10);
expectedapps.add(app);
List<EPRole> applicationRoles = new ArrayList<>();
- Mockito.when(dataAccessService1.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
- Mockito.when(dataAccessService1.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null)).thenReturn(expectedapps);
+ Mockito.when(dataAccessService.getList(EPRole.class, "test", null, null)).thenReturn(applicationRoles);
+ Mockito.when(dataAccessService.getList(EPApp.class, " where ueb_key = '" + uebKey + "'", null, null))
+ .thenReturn(expectedapps);
final Map<String, Long> appParams = new HashMap<>();
appParams.put("appId", app.getId());
List<EcompUserRoles> userList = new ArrayList<>();
@@ -426,31 +551,804 @@ public class ExternalAccessRolesServiceImplTest {
ecompUserRoles.setOrgUserId("guestT");
ecompUserRoles.setRoleId((long) 1);
ecompUserRoles.setRoleName("test");
-
+
EcompUserRoles ecompUserRoles2 = new EcompUserRoles();
ecompUserRoles2.setOrgUserId("guestT");
ecompUserRoles2.setRoleId((long) 2);
ecompUserRoles2.setRoleName("test new");
userList.add(ecompUserRoles);
userList.add(ecompUserRoles2);
-
- Mockito.when(dataAccessService1.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
+
+ Mockito.when(dataAccessService.executeNamedQuery("ApplicationUserRoles", appParams, null)).thenReturn(userList);
List<EcompUser> usersfinalList = externalAccessRolesServiceImpl.getAllAppUsers(uebKey);
assertEquals(usersfinalList.get(0).getRoles().size(), 2);
}
-
+
@Test
- public void getGlobalRolesOfPortalTest()
- {
- Mockito.when(dataAccessService1.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null);
+ public void getGlobalRolesOfPortalTest() {
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(null);
assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), null);
}
-
+
@Test
- public void getGlobalRolesOfPortalExceptionTest()
- {
+ public void getGlobalRolesOfPortalExceptionTest() {
List<EPRole> globalRoles = new ArrayList<>();
- Mockito.when(dataAccessService1.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenThrow(nullPointerException);
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null))
+ .thenThrow(nullPointerException);
assertEquals(externalAccessRolesServiceImpl.getGlobalRolesOfPortal(), globalRoles);
}
+
+ @Test
+ public void getRolesForAppTest() throws Exception {
+ EPApp app = mockApp();
+ app.setId(2l);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> applicationRoles = new ArrayList<>();
+ EPRole appRole = new EPRole();
+ appRole.setActive(true);
+ appRole.setAppId(app.getId());
+ appRole.setAppRoleId(100l);
+ appRole.setId(10l);
+ appRole.setName("test");
+ applicationRoles.add(appRole);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null))
+ .thenReturn(applicationRoles);
+ List<CentralV2RoleFunction> cenRoleFuncList = new ArrayList<>();
+ CentralV2RoleFunction v2RoleFunction = new CentralV2RoleFunction();
+ v2RoleFunction.setAppId(app.getId());
+ v2RoleFunction.setCode("test_type|test_code|*");
+ v2RoleFunction.setName("test name");
+ cenRoleFuncList.add(v2RoleFunction);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("roleId", appRole.getId());
+ params.put(APP_ID, appList.get(0).getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionList", params, null))
+ .thenReturn(cenRoleFuncList);
+ List<GlobalRoleWithApplicationRoleFunction> mockGlobalRoles = new ArrayList<>();
+ GlobalRoleWithApplicationRoleFunction mockGlobalRole = new GlobalRoleWithApplicationRoleFunction();
+ mockGlobalRole.setActive(true);
+ mockGlobalRole.setAppId(app.getId());
+ mockGlobalRole.setRoleId(1111l);
+ mockGlobalRole.setRoleName("global_test");
+ mockGlobalRole.setFunctionCd("test_type|test_code|*");
+ mockGlobalRole.setFunctionName("test name");
+ mockGlobalRoles.add(mockGlobalRole);
+ Map<String, Long> params2 = new HashMap<>();
+ params2.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleWithApplicationRoleFunctions", params2, null))
+ .thenReturn(mockGlobalRoles);
+ List<EPRole> globalRoles = new ArrayList<>();
+ EPRole globalRole = new EPRole();
+ globalRole.setName("global_test");
+ globalRole.setId(1111l);
+ globalRole.setActive(true);
+ globalRoles.add(globalRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
+ List<CentralV2Role> expected = new ArrayList<>();
+ CentralV2Role cenV2Role = new CentralV2Role();
+ CentralV2Role cenV2Role2 = new CentralV2Role();
+ expected.add(cenV2Role);
+ expected.add(cenV2Role2);
+ List<CentralV2Role> actual = externalAccessRolesServiceImpl.getRolesForApp(app.getUebKey());
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @Test
+ public void saveRoleForPortalApplicationNewTest() throws Exception {
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ EPApp app = mockApp();
+ app.setId(1l);
+ Role addRoleTest = new Role();
+ addRoleTest.setActive(true);
+ addRoleTest.setName("Test");
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ HttpHeaders headers = new HttpHeaders();
+ JSONObject mockJsonObjectRole = new JSONObject();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectRole.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ final Map<String, String> epAppPortalRoleParams = new HashMap<>();
+ epAppPortalRoleParams.put(APP_ROLE_NAME_PARAM, addRoleTest.getName());
+ List<EPRole> getRoleCreated = new ArrayList<>();
+ EPRole roleCreate = new EPRole();
+ roleCreate.setActive(true);
+ roleCreate.setId(10l);
+ roleCreate.setName("test");
+ getRoleCreated.add(roleCreate);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_PORTAL_APP_ROLES_QUERY, epAppPortalRoleParams, null))
+ .thenReturn(getRoleCreated);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
+ ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
+ app.getUebKey());
+ ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveRoleForPortalApplicationUpdateTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(1l);
+ Role addRoleTest = new Role();
+ SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
+ RoleFunction roleFunc= new RoleFunction();
+ roleFunc.setName("Test Name");
+ roleFunc.setCode("test_type|test_instance|*");
+ RoleFunction roleFunc2 = new RoleFunction();
+ roleFunc2.setName("Test Name3");
+ roleFunc2.setCode("test_type3|test_instance3|*");
+ roleFuncSet.add(roleFunc);
+ roleFuncSet.add(roleFunc2);
+ addRoleTest.setActive(true);
+ addRoleTest.setName("Test2");
+ addRoleTest.setId(2l);
+ addRoleTest.setRoleFunctions(roleFuncSet);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> globalRoles = new ArrayList<>();
+ EPRole globalRole = new EPRole();
+ globalRole.setName("global_test");
+ globalRole.setId(1111l);
+ globalRole.setActive(true);
+ globalRoles.add(globalRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setActive(true);
+ epRoleList.add(getEPRole);
+ final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
+ getPortalAppRoleParams.put("roleId", addRoleTest.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
+ .thenReturn(epRoleList);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ HttpHeaders headers = new HttpHeaders();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ JSONObject mockJsonObjectRole = new JSONObject();
+ JSONObject mockJsonObjectFinalRole = new JSONObject();
+ JSONObject mockJsonObjectPerm1 = new JSONObject();
+ JSONObject mockJsonObjectPerm2 = new JSONObject();
+ mockJsonObjectPerm1.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm1.put("instance", "test_instance");
+ mockJsonObjectPerm1.put("action", "*");
+ mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
+ mockJsonObjectPerm2.put("instance", "test_instance2");
+ mockJsonObjectPerm2.put("action", "*");
+ List<JSONObject> permsList = new ArrayList<>();
+ permsList.add(mockJsonObjectPerm1);
+ permsList.add(mockJsonObjectPerm2);
+ mockJsonObjectRole.put("name", "com.test.app.Test");
+ mockJsonObjectRole.put("perms", permsList);
+ mockJsonObjectRole.put("description",
+ "{\"id\":\"2\",\"name\":\"Test\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"null\",\"appRoleId\":\"null\"}");
+ List<JSONObject> roleList = new ArrayList<>();
+ roleList.add(mockJsonObjectRole);
+ mockJsonObjectFinalRole.put("role", roleList);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> delResponse = new ResponseEntity<>(roleList.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(delResponse);
+ ResponseEntity<String> addRoleResponse = new ResponseEntity<>(HttpStatus.CREATED);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addRoleResponse);
+ final Map<String, String> params = new HashMap<>();
+ params.put("uebKey", app.getUebKey());
+ params.put("roleId", String.valueOf(getEPRole.getId()));
+ List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
+ BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
+ bulkUploadUserRoles.setAppNameSpace("com.test.app");
+ bulkUploadUserRoles.setOrgUserId("guestT");
+ bulkUploadUserRoles.setRoleName("Test2");
+ userRolesList.add(bulkUploadUserRoles);
+ Mockito.when(dataAccessService.executeNamedQuery("getBulkUsersForSingleRole", params, null))
+ .thenReturn(userRolesList);
+ Mockito.when(
+ EPCommonSystemProperties.containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn(true);
+ Mockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN)).thenReturn("@test.com");
+ ResponseEntity<String> mockBulkUsersUpload = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(mockBulkUsersUpload);
+ List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
+ final Map<String, Long> appRoleFuncsParams = new HashMap<>();
+ appRoleFuncsParams.put("appId", app.getId());
+ appRoleFuncsParams.put("roleId", getEPRole.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null)).thenReturn(appRoleFunctionList);
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
+ final Map<String, String> getAppFunctionParams = new HashMap<>();
+ getAppFunctionParams.put("appId", String.valueOf(app.getId()));
+ getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
+ List<CentralV2RoleFunction> v2RoleFunction = new ArrayList<>();
+ CentralV2RoleFunction v2RoleFunction1 = new CentralV2RoleFunction("test_type|test_instance|*", "Test Name");
+ v2RoleFunction.add(v2RoleFunction1);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null)).thenReturn(v2RoleFunction);
+ final Map<String, String> getAppFunctionParams2 = new HashMap<>();
+ getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
+ getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
+ List<CentralV2RoleFunction> v2RoleFunction2 = new ArrayList<>();
+ CentralV2RoleFunction v2RoleFunction3 = new CentralV2RoleFunction("test_type3|test_instance3|*", "Test Name3");
+ v2RoleFunction2.add(v2RoleFunction3);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null)).thenReturn(v2RoleFunction2);
+ ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
+ app.getUebKey());
+ ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void saveGlobalRoleFunctionsForPartnerApplicationUpdateTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ Role addRoleTest = new Role();
+ SortedSet<RoleFunction> roleFuncSet = new TreeSet<>();
+ RoleFunction roleFunc= new RoleFunction();
+ roleFunc.setName("Test Name");
+ roleFunc.setCode("test_type|test_instance|*");
+ RoleFunction roleFunc2 = new RoleFunction();
+ roleFunc2.setName("Test Name3");
+ roleFunc2.setCode("test_type3|test_instance3|*");
+ roleFuncSet.add(roleFunc);
+ roleFuncSet.add(roleFunc2);
+ addRoleTest.setActive(true);
+ addRoleTest.setName("global_test");
+ addRoleTest.setId(1111l);
+ addRoleTest.setRoleFunctions(roleFuncSet);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> globalRoles = new ArrayList<>();
+ EPRole globalRole = new EPRole();
+ globalRole.setName("global_test");
+ globalRole.setId(1111l);
+ globalRole.setActive(true);
+ EPRole globalRole2 = new EPRole();
+ globalRole2.setName("global_test2");
+ globalRole2.setId(2222l);
+ globalRole2.setActive(true);
+ globalRoles.add(globalRole);
+ globalRoles.add(globalRole2);
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
+ List<EPRole> getGlobalRoles = new ArrayList<>();
+ EPRole getEPGlobalRole = new EPRole();
+ getEPGlobalRole.setName("global_test");
+ getEPGlobalRole.setId(1111l);
+ getEPGlobalRole.setActive(true);
+ getGlobalRoles.add(getEPGlobalRole);
+ final Map<String, Long> getPortalAppRoleParams = new HashMap<>();
+ getPortalAppRoleParams.put("roleId", globalRole.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPortalAppRoleParams, null))
+ .thenReturn(getGlobalRoles);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ Mockito.when(epAppCommonServiceImpl.getApp(PortalConstants.PORTAL_APP_ID)).thenReturn(app);
+ JSONObject mockJsonObjectPerm = new JSONObject();
+ JSONObject mockJsonObjectPerm2 = new JSONObject();
+ JSONObject mockJsonObjectPerm3 = new JSONObject();
+ JSONObject mockJsonObjectFinalPerm = new JSONObject();
+ mockJsonObjectPerm.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm.put("instance", "test_instance");
+ mockJsonObjectPerm.put("action", "*");
+ mockJsonObjectPerm.put("description", "Test Name");
+ mockJsonObjectPerm2.put("type", "com.test.app.access");
+ mockJsonObjectPerm2.put("instance", "test_instance2");
+ mockJsonObjectPerm2.put("action", "*");
+ mockJsonObjectPerm2.put("description", "Test Name2");
+ mockJsonObjectPerm3.put("type", "com.test.app.test_type3");
+ mockJsonObjectPerm3.put("instance", "test_instance3");
+ mockJsonObjectPerm3.put("action", "*");
+ mockJsonObjectPerm3.put("description", "Test Name3");
+ List<JSONObject> mockJson = new ArrayList<>();
+ mockJson.add(mockJsonObjectPerm);
+ mockJson.add(mockJsonObjectPerm2);
+ mockJson.add(mockJsonObjectPerm3);
+ mockJsonObjectFinalPerm.put("perm", mockJson);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
+ final Map<String, Long> epAppRoleFuncParams = new HashMap<>();
+ epAppRoleFuncParams.put("requestedAppId", app.getId());
+ epAppRoleFuncParams.put("roleId",globalRole.getId());
+ List<GlobalRoleWithApplicationRoleFunction> globalRoleFunctionList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRoleForRequestedApp", epAppRoleFuncParams, null)).thenReturn(globalRoleFunctionList);
+ final Map<String, Long> appRoleFuncsParams = new HashMap<>();
+ appRoleFuncsParams.put("appId", app.getId());
+ appRoleFuncsParams.put("roleId", globalRole.getId());
+ List<EPAppRoleFunction> appRoleFunctionList = new ArrayList<>();
+ EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
+ epAppRoleFunction.setAppId(app.getId());
+ epAppRoleFunction.setRoleAppId("1");
+ epAppRoleFunction.setCode("test");
+ epAppRoleFunction.setRoleId(1111l);
+ appRoleFunctionList.add(epAppRoleFunction);
+ Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null)).thenReturn(appRoleFunctionList);
+ final Map<String, String> getAppFunctionParams = new HashMap<>();
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc.getCode())).thenReturn("test_instance");
+ Mockito.when(EcompPortalUtils.getFunctionCode(roleFunc2.getCode())).thenReturn("test_instance3");
+ getAppFunctionParams.put("appId", String.valueOf(app.getId()));
+ getAppFunctionParams.put(FUNCTION_CODE_PARAMS, roleFunc.getCode());
+ List<CentralV2RoleFunction> roleFunction = new ArrayList<>();
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, roleFunc.getCode(), roleFunc.getName(), app.getId(), null);
+ roleFunction.add(centralV2RoleFunction);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams, null)).thenReturn(roleFunction);
+ final Map<String, String> getAppFunctionParams2 = new HashMap<>();
+ getAppFunctionParams2.put("appId", String.valueOf(app.getId()));
+ getAppFunctionParams2.put(FUNCTION_CODE_PARAMS, roleFunc2.getCode());
+ List<CentralV2RoleFunction> roleFunction2 = new ArrayList<>();
+ CentralV2RoleFunction centralV2RoleFunction2 = new CentralV2RoleFunction(null, roleFunc2.getCode(), roleFunc2.getName(), app.getId(), null);
+ roleFunction2.add(centralV2RoleFunction2);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_FUNCTION_QUERY, getAppFunctionParams2, null)).thenReturn(roleFunction2);
+ ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.saveRoleForApplication(addRoleTest,
+ app.getUebKey());
+ ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void syncRoleFunctionFromExternalAccessSystemTest() {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ JSONObject mockJsonObjectFinalPerm = new JSONObject();
+ JSONObject mockJsonObjectPerm = new JSONObject();
+ JSONObject mockJsonObjectPerm2 = new JSONObject();
+ JSONObject mockJsonObjectPerm3 = new JSONObject();
+ mockJsonObjectPerm.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm.put("instance", "test_instance");
+ mockJsonObjectPerm.put("action", "*");
+ mockJsonObjectPerm.put("description", "test_name");
+ List<String> rolePermList = new ArrayList<>();
+ rolePermList.add("com.test.app|test1");
+ mockJsonObjectPerm.put("roles", rolePermList);
+ mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
+ mockJsonObjectPerm2.put("instance", "test_instance2");
+ mockJsonObjectPerm2.put("action", "*");
+ mockJsonObjectPerm2.put("description", "test_name2");
+ mockJsonObjectPerm3.put("type", "com.test.app.access");
+ mockJsonObjectPerm3.put("instance", "test_instance3");
+ mockJsonObjectPerm3.put("action", "*");
+ mockJsonObjectPerm3.put("description", "test_name3");
+ List<JSONObject> permsList = new ArrayList<>();
+ permsList.add(mockJsonObjectPerm);
+ permsList.add(mockJsonObjectPerm2);
+ permsList.add(mockJsonObjectPerm3);
+ mockJsonObjectFinalPerm.put("perm", permsList);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalPerm.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ final Map<String, Long> params = new HashMap<>();
+ params.put(APP_ID, app.getId());
+ List<CentralV2RoleFunction> appFunctions = new ArrayList<>();
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*", "test_name", app.getId(), null);
+ appFunctions.add(centralV2RoleFunction);
+ Mockito.when(dataAccessService.executeNamedQuery("getAllRoleFunctions", params,null)).thenReturn(appFunctions);
+ List<EPRole> globalRoles = new ArrayList<>();
+ EPRole globalRole = new EPRole();
+ globalRole.setName("global_test");
+ globalRole.setId(1111l);
+ globalRole.setActive(true);
+ globalRoles.add(globalRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getGlobalRolesOfPortal", null, null)).thenReturn(globalRoles);
+ List<EPRole> getCurrentRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("test1");
+ getEPRole.setId(2l);
+ getEPRole.setActive(true);
+ EPRole getEPRole2 = new EPRole();
+ getEPRole2.setName("global_test");
+ getEPRole2.setId(1111l);
+ getEPRole2.setActive(true);
+ getCurrentRoleList.add(getEPRole);
+ getCurrentRoleList.add(getEPRole2);
+ Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRolesList", null, null)).thenReturn(getCurrentRoleList);
+ final Map<String, String> appSyncFuncsParams = new HashMap<>();
+ appSyncFuncsParams.put("appId", String.valueOf(app.getId()));
+ appSyncFuncsParams.put("functionCd", "");
+ List<CentralV2RoleFunction> roleFunctionList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams,
+ null)).thenReturn(roleFunctionList);
+ String code = centralV2RoleFunction.getCode();
+ appSyncFuncsParams.put("functionCd", code);
+ CentralV2RoleFunction getCentralV2RoleFunction = new CentralV2RoleFunction(null, "test_type|test_instance|*", "test_name", app.getId(), null);
+ roleFunctionList.add(getCentralV2RoleFunction);
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams,
+ null)).thenReturn(roleFunctionList);
+ final Map<String, String> appRoleFuncParams = new HashMap<>();
+ appRoleFuncParams.put("functionCd", roleFunctionList.get(0).getCode());
+ appRoleFuncParams.put("appId", String.valueOf(app.getId()));
+ Mockito.when(dataAccessService.executeNamedQuery("getCurrentAppRoleFunctions",
+ appRoleFuncParams, null)).thenReturn(new ArrayList<LocalRole>());
+ Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app", app.getNameSpace())).thenReturn(true);
+ Mockito.when(EcompPortalUtils.getFunctionCode("test_type2|test_instance2|*")).thenReturn("test_instance2");
+ appSyncFuncsParams.put("functionCd", "test_instance2");
+ List<CentralV2RoleFunction> roleFunctionList2 = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams,
+ null)).thenReturn(roleFunctionList2);
+ String code2 = "test_type2|test_instance2|*";
+ appSyncFuncsParams.put("functionCd", code2);
+ CentralV2RoleFunction getCentralV2RoleFunction2 = new CentralV2RoleFunction(null, "test_type2|test_instance2|*", "test_name2", app.getId(), null);
+ roleFunctionList2.add(getCentralV2RoleFunction2);
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appSyncFuncsParams,
+ null)).thenReturn(roleFunctionList2);
+ externalAccessRolesServiceImpl.syncRoleFunctionFromExternalAccessSystem(app);
+ }
+
+ @Test
+ public void syncApplicationRolesWithEcompDBTest(){
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ JSONObject mockJsonObjectRole = new JSONObject();
+ JSONObject mockJsonObjectRole2 = new JSONObject();
+ JSONObject mockJsonObjectFinalRole = new JSONObject();
+ JSONObject mockJsonObjectPerm1 = new JSONObject();
+ JSONObject mockJsonObjectPerm2 = new JSONObject();
+ mockJsonObjectPerm1.put("type", "com.test.app.test_type");
+ mockJsonObjectPerm1.put("instance", "test_instance");
+ mockJsonObjectPerm1.put("action", "*");
+ mockJsonObjectPerm2.put("type", "com.test.app.test_type2");
+ mockJsonObjectPerm2.put("instance", "test_instance2");
+ mockJsonObjectPerm2.put("action", "*");
+ List<JSONObject> permsList = new ArrayList<>();
+ permsList.add(mockJsonObjectPerm1);
+ permsList.add(mockJsonObjectPerm2);
+ mockJsonObjectRole.put("name", "com.test.app.Test");
+ mockJsonObjectRole.put("perms", permsList);
+ mockJsonObjectRole.put("description",
+ "{\"id\":\"2\",\"name\":\"test1\",\"active\":\"true\",\"priority\":\"null\",\"appId\":\"2\",\"appRoleId\":\"2\"}");
+ mockJsonObjectRole2.put("name", "com.test.app.Test2");
+ List<JSONObject> permsList2 = new ArrayList<>();
+ permsList2.add(mockJsonObjectPerm1);
+ mockJsonObjectRole2.put("perms", permsList2);
+ List<JSONObject> roleList = new ArrayList<>();
+ roleList.add(mockJsonObjectRole);
+ roleList.add(mockJsonObjectRole2);
+ mockJsonObjectFinalRole.put("role", roleList);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObjectFinalRole.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ List<EPRole> getCurrentRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppId(app.getId());
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ EPRole getEPRole2 = new EPRole();
+ getEPRole2.setName("Test3");
+ getEPRole2.setId(3l);
+ getEPRole.setAppId(app.getId());
+ getEPRole.setAppRoleId(3l);
+ getEPRole2.setActive(true);
+ getCurrentRoleList.add(getEPRole);
+ getCurrentRoleList.add(getEPRole2);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null)).thenReturn(getCurrentRoleList);
+ Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type", app.getNameSpace())).thenReturn(true);
+ Mockito.when(EcompPortalUtils.checkNameSpaceMatching("com.test.app.test_type2", app.getNameSpace())).thenReturn(true);
+ List<EPAppRoleFunction> appRoleFunctions = new ArrayList<>();
+ EPAppRoleFunction epAppRoleFunction = new EPAppRoleFunction();
+ epAppRoleFunction.setAppId(app.getId());
+ epAppRoleFunction.setCode("test_type|test_instance|*");
+ epAppRoleFunction.setRoleId(getEPRole.getId());
+ appRoleFunctions.add(epAppRoleFunction);
+ final Map<String, Long> appRoleFuncsParams = new HashMap<>();
+ appRoleFuncsParams.put("appId", app.getId());
+ appRoleFuncsParams.put("roleId", Long.valueOf(getEPRole.getId()));
+ Mockito.when(dataAccessService.executeNamedQuery("getAppRoleFunctionOnRoleIdandAppId", appRoleFuncsParams, null)).thenReturn(appRoleFunctions);
+ List<CentralV2RoleFunction> getV2RoleFunction = new ArrayList<>();
+ final Map<String, String> appFuncsParams = new HashMap<>();
+ appFuncsParams.put("appId", String.valueOf(app.getId()));
+ appFuncsParams.put("functionCd", "test_instance2");
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null)).thenReturn(getV2RoleFunction);
+ appFuncsParams.put("functionCd", "test_type2|test_instance2|*");
+ CentralV2RoleFunction centralV2RoleFunction = new CentralV2RoleFunction();
+ centralV2RoleFunction.setAppId(app.getId());
+ centralV2RoleFunction.setCode("test_type2|test_instance2|*");
+ centralV2RoleFunction.setName("test_name2");
+ getV2RoleFunction.add(centralV2RoleFunction);
+ final Map<String, String> extRoleParams = new HashMap<>();
+ List<EPRole> roleListDeactivate = new ArrayList<>();
+ extRoleParams.put(APP_ROLE_NAME_PARAM, "Test3");
+ extRoleParams.put(APP_ID, app.getId().toString());
+ EPRole getEPRoleDeactivate = new EPRole();
+ getEPRoleDeactivate.setName("Test3");
+ getEPRoleDeactivate.setId(3l);
+ getEPRoleDeactivate.setAppId(app.getId());
+ getEPRoleDeactivate.setAppRoleId(3l);
+ roleListDeactivate.add(getEPRoleDeactivate);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, extRoleParams, null)).thenReturn(roleListDeactivate);
+ Mockito.when(dataAccessService.executeNamedQuery("getAppFunctionOnCodeAndAppId", appFuncsParams, null)).thenReturn(getV2RoleFunction);
+ List<EPRole> updateLocalFromExtAuth = new ArrayList<>();
+ updateLocalFromExtAuth.add(getEPRole);
+ final Map<String, String> roleParams = new HashMap<>();
+ roleParams.put(APP_ROLE_NAME_PARAM, getEPRole.getName());
+ roleParams.put(APP_ID, app.getId().toString());
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, roleParams, null)).thenReturn(updateLocalFromExtAuth);
+ roleParams.put(APP_ROLE_NAME_PARAM, getEPRole2.getName());
+ List<EPRole> updateLocalFromExtAuth2 = new ArrayList<>();
+ updateLocalFromExtAuth.add(getEPRole);
+ Mockito.when(dataAccessService.executeNamedQuery("getRoletoUpdateInExternalAuthSystem", roleParams, null)).thenReturn(updateLocalFromExtAuth2);
+ final Map<String, String> globalRoleParams = new HashMap<>();
+ globalRoleParams.put("appId", String.valueOf(app.getId()));
+ globalRoleParams.put("appRoleName", "Test2");
+ List<EPRole> addNewRoleList = new ArrayList<>();
+ EPRole addRoleInLocal = new EPRole();
+ addRoleInLocal.setName("Test2");
+ addRoleInLocal.setId(4l);
+ addRoleInLocal.setAppId(app.getId());
+ addRoleInLocal.setActive(true);
+ addNewRoleList.add(addRoleInLocal);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, globalRoleParams, null)).thenReturn(addNewRoleList);
+ final Map<String, String> params = new HashMap<>();
+ params.put(APP_ROLE_NAME_PARAM, "Test2");
+ params.put(APP_ID, app.getId().toString());
+ addRoleInLocal.setAppRoleId(4l);
+ addNewRoleList.add(addRoleInLocal);
+ Mockito.when(dataAccessService.executeNamedQuery(GET_ROLE_TO_UPDATE_IN_EXTERNAL_AUTH_SYSTEM, params, null)).thenReturn(addNewRoleList);
+ externalAccessRolesServiceImpl.syncApplicationRolesWithEcompDB(app);
+ }
+
+ @Test
+ public void deleteDependencyRoleRecord() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ epRoleList.add(getEPRole);
+ final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
+ getPartnerAppRoleParams.put("appRoleId", getEPRole.getId());
+ getPartnerAppRoleParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null))
+ .thenReturn(epRoleList);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ JSONObject getUser = new JSONObject();
+ getUser.put("name", "com.test.app.test1");
+ ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
+ Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
+ ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l, app.getUebKey(), user.getOrgUserId());
+ ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void deleteDependencyRoleRecordForPortal() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ SQLQuery SqlQuery = Mockito.mock(SQLQuery.class);
+ EPApp app = mockApp();
+ app.setId(1l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ epRoleList.add(getEPRole);
+ final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
+ getPartnerAppRoleParams.put("roleId", getEPRole.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPortalAppRoleByRoleId", getPartnerAppRoleParams, null))
+ .thenReturn(epRoleList);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ JSONObject getUser = new JSONObject();
+ getUser.put("name", "com.test.app.test1");
+ ResponseEntity<String> getResponse = new ResponseEntity<>(getUser.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> DelResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(DelResponse);
+ Mockito.when(session.createSQLQuery(Matchers.anyString())).thenReturn(SqlQuery);
+ ExternalRequestFieldsValidator actual = externalAccessRolesServiceImpl.deleteDependencyRoleRecord(2l, app.getUebKey(), user.getOrgUserId());
+ ExternalRequestFieldsValidator expected = new ExternalRequestFieldsValidator(true, "");
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void bulkUploadFunctionsTest() throws Exception {
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<RoleFunction> roleFuncList = new ArrayList<>();
+ RoleFunction roleFunc = new RoleFunction();
+ roleFunc.setCode("test_code");
+ roleFunc.setName("test_name");
+ RoleFunction roleFunc2 = new RoleFunction();
+ roleFunc2.setCode("test_code2");
+ roleFunc2.setName("test_name2");
+ roleFuncList.add(roleFunc);
+ roleFuncList.add(roleFunc2);
+ Mockito.when(dataAccessService.executeNamedQuery("getAllFunctions", null, null)).thenReturn(roleFuncList);
+ JSONObject perm = new JSONObject();
+ JSONObject permList = new JSONObject();
+ perm.put("type", app.getNameSpace()+".access");
+ perm.put("instance", "type_instance");
+ perm.put("action", "*");
+ List<JSONObject> addPerms = new ArrayList<>();
+ addPerms.add(perm);
+ permList.put("perm", addPerms);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(permList.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Integer actual = externalAccessRolesServiceImpl.bulkUploadFunctions(app.getUebKey());
+ Integer expected = 2;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void bulkUploadRolesTest() throws Exception{
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<EPRole> epRoleList = new ArrayList<>();
+ EPRole getEPRole = new EPRole();
+ getEPRole.setName("Test");
+ getEPRole.setId(2l);
+ getEPRole.setAppRoleId(2l);
+ getEPRole.setActive(true);
+ EPRole getEPRole2 = new EPRole();
+ getEPRole2.setName("Test2");
+ getEPRole2.setId(3l);
+ getEPRole2.setAppRoleId(3l);
+ getEPRole2.setActive(true);
+ epRoleList.add(getEPRole);
+ epRoleList.add(getEPRole2);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRolesList", appParams, null)).thenReturn(epRoleList);
+ List<EPRole> epRoleList1 = new ArrayList<>();
+ EPRole ePRole = new EPRole();
+ ePRole.setName("Test");
+ ePRole.setId(2l);
+ ePRole.setAppRoleId(2l);
+ ePRole.setActive(true);
+ epRoleList1.add(ePRole);
+ final Map<String, Long> getPartnerAppRoleParams = new HashMap<>();
+ getPartnerAppRoleParams.put("appRoleId", ePRole.getId());
+ getPartnerAppRoleParams.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams, null)).thenReturn(epRoleList1);
+ List<EPRole> epRoleList2 = new ArrayList<>();
+ EPRole ePRole2 = new EPRole();
+ ePRole2.setName("Test2");
+ ePRole2.setId(3l);
+ ePRole2.setAppRoleId(3l);
+ ePRole2.setActive(true);
+ epRoleList2.add(ePRole2);
+ final Map<String, Long> getPartnerAppRoleParams2 = new HashMap<>();
+ getPartnerAppRoleParams2.put("appRoleId", ePRole2.getId());
+ getPartnerAppRoleParams2.put("appId", app.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getPartnerAppRoleByRoleId", getPartnerAppRoleParams2, null)).thenReturn(epRoleList2);
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Integer actual = externalAccessRolesServiceImpl.bulkUploadRoles(app.getUebKey());
+ Integer expected = 2;
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void bulkUploadUserRolesTest() throws Exception{
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(SystemProperties.class);
+ EPApp app = mockApp();
+ app.setId(2l);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> appList = new ArrayList<>();
+ final Map<String, String> appUebkeyParams = new HashMap<>();
+ appList.add(app);
+ appUebkeyParams.put("appKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getMyAppDetailsByUebKey", appUebkeyParams, null))
+ .thenReturn(appList);
+ List<BulkUploadUserRoles> userRolesList = new ArrayList<>();
+ BulkUploadUserRoles bulkUploadUserRoles = new BulkUploadUserRoles();
+ bulkUploadUserRoles.setAppNameSpace(app.getName());
+ bulkUploadUserRoles.setOrgUserId(user.getOrgUserId());
+ bulkUploadUserRoles.setRoleName("Test1");
+ BulkUploadUserRoles bulkUploadUserRoles2 = new BulkUploadUserRoles();
+ bulkUploadUserRoles2.setAppNameSpace(app.getName());
+ bulkUploadUserRoles2.setOrgUserId(user.getOrgUserId());
+ bulkUploadUserRoles2.setRoleName("Test2");
+ userRolesList.add(bulkUploadUserRoles);
+ userRolesList.add(bulkUploadUserRoles2);
+ final Map<String, String> appParams = new HashMap<>();
+ appParams.put("uebKey", app.getUebKey());
+ Mockito.when(dataAccessService.executeNamedQuery("getBulkUserRoles", appParams, null)).thenReturn(userRolesList);
+ ResponseEntity<String> postResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(postResponse);
+ Integer actual = externalAccessRolesServiceImpl.bulkUploadUserRoles(app.getUebKey());
+ Integer expected = 2;
+ assertEquals(expected, actual);
+ }
+
+
}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java
deleted file mode 100644
index c954fcbd..00000000
--- a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/FunctionalMenuServiceImplTest.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.onap.portalapp.portal.service;
-/*-
- * ============LICENSE_START==========================================
- * ONAP Portal
- * ===================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ===================================================================
- *
- * Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the "License");
- * you may not use this software except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
- * you may not use this documentation except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * https://creativecommons.org/licenses/by/4.0/
- *
- * Unless required by applicable law or agreed to in writing, documentation
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * ============LICENSE_END============================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- */
-//package org.openecomp.portalapp.portal.test.service;
-//
-//import static org.junit.Assert.assertTrue;
-//
-//import java.util.ArrayList;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//
-//import org.junit.Test;
-//import org.openecomp.portalapp.portal.service.FunctionalMenuService;
-//import org.openecomp.portalapp.portal.transport.BusinessCardApplicationRole;
-//import org.openecomp.portalapp.portal.transport.FunctionalMenuRole;
-//import org.openecomp.portalapp.test.framework.ApplicationCommonContextTestSuite;
-//import org.springframework.beans.factory.annotation.Autowired;
-//
-//public class FunctionalMenuServiceImplTest extends ApplicationCommonContextTestSuite {
-//
-// @Autowired
-// FunctionalMenuService functionalMenuService;
-//
-// @Test
-// public void getAppListTestService() throws Exception {
-//
-// String userId = "guestT";
-// List<BusinessCardApplicationRole> userAppRolesActualResult = null;
-//
-// List<BusinessCardApplicationRole> userAppRolesExpectedResult = new ArrayList<BusinessCardApplicationRole>();
-// BusinessCardApplicationRole businessCardApplicationRole = new BusinessCardApplicationRole();
-// businessCardApplicationRole.setAppName("ECOMP Portal");
-// businessCardApplicationRole.setRoleName("System Administrator");
-// userAppRolesExpectedResult.add(businessCardApplicationRole);
-// Map<String, String> params = new HashMap<String, String>();
-// params.put("userId", userId);
-// userAppRolesActualResult = functionalMenuService.getUserAppRolesList(userId);
-// assertTrue(userAppRolesActualResult.contains(businessCardApplicationRole));
-//
-// }
-//
-// @Test
-// public void getFunctionalMenuRoleTest() throws Exception {
-//
-// FunctionalMenuRole expectedFunctionalMenuRole = new FunctionalMenuRole();
-// expectedFunctionalMenuRole.setId(new Integer(-1));
-//
-// expectedFunctionalMenuRole.setMenuId((long) 137);
-// expectedFunctionalMenuRole.setAppId(new Integer(456));
-// expectedFunctionalMenuRole.setRoleId(new Integer(6214));
-// List<FunctionalMenuRole> actualFunctionalMenuRoleList = null;
-// actualFunctionalMenuRoleList = functionalMenuService.getFunctionalMenuRole();
-// assertTrue(actualFunctionalMenuRoleList.contains(expectedFunctionalMenuRole));
-//
-// }
-//}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserNotificationServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserNotificationServiceImplTest.java
new file mode 100644
index 00000000..ad41d5f6
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserNotificationServiceImplTest.java
@@ -0,0 +1,209 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EPUserNotification;
+import org.onap.portalapp.portal.domain.EcompAppRole;
+import org.onap.portalapp.portal.transport.EpNotificationItem;
+import org.onap.portalapp.portal.transport.EpNotificationItemVO;
+import org.onap.portalapp.portal.transport.EpRoleNotificationItem;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.service.DataAccessServiceImpl;
+
+public class UserNotificationServiceImplTest {
+
+ @Mock
+ DataAccessService dataAccessService = new DataAccessServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ UserNotificationServiceImpl userNotificationServiceImpl = new UserNotificationServiceImpl();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @Test
+ public void getNotificationsTest() {
+ EPUser user = mockUser.mockEPUser();
+ Map<String, String> params = new HashMap<>();
+ params.put("user_id", String.valueOf(user.getId()));
+ List<EpNotificationItem> mockNotificationList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getNotifications", params, null)).thenReturn(mockNotificationList);
+ List<EpNotificationItem> notificationList = userNotificationServiceImpl.getNotifications(user.getId());
+ assertEquals(notificationList, mockNotificationList);
+ }
+
+ @Test
+ public void getNotificationHistoryVOTest() {
+ EPUser user = mockUser.mockEPUser();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("user_id", String.valueOf(user.getId()));
+ List<EpNotificationItemVO> mockNotificationListVO = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getNotificationHistoryVO",
+ params, null)).thenReturn(mockNotificationListVO);
+ List<EpNotificationItemVO> notificationListVO = userNotificationServiceImpl.getNotificationHistoryVO(user.getId());
+ assertEquals(notificationListVO,mockNotificationListVO);
+ }
+
+ @Test
+ public void getAdminNotificationVOSTest() {
+ EPUser user = mockUser.mockEPUser();
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("user_id", String.valueOf(user.getId()));
+ List<EpNotificationItemVO> mockAdminNotificationListItemVO = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getAdminNotificationHistoryVO",
+ params, null)).thenReturn(mockAdminNotificationListItemVO);
+ List<EpNotificationItemVO> adminNotificationListItemVO = userNotificationServiceImpl.getAdminNotificationVOS(user.getId());
+ assertEquals(adminNotificationListItemVO,mockAdminNotificationListItemVO);
+ }
+
+ @Test
+ public void getNotificationRolesTest() {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("notificationId", Long.toString(1l));
+ List<EpRoleNotificationItem> mockRoleNotifList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getNotificationRoles",
+ params, null)).thenReturn(mockRoleNotifList);
+ List<EpRoleNotificationItem> roleNotifList = userNotificationServiceImpl.getNotificationRoles(1l);
+ assertEquals(roleNotifList,mockRoleNotifList);
+ }
+
+ @Test
+ public void getAppRoleListTest() {
+ List<EcompAppRole> mockAppRoleList = new ArrayList<>();
+ Mockito.when(dataAccessService
+ .executeNamedQuery("getEpNotificationAppRoles", null, null)).thenReturn(mockAppRoleList);
+ List<EcompAppRole> appRoleList = userNotificationServiceImpl.getAppRoleList();
+ assertEquals(mockAppRoleList, appRoleList);
+ }
+
+ @Test
+ public void setNotificationReadTest() {
+ EPUserNotification mockUserNotification = new EPUserNotification();
+ mockUserNotification.setNotificationId(1l);
+ mockUserNotification.setId(1l);
+ mockUserNotification.setUpdateTime(new Date());
+ mockUserNotification.setViewed("Y");
+ mockUserNotification.setUserId((long) 1);
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockUserNotification, null);
+ userNotificationServiceImpl.setNotificationRead(1l, 1);
+ }
+
+ @Test
+ public void saveNotificationTest() throws Exception {
+ EpNotificationItem epNotificationItem = new EpNotificationItem();
+ List<Long> roleIdList = new ArrayList<>();
+ Long roleId = new Long(1l);
+ Long roleId2 = new Long(16l);
+ roleIdList.add(roleId);
+ roleIdList.add(roleId2);
+ epNotificationItem.setIsForAllRoles("N");
+ epNotificationItem.setRoleIds(roleIdList);
+ epNotificationItem.setNotificationId(1l);
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(epNotificationItem, null);
+ userNotificationServiceImpl.saveNotification(epNotificationItem);
+ }
+
+ @Test
+ public void getUsersByOrgIdsTest() {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put("OrgIds", "test");
+ List<EPUser> mockUserList = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("getUsersByOrgIdsNotifications",
+ params, null)).thenReturn(mockUserList);
+ List<String> orgIdsList = new ArrayList<>();
+ String orgId = "test";
+ orgIdsList.add(orgId);
+ List<EPUser> userList = userNotificationServiceImpl.getUsersByOrgIds(orgIdsList);
+ assertEquals(userList, mockUserList);
+ }
+
+ @Test
+ public void getMessageRecipientsTest() {
+ Map<String, String> params = new HashMap<>();
+ params.put("notificationId", Long.toString(1l));
+ List<String> mockActiveUsers = new ArrayList<>();
+ Mockito.when(dataAccessService.executeNamedQuery("messageRecipients",
+ params, null)).thenReturn(mockActiveUsers);
+ List<String> activeUsers = userNotificationServiceImpl.getMessageRecipients(1l);
+ assertEquals(activeUsers, mockActiveUsers);
+ }
+
+ @Test
+ public void deleteNotificationsFromEpNotificationTableTest() {
+ Map<String, String> params = new HashMap<String, String>();
+ Mockito.when(dataAccessService
+ .executeNamedQuery("deleteNotificationsFromEpUserNotificationTable", params, null)).thenReturn(null);
+ userNotificationServiceImpl.deleteNotificationsFromEpNotificationTable();
+ }
+
+ @Test
+ public void deleteNotificationsFromEpUserNotificationTable() {
+ Map<String, String> params = new HashMap<String, String>();
+ Mockito.when(dataAccessService
+ .executeNamedQuery("deleteNotificationsFromEpUserNotificationTable", params, null)).thenReturn(null);
+ userNotificationServiceImpl.deleteNotificationsFromEpUserNotificationTable();
+ }
+
+ @Test
+ public void deleteNotificationsFromEpRoleNotificationTable() {
+ Map<String, String> params = new HashMap<String, String>();
+ Mockito.when(dataAccessService
+ .executeNamedQuery("deleteNotificationsFromEpRoleNotificationTable", params, null)).thenReturn(null);
+ userNotificationServiceImpl.deleteNotificationsFromEpRoleNotificationTable();
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java
new file mode 100644
index 00000000..2cb285f3
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/UserRolesCommonServiceImplTest.java
@@ -0,0 +1,1466 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.cxf.transport.http.HTTPException;
+import org.hibernate.Query;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.json.JSONObject;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.externalsystemapproval.model.ExternalSystemRoleApproval;
+import org.onap.portalapp.externalsystemapproval.model.ExternalSystemUser;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.EPApp;
+import org.onap.portalapp.portal.domain.EPRole;
+import org.onap.portalapp.portal.domain.EPUser;
+import org.onap.portalapp.portal.domain.EPUserApp;
+import org.onap.portalapp.portal.domain.EPUserAppCatalogRoles;
+import org.onap.portalapp.portal.domain.EPUserAppRoles;
+import org.onap.portalapp.portal.domain.EPUserAppRolesRequest;
+import org.onap.portalapp.portal.domain.EPUserAppRolesRequestDetail;
+import org.onap.portalapp.portal.domain.ExternalSystemAccess;
+import org.onap.portalapp.portal.transport.AppWithRolesForUser;
+import org.onap.portalapp.portal.transport.CentralV2Role;
+import org.onap.portalapp.portal.transport.EPUserAppCurrentRoles;
+import org.onap.portalapp.portal.transport.EcompUserAppRoles;
+import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
+import org.onap.portalapp.portal.transport.FieldsValidator;
+import org.onap.portalapp.portal.transport.FunctionalMenuItem;
+import org.onap.portalapp.portal.transport.FunctionalMenuRole;
+import org.onap.portalapp.portal.transport.RemoteRole;
+import org.onap.portalapp.portal.transport.RemoteUserWithRoles;
+import org.onap.portalapp.portal.transport.RoleInAppForUser;
+import org.onap.portalapp.portal.transport.UserApplicationRoles;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.portal.utils.EcompPortalUtils;
+import org.onap.portalapp.portal.utils.PortalConstants;
+import org.onap.portalsdk.core.domain.Role;
+import org.onap.portalsdk.core.restful.domain.EcompRole;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.service.DataAccessServiceImpl;
+import org.onap.portalsdk.core.service.RoleServiceImpl;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.client.RestTemplate;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ EcompPortalUtils.class, SystemProperties.class, PortalConstants.class,
+ EPCommonSystemProperties.class })
+public class UserRolesCommonServiceImplTest {
+
+ @Mock
+ DataAccessService dataAccessService = new DataAccessServiceImpl();
+
+ @Mock
+ EPAppCommonServiceImpl epAppCommonServiceImpl = new EPAppCommonServiceImpl();
+
+ @Mock
+ ExternalAccessRolesServiceImpl externalAccessRolesServiceImpl = new ExternalAccessRolesServiceImpl();
+
+ @Mock
+ ApplicationsRestClientService applicationsRestClientService;
+
+ @Mock
+ RoleServiceImpl roleServiceImpl = new RoleServiceImpl();
+
+ @Mock
+ SearchServiceImpl searchServiceImpl = new SearchServiceImpl();
+
+ @Mock
+ EPRoleServiceImpl epRoleServiceImpl = new EPRoleServiceImpl();
+
+ @Mock
+ RestTemplate template = new RestTemplate();
+
+ @Mock
+ SessionFactory sessionFactory;
+
+ @Mock
+ Session session;
+
+ @Mock
+ Transaction transaction;
+
+ @InjectMocks
+ UserRolesCommonServiceImpl userRolesCommonServiceImpl = new UserRolesCommonServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ Mockito.when(sessionFactory.openSession()).thenReturn(session);
+ Mockito.when(session.beginTransaction()).thenReturn(transaction);
+ }
+
+ @After
+ public void after() {
+ session.close();
+ }
+
+ MockEPUser mockUser = new MockEPUser();
+
+ public EPApp mockApp() {
+ EPApp app = new EPApp();
+ app.setName("Test");
+ app.setImageUrl("test");
+ app.setDescription("test");
+ app.setNotes("test");
+ app.setUrl("test");
+ app.setId((long) 1);
+ app.setAppRestEndpoint("test");
+ app.setAlternateUrl("test");
+ app.setName("test");
+ app.setMlAppName("test");
+ app.setMlAppAdminId("test");
+ app.setUsername("test");
+ app.setAppPassword("test");
+ app.setOpen(false);
+ app.setEnabled(false);
+ app.setCentralAuth(true);
+ app.setUebKey("test");
+ app.setUebSecret("test");
+ app.setUebTopicName("test");
+ app.setAppType(1);
+ return app;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppRolesForUserCentralizedForPortal() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<RoleInAppForUser> mockRoleInAppForUserList = getMockedRoleInAppUserList();
+ List<CentralV2Role> mockCenV2Role = new ArrayList<>();
+ CentralV2Role cenV2Role = new CentralV2Role(1l, null, null, null, null, null, "test1", true, null,
+ new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
+ CentralV2Role cenV2Role2 = new CentralV2Role(16l, null, null, null, null, null, "test2", true, null,
+ new TreeSet<>(), new TreeSet<>(), new TreeSet<>());
+ mockCenV2Role.add(cenV2Role);
+ mockCenV2Role.add(cenV2Role2);
+ Mockito.when(externalAccessRolesServiceImpl.getRolesForApp(mockApp.getUebKey())).thenReturn(mockCenV2Role);
+ List<EPUser> mockUserList = new ArrayList<>();
+ mockUserList.add(user);
+ Mockito.when((List<EPUser>) dataAccessService
+ .executeQuery("from EPUser where orgUserId='" + user.getOrgUserId() + "'", null))
+ .thenReturn(mockUserList);
+ Mockito.when(userRolesCommonServiceImpl.getAppRolesForUser(1l, user.getOrgUserId(), true))
+ .thenReturn(mockRoleInAppForUserList);
+ List<RoleInAppForUser> roleInAppForUser = userRolesCommonServiceImpl.getAppRolesForUser(1l, "test", true);
+ assertEquals(roleInAppForUser, mockRoleInAppForUserList);
+ }
+
+ private List<RoleInAppForUser> getMockedRoleInAppUserList() {
+ List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
+ RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
+ mockRoleInAppForUser.setIsApplied(false);
+ mockRoleInAppForUser.setRoleId(1l);
+ mockRoleInAppForUser.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(false);
+ mockRoleInAppForUser2.setRoleId(16l);
+ mockRoleInAppForUser2.setRoleName("test2");
+ mockRoleInAppForUserList.add(mockRoleInAppForUser);
+ mockRoleInAppForUserList.add(mockRoleInAppForUser2);
+ return mockRoleInAppForUserList;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getAppRolesForUserNonCentralizedForPortal() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ user.setId(1l);
+ EPApp mockApp = mockApp();
+ mockApp.setCentralAuth(false);
+ EPRole mockEPRole = new EPRole();
+ mockEPRole.setId(1l);
+ mockEPRole.setName("test1");
+ mockEPRole.setActive(true);
+ SortedSet<EPUserApp> mockUserApps = new TreeSet<EPUserApp>();
+ EPUserApp mockEPUserApp = new EPUserApp();
+ mockEPUserApp.setApp(mockApp);
+ mockEPUserApp.setRole(mockEPRole);
+ mockEPUserApp.setUserId(1l);
+ mockUserApps.add(mockEPUserApp);
+ user.setEPUserApps(mockUserApps);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<RoleInAppForUser> mockRoleInAppForUserListNonCentralizedList = getMockedRoleInAppUserList();
+ List<Role> mockRole = new ArrayList<>();
+ Role role = new Role();
+ role.setId(1l);
+ role.setName("test1");
+ role.setActive(true);
+ Role role2 = new Role();
+ role.setId(16l);
+ role.setName("test2");
+ role.setActive(true);
+ mockRole.add(role);
+ mockRole.add(role2);
+ Mockito.when(roleServiceImpl.getAvailableRoles(user.getOrgUserId())).thenReturn(mockRole);
+ List<EPUser> mockUserList = new ArrayList<>();
+ mockUserList.add(user);
+ Mockito.when((List<EPUser>) dataAccessService
+ .executeQuery("from EPUser where orgUserId='" + user.getOrgUserId() + "'", null))
+ .thenReturn(mockUserList);
+ Mockito.when(userRolesCommonServiceImpl.getAppRolesForUser(1l, user.getOrgUserId(), true))
+ .thenReturn(mockRoleInAppForUserListNonCentralizedList);
+ List<RoleInAppForUser> roleInAppForUserNonCentralized = userRolesCommonServiceImpl.getAppRolesForUser(1l,
+ user.getOrgUserId(), true);
+ assertNull(roleInAppForUserNonCentralized);
+ }
+
+ @Test
+ public void getAppRolesForCentralizedPartnerAppTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<RoleInAppForUser> mockRoleInAppForUserList = getMockedRoleInAppUserList();
+ List<EPRole> mockEPRoleList = new ArrayList<>();
+ EPRole mockEpRole = new EPRole();
+ mockEpRole.setActive(true);
+ mockEpRole.setAppId(2l);
+ mockEpRole.setName("test1");
+ mockEpRole.setAppRoleId(333l);
+ mockEpRole.setId(1l);
+ EPRole mockEpRole2 = new EPRole();
+ mockEpRole2.setActive(true);
+ mockEpRole2.setAppId(2l);
+ mockEpRole2.setName("test2");
+ mockEpRole2.setAppRoleId(444l);
+ mockEpRole2.setId(16l);
+ mockEPRoleList.add(mockEpRole);
+ mockEPRoleList.add(mockEpRole2);
+ final Map<String, Long> appParams = new HashMap<>();
+ appParams.put("appId", 2l);
+ Mockito.when(dataAccessService.executeNamedQuery("getActiveRolesOfApplication", appParams, null))
+ .thenReturn(mockEPRoleList);
+ final Map<String, String> params = new HashMap<>();
+ params.put("orgUserIdValue", "guestT");
+ List<EPUser> mockEPUserList = new ArrayList<>();
+ mockEPUserList.add(user);
+ Mockito.when(dataAccessService.executeNamedQuery("epUserAppId", params, null)).thenReturn(mockEPUserList);
+ final Map<String, Long> userParams = new HashMap<>();
+ userParams.put("appId", mockApp.getId());
+ userParams.put("userId", mockEPUserList.get(0).getId());
+ List<EPUserAppCurrentRoles> epUserAppCurrentRolesList = new ArrayList<>();
+ EPUserAppCurrentRoles epUserAppCurrentRoles = new EPUserAppCurrentRoles();
+ epUserAppCurrentRoles.setRoleId(444l);
+ epUserAppCurrentRoles.setRoleName("TestPartnerRole2");
+ epUserAppCurrentRoles.setUserId(mockEPUserList.get(0).getId());
+ epUserAppCurrentRolesList.add(epUserAppCurrentRoles);
+ Mockito.when(dataAccessService.executeNamedQuery("getUserAppCurrentRoles", userParams, null))
+ .thenReturn(epUserAppCurrentRolesList);
+ Mockito.when(userRolesCommonServiceImpl.getAppRolesForUser(2l, user.getOrgUserId(), true))
+ .thenReturn(mockRoleInAppForUserList);
+ List<RoleInAppForUser> roleInAppForUser = userRolesCommonServiceImpl.getAppRolesForUser(2l, user.getOrgUserId(),
+ true);
+ assertEquals(roleInAppForUser, mockRoleInAppForUserList);
+ }
+
+ @Test
+ public void getAppRolesForNonCentralizedPartnerAppTest() throws Exception {
+ EPUser user = mockUser.mockEPUser();
+ user.setId(2l);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setCentralAuth(false);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
+ RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
+ mockRoleInAppForUser.setIsApplied(true);
+ mockRoleInAppForUser.setRoleId(333l);
+ mockRoleInAppForUser.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(true);
+ mockRoleInAppForUser2.setRoleId(777l);
+ mockRoleInAppForUser2.setRoleName("test2");
+ RoleInAppForUser mockRoleInAppForUser3 = new RoleInAppForUser();
+ mockRoleInAppForUser3.setIsApplied(false);
+ mockRoleInAppForUser3.setRoleId(888l);
+ mockRoleInAppForUser3.setRoleName("test5");
+ mockRoleInAppForUserList.add(mockRoleInAppForUser);
+ mockRoleInAppForUserList.add(mockRoleInAppForUser2);
+ mockRoleInAppForUserList.add(mockRoleInAppForUser3);
+ List<EcompRole> mockEcompRoleList = new ArrayList<>();
+ EcompRole mockEcompRole = new EcompRole();
+ mockEcompRole.setId(333l);
+ mockEcompRole.setName("test1");
+ EcompRole mockEcompRole2 = new EcompRole();
+ mockEcompRole2.setId(777l);
+ mockEcompRole2.setName("test2");
+ EcompRole mockEcompRole3 = new EcompRole();
+ mockEcompRole3.setId(888l);
+ mockEcompRole3.setName("test5");
+ mockEcompRoleList.add(mockEcompRole);
+ mockEcompRoleList.add(mockEcompRole2);
+ mockEcompRoleList.add(mockEcompRole3);
+ EcompRole[] mockEcompRoleArray = mockEcompRoleList.toArray(new EcompRole[mockEcompRoleList.size()]);
+ List<EPRole> mockEPRoleList = new ArrayList<>();
+ EPRole mockEpRole = new EPRole();
+ mockEpRole.setActive(true);
+ mockEpRole.setAppId(2l);
+ mockEpRole.setName("test1");
+ mockEpRole.setAppRoleId(333l);
+ mockEpRole.setId(16l);
+ EPRole mockEpRole2 = new EPRole();
+ mockEpRole2.setActive(true);
+ mockEpRole2.setAppId(2l);
+ mockEpRole2.setName("test3");
+ mockEpRole2.setAppRoleId(555l);
+ mockEpRole2.setId(15l);
+ EPRole mockEpRole3 = new EPRole();
+ mockEpRole3.setActive(true);
+ mockEpRole3.setAppId(2l);
+ mockEpRole3.setName("test4");
+ mockEpRole3.setAppRoleId(888l);
+ mockEpRole3.setId(17l);
+ mockEPRoleList.add(mockEpRole);
+ mockEPRoleList.add(mockEpRole2);
+ mockEPRoleList.add(mockEpRole3);
+ List<EPUserApp> mockUserRolesList = new ArrayList<>();
+ EPUserApp mockEpUserApp = new EPUserApp();
+ mockEpUserApp.setApp(mockApp);
+ mockEpUserApp.setRole(mockEpRole2);
+ mockEpUserApp.setUserId(user.getId());
+ mockUserRolesList.add(mockEpUserApp);
+ List<FunctionalMenuRole> mockFunctionalMenuRolesList = new ArrayList<>();
+ FunctionalMenuRole mockFunctionalMenuRole = new FunctionalMenuRole();
+ mockFunctionalMenuRole.setAppId((int) (long) mockApp.getId());
+ mockFunctionalMenuRole.setRoleId((int) (long) 15l);
+ mockFunctionalMenuRole.setMenuId(10l);
+ mockFunctionalMenuRole.setId(10);
+ mockFunctionalMenuRolesList.add(mockFunctionalMenuRole);
+ List<FunctionalMenuItem> mockFunctionalMenuItemList = new ArrayList<>();
+ FunctionalMenuItem mockFunctionalMenuItem = new FunctionalMenuItem();
+ List<Integer> mockRolesList = new ArrayList<>();
+ Integer role1 = 1;
+ mockRolesList.add(role1);
+ mockFunctionalMenuItem.setRestrictedApp(false);
+ mockFunctionalMenuItem.setRoles(mockRolesList);
+ mockFunctionalMenuItem.setUrl("http://test.com");
+ mockFunctionalMenuItemList.add(mockFunctionalMenuItem);
+ Query epRoleQuery = Mockito.mock(Query.class);
+ Query epUserAppsQuery = Mockito.mock(Query.class);
+ Query epFunctionalMenuQuery = Mockito.mock(Query.class);
+ Query epFunctionalMenuQuery2 = Mockito.mock(Query.class);
+ Query epFunctionalMenuItemQuery = Mockito.mock(Query.class);
+ Query epUserListQuery = Mockito.mock(Query.class);
+ Query epUserRolesListQuery = Mockito.mock(Query.class);
+ Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(), "/roles"))
+ .thenReturn(mockEcompRoleArray);
+ // syncAppRolesTest
+ Mockito.when(session.createQuery("from " + EPRole.class.getName() + " where appId=" + mockApp.getId()))
+ .thenReturn(epRoleQuery);
+ Mockito.doReturn(mockEPRoleList).when(epRoleQuery).list();
+ Mockito.when(session.createQuery(
+ "from " + EPUserApp.class.getName() + " where app.id=" + mockApp.getId() + " and role_id=" + 15l))
+ .thenReturn(epUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList).when(epUserAppsQuery).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuRole.class.getName() + " where roleId=" + 15l))
+ .thenReturn(epFunctionalMenuQuery);
+ Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuRole.class.getName() + " where menuId=" + 10l))
+ .thenReturn(epFunctionalMenuQuery2);
+ Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery2).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuItem.class.getName() + " where menuId=" + 10l))
+ .thenReturn(epFunctionalMenuItemQuery);
+ Mockito.doReturn(mockFunctionalMenuItemList).when(epFunctionalMenuItemQuery).list();
+ List<EcompRole> mockEcompRoleList2 = new ArrayList<>();
+ EcompRole mockUserAppRoles = new EcompRole();
+ mockUserAppRoles.setId(333l);
+ mockUserAppRoles.setName("test1");
+ EcompRole mockUserAppRoles2 = new EcompRole();
+ mockUserAppRoles2.setId(777l);
+ mockUserAppRoles2.setName("test2");
+ mockEcompRoleList2.add(mockUserAppRoles);
+ mockEcompRoleList2.add(mockUserAppRoles2);
+ EcompRole[] mockEcompRoleArray2 = mockEcompRoleList2.toArray(new EcompRole[mockEcompRoleList2.size()]);
+ Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(),
+ String.format("/user/%s/roles", user.getOrgUserId()))).thenReturn(mockEcompRoleArray2);
+ // SyncUserRoleTest
+ Mockito.when(session
+ .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'"))
+ .thenReturn(epUserListQuery);
+ Mockito.doReturn(mockEpUserList).when(epUserListQuery).list();
+
+ List<EPUserApp> mockUserRolesList2 = new ArrayList<>();
+ EPUserApp mockEpUserAppRoles = new EPUserApp();
+ mockEpUserAppRoles.setApp(mockApp);
+ mockEpUserAppRoles.setRole(mockEpRole3);
+ mockEpUserAppRoles.setUserId(user.getId());
+ mockUserRolesList2.add(mockEpUserAppRoles);
+ Mockito.when(session.createQuery(
+ "from org.onap.portalapp.portal.domain.EPUserApp where app.id=2 and role.active = 'Y' and userId=2"))
+ .thenReturn(epUserRolesListQuery);
+ Mockito.doReturn(mockUserRolesList2).when(epUserRolesListQuery).list();
+ List<RoleInAppForUser> roleInAppForUser = userRolesCommonServiceImpl.getAppRolesForUser(2l, user.getOrgUserId(),
+ true);
+ assertEquals(roleInAppForUser, mockRoleInAppForUserList);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void setAppWithUserRoleStateForUserTestForCentralizedAppForPortal() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ EPUser user = mockUser.mockEPUser();
+ user.setId(2l);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ EPApp mockApp = mockApp();
+ mockApp.setNameSpace("com.test.com");
+ mockApp.setId(1l);
+ mockApp.setCentralAuth(true);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ AppWithRolesForUser mockWithRolesForUser = new AppWithRolesForUser();
+ List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
+ RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
+ mockRoleInAppForUser.setIsApplied(true);
+ mockRoleInAppForUser.setRoleId(1l);
+ mockRoleInAppForUser.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(true);
+ mockRoleInAppForUser2.setRoleId(1000l);
+ mockRoleInAppForUser2.setRoleName("test3");
+ mockRoleInAppForUserList.add(mockRoleInAppForUser);
+ mockRoleInAppForUserList.add(mockRoleInAppForUser2);
+ mockWithRolesForUser.setAppId(mockApp.getId());
+ mockWithRolesForUser.setAppName(mockApp.getName());
+ mockWithRolesForUser.setOrgUserId(user.getOrgUserId());
+ mockWithRolesForUser.setAppRoles(mockRoleInAppForUserList);
+ List<EPUserAppRolesRequest> mockEpRequestIdValList = new ArrayList<EPUserAppRolesRequest>();
+ Set<EPUserAppRolesRequestDetail> mockEpUserAppRolesRequestDetailList = new TreeSet<>();
+ EPUserAppRolesRequestDetail mockEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ EPUserAppRolesRequest mockEPUserAppRolesRequest = new EPUserAppRolesRequest();
+ mockEPUserAppRolesRequest.setAppId(mockApp.getId());
+ mockEPUserAppRolesRequest.setId(1l);
+ mockEPUserAppRolesRequest.setRequestStatus("P");
+ mockEPUserAppRolesRequest.setUserId(user.getId());
+ mockEPUserAppRolesRequest.setEpRequestIdDetail(mockEpUserAppRolesRequestDetailList);
+ mockEpRequestIdValList.add(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetail.setEpRequestIdData(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetailList.add(mockEpUserAppRolesRequestDetail);
+
+ // Update Requests if any requests are pending
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", mockApp.getId());
+ params.put("userId", user.getId());
+ Mockito.when((List<EPUserAppRolesRequest>) dataAccessService.executeNamedQuery("userAppRolesRequestList",
+ params, null)).thenReturn(mockEpRequestIdValList);
+ mockEPUserAppRolesRequest.setUpdatedDate(new Date());
+ mockEPUserAppRolesRequest.setRequestStatus("O");
+ HashMap<String, Long> additionalUpdateParam = new HashMap<String, Long>();
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockEPUserAppRolesRequest, additionalUpdateParam);
+ List<EPUserAppRolesRequestDetail> mockGetEpUserAppRolesRequestDetailList = new ArrayList<EPUserAppRolesRequestDetail>();
+ EPUserAppRolesRequestDetail mockGetEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ mockGetEpUserAppRolesRequestDetailList.add(mockGetEpUserAppRolesRequestDetail);
+ // Updates in External Auth System
+ final Map<String, String> userParams = new HashMap<>();
+ userParams.put("orgUserIdValue", user.getOrgUserId());
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("epUserAppId", userParams, null))
+ .thenReturn(mockEpUserList);
+ PowerMockito
+ .when(EPCommonSystemProperties
+ .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn(true);
+ PowerMockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn("@test.com");
+ HttpHeaders headers = new HttpHeaders();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ JSONObject mockJsonObject1 = new JSONObject();
+ JSONObject mockJsonObject2 = new JSONObject();
+ JSONObject mockJsonObject3 = new JSONObject();
+ mockJsonObject1.put("name", "com.test.com.test1");
+ mockJsonObject2.put("name", "com.test.com.test2");
+ List<JSONObject> mockJson = new ArrayList<>();
+ mockJson.add(mockJsonObject1);
+ mockJson.add(mockJsonObject2);
+ mockJsonObject3.put("role", mockJson);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObject3.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ EPRole mockEPRole = new EPRole();
+ mockEPRole.setActive(true);
+ mockEPRole.setAppId(null);
+ mockEPRole.setAppRoleId(null);
+ mockEPRole.setId(1l);
+ mockEPRole.setName("test1");
+ EPRole mockEPRole2 = new EPRole();
+ mockEPRole2.setActive(true);
+ mockEPRole2.setAppId(null);
+ mockEPRole2.setAppRoleId(null);
+ mockEPRole2.setId(16l);
+ mockEPRole2.setName("test2");
+ EPRole mockEPRole3 = new EPRole();
+ mockEPRole3.setActive(true);
+ mockEPRole3.setAppId(null);
+ mockEPRole3.setAppRoleId(null);
+ mockEPRole3.setId(1000l);
+ mockEPRole3.setName("test3");
+ Map<String, EPRole> mockEPRoleList = new HashMap<>();
+ mockEPRoleList.put("test1", mockEPRole);
+ mockEPRoleList.put("test2", mockEPRole2);
+ mockEPRoleList.put("test3", mockEPRole3);
+ Mockito.when(externalAccessRolesServiceImpl.getCurrentRolesInDB(mockApp)).thenReturn(mockEPRoleList);
+ final Map<String, Long> params2 = new HashMap<>();
+ params2.put("appId", mockApp.getId());
+ params2.put("userId", user.getId());
+ List<EcompUserAppRoles> mockEPuserAppList = getCurrentUserRoles(user, mockApp);
+ Mockito.when(dataAccessService.executeNamedQuery("getUserAppExistingRoles", params2, null))
+ .thenReturn(mockEPuserAppList);
+ final Map<String, Long> epDetailParams = new HashMap<>();
+ epDetailParams.put("reqId", mockEPUserAppRolesRequest.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("userAppRolesRequestDetailList", epDetailParams, null))
+ .thenReturn(mockGetEpUserAppRolesRequestDetailList);
+
+ ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
+
+ ResponseEntity<String> deleteResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(deleteResponse);
+
+ // Updates in EP DB
+ Query epsetAppWithUserRoleGetUserQuery = Mockito.mock(Query.class);
+ Query epsetAppWithUserRoleGetUserAppsQuery = Mockito.mock(Query.class);
+ Query epsetAppWithUserRoleGetRolesQuery = Mockito.mock(Query.class);
+ SQLQuery epsetAppWithUserRoleUpdateEPRoleQuery = Mockito.mock(SQLQuery.class);
+ Mockito.when(session.get(EPApp.class, mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(session
+ .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'"))
+ .thenReturn(epsetAppWithUserRoleGetUserQuery);
+ Mockito.doReturn(mockEpUserList).when(epsetAppWithUserRoleGetUserQuery).list();
+ List<EPUserApp> mockUserRolesList2 = new ArrayList<>();
+ EPUserApp mockEpUserAppRoles = new EPUserApp();
+ mockEpUserAppRoles.setApp(mockApp);
+ mockEpUserAppRoles.setRole(mockEPRole);
+ mockEpUserAppRoles.setUserId(user.getId());
+ mockUserRolesList2.add(mockEpUserAppRoles);
+ Mockito.when(session.createQuery(
+ "from org.onap.portalapp.portal.domain.EPUserApp where app.id=1 and role.active = 'Y' and userId=2"))
+ .thenReturn(epsetAppWithUserRoleGetUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList2).when(epsetAppWithUserRoleGetUserAppsQuery).list();
+ List<EPRole> mockEPRoles = new ArrayList<>();
+ mockEPRoles.add(mockEPRole2);
+ mockEPRoles.add(mockEPRole3);
+ Mockito.when(session.createQuery("from " + EPRole.class.getName() + " where appId is null and id != 1"))
+ .thenReturn(epsetAppWithUserRoleGetRolesQuery);
+ Mockito.doReturn(mockEPRoles).when(epsetAppWithUserRoleGetRolesQuery).list();
+ Mockito.when(session.createSQLQuery("update fn_role set app_id = null where app_id = 1 "))
+ .thenReturn(epsetAppWithUserRoleUpdateEPRoleQuery);
+ boolean actual = userRolesCommonServiceImpl.setAppWithUserRoleStateForUser(user, mockWithRolesForUser);
+ assertTrue(actual);
+ }
+
+ private List<EcompUserAppRoles> getCurrentUserRoles(EPUser user, EPApp mockApp) {
+ List<EcompUserAppRoles> mockEPuserAppList = new ArrayList<>();
+ EcompUserAppRoles mockEcompUserAppRoles = new EcompUserAppRoles();
+ mockEcompUserAppRoles.setAppId(String.valueOf(mockApp.getId()));
+ mockEcompUserAppRoles.setRoleId(1l);
+ mockEcompUserAppRoles.setRoleName("test1");
+ mockEcompUserAppRoles.setUserId(user.getId());
+ mockEPuserAppList.add(mockEcompUserAppRoles);
+ return mockEPuserAppList;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void setAppWithUserRoleStateForUserTestForNonCentralizedApp() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ EPUser user = mockUser.mockEPUser();
+ user.setId(2l);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ EPApp mockApp = mockApp();
+ mockApp.setNameSpace("com.test.com");
+ mockApp.setId(2l);
+ mockApp.setCentralAuth(false);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ AppWithRolesForUser mockWithRolesForUser = new AppWithRolesForUser();
+ List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
+ RoleInAppForUser mockRoleInAppForUser = new RoleInAppForUser();
+ mockRoleInAppForUser.setIsApplied(true);
+ mockRoleInAppForUser.setRoleId(1l);
+ mockRoleInAppForUser.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(true);
+ mockRoleInAppForUser2.setRoleId(1000l);
+ mockRoleInAppForUser2.setRoleName("test3");
+ mockRoleInAppForUserList.add(mockRoleInAppForUser);
+ mockRoleInAppForUserList.add(mockRoleInAppForUser2);
+ mockWithRolesForUser.setAppId(mockApp.getId());
+ mockWithRolesForUser.setAppName(mockApp.getName());
+ mockWithRolesForUser.setOrgUserId(user.getOrgUserId());
+ mockWithRolesForUser.setAppRoles(mockRoleInAppForUserList);
+ List<EPUserAppRolesRequest> mockEpRequestIdValList = new ArrayList<EPUserAppRolesRequest>();
+ Set<EPUserAppRolesRequestDetail> mockEpUserAppRolesRequestDetailList = new TreeSet<>();
+ EPUserAppRolesRequestDetail mockEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ EPUserAppRolesRequest mockEPUserAppRolesRequest = new EPUserAppRolesRequest();
+ mockEPUserAppRolesRequest.setAppId(mockApp.getId());
+ mockEPUserAppRolesRequest.setId(1l);
+ mockEPUserAppRolesRequest.setRequestStatus("P");
+ mockEPUserAppRolesRequest.setUserId(user.getId());
+ mockEPUserAppRolesRequest.setEpRequestIdDetail(mockEpUserAppRolesRequestDetailList);
+ mockEpRequestIdValList.add(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetail.setEpRequestIdData(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetailList.add(mockEpUserAppRolesRequestDetail);
+
+ // Update Requests if any requests are pending
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", mockApp.getId());
+ params.put("userId", user.getId());
+ Mockito.when((List<EPUserAppRolesRequest>) dataAccessService.executeNamedQuery("userAppRolesRequestList",
+ params, null)).thenReturn(mockEpRequestIdValList);
+ mockEPUserAppRolesRequest.setUpdatedDate(new Date());
+ mockEPUserAppRolesRequest.setRequestStatus("O");
+ HashMap<String, Long> additionalUpdateParam = new HashMap<String, Long>();
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockEPUserAppRolesRequest, additionalUpdateParam);
+ List<EPUserAppRolesRequestDetail> mockGetEpUserAppRolesRequestDetailList = new ArrayList<EPUserAppRolesRequestDetail>();
+ EPUserAppRolesRequestDetail mockGetEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ mockGetEpUserAppRolesRequestDetailList.add(mockGetEpUserAppRolesRequestDetail);
+ final Map<String, Long> epDetailParams = new HashMap<>();
+ epDetailParams.put("reqId", mockEPUserAppRolesRequest.getId());
+
+ final Map<String, String> userParams = new HashMap<>();
+ userParams.put("orgUserIdValue", user.getOrgUserId());
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("epUserAppId", userParams, null))
+ .thenReturn(mockEpUserList);
+
+ PowerMockito
+ .when(EPCommonSystemProperties
+ .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn(true);
+ PowerMockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn("@test.com");
+ HttpHeaders headers = new HttpHeaders();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ EPRole mockEPRole = new EPRole();
+ mockEPRole.setActive(true);
+ mockEPRole.setAppId(2l);
+ mockEPRole.setAppRoleId(null);
+ mockEPRole.setId(10l);
+ mockEPRole.setAppRoleId(1l);
+ mockEPRole.setName("test1");
+ EPRole mockEPRole2 = new EPRole();
+ mockEPRole2.setActive(true);
+ mockEPRole2.setAppId(2l);
+ mockEPRole2.setAppRoleId(null);
+ mockEPRole2.setId(160l);
+ mockEPRole2.setName("test2");
+ mockEPRole2.setAppRoleId(16l);
+ EPRole mockEPRole3 = new EPRole();
+ mockEPRole3.setActive(true);
+ mockEPRole3.setAppId(2l);
+ mockEPRole3.setAppRoleId(null);
+ mockEPRole3.setId(1100l);
+ mockEPRole3.setAppRoleId(100l);
+ mockEPRole3.setName("test3");
+ Mockito.when(applicationsRestClientService.get(EPUser.class, mockApp.getId(),
+ String.format("/user/%s", user.getOrgUserId()), true)).thenReturn(user);
+ // Updates in EP DB
+ Query epsetAppWithUserRoleNonCentralizedGetUserQuery = Mockito.mock(Query.class);
+ Query epsetAppWithUserRoleNonCentralizedGetUserAppsQuery = Mockito.mock(Query.class);
+ Query epsetAppWithUserRoleNonCentralizedGetRolesQuery = Mockito.mock(Query.class);
+ Mockito.when(session.get(EPApp.class, mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(session
+ .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'"))
+ .thenReturn(epsetAppWithUserRoleNonCentralizedGetUserQuery);
+ Mockito.doReturn(mockEpUserList).when(epsetAppWithUserRoleNonCentralizedGetUserQuery).list();
+ List<EPUserApp> mockUserRolesList2 = new ArrayList<>();
+ EPUserApp mockEpUserAppRoles = new EPUserApp();
+ mockEpUserAppRoles.setApp(mockApp);
+ mockEpUserAppRoles.setRole(mockEPRole);
+ mockEpUserAppRoles.setUserId(user.getId());
+ mockUserRolesList2.add(mockEpUserAppRoles);
+ Mockito.when(session.createQuery(
+ "from org.onap.portalapp.portal.domain.EPUserApp where app.id=2 and role.active = 'Y' and userId=2"))
+ .thenReturn(epsetAppWithUserRoleNonCentralizedGetUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList2).when(epsetAppWithUserRoleNonCentralizedGetUserAppsQuery).list();
+ List<EPRole> mockEPRoles = new ArrayList<>();
+ mockEPRoles.add(mockEPRole2);
+ mockEPRoles.add(mockEPRole3);
+ Mockito.when(session.createQuery("from " + EPRole.class.getName() + " where appId=2"))
+ .thenReturn(epsetAppWithUserRoleNonCentralizedGetRolesQuery);
+ Mockito.doReturn(mockEPRoles).when(epsetAppWithUserRoleNonCentralizedGetRolesQuery).list();
+ boolean expected = userRolesCommonServiceImpl.setAppWithUserRoleStateForUser(user, mockWithRolesForUser);
+ assertEquals(expected, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void setExternalRequestUserAppRoleMerdianCentralizedAppTest() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EcompPortalUtils.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ EPUser user = mockUser.mockEPUser();
+ user.setId(2l);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ EPApp mockApp = mockApp();
+ mockApp.setNameSpace("com.test.com");
+ mockApp.setId(1l);
+ mockApp.setCentralAuth(true);
+ Mockito.when(EcompPortalUtils.checkIfRemoteCentralAccessAllowed()).thenReturn(true);
+ ExternalSystemUser externalSystemUser = new ExternalSystemUser();
+ List<ExternalSystemRoleApproval> mockExternalSystemRoleApprovalList = new ArrayList<>();
+ ExternalSystemRoleApproval mockExternalSystemRoleApproval = new ExternalSystemRoleApproval();
+ mockExternalSystemRoleApproval.setRoleName("test1");
+ ExternalSystemRoleApproval mockExternalSystemRoleApproval2 = new ExternalSystemRoleApproval();
+ mockExternalSystemRoleApproval2.setRoleName("test2");
+ mockExternalSystemRoleApprovalList.add(mockExternalSystemRoleApproval);
+ mockExternalSystemRoleApprovalList.add(mockExternalSystemRoleApproval2);
+ externalSystemUser.setApplicationName(mockApp.getMlAppName());
+ externalSystemUser.setLoginId(user.getOrgUserId());
+ externalSystemUser.setRoles(mockExternalSystemRoleApprovalList);
+ EPRole mockEPRole = new EPRole();
+ mockEPRole.setActive(true);
+ mockEPRole.setAppId(null);
+ mockEPRole.setAppRoleId(null);
+ mockEPRole.setId(1l);
+ mockEPRole.setName("test1");
+ EPRole mockEPRole2 = new EPRole();
+ mockEPRole2.setActive(true);
+ mockEPRole2.setAppId(null);
+ mockEPRole2.setAppRoleId(null);
+ mockEPRole2.setId(16l);
+ mockEPRole2.setName("test2");
+ EPRole mockEPRole3 = new EPRole();
+ mockEPRole3.setActive(true);
+ mockEPRole3.setAppId(null);
+ mockEPRole3.setAppRoleId(null);
+ mockEPRole3.setId(1000l);
+ mockEPRole3.setName("test3");
+
+ Mockito.when(epAppCommonServiceImpl.getAppDetail(mockApp.getMlAppName())).thenReturn(mockApp);
+ final Map<String, String> userParams = new HashMap<>();
+ userParams.put("orgUserIdValue", user.getOrgUserId());
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("epUserAppId", userParams, null))
+ .thenReturn(mockEpUserList);
+
+ List<EPUserAppRolesRequest> mockMerdianEpRequestIdValList = new ArrayList<EPUserAppRolesRequest>();
+ Set<EPUserAppRolesRequestDetail> mockEpUserAppRolesRequestDetailList = new TreeSet<>();
+ EPUserAppRolesRequestDetail mockEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ EPUserAppRolesRequest mockEPUserAppRolesRequest = new EPUserAppRolesRequest();
+ mockEPUserAppRolesRequest.setAppId(mockApp.getId());
+ mockEPUserAppRolesRequest.setId(1l);
+ mockEPUserAppRolesRequest.setRequestStatus("P");
+ mockEPUserAppRolesRequest.setUserId(user.getId());
+ mockEPUserAppRolesRequest.setEpRequestIdDetail(mockEpUserAppRolesRequestDetailList);
+ mockMerdianEpRequestIdValList.add(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetail.setEpRequestIdData(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetailList.add(mockEpUserAppRolesRequestDetail);
+
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", mockApp.getId());
+ params.put("userId", user.getId());
+ Mockito.when((List<EPUserAppRolesRequest>) dataAccessService.executeNamedQuery("userAppRolesRequestList",
+ params, null)).thenReturn(mockMerdianEpRequestIdValList);
+ RoleInAppForUser mockRoleInAppForUser1 = new RoleInAppForUser();
+ mockRoleInAppForUser1.setIsApplied(true);
+ mockRoleInAppForUser1.setRoleId(1l);
+ mockRoleInAppForUser1.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(true);
+ mockRoleInAppForUser2.setRoleId(16l);
+ mockRoleInAppForUser2.setRoleName("test2");
+ Mockito.when(epRoleServiceImpl.getAppRole(mockExternalSystemRoleApproval.getRoleName(), mockApp.getId()))
+ .thenReturn(mockEPRole);
+ Mockito.when(epRoleServiceImpl.getAppRole(mockExternalSystemRoleApproval2.getRoleName(), mockApp.getId()))
+ .thenReturn(mockEPRole2);
+ List<EcompUserAppRoles> mockEPuserAppList = getCurrentUserRoles(user, mockApp);
+ final Map<String, Long> params2 = new HashMap<>();
+ params2.put("userId", user.getId());
+ params2.put("appId", mockApp.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getUserAppExistingRoles", params2, null))
+ .thenReturn(mockEPuserAppList);
+ // Updates in External Auth System
+ List<EPUserAppRolesRequestDetail> mockGetEpUserAppRolesRequestDetailList = new ArrayList<EPUserAppRolesRequestDetail>();
+ EPUserAppRolesRequestDetail mockGetEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ mockGetEpUserAppRolesRequestDetailList.add(mockGetEpUserAppRolesRequestDetail);
+ final Map<String, String> userParams2 = new HashMap<>();
+ userParams2.put("orgUserIdValue", user.getOrgUserId());
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("epUserAppId", userParams2, null))
+ .thenReturn(mockEpUserList);
+ PowerMockito
+ .when(EPCommonSystemProperties
+ .containsProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn(true);
+ PowerMockito.when(SystemProperties.getProperty(EPCommonSystemProperties.EXTERNAL_CENTRAL_ACCESS_USER_DOMAIN))
+ .thenReturn("@test.com");
+ HttpHeaders headers = new HttpHeaders();
+ Mockito.when(EcompPortalUtils.base64encodeKeyForAAFBasicAuth()).thenReturn(headers);
+ JSONObject mockJsonObject1 = new JSONObject();
+ JSONObject mockJsonObject2 = new JSONObject();
+ JSONObject mockJsonObject3 = new JSONObject();
+ mockJsonObject1.put("name", "com.test.com.test1");
+ mockJsonObject2.put("name", "com.test.com.test2");
+ List<JSONObject> mockJson = new ArrayList<>();
+ mockJson.add(mockJsonObject1);
+ mockJson.add(mockJsonObject2);
+ mockJsonObject3.put("role", mockJson);
+ ResponseEntity<String> getResponse = new ResponseEntity<>(mockJsonObject3.toString(), HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(getResponse);
+ Map<String, EPRole> mockEPRoleList = new HashMap<>();
+ mockEPRoleList.put("test1", mockEPRole);
+ mockEPRoleList.put("test2", mockEPRole2);
+ mockEPRoleList.put("test3", mockEPRole3);
+ Mockito.when(externalAccessRolesServiceImpl.getCurrentRolesInDB(mockApp)).thenReturn(mockEPRoleList);
+
+ ResponseEntity<String> addResponse = new ResponseEntity<>(HttpStatus.CREATED);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.POST),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(addResponse);
+
+ ResponseEntity<String> deleteResponse = new ResponseEntity<>(HttpStatus.OK);
+ Mockito.when(template.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE),
+ Matchers.<HttpEntity<String>>any(), Matchers.eq(String.class))).thenReturn(deleteResponse);
+ // Updated in EP DB
+ Query epsetExternalRequestUserAppRoleGetUserQuery = Mockito.mock(Query.class);
+ Query epsetExternalRequestUserAppRoleGetUserAppsQuery = Mockito.mock(Query.class);
+ Query epsetExternalRequestUserAppRoleGetRolesQuery = Mockito.mock(Query.class);
+ SQLQuery epsetAppWithUserRoleUpdateEPRoleQuery = Mockito.mock(SQLQuery.class);
+ Mockito.when(session.get(EPApp.class, mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(session
+ .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'"))
+ .thenReturn(epsetExternalRequestUserAppRoleGetUserQuery);
+ Mockito.doReturn(mockEpUserList).when(epsetExternalRequestUserAppRoleGetUserQuery).list();
+ List<EPUserApp> mockUserRolesList2 = new ArrayList<>();
+ EPUserApp mockEpUserAppRoles = new EPUserApp();
+ mockEpUserAppRoles.setApp(mockApp);
+ mockEpUserAppRoles.setRole(mockEPRole);
+ mockEpUserAppRoles.setUserId(user.getId());
+ mockUserRolesList2.add(mockEpUserAppRoles);
+ Mockito.when(session.createQuery(
+ "from org.onap.portalapp.portal.domain.EPUserApp where app.id=1 and role.active = 'Y' and userId=2"))
+ .thenReturn(epsetExternalRequestUserAppRoleGetUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList2).when(epsetExternalRequestUserAppRoleGetUserAppsQuery).list();
+ List<EPRole> mockEPRoles = new ArrayList<>();
+ mockEPRoles.add(mockEPRole2);
+ mockEPRoles.add(mockEPRole3);
+ Mockito.when(session.createQuery("from org.onap.portalapp.portal.domain.EPRole where appId is null "))
+ .thenReturn(epsetExternalRequestUserAppRoleGetRolesQuery);
+ Mockito.doReturn(mockEPRoles).when(epsetExternalRequestUserAppRoleGetRolesQuery).list();
+ Mockito.when(session.createSQLQuery("update fn_role set app_id = null where app_id = 1 "))
+ .thenReturn(epsetAppWithUserRoleUpdateEPRoleQuery);
+
+ ExternalRequestFieldsValidator mockExternalRequestFieldsValidator = new ExternalRequestFieldsValidator(true,
+ "Updated Successfully");
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = userRolesCommonServiceImpl
+ .setExternalRequestUserAppRole(externalSystemUser, "POST");
+ assertTrue(mockExternalRequestFieldsValidator.equals(externalRequestFieldsValidator));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void setExternalRequestUserAppRoleMerdianNonCentralizedAppTest() throws Exception {
+ PowerMockito.mockStatic(SystemProperties.class);
+ PowerMockito.mockStatic(EPCommonSystemProperties.class);
+ PowerMockito.mockStatic(PortalConstants.class);
+ EPUser user = mockUser.mockEPUser();
+ user.setId(2l);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ ExternalSystemUser externalSystemUser = new ExternalSystemUser();
+ List<ExternalSystemRoleApproval> mockExternalSystemRoleApprovalList = new ArrayList<>();
+ ExternalSystemRoleApproval mockExternalSystemRoleApproval = new ExternalSystemRoleApproval();
+ mockExternalSystemRoleApproval.setRoleName("test1");
+ ExternalSystemRoleApproval mockExternalSystemRoleApproval2 = new ExternalSystemRoleApproval();
+ mockExternalSystemRoleApproval2.setRoleName("test2");
+ mockExternalSystemRoleApprovalList.add(mockExternalSystemRoleApproval);
+ mockExternalSystemRoleApprovalList.add(mockExternalSystemRoleApproval2);
+ externalSystemUser.setApplicationName(mockApp.getMlAppName());
+ externalSystemUser.setLoginId(user.getOrgUserId());
+ externalSystemUser.setRoles(mockExternalSystemRoleApprovalList);
+
+ EPRole mockEPRole = new EPRole();
+ mockEPRole.setActive(true);
+ mockEPRole.setAppId(2l);
+ mockEPRole.setAppRoleId(1l);
+ mockEPRole.setId(1000l);
+ mockEPRole.setName("test1");
+ EPRole mockEPRole2 = new EPRole();
+ mockEPRole2.setActive(true);
+ mockEPRole2.setAppId(2l);
+ mockEPRole2.setAppRoleId(16l);
+ mockEPRole2.setId(160l);
+ mockEPRole2.setName("test2");
+ EPRole mockEPRole3 = new EPRole();
+ mockEPRole3.setActive(true);
+ mockEPRole3.setAppId(2l);
+ mockEPRole3.setAppRoleId(10l);
+ mockEPRole3.setId(100l);
+ mockEPRole3.setName("test3");
+
+ Mockito.when(epAppCommonServiceImpl.getAppDetail(mockApp.getMlAppName())).thenReturn(mockApp);
+ final Map<String, String> userParams = new HashMap<>();
+ userParams.put("orgUserIdValue", user.getOrgUserId());
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("epUserAppId", userParams, null))
+ .thenReturn(mockEpUserList);
+
+ List<EPUserAppRolesRequest> mockMerdianEpRequestIdValList = new ArrayList<EPUserAppRolesRequest>();
+ Set<EPUserAppRolesRequestDetail> mockEpUserAppRolesRequestDetailList = new TreeSet<>();
+ EPUserAppRolesRequestDetail mockEpUserAppRolesRequestDetail = new EPUserAppRolesRequestDetail();
+ mockEpUserAppRolesRequestDetail.setId(2l);
+ mockEpUserAppRolesRequestDetail.setReqType("P");
+ mockEpUserAppRolesRequestDetail.setReqRoleId(16l);
+ EPUserAppRolesRequest mockEPUserAppRolesRequest = new EPUserAppRolesRequest();
+ mockEPUserAppRolesRequest.setAppId(mockApp.getId());
+ mockEPUserAppRolesRequest.setId(1l);
+ mockEPUserAppRolesRequest.setRequestStatus("P");
+ mockEPUserAppRolesRequest.setUserId(user.getId());
+ mockEPUserAppRolesRequest.setEpRequestIdDetail(mockEpUserAppRolesRequestDetailList);
+ mockMerdianEpRequestIdValList.add(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetail.setEpRequestIdData(mockEPUserAppRolesRequest);
+ mockEpUserAppRolesRequestDetailList.add(mockEpUserAppRolesRequestDetail);
+
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", mockApp.getId());
+ params.put("userId", user.getId());
+ Mockito.when((List<EPUserAppRolesRequest>) dataAccessService.executeNamedQuery("userAppRolesRequestList",
+ params, null)).thenReturn(mockMerdianEpRequestIdValList);
+ RoleInAppForUser mockRoleInAppForUser1 = new RoleInAppForUser();
+ mockRoleInAppForUser1.setIsApplied(true);
+ mockRoleInAppForUser1.setRoleId(1l);
+ mockRoleInAppForUser1.setRoleName("test1");
+ RoleInAppForUser mockRoleInAppForUser2 = new RoleInAppForUser();
+ mockRoleInAppForUser2.setIsApplied(true);
+ mockRoleInAppForUser2.setRoleId(16l);
+ mockRoleInAppForUser2.setRoleName("test2");
+ Mockito.when(epRoleServiceImpl.getAppRole(mockExternalSystemRoleApproval.getRoleName(), mockApp.getId()))
+ .thenReturn(mockEPRole);
+ Mockito.when(epRoleServiceImpl.getAppRole(mockExternalSystemRoleApproval2.getRoleName(), mockApp.getId()))
+ .thenReturn(mockEPRole2);
+ List<EcompUserAppRoles> mockEPuserAppList = new ArrayList<>();
+ EcompUserAppRoles mockEcompUserAppRoles = new EcompUserAppRoles();
+ mockEcompUserAppRoles.setAppId(String.valueOf(mockApp.getId()));
+ mockEcompUserAppRoles.setRoleId(100l);
+ mockEcompUserAppRoles.setRoleName("test1");
+ mockEcompUserAppRoles.setUserId(user.getId());
+ mockEPuserAppList.add(mockEcompUserAppRoles);
+ final Map<String, Long> params2 = new HashMap<>();
+ params2.put("userId", user.getId());
+ params2.put("appId", mockApp.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getUserAppExistingRoles", params2, null))
+ .thenReturn(mockEPuserAppList);
+ List<EcompRole> mockEcompRoleList = new ArrayList<>();
+ EcompRole mockEcompRole = new EcompRole();
+ mockEcompRole.setId(1l);
+ mockEcompRole.setName("test1");
+ EcompRole mockEcompRole2 = new EcompRole();
+ mockEcompRole2.setId(16l);
+ mockEcompRole2.setName("test2");
+ mockEcompRoleList.add(mockEcompRole);
+ mockEcompRoleList.add(mockEcompRole2);
+ EcompRole[] mockEcompRoleArray = mockEcompRoleList.toArray(new EcompRole[mockEcompRoleList.size()]);
+ Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(), "/roles"))
+ .thenReturn(mockEcompRoleArray);
+
+ // SyncAppRoles
+ List<EPUserApp> mockUserRolesList = new ArrayList<>();
+ EPUserApp mockEpUserApp = new EPUserApp();
+ mockEpUserApp.setApp(mockApp);
+ mockEpUserApp.setRole(mockEPRole2);
+ mockEpUserApp.setUserId(user.getId());
+ mockUserRolesList.add(mockEpUserApp);
+ List<FunctionalMenuRole> mockFunctionalMenuRolesList = new ArrayList<>();
+ FunctionalMenuRole mockFunctionalMenuRole = new FunctionalMenuRole();
+ mockFunctionalMenuRole.setAppId((int) (long) mockApp.getId());
+ mockFunctionalMenuRole.setRoleId((int) (long) 15l);
+ mockFunctionalMenuRole.setMenuId(10l);
+ mockFunctionalMenuRole.setId(10);
+ mockFunctionalMenuRolesList.add(mockFunctionalMenuRole);
+ List<FunctionalMenuItem> mockFunctionalMenuItemList = new ArrayList<>();
+ FunctionalMenuItem mockFunctionalMenuItem = new FunctionalMenuItem();
+ List<Integer> mockRolesList = new ArrayList<>();
+ Integer role1 = 1;
+ mockRolesList.add(role1);
+ mockFunctionalMenuItem.setRestrictedApp(false);
+ mockFunctionalMenuItem.setRoles(mockRolesList);
+ mockFunctionalMenuItem.setUrl("http://test.com");
+ mockFunctionalMenuItemList.add(mockFunctionalMenuItem);
+ Query epRoleQuery = Mockito.mock(Query.class);
+ Query epUserAppsQuery = Mockito.mock(Query.class);
+ Query epFunctionalMenuQuery = Mockito.mock(Query.class);
+ Query epFunctionalMenuQuery2 = Mockito.mock(Query.class);
+ Query epFunctionalMenuItemQuery = Mockito.mock(Query.class);
+ Mockito.when(applicationsRestClientService.get(EcompRole[].class, mockApp.getId(), "/roles"))
+ .thenReturn(mockEcompRoleArray);
+ // syncAppRolesTest
+ Mockito.when(session.createQuery("from " + EPRole.class.getName() + " where appId=" + mockApp.getId()))
+ .thenReturn(epRoleQuery);
+ Mockito.doReturn(mockEcompRoleList).when(epRoleQuery).list();
+ Mockito.when(session.createQuery(
+ "from " + EPUserApp.class.getName() + " where app.id=" + mockApp.getId() + " and role_id=" + 100l))
+ .thenReturn(epUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList).when(epUserAppsQuery).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuRole.class.getName() + " where roleId=" + 100l))
+ .thenReturn(epFunctionalMenuQuery);
+ Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuRole.class.getName() + " where menuId=" + 10l))
+ .thenReturn(epFunctionalMenuQuery2);
+ Mockito.doReturn(mockFunctionalMenuRolesList).when(epFunctionalMenuQuery2).list();
+
+ Mockito.when(session.createQuery("from " + FunctionalMenuItem.class.getName() + " where menuId=" + 10l))
+ .thenReturn(epFunctionalMenuItemQuery);
+ Mockito.doReturn(mockFunctionalMenuItemList).when(epFunctionalMenuItemQuery).list();
+
+ Mockito.when(applicationsRestClientService.get(EPUser.class, mockApp.getId(),
+ String.format("/user/%s", user.getOrgUserId()), true)).thenReturn(user);
+ // Updated in EP DB
+ Query epsetExternalRequestUserAppRoleGetUserQuery = Mockito.mock(Query.class);
+ Query epsetExternalRequestUserAppRoleGetUserAppsQuery = Mockito.mock(Query.class);
+ Query epsetExternalRequestUserAppRoleGetRolesQuery = Mockito.mock(Query.class);
+ Mockito.when(session.get(EPApp.class, mockApp.getId())).thenReturn(mockApp);
+ Mockito.when(session
+ .createQuery("from " + EPUser.class.getName() + " where orgUserId='" + user.getOrgUserId() + "'"))
+ .thenReturn(epsetExternalRequestUserAppRoleGetUserQuery);
+ Mockito.doReturn(mockEpUserList).when(epsetExternalRequestUserAppRoleGetUserQuery).list();
+ List<EPUserApp> mockUserRolesList2 = new ArrayList<>();
+ EPUserApp mockEpUserAppRoles = new EPUserApp();
+ mockEpUserAppRoles.setApp(mockApp);
+ mockEpUserAppRoles.setRole(mockEPRole);
+ mockEpUserAppRoles.setUserId(user.getId());
+ mockUserRolesList2.add(mockEpUserAppRoles);
+ Mockito.when(session.createQuery(
+ "from org.onap.portalapp.portal.domain.EPUserApp where app.id=2 and role.active = 'Y' and userId=2"))
+ .thenReturn(epsetExternalRequestUserAppRoleGetUserAppsQuery);
+ Mockito.doReturn(mockUserRolesList2).when(epsetExternalRequestUserAppRoleGetUserAppsQuery).list();
+ List<EPRole> mockEPRoles = new ArrayList<>();
+ mockEPRoles.add(mockEPRole2);
+ mockEPRoles.add(mockEPRole3);
+ Mockito.when(session.createQuery("from org.onap.portalapp.portal.domain.EPRole where appId=2"))
+ .thenReturn(epsetExternalRequestUserAppRoleGetRolesQuery);
+ Mockito.doReturn(mockEPRoles).when(epsetExternalRequestUserAppRoleGetRolesQuery).list();
+
+ ExternalRequestFieldsValidator mockExternalRequestFieldsValidator = new ExternalRequestFieldsValidator(true,
+ "Updated Successfully");
+ ExternalRequestFieldsValidator externalRequestFieldsValidator = userRolesCommonServiceImpl
+ .setExternalRequestUserAppRole(externalSystemUser, "POST");
+ assertTrue(mockExternalRequestFieldsValidator.equals(externalRequestFieldsValidator));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUsersFromAppEndpointCentralizedAppTest() throws HTTPException {
+ EPApp mockApp = mockApp();
+ mockApp.setId(1l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(true);
+ EPUser user = mockUser.mockEPUser();
+ EPUser user2 = mockUser.mockEPUser();
+ user2.setActive(true);
+ user2.setOrgUserId("guestT2");
+ user2.setId(2l);
+ user2.setFirstName("Guest2");
+ user2.setLastName("Test2");
+ user.setId(1l);
+ user.setFirstName("Guest");
+ user.setLastName("Test");
+ EPRole mockEPRole1 = new EPRole();
+ mockEPRole1.setId(1l);
+ mockEPRole1.setName("test1");
+ mockEPRole1.setActive(true);
+ EPRole mockEPRole2 = new EPRole();
+ mockEPRole2.setId(16l);
+ mockEPRole2.setName("test2");
+ mockEPRole2.setActive(true);
+ SortedSet<EPUserApp> mockUserApps1 = new TreeSet<EPUserApp>();
+ EPUserApp mockEPUserApp1 = new EPUserApp();
+ mockEPUserApp1.setApp(mockApp);
+ mockEPUserApp1.setRole(mockEPRole1);
+ mockEPUserApp1.setUserId(1l);
+ mockUserApps1.add(mockEPUserApp1);
+ user.setEPUserApps(mockUserApps1);
+ SortedSet<EPUserApp> mockUserApps2 = new TreeSet<EPUserApp>();
+ EPUserApp mockEPUserApp2 = new EPUserApp();
+ mockEPUserApp2.setApp(mockApp);
+ mockEPUserApp2.setRole(mockEPRole2);
+ mockEPUserApp2.setUserId(2l);
+ mockUserApps2.add(mockEPUserApp2);
+ user2.setEPUserApps(mockUserApps2);
+ List<EPUser> mockEpUserList = new ArrayList<>();
+ mockEpUserList.add(user);
+ mockEpUserList.add(user2);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<UserApplicationRoles> mockUserApplicationRolesList = new ArrayList<>();
+ UserApplicationRoles mockUserApplicationRoles = new UserApplicationRoles();
+ List<RemoteRole> mockRemoteRoleList = new ArrayList<>();
+ RemoteRole mockRemoteRole = new RemoteRole();
+ mockRemoteRole.setId(1l);
+ mockRemoteRole.setName("test1");
+ mockRemoteRoleList.add(mockRemoteRole);
+ mockUserApplicationRoles.setAppId(mockApp.getId());
+ mockUserApplicationRoles.setFirstName("Guest");
+ mockUserApplicationRoles.setLastName("Test");
+ mockUserApplicationRoles.setOrgUserId("guestT");
+ mockUserApplicationRoles.setRoles(mockRemoteRoleList);
+ UserApplicationRoles mockUserApplicationRoles2 = new UserApplicationRoles();
+ List<RemoteRole> mockRemoteRoleList2 = new ArrayList<>();
+ RemoteRole mockRemoteRole2 = new RemoteRole();
+ mockRemoteRole2.setId(16l);
+ mockRemoteRole2.setName("test2");
+ mockRemoteRoleList2.add(mockRemoteRole2);
+ mockUserApplicationRoles2.setAppId(mockApp.getId());
+ mockUserApplicationRoles2.setFirstName("Guest2");
+ mockUserApplicationRoles2.setLastName("Test2");
+ mockUserApplicationRoles2.setOrgUserId("guestT2");
+ mockUserApplicationRoles2.setRoles(mockRemoteRoleList2);
+ mockUserApplicationRolesList.add(mockUserApplicationRoles);
+ mockUserApplicationRolesList.add(mockUserApplicationRoles2);
+ Mockito.when((List<EPUser>) dataAccessService.executeNamedQuery("getActiveUsers", null, null))
+ .thenReturn(mockEpUserList);
+ assertEquals(userRolesCommonServiceImpl.getUsersFromAppEndpoint(1l).size(),
+ mockUserApplicationRolesList.size());
+ }
+
+ @Test
+ public void getUsersFromAppEndpointNonCentralizedAppTest() throws HTTPException, JsonProcessingException {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ Mockito.when(epAppCommonServiceImpl.getApp(mockApp.getId())).thenReturn(mockApp);
+ List<UserApplicationRoles> mockUserApplicationRolesNonCentralizedList = new ArrayList<>();
+ UserApplicationRoles mockUserApplicationRoles = new UserApplicationRoles();
+ List<RemoteRole> mockRemoteRoleList = new ArrayList<>();
+ RemoteRole mockRemoteRole = new RemoteRole();
+ mockRemoteRole.setId(1l);
+ mockRemoteRole.setName("test1");
+ mockRemoteRoleList.add(mockRemoteRole);
+ mockUserApplicationRoles.setAppId(mockApp.getId());
+ mockUserApplicationRoles.setFirstName("Guest");
+ mockUserApplicationRoles.setLastName("Test");
+ mockUserApplicationRoles.setOrgUserId("guestT");
+ mockUserApplicationRoles.setRoles(mockRemoteRoleList);
+ UserApplicationRoles mockUserApplicationRoles2 = new UserApplicationRoles();
+ List<RemoteRole> mockRemoteRoleList2 = new ArrayList<>();
+ RemoteRole mockRemoteRole2 = new RemoteRole();
+ mockRemoteRole2.setId(16l);
+ mockRemoteRole2.setName("test2");
+ mockRemoteRoleList2.add(mockRemoteRole2);
+ mockUserApplicationRoles2.setAppId(mockApp.getId());
+ mockUserApplicationRoles2.setFirstName("Guest2");
+ mockUserApplicationRoles2.setLastName("Test2");
+ mockUserApplicationRoles2.setOrgUserId("guestT2");
+ mockUserApplicationRoles2.setRoles(mockRemoteRoleList2);
+ mockUserApplicationRolesNonCentralizedList.add(mockUserApplicationRoles);
+ mockUserApplicationRolesNonCentralizedList.add(mockUserApplicationRoles2);
+ RemoteUserWithRoles mockRemoteUserWithRoles1 = new RemoteUserWithRoles();
+ mockRemoteUserWithRoles1.setFirstName("Guest1");
+ mockRemoteUserWithRoles1.setLastName("Test1");
+ mockRemoteUserWithRoles1.setOrgUserId("guestT");
+ mockRemoteUserWithRoles1.setRoles(mockRemoteRoleList);
+ RemoteUserWithRoles mockRemoteUserWithRoles2 = new RemoteUserWithRoles();
+ mockRemoteUserWithRoles2.setFirstName("Guest2");
+ mockRemoteUserWithRoles2.setLastName("Test2");
+ mockRemoteUserWithRoles2.setOrgUserId("guestT");
+ mockRemoteUserWithRoles2.setRoles(mockRemoteRoleList2);
+ List<RemoteUserWithRoles> mockRemoteUserWithRolesList = new ArrayList<>();
+ mockRemoteUserWithRolesList.add(mockRemoteUserWithRoles1);
+ mockRemoteUserWithRolesList.add(mockRemoteUserWithRoles2);
+ ObjectMapper mapper = new ObjectMapper();
+ String mockGetRemoteUsersWithRoles = mapper.writeValueAsString(mockRemoteUserWithRolesList);
+ Mockito.when(applicationsRestClientService.getIncomingJsonString(mockApp.getId(), "/users"))
+ .thenReturn(mockGetRemoteUsersWithRoles);
+ List<UserApplicationRoles> userApplicationRolesNonCentralizedList = userRolesCommonServiceImpl
+ .getUsersFromAppEndpoint(2l);
+ assertEquals(mockUserApplicationRolesNonCentralizedList.size(), userApplicationRolesNonCentralizedList.size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void putUserAppRolesRequestTest() {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ EPUser user = mockUser.mockEPUser();
+ AppWithRolesForUser appWithRolesForUser = new AppWithRolesForUser();
+ List<RoleInAppForUser> mockRoleInAppForUserList = new ArrayList<>();
+ RoleInAppForUser roleInAppForUser = new RoleInAppForUser();
+ roleInAppForUser.setIsApplied(true);
+ roleInAppForUser.setRoleId(1l);
+ roleInAppForUser.setRoleName("test1");
+ RoleInAppForUser roleInAppForUser2 = new RoleInAppForUser();
+ roleInAppForUser2.setIsApplied(true);
+ roleInAppForUser2.setRoleId(1000l);
+ roleInAppForUser2.setRoleName("test3");
+ mockRoleInAppForUserList.add(roleInAppForUser);
+ mockRoleInAppForUserList.add(roleInAppForUser2);
+ appWithRolesForUser.setAppId(mockApp.getId());
+ appWithRolesForUser.setAppName(mockApp.getName());
+ appWithRolesForUser.setOrgUserId(user.getOrgUserId());
+ appWithRolesForUser.setAppRoles(mockRoleInAppForUserList);
+ List<EPUserAppRoles> epUserAppRolesList = new ArrayList<>();
+ EPUserAppRoles appRole1 = new EPUserAppRoles();
+ appRole1.setAppId(mockApp.getId());
+ appRole1.setId(10l);
+ appRole1.setRoleId(roleInAppForUser.roleId);
+ epUserAppRolesList.add(appRole1);
+ List<EPUserAppRoles> epUserAppRolesList2 = new ArrayList<>();
+ EPUserAppRoles appRole2 = new EPUserAppRoles();
+ appRole2.setAppId(mockApp.getId());
+ appRole2.setId(11l);
+ appRole2.setRoleId(roleInAppForUser2.roleId);
+ epUserAppRolesList2.add(appRole2);
+ EPUserAppRolesRequest mockEpAppRolesRequestData = new EPUserAppRolesRequest();
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockEpAppRolesRequestData, null);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", appWithRolesForUser.appId);
+ params.put("appRoleId", roleInAppForUser.roleId);
+ Mockito.when((List<EPUserAppRoles>) dataAccessService.executeNamedQuery("appRoles", params, null))
+ .thenReturn(epUserAppRolesList);
+ params.put("appRoleId", roleInAppForUser2.roleId);
+ Mockito.when((List<EPUserAppRoles>) dataAccessService.executeNamedQuery("appRoles", params, null))
+ .thenReturn(epUserAppRolesList2);
+ EPUserAppRolesRequestDetail mockEPAppRoleDetail = new EPUserAppRolesRequestDetail();
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockEPAppRoleDetail, null);
+ FieldsValidator expected = new FieldsValidator();
+ expected.setHttpStatusCode(Long.valueOf(HttpServletResponse.SC_OK));
+ FieldsValidator actual = userRolesCommonServiceImpl.putUserAppRolesRequest(appWithRolesForUser, user);
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void importRolesFromRemoteApplicationTest() throws HTTPException {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ List<EPRole> expected = new ArrayList<>();
+ EPRole epRole = new EPRole();
+ epRole.setAppId(mockApp.getId());
+ epRole.setActive(true);
+ epRole.setId(10l);
+ epRole.setName("test1");
+ EPRole epRole2 = new EPRole();
+ epRole2.setAppId(mockApp.getId());
+ epRole2.setActive(true);
+ epRole2.setId(11l);
+ epRole2.setName("test2");
+ expected.add(epRole);
+ expected.add(epRole2);
+ EPRole[] epRoleArray = expected.toArray(new EPRole[expected.size()]);
+ Mockito.when(applicationsRestClientService.get(EPRole[].class, mockApp.getId(), "/rolesFull"))
+ .thenReturn(epRoleArray);
+ Mockito.when(epRoleServiceImpl.getRole(mockApp.getId(), epRole.getId())).thenReturn(epRole);
+ Mockito.when(epRoleServiceImpl.getRole(mockApp.getId(), epRole2.getId())).thenReturn(epRole2);
+ List<EPRole> actual = userRolesCommonServiceImpl.importRolesFromRemoteApplication(mockApp.getId());
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings("deprecation")
+ @Test
+ public void getCachedAppRolesForUserTest() {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ EPUser user = mockUser.mockEPUser();
+ List<EPUserApp> expected = new ArrayList<>();
+ EPUserApp epUserApp = new EPUserApp();
+ EPRole epRole = new EPRole();
+ epRole.setAppId(mockApp.getId());
+ epRole.setActive(true);
+ epRole.setId(10l);
+ epRole.setName("test1");
+ epUserApp.setApp(mockApp);
+ epUserApp.setRole(epRole);
+ epUserApp.setUserId(user.getId());
+ expected.add(epUserApp);
+ String filter = " where user_id = " + Long.toString(user.getId()) + " and app_id = "
+ + Long.toString(mockApp.getId());
+ Mockito.when(dataAccessService.getList(EPUserApp.class, filter, null, null)).thenReturn(expected);
+ List<EPUserApp> actual = userRolesCommonServiceImpl.getCachedAppRolesForUser(mockApp.getId(), user.getId());
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserAppCatalogRolesTest() {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ EPUser user = mockUser.mockEPUser();
+ List<EPUserAppCatalogRoles> expected = new ArrayList<>();
+ EPUserAppCatalogRoles epUserAppCatalogRoles = new EPUserAppCatalogRoles();
+ epUserAppCatalogRoles.setAppId(mockApp.getId());
+ epUserAppCatalogRoles.setId(2l);
+ epUserAppCatalogRoles.setRequestedRoleId(10l);
+ epUserAppCatalogRoles.setRequestStatus("S");
+ epUserAppCatalogRoles.setRolename("test1");
+ expected.add(epUserAppCatalogRoles);
+ Map<String, String> params = new HashMap<>();
+ params.put("userid", user.getId().toString());
+ params.put("appName", mockApp.getName());
+ Mockito.when(
+ (List<EPUserAppCatalogRoles>) dataAccessService.executeNamedQuery("userAppCatalogRoles", params, null))
+ .thenReturn(expected);
+ List<EPUserAppCatalogRoles> actual = userRolesCommonServiceImpl.getUserAppCatalogRoles(user, mockApp.getName());
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @Test
+ public void getExternalRequestAccessTest() {
+ ExternalSystemAccess expected = new ExternalSystemAccess("external_access_enable", false);
+ ExternalSystemAccess actual = userRolesCommonServiceImpl.getExternalRequestAccess();
+ assertEquals(expected, actual);
+ }
+
+ @Test
+ public void getEPUserAppListTest() {
+ EPApp mockApp = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ EPUser user = mockUser.mockEPUser();
+ List<EPUserApp> expected = new ArrayList<>();
+ EPUserApp epUserApp = new EPUserApp();
+ EPRole epRole = new EPRole();
+ epRole.setAppId(mockApp.getId());
+ epRole.setActive(true);
+ epRole.setId(10l);
+ epRole.setName("test1");
+ epUserApp.setApp(mockApp);
+ epUserApp.setRole(epRole);
+ epUserApp.setUserId(user.getId());
+ expected.add(epUserApp);
+ final Map<String, Long> params = new HashMap<>();
+ params.put("appId", mockApp.getId());
+ params.put("userId", user.getId());
+ params.put("roleId", epRole.getId());
+ Mockito.when(dataAccessService.executeNamedQuery("getUserRoleOnUserIdAndRoleIdAndAppId", params, null))
+ .thenReturn(expected);
+ List<EPUserApp> actual = userRolesCommonServiceImpl.getEPUserAppList(mockApp.getId(), user.getId(),
+ epRole.getId());
+ assertEquals(expected.size(), actual.size());
+ }
+
+ @Test
+ public void updateRemoteUserProfileTest() {
+ EPApp mockApp = mockApp();
+ EPApp mockApp2 = mockApp();
+ mockApp.setId(2l);
+ mockApp.setEnabled(true);
+ mockApp.setCentralAuth(false);
+ EPUser user = mockUser.mockEPUser();
+ List<EPApp> mockEpAppList = new ArrayList<>();
+ mockEpAppList.add(mockApp);
+ mockEpAppList.add(mockApp2);
+ Mockito.when(searchServiceImpl.searchUserByUserId(user.getOrgUserId())).thenReturn(user);
+ Mockito.when(epAppCommonServiceImpl.getUserRemoteApps(user.getId().toString())).thenReturn(mockEpAppList);
+ String expected = "success";
+ String actual = userRolesCommonServiceImpl.updateRemoteUserProfile(user.getOrgUserId(), mockApp.getId());
+ assertEquals(expected, actual);
+ }
+}
diff --git a/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetParameterServiceImplTest.java b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetParameterServiceImplTest.java
new file mode 100644
index 00000000..ffaee13f
--- /dev/null
+++ b/ecomp-portal-BE-common/src/test/java/org/onap/portalapp/portal/service/WidgetParameterServiceImplTest.java
@@ -0,0 +1,129 @@
+/*-
+ * ============LICENSE_START==========================================
+ * ONAP Portal
+ * ===================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ===================================================================
+ *
+ * Unless otherwise specified, all software contained herein is licensed
+ * under the Apache License, Version 2.0 (the "License");
+ * you may not use this software except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Unless otherwise specified, all documentation contained herein is licensed
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
+ * you may not use this documentation except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://creativecommons.org/licenses/by/4.0/
+ *
+ * Unless required by applicable law or agreed to in writing, documentation
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ============LICENSE_END============================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+package org.onap.portalapp.portal.service;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.hibernate.criterion.Criterion;
+import org.hibernate.criterion.Restrictions;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.onap.portalapp.portal.core.MockEPUser;
+import org.onap.portalapp.portal.domain.WidgetCatalogParameter;
+import org.onap.portalsdk.core.service.DataAccessService;
+import org.onap.portalsdk.core.service.DataAccessServiceImpl;
+
+public class WidgetParameterServiceImplTest {
+ @Mock
+ DataAccessService dataAccessService = new DataAccessServiceImpl();
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @InjectMocks
+ WidgetParameterServiceImpl widgetParameterServiceImpl = new WidgetParameterServiceImpl();
+
+ MockEPUser mockUser = new MockEPUser();
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserParamByIdTest() {
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion widgetIdCrit = Restrictions.eq("widgetId", "1");
+ restrictionsList.add(widgetIdCrit);
+ Criterion userIdCrit = Restrictions.eq("userId", "1");
+ restrictionsList.add(userIdCrit);
+ Criterion paramIdCrit = Restrictions.eq("paramId", "1");
+ restrictionsList.add(paramIdCrit);
+ List<WidgetCatalogParameter> mockWidgetCatParamsList = new ArrayList<>();
+ Mockito.when((List<WidgetCatalogParameter>)dataAccessService
+ .getList(WidgetCatalogParameter.class, null, restrictionsList, null)).thenReturn(mockWidgetCatParamsList);
+ WidgetCatalogParameter widgetCatalogParameter = widgetParameterServiceImpl.getUserParamById(1l, 1l, 1l);
+ if(mockWidgetCatParamsList.isEmpty()) {
+ mockWidgetCatParamsList = null;
+ }
+ assertEquals(widgetCatalogParameter, mockWidgetCatParamsList);
+ }
+
+ @Test
+ public void saveUserParameterTest(){
+ WidgetCatalogParameter mockWidgetParameter = new WidgetCatalogParameter();
+ WidgetCatalogParameter widgetParameter = new WidgetCatalogParameter();
+ widgetParameter.setId(1l);
+ widgetParameter.setParamId(1l);
+ widgetParameter.setUser_value("test");
+ widgetParameter.setWidgetId(1l);
+ widgetParameter.setUserId(1l);
+ Mockito.doNothing().when(dataAccessService).saveDomainObject(mockWidgetParameter, null);
+ widgetParameterServiceImpl.saveUserParameter(widgetParameter);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void getUserParameterByIdTest() {
+ List<Criterion> restrictionsList = new ArrayList<Criterion>();
+ Criterion paramIdCrit = Restrictions.eq("paramId", 1);
+ restrictionsList.add(paramIdCrit);
+ List<WidgetCatalogParameter> mockWidgetCatalogParameter = new ArrayList<>();
+ Mockito.when((List<WidgetCatalogParameter>) dataAccessService
+ .getList(WidgetCatalogParameter.class, null, restrictionsList, null)).thenReturn(mockWidgetCatalogParameter);
+ List<WidgetCatalogParameter> list = widgetParameterServiceImpl.getUserParameterById(1l);
+ assertEquals(list, mockWidgetCatalogParameter);
+ }
+
+ @Test
+ public void deleteUserParameterById() {
+ Map<String, String> params = new HashMap<String, String>();
+ params.put("paramId", Long.toString(1));
+ Mockito.when(dataAccessService.executeNamedQuery("deleteWidgetCatalogParameter", params, null)).thenReturn(null);
+ Mockito.when(dataAccessService.executeNamedQuery("deleteMicroserviceParameterById", params, null)).thenReturn(null);
+ widgetParameterServiceImpl.deleteUserParameterById(1l);
+ }
+
+}