AT&T 1712 and 1802 release code
[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.core.domain.VnfResource;
46 import org.openecomp.mso.bpmn.mock.FileUtil;
47
48 /**
49  * Unit Test for the DoCreateVnf Flow
50  *
51  */
52 public class DoCreateVnfTest extends WorkflowTest {
53
54         private String createVnfInfraRequest;
55         private final CallbackSet callbacks = new CallbackSet();
56
57
58         public DoCreateVnfTest() throws IOException {
59                 createVnfInfraRequest = FileUtil.readResourceFile("__files/InfrastructureFlows/CreateVnfInfraRequest.json");
60                 callbacks.put("assign", FileUtil.readResourceFile(
61                                 "__files/VfModularity/SDNCTopologyAssignCallback.xml"));
62                 callbacks.put("activate", FileUtil.readResourceFile(
63                                 "__files/VfModularity/SDNCTopologyActivateCallback.xml"));
64         }
65
66         @Test
67         @Deployment(resources = {"subprocess/GenericGetService.bpmn", "subprocess/GenericGetVnf.bpmn", "subprocess/GenericPutVnf.bpmn", "subprocess/SDNCAdapterV1.bpmn", "subprocess/DoCreateVnf.bpmn"})
68         public void testDoCreateVnfInfra_success() throws Exception{
69
70                 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
71                 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
72                 MockGetGenericVnfByName_404("testVnfName123");
73                 MockPutGenericVnf("testVnfId123");
74                 mockSDNCAdapter("/SDNCAdapter", "vnf-type>STMTN", 200, "VfModularity/StandardSDNCSynchResponse.xml");
75                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
76
77                 String businessKey = UUID.randomUUID().toString();
78                 Map<String, Object> variables = new HashMap<>();
79                 setVariablesSuccess(variables, createVnfInfraRequest, "testRequestId123", "MIS%2F1604%2F0026%2FSW_INTERNET");
80                 invokeSubProcess("DoCreateVnf", businessKey, variables);
81
82                 waitForProcessEnd(businessKey, 10000);
83
84                 Assert.assertTrue(isProcessEnded(businessKey));
85                 assertVariables("true", "true", "false", "true", "Success", null);
86         }
87
88         private void assertVariables(String exSIFound, String exSISucc, String exVnfFound, String exVnfSucc, String exResponse, String exWorkflowException) {
89                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoCreateVnf", "SavedWorkflowException1");
90
91                 assertEquals(exWorkflowException, workflowException);
92         }
93
94         private void setVariablesSuccess(Map<String, Object> variables, String request, String requestId, String siId) {
95                 variables.put("isDebugLogEnabled", "true");
96                 //variables.put("bpmnRequest", request);
97                 variables.put("mso-request-id", requestId);
98                 variables.put("serviceInstanceId",siId);
99                 variables.put("vnfName", "testVnfName123");
100                 variables.put("disableRollback", "true");
101                 variables.put("requestId", requestId);
102                 variables.put("testVnfId","testVnfId123");
103                 variables.put("vnfType", "STMTN");
104                 variables.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
105                 String vnfModelInfo = "{ "+ "\"modelType\": \"vnf\"," +
106                                 "\"modelInvariantUuid\": \"ff5256d2-5a33-55df-13ab-12abad84e7ff\"," +
107                                 "\"modelUuid\": \"fe6478e5-ea33-3346-ac12-ab121484a3fe\"," +
108                                 "\"modelName\": \"vSAMP12\"," +
109                                 "\"modelVersion\": \"1.0\"," +
110                                 "\"modelCustomizationUuid\": \"MODEL-ID-1234\"," +
111                                 "}";
112                 variables.put("vnfModelInfo", vnfModelInfo);
113
114                 String cloudConfiguration = "{ " +
115                                 "\"lcpCloudRegionId\": \"mdt1\"," +
116                                 "\"tenantId\": \"88a6ca3ee0394ade9403f075db23167e\"" + "}";
117                 variables.put("cloudConfiguration", cloudConfiguration);
118                 
119                 String serviceModelInfo = "{ "+ "\"modelType\": \"service\"," +
120                                 "\"modelInvariantUuid\": \"995256d2-5a33-55df-13ab-12abad84e7ff\"," +
121                                 "\"modelUuid\": \"ab6478e5-ea33-3346-ac12-ab121484a3fe\"," +
122                                 "\"modelName\": \"ServicevSAMP12\"," +
123                                 "\"modelVersion\": \"1.0\"," +
124                                 "}";
125                 variables.put("serviceModelInfo", serviceModelInfo);
126                 variables.put("globalSubscriberId", "MSO-1610");
127                 VnfResource vnfResource = new VnfResource();
128                 variables.put("vnfResourceDecomposition", vnfResource);
129         }
130
131 }