package org.openecomp.mso.bpmn.infrastructure;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.containing;
import static com.github.tomakehurst.wiremock.client.WireMock.delete;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
import static org.openecomp.mso.bpmn.common.DeleteAAIVfModuleTest.MockAAIDeleteVfModule;
import static org.openecomp.mso.bpmn.common.DeleteAAIVfModuleTest.MockAAIGenericVnfSearch;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.camunda.bpm.engine.test.Deployment;
import org.junit.Test;
import org.openecomp.mso.bpmn.common.WorkflowTest;
import org.openecomp.mso.bpmn.core.WorkflowException;
public class DoDeleteVfModuleFromVnfTest extends WorkflowTest {
private final CallbackSet callbacks = new CallbackSet();
private static final String EOL = "\n";
private final String vnfAdapterDeleteCallback =
"" + EOL +
" a27ce5a9-29c4-4c22-a017-6615ac73c721" + EOL +
" 973ed047-d251-4fb9-bf1a-65b8949e0a73" + EOL +
" true" + EOL +
" {{MESSAGE-ID}}" + EOL +
"" + EOL;
private final String vnfAdapterDeleteCallbackFail =
"" + EOL +
" Error processing request to VNF-Async. Not Found." + EOL +
" INTERNAL" + EOL +
" false" + EOL +
" {{MESSAGE-ID}}" + EOL +
"" + EOL;
private final String sdncAdapterDeleteCallback =
"" + EOL;
public DoDeleteVfModuleFromVnfTest() throws IOException {
callbacks.put("deactivate", sdncAdapterDeleteCallback);
callbacks.put("unassign", sdncAdapterDeleteCallback);
callbacks.put("vnfDelete", vnfAdapterDeleteCallback);
callbacks.put("vnfDeleteFail", vnfAdapterDeleteCallbackFail);
}
private final String wfeString = "WorkflowException";
@Test
@Deployment(resources = {
"subprocess/DoDeleteVfModuleFromVnf.bpmn",
"subprocess/SDNCAdapterV1.bpmn",
"subprocess/VnfAdapterRestV1.bpmn",
"subprocess/DeleteAAIVfModule.bpmn"
})
public void TestDoDeleteVfModuleFromVnfSuccess() {
// delete the Base Module and Generic Vnf
// vnf-id=a27ce5a9-29c4-4c22-a017-6615ac73c721, vf-module-id=973ed047-d251-4fb9-bf1a-65b8949e0a73
String request =
"" + EOL +
" " + EOL +
" DELETE_VF_MODULE" + EOL +
" PORTAL" + EOL +
" " + EOL +
" " + EOL +
" a27ce5a9-29c4-4c22-a017-6615ac73c721" + EOL +
" STMTN5MMSC21" + EOL +
" asc_heat-int" + EOL +
" 973ed047-d251-4fb9-bf1a-65b8949e0a73" + EOL +
" STMTN5MMSC21-MMSC::module-0-0" + EOL +
" 00000000-0000-0000-0000-000000000000" + EOL +
" SDN-ETHERNET-INTERNET" + EOL +
" fba1bd1e195a404cacb9ce17a9b2b421" + EOL +
" pending-delete" + EOL +
" RDM2WAGPLCP" + EOL +
" " + EOL +
" " + EOL +
"" + EOL;
logStart();
MockDoDeleteVfModule_SDNCSuccess();
MockDoDeleteVfModule_DeleteVNFSuccess();
MockAAIGenericVnfSearch();
MockAAIDeleteVfModule();
String businessKey = UUID.randomUUID().toString();
Map variables = new HashMap();
variables.put("isDebugLogEnabled","true");
variables.put("mso-request-id", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
variables.put("msoRequestId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
variables.put("serviceInstanceId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
variables.put("vnfId", "a27ce5a9-29c4-4c22-a017-6615ac73c721");
variables.put("vfModuleId", "973ed047-d251-4fb9-bf1a-65b8949e0a73");
variables.put("lcpCloudRegionId", "RDM2WAGPLCP");
variables.put("tenantId", "fba1bd1e195a404cacb9ce17a9b2b421");
variables.put("sdncVersion", "1707");
invokeSubProcess("DoDeleteVfModuleFromVnf", businessKey, variables);
injectSDNCCallbacks(callbacks, "deactivate");
injectVNFRestCallbacks(callbacks, "vnfDelete");
//waitForRunningProcessCount("vnfAdapterDeleteV1", 0, 120000);
injectSDNCCallbacks(callbacks, "unassign");
waitForProcessEnd(businessKey, 10000);
WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, wfeString);
checkVariable(businessKey, wfeString, null);
if (wfe != null) {
System.out.println("TestDoDeleteVfModuleSuccess: ErrorCode=" + wfe.getErrorCode() +
", ErrorMessage=" + wfe.getErrorMessage());
}
logEnd();
}
// start of mocks used locally and by other VF Module unit tests
public static void MockDoDeleteVfModule_SDNCSuccess() {
stubFor(post(urlEqualTo("/SDNCAdapter"))
.withRequestBody(containing("SvcAction>deactivate"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBodyFile("DeleteGenericVNFV1/sdncAdapterResponse.xml")));
stubFor(post(urlEqualTo("/SDNCAdapter"))
.withRequestBody(containing("SvcAction>unassign"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBodyFile("DeleteGenericVNFV1/sdncAdapterResponse.xml")));
}
public static void MockDoDeleteVfModule_DeleteVNFSuccess() {
stubFor(delete(urlMatching("/vnfs/v1/vnfs/.*/vf-modules/.*"))
.willReturn(aResponse()
.withStatus(202)
.withHeader("Content-Type", "application/xml")));
stubFor(delete(urlMatching("/vnfs/v1/volume-groups/78987"))
.willReturn(aResponse()
.withStatus(202)
.withHeader("Content-Type", "application/xml")));
}
}