aboutsummaryrefslogtreecommitdiffstats
path: root/plans
diff options
context:
space:
mode:
Diffstat (limited to 'plans')
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java30
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java51
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java36
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java36
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java4
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java75
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java6
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java58
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java7
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java116
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java54
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java26
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java24
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java14
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json4
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json3
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json25
17 files changed, 530 insertions, 39 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java
index 23633158..2df11c1f 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/CloudRegionsController.java
@@ -21,6 +21,7 @@ package org.onap.so.aaisimulator.controller;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGIONS;
+import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getHeaders;
import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
@@ -32,9 +33,11 @@ import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.Tenant;
import org.onap.so.aaisimulator.models.CloudRegionKey;
import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider;
+import org.onap.so.aaisimulator.utils.HttpServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@@ -121,7 +124,6 @@ public class CloudRegionsController {
}
LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedTo(), key);
-
return getRequestErrorResponseEntity(request, CLOUD_REGION);
}
@@ -168,4 +170,30 @@ public class CloudRegionsController {
LOGGER.error("Unable to find Tenant in cache key : {} and tenant-id:{} ...", key, tenantId);
return getRequestErrorResponseEntity(request, CLOUD_REGION);
}
+
+ @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/relationship-list/relationship",
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putRelationShip(@RequestBody final Relationship relationship,
+ @PathVariable("cloud-owner") final String cloudOwner,
+ @PathVariable("cloud-region-id") final String cloudRegionId,
+ @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) {
+
+ final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
+ LOGGER.info("Will put RelationShip for key : {} and tenant-id:{} ...", key, tenantId);
+
+ if (relationship.getRelatedLink() != null) {
+ final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString();
+ final HttpHeaders incomingHeader = getHeaders(request);
+ boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl,
+ request.getRequestURI(), key, tenantId, relationship);
+ if (result) {
+ LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink());
+ return ResponseEntity.accepted().build();
+ }
+
+ }
+ LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink());
+ return getRequestErrorResponseEntity(request, CLOUD_REGION);
+ }
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
index 1e8c0cc0..e71cd505 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
@@ -19,8 +19,10 @@
*/
package org.onap.so.aaisimulator.controller;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNFS_URL;
+import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getHeaders;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
@@ -36,12 +38,15 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -85,7 +90,7 @@ public class GenericVnfsController {
@RequestParam(name = "resultSize", required = false) final Integer resultSize,
@RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) {
LOGGER.info(
- "Will get GenericVnf for 'vnf-id': {} with depth: {}, resultIndex: {}, resultSize:{}, format:{} ...",
+ "Will get GenericVnf for 'vnf-id': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...",
vnfId, depth, resultIndex, resultSize, format);
final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId);
@@ -113,7 +118,7 @@ public class GenericVnfsController {
if (relationship.getRelatedLink() != null) {
final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString();
final HttpHeaders incomingHeader = getHeaders(request);
- boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl,
+ final boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl,
request.getRequestURI(), vnfId, relationship);
if (result) {
LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink());
@@ -124,4 +129,46 @@ public class GenericVnfsController {
return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF);
}
+ @PutMapping(value = "/generic-vnf/{vnf-id}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL,
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putBiDirectionalRelationShip(@RequestBody final Relationship relationship,
+ @PathVariable("vnf-id") final String vnfId, final HttpServletRequest request) {
+ LOGGER.info("Will put RelationShip for 'vnf-id': {} ...", vnfId);
+
+ final Optional<Relationship> optional =
+ cacheServiceProvider.addRelationShip(vnfId, relationship, request.getRequestURI());
+
+ if (optional.isPresent()) {
+ final Relationship resultantRelationship = optional.get();
+ LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship);
+ return ResponseEntity.accepted().body(resultantRelationship);
+ }
+
+ LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink());
+ return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF);
+ }
+
+ @PostMapping(value = "/generic-vnf/{vnf-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> patchGenericVnf(@RequestBody final GenericVnf genericVnf,
+ @PathVariable("vnf-id") final String vnfId,
+ @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride,
+ final HttpServletRequest request) {
+
+ LOGGER.info("Will post GenericVnf to cache with 'vnf-id': {} and '{}': {} ...", vnfId, X_HTTP_METHOD_OVERRIDE,
+ xHttpHeaderOverride);
+
+ if (HttpMethod.PATCH.toString().equalsIgnoreCase(xHttpHeaderOverride)) {
+ if (cacheServiceProvider.patchGenericVnf(vnfId, genericVnf)) {
+ return ResponseEntity.accepted().build();
+ }
+ LOGGER.error("Unable to apply patch to GenericVnf using 'vnf-id': {} ... ", vnfId);
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+ }
+ LOGGER.error("{} not supported ... ", xHttpHeaderOverride);
+
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+ }
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java
index c6fc6c7b..b3438d27 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/LinesOfBusinessController.java
@@ -19,16 +19,20 @@
*/
package org.onap.so.aaisimulator.controller;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.Constants.LINES_OF_BUSINESS_URL;
import static org.onap.so.aaisimulator.utils.Constants.LINE_OF_BUSINESS;
-import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import org.onap.aai.domain.yang.LineOfBusiness;
import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.aaisimulator.models.Format;
+import org.onap.so.aaisimulator.models.Results;
import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +44,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -76,13 +81,32 @@ public class LinesOfBusinessController {
@GetMapping(value = "{line-of-business-name}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<?> getLineOfBusiness(@PathVariable("line-of-business-name") final String lineOfBusinessName,
- final HttpServletRequest request) {
- LOGGER.info("retrieving Platform for 'platform-name': {} ...", lineOfBusinessName);
+ @RequestParam(name = "depth", required = false) final Integer depth,
+ @RequestParam(name = "resultIndex", required = false) final Integer resultIndex,
+ @RequestParam(name = "resultSize", required = false) final Integer resultSize,
+ @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "retrieving Platform for 'platform-name': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...",
+ lineOfBusinessName, depth, resultIndex, resultSize, format);
+
final Optional<LineOfBusiness> optional = cacheServiceProvider.getLineOfBusiness(lineOfBusinessName);
if (optional.isPresent()) {
- final LineOfBusiness platform = optional.get();
- LOGGER.info("found LineOfBusiness {} in cache", platform);
- return ResponseEntity.ok(platform);
+
+ final Format value = Format.forValue(format);
+ switch (value) {
+ case RAW:
+ final LineOfBusiness platform = optional.get();
+ LOGGER.info("found LineOfBusiness {} in cache", platform);
+ return ResponseEntity.ok(platform);
+ case COUNT:
+ final Map<String, Object> map = new HashMap<>();
+ map.put(LINE_OF_BUSINESS, 1);
+ return ResponseEntity.ok(new Results(map));
+ default:
+ break;
+ }
+ LOGGER.error("invalid format type :{}", format);
}
LOGGER.error("Unable to find LineOfBusiness in cache using {}", lineOfBusinessName);
return getRequestErrorResponseEntity(request, LINE_OF_BUSINESS);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java
index 8d68469d..39e35947 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java
@@ -19,16 +19,20 @@
*/
package org.onap.so.aaisimulator.controller;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.Constants.PLATFORM;
import static org.onap.so.aaisimulator.utils.Constants.PLATFORMS_URL;
-import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import org.onap.aai.domain.yang.Platform;
import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.aaisimulator.models.Format;
+import org.onap.so.aaisimulator.models.Results;
import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -40,6 +44,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -73,13 +78,32 @@ public class PlatformController {
@GetMapping(value = "/{platform-name}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public ResponseEntity<?> getPlatform(@PathVariable("platform-name") final String platformName,
- final HttpServletRequest request) {
- LOGGER.info("retrieving Platform for 'platform-name': {} ...", platformName);
+ @RequestParam(name = "depth", required = false) final Integer depth,
+ @RequestParam(name = "resultIndex", required = false) final Integer resultIndex,
+ @RequestParam(name = "resultSize", required = false) final Integer resultSize,
+ @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "retrieving Platform for 'platform-name': {} with depth: {}, resultIndex: {}, resultSize:{}, format: {} ...",
+ platformName, depth, resultIndex, resultSize, format);
final Optional<Platform> optional = cacheServiceProvider.getPlatform(platformName);
if (optional.isPresent()) {
- final Platform platform = optional.get();
- LOGGER.info("found Platform {} in cache", platform);
- return ResponseEntity.ok(platform);
+
+ final Format value = Format.forValue(format);
+ switch (value) {
+ case RAW:
+ final Platform platform = optional.get();
+ LOGGER.info("found Platform {} in cache", platform);
+ return ResponseEntity.ok(platform);
+ case COUNT:
+ final Map<String, Object> map = new HashMap<>();
+ map.put(PLATFORM, 1);
+ return ResponseEntity.ok(new Results(map));
+ default:
+ break;
+ }
+ LOGGER.error("invalid format type :{}", format);
+
}
LOGGER.error("Unable to find Platform in cahce using {}", platformName);
return getRequestErrorResponseEntity(request, PLATFORM);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java
index ebaf7ce3..a53da3f5 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java
@@ -24,6 +24,7 @@ import org.onap.aai.domain.yang.CloudRegion;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.Tenant;
import org.onap.so.aaisimulator.models.CloudRegionKey;
+import org.springframework.http.HttpHeaders;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -41,4 +42,7 @@ public interface CloudRegionCacheServiceProvider extends Clearable {
boolean putTenant(final CloudRegionKey key, Tenant tenant);
Optional<Tenant> getTenant(final CloudRegionKey key, final String tenantId);
+
+ boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, final String requestURI, final CloudRegionKey key,
+ final String tenantId, final Relationship relationship);
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java
index ebefd056..c18fc8f0 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java
@@ -20,11 +20,16 @@
package org.onap.so.aaisimulator.service.providers;
import static org.onap.so.aaisimulator.utils.CacheName.CLOUD_REGION_CACHE;
+import static org.onap.so.aaisimulator.utils.Constants.BELONGS_TO;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_OWNER;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_REGION_ID;
import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_OWNER_DEFINED_TYPE;
import static org.onap.so.aaisimulator.utils.Constants.LOCATED_IN;
+import static org.onap.so.aaisimulator.utils.Constants.TENANT;
+import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_ID;
+import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_NAME;
import java.util.List;
import java.util.Optional;
import org.onap.aai.domain.yang.CloudRegion;
@@ -41,7 +46,9 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
+import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
+import org.springframework.web.util.UriComponentsBuilder;
/**
* @author Waqas Ikram (waqas.ikram@est.tech)
@@ -53,10 +60,13 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro
private static final Logger LOGGER = LoggerFactory.getLogger(CloudRegionCacheServiceProviderImpl.class);
+ private final HttpRestServiceProvider httpRestServiceProvider;
@Autowired
- public CloudRegionCacheServiceProviderImpl(final CacheManager cacheManager) {
+ public CloudRegionCacheServiceProviderImpl(final CacheManager cacheManager,
+ final HttpRestServiceProvider httpRestServiceProvider) {
super(cacheManager);
+ this.httpRestServiceProvider = httpRestServiceProvider;
}
@Override
@@ -158,6 +168,69 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro
return Optional.empty();
}
+ @Override
+ public boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl,
+ final String requestUriString, final CloudRegionKey key, final String tenantId,
+ final Relationship relationship) {
+ try {
+ final Optional<Tenant> optional = getTenant(key, tenantId);
+ if (optional.isPresent()) {
+ final Tenant tenant = optional.get();
+ final String targetUrl = getTargetUrl(targetBaseUrl, relationship.getRelatedLink());
+
+ final Relationship outGoingRelationShip = getRelationship(requestUriString, key, tenant);
+ final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(incomingHeader,
+ outGoingRelationShip, targetUrl, Relationship.class);
+
+ if (optionalRelationship.isPresent()) {
+ final Relationship resultantRelationship = optionalRelationship.get();
+ RelationshipList relationshipList = tenant.getRelationshipList();
+ if (relationshipList == null) {
+ relationshipList = new RelationshipList();
+ tenant.setRelationshipList(relationshipList);
+ }
+
+ if (relationshipList.getRelationship().add(resultantRelationship)) {
+ LOGGER.info("added relationship {} in cache successfully", resultantRelationship);
+ return true;
+ }
+ }
+
+
+ }
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to add two-way relationship for CloudRegion: {} and tenant: {}", key, tenantId,
+ exception);
+ }
+ LOGGER.error("Unable to add relationship in cache for CloudRegion: {} and tenant: {}", key, tenantId);
+ return false;
+ }
+
+ private Relationship getRelationship(final String relatedLink, final CloudRegionKey cloudRegionKey, final Tenant tenant) {
+ final Relationship relationShip = new Relationship();
+ relationShip.setRelatedTo(TENANT);
+ relationShip.setRelationshipLabel(BELONGS_TO);
+ relationShip.setRelatedLink(relatedLink);
+
+
+ final List<RelationshipData> relationshipDataList = relationShip.getRelationshipData();
+ relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_OWNER, cloudRegionKey.getCloudOwner()));
+ relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_REGION_ID, cloudRegionKey.getCloudRegionId()));
+ relationshipDataList.add(getRelationshipData(TENANT_TENANT_ID, tenant.getTenantId()));
+
+
+ final RelatedToProperty relatedToProperty = new RelatedToProperty();
+ relatedToProperty.setPropertyKey(TENANT_TENANT_NAME);
+ relatedToProperty.setPropertyValue(tenant.getTenantName());
+ relationShip.getRelatedToProperty().add(relatedToProperty);
+ return relationShip;
+ }
+
+ private String getTargetUrl(final String targetBaseUrl, final String relatedLink) {
+ return UriComponentsBuilder.fromUriString(targetBaseUrl).path(relatedLink)
+ .path(BI_DIRECTIONAL_RELATIONSHIP_LIST_URL).toUriString();
+ }
+
private RelationshipData getRelationshipData(final String key, final String value) {
final RelationshipData relationshipData = new RelationshipData();
relationshipData.setRelationshipKey(key);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
index 093cfa12..20c0f223 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
@@ -34,11 +34,15 @@ public interface GenericVnfCacheServiceProvider extends Clearable {
Optional<GenericVnf> getGenericVnf(final String vnfId);
- boolean addRelationShip(final String vnfId, final Relationship relationship);
+ Optional<Relationship> addRelationShip(final String vnfId, final Relationship relationship,
+ final String requestURI);
boolean addRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, final String requestUriString,
final String vnfId, final Relationship relationship);
Optional<String> getGenericVnfId(final String vnfName);
+ boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf);
+
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
index 472ca172..fed79d8e 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
@@ -81,22 +81,6 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
}
@Override
- public boolean addRelationShip(final String vnfId, final Relationship relationship) {
- final Optional<GenericVnf> optional = getGenericVnf(vnfId);
- if (optional.isPresent()) {
- final GenericVnf genericVnf = optional.get();
- RelationshipList relationshipList = genericVnf.getRelationshipList();
- if (relationshipList == null) {
- relationshipList = new RelationshipList();
- genericVnf.setRelationshipList(relationshipList);
- }
- return relationshipList.getRelationship().add(relationship);
- }
- LOGGER.error("Unable to find GenericVnf ...");
- return false;
- }
-
- @Override
public Optional<String> getGenericVnfId(final String vnfName) {
final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
if (cache != null) {
@@ -133,7 +117,13 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
outGoingRelationShip, targetUrl, Relationship.class);
if (optionalRelationship.isPresent()) {
final Relationship resultantRelationship = optionalRelationship.get();
- if (addRelationShip(vnfId, resultantRelationship)) {
+
+ RelationshipList relationshipList = genericVnf.getRelationshipList();
+ if (relationshipList == null) {
+ relationshipList = new RelationshipList();
+ genericVnf.setRelationshipList(relationshipList);
+ }
+ if (relationshipList.getRelationship().add(resultantRelationship)) {
LOGGER.info("added relationship {} in cache successfully", resultantRelationship);
return true;
}
@@ -146,6 +136,40 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
return false;
}
+ @Override
+ public Optional<Relationship> addRelationShip(final String vnfId, final Relationship relationship,
+ final String requestURI) {
+ final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+ if (optional.isPresent()) {
+ final GenericVnf genericVnf = optional.get();
+ RelationshipList relationshipList = genericVnf.getRelationshipList();
+ if (relationshipList == null) {
+ relationshipList = new RelationshipList();
+ genericVnf.setRelationshipList(relationshipList);
+ }
+ relationshipList.getRelationship().add(relationship);
+ LOGGER.info("Successfully added relation to GenericVnf for vnfId: {}", vnfId);
+
+ final Relationship resultantRelationship = getRelationship(requestURI, genericVnf);
+ return Optional.of(resultantRelationship);
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf) {
+ final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+ if (optional.isPresent()) {
+ final GenericVnf cachedGenericVnf = optional.get();
+ LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedGenericVnf.getOrchestrationStatus(),
+ genericVnf.getOrchestrationStatus());
+ cachedGenericVnf.setOrchestrationStatus(genericVnf.getOrchestrationStatus());
+ return true;
+ }
+ LOGGER.error("Unable to find GenericVnf ...");
+ return false;
+ }
+
private String getTargetUrl(final String targetBaseUrl, final String relatedLink) {
return UriComponentsBuilder.fromUriString(targetBaseUrl).path(relatedLink)
.path(BI_DIRECTIONAL_RELATIONSHIP_LIST_URL).toUriString();
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java
index 231b0c61..83ae57a1 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java
@@ -108,6 +108,13 @@ public class Constants {
public static final String CLOUD_REGION = "cloud-region";
+ public static final String TENANT_TENANT_NAME = "tenant.tenant-name";
+
+ public static final String TENANT_TENANT_ID = "tenant.tenant-id";
+
+ public static final String BELONGS_TO = "org.onap.relationships.inventory.BelongsTo";
+
+ public static final String TENANT = "tenant";
private Constants() {}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java
index 980c7582..a7bacb29 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/CloudRegionsControllerTest.java
@@ -24,22 +24,33 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
+import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME;
import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME;
+import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME;
+import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.TENANTS_TENANT;
import static org.onap.so.aaisimulator.utils.TestConstants.TENANT_ID;
+import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import org.junit.After;
import org.junit.Test;
import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.aai.domain.yang.GenericVnf;
import org.onap.aai.domain.yang.RelatedToProperty;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.Tenant;
import org.onap.so.aaisimulator.models.CloudRegionKey;
import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider;
+import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider;
+import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider;
import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.aaisimulator.utils.TestConstants;
import org.onap.so.aaisimulator.utils.TestUtils;
@@ -58,9 +69,17 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest {
@Autowired
private CloudRegionCacheServiceProvider cloudRegionCacheServiceProvider;
+ @Autowired
+ private CustomerCacheServiceProvider customerCacheServiceProvider;
+
+ @Autowired
+ private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider;
+
@After
public void after() {
cloudRegionCacheServiceProvider.clearAll();
+ customerCacheServiceProvider.clearAll();
+ genericVnfCacheServiceProvider.clearAll();
}
@Test
@@ -147,9 +166,7 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest {
final String tenantUrl =
getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME + TENANTS_TENANT + TENANT_ID);
- final ResponseEntity<Void> responseEntity =
- testRestTemplateService.invokeHttpPut(tenantUrl, TestUtils.getTenant(), Void.class);
- assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+ addTenantAndAssertResponse(tenantUrl);
final ResponseEntity<Tenant> response = testRestTemplateService.invokeHttpGet(tenantUrl, Tenant.class);
assertEquals(HttpStatus.OK, response.getStatusCode());
@@ -164,6 +181,99 @@ public class CloudRegionsControllerTest extends AbstractSpringBootTest {
}
+ @Test
+ public void test_putTenantRelationToGenericVnf_successfullyAddedToCache() throws Exception {
+
+ addCustomerServiceAndGenericVnf();
+
+ final String cloudRegionUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME);
+ invokeCloudRegionHttpPutEndPointAndAssertResponse(cloudRegionUrl);
+
+ final String tenantUrl =
+ getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME, TENANTS_TENANT + TENANT_ID);
+ addTenantAndAssertResponse(tenantUrl);
+
+ final String tenantRelationShipUrl = getUrl(Constants.CLOUD_REGIONS, CLOUD_OWNER_NAME, "/" + CLOUD_REGION_NAME,
+ TENANTS_TENANT + TENANT_ID, RELATIONSHIP_LIST_RELATIONSHIP_URL);
+
+ final ResponseEntity<Void> tenantRelationShipResponse = testRestTemplateService
+ .invokeHttpPut(tenantRelationShipUrl, TestUtils.getGenericVnfRelatedLink(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, tenantRelationShipResponse.getStatusCode());
+
+ final Optional<Tenant> optional = cloudRegionCacheServiceProvider.getTenant(CLOUD_REGION_KEY, TENANT_ID);
+
+ assertTrue(optional.isPresent());
+ final Tenant actualTenant = optional.get();
+ final RelationshipList relationshipList = actualTenant.getRelationshipList();
+ assertNotNull(relationshipList);
+ assertFalse(relationshipList.getRelationship().isEmpty());
+
+ final Relationship relationship = relationshipList.getRelationship().get(0);
+
+ assertEquals(Constants.COMPOSED_OF, relationship.getRelationshipLabel());
+ assertFalse(relationship.getRelationshipData().isEmpty());
+ assertEquals(1, relationship.getRelationshipData().size());
+
+ final List<RelationshipData> relationshipDataList = relationship.getRelationshipData();
+
+ final RelationshipData relationshipData =
+ getRelationshipData(relationshipDataList, Constants.GENERIC_VNF_VNF_ID);
+ assertNotNull(relationshipData);
+ assertEquals(VNF_ID, relationshipData.getRelationshipValue());
+
+ final List<RelatedToProperty> relatedToPropertyList = relationship.getRelatedToProperty();
+
+ final RelatedToProperty property = getRelatedToProperty(relatedToPropertyList, Constants.GENERIC_VNF_VNF_NAME);
+ assertNotNull(property);
+ assertEquals(GENERIC_VNF_NAME, property.getPropertyValue());
+
+ final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID);
+ assertTrue(genericVnfOptional.isPresent());
+ final GenericVnf actualGenericVnf = genericVnfOptional.get();
+ final RelationshipList relationshipListGenericVnf = actualGenericVnf.getRelationshipList();
+ assertNotNull(relationshipListGenericVnf);
+ assertFalse(relationshipListGenericVnf.getRelationship().isEmpty());
+
+ final Relationship relationshipGenericVnf = relationshipListGenericVnf.getRelationship().get(0);
+
+ assertEquals(Constants.BELONGS_TO, relationshipGenericVnf.getRelationshipLabel());
+ assertFalse(relationshipGenericVnf.getRelationshipData().isEmpty());
+ assertEquals(3, relationshipGenericVnf.getRelationshipData().size());
+
+ }
+
+ private void addTenantAndAssertResponse(final String tenantUrl) throws IOException {
+ final ResponseEntity<Void> responseEntity =
+ testRestTemplateService.invokeHttpPut(tenantUrl, TestUtils.getTenant(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+ }
+
+ private void addCustomerServiceAndGenericVnf() throws Exception, IOException {
+ final ResponseEntity<Void> customerResponse =
+ testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode());
+
+ final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+ final ResponseEntity<Void> serviceInstanceResponse =
+ testRestTemplateService.invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode());
+
+ final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+ final ResponseEntity<Void> genericVnfResponse =
+ testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+ }
+
+ private RelationshipData getRelationshipData(final List<RelationshipData> relationshipData, final String key) {
+ return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null);
+ }
+
+ private RelatedToProperty getRelatedToProperty(final List<RelatedToProperty> relatedToPropertyList,
+ final String key) {
+ return relatedToPropertyList.stream().filter(data -> data.getPropertyKey().equals(key)).findFirst()
+ .orElse(null);
+ }
private void invokeCloudRegionHttpPutEndPointAndAssertResponse(final String url) throws IOException {
final ResponseEntity<Void> responseEntity =
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
index 4411e3e8..a02900cd 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
@@ -23,7 +23,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL;
+import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_OWNER_NAME;
import static org.onap.so.aaisimulator.utils.TestConstants.CLOUD_REGION_NAME;
import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL;
@@ -56,6 +58,8 @@ import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.aaisimulator.utils.TestUtils;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -299,6 +303,56 @@ public class GenericVnfsControllerTest extends AbstractSpringBootTest {
}
+ @Test
+ public void test_putBiDirectionalRelationShip_successfullyAddedToCache() throws Exception {
+ addCustomerServiceAndGenericVnf();
+
+ final String relationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
+
+ final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl,
+ TestUtils.getTenantRelationShip(), Relationship.class);
+ assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+
+ final Optional<GenericVnf> optional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID);
+ assertTrue(optional.isPresent());
+
+ final GenericVnf actual = optional.get();
+
+ assertNotNull(actual.getRelationshipList());
+ final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship();
+ assertFalse("Relationship list should not be empty", relationshipList.isEmpty());
+ final Relationship relationship = relationshipList.get(0);
+
+ assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty());
+ assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty());
+ }
+
+ @Test
+ public void test_patchGenericVnf_usingVnfId_OrchStatusChangedInCache() throws Exception {
+ addCustomerServiceAndGenericVnf();
+
+ final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders();
+ httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString());
+
+ final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+ final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = testRestTemplateService
+ .invokeHttpPost(httpHeaders, genericVnfUrl, TestUtils.getGenericVnfOrchStatuUpdate(), Void.class);
+
+ assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode());
+
+ final ResponseEntity<GenericVnf> response =
+ testRestTemplateService.invokeHttpGet(genericVnfUrl, GenericVnf.class);
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+
+ assertTrue(response.hasBody());
+
+ final GenericVnf actualGenericVnf = response.getBody();
+ assertEquals(GENERIC_VNF_NAME, actualGenericVnf.getVnfName());
+ assertEquals(VNF_ID, actualGenericVnf.getVnfId());
+ assertEquals("Assigned", actualGenericVnf.getOrchestrationStatus());
+
+ }
+
private void addCustomerServiceAndGenericVnf() throws Exception, IOException {
final ResponseEntity<Void> customerResponse =
testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer(), Void.class);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java
index daa5138e..3b1b0ac3 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/LinesOfBusinessControllerTest.java
@@ -33,6 +33,8 @@ import org.onap.aai.domain.yang.LineOfBusiness;
import org.onap.aai.domain.yang.RelatedToProperty;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.so.aaisimulator.models.Format;
+import org.onap.so.aaisimulator.models.Results;
import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider;
import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.aaisimulator.utils.TestConstants;
@@ -76,6 +78,27 @@ public class LinesOfBusinessControllerTest extends AbstractSpringBootTest {
}
@Test
+ public void test_getLineOfBusinessWithFormatCount() throws Exception {
+
+ final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
+ final ResponseEntity<Void> lineOfBusinessResponse =
+ testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode());
+
+ final ResponseEntity<Results> response = testRestTemplateService
+ .invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class);
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+
+ assertTrue(response.hasBody());
+
+ final Results result = response.getBody();
+ assertNotNull(result.getValues());
+ assertFalse(result.getValues().isEmpty());
+ assertEquals(1, result.getValues().get(0).get(Constants.LINE_OF_BUSINESS));
+ }
+
+
+ @Test
public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
@@ -83,7 +106,8 @@ public class LinesOfBusinessControllerTest extends AbstractSpringBootTest {
testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
- final String relationShipUrl = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
+ final String relationShipUrl =
+ getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl,
TestUtils.getGenericVnfRelationShip(), Relationship.class);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java
index 754c7ebe..ea8f59b6 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java
@@ -33,6 +33,8 @@ import org.onap.aai.domain.yang.Platform;
import org.onap.aai.domain.yang.RelatedToProperty;
import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.so.aaisimulator.models.Format;
+import org.onap.so.aaisimulator.models.Results;
import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.aaisimulator.utils.TestConstants;
@@ -75,6 +77,28 @@ public class PlatformControllerTest extends AbstractSpringBootTest {
}
@Test
+ public void test_getPlatformWithFormatCount() throws Exception {
+
+ final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME);
+
+ final ResponseEntity<Void> platformResponse =
+ testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
+ assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
+
+ final ResponseEntity<Results> response = testRestTemplateService.invokeHttpGet(
+ platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class);
+ assertEquals(HttpStatus.OK, response.getStatusCode());
+
+ assertTrue(response.hasBody());
+
+ final Results result = response.getBody();
+ assertNotNull(result.getValues());
+ assertFalse(result.getValues().isEmpty());
+ assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM));
+
+ }
+
+ @Test
public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME);
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java
index d851b70e..1cdfeb91 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java
@@ -140,10 +140,22 @@ public class TestUtils {
return getJsonString("test-data/tenant.json");
}
- public static Object getCloudRegionRelatedLink() throws IOException {
+ public static String getCloudRegionRelatedLink() throws IOException {
return getJsonString("test-data/cloud-region-related-link.json");
}
+ public static String getGenericVnfRelatedLink() throws IOException {
+ return getJsonString("test-data/generic-vnf-related-link.json");
+ }
+
+ public static String getTenantRelationShip() throws IOException {
+ return getJsonString("test-data/tenant-relationship.json");
+ }
+
+ public static String getGenericVnfOrchStatuUpdate() throws IOException {
+ return getJsonString("test-data/generic-vnf-orch-status-update.json");
+ }
+
public static String getUrl(final int port, final String... urls) {
final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port);
for (final String url : urls) {
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json
new file mode 100644
index 00000000..2c00ea3a
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-orch-status-update.json
@@ -0,0 +1,4 @@
+{
+ "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701",
+ "orchestration-status": "Assigned"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json
new file mode 100644
index 00000000..388773b7
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf-related-link.json
@@ -0,0 +1,3 @@
+{
+ "related-link": "/network/generic-vnfs/generic-vnf/dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json
new file mode 100644
index 00000000..e1535727
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/tenant-relationship.json
@@ -0,0 +1,25 @@
+{
+ "related-to": "tenant",
+ "relationship-label": "org.onap.relationships.inventory.BelongsTo",
+ "related-link": "/aai/v15/cloud-infrastructure/cloud-regions/cloud-region/CloudOwner/EtsiCloudRegion/tenants/tenant/693c7729b2364a26a3ca602e6f66187d",
+ "relationship-data": [
+ {
+ "relationship-key": "cloud-region.cloud-owner",
+ "relationship-value": "CloudOwner"
+ },
+ {
+ "relationship-key": "cloud-region.cloud-region-id",
+ "relationship-value": "EtsiCloudRegion"
+ },
+ {
+ "relationship-key": "tenant.tenant-id",
+ "relationship-value": "693c7729b2364a26a3ca602e6f66187d"
+ }
+ ],
+ "related-to-property": [
+ {
+ "property-key": "tenant.tenant-name",
+ "property-value": "admin"
+ }
+ ]
+}