Use distribution json for workflow install
[so.git] / asdc-controller / src / test / java / org / onap / so / asdc / client / test / rest / ASDCRestInterfaceTest.java
index 2e5ad13..ac107f6 100644 (file)
@@ -22,12 +22,15 @@ package org.onap.so.asdc.client.test.rest;
 
 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
 import static com.github.tomakehurst.wiremock.client.WireMock.post;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import java.io.File;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.HashSet;
 import java.util.Set;
 import javax.transaction.Transactional;
@@ -43,9 +46,11 @@ import org.onap.so.asdc.client.test.emulators.NotificationDataImpl;
 import org.onap.so.db.catalog.beans.AllottedResource;
 import org.onap.so.db.catalog.beans.AllottedResourceCustomization;
 import org.onap.so.db.catalog.beans.Service;
+import org.onap.so.db.catalog.beans.Workflow;
 import org.onap.so.db.catalog.data.repository.AllottedResourceRepository;
 import org.onap.so.db.catalog.data.repository.NetworkResourceRepository;
 import org.onap.so.db.catalog.data.repository.ServiceRepository;
+import org.onap.so.db.catalog.data.repository.WorkflowRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.web.client.TestRestTemplate;
 import org.springframework.boot.web.server.LocalServerPort;
@@ -66,6 +71,9 @@ public class ASDCRestInterfaceTest extends BaseTest {
     @Autowired
     private NetworkResourceRepository networkRepo;
 
+    @Autowired
+    private WorkflowRepository workflowRepo;
+
     @Autowired
     private ASDCRestInterface asdcRestInterface;
 
@@ -97,6 +105,10 @@ public class ASDCRestInterfaceTest extends BaseTest {
         wireMockServer.stubFor(post(urlPathMatching("/aai/.*"))
                 .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
 
+        wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
+                .willReturn(aResponse().withHeader("Content-Type", "application/json")
+                        .withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
+
         ObjectMapper mapper = new ObjectMapper();
         NotificationDataImpl request =
                 mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"),
@@ -146,6 +158,10 @@ public class ASDCRestInterfaceTest extends BaseTest {
         wireMockServer.stubFor(post(urlPathMatching("/aai/.*"))
                 .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
 
+        wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
+                .willReturn(aResponse().withHeader("Content-Type", "application/json")
+                        .withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
+
         ObjectMapper mapper = new ObjectMapper();
         NotificationDataImpl request = mapper.readValue(
                 new File("src/test/resources/resource-examples/vFW/notification.json"), NotificationDataImpl.class);
@@ -175,16 +191,59 @@ public class ASDCRestInterfaceTest extends BaseTest {
         assertEquals(expectedService.getModelName(), actualService.getModelName());
     }
 
+    @Test
+    @Transactional
+    public void testWorkflowDistribution() throws Exception {
+
+        wireMockServer.stubFor(post(urlPathMatching("/aai/.*"))
+                .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
+
+        wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
+                .willReturn(aResponse().withHeader("Content-Type", "application/json")
+                        .withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
+
+        wireMockServer.stubFor(
+                post(urlPathEqualTo("/sobpmnengine/deployment/create")).willReturn(aResponse().withStatus(200)));
+
+        ObjectMapper mapper = new ObjectMapper();
+        NotificationDataImpl request = mapper.readValue(
+                new File("src/test/resources/resource-examples/WorkflowBpmn/workflow-distribution.json"),
+                NotificationDataImpl.class);
+        headers.add("resource-location", "src/test/resources/resource-examples/WorkflowBpmn/");
+        HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
+
+        ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"),
+                HttpMethod.POST, entity, String.class);
+
+        assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
+
+        Workflow actualResponse = workflowRepo.findByArtifactUUID("a90f8eaa-7c20-422f-8c81-aacbca6fb9e7");
+
+        if (actualResponse == null)
+            throw new Exception("No Workflow Written to database");
+
+        String expectedBody = new String(
+                Files.readAllBytes(Paths.get("src/test/resources/resource-examples/WorkflowBpmn/TestWF2-1_0.bpmn")));
+        assertEquals(actualResponse.getArtifactChecksum(), "ZjUzNjg1NDMyMTc4MWJmZjFlNDcyOGQ0Zjc1YWQwYzQ\u003d");
+        assertEquals(actualResponse.getArtifactName(), "TestWF2-1_0.bpmn");
+        assertEquals(actualResponse.getDescription(), "Workflow Artifact Description");
+        assertEquals(actualResponse.getBody(), expectedBody);
+
+        Workflow shouldNotBeFound = workflowRepo.findByArtifactUUID("f27066a1-c3a7-4672-b02e-1251b74b7b71");
+        assertNull(shouldNotBeFound);
+    }
+
     @Test
     public void invokeASDCStatusDataNullTest() {
         String request = "";
+        wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec"))
+                .willReturn(aResponse().withHeader("Content-Type", "application/json")
+                        .withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
         Response response = asdcRestInterface.invokeASDCStatusData(request);
         assertNull(response);
 
     }
 
-
-
     protected String createURLWithPort(String uri) {
         return "http://localhost:" + port + uri;
     }