aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java21
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java84
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java3
-rwxr-xr-xvid-app-common/src/main/webapp/app/vid/test/testMso.js36
-rwxr-xr-xvid-app-common/src/main/webapp/app/vid/test/testViewEdit.js40
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java231
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/logging/VidLoggerAspectTest.java43
9 files changed, 319 insertions, 148 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
index f511a4746..6fe295c15 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
@@ -3,6 +3,7 @@
* VID
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2018 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +28,8 @@ import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationshipList {
+ public List<Relationship> relationship;
+
@JsonProperty("relationship")
public List<Relationship> getRelationship() {
return relationship;
@@ -37,7 +40,6 @@ public class RelationshipList {
this.relationship = relationship;
}
- public List<Relationship> relationship;
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
index eee2acc51..2b3ad60ea 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController.java
@@ -77,6 +77,7 @@ public class AaiController extends RestrictedBaseController {
private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(AaiController.class);
private static final String FROM_APP_ID = "VidAaiController";
+ private final ObjectMapper objectMapper = new ObjectMapper();
private AaiService aaiService;
private AAIRestInterface aaiRestInterface;
@@ -157,7 +158,7 @@ public class AaiController extends RestrictedBaseController {
throws IOException {
ResponseEntity<String> responseEntity;
if (aaiResponseData.getHttpCode() == 200) {
- responseEntity = new ResponseEntity<>(new ObjectMapper().writeValueAsString(aaiResponseData.getT()),
+ responseEntity = new ResponseEntity<>(objectMapper.writeValueAsString(aaiResponseData.getT()),
HttpStatus.OK);
} else {
responseEntity = new ResponseEntity<>(aaiResponseData.getErrorMessage(),
@@ -225,7 +226,6 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_full_subscribers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getFullSubscriberList(HttpServletRequest request) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity<String> responseEntity;
RoleValidator roleValidator = RoleValidator.by(roleProvider.getUserRoles(request));
SubscriberFilteredResults subscriberList = aaiService.getFullSubscriberList(roleValidator);
@@ -270,17 +270,14 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_sub_details/{subscriberId}", method = RequestMethod.GET)
public ResponseEntity<String> getSubscriberDetails(HttpServletRequest request, @PathVariable("subscriberId") String subscriberId,
@RequestParam(value="omitServiceInstances", required = false, defaultValue = "false") boolean omitServiceInstances) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
- ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
RoleValidator roleValidator = RoleValidator.by(roles);
- AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator, featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances);
- String httpMessage = subscriberData.getT() != null ?
- objectMapper.writeValueAsString(subscriberData.getT()) :
- subscriberData.getErrorMessage();
+ AaiResponse subscriberData = aaiService.getSubscriberData(subscriberId, roleValidator,
+ featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH) && omitServiceInstances);
+ String httpMessage = subscriberData.getT() != null ? objectMapper.writeValueAsString(subscriberData.getT()) : subscriberData.getErrorMessage();
- responseEntity = new ResponseEntity<>(httpMessage, HttpStatus.valueOf(subscriberData.getHttpCode()));
- return responseEntity;
+ return new ResponseEntity<>(httpMessage,
+ HttpStatus.valueOf(subscriberData.getHttpCode()));
}
@RequestMapping(value = "/search_service_instances", method = RequestMethod.GET)
@@ -289,7 +286,6 @@ public class AaiController extends RestrictedBaseController {
@RequestParam(value = "serviceInstanceIdentifier", required = false) String instanceIdentifier,
@RequestParam(value = "project", required = false) List<String> projects,
@RequestParam(value = "owningEntity", required = false) List<String> owningEntities) throws IOException {
- ObjectMapper objectMapper = new ObjectMapper();
ResponseEntity responseEntity;
List<Role> roles = roleProvider.getUserRoles(request);
@@ -354,7 +350,6 @@ public class AaiController extends RestrictedBaseController {
@RequestMapping(value = "/aai_get_network_collection_details/{serviceInstanceId}", method = RequestMethod.GET)
public ResponseEntity<String> getNetworkCollectionDetails(
@PathVariable("serviceInstanceId") String serviceInstanceId) throws IOException {
- com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
AaiResponse<String> resp = aaiService.getNetworkCollectionDetails(serviceInstanceId);
String httpMessage = resp.getT() != null ?
@@ -367,7 +362,6 @@ public class AaiController extends RestrictedBaseController {
public ResponseEntity<String> getInstanceGroupsByCloudRegion(@PathVariable("cloudOwner") String cloudOwner,
@PathVariable("cloudRegionId") String cloudRegionId,
@PathVariable("networkFunction") String networkFunction) throws IOException {
- com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
AaiResponse<AaiGetInstanceGroupsByCloudRegion> resp = aaiService
.getInstanceGroupsByCloudRegion(cloudOwner, cloudRegionId, networkFunction);
@@ -424,7 +418,6 @@ public class AaiController extends RestrictedBaseController {
ResponseEntity responseEntity;
try {
- ObjectMapper objectMapper = new ObjectMapper();
List<Role> roles = roleProvider.getUserRoles(request);
RoleValidator roleValidator = RoleValidator.by(roles);
AaiResponse<GetTenantsResponse[]> response = aaiService
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
index befbe0320..693c84bff 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/ControllersUtils.java
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nokia. All rights reserved.
+ * Modifications Copyright (C) 2019 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,9 +46,7 @@ public final class ControllersUtils {
public static ExceptionResponse handleException(Exception e, EELFLoggerDelegate logger) {
logger.error(EELFLoggerDelegate.errorLogger, "{}: {}", getMethodCallerName(), ExceptionUtils.getMessage(e), e);
-
- ExceptionResponse exceptionResponse = new ExceptionResponse(e);
- return exceptionResponse;
+ return new ExceptionResponse(e);
}
public static ResponseEntity handleWebApplicationException(WebApplicationException e, EELFLoggerDelegate logger) {
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
index 514779f49..309ead40c 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
@@ -20,6 +20,13 @@
package org.onap.vid.logging;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static org.apache.commons.lang3.StringUtils.defaultIfEmpty;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -27,13 +34,14 @@ import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.service.AppService;
import org.onap.portalsdk.core.util.SystemProperties;
+import org.onap.portalsdk.core.web.support.UserUtils;
+import org.onap.vid.controller.ControllersUtils;
+import org.onap.vid.utils.SystemPropertiesWrapper;
import org.springframework.beans.factory.annotation.Autowired;
-
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
@Aspect
@@ -41,10 +49,14 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
public class VidLoggerAspect {
private String canonicalHostName;
- @Autowired
- EELFLoggerAdvice advice;
+ private final ControllersUtils controllersUtils;
+ private final String appName;
+
+ private final EELFLoggerAdvice advice;
- public VidLoggerAspect() {
+ @Autowired
+ public VidLoggerAspect(EELFLoggerAdvice advice, SystemPropertiesWrapper systemPropertiesWrapper,
+ AppService appService) {
try {
final InetAddress localHost = InetAddress.getLocalHost();
canonicalHostName = localHost.getCanonicalHostName();
@@ -52,9 +64,13 @@ public class VidLoggerAspect {
// YOLO
canonicalHostName = null;
}
+ this.advice = advice;
+ this.controllersUtils = new ControllersUtils(systemPropertiesWrapper);
+
+ this.appName = defaultIfEmpty(appService.getDefaultAppName(), SystemProperties.SDK_NAME);
}
- @Pointcut("execution(public * org.onap.vid.controller.*Controller.*(..))")
+ @Pointcut("execution(public * org.onap.vid.controller..*Controller.*(..))")
public void vidControllers() {}
@Around("vidControllers() && (" +
@@ -69,7 +85,10 @@ public class VidLoggerAspect {
private Object logAroundMethod(ProceedingJoinPoint joinPoint, SystemProperties.SecurityEventTypeEnum securityEventType) throws Throwable {
//Before
Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
- Object[] returnArgs = advice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
+ Object[] returnArgs = advice.before(securityEventType, fabricateArgsWithNull(), passOnArgs);
+
+ fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequestOrNull(joinPoint),
+ joinPoint.getSignature().getDeclaringType().getName());
fixServerFqdnInMDC();
@@ -94,6 +113,51 @@ public class VidLoggerAspect {
EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus);
}
+ /**
+ * Returns an array with a single entry with a null value. This will stop org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before
+ * from throwing on ArrayIndexOutOfBound, and also prevent SessionExpiredException.
+ */
+ private Object[] fabricateArgsWithNull() {
+ return new Object[]{null};
+ }
+
+ /**
+ * Finds the first joinPoint's param which is an HttpServletRequest. If not found, use Spring's RequestContextHolder
+ * to retrieve it.
+ *
+ * @return null or the current httpServletRequest
+ */
+ private HttpServletRequest httpServletRequestOrNull(ProceedingJoinPoint joinPoint) {
+ final Object httpServletRequest = Arrays.stream(joinPoint.getArgs())
+ .filter(param -> param instanceof HttpServletRequest)
+ .findFirst()
+ .orElseGet(() -> {
+ try {
+ return ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
+ } catch (Exception e) { // ClassCast, IllegalState, etc.
+ return null;
+ }
+ });
+
+ return (HttpServletRequest) httpServletRequest;
+ }
+
+ /**
+ * Mimics a part from org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice.before, but with much more carefulness
+ * of exceptions and defaults. Main difference is that if no session, function does not throw. It just fallback to
+ * an empty loginId.
+ */
+ private void fixSetRequestBasedDefaultsIntoGlobalLoggingContext(HttpServletRequest httpServletRequest, String className) {
+ if (httpServletRequest != null) {
+
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(className);
+ String requestId = UserUtils.getRequestId(httpServletRequest);
+ String loginId = controllersUtils.extractUserId(httpServletRequest);
+
+ logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId);
+ }
+ }
+
// Override the non-canonical hostname set by EELFLoggerDelegate::setGlobalLoggingContext()
// that was invoked by advice.before() (and some other SDK cases)
private void fixServerFqdnInMDC() {
diff --git a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
index 7878c2fb8..001a8ae6d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/scheduler/SchedulerRestInterface.java
@@ -98,12 +98,13 @@ public class SchedulerRestInterface implements SchedulerRestInterfaceIfc {
status = response.getStatus();
restObject.setStatusCode(status);
rawData = response.getBody();
+ restObject.setRaw(rawData);
if (status == 200) {
if (t instanceof String) {
restObject.set((T)rawData);
}
else {
- restObject.set(JACKSON_OBJECT_MAPPER.readValue(rawData, new TypeReference<T>() {}));
+ restObject.set(JACKSON_OBJECT_MAPPER.readValue(rawData, (Class<T>)t.getClass()));
}
logger.debug(EELFLoggerDelegate.debugLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE);
logger.info(EELFLoggerDelegate.errorLogger, "<== " + methodName + SUCCESSFUL_API_MESSAGE);
diff --git a/vid-app-common/src/main/webapp/app/vid/test/testMso.js b/vid-app-common/src/main/webapp/app/vid/test/testMso.js
index 7f14ef8ce..8e207d52e 100755
--- a/vid-app-common/src/main/webapp/app/vid/test/testMso.js
+++ b/vid-app-common/src/main/webapp/app/vid/test/testMso.js
@@ -45,13 +45,13 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
setTestMode();
DataService.setSubscriberName("Mobility");
- DataService.setGlobalCustomerId("CUSTID12345")
+ DataService.setGlobalCustomerId("CUSTID12345");
DataService.setServiceType("Mobility Type 1");
DataService.setServiceName("Mobility Service 1");
DataService.setServiceInstanceId("mmsc-test-service-instance");
DataService.setVnfInstanceId("abcd-12345-56789");
DataService.setVfModuleInstanceId("xye-99990123213");
- }
+ };
var TEST_MODE_COOKIE = "isTestModeEnabled";
@@ -75,7 +75,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
} else {
PropertyService.setMsoBaseUrl(defaultMsoBaseUrl);
}
- }
+ };
$scope.autoStartCommitTest = function() {
/*
@@ -87,7 +87,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
// $scope.deleteServiceInstance();
// $scope.generateInvalidUrl404();
}, 500);
- }
+ };
$scope.autoStartQueryTest = function() {
/*
@@ -97,7 +97,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
$timeout(function() {
// $scope.queryServiceInstance();
}, 500);
- }
+ };
$scope.queryServiceInstance = function() {
/*
@@ -106,7 +106,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
$scope.$broadcast("showComponentDetails", {
componentId : COMPONENT.SERVICE
});
- }
+ };
$scope.createServiceInstance = function() {
/*
@@ -116,7 +116,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_svc_instance",
requestDetails : createServiceRequestDetails
});
- }
+ };
$scope.deleteServiceInstance = function() {
/*
@@ -126,7 +126,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_delete_svc_instance/bc305d54-75b4-431b-adb2-eb6b9e546014",
requestDetails : deleteServiceRequestDetails
});
- }
+ };
$scope.createVNFInstance = function() {
/*
@@ -136,7 +136,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_vnf_instance/bc305d54-75b4-431b-adb2-eb6b9e546099",
requestDetails : createVnfRequestDetails
});
- }
+ };
$scope.deleteVNFInstance = function() {
/*
@@ -146,7 +146,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_delete_vnf_instance/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/ab9000-0009-9999",
requestDetails : deleteVnfRequestDetails
});
- }
+ };
$scope.createVolumeGroupInstance = function() {
/*
@@ -156,7 +156,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_volumegroup_instance/bc305d54-75b4-431b-adb2-eb6b9e546099/vnfs/fe305d54-75b4-431b-adb2-eb6b9e546fea",
requestDetails : createVolumeGroupRequestDetails
});
- }
+ };
$scope.deleteVolumeGroupInstance = function() {
/*
@@ -166,7 +166,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_delete_volumegroup_instance/bc305d54-75b4-431b-adb2-eb6b9e546014/vnfs/fe305d54-75b4-431b-adb2-eb6b9e546fea/volumeGroups/fe9000-0009-9999",
requestDetails : deleteVolumeGroupRequestDetails
});
- }
+ };
$scope.createVFModuleInstance = function() {
/*
* Example of method call needed to commit an instance creation request.
@@ -175,7 +175,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_vfmodule_instance/bc305d54-75b4-431b-adb2-eb6b9e546099/vnfs/111-111-111-111",
requestDetails : createVFModuleRequestDetails
});
- }
+ };
$scope.deleteVFModuleInstance = function() {
/*
@@ -192,14 +192,14 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_nw_instance/789098877777",
requestDetails : createNetworkRequestDetails
});
- }
+ };
$scope.deleteNetworkInstance = function() {
$scope.$broadcast("deleteInstance", {
url : "mso_delete_nw_instance/bc305d54-75b4-431b-adb2-eb6b9e546014/networks/ff305d54-75b4-ff1b-fff1-eb6b9e5460ff",
requestDetails : deleteNetworkRequestDetails
});
- }
+ };
$scope.generateError = function(testName) {
// Clone example request object
@@ -209,7 +209,7 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
url : "mso_create_svc_instance",
requestDetails : request
});
- }
+ };
$scope.generateInvalidUrl404 = function() {
var baseUrl = PropertyService.getMsoBaseUrl();
@@ -223,14 +223,14 @@ app.controller("testController", [ "$scope", "$timeout", "$cookieStore", "$log",
$scope.popup.isVisible = false;
}
});
- }
+ };
$scope.generateInvalidUrl405 = function() {
$scope.$broadcast("createInstance", {
url : "INVALID_STRING_mso_create_svc_instance",
requestDetails : createServiceRequestDetails
});
- }
+ };
/*
* Test data objects:
diff --git a/vid-app-common/src/main/webapp/app/vid/test/testViewEdit.js b/vid-app-common/src/main/webapp/app/vid/test/testViewEdit.js
index 5b4d8bd8b..a09a8ce37 100755
--- a/vid-app-common/src/main/webapp/app/vid/test/testViewEdit.js
+++ b/vid-app-common/src/main/webapp/app/vid/test/testViewEdit.js
@@ -47,7 +47,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
*/
DataService.setSubscriberName("Mobility");
- DataService.setGlobalCustomerId("CUSTID12345")
+ DataService.setGlobalCustomerId("CUSTID12345");
DataService.setServiceType("Mobility Type 1");
DataService.setServiceInstanceName("Example Service Instance Name");
DataService.setServiceName("Mobility Service 1");
@@ -61,7 +61,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
setTestMode();
- }
+ };
$scope.autoStartTest = function() {
/*
@@ -80,7 +80,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
// $scope.deleteVnf();
// $scope.createVfModule();
}, 500);
- }
+ };
/*
* This block of code is only used for testing.
@@ -165,14 +165,14 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.SERVICE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.createVnf = function() {
DataService.setModelId("91238134091820938018230918230989");
DataService.setModelInstanceName("VNF_MODEL_INSTANCE_NAME");
- DataService.setCloudRegionTenantList(exampleCloudRegionTenantList)
+ DataService.setCloudRegionTenantList(exampleCloudRegionTenantList);
DataService.setServiceIdList(exampleServiceIdList);
// Data used to create MSO "relatedInstanceList" object
@@ -183,7 +183,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VNF,
callbackFunction : callbackFunction
});
- }
+ };
$scope.createVfModule = function() {
DataService
@@ -211,7 +211,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VF_MODULE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.createVolumeGroup = function() {
@@ -230,7 +230,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VOLUME_GROUP,
callbackFunction : callbackFunction
});
- }
+ };
$scope.createNetwork = function() {
@@ -248,7 +248,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.NETWORK,
callbackFunction : callbackFunction
});
- }
+ };
/*
* Delete functions
@@ -263,7 +263,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.SERVICE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.deleteVnf = function() {
@@ -279,7 +279,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VNF,
callbackFunction : callbackFunction
});
- }
+ };
$scope.deleteVfModule = function() {
@@ -296,7 +296,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VF_MODULE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.deleteVolumeGroup = function() {
@@ -313,7 +313,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VOLUME_GROUP,
callbackFunction : callbackFunction
});
- }
+ };
$scope.deleteNetwork = function() {
@@ -328,7 +328,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.NETWORK,
callbackFunction : callbackFunction
});
- }
+ };
/*
* Show Details functions
@@ -341,7 +341,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.SERVICE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.showVnfDetails = function() {
@@ -353,7 +353,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VNF,
callbackFunction : callbackFunction
});
- }
+ };
$scope.showVfModuleDetails = function() {
@@ -365,7 +365,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VF_MODULE,
callbackFunction : callbackFunction
});
- }
+ };
$scope.showVolumeGroupDetails = function() {
@@ -376,7 +376,7 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.VOLUME_GROUP,
callbackFunction : callbackFunction
});
- }
+ };
$scope.showNetworkDetails = function() {
@@ -387,8 +387,8 @@ var testViewEditController = function(COMPONENT, DataService, PropertyService,
componentId : COMPONENT.NETWORK,
callbackFunction : callbackFunction
});
- }
-}
+ };
+};
app.controller("testViewEditController", [ "COMPONENT", "DataService",
"PropertyService", "UtilityService", "$scope", "$timeout",
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
index 2377c8055..b51bbdc31 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiControllerTest.java
@@ -21,14 +21,11 @@
package org.onap.vid.controller;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.ArgumentMatchers.booleanThat;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@@ -40,16 +37,14 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
-import java.io.IOException;
import java.util.Map;
import java.util.UUID;
-import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Answers;
import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.aai.AaiResponse;
import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData;
@@ -62,13 +57,13 @@ import org.onap.vid.aai.model.PortDetailsTranslator.PortDetails;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsError;
import org.onap.vid.aai.model.PortDetailsTranslator.PortDetailsOk;
import org.onap.vid.aai.util.AAIRestInterface;
-import org.onap.vid.properties.Features;
-import org.onap.vid.roles.Role;
import org.onap.vid.model.VersionByInvariantIdsRequest;
+import org.onap.vid.properties.Features;
import org.onap.vid.roles.RoleProvider;
-import org.onap.vid.roles.RoleValidator;
+import org.onap.vid.roles.RoleValidatorByRoles;
import org.onap.vid.services.AaiService;
import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.onap.vid.utils.Unchecked;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
@@ -83,7 +78,7 @@ public class AaiControllerTest {
private final ObjectMapper objectMapper = new ObjectMapper();
@Mock
private AaiService aaiService;
- @Mock
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
private AAIRestInterface aaiRestInterface;
@Mock
private RoleProvider roleProvider;
@@ -98,11 +93,140 @@ public class AaiControllerTest {
@Before
public void setUp() {
- aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper, featureManager);
+ aaiController = new AaiController(aaiService, aaiRestInterface, roleProvider, systemPropertiesWrapper,
+ featureManager);
mockMvc = MockMvcBuilders.standaloneSetup(aaiController).build();
}
@Test
+ public void getAicZoneForPnf_shouldReturnOKResponse() throws Exception {
+ String globalCustomerId = "testCustomerId";
+ String serviceType = "testServiceType";
+ String serviceId = "testServiceId";
+ String expectedResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
+ given(aaiService.getAicZoneForPnf(globalCustomerId, serviceType, serviceId)).willReturn(aaiResponse);
+
+ mockMvc.perform(
+ get("/aai_get_aic_zone_for_pnf/{globalCustomerId}/{serviceType}/{serviceId}", globalCustomerId, serviceType,
+ serviceId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+
+ @Test
+ public void getInstanceGroupsByVnfInstanceId_shouldReturnOKResponse() throws Exception {
+ String vnfInstanceId = "testVndInstanceId";
+ String expectedResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(expectedResponseBody, null, HttpStatus.OK.value());
+ given(aaiService.getInstanceGroupsByVnfInstanceId(vnfInstanceId)).willReturn(aaiResponse);
+
+ mockMvc.perform(get("/aai_get_instance_groups_by_vnf_instance_id/{vnfInstanceId}", vnfInstanceId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(objectMapper.writeValueAsString(expectedResponseBody)));
+ }
+
+ @Test
+ public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceId() throws Exception {
+ String serviceInstanceId = "testServiceInstanceId";
+ String serviceInstanceType = "Service Instance Id";
+ String expectedResponseBody = "OK_RESPONSE";
+ Response response = mock(Response.class);
+ given(response.readEntity(String.class)).willReturn(expectedResponseBody);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+
+ given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI(
+ "search/nodes-query?search-node-type=service-instance&filter=service-instance-id:EQUALS:"
+ + serviceInstanceId)),
+ eq(false)).getResponse()).willReturn(response);
+
+ mockMvc
+ .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId,
+ serviceInstanceType)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(expectedResponseBody));
+ }
+
+ @Test
+ public void doGetServiceInstance_shouldFetchServiceInstance_byServiceInstanceName() throws Exception {
+ String serviceInstanceId = "testServiceInstanceId";
+ String serviceInstanceType = "testServiceInstanceType";
+ String expectedResponseBody = "OK_RESPONSE";
+ Response response = mock(Response.class);
+ given(response.readEntity(String.class)).willReturn(expectedResponseBody);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+
+ given(aaiRestInterface.RestGet(eq("VidAaiController"), anyString(), eq(Unchecked.toURI(
+ "search/nodes-query?search-node-type=service-instance&filter=service-instance-name:EQUALS:"
+ + serviceInstanceId)),
+ eq(false)).getResponse()).willReturn(response);
+
+ mockMvc
+ .perform(get("/aai_get_service_instance/{service-instance-id}/{service-instance-type}", serviceInstanceId,
+ serviceInstanceType)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(expectedResponseBody));
+ }
+
+ @Test
+ public void doGetServices_shouldReturnOkResponse() throws Exception {
+ String globalCustomerId = "testGlobalCustomerId";
+ String serviceSubscriptionId = "testServiceSubscriptionId";
+ String expectedResponseBody = "OK_RESPONSE";
+ Response response = mock(Response.class);
+ given(response.readEntity(String.class)).willReturn(expectedResponseBody);
+ given(response.getStatus()).willReturn(HttpStatus.OK.value());
+
+ given(aaiRestInterface.RestGet(
+ eq("VidAaiController"),
+ anyString(),
+ eq(Unchecked.toURI(
+ "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
+ + serviceSubscriptionId + "?depth=0")),
+ eq(false)).getResponse()).willReturn(response);
+
+ mockMvc
+ .perform(
+ get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId,
+ serviceSubscriptionId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(expectedResponseBody));
+ }
+
+ @Test
+ public void doGetServices_shouldReturnInternalServerError_forEmptyResponse() throws Exception {
+ String globalCustomerId = "testGlobalCustomerId";
+ String serviceSubscriptionId = "testServiceSubscriptionId";
+ String expectedResponseBody = "Failed to fetch data from A&AI, check server logs for details.";
+ given(aaiRestInterface.RestGet(
+ eq("VidAaiController"),
+ anyString(),
+ eq(Unchecked.toURI(
+ "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/"
+ + serviceSubscriptionId + "?depth=0")),
+ eq(false)).getResponse()).willReturn(null);
+
+ mockMvc
+ .perform(
+ get("/aai_get_service_subscription/{global-customer-id}/{service-subscription-id}", globalCustomerId,
+ serviceSubscriptionId)
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isInternalServerError())
+ .andExpect(content().string(expectedResponseBody));
+ }
+
+ @Test
public void getPortMirroringConfigData_givenIds_shouldReturnConfigDataMappedById() throws Exception {
PortMirroringConfigDataOk okConfigData = new PortMirroringConfigDataOk("foo");
PortMirroringConfigDataError errorConfigData = new PortMirroringConfigDataError("bar", "{ baz: qux }");
@@ -259,7 +383,7 @@ public class AaiControllerTest {
mockMvc.perform(
post("/aai_get_version_by_invariant_id")
- .content(new ObjectMapper().writeValueAsString(request))
+ .content(objectMapper.writeValueAsString(request))
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
@@ -267,40 +391,71 @@ public class AaiControllerTest {
}
@Test
- public void getSubscriberDetailsOmitServiceInstances_reduceDepthEnabledAndOmitQueryParam() throws IOException {
- getSubscriberDetailsOmitServiceInstances("some subscriber id",
- true, true, true);
+ public void getSubscriberDetails_shouldOmitServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsTrue()
+ throws Exception {
+ boolean isFeatureActive = true;
+ boolean omitServiceInstances = true;
+
+ String subscriberId = "subscriberId";
+ String okResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value());
+ given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive);
+ given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidatorByRoles.class),
+ eq(isFeatureActive && omitServiceInstances)))
+ .willReturn(aaiResponse);
+
+ mockMvc.perform(
+ get("/aai_sub_details/{subscriberId}", subscriberId)
+ .param("omitServiceInstances", Boolean.toString(omitServiceInstances))
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody)));
}
@Test
- public void getSubscriberDetailsOmitServiceInstances_reduceDepthDisabledAndOmitQueryParam() throws IOException {
- getSubscriberDetailsOmitServiceInstances("another-subscriber-id-123",
- false, true, false);
+ public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureEnabled_andOmitFlagIsFalse()
+ throws Exception {
+ boolean isFeatureActive = true;
+ boolean omitServiceInstances = false;
+
+ getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
}
@Test
- public void getSubscriberDetailsOmitServiceInstances_reduceDepthDisabled() throws IOException {
- getSubscriberDetailsOmitServiceInstances("123-456-789-123-345-567-6",
- false, false, false);
+ public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsTrue()
+ throws Exception {
+ boolean isFeatureActive = false;
+ boolean omitServiceInstances = true;
+
+ getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
}
@Test
- public void getSubscriberDetailsOmitServiceInstances_reduceDepthEnabled() throws IOException {
- getSubscriberDetailsOmitServiceInstances("0000000000000000000000000",
- true, false, false);
+ public void getSubscriberDetails_shouldIncludeServiceInstancesFromSubscriberData_whenFeatureDisabled_andOmitFlagIsFalse()
+ throws Exception {
+ boolean isFeatureActive = false;
+ boolean omitServiceInstances = false;
+ getSubscriberDetails_assertServiceInstancesInclusion(isFeatureActive, omitServiceInstances);
}
- private void getSubscriberDetailsOmitServiceInstances(String subscriberId, boolean isFlag1906AaiSubDetailsReduceDepthEnabled,
- boolean omitServiceInstancesQueryParam, boolean omitServiceInstancesExpectedGetSubscriberDataParam) throws IOException {
- when(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).thenReturn(isFlag1906AaiSubDetailsReduceDepthEnabled);
- HttpServletRequest request = mock(HttpServletRequest.class);
- when(roleProvider.getUserRoles(request)).thenReturn(ImmutableList.of(mock(Role.class), mock(Role.class)));
- AaiResponse subscriberData = mock(AaiResponse.class);
- when(subscriberData.getT()).thenReturn(null);
- when(subscriberData.getHttpCode()).thenReturn(200);
- when(aaiService.getSubscriberData(any(), any(), anyBoolean())).thenReturn(subscriberData);
- aaiController.getSubscriberDetails(request, subscriberId, omitServiceInstancesQueryParam);
- verify(aaiService).getSubscriberData(argThat(subscriberId::equals), any(RoleValidator.class), booleanThat(b -> omitServiceInstancesExpectedGetSubscriberDataParam == b));
+ private void getSubscriberDetails_assertServiceInstancesInclusion(boolean isFeatureActive,
+ boolean omitServiceInstances) throws Exception {
+ String subscriberId = "subscriberId";
+ String okResponseBody = "OK_RESPONSE";
+ AaiResponse<String> aaiResponse = new AaiResponse<>(okResponseBody, "", HttpStatus.OK.value());
+ given(featureManager.isActive(Features.FLAG_1906_AAI_SUB_DETAILS_REDUCE_DEPTH)).willReturn(isFeatureActive);
+ given(aaiService.getSubscriberData(eq(subscriberId), isA(RoleValidatorByRoles.class),
+ eq(isFeatureActive && omitServiceInstances)))
+ .willReturn(aaiResponse);
+
+ mockMvc.perform(
+ get("/aai_sub_details/{subscriberId}", subscriberId)
+ .param("omitServiceInstances", Boolean.toString(omitServiceInstances))
+ .contentType(MediaType.APPLICATION_JSON)
+ .accept(MediaType.APPLICATION_JSON))
+ .andExpect(status().isOk())
+ .andExpect(content().string(objectMapper.writeValueAsString(okResponseBody)));
}
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggerAspectTest.java b/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggerAspectTest.java
deleted file mode 100644
index 82f0b85ba..000000000
--- a/vid-app-common/src/test/java/org/onap/vid/logging/VidLoggerAspectTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * VID
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.vid.logging;
-
-import org.aspectj.lang.ProceedingJoinPoint;
-import org.junit.Test;
-import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
-
-
-public class VidLoggerAspectTest {
-
- private VidLoggerAspect createTestSubject() {
- return new VidLoggerAspect();
- }
-
- @Test
- public void testVidControllers() throws Exception {
- VidLoggerAspect testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.vidControllers();
- }
-
-}