Adding owning-entity endpoint 65/92365/2
authorwaqas.ikram <waqas.ikram@est.tech>
Wed, 31 Jul 2019 14:30:55 +0000 (14:30 +0000)
committerWaqas Ikram <waqas.ikram@est.tech>
Wed, 31 Jul 2019 14:31:34 +0000 (14:31 +0000)
Change-Id: I2d0e05bc8563d86be38440dcbed7b2abcfe6411c
Issue-ID: SO-1953
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
21 files changed:
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity.json [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json [new file with mode: 0644]
plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json [new file with mode: 0644]

index af00ba7..b1f1779 100644 (file)
@@ -21,8 +21,10 @@ package org.onap.so.aai.simulator.configration;
 
 import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_CACHE;
 import static org.onap.so.aai.simulator.utils.Constants.NODES_CACHE;
+import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE;
 import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE;
 import java.util.Arrays;
+import java.util.List;
 import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
 import org.springframework.cache.Cache;
 import org.springframework.cache.CacheManager;
@@ -47,7 +49,9 @@ public class ApplicationConfigration {
     @Bean
     public CacheManager cacheManager() {
         final SimpleCacheManager manager = new SimpleCacheManager();
-        manager.setCaches(Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), getCache(NODES_CACHE)));
+        final List<Cache> caches = Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE),
+                getCache(NODES_CACHE), getCache(OWNING_ENTITY_CACHE));
+        manager.setCaches(caches);
         return manager;
     }
 
index e7fd00d..0189a42 100644 (file)
@@ -20,9 +20,9 @@
 package org.onap.so.aai.simulator.controller;
 
 import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_URL;
-import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE;
-import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE_ID;
 import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE;
+import static org.onap.so.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
+import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity;
 import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion;
 import java.util.Optional;
 import javax.servlet.http.HttpServletRequest;
@@ -34,17 +34,18 @@ import org.onap.aai.domain.yang.ServiceSubscription;
 import org.onap.so.aai.simulator.models.NodeServiceInstance;
 import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider;
 import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider;
-import org.onap.so.aai.simulator.utils.RequestErrorBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
+import org.springframework.http.HttpMethod;
 import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.PutMapping;
 import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestHeader;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestParam;
 
@@ -56,6 +57,8 @@ 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;
@@ -80,7 +83,7 @@ public class BusinessController {
         }
 
         LOGGER.error("Couldn't find {} in cache", globalCustomerId);
-        return getRequestErrorResponseEntity(request);
+        return getRequestErrorResponseEntity(request, CUSTOMER_TYPE);
     }
 
     @PutMapping(value = "/{global-customer-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
@@ -115,9 +118,27 @@ public class BusinessController {
 
         LOGGER.error("Couldn't find 'global customer id': {} and 'service type': {} in cache", globalCustomerId,
                 serviceType);
-        return getRequestErrorResponseEntity(request);
+        return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION);
     }
 
+    @PutMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}",
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> putServiceSubscription(@PathVariable("global-customer-id") final String globalCustomerId,
+            @PathVariable("service-type") final String serviceType,
+            @RequestBody final ServiceSubscription serviceSubscription, final HttpServletRequest request) {
+        LOGGER.info("Will add service subscription for 'global customer id': {} and 'service type': {} ...",
+                globalCustomerId, serviceType);
+
+        if (cacheServiceProvider.putServiceSubscription(globalCustomerId, serviceType, serviceSubscription)) {
+            LOGGER.info("Successfully add service subscription in cache ...");
+            return ResponseEntity.accepted().build();
+        }
+
+        LOGGER.error("Couldn't add service subscription using 'global customer id': {} and 'service type': {}",
+                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})
@@ -177,6 +198,7 @@ public class BusinessController {
     public ResponseEntity<?> putSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId,
             @PathVariable("service-type") final String serviceType,
             @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+            @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String invocationId,
             @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) {
 
         LOGGER.info(
@@ -199,12 +221,28 @@ public class BusinessController {
         return getRequestErrorResponseEntity(request);
     }
 
-    private ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) {
-        return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE)
-                .variables(request.getMethod(), request.getRequestURI(),
-                        "Node Not Found:No Node of type service-instance found at: " + request.getRequestURI(),
-                        "ERR.5.4.6114")
-                .build(), HttpStatus.NOT_FOUND);
+    @PostMapping(
+            value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}",
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> patchSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId,
+            @PathVariable("service-type") final String serviceType,
+            @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+            @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride,
+            @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) {
+
+        LOGGER.info(
+                "Will post service instance for 'global customer id': {}, 'service type': {}, 'service instance id: '{} and '{}': {}...",
+                globalCustomerId, serviceType, serviceInstanceId, X_HTTP_METHOD_OVERRIDE, xHttpHeaderOverride);
+
+        if (HttpMethod.PATCH.toString().equalsIgnoreCase(xHttpHeaderOverride)) {
+            cacheServiceProvider.patchServiceInstance(globalCustomerId, serviceType, serviceInstanceId,
+                    serviceInstance);
+            return ResponseEntity.accepted().build();
+        }
+        LOGGER.error("{} not supported ... ", xHttpHeaderOverride);
+
+        return getRequestErrorResponseEntity(request);
     }
 
+
 }
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java
new file mode 100644 (file)
index 0000000..e3d6b4f
--- /dev/null
@@ -0,0 +1,127 @@
+/*-
+ * ============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.aai.simulator.controller;
+
+import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY;
+import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_URL;
+import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity;
+import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.core.MediaType;
+import org.onap.aai.domain.yang.OwningEntity;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.so.aai.simulator.models.Format;
+import org.onap.so.aai.simulator.models.Result;
+import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider;
+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.bind.annotation.RequestParam;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ *
+ */
+@Controller
+@RequestMapping(path = OWNING_ENTITY_URL)
+public class OwningEntityController {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(OwningEntityController.class);
+
+    private final OwnEntityCacheServiceProvider cacheServiceProvider;
+
+    @Autowired
+    public OwningEntityController(final OwnEntityCacheServiceProvider cacheServiceProvider) {
+        this.cacheServiceProvider = cacheServiceProvider;
+    }
+
+
+    @PutMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> putOwningEntity(@RequestBody final OwningEntity owningEntity,
+            @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) {
+        LOGGER.info("Will add OwningEntity to cache with key 'owning-entity-id': {} ...",
+                owningEntity.getOwningEntityId());
+
+        if (owningEntity.getResourceVersion() == null || owningEntity.getResourceVersion().isEmpty()) {
+            owningEntity.setResourceVersion(getResourceVersion());
+
+        }
+        cacheServiceProvider.putOwningEntity(owningEntityId, owningEntity);
+        return ResponseEntity.accepted().build();
+    }
+
+    @GetMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> getOwningEntity(@PathVariable("owning-entity-id") final String owningEntityId,
+            @RequestParam(name = "resultIndex", required = false) final Integer resultIndex,
+            @RequestParam(name = "resultSize", required = false) final Integer resultSize,
+            @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) {
+        LOGGER.info("retrieving owning entity for 'owning-entity-id': {} ...", owningEntityId);
+
+        final Optional<OwningEntity> optional = cacheServiceProvider.getOwningEntity(owningEntityId);
+        if (!optional.isPresent()) {
+            LOGGER.error("Couldn't find {} in cache", owningEntityId);
+            return getRequestErrorResponseEntity(request);
+        }
+
+        final Format value = Format.forValue(format);
+        switch (value) {
+            case RAW:
+                final OwningEntity owningEntity = optional.get();
+                LOGGER.info("found OwningEntity {} in cache", owningEntity);
+                return ResponseEntity.ok(owningEntity);
+            case COUNT:
+                final Map<String, Object> map = new HashMap<>();
+                map.put(OWNING_ENTITY, 1);
+                return ResponseEntity.ok(new Result(map));
+            default:
+                break;
+        }
+        LOGGER.error("invalid format type :{}", format);
+        return getRequestErrorResponseEntity(request);
+    }
+
+    @PutMapping(value = "/{owning-entity-id}/relationship-list/relationship",
+            consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+            produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+    public ResponseEntity<?> putOwningEntityRelationShip(@RequestBody final Relationship relationship,
+            @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) {
+
+        LOGGER.info("adding relationship for owning-entity-id: {} ...", owningEntityId);
+        if (cacheServiceProvider.putOwningEntityRelationShip(owningEntityId, relationship)) {
+            LOGGER.info("added OwningEntity relationship {} in cache", relationship);
+            return ResponseEntity.accepted().build();
+        }
+        LOGGER.error("Couldn't add relationship for {} in cache", owningEntityId);
+        return getRequestErrorResponseEntity(request);
+    }
+
+}
index 5f63494..0c3b3b7 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.onap.so.aai.simulator.controller;
 
+import static org.onap.so.aai.simulator.utils.Constants.PROJECT;
 import static org.onap.so.aai.simulator.utils.Constants.PROJECT_URL;
 import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity;
 import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion;
@@ -97,15 +98,13 @@ public class ProjectController {
                 return ResponseEntity.ok(project);
             case COUNT:
                 final Map<String, Object> map = new HashMap<>();
-                map.put(projectName, 1);
+                map.put(PROJECT, 1);
                 return ResponseEntity.ok(new Result(map));
             default:
                 break;
         }
         LOGGER.error("invalid format type :{}", format);
         return getRequestErrorResponseEntity(request);
-
-
     }
 
     @PutMapping(value = "/{project-name}/relationship-list/relationship",
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java
new file mode 100644 (file)
index 0000000..4a45e81
--- /dev/null
@@ -0,0 +1,55 @@
+/*-
+ * ============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.aai.simulator.service.providers;
+
+import java.util.concurrent.ConcurrentHashMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.cache.Cache;
+import org.springframework.cache.CacheManager;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ *
+ */
+public abstract class AbstractCacheServiceProvider {
+
+    private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
+
+    private final CacheManager cacheManager;
+
+    public AbstractCacheServiceProvider(final CacheManager cacheManager) {
+        this.cacheManager = cacheManager;
+    }
+
+    protected void clearCahce(final String name) {
+        final Cache cache = cacheManager.getCache(name);
+        if (cache != null) {
+            final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache();
+            LOGGER.info("Clear all entries from cahce: {}", cache.getName());
+            nativeCache.clear();
+        }
+    }
+
+    protected Cache getCache(final String name) {
+        return cacheManager.getCache(name);
+    }
+
+}
index 51fc554..713da54 100644 (file)
@@ -37,6 +37,9 @@ public interface CustomerCacheServiceProvider {
 
     Optional<ServiceSubscription> getServiceSubscription(final String globalCustomerId, final String serviceType);
 
+    boolean putServiceSubscription(final String globalCustomerId, final String serviceType,
+            final ServiceSubscription serviceSubscription);
+
     Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType,
             final String serviceInstanceName);
 
@@ -46,6 +49,9 @@ public interface CustomerCacheServiceProvider {
     boolean putServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId,
             final ServiceInstance serviceInstance);
 
+    boolean patchServiceInstance(final String globalCustomerId, final String serviceType,
+            final String serviceInstanceId, final ServiceInstance serviceInstance);
+
     void clearAll();
 
 }
index 11a82be..c3b5a47 100644 (file)
@@ -21,12 +21,12 @@ package org.onap.so.aai.simulator.service.providers;
 
 import java.util.List;
 import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import org.onap.aai.domain.yang.Customer;
 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.aai.simulator.utils.Constants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -40,20 +40,20 @@ import org.springframework.stereotype.Service;
  *
  */
 @Service
-public class CustomerCacheServiceProviderImpl implements CustomerCacheServiceProvider {
+public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvider
+        implements CustomerCacheServiceProvider {
     private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class);
 
-    public final CacheManager cacheManager;
 
     @Autowired
     public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) {
-        this.cacheManager = cacheManager;
+        super(cacheManager);
     }
 
     @Override
     public Optional<Customer> getCustomer(final String globalCustomerId) {
         LOGGER.info("getting customer from cache using key: {}", globalCustomerId);
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
         final Customer value = cache.get(globalCustomerId, Customer.class);
         if (value != null) {
             return Optional.of(value);
@@ -64,7 +64,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
     @Override
     public void putCustomer(final String globalCustomerId, final Customer customer) {
         LOGGER.info("Adding customer: {} with key: {} in cache ...", customer, globalCustomerId);
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
 
         cache.put(globalCustomerId, customer);
     }
@@ -75,7 +75,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
         LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}",
                 globalCustomerId, serviceType);
 
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
 
         final Customer value = cache.get(globalCustomerId, Customer.class);
 
@@ -91,7 +91,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
     public Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType,
             final String serviceInstanceName) {
 
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
         final Customer value = cache.get(globalCustomerId, Customer.class);
 
         if (value != null) {
@@ -119,7 +119,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
     @Override
     public Optional<ServiceInstance> getServiceInstance(final String globalCustomerId, final String serviceType,
             final String serviceInstanceId) {
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
         final Customer value = cache.get(globalCustomerId, Customer.class);
 
         if (value != null) {
@@ -145,7 +145,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
             final String serviceInstanceId, final ServiceInstance serviceInstance) {
         LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId);
 
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
+        final Cache cache = getCache(Constants.CUSTOMER_CACHE);
         final Customer value = cache.get(globalCustomerId, Customer.class);
 
         if (value != null) {
@@ -171,6 +171,48 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
         return false;
     }
 
+    @Override
+    public boolean putServiceSubscription(final String globalCustomerId, final String serviceType,
+            final ServiceSubscription serviceSubscription) {
+
+        final Optional<Customer> customerOptional = getCustomer(globalCustomerId);
+
+        if (customerOptional.isPresent()) {
+            final Customer customer = customerOptional.get();
+            if (customer.getServiceSubscriptions() == null) {
+                final ServiceSubscriptions serviceSubscriptions = new ServiceSubscriptions();
+                customer.setServiceSubscriptions(serviceSubscriptions);
+                return serviceSubscriptions.getServiceSubscription().add(serviceSubscription);
+            }
+
+            final Optional<ServiceSubscription> serviceSubscriptionOptional = customer.getServiceSubscriptions()
+                    .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst();
+
+            if (!serviceSubscriptionOptional.isPresent()) {
+                return customer.getServiceSubscriptions().getServiceSubscription().add(serviceSubscription);
+            }
+            LOGGER.error("ServiceSubscription already exists {}", serviceSubscriptionOptional.get().getServiceType());
+            return false;
+        }
+        LOGGER.error("Unable to add ServiceSubscription to cache becuase customer does not exits ...");
+        return false;
+    }
+
+    @Override
+    public boolean patchServiceInstance(final String globalCustomerId, final String serviceType,
+            final String serviceInstanceId, final ServiceInstance serviceInstance) {
+        final Optional<ServiceInstance> instance = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId);
+        if (instance.isPresent()) {
+            final ServiceInstance cachedServiceInstance = instance.get();
+            LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedServiceInstance.getOrchestrationStatus(),
+                    serviceInstance.getOrchestrationStatus());
+            cachedServiceInstance.setOrchestrationStatus(serviceInstance.getOrchestrationStatus());
+            return true;
+        }
+        LOGGER.error("Unable to find ServiceInstance ...");
+        return false;
+    }
+
     private ServiceInstances getServiceInstances(final Optional<ServiceSubscription> optional) {
         final ServiceSubscription serviceSubscription = optional.get();
         final ServiceInstances serviceInstances = serviceSubscription.getServiceInstances();
@@ -184,10 +226,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro
 
     @Override
     public void clearAll() {
-        final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE);
-        final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache();
-        LOGGER.info("Clear all entries from cahce: {}", cache.getName());
-        nativeCache.clear();
+        clearCahce(Constants.CUSTOMER_CACHE);
     }
 
 }
index 61cb35a..0f0ac11 100644 (file)
@@ -35,26 +35,25 @@ import org.springframework.stereotype.Service;
  *
  */
 @Service
-public class NodesCacheServiceProviderImpl implements NodesCacheServiceProvider {
+public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider implements NodesCacheServiceProvider {
     private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class);
 
-    public final CacheManager cacheManager;
 
     @Autowired
     public NodesCacheServiceProviderImpl(final CacheManager cacheManager) {
-        this.cacheManager = cacheManager;
+        super(cacheManager);
     }
 
     @Override
     public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) {
-        final Cache cache = cacheManager.getCache(NODES_CACHE);
+        final Cache cache = getCache(NODES_CACHE);
         LOGGER.info("Adding {} to cache with key: {}...", nodeServiceInstance, serviceInstanceId);
         cache.put(serviceInstanceId, nodeServiceInstance);
     }
 
     @Override
     public Optional<NodeServiceInstance> getNodeServiceInstance(final String serviceInstanceId) {
-        final Cache cache = cacheManager.getCache(NODES_CACHE);
+        final Cache cache = getCache(NODES_CACHE);
         final NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class);
         if (value != null) {
             return Optional.of(value);
@@ -65,7 +64,7 @@ public class NodesCacheServiceProviderImpl implements NodesCacheServiceProvider
 
     @Override
     public void clearAll() {
-        final Cache cache = cacheManager.getCache(NODES_CACHE);
+        final Cache cache = getCache(NODES_CACHE);
         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/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java
new file mode 100644 (file)
index 0000000..a7b6409
--- /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.aai.simulator.service.providers;
+
+import java.util.Optional;
+import org.onap.aai.domain.yang.OwningEntity;
+import org.onap.aai.domain.yang.Relationship;
+
+/**
+ * @author waqas.ikram@ericsson.com
+ *
+ */
+public interface OwnEntityCacheServiceProvider {
+
+    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/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java
new file mode 100644 (file)
index 0000000..6b7af02
--- /dev/null
@@ -0,0 +1,98 @@
+/*-
+ * ============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.aai.simulator.service.providers;
+
+import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE;
+import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE;
+import java.util.Optional;
+import org.onap.aai.domain.yang.OwningEntity;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipList;
+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@ericsson.com
+ *
+ */
+@Service
+public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvider
+        implements OwnEntityCacheServiceProvider {
+
+    private static final Logger LOGGER = LoggerFactory.getLogger(OwnEntityCacheServiceProviderImpl.class);
+    private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.BelongsTo";
+
+    @Autowired
+    public OwnEntityCacheServiceProviderImpl(final CacheManager cacheManager) {
+        super(cacheManager);
+    }
+
+    @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);
+        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 OwningEntity value = cache.get(owningEntityId, OwningEntity.class);
+        if (value != null) {
+            return Optional.of(value);
+        }
+        return Optional.empty();
+    }
+
+    @Override
+    public boolean putOwningEntityRelationShip(final String owningEntityId, final Relationship relationship) {
+        final Cache cache = getCache(OWNING_ENTITY_CACHE);
+        final OwningEntity value = cache.get(owningEntityId, OwningEntity.class);
+        if (value != null) {
+            RelationshipList relationshipList = value.getRelationshipList();
+            if (relationshipList == null) {
+                relationshipList = new RelationshipList();
+                value.setRelationshipList(relationshipList);
+            }
+
+            if (relationship.getRelatedTo() == null) {
+                relationship.setRelatedTo(SERVICE_RESOURCE_TYPE);
+            }
+            if (relationship.getRelationshipLabel() == null) {
+                relationship.setRelationshipLabel(RELATIONSHIPS_LABEL);
+            }
+
+            return relationshipList.getRelationship().add(relationship);
+        }
+        LOGGER.error("OwningEntity not found in cache for {}", owningEntityId);
+        return false;
+    }
+
+    @Override
+    public void clearAll() {
+        clearCahce(OWNING_ENTITY_CACHE);
+    }
+
+}
index a104788..4fca311 100644 (file)
@@ -22,7 +22,6 @@ package org.onap.so.aai.simulator.service.providers;
 import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE;
 import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE;
 import java.util.Optional;
-import java.util.concurrent.ConcurrentHashMap;
 import org.onap.aai.domain.yang.Project;
 import org.onap.aai.domain.yang.Relationship;
 import org.onap.aai.domain.yang.RelationshipList;
@@ -38,23 +37,23 @@ import org.springframework.stereotype.Service;
  *
  */
 @Service
-public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvider {
+public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvider
+        implements ProjectCacheServiceProvider {
 
     private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.Uses";
 
     private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class);
 
-    public final CacheManager cacheManager;
 
     @Autowired
     public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) {
-        this.cacheManager = cacheManager;
+        super(cacheManager);
     }
 
     @Override
     public void putProject(final String projectName, final Project project) {
         LOGGER.info("Adding project: {} with name to cache", project, projectName);
-        final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+        final Cache cache = getCache(PROJECT_CACHE);
         cache.put(projectName, project);
     }
 
@@ -62,7 +61,7 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi
     @Override
     public Optional<Project> getProject(final String projectName) {
         LOGGER.info("getting project from cache using key: {}", projectName);
-        final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+        final Cache cache = getCache(PROJECT_CACHE);
         final Project value = cache.get(projectName, Project.class);
         if (value != null) {
             return Optional.of(value);
@@ -72,7 +71,7 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi
 
     @Override
     public boolean putProjectRelationShip(final String projectName, final Relationship relationship) {
-        final Cache cache = cacheManager.getCache(PROJECT_CACHE);
+        final Cache cache = getCache(PROJECT_CACHE);
         final Project value = cache.get(projectName, Project.class);
         if (value != null) {
             RelationshipList relationshipList = value.getRelationshipList();
@@ -90,15 +89,13 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi
 
             return relationshipList.getRelationship().add(relationship);
         }
+        LOGGER.error("Project not found in cache for {}", projectName);
         return false;
 
     }
 
     @Override
     public void clearAll() {
-        final Cache cache = cacheManager.getCache(PROJECT_CACHE);
-        final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache();
-        LOGGER.info("Clear all entries from cahce: {}", cache.getName());
-        nativeCache.clear();
+        clearCahce(PROJECT_CACHE);
     }
 }
index 1cb6336..3d1f85d 100644 (file)
@@ -35,6 +35,8 @@ public class Constants {
 
     public static final String PROJECT_URL = BUSINESS_URL + "/projects/project/";
 
+    public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity";
+
     public static final String HEALTHY = "healthy";
 
     public static final String CUSTOMER_CACHE = "customer-cache";
@@ -43,12 +45,20 @@ public class Constants {
 
     public static final String NODES_CACHE = "nodes-cache";
 
+    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 ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)";
 
     public static final String SERVICE_RESOURCE_TYPE = "service-instance";
-    
+
     public static final String RESOURCE_LINK = "resource-link";
 
     public static final String RESOURCE_TYPE = "resource-type";
index db90a23..81deb86 100644 (file)
@@ -37,12 +37,19 @@ public class Utils {
         return System.currentTimeMillis() + EMPTY_STRING;
     }
 
+    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);
+    }
+
+
     public static ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) {
-        return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE)
-                .variables(request.getMethod(), request.getRequestURI(),
-                        "Node Not Found:No Node of type service-instance found at: " + request.getRequestURI(),
-                        "ERR.5.4.6114")
-                .build(), HttpStatus.NOT_FOUND);
+        return getRequestErrorResponseEntity(request, Constants.SERVICE_RESOURCE_TYPE);
     }
 
 
index 283a2a2..ed9a129 100644 (file)
@@ -23,6 +23,7 @@ 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.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
 import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL;
 import static org.onap.so.aai.simulator.utils.TestConstants.GLOBAL_CUSTOMER_ID;
 import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCES_URL;
@@ -72,6 +73,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 @Configuration
 public class BusinessControllerTest {
 
+    private static final String FIREWALL_SERVICE_TTYPE = "Firewall";
+
+    private static final String ORCHESTRATION_STATUS = "Active";
+
     @LocalServerPort
     private int port;
 
@@ -287,10 +292,76 @@ public class BusinessControllerTest {
 
     }
 
+    @Test
+    public void test_PathSericeInstance_usingServiceInstanceId_OrchStatusChangedInCache() 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> serviceInstancePutResponse = invokeHttpPut(url, getServiceInstance());
+        assertEquals(HttpStatus.ACCEPTED, serviceInstancePutResponse.getStatusCode());
+
+        final HttpHeaders httpHeaders = getHttpHeaders();
+        httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString());
+
+        final HttpEntity<?> orchStatuUpdateServiceInstance =
+                getHttpEntity(getOrchStatuUpdateServiceInstance(), httpHeaders);
+
+        final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse =
+                invokeHttpPost(orchStatuUpdateServiceInstance, url, getOrchStatuUpdateServiceInstance());
+
+        assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode());
+
+
+        final ResponseEntity<ServiceInstance> actual =
+                restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceInstance.class);
+
+        assertEquals(HttpStatus.OK, actual.getStatusCode());
+        assertTrue(actual.hasBody());
+
+        final ServiceInstance actualServiceInstance = actual.getBody();
+
+        assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName());
+        assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId());
+        assertEquals(ORCHESTRATION_STATUS, actualServiceInstance.getOrchestrationStatus());
+
+    }
+
+    @Test
+    public void test_putServiceSubscription_successfullyAddedToCache() throws Exception {
+        final String serviceSubscriptionurl =
+                getCustomerEndPointUrl() + "/service-subscriptions/service-subscription/" + FIREWALL_SERVICE_TTYPE;
+
+        final ResponseEntity<Void> customerPutResponse = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        assertEquals(HttpStatus.ACCEPTED, customerPutResponse.getStatusCode());
+
+        final ResponseEntity<Void> serviceSubscriptionPutResponse =
+                invokeHttpPut(serviceSubscriptionurl, getServiceSubscription());
+        assertEquals(HttpStatus.ACCEPTED, serviceSubscriptionPutResponse.getStatusCode());
+
+        final ResponseEntity<ServiceSubscription> actual = restTemplate.exchange(serviceSubscriptionurl, HttpMethod.GET,
+                new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class);
+
+        assertEquals(HttpStatus.OK, actual.getStatusCode());
+        assertTrue(actual.hasBody());
+
+        final ServiceSubscription actualServiceSubscription = actual.getBody();
+        assertEquals(FIREWALL_SERVICE_TTYPE, actualServiceSubscription.getServiceType());
+
+    }
+
     private String getCustomer() throws Exception, IOException {
         return getJsonString("test-data/business-customer.json");
     }
 
+    private String getServiceSubscription() throws Exception, IOException {
+        return getJsonString("test-data/service-subscription.json");
+    }
+
+
     private String getCustomerEndPointUrl() {
         return TestUtils.getBaseUrl(port) + CUSTOMERS_URL;
     }
@@ -300,10 +371,18 @@ public class BusinessControllerTest {
         return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class);
     }
 
+    private ResponseEntity<Void> invokeHttpPost(final HttpEntity<?> httpEntity, final String url, final Object obj) {
+        return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class);
+    }
+
     private HttpEntity<?> getHttpEntity(final Object obj) {
         return new HttpEntity<>(obj, getHttpHeaders());
     }
 
+    private HttpEntity<?> getHttpEntity(final Object obj, final HttpHeaders headers) {
+        return new HttpEntity<>(obj, headers);
+    }
+
     private HttpHeaders getHttpHeaders() {
         return TestUtils.getHttpHeaders(username);
     }
@@ -312,4 +391,8 @@ public class BusinessControllerTest {
         return getJsonString("test-data/service-instance.json");
     }
 
+    private String getOrchStatuUpdateServiceInstance() throws Exception, IOException {
+        return getJsonString("test-data/service-instance-orch-status-update.json");
+    }
+
 }
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/OwningEntityControllerTest.java
new file mode 100644 (file)
index 0000000..bbb2cad
--- /dev/null
@@ -0,0 +1,172 @@
+/*-
+ * ============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.aai.simulator.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.aai.simulator.utils.TestConstants.RELATIONSHIP_URL;
+import static org.onap.so.aai.simulator.utils.TestUtils.getFile;
+import static org.onap.so.aai.simulator.utils.TestUtils.getHttpHeaders;
+import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString;
+import java.io.IOException;
+import java.nio.file.Files;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aai.domain.yang.OwningEntity;
+import org.onap.so.aai.simulator.models.Format;
+import org.onap.so.aai.simulator.models.Result;
+import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider;
+import org.onap.so.aai.simulator.utils.Constants;
+import org.onap.so.aai.simulator.utils.TestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+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.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@ericsson.com
+ *
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ActiveProfiles("test")
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+@Configuration
+public class OwningEntityControllerTest {
+    private static final String OWNING_ENTITY_JSON_FILE = "test-data/owning-entity.json";
+
+    private static final String OWN_ENTITY_ID_VALUE = "oe_1";
+    private static final String OWN_ENTITY_NAME_VALUE = "oe_2";
+
+    private static final String OWNING_ENTITY_RELATION_SHIP_JSON_FILE = "test-data/owning-entity-relation-ship.json";
+
+    @LocalServerPort
+    private int port;
+
+    @Autowired
+    private TestRestTemplate restTemplate;
+
+    @Value("${spring.security.username}")
+    private String username;
+
+    @Autowired
+    private OwnEntityCacheServiceProvider cacheServiceProvider;
+
+    @After
+    public void after() {
+        cacheServiceProvider.clearAll();
+    }
+
+    @Test
+    public void test_putOwningEntity_successfullyAddedToCache() throws Exception {
+        final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE;
+        final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath()));
+        final ResponseEntity<Void> actual = invokeHttpPut(url, body);
+
+        assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
+
+        final ResponseEntity<OwningEntity> actualResponse = invokeHttpGet(url, OwningEntity.class);
+
+        assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
+        assertTrue(actualResponse.hasBody());
+        final OwningEntity actualOwningEntity = actualResponse.getBody();
+        assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId());
+        assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName());
+        assertNotNull(actualOwningEntity.getResourceVersion());
+
+    }
+
+    @Test
+    public void test_getOwningEntityCount_correctResult() throws Exception {
+        final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE;
+        final String body = new String(Files.readAllBytes(getFile(OWNING_ENTITY_JSON_FILE).toPath()));
+        final ResponseEntity<Void> actual = invokeHttpPut(url, body);
+
+        assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
+
+        final ResponseEntity<Result> actualResponse =
+                invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Result.class);
+
+        assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
+        assertTrue(actualResponse.hasBody());
+        final Result result = actualResponse.getBody();
+        assertNotNull(result.getValues());
+        assertFalse(result.getValues().isEmpty());
+        assertEquals(1, result.getValues().get(0).get(Constants.OWNING_ENTITY));
+    }
+
+    @Test
+    public void test_putOwningEntityRelationShip_successfullyAddedToCache() throws Exception {
+        final String url = getOwningEntityEndPointUrl() + "/" + OWN_ENTITY_ID_VALUE;
+        final ResponseEntity<Void> actual = invokeHttpPut(url, getJsonString(OWNING_ENTITY_JSON_FILE));
+        assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
+
+        final String owningEntityRelationshipUrl = url + RELATIONSHIP_URL;
+
+        final ResponseEntity<Void> putResponse = invokeHttpPut(owningEntityRelationshipUrl, getRelationship());
+
+        assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode());
+
+        final ResponseEntity<OwningEntity> actualResponse = invokeHttpGet(url, OwningEntity.class);
+
+        assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
+        assertTrue(actualResponse.hasBody());
+        final OwningEntity actualOwningEntity = actualResponse.getBody();
+        assertEquals(OWN_ENTITY_ID_VALUE, actualOwningEntity.getOwningEntityId());
+        assertEquals(OWN_ENTITY_NAME_VALUE, actualOwningEntity.getOwningEntityName());
+        assertNotNull(actualOwningEntity.getRelationshipList());
+        assertFalse(actualOwningEntity.getRelationshipList().getRelationship().isEmpty());
+        assertNotNull(actualOwningEntity.getRelationshipList().getRelationship().get(0));
+
+    }
+
+    private String getRelationship() throws IOException {
+        return TestUtils.getJsonString(OWNING_ENTITY_RELATION_SHIP_JSON_FILE);
+    }
+
+    private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) {
+        return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz);
+    }
+
+    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 HttpEntity<?> getHttpEntity(final Object obj) {
+        return new HttpEntity<>(obj, getHttpHeaders(username));
+    }
+
+    private String getOwningEntityEndPointUrl() {
+        return TestUtils.getBaseUrl(port) + Constants.OWNING_ENTITY_URL;
+    }
+
+}
index b198e35..dbe70ce 100644 (file)
@@ -143,7 +143,7 @@ public class ProjectControllerTest {
         final Result result = actualResponse.getBody();
         assertNotNull(result.getValues());
         assertFalse(result.getValues().isEmpty());
-        assertEquals(1, result.getValues().get(0).get(PROJECT_NAME_VALUE));
+        assertEquals(1, result.getValues().get(0).get(Constants.PROJECT));
 
 
     }
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity-relation-ship.json
new file mode 100644 (file)
index 0000000..1c41947
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "related-link": "/business/customers/customer/NordixDemoCustomer/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/owning-entity.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/owning-entity.json
new file mode 100644 (file)
index 0000000..7248d41
--- /dev/null
@@ -0,0 +1,4 @@
+{
+    "owning-entity-id": "oe_1",
+    "owning-entity-name": "oe_2"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-instance-orch-status-update.json
new file mode 100644 (file)
index 0000000..5cd566a
--- /dev/null
@@ -0,0 +1,5 @@
+{
+    "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b",
+    "service-instance-name": "ServiceTest",
+    "orchestration-status": "Active"
+}
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/resources/test-data/service-subscription.json
new file mode 100644 (file)
index 0000000..e1b4f4f
--- /dev/null
@@ -0,0 +1,3 @@
+{
+    "service-type": "Firewall"
+}