/*-
* ============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.bpmn.common;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFDelete;
import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFPost;
import static org.onap.so.bpmn.mock.StubResponseVNFAdapter.mockVNFPut;
import static org.onap.so.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.onap.so.BaseIntegrationTest;
import org.onap.so.bpmn.core.WorkflowException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Unit tests for VnfAdapterRestV1.
*/
public class VnfAdapterRestV1IT extends BaseIntegrationTest {
Logger logger = LoggerFactory.getLogger(VnfAdapterRestV1IT.class);
private static final String EOL = "\n";
private final CallbackSet callbacks = new CallbackSet();
private final String CREATE_VF_MODULE_REQUEST = "" + EOL
+ " cloudSiteId" + EOL + " cloudOwner" + 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 + " cloudOwner" + 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 + " cloudOwner" + 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 + " cloudOwner" + EOL
+ " tenantId" + EOL + " vnfId" + EOL
+ " vfModuleId" + EOL + " vfModuleStackId"
+ EOL + " " + EOL + " requestId" + EOL
+ " serviceInstanceId" + EOL + " " + EOL
+ " {{MESSAGE-ID}}" + EOL + " true" + EOL
+ " " + EOL + "" + EOL;
public VnfAdapterRestV1IT() 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
+ " cloudOwner" + 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
public void testCreateVfModuleSuccess() throws Exception {
logStart();
mockVNFPost(wireMockServer, "", 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");
logger.debug("Response:\n{}", response);
assertTrue(response != null && response.contains(""));
assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
logEnd();
}
@Test
public void testUpdateVfModuleSuccess() throws Exception {
logStart();
mockVNFPut(wireMockServer, "/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");
logger.debug("Response:\n{}", response);
assertTrue(response.contains(""));
assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
logEnd();
}
@Test
public void testDeleteVfModuleSuccess() throws Exception {
logStart();
mockVNFDelete(wireMockServer, "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");
logger.debug("Response:\n{}", response);
assertTrue(response.contains(""));
assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
logEnd();
}
@Test
public void testRollbackVfModuleSuccess() throws Exception {
logStart();
mockVNFRollbackDelete(wireMockServer, "/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");
logger.debug("Response:\n{}", response);
assertTrue(response.contains(""));
assertTrue((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
logEnd();
}
@Test
public void testCreateVfModuleException() throws Exception {
logStart();
mockVNFPost(wireMockServer, "", 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);
logger.debug(wfe.toString());
String response = (String) getVariableFromHistory(businessKey, "WorkflowResponse");
logger.debug("Response:\n{}", response);
assertTrue(response.contains(""));
assertFalse((boolean) getVariableFromHistory(businessKey, "VNFREST_SuccessIndicator"));
logEnd();
}
}