summaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/test/java/org
diff options
context:
space:
mode:
authorElena Kuleshov <evn@att.com>2019-04-15 22:59:18 -0400
committerElena Kuleshov <evn@att.com>2019-04-16 01:29:00 -0400
commit5223788222fd78c9e50680471eb0529361645230 (patch)
tree7cc521a22a5c1753937d71c4dd6dc9dd57746d1e /asdc-controller/src/test/java/org
parent9c0663079469cb5a42c96ff990385c23be2f361e (diff)
Use distribution json for workflow install
Use distribution json for workflow install Change-Id: I2eec3700d0ba92794b6ca11bd43683d91fb480ee Issue-ID: SO-1726 Signed-off-by: Kuleshov, Elena <evn@att.com>
Diffstat (limited to 'asdc-controller/src/test/java/org')
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java63
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/BpmnInstallerTest.java4
-rw-r--r--asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java109
3 files changed, 172 insertions, 4 deletions
diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java
index 2e5ad13c21..ac107f6449 100644
--- a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java
+++ b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java
@@ -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;
@@ -67,6 +72,9 @@ public class ASDCRestInterfaceTest extends BaseTest {
private NetworkResourceRepository networkRepo;
@Autowired
+ private WorkflowRepository workflowRepo;
+
+ @Autowired
private ASDCRestInterface asdcRestInterface;
private TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
@@ -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);
@@ -176,15 +192,58 @@ public class ASDCRestInterfaceTest extends BaseTest {
}
@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;
}
diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/BpmnInstallerTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/BpmnInstallerTest.java
index 6efb04fc35..7071a68a23 100644
--- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/BpmnInstallerTest.java
+++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/BpmnInstallerTest.java
@@ -81,7 +81,7 @@ public class BpmnInstallerTest {
public void buildMimeMultiPart_Test() throws Exception {
Path tempFilePath = Paths.get(tempDirectoryPath.toAbsolutePath().toString(), "TestBB.bpmn");
Files.createFile(tempFilePath);
- HttpEntity entity = bpmnInstaller.buildMimeMultipart("TestBB.bpmn");
+ HttpEntity entity = bpmnInstaller.buildMimeMultipart("TestBB.bpmn", "");
String mimeMultipartBodyFilePath = "src/test/resources" + "/mime-multipart-body.txt";
File mimeMultipartBody = new File(mimeMultipartBodyFilePath);
@@ -99,7 +99,7 @@ public class BpmnInstallerTest {
HttpClient httpClient = mock(HttpClient.class);
doReturn(response).when(httpClient).execute(any(HttpPost.class));
bpmnInstallerSpy.installBpmn(TEST_CSAR);
- verify(bpmnInstallerSpy, times(1)).sendDeploymentRequest(anyString());
+ verify(bpmnInstallerSpy, times(1)).sendDeploymentRequest(anyString(), anyString());
}
@Test
diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java
new file mode 100644
index 0000000000..e655245c31
--- /dev/null
+++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/bpmn/WorkflowResourceTest.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.asdc.installer.bpmn;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.List;
+import javax.transaction.Transactional;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.onap.sdc.api.notification.IArtifactInfo;
+
+@Transactional
+public class WorkflowResourceTest {
+
+ private WorkflowResource workflowResource = new WorkflowResource();
+
+ private static final String TEST_CSAR = "src/test/resources/resource-examples/WorkflowBpmn/service-CxSvc-csar.csar";
+ private Path tempDirectoryPath;
+
+ @Test
+ public void getActivityNameList_Test() throws Exception {
+ String bpmnContent = new String(Files
+ .readAllBytes(Paths.get("src/test/resources/resource-examples/WorkflowBpmn/TestBpmnFromSDC.bpmn")));
+ List<String> activityNames = workflowResource.getActivityNameList(bpmnContent);
+ assertEquals("VNFSetInMaintFlagActivity", activityNames.get(0));
+ }
+
+ @Test
+ public void getWorkflowNameStandard_Test() {
+ String workflowName = workflowResource.getWorkflowNameFromArtifactName("TestWF2-1_0.bpmn");
+ assertEquals("TestWF2", workflowName);
+ }
+
+ @Test
+ public void getWorkflowNameNoVersion_Test() {
+ String workflowName = workflowResource.getWorkflowNameFromArtifactName("TestWF2.bpmn");
+ assertEquals("TestWF2", workflowName);
+ }
+
+ @Test
+ public void getWorkflowNameNoSuffix_Test() {
+ String workflowName = workflowResource.getWorkflowNameFromArtifactName("TestWF2-1_0");
+ assertEquals("TestWF2", workflowName);
+ }
+
+ @Test
+ public void getWorkflowVersionStandard_Test() {
+ Double workflowVersion = workflowResource.getWorkflowVersionFromArtifactName("TestWF2-1_0.bpmn");
+ assertTrue(workflowVersion == 1.0);
+ }
+
+ @Test
+ public void getWorkflowVersionNoVersion_Test() {
+ Double workflowVersion = workflowResource.getWorkflowVersionFromArtifactName("TestWF2.bpmn");
+ assertNull(workflowVersion);
+ }
+
+ @Test
+ public void getWorkflowVersionNoSuffix_Test() {
+ Double workflowVersion = workflowResource.getWorkflowVersionFromArtifactName("TestWF2-1_0");
+ assertTrue(workflowVersion == 1.0);
+ }
+
+}