/*- * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * 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.openecomp.mso.bpmn.common; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFDelete; import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFPost; import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFPut; import static org.openecomp.mso.bpmn.mock.StubResponseVNFAdapter.mockVNFRollbackDelete; 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.Ignore; import org.junit.Test; import org.openecomp.mso.bpmn.core.WorkflowException; /** * Unit tests for VnfAdapterRestV1. */ public class VnfAdapterRestV1Test extends WorkflowTest { private static final String EOL = "\n"; private final CallbackSet callbacks = new CallbackSet(); private final String CREATE_VF_MODULE_REQUEST = "" + EOL + " cloudSiteId" + EOL + " tenantId" + EOL + " vnfId" + EOL + " vfModuleName" + EOL + " vfModuleId" + EOL + " vnfType" + EOL + " vnfVersion" + EOL + " vfModuleType" + EOL + " volumeGroupId" + EOL + " volumeGroupStackId" + EOL + " baseVfModuleId" + EOL + " baseVfModuleStackId" + EOL + " true" + EOL + " false" + EOL + " true" + EOL + " " + EOL + " " + EOL + " key1" + EOL + " value1" + EOL + " " + EOL + " " + EOL + " key2" + EOL + " value2" + EOL + " " + EOL + " " + EOL + " " + EOL + " requestId" + EOL + " serviceInstanceId" + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + " http://localhost:28080/mso/WorkflowMessage" + EOL + "" + EOL; private final String UPDATE_VF_MODULE_REQUEST = "" + EOL + " cloudSiteId" + EOL + " tenantId" + EOL + " vnfId" + EOL + " vfModuleName" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " vnfType" + EOL + " vnfVersion" + EOL + " vfModuleType" + EOL + " volumeGroupId" + EOL + " volumeGroupStackId" + EOL + " baseVfModuleId" + EOL + " baseVfModuleStackId" + EOL + " true" + EOL + " false" + EOL + " true" + EOL + " " + EOL + " " + EOL + " key1" + EOL + " value1" + EOL + " " + EOL + " " + EOL + " key2" + EOL + " value2" + EOL + " " + EOL + " " + EOL + " " + EOL + " requestId" + EOL + " serviceInstanceId" + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + " http://localhost:28080/mso/WorkflowMessage" + EOL + "" + EOL; private final String DELETE_VF_MODULE_REQUEST = "" + EOL + " cloudSiteId" + EOL + " tenantId" + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " true" + EOL + " " + EOL + " requestId" + EOL + " serviceInstanceId" + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + " http://localhost:28080/mso/WorkflowMessage" + EOL + "" + EOL; private final String ROLLBACK_VF_MODULE_REQUEST = "" + EOL + " {{MESSAGE-ID}}" + EOL + " http://localhost:28080/mso/WorkflowMessage" + EOL + " true" + EOL + " " + EOL + " cloudSiteId" + EOL + " tenantId" + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " " + EOL + " requestId" + EOL + " serviceInstanceId" + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + " true" + EOL + " " + EOL + "" + EOL; public VnfAdapterRestV1Test() throws IOException { callbacks.put("createVfModule", "" + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " true" + EOL + " " + EOL + " " + EOL + " key1" + EOL + " value1" + EOL + " " + EOL + " " + EOL + " key2" + EOL + " value2" + EOL + " " + EOL + " " + EOL + " " + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " true" + EOL + " tenantId" + EOL + " cloudSiteId" + EOL + " " + EOL + " requestId" + EOL + " serviceInstanceId" + EOL + " " + EOL + " messageId" + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + "" + EOL); callbacks.put("updateVfModule", "" + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " vfModuleStackId" + EOL + " " + EOL + " " + EOL + " key1" + EOL + " value1" + EOL + " " + EOL + " " + EOL + " key2" + EOL + " value2" + EOL + " " + EOL + " " + EOL + " {{MESSAGE-ID}}" + EOL + "" + EOL); callbacks.put("deleteVfModule", "" + EOL + " vnfId" + EOL + " vfModuleId" + EOL + " true" + EOL + " {{MESSAGE-ID}}" + EOL + "" + EOL); callbacks.put("rollbackVfModule", "" + EOL + " {{MESSAGE-ID}}" + EOL + " true" + EOL + "" + EOL); callbacks.put("vfModuleException", "" + EOL + " message" + EOL + " category" + EOL + " false" + EOL + " {{MESSAGE-ID}}" + EOL + "" + EOL); } @Test @Deployment(resources = { "subprocess/VnfAdapterRestV1.bpmn" }) public void testCreateVfModuleSuccess() throws Exception { logStart(); mockVNFPost("", 202, "vnfId"); String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312"; String messageId = requestId + "-" + System.currentTimeMillis(); String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId); String businessKey = UUID.randomUUID().toString(); Map variables = new HashMap<>(); variables.put("mso-request-id", requestId); variables.put("isDebugLogEnabled", "true"); variables.put("vnfAdapterRestV1Request", request); invokeSubProcess("vnfAdapterRestV1", businessKey, variables); injectVNFRestCallbacks(callbacks, "createVfModule"); waitForProcessEnd(businessKey, 10000); String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response"); System.out.println("Response:\n" + response); assertTrue(response!=null && response.contains("")); assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator")); logEnd(); } @Test @Deployment(resources = { "subprocess/VnfAdapterRestV1.bpmn" }) public void testUpdateVfModuleSuccess() throws Exception { logStart(); mockVNFPut("/vfModuleId", 202); String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312"; String messageId = requestId + "-" + System.currentTimeMillis(); String request = UPDATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId); String businessKey = UUID.randomUUID().toString(); Map variables = new HashMap<>(); variables.put("mso-request-id", requestId); variables.put("isDebugLogEnabled", "true"); variables.put("vnfAdapterRestV1Request", request); invokeSubProcess("vnfAdapterRestV1", businessKey, variables); injectVNFRestCallbacks(callbacks, "updateVfModule"); waitForProcessEnd(businessKey, 10000); String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response"); System.out.println("Response:\n" + response); assertTrue(response.contains("")); assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator")); logEnd(); } @Test @Deployment(resources = { "subprocess/VnfAdapterRestV1.bpmn" }) public void testDeleteVfModuleSuccess() throws Exception { logStart(); mockVNFDelete("vnfId", "/vfModuleId", 202); String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312"; String messageId = requestId + "-" + System.currentTimeMillis(); String request = DELETE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId); String businessKey = UUID.randomUUID().toString(); Map variables = new HashMap<>(); variables.put("mso-request-id", requestId); variables.put("isDebugLogEnabled", "true"); variables.put("vnfAdapterRestV1Request", request); invokeSubProcess("vnfAdapterRestV1", businessKey, variables); injectVNFRestCallbacks(callbacks, "deleteVfModule"); waitForProcessEnd(businessKey, 10000); String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response"); System.out.println("Response:\n" + response); assertTrue(response.contains("")); assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator")); logEnd(); } @Test @Deployment(resources = { "subprocess/VnfAdapterRestV1.bpmn" }) public void testRollbackVfModuleSuccess() throws Exception { logStart(); mockVNFRollbackDelete("/vfModuleId", 202); String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312"; String messageId = requestId + "-" + System.currentTimeMillis(); String request = ROLLBACK_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId); String businessKey = UUID.randomUUID().toString(); Map variables = new HashMap<>(); variables.put("mso-request-id", requestId); variables.put("isDebugLogEnabled", "true"); variables.put("vnfAdapterRestV1Request", request); invokeSubProcess("vnfAdapterRestV1", businessKey, variables); injectVNFRestCallbacks(callbacks, "rollbackVfModule"); waitForProcessEnd(businessKey, 10000); String response = (String) getVariableFromHistory(businessKey, "vnfAdapterRestV1Response"); System.out.println("Response:\n" + response); assertTrue(response.contains("")); assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator")); logEnd(); } @Test @Deployment(resources = { "subprocess/VnfAdapterRestV1.bpmn" }) public void testCreateVfModuleException() throws Exception { logStart(); mockVNFPost("", 202, "vnfId"); String requestId = "dffbae0e-5588-4bd6-9749-b0f0adb52312"; String messageId = requestId + "-" + System.currentTimeMillis(); String request = CREATE_VF_MODULE_REQUEST.replace("{{MESSAGE-ID}}", messageId); String businessKey = UUID.randomUUID().toString(); Map variables = new HashMap<>(); variables.put("mso-request-id", requestId); variables.put("isDebugLogEnabled", "true"); variables.put("vnfAdapterRestV1Request", request); invokeSubProcess("vnfAdapterRestV1", businessKey, variables); injectVNFRestCallbacks(callbacks, "vfModuleException"); waitForProcessEnd(businessKey, 10000); WorkflowException wfe = (WorkflowException) getVariableFromHistory(businessKey, "WorkflowException"); assertNotNull(wfe); System.out.println(wfe.toString()); String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse"); System.out.println("Response:\n" + response); assertTrue(response.contains("")); assertFalse((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator")); logEnd(); } }