Upgrading current ETSI CSIT to latest honolulu
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / BusinessControllerTest.java
index 98b0fa7..7da3779 100644 (file)
@@ -23,13 +23,13 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
 import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
 import static org.onap.so.aaisimulator.utils.TestConstants.CUSTOMERS_URL;
 import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_NAME;
 import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL;
 import static org.onap.so.aaisimulator.utils.TestConstants.GLOBAL_CUSTOMER_ID;
 import static org.onap.so.aaisimulator.utils.TestConstants.RELATED_TO_URL;
-import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL;
 import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCES_URL;
 import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_ID;
 import static org.onap.so.aaisimulator.utils.TestConstants.SERVICE_INSTANCE_URL;
@@ -37,13 +37,13 @@ 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 static org.onap.so.aaisimulator.utils.TestUtils.getCustomer;
+import static org.onap.so.aaisimulator.utils.TestUtils.getServiceInstance;
 import java.io.IOException;
 import java.util.Optional;
 import java.util.UUID;
 import org.junit.After;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.onap.aai.domain.yang.Customer;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.aai.domain.yang.GenericVnfs;
@@ -56,44 +56,22 @@ import org.onap.so.aaisimulator.utils.RequestError;
 import org.onap.so.aaisimulator.utils.RequestErrorResponseUtils;
 import org.onap.so.aaisimulator.utils.ServiceException;
 import org.onap.so.aaisimulator.utils.TestUtils;
-import org.onap.so.simulator.model.UserCredentials;
 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@ericsson.com
  *
  */
-@RunWith(SpringJUnit4ClassRunner.class)
-@ActiveProfiles("test")
-@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@Configuration
-public class BusinessControllerTest {
+public class BusinessControllerTest extends AbstractSpringBootTest {
 
-    private static final String FIREWALL_SERVICE_TTYPE = "Firewall";
+    private static final String FIREWALL_SERVICE_TYPE = "Firewall";
 
     private static final String ORCHESTRATION_STATUS = "Active";
 
-    @LocalServerPort
-    private int port;
-
-    @Autowired
-    private TestRestTemplate restTemplate;
-
-    @Autowired
-    private UserCredentials userCredentials;
-
     @Autowired
     private CustomerCacheServiceProvider cacheServiceProvider;
 
@@ -104,20 +82,18 @@ public class BusinessControllerTest {
 
     @Test
     public void test_putCustomer_successfullyAddedToCache() throws Exception {
-        final ResponseEntity<Void> actual = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
-
-        assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
+        invokeCustomerEndPointAndAssertResponse();
         assertTrue(cacheServiceProvider.getCustomer(GLOBAL_CUSTOMER_ID).isPresent());
     }
 
     @Test
     public void test_getCustomer_ableToRetrieveCustomer() throws Exception {
-        final String url = getCustomerEndPointUrl();
+        final String url = getUrl(CUSTOMERS_URL);
 
-        invokeHttpPut(url, getCustomer());
+        final ResponseEntity<Void> response = testRestTemplateService.invokeHttpPut(url, getCustomer(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
 
-        final ResponseEntity<Customer> actual =
-                restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), Customer.class);
+        final ResponseEntity<Customer> actual = testRestTemplateService.invokeHttpGet(url, Customer.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -130,10 +106,9 @@ public class BusinessControllerTest {
 
     @Test
     public void test_getCustomer_returnRequestError_ifCustomerNotInCache() throws Exception {
-        final String url = getCustomerEndPointUrl();
+        final String url = getUrl(CUSTOMERS_URL);
 
-        final ResponseEntity<RequestError> actual =
-                restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), RequestError.class);
+        final ResponseEntity<RequestError> actual = testRestTemplateService.invokeHttpGet(url, RequestError.class);
 
         assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode());
 
@@ -149,12 +124,12 @@ public class BusinessControllerTest {
 
     @Test
     public void test_getServiceSubscription_ableToRetrieveServiceSubscriptionFromCache() throws Exception {
-        final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL;
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL);
 
-        invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        invokeCustomerEndPointAndAssertResponse();
 
-        final ResponseEntity<ServiceSubscription> actual = restTemplate.exchange(url, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class);
+        final ResponseEntity<ServiceSubscription> actual =
+                testRestTemplateService.invokeHttpGet(url, ServiceSubscription.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -168,13 +143,9 @@ public class BusinessControllerTest {
     @Test
     public void test_putSericeInstance_ableToRetrieveServiceInstanceFromCache() throws Exception {
 
-        final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL;
-
-        final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        invokeCustomerEndPointAndAssertResponse();
+        invokeServiceInstanceEndPointAndAssertResponse();
 
-        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
-
-        invokeHttpPut(url, getServiceInstance());
 
         final Optional<ServiceInstance> actual =
                 cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID);
@@ -191,19 +162,15 @@ public class BusinessControllerTest {
     public void test_getSericeInstance_usingServiceInstanceName_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());
+        invokeCustomerEndPointAndAssertResponse();
+        invokeServiceInstanceEndPointAndAssertResponse();
 
-        invokeHttpPut(url, getServiceInstance());
 
-        final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL
+        final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL)
                 + "?depth=2&service-instance-name=" + SERVICE_NAME;
 
-        final ResponseEntity<ServiceInstances> actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), ServiceInstances.class);
+        final ResponseEntity<ServiceInstances> actual =
+                testRestTemplateService.invokeHttpGet(serviceInstanceUrl, ServiceInstances.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -219,15 +186,13 @@ public class BusinessControllerTest {
     public void test_getSericeInstance_usingServiceInstanceName_returnRequestErrorIfnoServiceInstanceFound()
             throws Exception {
 
-        final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        invokeCustomerEndPointAndAssertResponse();
 
-        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
-
-        final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL
+        final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL)
                 + "?depth=2&service-instance-name=" + SERVICE_NAME;
 
-        final ResponseEntity<RequestError> actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), RequestError.class);
+        final ResponseEntity<RequestError> actual =
+                testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class);
 
         assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -240,16 +205,13 @@ public class BusinessControllerTest {
     public void test_getSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache()
             throws Exception {
 
-        final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL;
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
 
-        final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
-
-        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
-
-        invokeHttpPut(url, getServiceInstance());
+        invokeCustomerEndPointAndAssertResponse();
+        invokeServiceInstanceEndPointAndAssertResponse();
 
         final ResponseEntity<ServiceInstance> actual =
-                restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceInstance.class);
+                testRestTemplateService.invokeHttpGet(url, ServiceInstance.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -264,19 +226,16 @@ public class BusinessControllerTest {
     @Test
     public void test_getSericeInstance_usinginvalidServiceInstanceId_shouldReturnError() throws Exception {
 
-        final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL;
+        invokeCustomerEndPointAndAssertResponse();
 
-        final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        invokeServiceInstanceEndPointAndAssertResponse();
 
-        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
 
-        invokeHttpPut(url, getServiceInstance());
+        final String invalidServiceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL,
+                SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID());
 
-        final String invalidServiceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL
-                + SERVICE_INSTANCES_URL + "/service-instance/" + UUID.randomUUID();
-
-        final ResponseEntity<RequestError> actual = restTemplate.exchange(invalidServiceInstanceUrl, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), RequestError.class);
+        final ResponseEntity<RequestError> actual =
+                testRestTemplateService.invokeHttpGet(invalidServiceInstanceUrl, RequestError.class);
 
         assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode());
 
@@ -293,21 +252,15 @@ public class BusinessControllerTest {
     @Test
     public void test_getSericeInstance_usingInvalidServiceInstanceName_shouldReturnError() 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> putRequestReponse = invokeHttpPut(url, getServiceInstance());
-        assertEquals(HttpStatus.ACCEPTED, putRequestReponse.getStatusCode());
+        invokeCustomerEndPointAndAssertResponse();
+        invokeServiceInstanceEndPointAndAssertResponse();
 
 
-        final String serviceInstanceUrl = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCES_URL
+        final String serviceInstanceUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCES_URL)
                 + "?service-instance-name=Dummy&depth=2";
 
-        final ResponseEntity<RequestError> actual = restTemplate.exchange(serviceInstanceUrl, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), RequestError.class);
+        final ResponseEntity<RequestError> actual =
+                testRestTemplateService.invokeHttpGet(serviceInstanceUrl, RequestError.class);
 
         assertEquals(HttpStatus.NOT_FOUND, actual.getStatusCode());
 
@@ -324,29 +277,21 @@ 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 String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
 
-        final ResponseEntity<Void> serviceInstancePutResponse = invokeHttpPut(url, getServiceInstance());
-        assertEquals(HttpStatus.ACCEPTED, serviceInstancePutResponse.getStatusCode());
+        invokeCustomerEndPointAndAssertResponse();
+        invokeServiceInstanceEndPointAndAssertResponse();
 
-        final HttpHeaders httpHeaders = getHttpHeaders();
+        final HttpHeaders httpHeaders = testRestTemplateService.getHttpHeaders();
         httpHeaders.add(X_HTTP_METHOD_OVERRIDE, HttpMethod.PATCH.toString());
 
-        final HttpEntity<?> orchStatuUpdateServiceInstance =
-                getHttpEntity(getOrchStatuUpdateServiceInstance(), httpHeaders);
-
-        final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse =
-                invokeHttpPost(orchStatuUpdateServiceInstance, url, getOrchStatuUpdateServiceInstance());
+        final ResponseEntity<Void> orchStatuUpdateServiceInstanceResponse = testRestTemplateService
+                .invokeHttpPost(httpHeaders, url, TestUtils.getOrchStatuUpdateServiceInstance(), Void.class);
 
         assertEquals(HttpStatus.ACCEPTED, orchStatuUpdateServiceInstanceResponse.getStatusCode());
 
-
         final ResponseEntity<ServiceInstance> actual =
-                restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders()), ServiceInstance.class);
+                testRestTemplateService.invokeHttpGet(url, ServiceInstance.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
@@ -362,115 +307,126 @@ public class BusinessControllerTest {
     @Test
     public void test_putServiceSubscription_successfullyAddedToCache() throws Exception {
         final String serviceSubscriptionurl =
-                getCustomerEndPointUrl() + "/service-subscriptions/service-subscription/" + FIREWALL_SERVICE_TTYPE;
+                getUrl(CUSTOMERS_URL, "/service-subscriptions/service-subscription/", FIREWALL_SERVICE_TYPE);
 
-        final ResponseEntity<Void> customerPutResponse = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
-        assertEquals(HttpStatus.ACCEPTED, customerPutResponse.getStatusCode());
+        invokeCustomerEndPointAndAssertResponse();
 
-        final ResponseEntity<Void> serviceSubscriptionPutResponse =
-                invokeHttpPut(serviceSubscriptionurl, getServiceSubscription());
-        assertEquals(HttpStatus.ACCEPTED, serviceSubscriptionPutResponse.getStatusCode());
+        final ResponseEntity<Void> responseEntity = testRestTemplateService.invokeHttpPut(serviceSubscriptionurl,
+                TestUtils.getServiceSubscription(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
 
-        final ResponseEntity<ServiceSubscription> actual = restTemplate.exchange(serviceSubscriptionurl, HttpMethod.GET,
-                new HttpEntity<>(getHttpHeaders()), ServiceSubscription.class);
+        final ResponseEntity<ServiceSubscription> actual =
+                testRestTemplateService.invokeHttpGet(serviceSubscriptionurl, ServiceSubscription.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
         assertTrue(actual.hasBody());
 
         final ServiceSubscription actualServiceSubscription = actual.getBody();
-        assertEquals(FIREWALL_SERVICE_TTYPE, actualServiceSubscription.getServiceType());
+        assertEquals(FIREWALL_SERVICE_TYPE, actualServiceSubscription.getServiceType());
 
     }
 
     @Test
     public void test_putSericeInstanceRelatedTo_ableToRetrieveServiceInstanceFromCache() throws Exception {
 
-        final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL;
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
 
-        final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer());
+        invokeCustomerEndPointAndAssertResponse();
 
-        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+        invokeServiceInstanceEndPointAndAssertResponse();
 
-        final ResponseEntity<Void> responseEntity = invokeHttpPut(url, getServiceInstance());
-        assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
-
-        final String relationShipUrl =
-                getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL + RELATIONSHIP_URL;
+        final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL,
+                BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
 
+        final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl,
+                TestUtils.getRelationShipJsonObject(), Relationship.class);
 
-        final HttpEntity<?> httpEntity = getHttpEntity(getRelationShipJsonObject());
-        final ResponseEntity<Relationship> responseEntity2 =
-                restTemplate.exchange(relationShipUrl, HttpMethod.PUT, httpEntity, Relationship.class);
         assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode());
 
-        final String genericVnfUrl = TestUtils.getBaseUrl(port) + GENERIC_VNF_URL + VNF_ID;
-        final ResponseEntity<Void> genericVnfResponse = invokeHttpPut(genericVnfUrl, getGenericVnf());
+        final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+        final ResponseEntity<Void> genericVnfResponse =
+                testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class);
         assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
 
-
-        final ResponseEntity<GenericVnfs> actual =
-                restTemplate.exchange(url + RELATED_TO_URL + "?vnf-name=" + GENERIC_VNF_NAME, HttpMethod.GET,
-                        new HttpEntity<>(getHttpHeaders()), GenericVnfs.class);
+        final ResponseEntity<GenericVnfs> actual = testRestTemplateService
+                .invokeHttpGet(url + RELATED_TO_URL + "?vnf-name=" + GENERIC_VNF_NAME, GenericVnfs.class);
 
         assertEquals(HttpStatus.OK, actual.getStatusCode());
-        
+
         assertTrue(actual.hasBody());
         final GenericVnfs genericVnfs = actual.getBody();
         assertFalse(genericVnfs.getGenericVnf().isEmpty());
         final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
         assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName());
+    }
 
+    @Test
+    public void test_putServiceInstanceRelatedTo_ableToRetrieveAllRelatedGenericVnfsFromCache() throws Exception {
 
-    }
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
 
-    private String getCustomer() throws Exception, IOException {
-        return getJsonString("test-data/business-customer.json");
-    }
+        invokeCustomerEndPointAndAssertResponse();
 
-    private String getServiceSubscription() throws Exception, IOException {
-        return getJsonString("test-data/service-subscription.json");
-    }
+        invokeServiceInstanceEndPointAndAssertResponse();
 
+        final String relationShipUrl = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL,
+                BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
 
-    private String getCustomerEndPointUrl() {
-        return TestUtils.getBaseUrl(port) + CUSTOMERS_URL;
-    }
+        final ResponseEntity<Relationship> responseEntity2 = testRestTemplateService.invokeHttpPut(relationShipUrl,
+                TestUtils.getRelationShipJsonObject(), Relationship.class);
 
-    private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) {
-        final HttpEntity<?> httpEntity = getHttpEntity(obj);
-        return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class);
-    }
+        assertEquals(HttpStatus.ACCEPTED, responseEntity2.getStatusCode());
 
-    private ResponseEntity<Void> invokeHttpPost(final HttpEntity<?> httpEntity, final String url, final Object obj) {
-        return restTemplate.exchange(url, HttpMethod.POST, httpEntity, Void.class);
-    }
+        final String genericVnfUrl = getUrl(GENERIC_VNF_URL, VNF_ID);
+        final ResponseEntity<Void> genericVnfResponse =
+                testRestTemplateService.invokeHttpPut(genericVnfUrl, TestUtils.getGenericVnf(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, genericVnfResponse.getStatusCode());
 
-    private HttpEntity<?> getHttpEntity(final Object obj) {
-        return new HttpEntity<>(obj, getHttpHeaders());
-    }
+        final ResponseEntity<GenericVnfs> actual =
+                testRestTemplateService.invokeHttpGet(url + RELATED_TO_URL, GenericVnfs.class);
 
-    private HttpEntity<?> getHttpEntity(final Object obj, final HttpHeaders headers) {
-        return new HttpEntity<>(obj, headers);
-    }
+        assertEquals(HttpStatus.OK, actual.getStatusCode());
 
-    private HttpHeaders getHttpHeaders() {
-        return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername());
+        assertTrue(actual.hasBody());
+        final GenericVnfs genericVnfs = actual.getBody();
+        assertFalse(genericVnfs.getGenericVnf().isEmpty());
+        final GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0);
+        assertEquals(GENERIC_VNF_NAME, genericVnf.getVnfName());
     }
 
-    private String getServiceInstance() throws Exception, IOException {
-        return getJsonString("test-data/service-instance.json");
-    }
 
-    private String getOrchStatuUpdateServiceInstance() throws Exception, IOException {
-        return getJsonString("test-data/service-instance-orch-status-update.json");
+    @Test
+    public void test_DeleteSericeInstance_ServiceInstanceRemovedFromCache() throws Exception {
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+
+        invokeCustomerEndPointAndAssertResponse();
+
+        invokeServiceInstanceEndPointAndAssertResponse();
+
+        final Optional<ServiceInstance> optional =
+                cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID);
+        assertTrue(optional.isPresent());
+        final ServiceInstance serviceInstance = optional.get();
+
+        final ResponseEntity<Void> responseEntity = testRestTemplateService
+                .invokeHttpDelete(url + "?resource-version=" + serviceInstance.getResourceVersion(), Void.class);
+        assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode());
+        assertFalse(cacheServiceProvider.getServiceInstance(GLOBAL_CUSTOMER_ID, SERVICE_TYPE, SERVICE_INSTANCE_ID)
+                .isPresent());
     }
 
-    private String getRelationShipJsonObject() throws IOException {
-        return getJsonString("test-data/service-Instance-relationShip.json");
+    private void invokeServiceInstanceEndPointAndAssertResponse() throws IOException {
+        final String url = getUrl(CUSTOMERS_URL, SERVICE_SUBSCRIPTIONS_URL, SERVICE_INSTANCE_URL);
+        final ResponseEntity<Void> responseEntity =
+                testRestTemplateService.invokeHttpPut(url, getServiceInstance(), Void.class);
+        assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
     }
-    
-    private String getGenericVnf() throws IOException {
-        return getJsonString("test-data/generic-vnf.json");
+
+    private void invokeCustomerEndPointAndAssertResponse() throws Exception, IOException {
+        final ResponseEntity<Void> response =
+                testRestTemplateService.invokeHttpPut(getUrl(CUSTOMERS_URL), getCustomer(), Void.class);
+
+        assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
     }
 
 }