aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@est.tech>2019-08-16 16:25:12 +0000
committerwaqas.ikram <waqas.ikram@est.tech>2019-08-16 16:25:12 +0000
commit450b162a79a1b98b223ffe96ae386779483ac7e4 (patch)
treed3be3bb6afd1942367fb71c58a82b27251e21f18
parent50e7ec9e942e0aaa75867ed854c926639514e5e7 (diff)
Adding generic vnf and relationship endpoints
Change-Id: I14a331e1a2d46dcb8f4b5ecd39723156a9da5754 Issue-ID: SO-2219 Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml1
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java62
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java127
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java170
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java2
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java4
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java4
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/InvalidRestRequestException.java37
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/RestProcessingException.java37
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java9
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java67
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java40
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java89
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java36
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java97
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java8
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java10
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java10
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/CacheName.java43
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java38
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/HttpServiceUtils.java65
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorResponseUtils.java (renamed from plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java)23
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml7
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/truststore/org.onap.so.trust.jksbin0 -> 1413 bytes
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java72
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java242
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java11
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java8
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf.json13
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/relation-ship.json3
-rw-r--r--plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-Instance-relationShip.json13
31 files changed, 1272 insertions, 76 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml
index 428aeb7b..e6a210a5 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/pom.xml
@@ -38,7 +38,6 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <scope>test</scope>
</dependency>
</dependencies>
<build>
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java
index 2a55760b..109be8a8 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/configration/ApplicationConfigration.java
@@ -19,12 +19,17 @@
*/
package org.onap.so.aaisimulator.configration;
-import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_CACHE;
-import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE;
-import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_CACHE;
-import static org.onap.so.aaisimulator.utils.Constants.PROJECT_CACHE;
-import java.util.Arrays;
+import java.util.ArrayList;
import java.util.List;
+import javax.net.ssl.SSLContext;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.ssl.SSLContextBuilder;
+import org.onap.so.aaisimulator.utils.CacheName;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
@@ -32,6 +37,10 @@ import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
+import org.springframework.core.io.Resource;
+import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
/**
@@ -40,6 +49,8 @@ import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
*/
@Configuration
public class ApplicationConfigration {
+ private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationConfigration.class);
+
@Bean
public Jackson2ObjectMapperBuilderCustomizer jacksonCustomizer() {
@@ -49,13 +60,50 @@ public class ApplicationConfigration {
@Bean
public CacheManager cacheManager() {
final SimpleCacheManager manager = new SimpleCacheManager();
- final List<Cache> caches = Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE),
- getCache(NODES_CACHE), getCache(OWNING_ENTITY_CACHE));
+
+ final List<Cache> caches = new ArrayList<>();
+ for (final CacheName cacheName : CacheName.values()) {
+ caches.add(getCache(cacheName.getName()));
+ }
manager.setCaches(caches);
return manager;
}
private Cache getCache(final String name) {
+ LOGGER.info("Creating cache with name: {}", name);
return new ConcurrentMapCache(name);
}
+
+ @Profile("!test")
+ @Bean
+ public RestTemplate restTemplate(@Value("${http.client.ssl.trust-store:#{null}}") final Resource trustStore,
+ @Value("${http.client.ssl.trust-store-password:#{null}}") final String trustStorePassword)
+ throws Exception {
+ LOGGER.info("Setting up RestTemplate .... ");
+ final RestTemplate restTemplate = new RestTemplate();
+
+ final HttpComponentsClientHttpRequestFactory factory =
+ new HttpComponentsClientHttpRequestFactory(httpClient(trustStore, trustStorePassword));
+
+ restTemplate.setRequestFactory(factory);
+ return restTemplate;
+ }
+
+ private CloseableHttpClient httpClient(final Resource trustStore, final String trustStorePassword)
+ throws Exception {
+ LOGGER.info("Creating SSLConnectionSocketFactory with custom SSLContext and HostnameVerifier ... ");
+ return HttpClients.custom().setSSLSocketFactory(getSSLConnectionSocketFactory(trustStore, trustStorePassword))
+ .build();
+ }
+
+ private SSLConnectionSocketFactory getSSLConnectionSocketFactory(final Resource trustStore,
+ final String trustStorePassword) throws Exception {
+ return new SSLConnectionSocketFactory(getSslContext(trustStore, trustStorePassword));
+ }
+
+ private SSLContext getSslContext(final Resource trustStore, final String trustStorePassword)
+ throws Exception, Exception {
+ return new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build();
+ }
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
index 190d86e6..c88dac46 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
@@ -19,21 +19,38 @@
*/
package org.onap.so.aaisimulator.controller;
+import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF;
+import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_GLOBAL_CUSTOMER_ID;
+import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_TYPE;
import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_URL;
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID;
+import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID;
+import static org.onap.so.aaisimulator.utils.Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME;
import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE;
+import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION;
+import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE;
import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
-import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity;
-import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion;
+import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
+import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
+import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import org.onap.aai.domain.yang.Customer;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+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.ServiceInstance;
import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.ServiceSubscription;
import org.onap.so.aaisimulator.models.NodeServiceInstance;
import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider;
+import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider;
import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider;
+import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -57,17 +74,18 @@ import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping(path = CUSTOMER_URL)
public class BusinessController {
- private static final String SERVICE_SUBSCRIPTION = "service-subscription";
- private static final String CUSTOMER_TYPE = "Customer";
private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class);
private final CustomerCacheServiceProvider cacheServiceProvider;
private final NodesCacheServiceProvider nodesCacheServiceProvider;
+ private final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider;
@Autowired
public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider,
- final NodesCacheServiceProvider nodesCacheServiceProvider) {
+ final NodesCacheServiceProvider nodesCacheServiceProvider,
+ final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider) {
this.cacheServiceProvider = cacheServiceProvider;
this.nodesCacheServiceProvider = nodesCacheServiceProvider;
+ this.genericVnfCacheServiceProvider = genericVnfCacheServiceProvider;
}
@GetMapping(value = "{global-customer-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -138,7 +156,7 @@ public class BusinessController {
globalCustomerId, serviceType);
return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION);
}
-
+
@GetMapping(
value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances",
produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@@ -245,4 +263,101 @@ public class BusinessController {
}
+ @GetMapping(
+ value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/related-to/generic-vnfs",
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> getRelatedToGenericVnf(@PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestParam(name = "vnf-name", required = true) final String vnfName, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will retrieve generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...",
+ globalCustomerId, serviceType, serviceInstanceId, vnfName);
+
+ final Optional<Relationship> optional =
+ cacheServiceProvider.getRelationship(globalCustomerId, serviceType, serviceInstanceId, vnfName);
+
+ if (optional.isPresent()) {
+
+ final Relationship relationship = optional.get();
+ final Optional<RelationshipData> relationshipDataOptional = relationship.getRelationshipData().stream()
+ .filter(existing -> GENERIC_VNF_VNF_ID.equals(existing.getRelationshipKey())).findFirst();
+
+ if (relationshipDataOptional.isPresent()) {
+ final RelationshipData relationshipData = relationshipDataOptional.get();
+ final String vnfId = relationshipData.getRelationshipValue();
+ final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(vnfId);
+ if (genericVnfOptional.isPresent()) {
+ final GenericVnfs genericVnfs = new GenericVnfs();
+ genericVnfs.getGenericVnf().add(genericVnfOptional.get());
+ LOGGER.info("found service instance {} in cache", relationship);
+ return ResponseEntity.ok(genericVnfs);
+ }
+ }
+ }
+ LOGGER.error(
+ "Couldn't find generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...",
+ globalCustomerId, serviceType, serviceInstanceId, vnfName);
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+ }
+
+
+ @PutMapping(
+ value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/relationship-list/relationship",
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putSericeInstanceRelationShip(
+ @PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestBody final Relationship relationship, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...",
+ relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId);
+ final Optional<ServiceInstance> optional =
+ cacheServiceProvider.addRelationShip(globalCustomerId, serviceType, serviceInstanceId, relationship);
+
+ if (optional.isPresent()) {
+ final ServiceInstance serviceInstance = optional.get();
+ final Relationship resultantRelationship = new Relationship();
+ resultantRelationship.setRelatedTo(GENERIC_VNF);
+ resultantRelationship.setRelatedLink(COMPOSED_OF);
+ resultantRelationship.setRelatedLink(request.getRequestURI());
+
+ final List<RelationshipData> relationshipDataList = resultantRelationship.getRelationshipData();
+ relationshipDataList.add(getRelationshipData(CUSTOMER_GLOBAL_CUSTOMER_ID, globalCustomerId));
+ relationshipDataList.add(getRelationshipData(SERVICE_SUBSCRIPTION_SERVICE_TYPE, serviceType));
+ relationshipDataList.add(getRelationshipData(SERVICE_INSTANCE_SERVICE_INSTANCE_ID, serviceInstanceId));
+
+ final List<RelatedToProperty> relatedToProperty = resultantRelationship.getRelatedToProperty();
+ relatedToProperty.add(getRelatedToProperty(SERVICE_INSTANCE_SERVICE_INSTANCE_NAME,
+ serviceInstance.getServiceInstanceName()));
+
+ return ResponseEntity.accepted().body(resultantRelationship);
+ }
+
+ LOGGER.error(
+ "Couldn't add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...",
+ relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId);
+
+ return RequestErrorResponseUtils.getRequestErrorResponseEntity(request);
+ }
+
+ private RelatedToProperty getRelatedToProperty(final String key, final String value) {
+ final RelatedToProperty relatedToProperty = new RelatedToProperty();
+ relatedToProperty.setPropertyKey(key);
+ relatedToProperty.setPropertyValue(value);
+ return relatedToProperty;
+ }
+
+ private RelationshipData getRelationshipData(final String key, final String value) {
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey(key);
+ relationshipData.setRelationshipValue(value);
+ return relationshipData;
+ }
+
+
}
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
new file mode 100644
index 00000000..c6ec3a5e
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
@@ -0,0 +1,170 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.controller;
+
+import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF;
+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.GENERIC_VNF_VNF_ID;
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME;
+import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL;
+import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getBaseUrl;
+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;
+import java.util.Optional;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.MediaType;
+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.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider;
+import org.onap.so.aaisimulator.service.providers.HttpRestServiceProvider;
+import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+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.PutMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Controller
+@RequestMapping(path = GENERIC_VNFS_URL)
+public class GenericVnfsController {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfsController.class);
+
+ private final GenericVnfCacheServiceProvider cacheServiceProvider;
+
+ private final HttpRestServiceProvider httpRestServiceProvider;
+
+ @Autowired
+ public GenericVnfsController(final GenericVnfCacheServiceProvider cacheServiceProvider,
+ final HttpRestServiceProvider httpRestServiceProvider) {
+ this.cacheServiceProvider = cacheServiceProvider;
+ this.httpRestServiceProvider = httpRestServiceProvider;
+ }
+
+ @PutMapping(value = "/generic-vnf/{vnf-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putGenericVnf(@RequestBody final GenericVnf genericVnf,
+ @PathVariable("vnf-id") final String vnfId, final HttpServletRequest request) {
+ LOGGER.info("Will add GenericVnf to cache with 'vnf-id': {} ...", vnfId);
+
+ if (genericVnf.getResourceVersion() == null || genericVnf.getResourceVersion().isEmpty()) {
+ genericVnf.setResourceVersion(getResourceVersion());
+
+ }
+ cacheServiceProvider.putGenericVnf(vnfId, genericVnf);
+ return ResponseEntity.accepted().build();
+
+ }
+
+ @GetMapping(value = "/generic-vnf/{vnf-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> getGenericVnf(@PathVariable("vnf-id") final String vnfId,
+ final HttpServletRequest request) {
+ LOGGER.info("Will get GenericVnf for 'vnf-id': {} ...", vnfId);
+
+ final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId);
+
+ if (optional.isPresent()) {
+ final GenericVnf genericVnf = optional.get();
+ LOGGER.info("found GenericVnf {} in cache", genericVnf);
+ return ResponseEntity.ok(genericVnf);
+ }
+
+ LOGGER.error("Unable to find GenericVnf in cache for 'vnf-id': {} ...", vnfId);
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+
+ }
+
+ @PutMapping(value = "/generic-vnf/{vnf-id}/relationship-list/relationship",
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putGenericVnfRelationShip(@RequestBody final Relationship relationship,
+ @PathVariable("vnf-id") final String vnfId, final HttpServletRequest request) {
+ LOGGER.info("Will put customer for 'global customer id': {} ...", vnfId);
+
+ try {
+ if (relationship.getRelatedLink() != null) {
+ final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId);
+
+ if (optional.isPresent()) {
+ final GenericVnf genericVnf = optional.get();
+ final String url = getRelationShipUrl(request, relationship.getRelatedLink());
+
+ final Relationship serviceRelationship = getRelationship(request.getRequestURI(), genericVnf);
+ final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(getHeaders(request),
+ serviceRelationship, url, Relationship.class);
+
+ if (optionalRelationship.isPresent()) {
+ final Relationship resultantRelationship = optionalRelationship.get();
+ final boolean result = cacheServiceProvider.addRelationShip(vnfId, resultantRelationship);
+ if (result) {
+ LOGGER.info("added relationship {} in cache successfully", relationship);
+ return ResponseEntity.accepted().build();
+ }
+ LOGGER.error("Unable to add relationship {} in cache", relationship);
+ }
+ }
+ }
+ } catch (final Exception exception) {
+ LOGGER.error("Unable to add two-way relationship ", exception);
+ }
+
+ LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink());
+ return RequestErrorResponseUtils.getRequestErrorResponseEntity(request, GENERIC_VNF);
+
+ }
+
+ private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) {
+ final Relationship relationShip = new Relationship();
+ relationShip.setRelatedTo(GENERIC_VNF);
+ relationShip.setRelationshipLabel(COMPOSED_OF);
+ relationShip.setRelatedLink(relatedLink);
+
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey(GENERIC_VNF_VNF_ID);
+ relationshipData.setRelationshipValue(genericVnf.getVnfId());
+ relationShip.getRelationshipData().add(relationshipData);
+
+ final RelatedToProperty relatedToProperty = new RelatedToProperty();
+ relatedToProperty.setPropertyKey(GENERIC_VNF_VNF_NAME);
+ relatedToProperty.setPropertyValue(genericVnf.getVnfName());
+ relationShip.getRelatedToProperty().add(relatedToProperty);
+ return relationShip;
+ }
+
+ private String getRelationShipUrl(final HttpServletRequest request, final String relatedLink) {
+ return UriComponentsBuilder.fromUri(getBaseUrl(request)).path(relatedLink)
+ .path(RELATIONSHIP_LIST_RELATIONSHIP_URL).toUriString();
+ }
+
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java
index 9e93cc3b..17de3748 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java
@@ -22,7 +22,7 @@ package org.onap.so.aaisimulator.controller;
import static org.onap.so.aaisimulator.utils.Constants.NODES_URL;
import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_LINK;
import static org.onap.so.aaisimulator.utils.Constants.RESOURCE_TYPE;
-import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity;
+import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java
index ec6412c2..4923083d 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/OwningEntityController.java
@@ -21,8 +21,8 @@ package org.onap.so.aaisimulator.controller;
import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY;
import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_URL;
-import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity;
-import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion;
+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;
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java
index 8a7c1b8a..774eef23 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/ProjectController.java
@@ -21,8 +21,8 @@ package org.onap.so.aaisimulator.controller;
import static org.onap.so.aaisimulator.utils.Constants.PROJECT;
import static org.onap.so.aaisimulator.utils.Constants.PROJECT_URL;
-import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity;
-import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion;
+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;
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/InvalidRestRequestException.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/InvalidRestRequestException.java
new file mode 100644
index 00000000..4a7c289c
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/InvalidRestRequestException.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.aaisimulator.exception;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public class InvalidRestRequestException extends RuntimeException {
+ private static final long serialVersionUID = -1158414939006977465L;
+
+ public InvalidRestRequestException(final String message) {
+ super(message);
+ }
+
+ public InvalidRestRequestException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/RestProcessingException.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/RestProcessingException.java
new file mode 100644
index 00000000..0a93e2f2
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/exception/RestProcessingException.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.exception;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public class RestProcessingException extends RuntimeException {
+
+ private static final long serialVersionUID = 16862313537198441L;
+
+ public RestProcessingException(final String message) {
+ super(message);
+ }
+
+ public RestProcessingException(final String message, final Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
index 32d5ca0b..f20bd15b 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
@@ -21,6 +21,7 @@ package org.onap.so.aaisimulator.service.providers;
import java.util.Optional;
import org.onap.aai.domain.yang.Customer;
+import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.ServiceSubscription;
@@ -52,6 +53,14 @@ public interface CustomerCacheServiceProvider {
boolean patchServiceInstance(final String globalCustomerId, final String serviceType,
final String serviceInstanceId, final ServiceInstance serviceInstance);
+ Optional<Relationship> getRelationship(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final String vnfName);
+
+ Optional<ServiceInstance> addRelationShip(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final Relationship relationship);
+
void clearAll();
+
+
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
index 5c022c95..695bfc0f 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProviderImpl.java
@@ -19,15 +19,18 @@
*/
package org.onap.so.aaisimulator.service.providers;
+import static org.onap.so.aaisimulator.utils.CacheName.CUSTOMER_CACHE;
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.onap.aai.domain.yang.Customer;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.ServiceSubscription;
import org.onap.aai.domain.yang.ServiceSubscriptions;
-import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,7 +48,6 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
implements CustomerCacheServiceProvider {
private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class);
-
@Autowired
public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) {
super(cacheManager);
@@ -54,7 +56,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
@Override
public Optional<Customer> getCustomer(final String globalCustomerId) {
LOGGER.info("getting customer from cache using key: {}", globalCustomerId);
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
final Customer value = cache.get(globalCustomerId, Customer.class);
if (value != null) {
return Optional.of(value);
@@ -65,7 +67,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
@Override
public void putCustomer(final String globalCustomerId, final Customer customer) {
LOGGER.info("Adding customer: {} with key: {} in cache ...", customer, globalCustomerId);
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
cache.put(globalCustomerId, customer);
}
@@ -76,7 +78,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}",
globalCustomerId, serviceType);
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
final Customer value = cache.get(globalCustomerId, Customer.class);
@@ -92,7 +94,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
public Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType,
final String serviceInstanceName) {
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
final Customer value = cache.get(globalCustomerId, Customer.class);
if (value != null) {
@@ -124,7 +126,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
@Override
public Optional<ServiceInstance> getServiceInstance(final String globalCustomerId, final String serviceType,
final String serviceInstanceId) {
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
final Customer value = cache.get(globalCustomerId, Customer.class);
if (value != null) {
@@ -150,7 +152,7 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
final String serviceInstanceId, final ServiceInstance serviceInstance) {
LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId);
- final Cache cache = getCache(Constants.CUSTOMER_CACHE);
+ final Cache cache = getCache(CUSTOMER_CACHE.getName());
final Customer value = cache.get(globalCustomerId, Customer.class);
if (value != null) {
@@ -230,8 +232,55 @@ public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvid
}
@Override
+ public Optional<Relationship> getRelationship(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final String vnfName) {
+ final Optional<ServiceInstance> optional = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId);
+
+ if (optional.isPresent()) {
+ LOGGER.info("Found service instance ...");
+ final ServiceInstance serviceInstance = optional.get();
+ final RelationshipList relationshipList = serviceInstance.getRelationshipList();
+
+ if (relationshipList != null) {
+ final List<Relationship> relationship = relationshipList.getRelationship();
+ return relationship.stream().filter(
+ relationShip -> relationShip.getRelatedToProperty().stream().filter(relatedToProperty -> {
+ final String propertyKey = relatedToProperty.getPropertyKey();
+ final String propertyValue = relatedToProperty.getPropertyValue();
+ return GENERIC_VNF_VNF_NAME.equals(propertyKey) && propertyValue != null
+ && propertyValue.equals(vnfName);
+ }).findFirst().isPresent()).findFirst();
+ }
+ LOGGER.warn("Relationship list is nulll ...");
+ }
+ LOGGER.error("Unable to RelationShip with property value: {}... ", vnfName);
+
+ return Optional.empty();
+ }
+
+ @Override
+ public Optional<ServiceInstance> addRelationShip(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final Relationship relationship) {
+ final Optional<ServiceInstance> optional = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId);
+ if (optional.isPresent()) {
+ final ServiceInstance serviceInstance = optional.get();
+ RelationshipList relationshipList = serviceInstance.getRelationshipList();
+ if (relationshipList == null) {
+ relationshipList = new RelationshipList();
+ serviceInstance.setRelationshipList(relationshipList);
+ }
+ relationshipList.getRelationship().add(relationship);
+ return Optional.of(serviceInstance);
+
+ }
+ LOGGER.error("Unable to find ServiceInstance ...");
+ return Optional.empty();
+
+ }
+
+ @Override
public void clearAll() {
- clearCahce(Constants.CUSTOMER_CACHE);
+ clearCahce(CUSTOMER_CACHE.getName());
}
}
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
new file mode 100644
index 00000000..e2bcc9a4
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.service.providers;
+
+import java.util.Optional;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Relationship;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface GenericVnfCacheServiceProvider {
+
+ void putGenericVnf(final String vnfId, final GenericVnf genericVnf);
+
+ Optional<GenericVnf> getGenericVnf(final String vnfId);
+
+ boolean addRelationShip(final String vnfId, final Relationship relationship);
+
+ void clearAll();
+
+}
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
new file mode 100644
index 00000000..709f80d7
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.service.providers;
+
+import static org.onap.so.aaisimulator.utils.CacheName.GENERIC_VNF_CACHE;
+import java.util.Optional;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
+import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Service
+public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProvider
+ implements GenericVnfCacheServiceProvider {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfCacheServiceProviderImpl.class);
+
+ @Autowired
+ public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager) {
+ super(cacheManager);
+ }
+
+ @Override
+ public void putGenericVnf(final String vnfId, final GenericVnf genericVnf) {
+ LOGGER.info("Adding customer: {} with key: {} in cache ...", genericVnf, vnfId);
+ final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+ cache.put(vnfId, genericVnf);
+ }
+
+ @Override
+ public Optional<GenericVnf> getGenericVnf(final String vnfId) {
+ LOGGER.info("getting GenericVnf from cache using key: {}", vnfId);
+ final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+ final GenericVnf value = cache.get(vnfId, GenericVnf.class);
+ if (value != null) {
+ return Optional.of(value);
+ }
+ LOGGER.error("Unable to find GenericVnf ...");
+ return Optional.empty();
+ }
+
+ @Override
+ public boolean addRelationShip(final String vnfId, final Relationship relationship) {
+ final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+ if (optional.isPresent()) {
+ 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 void clearAll() {
+ clearCahce(GENERIC_VNF_CACHE.getName());
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java
new file mode 100644
index 00000000..38d23d78
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProvider.java
@@ -0,0 +1,36 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.service.providers;
+
+import java.util.Optional;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.ResponseEntity;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface HttpRestServiceProvider {
+
+ <T> ResponseEntity<T> invokeHttpPut(final HttpHeaders headers, final Object object, final String url,
+ final Class<T> clazz);
+
+ <T> Optional<T> put(final HttpHeaders headers, final Object object, final String url, final Class<T> clazz);
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java
new file mode 100644
index 00000000..b9f92c87
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/HttpRestServiceProviderImpl.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.service.providers;
+
+import java.util.Optional;
+import org.onap.so.aaisimulator.exception.InvalidRestRequestException;
+import org.onap.so.aaisimulator.exception.RestProcessingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.HttpClientErrorException;
+import org.springframework.web.client.RestClientException;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Service
+public class HttpRestServiceProviderImpl implements HttpRestServiceProvider {
+ private static final Logger LOGGER = LoggerFactory.getLogger(HttpRestServiceProviderImpl.class);
+
+ private final RestTemplate restTemplate;
+
+ @Autowired
+ public HttpRestServiceProviderImpl(final RestTemplate restTemplate) {
+ this.restTemplate = restTemplate;
+ }
+
+ @Override
+ public <T> ResponseEntity<T> invokeHttpPut(final HttpHeaders headers, final Object object, final String url,
+ final Class<T> clazz) {
+
+ final HttpMethod httpMethod = HttpMethod.PUT;
+ LOGGER.trace("Will invoke HTTP {} using URL: {}", httpMethod, url);
+ try {
+ return restTemplate.exchange(url, httpMethod, new HttpEntity<>(object, headers), clazz);
+
+ } catch (final HttpClientErrorException httpClientErrorException) {
+ final String message = "Unable to invoke HTTP " + httpMethod + " using url: " + url + ", Response: "
+ + httpClientErrorException.getRawStatusCode();
+ LOGGER.error(message, httpClientErrorException);
+ final int rawStatusCode = httpClientErrorException.getRawStatusCode();
+ if (rawStatusCode == HttpStatus.BAD_REQUEST.value() || rawStatusCode == HttpStatus.NOT_FOUND.value()) {
+ throw new InvalidRestRequestException("No result found for given url: " + url);
+ }
+ throw new RestProcessingException("Unable to invoke HTTP " + httpMethod + " using URL: " + url);
+
+ } catch (final RestClientException restClientException) {
+ LOGGER.error("Unable to invoke HTTP POST using url: {}", url, restClientException);
+ throw new RestProcessingException("Unable to invoke HTTP " + httpMethod + " using URL: " + url,
+ restClientException);
+ }
+ }
+
+ @Override
+ public <T> Optional<T> put(final HttpHeaders headers, final Object object, final String url, final Class<T> clazz) {
+ final ResponseEntity<T> response = invokeHttpPut(headers, object, url, clazz);
+
+ if (!response.getStatusCode().equals(HttpStatus.OK) && !response.getStatusCode().equals(HttpStatus.CREATED)
+ && !response.getStatusCode().equals(HttpStatus.ACCEPTED)) {
+ final String message = "Unable to invoke HTTP " + HttpMethod.PUT + " using URL: " + url
+ + ", Response Code: " + response.getStatusCode();
+ LOGGER.error(message);
+ return Optional.empty();
+ }
+
+ if (response.hasBody()) {
+ return Optional.of(response.getBody());
+ }
+ LOGGER.error("Received response without body status code: {}", response.getStatusCode());
+ return Optional.empty();
+ }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java
index 156abd24..ca4765e5 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java
@@ -19,7 +19,7 @@
*/
package org.onap.so.aaisimulator.service.providers;
-import static org.onap.so.aaisimulator.utils.Constants.NODES_CACHE;
+import static org.onap.so.aaisimulator.utils.CacheName.NODES_CACHE;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import org.onap.so.aaisimulator.models.NodeServiceInstance;
@@ -47,14 +47,14 @@ public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider
@Override
public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) {
- final Cache cache = getCache(NODES_CACHE);
+ final Cache cache = getCache(NODES_CACHE.getName());
LOGGER.info("Adding {} to cache with key: {}...", nodeServiceInstance, serviceInstanceId);
cache.put(serviceInstanceId, nodeServiceInstance);
}
@Override
public Optional<NodeServiceInstance> getNodeServiceInstance(final String serviceInstanceId) {
- final Cache cache = getCache(NODES_CACHE);
+ final Cache cache = getCache(NODES_CACHE.getName());
final NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class);
if (value != null) {
return Optional.of(value);
@@ -65,7 +65,7 @@ public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider
@Override
public void clearAll() {
- final Cache cache = getCache(NODES_CACHE);
+ final Cache cache = getCache(NODES_CACHE.getName());
final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache();
LOGGER.info("Clear all entries from cahce: {}", cache.getName());
nativeCache.clear();
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java
index 58a8b1e6..59fdfb08 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProviderImpl.java
@@ -19,7 +19,7 @@
*/
package org.onap.so.aaisimulator.service.providers;
-import static org.onap.so.aaisimulator.utils.Constants.OWNING_ENTITY_CACHE;
+import static org.onap.so.aaisimulator.utils.CacheName.OWNING_ENTITY_CACHE;
import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE;
import java.util.Optional;
import org.onap.aai.domain.yang.OwningEntity;
@@ -52,14 +52,14 @@ public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvi
@Override
public void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity) {
LOGGER.info("Adding OwningEntity: {} with name to cache", owningEntityId, owningEntity);
- final Cache cache = getCache(OWNING_ENTITY_CACHE);
+ final Cache cache = getCache(OWNING_ENTITY_CACHE.getName());
cache.put(owningEntityId, owningEntity);
}
@Override
public Optional<OwningEntity> getOwningEntity(final String owningEntityId) {
LOGGER.info("getting OwningEntity from cache using key: {}", owningEntityId);
- final Cache cache = getCache(OWNING_ENTITY_CACHE);
+ final Cache cache = getCache(OWNING_ENTITY_CACHE.getName());
final OwningEntity value = cache.get(owningEntityId, OwningEntity.class);
if (value != null) {
return Optional.of(value);
@@ -69,7 +69,7 @@ public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvi
@Override
public boolean putOwningEntityRelationShip(final String owningEntityId, final Relationship relationship) {
- final Cache cache = getCache(OWNING_ENTITY_CACHE);
+ final Cache cache = getCache(OWNING_ENTITY_CACHE.getName());
final OwningEntity value = cache.get(owningEntityId, OwningEntity.class);
if (value != null) {
RelationshipList relationshipList = value.getRelationshipList();
@@ -93,7 +93,7 @@ public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvi
@Override
public void clearAll() {
- clearCahce(OWNING_ENTITY_CACHE);
+ clearCahce(OWNING_ENTITY_CACHE.getName());
}
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java
index 3ddefbe6..9eaedfda 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java
@@ -19,7 +19,7 @@
*/
package org.onap.so.aaisimulator.service.providers;
-import static org.onap.so.aaisimulator.utils.Constants.PROJECT_CACHE;
+import static org.onap.so.aaisimulator.utils.CacheName.PROJECT_CACHE;
import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE;
import java.util.Optional;
import org.onap.aai.domain.yang.Project;
@@ -54,7 +54,7 @@ public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvide
@Override
public void putProject(final String projectName, final Project project) {
LOGGER.info("Adding project: {} with name to cache", project, projectName);
- final Cache cache = getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE.getName());
cache.put(projectName, project);
}
@@ -62,7 +62,7 @@ public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvide
@Override
public Optional<Project> getProject(final String projectName) {
LOGGER.info("getting project from cache using key: {}", projectName);
- final Cache cache = getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE.getName());
final Project value = cache.get(projectName, Project.class);
if (value != null) {
return Optional.of(value);
@@ -72,7 +72,7 @@ public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvide
@Override
public boolean putProjectRelationShip(final String projectName, final Relationship relationship) {
- final Cache cache = getCache(PROJECT_CACHE);
+ final Cache cache = getCache(PROJECT_CACHE.getName());
final Project value = cache.get(projectName, Project.class);
if (value != null) {
RelationshipList relationshipList = value.getRelationshipList();
@@ -97,6 +97,6 @@ public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvide
@Override
public void clearAll() {
- clearCahce(PROJECT_CACHE);
+ clearCahce(PROJECT_CACHE.getName());
}
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/CacheName.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/CacheName.java
new file mode 100644
index 00000000..e276a045
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/CacheName.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.utils;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public enum CacheName {
+
+ CUSTOMER_CACHE("customer-cache"),
+ PROJECT_CACHE("project-cache"),
+ NODES_CACHE("nodes-cache"),
+ GENERIC_VNF_CACHE("generic-vnf-cache"),
+ OWNING_ENTITY_CACHE("owning-entity-cache");
+
+ private String name;
+
+ private CacheName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+}
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 f81d6bd1..9078f036 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
@@ -37,25 +37,19 @@ public class Constants {
public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity";
- public static final String HEALTHY = "healthy";
+ public static final String NETWORK_URL = BASE_URL + "/network";
- public static final String CUSTOMER_CACHE = "customer-cache";
+ public static final String GENERIC_VNFS_URL = NETWORK_URL + "/generic-vnfs/";
- public static final String PROJECT_CACHE = "project-cache";
+ public static final String RELATIONSHIP_LIST_RELATIONSHIP_URL = "/relationship-list/relationship";
- public static final String NODES_CACHE = "nodes-cache";
+ public static final String HEALTHY = "healthy";
- public static final String OWNING_ENTITY_CACHE = "owning-entity-cache";
-
public static final String PROJECT = "project";
-
- public static final String OWNING_ENTITY = "owning-entity";
-
- public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override";
- public static final String ERROR_MESSAGE_ID = "SVC3001";
+ public static final String OWNING_ENTITY = "owning-entity";
- public static final String ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)";
+ public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override";
public static final String SERVICE_RESOURCE_TYPE = "service-instance";
@@ -63,6 +57,26 @@ public class Constants {
public static final String RESOURCE_TYPE = "resource-type";
+ public static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name";
+
+ public static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id";
+
+ public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_ID = "service-instance.service-instance-id";
+
+ public static final String SERVICE_SUBSCRIPTION_SERVICE_TYPE = "service-subscription.service-type";
+
+ public static final String CUSTOMER_GLOBAL_CUSTOMER_ID = "customer.global-customer-id";
+
+ public static final String COMPOSED_OF = "org.onap.relationships.inventory.ComposedOf";
+
+ public static final String GENERIC_VNF = "generic-vnf";
+
+ public static final String SERVICE_SUBSCRIPTION = "service-subscription";
+
+ public static final String CUSTOMER_TYPE = "Customer";
+
+ public static final String SERVICE_INSTANCE_SERVICE_INSTANCE_NAME = "service-instance.service-instance-name";
+
private Constants() {}
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/HttpServiceUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/HttpServiceUtils.java
new file mode 100644
index 00000000..339ae814
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/HttpServiceUtils.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.utils;
+
+import static org.onap.so.aaisimulator.utils.Constants.BASE_URL;
+import static org.springframework.http.MediaType.APPLICATION_XML;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.Enumeration;
+import javax.servlet.http.HttpServletRequest;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.MediaType;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public class HttpServiceUtils {
+
+ private HttpServiceUtils() {}
+
+ public static URI getBaseUrl(final HttpServletRequest request) {
+ final StringBuffer url = request.getRequestURL();
+ final String uri = request.getRequestURI();
+ return UriComponentsBuilder.fromHttpUrl(url.substring(0, url.indexOf(uri))).path(BASE_URL).build().toUri();
+ }
+
+ public static String getBaseServiceInstanceUrl(final HttpServletRequest request, final String relatedLink) {
+ return UriComponentsBuilder.fromUri(getBaseUrl(request)).path(relatedLink).toUriString();
+ }
+
+ public static HttpHeaders getHeaders(final HttpServletRequest request) {
+ return getHeaders(request, APPLICATION_XML);
+ }
+
+ public static HttpHeaders getHeaders(final HttpServletRequest request, MediaType mediaType) {
+ final HttpHeaders headers = new HttpHeaders();
+ for (final Enumeration<String> enumeration = request.getHeaderNames(); enumeration.hasMoreElements();) {
+ final String headerName = enumeration.nextElement();
+ headers.add(headerName, request.getHeader(headerName));
+ }
+ headers.setContentType(mediaType);
+ headers.setAccept(Arrays.asList(MediaType.APPLICATION_XML));
+ return headers;
+ }
+
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorResponseUtils.java
index 1963728c..755d3a70 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Utils.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/RequestErrorResponseUtils.java
@@ -19,8 +19,6 @@
*/
package org.onap.so.aaisimulator.utils;
-import static org.onap.so.aaisimulator.utils.Constants.ERROR_MESSAGE;
-import static org.onap.so.aaisimulator.utils.Constants.ERROR_MESSAGE_ID;
import javax.servlet.http.HttpServletRequest;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -29,7 +27,11 @@ import org.springframework.http.ResponseEntity;
* @author waqas.ikram@ericsson.com
*
*/
-public class Utils {
+public class RequestErrorResponseUtils {
+
+ public static final String ERROR_MESSAGE_ID = "SVC3001";
+
+ public static final String ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)";
private static final String EMPTY_STRING = "";
@@ -39,20 +41,17 @@ public class Utils {
public static ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request,
final String nodeType) {
- return new ResponseEntity<>(
- new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE)
- .variables(request.getMethod(), request.getRequestURI(), "Node Not Found:No Node of " + nodeType
- + " service-instance found at: " + request.getRequestURI(), "ERR.5.4.6114")
- .build(),
- HttpStatus.NOT_FOUND);
+ return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE)
+ .variables(request.getMethod(), request.getRequestURI(),
+ "Node Not Found:No Node of " + nodeType + " found at: " + request.getRequestURI(),
+ "ERR.5.4.6114")
+ .build(), HttpStatus.NOT_FOUND);
}
-
public static ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) {
return getRequestErrorResponseEntity(request, Constants.SERVICE_RESOURCE_TYPE);
}
-
- private Utils() {}
+ private RequestErrorResponseUtils() {}
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml
index de819447..205abe40 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/application.yaml
@@ -17,4 +17,9 @@ spring:
- username: aai@aai.onap.org
#password: demo123456!
password: $2a$04$06VCpDvW5ztE7WOvhhvAtOx7JHLghECyZIzOShIbXLWpnshMva8T6
- role: VID \ No newline at end of file
+ role: VID
+http:
+ client:
+ ssl:
+ trust-store: classpath:truststore/org.onap.so.trust.jks
+ trust-store-password: '[)3KV.k*!IlkFhWEq0Nv2dDa' \ No newline at end of file
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/truststore/org.onap.so.trust.jks b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/truststore/org.onap.so.trust.jks
new file mode 100644
index 00000000..88d61846
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/resources/truststore/org.onap.so.trust.jks
Binary files differ
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
index e7d07859..98b0fa79 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/BusinessControllerTest.java
@@ -25,13 +25,18 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
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.GLOBAL_CUSTOMER_ID;
+import static org.onap.so.aaisimulator.utils.TestConstants.RELATED_TO_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL;
import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE;
+import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID;
import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString;
import java.io.IOException;
import java.util.Optional;
@@ -40,12 +45,15 @@ import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.aai.domain.yang.Customer;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.Relationship;
import org.onap.aai.domain.yang.ServiceInstance;
import org.onap.aai.domain.yang.ServiceInstances;
import org.onap.aai.domain.yang.ServiceSubscription;
import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider;
-import org.onap.so.aaisimulator.utils.Constants;
import org.onap.so.aaisimulator.utils.RequestError;
+import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils;
import org.onap.so.aaisimulator.utils.ServiceException;
import org.onap.so.aaisimulator.utils.TestUtils;
import org.onap.so.simulator.model.UserCredentials;
@@ -133,8 +141,8 @@ public class BusinessControllerTest {
final ServiceException serviceException = actualError.getServiceException();
assertNotNull(serviceException);
- assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId());
- assertEquals(Constants.ERROR_MESSAGE, serviceException.getText());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText());
assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString()));
}
@@ -211,7 +219,6 @@ public class BusinessControllerTest {
public void test_getSericeInstance_usingServiceInstanceName_returnRequestErrorIfnoServiceInstanceFound()
throws Exception {
-
final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
@@ -277,8 +284,8 @@ public class BusinessControllerTest {
final ServiceException serviceException = actualError.getServiceException();
assertNotNull(serviceException);
- assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId());
- assertEquals(Constants.ERROR_MESSAGE, serviceException.getText());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText());
assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString()));
}
@@ -308,8 +315,8 @@ public class BusinessControllerTest {
final ServiceException serviceException = actualError.getServiceException();
assertNotNull(serviceException);
- assertEquals(Constants.ERROR_MESSAGE_ID, serviceException.getMessageId());
- assertEquals(Constants.ERROR_MESSAGE, serviceException.getText());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE_ID, serviceException.getMessageId());
+ assertEquals(RequestErrorResponseUtils.ERROR_MESSAGE, serviceException.getText());
assertTrue(serviceException.getVariables().contains(HttpMethod.GET.toString()));
}
@@ -375,6 +382,47 @@ public class BusinessControllerTest {
}
+ @Test
+ public void test_putSericeInstanceRelatedTo_ableToRetrieveServiceInstanceFromCache() throws Exception {
+
+ final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL;
+
+ final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+
+ assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+
+ final ResponseEntity<Void> responseEntity = invokeHttpPut(url, getServiceInstance());
+ assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+
+ final String relationShipUrl =
+ getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL + RELATIONSHIP_URL;
+
+
+ final HttpEntity<?> httpEntity = getHttpEntity(getRelationShipJsonObject());
+ final ResponseEntity<Relationship> responseEntity2 =
+ restTemplate.exchange(relationShipUrl, HttpMethod.PUT, httpEntity, Relationship.class);
+ assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode());
+
+ final String genericVnfUrl = TestUtils.getBaseUrl(port) + GENERIC_VNF_URL + VNF_ID;
+ final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, getGenericVnf());
+ assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+
+ final ResponseEntity<GenericVnfs> actual =
+ restTemplate.exchange(url + RELATED_TO_URL + "?vnf-name=" + GENERIC_VNF_NAME, HttpMethod.GET,
+ new HttpEntity<>(getHttpHeaders()), GenericVnfs.class);
+
+ assertEquals(HttpStatus.OK, actual.getStatusCode());
+
+ assertTrue(actual.hasBody());
+ final GenericVnfs genericVnfs = actual.getBody();
+ assertFalse(genericVnfs.getGenericVnf().isEmpty());
+ final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
+ assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName());
+
+
+ }
+
private String getCustomer() throws Exception, IOException {
return getJsonString("test-data/business-customer.json");
}
@@ -417,4 +465,12 @@ public class BusinessControllerTest {
return getJsonString("test-data/service-instance-orch-status-update.json");
}
+ private String getRelationShipJsonObject() throws IOException {
+ return getJsonString("test-data/service-Instance-relationShip.json");
+ }
+
+ private String getGenericVnf() throws IOException {
+ return getJsonString("test-data/generic-vnf.json");
+ }
+
}
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
new file mode 100644
index 00000000..5327a1fe
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
@@ -0,0 +1,242 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.so.aaisimulator.controller;
+
+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.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.GLOBAL_CUSTOMER_ID;
+import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_NAME;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_TYPE;
+import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID;
+import static org.onap.so.aaisimulator.utils.TestUtils.getJsonString;
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+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.ServiceInstance;
+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.TestUtils;
+import org.onap.so.simulator.model.UserCredentials;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.web.util.UriComponentsBuilder;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ActiveProfiles("test")
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@Configuration
+public class GenericVnfsControllerTest {
+
+ @LocalServerPort
+ private int port;
+
+ @Autowired
+ private TestRestTemplate restTemplate;
+
+ @Autowired
+ private UserCredentials userCredentials;
+
+ @Autowired
+ private CustomerCacheServiceProvider customerCacheServiceProvider;
+
+ @Autowired
+ private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider;
+
+ @After
+ public void after() {
+ customerCacheServiceProvider.clearAll();
+ genericVnfCacheServiceProvider.clearAll();
+ }
+
+ @Test
+ public void test_putGenericVnf_successfullyAddedToCache() throws Exception {
+
+ final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+ final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, getGenericVnf());
+ assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+ final ResponseEntity<GenericVnf> response = 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());
+
+ }
+
+ @Test
+ public void test_putGenericVnfRelation_successfullyAddedToCache() throws Exception {
+
+ final ResponseEntity<Void> customerResponse = invokeHttpPut(getUrl(CUSTOMERS_URL), getCustomer());
+ assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode());
+
+ final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+ final ResponseEntity<Void> serviceInstanceResponse = invokeHttpPut(serviceInstanceUrl, getServiceInstance());
+ assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode());
+
+ final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+ final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, getGenericVnf());
+ assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+ final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL);
+ final ResponseEntity<Void> genericVnfRelationShipResponse =
+ invokeHttpPut(genericVnfRelationShipUrl, getRelationShip());
+
+ assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode());
+
+
+ final Optional<ServiceInstance> optional =
+ customerCacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID);
+
+ assertTrue(optional.isPresent());
+
+ final ServiceInstance actualServiceInstance = optional.get();
+ final RelationshipList actualRelationshipList = actualServiceInstance.getRelationshipList();
+ assertNotNull(actualRelationshipList);
+ assertFalse(actualRelationshipList.getRelationship().isEmpty());
+ final Relationship actualRelationShip = actualRelationshipList.getRelationship().get(0);
+
+ assertFalse(actualRelationShip.getRelatedToProperty().isEmpty());
+ assertFalse(actualRelationShip.getRelationshipData().isEmpty());
+ final RelatedToProperty actualRelatedToProperty = actualRelationShip.getRelatedToProperty().get(0);
+ final RelationshipData actualRelationshipData = actualRelationShip.getRelationshipData().get(0);
+
+ assertEquals(Constants.GENERIC_VNF_VNF_NAME, actualRelatedToProperty.getPropertyKey());
+ assertEquals(GENERIC_VNF_NAME, actualRelatedToProperty.getPropertyValue());
+ assertEquals(Constants.GENERIC_VNF_VNF_ID, actualRelationshipData.getRelationshipKey());
+ assertEquals(VNF_ID, actualRelationshipData.getRelationshipValue());
+
+ final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(VNF_ID);
+ assertTrue(genericVnfOptional.isPresent());
+ final GenericVnf actualGenericVnf = genericVnfOptional.get();
+ final RelationshipList relationshipList = actualGenericVnf.getRelationshipList();
+ assertNotNull(relationshipList);
+ assertFalse(relationshipList.getRelationship().isEmpty());
+
+ final Relationship relationship = relationshipList.getRelationship().get(0);
+ assertFalse(relationship.getRelatedToProperty().isEmpty());
+ assertEquals(3, relationship.getRelationshipData().size());
+
+ final List<RelatedToProperty> relatedToProperty = relationship.getRelatedToProperty();
+ final RelatedToProperty firstRelatedToProperty = relatedToProperty.get(0);
+ assertEquals(Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_NAME, firstRelatedToProperty.getPropertyKey());
+ assertEquals(SERVICE_NAME, firstRelatedToProperty.getPropertyValue());
+
+ final List<RelationshipData> relationshipData = relationship.getRelationshipData();
+
+ final RelationshipData globalRelationshipData =
+ getRelationshipData(relationshipData, Constants.CUSTOMER_GLOBAL_CUSTOMER_ID);
+ assertNotNull(globalRelationshipData);
+ assertEquals(GLOBAL_CUSTOMER_ID, globalRelationshipData.getRelationshipValue());
+
+ final RelationshipData serviceSubscriptionRelationshipData =
+ getRelationshipData(relationshipData, Constants.SERVICE_SUBSCRIPTION_SERVICE_TYPE);
+ assertNotNull(serviceSubscriptionRelationshipData);
+ assertEquals(SERVICE_TYPE, serviceSubscriptionRelationshipData.getRelationshipValue());
+
+ final RelationshipData serviceInstanceRelationshipData =
+ getRelationshipData(relationshipData, Constants.SERVICE_INSTANCE_SERVICE_INSTANCE_ID);
+ assertNotNull(serviceInstanceRelationshipData);
+ assertEquals(SERVICE_INSTANCE_ID, serviceInstanceRelationshipData.getRelationshipValue());
+
+ }
+
+ private RelationshipData getRelationshipData(final List<RelationshipData> relationshipData, final String key) {
+ return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null);
+ }
+
+ private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) {
+ final HttpEntity<?> httpEntity = getHttpEntity(obj);
+ return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class);
+ }
+
+ private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) {
+ return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), clazz);
+ }
+
+ private HttpEntity<?> getHttpEntity(final Object obj) {
+ return new HttpEntity<>(obj, getHttpHeaders());
+ }
+
+ private HttpHeaders getHttpHeaders() {
+ return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername());
+ }
+
+ private String getUrl(final String... urls) {
+ final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port);
+ for (final String url : urls) {
+ baseUri.path(url);
+
+ }
+ return baseUri.toUriString();
+ }
+
+ private String getCustomer() throws IOException {
+ return getJsonString("test-data/business-customer.json");
+ }
+
+ private String getServiceInstance() throws IOException {
+ return getJsonString("test-data/service-instance.json");
+ }
+
+ private String getGenericVnf() throws IOException {
+ return getJsonString("test-data/generic-vnf.json");
+ }
+
+ private String getRelationShip() throws IOException {
+ return getJsonString("test-data/relation-ship.json");
+ }
+
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java
index 7683721c..92036e83 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/configuration/TestRestTemplateConfigration.java
@@ -31,12 +31,15 @@ import org.slf4j.LoggerFactory;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Profile;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
+import org.springframework.web.client.RestTemplate;
/**
* @author waqas.ikram@ericsson.com
*
*/
+@Profile("test")
@Configuration
public class TestRestTemplateConfigration {
@@ -44,7 +47,6 @@ public class TestRestTemplateConfigration {
@Bean
public TestRestTemplate testRestTemplate() throws Exception {
-
final TestRestTemplate testRestTemplate = new TestRestTemplate();
((HttpComponentsClientHttpRequestFactory) testRestTemplate.getRestTemplate().getRequestFactory())
.setHttpClient(httpClient());
@@ -52,6 +54,13 @@ public class TestRestTemplateConfigration {
}
+ @Bean
+ public RestTemplate restTemplate() throws Exception {
+ final RestTemplate restTemplate = new RestTemplate();
+ restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient()));
+ return restTemplate;
+ }
+
private CloseableHttpClient httpClient() throws Exception {
final TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java
index f59e8b58..ed2c9e66 100644
--- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java
@@ -47,6 +47,14 @@ public class TestConstants {
public static final String RELATIONSHIP_URL = "/relationship-list/relationship";
+ public static final String VNF_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701";
+
+ public static final String GENERIC_VNF_NAME = "EsyVnfInstantiationTest2";
+
+ public static final String GENERIC_VNF_URL = Constants.GENERIC_VNFS_URL + "/generic-vnf/";
+
+ public static final String RELATED_TO_URL = "/related-to/generic-vnfs";
+
private TestConstants() {}
}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf.json
new file mode 100644
index 00000000..de246cd3
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/generic-vnf.json
@@ -0,0 +1,13 @@
+{
+ "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701",
+ "vnf-name": "EsyVnfInstantiationTest2",
+ "vnf-type": "Sol004Zip4Service/Sol004Zip3VSP 0",
+ "service-id": "f13844f4-dbf8-4d0e-a979-45204f3ddb4e",
+ "prov-status": "PREPROV",
+ "orchestration-status": "Inventoried",
+ "model-invariant-id": "b0f14066-2b65-40d2-b5a4-c8f2116fb5fc",
+ "model-version-id": "84b9649a-4eb9-4967-9abe-e8702f55518b",
+ "model-customization-id": "50a90cd7-a84e-4ee1-b5ba-bfa5a26f5e15",
+ "nf-type": "vnflcm",
+ "nf-role": "vnflcm"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/relation-ship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/relation-ship.json
new file mode 100644
index 00000000..c2662266
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/relation-ship.json
@@ -0,0 +1,3 @@
+{
+ "related-link": "/business/customers/customer/DemoCustomer/service-subscriptions/service-subscription/vCPE/service-instances/service-instance/ccece8fe-13da-456a-baf6-41b3a4a2bc2b"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-Instance-relationShip.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-Instance-relationShip.json
new file mode 100644
index 00000000..ab643d3c
--- /dev/null
+++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-Instance-relationShip.json
@@ -0,0 +1,13 @@
+{
+ "related-to": "generic-vnf",
+ "relationship-label": "org.onap.relationships.inventory.ComposedOf",
+ "related-link": "/aai/v15/network/generic-vnfs/generic-vnf/dfd02fb5-d7fb-4aac-b3c4-cd6b60058701",
+ "relationship-data": [{
+ "relationship-key": "generic-vnf.vnf-id",
+ "relationship-value": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"
+ }],
+ "related-to-property": [{
+ "property-key": "generic-vnf.vnf-name",
+ "property-value": "EsyVnfInstantiationTest2"
+ }]
+} \ No newline at end of file