Adding aai platform endpoints 70/93870/2
authorwaqas.ikram <waqas.ikram@est.tech>
Mon, 19 Aug 2019 13:44:42 +0000 (13:44 +0000)
committerWaqas Ikram <waqas.ikram@est.tech>
Mon, 19 Aug 2019 13:45:21 +0000 (13:45 +0000)
Change-Id: Ibe08bf0a6f7e65632a1ebc7a539272f55a049eaf
Issue-ID: SO-2219
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
25 files changed:
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/BusinessController.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/GenericVnfsController.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/NodesController.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/Clearable.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CustomerCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/NodesCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/OwnEntityCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/PlatformCacheServiceProvider.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/PlatformCacheServiceProviderImpl.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/ProjectCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/CacheName.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/utils/Constants.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/GenericVnfsControllerTest.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/NodesControllerTest.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestConstants.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/utils/TestUtils.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-related-link.json [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-relationship.json [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform.json [new file with mode: 0644]

index c88dac4..22767b2 100644 (file)
@@ -323,7 +323,7 @@ public class BusinessController {
             final ServiceInstance serviceInstance = optional.get();
             final Relationship resultantRelationship = new Relationship();
             resultantRelationship.setRelatedTo(GENERIC_VNF);
-            resultantRelationship.setRelatedLink(COMPOSED_OF);
+            resultantRelationship.setRelationshipLabel(COMPOSED_OF);
             resultantRelationship.setRelatedLink(request.getRequestURI());
 
             final List<RelationshipData> relationshipDataList = resultantRelationship.getRelationshipData();
index c6ec3a5..2eb84f0 100644 (file)
@@ -49,6 +49,7 @@ import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.util.UriComponentsBuilder;
 
 /**
@@ -89,8 +90,8 @@ public class GenericVnfsController {
 
     @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);
+            @RequestParam(name = "depth", required = false) final Integer depth, final HttpServletRequest request) {
+        LOGGER.info("Will get GenericVnf for 'vnf-id': {} with depth: {}...", vnfId, depth);
 
         final Optional<GenericVnf> optional = cacheServiceProvider.getGenericVnf(vnfId);
 
@@ -100,7 +101,7 @@ public class GenericVnfsController {
             return ResponseEntity.ok(genericVnf);
         }
 
-        LOGGER.error("Unable to find GenericVnf in cache for 'vnf-id': {} ...", vnfId);
+        LOGGER.error("Unable to find GenericVnf in cache for 'vnf-id': {} with depth: {} ...", vnfId, depth);
         return getRequestErrorResponseEntity(request, GENERIC_VNF);
 
     }
@@ -110,7 +111,7 @@ public class GenericVnfsController {
             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);
+        LOGGER.info("Will put RelationShip for 'vnf-id': {} ...", vnfId);
 
         try {
             if (relationship.getRelatedLink() != null) {
index 17de374..21bcae9 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.onap.so.aaisimulator.controller;
 
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
 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;
@@ -28,11 +29,11 @@ import java.util.Map;
 import java.util.Optional;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.MediaType;
+import org.onap.aai.domain.yang.GenericVnfs;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.so.aaisimulator.models.Format;
 import org.onap.so.aaisimulator.models.NodeServiceInstance;
 import org.onap.so.aaisimulator.models.Results;
-import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider;
 import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -57,12 +58,8 @@ public class NodesController {
 
     private final NodesCacheServiceProvider cacheServiceProvider;
 
-    private final CustomerCacheServiceProvider customerCacheServiceProvider;
-
     @Autowired
-    public NodesController(final CustomerCacheServiceProvider customerCacheServiceProvider,
-            final NodesCacheServiceProvider cacheServiceProvider) {
-        this.customerCacheServiceProvider = customerCacheServiceProvider;
+    public NodesController(final NodesCacheServiceProvider cacheServiceProvider) {
         this.cacheServiceProvider = cacheServiceProvider;
     }
 
@@ -90,12 +87,11 @@ public class NodesController {
                 return ResponseEntity.ok(new Results(map));
             case RAW:
                 final Optional<ServiceInstance> serviceInstance =
-                        customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(),
-                                nodeServiceInstance.getServiceType(), nodeServiceInstance.getServiceInstanceId());
+                        cacheServiceProvider.getServiceInstance(nodeServiceInstance);
                 if (serviceInstance.isPresent()) {
                     return ResponseEntity.ok(serviceInstance.get());
                 }
-                LOGGER.info("Unable to find Service instance in cahce using {}", nodeServiceInstance);
+                LOGGER.error("Unable to find Service instance in cahce using {}", nodeServiceInstance);
                 return getRequestErrorResponseEntity(request);
             default:
                 break;
@@ -103,4 +99,17 @@ public class NodesController {
         LOGGER.error("invalid format type :{}", format);
         return getRequestErrorResponseEntity(request);
     }
+
+    @GetMapping(value = "/generic-vnfs", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> getGenericVnfs(@RequestParam(name = "vnf-name") final String vnfName,
+            final HttpServletRequest request) {
+        LOGGER.info("will find GenericVnfs for name: {}", vnfName);
+        final Optional<GenericVnfs> optional = cacheServiceProvider.getGenericVnfs(vnfName);
+        if (optional.isPresent()) {
+            LOGGER.info("found matching GenericVnfs for name: {}", vnfName);
+            return ResponseEntity.ok(optional.get());
+        }
+        LOGGER.error("Unable to find GenericVnfs in cahce using {}", vnfName);
+        return getRequestErrorResponseEntity(request, GENERIC_VNF);
+    }
 }
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/controller/PlatformController.java
new file mode 100644 (file)
index 0000000..a80477c
--- /dev/null
@@ -0,0 +1,109 @@
+/*-
+ * ============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.PLATFORMS_URL;
+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.Platform;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
+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;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Controller
+@RequestMapping(path = PLATFORMS_URL)
+public class PlatformController {
+    private static final Logger LOGGER = LoggerFactory.getLogger(PlatformController.class);
+
+    private final PlatformCacheServiceProvider cacheServiceProvider;
+
+    @Autowired
+    public PlatformController(final PlatformCacheServiceProvider cacheServiceProvider) {
+        this.cacheServiceProvider = cacheServiceProvider;
+    }
+
+    @PutMapping(value = "{platform-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> putPlatform(@RequestBody final Platform platform,
+            @PathVariable("platform-name") final String platformName, final HttpServletRequest request) {
+        LOGGER.info("Will add Platform to cache with key 'platform-name': {} ...", platform.getPlatformName());
+
+        if (platform.getResourceVersion() == null || platform.getResourceVersion().isEmpty()) {
+            platform.setResourceVersion(getResourceVersion());
+
+        }
+        cacheServiceProvider.putPlatform(platformName, platform);
+        return ResponseEntity.accepted().build();
+    }
+
+    @GetMapping(value = "/{platform-name}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> getPlatform(@PathVariable("platform-name") final String platformName,
+            final HttpServletRequest request) {
+        LOGGER.info("retrieving Platform for 'platform-name': {} ...", platformName);
+        final Optional<Platform> optional = cacheServiceProvider.getPlatform(platformName);
+        if (optional.isPresent()) {
+            final Platform platform = optional.get();
+            LOGGER.info("found Platform {} in cache", platform);
+            return ResponseEntity.ok(platform);
+        }
+        LOGGER.error("Unable to find Platform in cahce using {}", platformName);
+        return getRequestErrorResponseEntity(request);
+    }
+
+    @PutMapping(value = "/{platform-name}/relationship-list/relationship",
+            consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> putSericeInstanceRelationShip(@PathVariable("platform-name") final String platformName,
+            @RequestBody final Relationship relationship, final HttpServletRequest request) {
+        LOGGER.info("Will add {} relationship to : {} ...", relationship.getRelatedTo());
+
+        final Optional<Relationship> optional =
+                cacheServiceProvider.addRelationShip(platformName, relationship, request.getRequestURI());
+
+        if (optional.isPresent()) {
+            final Relationship resultantRelationship = optional.get();
+            LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship);
+            return ResponseEntity.accepted().body(resultantRelationship);
+        }
+
+        LOGGER.error("Couldn't add {} relationship for 'platform-name': {} ...", relationship.getRelatedTo(),
+                platformName);
+
+        return RequestErrorResponseUtils.getRequestErrorResponseEntity(request);
+
+    }
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/Clearable.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/Clearable.java
new file mode 100644 (file)
index 0000000..dd4ace4
--- /dev/null
@@ -0,0 +1,28 @@
+/*-
+ * ============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;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface Clearable {
+    void clearAll();
+}
index f20bd15..bf30013 100644 (file)
@@ -30,7 +30,7 @@ import org.onap.aai.domain.yang.ServiceSubscription;
  * @author waqas.ikram@ericsson.com
  *
  */
-public interface CustomerCacheServiceProvider {
+public interface CustomerCacheServiceProvider extends Clearable {
 
     Optional<Customer> getCustomer(final String globalCustomerId);
 
@@ -59,8 +59,4 @@ public interface CustomerCacheServiceProvider {
     Optional<ServiceInstance> addRelationShip(final String globalCustomerId, final String serviceType,
             final String serviceInstanceId, final Relationship relationship);
 
-    void clearAll();
-
-
-
 }
index e2bcc9a..213ecf6 100644 (file)
@@ -27,14 +27,14 @@ import org.onap.aai.domain.yang.Relationship;
  * @author Waqas Ikram (waqas.ikram@est.tech)
  *
  */
-public interface GenericVnfCacheServiceProvider {
+public interface GenericVnfCacheServiceProvider extends Clearable {
 
     void putGenericVnf(final String vnfId, final GenericVnf genericVnf);
 
     Optional<GenericVnf> getGenericVnf(final String vnfId);
-    
+
     boolean addRelationShip(final String vnfId, final Relationship relationship);
 
-    void clearAll();
+    Optional<String> getGenericVnfId(final String vnfName);
 
 }
index 709f80d..7ff012f 100644 (file)
@@ -21,6 +21,7 @@ package org.onap.so.aaisimulator.service.providers;
 
 import static org.onap.so.aaisimulator.utils.CacheName.GENERIC_VNF_CACHE;
 import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.aai.domain.yang.Relationship;
 import org.onap.aai.domain.yang.RelationshipList;
@@ -70,7 +71,7 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
     public boolean addRelationShip(final String vnfId, final Relationship relationship) {
         final Optional<GenericVnf> optional = getGenericVnf(vnfId);
         if (optional.isPresent()) {
-            GenericVnf genericVnf = optional.get();
+            final GenericVnf genericVnf = optional.get();
             RelationshipList relationshipList = genericVnf.getRelationshipList();
             if (relationshipList == null) {
                 relationshipList = new RelationshipList();
@@ -82,8 +83,33 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
         return false;
     }
 
+    @Override
+    public Optional<String> getGenericVnfId(final String vnfName) {
+        final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+        if (cache != null) {
+            final Object nativeCache = cache.getNativeCache();
+            if (nativeCache instanceof ConcurrentHashMap) {
+                @SuppressWarnings("unchecked")
+                final ConcurrentHashMap<Object, Object> concurrentHashMap =
+                        (ConcurrentHashMap<Object, Object>) nativeCache;
+                for (final Object key : concurrentHashMap.keySet()) {
+                    final GenericVnf value = cache.get(key, GenericVnf.class);
+                    final String genericVnfName = value.getVnfName();
+                    if (value != null && genericVnfName.equals(vnfName)) {
+                        final String genericVnfId = value.getVnfId();
+                        LOGGER.info("Found matching vnf for name: {}, vnf-id: {}", genericVnfName, genericVnfId);
+                        return Optional.of(genericVnfId);
+                    }
+                }
+            }
+        }
+        LOGGER.info("No match found for vnf name: {}", vnfName);
+        return Optional.empty();
+    }
+
     @Override
     public void clearAll() {
         clearCahce(GENERIC_VNF_CACHE.getName());
     }
+
 }
index 0dbd45e..0232746 100644 (file)
 package org.onap.so.aaisimulator.service.providers;
 
 import java.util.Optional;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.so.aaisimulator.models.NodeServiceInstance;
 
 /**
  * @author waqas.ikram@ericsson.com
  *
  */
-public interface NodesCacheServiceProvider {
+public interface NodesCacheServiceProvider extends Clearable {
 
     void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance);
 
     Optional<NodeServiceInstance> getNodeServiceInstance(final String serviceInstanceId);
 
-    void clearAll();
+    Optional<GenericVnfs> getGenericVnfs(final String vnfName);
+
+    Optional<ServiceInstance> getServiceInstance(final NodeServiceInstance nodeServiceInstance);
 
 }
index ca4765e..4ea255f 100644 (file)
@@ -22,6 +22,9 @@ package org.onap.so.aaisimulator.service.providers;
 import static org.onap.so.aaisimulator.utils.CacheName.NODES_CACHE;
 import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.so.aaisimulator.models.NodeServiceInstance;
 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
 import org.slf4j.Logger;
@@ -38,11 +41,17 @@ import org.springframework.stereotype.Service;
 @Service
 public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider implements NodesCacheServiceProvider {
     private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class);
+    private final GenericVnfCacheServiceProvider cacheServiceProvider;
+    private final CustomerCacheServiceProvider customerCacheServiceProvider;
 
 
     @Autowired
-    public NodesCacheServiceProviderImpl(final CacheManager cacheManager) {
+    public NodesCacheServiceProviderImpl(final CacheManager cacheManager,
+            final GenericVnfCacheServiceProvider cacheServiceProvider,
+            final CustomerCacheServiceProvider customerCacheServiceProvider) {
         super(cacheManager);
+        this.cacheServiceProvider = cacheServiceProvider;
+        this.customerCacheServiceProvider = customerCacheServiceProvider;
     }
 
     @Override
@@ -63,6 +72,27 @@ public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider
         return Optional.empty();
     }
 
+    @Override
+    public Optional<GenericVnfs> getGenericVnfs(final String vnfName) {
+        final Optional<String> genericVnfId = cacheServiceProvider.getGenericVnfId(vnfName);
+        if (genericVnfId.isPresent()) {
+            final Optional<GenericVnf> genericVnf = cacheServiceProvider.getGenericVnf(genericVnfId.get());
+            if (genericVnf.isPresent()) {
+                final GenericVnfs genericVnfs = new GenericVnfs();
+                genericVnfs.getGenericVnf().add(genericVnf.get());
+                return Optional.of(genericVnfs);
+            }
+        }
+        LOGGER.error("Unable to find GenericVnf for name: {}", vnfName);
+        return Optional.empty();
+    }
+
+    @Override
+    public Optional<ServiceInstance> getServiceInstance(final NodeServiceInstance nodeServiceInstance) {
+        return customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(),
+                nodeServiceInstance.getServiceType(), nodeServiceInstance.getServiceInstanceId());
+    }
+
     @Override
     public void clearAll() {
         final Cache cache = getCache(NODES_CACHE.getName());
index e34aa70..d7f3f12 100644 (file)
@@ -27,13 +27,12 @@ import org.onap.aai.domain.yang.Relationship;
  * @author waqas.ikram@ericsson.com
  *
  */
-public interface OwnEntityCacheServiceProvider {
+public interface OwnEntityCacheServiceProvider extends Clearable {
 
     void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity);
 
     Optional<OwningEntity> getOwningEntity(final String owningEntityId);
 
     boolean putOwningEntityRelationShip(String owningEntityId, 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/PlatformCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/PlatformCacheServiceProvider.java
new file mode 100644 (file)
index 0000000..65788bc
--- /dev/null
@@ -0,0 +1,39 @@
+/*-
+ * ============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.Platform;
+import org.onap.aai.domain.yang.Relationship;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface PlatformCacheServiceProvider extends Clearable {
+
+    void putPlatform(final String platformName, final Platform platform);
+
+    Optional<Platform> getPlatform(final String platformName);
+
+    Optional<Relationship> addRelationShip(final String platformName, final Relationship relationship,
+            final String requestUri);
+
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/PlatformCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/PlatformCacheServiceProviderImpl.java
new file mode 100644 (file)
index 0000000..f4c1007
--- /dev/null
@@ -0,0 +1,109 @@
+/*-
+ * ============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.PLATFORM_CACHE;
+import static org.onap.so.aaisimulator.utils.Constants.PLATFORM;
+import static org.onap.so.aaisimulator.utils.Constants.PLATFORM_PLATFORM_NAME;
+import static org.onap.so.aaisimulator.utils.Constants.USES;
+import java.util.Optional;
+import org.onap.aai.domain.yang.Platform;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+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 PlatformCacheServiceProviderImpl extends AbstractCacheServiceProvider
+        implements PlatformCacheServiceProvider {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(PlatformCacheServiceProviderImpl.class);
+
+    @Autowired
+    public PlatformCacheServiceProviderImpl(final CacheManager cacheManager) {
+        super(cacheManager);
+    }
+
+    @Override
+    public void putPlatform(final String platformName, final Platform platform) {
+        LOGGER.info("Adding Platform to cache with key: {} ...", platformName);
+        final Cache cache = getCache(PLATFORM_CACHE.getName());
+        cache.put(platformName, platform);
+    }
+
+    @Override
+    public Optional<Platform> getPlatform(final String platformName) {
+        LOGGER.info("getting Platform from cache using key: {}", platformName);
+        final Cache cache = getCache(PLATFORM_CACHE.getName());
+        final Platform value = cache.get(platformName, Platform.class);
+        if (value != null) {
+            return Optional.of(value);
+        }
+        LOGGER.error("Unable to find Platform in cache using key:{} ", platformName);
+        return Optional.empty();
+    }
+
+    @Override
+    public Optional<Relationship> addRelationShip(final String platformName, final Relationship relationship,
+            final String requestUri) {
+        final Optional<Platform> optional = getPlatform(platformName);
+        if (optional.isPresent()) {
+            final Platform platform = optional.get();
+            RelationshipList relationshipList = platform.getRelationshipList();
+            if (relationshipList == null) {
+                relationshipList = new RelationshipList();
+                platform.setRelationshipList(relationshipList);
+            }
+            relationshipList.getRelationship().add(relationship);
+            
+            LOGGER.info("Successfully add relation to Platform with name: {}", platformName);
+
+            final Relationship resultantRelationship = new Relationship();
+            resultantRelationship.setRelatedTo(PLATFORM);
+            resultantRelationship.setRelationshipLabel(USES);
+            resultantRelationship.setRelatedLink(requestUri);
+
+            final RelationshipData relationshipData = new RelationshipData();
+            relationshipData.setRelationshipKey(PLATFORM_PLATFORM_NAME);
+            relationshipData.setRelationshipValue(platform.getPlatformName());
+            resultantRelationship.getRelationshipData().add(relationshipData);
+
+            return Optional.of(resultantRelationship);
+        }
+        LOGGER.error("Unable to find Platform ...");
+        return Optional.empty();
+    }
+
+    @Override
+    public void clearAll() {
+        clearCahce(PLATFORM_CACHE.getName());
+    }
+
+}
index 60f763c..3e1976c 100644 (file)
@@ -27,7 +27,7 @@ import org.onap.aai.domain.yang.Relationship;
  * @author waqas.ikram@ericsson.com
  *
  */
-public interface ProjectCacheServiceProvider {
+public interface ProjectCacheServiceProvider extends Clearable {
 
     void putProject(final String projectName, final Project project);
 
@@ -35,5 +35,4 @@ public interface ProjectCacheServiceProvider {
 
     boolean putProjectRelationShip(final String projectName, final Relationship relationship);
 
-    void clearAll();
 }
index e276a04..c39daa0 100644 (file)
@@ -29,7 +29,8 @@ public enum CacheName {
     PROJECT_CACHE("project-cache"),
     NODES_CACHE("nodes-cache"),
     GENERIC_VNF_CACHE("generic-vnf-cache"),
-    OWNING_ENTITY_CACHE("owning-entity-cache");
+    OWNING_ENTITY_CACHE("owning-entity-cache"),
+    PLATFORM_CACHE("platform-cache");
 
     private String name;
 
index 9078f03..94bee27 100644 (file)
@@ -37,6 +37,8 @@ public class Constants {
 
     public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity";
 
+    public static final String PLATFORMS_URL = BUSINESS_URL + "/platforms/platform/";
+
     public static final String NETWORK_URL = BASE_URL + "/network";
 
     public static final String GENERIC_VNFS_URL = NETWORK_URL + "/generic-vnfs/";
@@ -71,6 +73,12 @@ public class Constants {
 
     public static final String GENERIC_VNF = "generic-vnf";
 
+    public static final String PLATFORM = "platform";
+
+    public static final String USES = "org.onap.relationships.inventory.Uses";
+    
+    public static final String PLATFORM_PLATFORM_NAME = "platform.platform-name";
+
     public static final String SERVICE_SUBSCRIPTION = "service-subscription";
 
     public static final String CUSTOMER_TYPE = "Customer";
index 5327a1f..abff749 100644 (file)
@@ -27,6 +27,7 @@ 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.PLATFORM_NAME;
 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;
@@ -34,7 +35,6 @@ 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;
@@ -49,6 +49,7 @@ 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.service.providers.PlatformCacheServiceProvider;
 import org.onap.so.aaisimulator.utils.Constants;
 import org.onap.so.aaisimulator.utils.TestUtils;
 import org.onap.so.simulator.model.UserCredentials;
@@ -65,7 +66,6 @@ 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)
@@ -92,17 +92,21 @@ public class GenericVnfsControllerTest {
     @Autowired
     private GenericVnfCacheServiceProvider genericVnfCacheServiceProvider;
 
+    @Autowired
+    private PlatformCacheServiceProvider platformVnfCacheServiceProvider;
+
     @After
     public void after() {
         customerCacheServiceProvider.clearAll();
         genericVnfCacheServiceProvider.clearAll();
+        platformVnfCacheServiceProvider.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());
+        final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf());
         assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
 
         final ResponseEntity<GenericVnf> response = invokeHttpGet(genericVnfUrl, GenericVnf.class);
@@ -119,20 +123,11 @@ public class GenericVnfsControllerTest {
     @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());
+        addCustomerServiceAndGenericVnf();
 
         final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL);
         final ResponseEntity<Void> genericVnfRelationShipResponse =
-                invokeHttpPut(genericVnfRelationShipUrl, getRelationShip());
+                invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getRelationShip());
 
         assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode());
 
@@ -148,6 +143,8 @@ public class GenericVnfsControllerTest {
         assertFalse(actualRelationshipList.getRelationship().isEmpty());
         final Relationship actualRelationShip = actualRelationshipList.getRelationship().get(0);
 
+        assertEquals(Constants.COMPOSED_OF, actualRelationShip.getRelationshipLabel());
+
         assertFalse(actualRelationShip.getRelatedToProperty().isEmpty());
         assertFalse(actualRelationShip.getRelationshipData().isEmpty());
         final RelatedToProperty actualRelatedToProperty = actualRelationShip.getRelatedToProperty().get(0);
@@ -193,6 +190,57 @@ public class GenericVnfsControllerTest {
 
     }
 
+    @Test
+    public void test_putGenericVnfRelationToPlatform_successfullyAddedToCache() throws Exception {
+        addCustomerServiceAndGenericVnf();
+
+        final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME);
+        final ResponseEntity<Void> platformResponse = invokeHttpPut(platformUrl, TestUtils.getPlatform());
+        assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
+
+        final String genericVnfRelationShipUrl = getUrl(GENERIC_VNF_URL, VNF_ID, RELATIONSHIP_URL);
+        final ResponseEntity<Void> genericVnfRelationShipResponse =
+                invokeHttpPut(genericVnfRelationShipUrl, TestUtils.getPlatformRelatedLink());
+
+        assertEquals(HttpStatus.ACCEPTED, genericVnfRelationShipResponse.getStatusCode());
+
+        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);
+
+        assertEquals(Constants.USES, relationship.getRelationshipLabel());
+        assertFalse(relationship.getRelationshipData().isEmpty());
+        assertEquals(1, relationship.getRelationshipData().size());
+
+        final List<RelationshipData> relationshipData = relationship.getRelationshipData();
+
+        final RelationshipData platformRelationshipData =
+                getRelationshipData(relationshipData, Constants.PLATFORM_PLATFORM_NAME);
+        assertNotNull(platformRelationshipData);
+        assertEquals(PLATFORM_NAME, platformRelationshipData.getRelationshipValue());
+
+    }
+
+    private void addCustomerServiceAndGenericVnf() throws Exception, IOException {
+        final ResponseEntity<Void> customerResponse = invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer());
+        assertEquals(HttpStatus.ACCEPTED, customerResponse.getStatusCode());
+
+        final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+        final ResponseEntity<Void> serviceInstanceResponse =
+                invokeHttpPut(serviceInstanceUrl, TestUtils.getServiceInstance());
+        assertEquals(HttpStatus.ACCEPTED, serviceInstanceResponse.getStatusCode());
+
+        final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+        final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf());
+        assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+    }
+
     private RelationshipData getRelationshipData(final List<RelationshipData> relationshipData, final String key) {
         return relationshipData.stream().filter(data -> data.getRelationshipKey().equals(key)).findFirst().orElse(null);
     }
@@ -215,28 +263,7 @@ public class GenericVnfsControllerTest {
     }
 
     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");
+        return TestUtils.getUrl(port, urls);
     }
 
 }
index e67d098..fb9a114 100644 (file)
@@ -23,20 +23,26 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.onap.so.aaisimulator.utils.Constants.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.Constants.SERVICE_RESOURCE_TYPE;
 import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNFS_URL;
+import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME;
+import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL;
 import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_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.TestUtils.getJsonString;
+import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID;
 import java.io.IOException;
 import java.util.Map;
 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.GenericVnfs;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.so.aaisimulator.models.Format;
 import org.onap.so.aaisimulator.models.Results;
@@ -94,17 +100,10 @@ public class NodesControllerTest {
     public void test_getNodesSericeInstance_usingServiceInstanceId_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> response2 = invokeHttpPut(url, getServiceInstance());
-        assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode());
+        invokeCustomerandServiceInstanceUrls();
 
         final ResponseEntity<ServiceInstance> actual =
-                restTemplate.exchange(getNodesEndPointUrl() + SERVICE_INSTANCE_URL, HttpMethod.GET,
+                restTemplate.exchange(getUrl(Constants.NODES_URL, SERVICE_INSTANCE_URL), HttpMethod.GET,
                         new HttpEntity<>(getHttpHeaders()), ServiceInstance.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
@@ -121,18 +120,11 @@ public class NodesControllerTest {
     public void test_getNodesSericeInstance_usingServiceInstanceIdAndFormatPathed_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> response2 = invokeHttpPut(url, getServiceInstance());
-        assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode());
+        invokeCustomerandServiceInstanceUrls();
 
         final ResponseEntity<Results> actual = restTemplate.exchange(
-                getNodesEndPointUrl() + SERVICE_INSTANCE_URL + "?format=" + Format.PATHED.getValue(), HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), Results.class);
+                getUrl(Constants.NODES_URL, SERVICE_INSTANCE_URL) + "?format=" + Format.PATHED.getValue(),
+                HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), Results.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -148,21 +140,43 @@ public class NodesControllerTest {
 
     }
 
-    private String getNodesEndPointUrl() {
-        return TestUtils.getBaseUrl(port) + Constants.NODES_URL;
-    }
+    @Test
+    public void test_getNodesGenericVnfs_usingVnfName_ableToRetrieveItFromCache() throws Exception {
+        invokeCustomerandServiceInstanceUrls();
 
+        final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+        final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf());
+        assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
+
+        final String nodeGenericVnfsUrl = getUrl(NODES_URL, GENERIC_VNFS_URL) + "?vnf-name=" + GENERIC_VNF_NAME;
+        final ResponseEntity<GenericVnfs> actual = restTemplate.exchange(nodeGenericVnfsUrl, HttpMethod.GET,
+                new HttpEntity<>(getHttpHeaders()), GenericVnfs.class);
+
+        assertEquals(HttpStatus.OK, actual.getStatusCode());
+        assertTrue(actual.hasBody());
+
+        final GenericVnfs genericVnfs = actual.getBody();
+        assertEquals(1, genericVnfs.getGenericVnf().size());
+
+        final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
+        assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName());
+        assertEquals(VNF_ID, genericVnf.getVnfId());
 
-    private String getCustomerEndPointUrl() {
-        return TestUtils.getBaseUrl(port) + CUSTOMERS_URL;
     }
 
-    private String getCustomer() throws Exception, IOException {
-        return getJsonString("test-data/business-customer.json");
+    private void invokeCustomerandServiceInstanceUrls() throws Exception, IOException {
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+
+        final ResponseEntity<Void> response = invokeHttpPut(getUrl(CUSTOMERS_URL), TestUtils.getCustomer());
+
+        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+
+        final ResponseEntity<Void> response2 = invokeHttpPut(url, TestUtils.getServiceInstance());
+        assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode());
     }
 
-    private String getServiceInstance() throws Exception, IOException {
-        return getJsonString("test-data/service-instance.json");
+    private String getUrl(final String... urls) {
+        return TestUtils.getUrl(port, urls);
     }
 
     private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) {
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aaisimulator/controller/PlatformControllerTest.java
new file mode 100644 (file)
index 0000000..cb70479
--- /dev/null
@@ -0,0 +1,159 @@
+/*-
+ * ============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.PLATFORM_NAME;
+import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL;
+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.Platform;
+import org.onap.aai.domain.yang.RelatedToProperty;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
+import org.onap.so.aaisimulator.utils.Constants;
+import org.onap.so.aaisimulator.utils.TestConstants;
+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;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ActiveProfiles("test")
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@Configuration
+public class PlatformControllerTest {
+
+    @LocalServerPort
+    private int port;
+
+    @Autowired
+    private TestRestTemplate restTemplate;
+
+    @Autowired
+    private UserCredentials userCredentials;
+
+    @Autowired
+    private PlatformCacheServiceProvider platformCacheServiceProvider;
+
+
+    @After
+    public void after() {
+        platformCacheServiceProvider.clearAll();
+    }
+
+    @Test
+    public void test_putPlatform_successfullyAddedToCache() throws Exception {
+
+        final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME);
+        final ResponseEntity<Void> platformResponse = invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
+
+        final ResponseEntity<Platform> response = invokeHttpGet(platformUrl, Platform.class);
+        assertEquals(HttpStatus.OK, response.getStatusCode());
+
+        assertTrue(response.hasBody());
+
+        final Platform actualPlatform = response.getBody();
+        assertEquals(PLATFORM_NAME, actualPlatform.getPlatformName());
+        assertNotNull("resource version should not be null", actualPlatform.getResourceVersion());
+
+    }
+
+    @Test
+    public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
+
+        final String platformUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME);
+        final ResponseEntity<Void> platformResponse = invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
+
+        final String platformRelationShipUrl = getUrl(Constants.PLATFORMS_URL, PLATFORM_NAME, RELATIONSHIP_URL);
+
+        final ResponseEntity<Relationship> responseEntity =
+                invokeHttpPut(platformRelationShipUrl, TestUtils.getPlatformRelationShip(), Relationship.class);
+        assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
+
+        final Optional<Platform> optional = platformCacheServiceProvider.getPlatform(PLATFORM_NAME);
+        assertTrue(optional.isPresent());
+
+        final Platform actual = optional.get();
+
+        assertNotNull(actual.getRelationshipList());
+        final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship();
+        assertFalse("Relationship list should not be empty", relationshipList.isEmpty());
+        final Relationship relationship = relationshipList.get(0);
+
+        assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty());
+        assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty());
+
+        final RelationshipData relationshipData = relationship.getRelationshipData().get(0);
+        assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey());
+        assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue());
+
+        final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0);
+        assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey());
+        assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue());
+
+    }
+
+    private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) {
+        return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), clazz);
+    }
+
+    private <T> ResponseEntity<T> invokeHttpPut(final String url, final Object obj, final Class<T> clazz) {
+        final HttpEntity<?> httpEntity = getHttpEntity(obj);
+        return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, 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) {
+        return TestUtils.getUrl(port, urls);
+    }
+
+}
index ed2c9e6..5bb759f 100644 (file)
@@ -53,7 +53,11 @@ public class TestConstants {
 
     public static final String GENERIC_VNF_URL = Constants.GENERIC_VNFS_URL + "/generic-vnf/";
 
-    public static final String RELATED_TO_URL = "/related-to/generic-vnfs";
+    public static final String GENERIC_VNFS_URL = "/generic-vnfs";
+
+    public static final String RELATED_TO_URL = "/related-to" + GENERIC_VNFS_URL;
+
+    public static final String PLATFORM_NAME = "PLATFORM_APP_ID_1";
 
     private TestConstants() {}
 
index 4dfe9c2..880e799 100644 (file)
@@ -26,6 +26,7 @@ import java.util.Base64;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
+import org.springframework.web.util.UriComponentsBuilder;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
 
@@ -67,6 +68,43 @@ public class TestUtils {
         return "https://localhost:" + port;
     }
 
+    public static String getCustomer() throws Exception, IOException {
+        return getJsonString("test-data/business-customer.json");
+    }
+
+    public static String getServiceInstance() throws IOException {
+        return getJsonString("test-data/service-instance.json");
+    }
+
+    public static String getGenericVnf() throws IOException {
+        return getJsonString("test-data/generic-vnf.json");
+    }
+
+    public static String getRelationShip() throws IOException {
+        return getJsonString("test-data/relation-ship.json");
+    }
+
+    public static String getPlatformRelatedLink() throws IOException {
+        return getJsonString("test-data/platform-related-link.json");
+    }
+
+    public static String getPlatform() throws IOException {
+        return getJsonString("test-data/platform.json");
+    }
+
+    public static String getPlatformRelationShip() throws IOException {
+        return getJsonString("test-data/platform-relationship.json");
+    }
+
+    public static String getUrl(final int port, final String... urls) {
+        final UriComponentsBuilder baseUri = UriComponentsBuilder.fromUriString("https://localhost:" + port);
+        for (final String url : urls) {
+            baseUri.path(url);
+
+        }
+        return baseUri.toUriString();
+    }
+
     private TestUtils() {}
 
 }
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-related-link.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-related-link.json
new file mode 100644 (file)
index 0000000..6e0de8e
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "related-link": "/business/platforms/platform/PLATFORM_APP_ID_1"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-relationship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform-relationship.json
new file mode 100644 (file)
index 0000000..a53ffa9
--- /dev/null
@@ -0,0 +1,13 @@
+{
+    "related-to": "generic-vnf",
+    "relationship-label": "org.onap.relationships.inventory.Uses",
+    "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
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/platform.json
new file mode 100644 (file)
index 0000000..d94f2f0
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "platform-name": "PLATFORM_APP_ID_1"
+}