Change the header to SO
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / DoCreateVnfTest.java
1 /*
2  * © 2014 AT&T Intellectual Property. All rights reserved. Used under license from AT&T Intellectual Property.
3  */
4 /*- 
5  * ============LICENSE_START======================================================= 
6  * ONAP - SO 
7  * ================================================================================ 
8  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
9  * ================================================================================ 
10  * Licensed under the Apache License, Version 2.0 (the "License"); 
11  * you may not use this file except in compliance with the License. 
12  * You may obtain a copy of the License at 
13  * 
14  *      http://www.apache.org/licenses/LICENSE-2.0 
15  * 
16  * Unless required by applicable law or agreed to in writing, software 
17  * distributed under the License is distributed on an "AS IS" BASIS, 
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
19  * See the License for the specific language governing permissions and 
20  * limitations under the License. 
21  * ============LICENSE_END========================================================= 
22  */ 
23
24 package org.openecomp.mso.bpmn.infrastructure;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByName_404;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutGenericVnf;
31 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
32 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
33
34 import java.io.IOException;
35 import java.util.HashMap;
36 import java.util.Map;
37 import java.util.UUID;
38
39 import org.camunda.bpm.engine.test.Deployment;
40 import org.junit.Assert;
41 import org.junit.Test;
42 import org.openecomp.mso.bpmn.common.BPMNUtil;
43 import org.openecomp.mso.bpmn.common.WorkflowTest;
44 import org.openecomp.mso.bpmn.common.WorkflowTest.CallbackSet;
45 import org.openecomp.mso.bpmn.mock.FileUtil;
46
47 /**
48  * Unit Test for the DoCreateVnf Flow
49  *
50  */
51 public class DoCreateVnfTest extends WorkflowTest {
52
53         private String createVnfInfraRequest;
54         private final CallbackSet callbacks = new CallbackSet();
55
56
57         public DoCreateVnfTest() throws IOException {
58                 createVnfInfraRequest = FileUtil.readResourceFile("__files/InfrastructureFlows/CreateVnfInfraRequest.json");
59                 callbacks.put("assign", FileUtil.readResourceFile(
60                                 "__files/VfModularity/SDNCTopologyAssignCallback.xml"));
61                 callbacks.put("activate", FileUtil.readResourceFile(
62                                 "__files/VfModularity/SDNCTopologyActivateCallback.xml"));
63         }
64
65         @Test
66         @Deployment(resources = {"subprocess/GenericGetService.bpmn", "subprocess/GenericGetVnf.bpmn", "subprocess/GenericPutVnf.bpmn", "subprocess/SDNCAdapterV1.bpmn", "subprocess/DoCreateVnf.bpmn"})
67         public void testDoCreateVnfInfra_success() throws Exception{
68
69                 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
70                 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
71                 MockGetGenericVnfByName_404("testVnfName123");
72                 MockPutGenericVnf("testVnfId123");
73                 mockSDNCAdapter("/SDNCAdapter", "vnf-type>STMTN", 200, "VfModularity/StandardSDNCSynchResponse.xml");
74                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
75
76                 String businessKey = UUID.randomUUID().toString();
77                 Map<String, Object> variables = new HashMap<String, Object>();
78                 setVariablesSuccess(variables, createVnfInfraRequest, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
79                 invokeSubProcess("DoCreateVnf", businessKey, variables);
80
81                 waitForProcessEnd(businessKey, 10000);
82
83                 Assert.assertTrue(isProcessEnded(businessKey));
84                 assertVariables("true", "true", "false", "true", "Success", null);
85         }
86
87         private void assertVariables(String exSIFound, String exSISucc, String exVnfFound, String exVnfSucc, String exResponse, String exWorkflowException) {
88                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoCreateVnf", "SavedWorkflowException1");
89
90                 assertEquals(exWorkflowException, workflowException);
91         }
92
93         private void setVariablesSuccess(Map<String, Object> variables, String request, String requestId, String siId) {
94                 variables.put("isDebugLogEnabled", "true");
95                 //variables.put("bpmnRequest", request);
96                 variables.put("mso-request-id", requestId);
97                 variables.put("serviceInstanceId",siId);
98                 variables.put("vnfName", "testVnfName123");
99                 variables.put("disableRollback", "true");
100                 variables.put("requestId", requestId);
101                 variables.put("testVnfId","testVnfId123");
102                 variables.put("vnfType", "STMTN");
103                 variables.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
104                 String vnfModelInfo = "{ "+ "\"modelType\": \"vnf\"," +
105                                 "\"modelInvariantUuid\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\"," +
106                                 "\"modelUuid\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," +
107                                 "\"modelName\": \"vSAMP12\"," +
108                                 "\"modelVersion\": \"1.0\"," +
109                                 "\"modelCustomizationUuid\": \"MODEL-ID-1234\"," +
110                                 "}";
111                 variables.put("vnfModelInfo", vnfModelInfo);
112
113                 String cloudConfiguration = "{ " +
114                                 "\"lcpCloudRegionId\": \"mdt1\"," +
115                                 "\"tenantId\": \"88a6ca3ee0394ade9403f075db23167e\"" + "}";
116                 variables.put("cloudConfiguration", cloudConfiguration);
117                 
118                 String serviceModelInfo = "{ "+ "\"modelType\": \"service\"," +
119                                 "\"modelInvariantUuid\": \"995256d2-5a33-55df-13ab-12abad84e7ff\"," +
120                                 "\"modelUuid\": \"ab6478e5-ea33-3346-ac12-ab121484a3fe\"," +
121                                 "\"modelName\": \"ServicevSAMP12\"," +
122                                 "\"modelVersion\": \"1.0\"," +
123                                 "}";
124                 variables.put("serviceModelInfo", serviceModelInfo);
125                 variables.put("globalSubscriberId", "MSO-1610");
126         }
127
128 }