aboutsummaryrefslogtreecommitdiffstats
path: root/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java
diff options
context:
space:
mode:
authorByung-Woo Jun <byung-woo.jun@est.tech>2020-10-02 13:47:09 +0000
committerGerrit Code Review <gerrit@onap.org>2020-10-02 13:47:09 +0000
commit23312bd92a1bc9a64b26602a2798c05005187d0f (patch)
treeb8c3180d04a0b623401b7673d064e6df20e7583d /so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java
parent0e28abb8561b94d029d9d4d6d36bebea7ce33604 (diff)
parent57aa480c5a0e9a823c13024f71e84f7673d7ed23 (diff)
Merge "SO-ETSI-NFVO Delete NS Backend Service"
Diffstat (limited to 'so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java')
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java5
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java12
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java185
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java2
-rw-r--r--so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java13
5 files changed, 194 insertions, 23 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java
index 86f2879966..b6fd9e407a 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java
@@ -147,4 +147,9 @@ public abstract class BaseTest {
return runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null;
}
+ protected String getAaiServiceInstanceEndPoint() {
+ return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID
+ + "/service-subscriptions/service-subscription/" + SERVICE_TYPE
+ + "/service-instances/service-instance/.*";
+ }
}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java
index 05213a344f..3686cd620d 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java
@@ -234,7 +234,7 @@ public class CreateNsTaskTest extends BaseTest {
assertNull(nsResponseVariable);
final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(),
- CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME);
+ CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME);
final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue();
assertNotNull(problemDetails);
@@ -306,7 +306,7 @@ public class CreateNsTaskTest extends BaseTest {
mockEtsiCatalogEndpoints(nsdId);
- final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest);
+ final String modelEndpoint = getAaiServiceInstanceEndPoint();
wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(WireMock.serverError()));
wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(WireMock.serverError()));
@@ -339,18 +339,12 @@ public class CreateNsTaskTest extends BaseTest {
}
private void mockAAIEndpoints(final CreateNsRequest createNsRequest) {
- final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest);
+ final String modelEndpoint = getAaiServiceInstanceEndPoint();
wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok()));
wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(notFound()));
}
- private String getAiaServiceInstancelEndPoint(final CreateNsRequest createNsRequest) {
- return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID
- + "/service-subscriptions/service-subscription/" + SERVICE_TYPE
- + "/service-instances/service-instance/.*";
- }
-
private void mockEtsiCatalogEndpoints(final String nsdId) {
mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId))
.andExpect(method(HttpMethod.GET))
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java
new file mode 100644
index 0000000000..adb8a9e69b
--- /dev/null
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java
@@ -0,0 +1,185 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.etsi.nfvo.ns.workflow.engine.tasks;
+
+import com.google.gson.Gson;
+import org.camunda.bpm.engine.history.HistoricProcessInstance;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException;
+import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst;
+import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State;
+import org.springframework.beans.factory.annotation.Autowired;
+import java.time.LocalDateTime;
+import java.util.Optional;
+import java.util.UUID;
+import static com.github.tomakehurst.wiremock.client.WireMock.delete;
+import static com.github.tomakehurst.wiremock.client.WireMock.get;
+import static com.github.tomakehurst.wiremock.client.WireMock.ok;
+import static com.github.tomakehurst.wiremock.client.WireMock.okJson;
+import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Andrew Lamb (andrew.a.lamb@est.tech)
+ *
+ */
+public class DeleteNsTaskTest extends BaseTest {
+
+ @Autowired
+ private JobExecutorService objUnderTest;
+
+ @Autowired
+ private GsonProvider gsonProvider;
+
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
+ private Gson gson;
+
+ @Before
+ public void before() {
+ wireMockServer.resetAll();
+ gson = gsonProvider.getGson();
+ }
+
+ @After
+ public void after() {
+ wireMockServer.resetAll();
+ }
+
+ @Test
+ public void testRunDeleteNsJob_nsInstanceIdNotInDatabase_throwsException() {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ assertTrue(databaseServiceProvider.getNfvoNsInst(nsInstanceId).isEmpty());
+
+ expectedException.expect(NsRequestProcessingException.class);
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+ }
+
+ @Test
+ public void testRunDeleteNsJob_nsInstanceStateInstantiated_throwsException() {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ addDummyNsToDatabase(nsInstanceId, State.INSTANTIATED);
+
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInst.isPresent());
+ assertEquals(State.INSTANTIATED, optionalNfvoNsInst.get().getStatus());
+
+ expectedException.expect(NsRequestProcessingException.class);
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+ }
+
+ @Test
+ public void testRunDeleteNsJob_nsInstanceStateInstantiating_throwsException() {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ addDummyNsToDatabase(nsInstanceId, State.INSTANTIATING);
+
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInst.isPresent());
+ assertEquals(State.INSTANTIATING, optionalNfvoNsInst.get().getStatus());
+
+ expectedException.expect(NsRequestProcessingException.class);
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+ }
+
+ @Test
+ public void testRunDeleteNsJob_nsInstanceStateTerminating_throwsException() {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ addDummyNsToDatabase(nsInstanceId, State.TERMINATING);
+
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInst.isPresent());
+ assertEquals(State.TERMINATING, optionalNfvoNsInst.get().getStatus());
+
+ expectedException.expect(NsRequestProcessingException.class);
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+ }
+
+ @Test
+ public void testRunDeleteNsJob_nsInstanceStateFailed_throwsException() {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ addDummyNsToDatabase(nsInstanceId, State.FAILED);
+
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInst.isPresent());
+ assertEquals(State.FAILED, optionalNfvoNsInst.get().getStatus());
+
+ expectedException.expect(NsRequestProcessingException.class);
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+ }
+
+ @Test
+ public void testRunDeleteNsJob_SuccessfulCase() throws InterruptedException {
+ final String nsInstanceId = UUID.randomUUID().toString();
+ addDummyNsToDatabase(nsInstanceId, State.NOT_INSTANTIATED);
+ mockAaiEndpoints();
+
+ final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInst.isPresent());
+ assertEquals(State.NOT_INSTANTIATED, optionalNfvoNsInst.get().getStatus());
+
+ objUnderTest.runDeleteNsJob(nsInstanceId);
+
+ final Optional<NfvoJob> optional = getJobByResourceId(nsInstanceId);
+ assertTrue(optional.isPresent());
+ final NfvoJob nfvoJob = optional.get();
+
+ // Confirm Process finishes in STATE_COMPLETED
+ assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId()));
+ final HistoricProcessInstance historicProcessInstance =
+ getHistoricProcessInstance(nfvoJob.getProcessInstanceId());
+ assertNotNull(historicProcessInstance);
+ assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState());
+
+ // Confirm NS Instance no longer in database
+ final Optional<NfvoNsInst> optionalNfvoNsInstance = databaseServiceProvider.getNfvoNsInst(nsInstanceId);
+ assertTrue(optionalNfvoNsInstance.isEmpty());
+ }
+
+ private void addDummyNsToDatabase(final String nsInstanceId, final State state) {
+ final String nsPackageId = UUID.randomUUID().toString();
+ final NfvoNsInst nfvoNsInst = new NfvoNsInst().nsInstId(nsInstanceId).name("nsName").nsPackageId(nsPackageId)
+ .nsdId("nsdId").nsdInvariantId("nsdId").status(state).statusUpdatedTime(LocalDateTime.now())
+ .globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE);
+ databaseServiceProvider.saveNfvoNsInst(nfvoNsInst);
+ }
+
+ private void mockAaiEndpoints() {
+ final String modelEndpoint = getAaiServiceInstanceEndPoint();
+ final String resourceVersion = "12345";
+
+ final String body =
+ "{\"resource-version\": \"" + resourceVersion + "\",\n\"orchestration-status\": \"Assigned\"}";
+ wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()).willReturn(okJson(body)));
+
+ wireMockServer.stubFor(
+ delete(urlMatching(modelEndpoint + "\\?resource-version=" + resourceVersion)).willReturn(ok()));
+ }
+}
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java
index ff5c2a9105..aa8d8cf10e 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java
@@ -132,7 +132,7 @@ public class MonitorSol003AdapterCreateJobTaskTest extends BaseTest {
assertNull(nsResponseVariable);
final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(),
- CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME);
+ CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME);
final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue();
assertNotNull(problemDetails);
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java
index 14e5b1cafc..b821c85edd 100644
--- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java
+++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java
@@ -75,15 +75,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
public class TerminateNsTaskTest extends BaseTest {
@Autowired
- @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN)
- private RestTemplate etsiCatalogRestTemplate;
-
- @Autowired
@Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN)
private RestTemplate sol003AdapterRestTemplate;
- private MockRestServiceServer mockEtsiCatalogRestServiceServer;
-
private MockRestServiceServer mockSol003AdapterRestServiceServer;
@Autowired
@@ -101,21 +95,14 @@ public class TerminateNsTaskTest extends BaseTest {
public void before() {
wireMockServer.resetAll();
gson = gsonProvider.getGson();
-
- mockEtsiCatalogRestServiceServer =
- MockRestServiceServer.bindTo(etsiCatalogRestTemplate).ignoreExpectOrder(true).build();
mockSol003AdapterRestServiceServer =
MockRestServiceServer.bindTo(sol003AdapterRestTemplate).ignoreExpectOrder(true).build();
-
- etsiCatalogRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
sol003AdapterRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
-
}
@After
public void after() {
wireMockServer.resetAll();
- mockEtsiCatalogRestServiceServer.reset();
}
@Test