AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / VnfConfigUpdateTest.java
1 /*- 
2  * ============LICENSE_START======================================================= 
3  * ONAP - SO 
4  * ================================================================================ 
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. 
6  * ================================================================================ 
7  * Licensed under the Apache License, Version 2.0 (the "License"); 
8  * you may not use this file except in compliance with the License. 
9  * You may obtain a copy of the License at 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
13  * Unless required by applicable law or agreed to in writing, software 
14  * distributed under the License is distributed on an "AS IS" BASIS, 
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
16  * See the License for the specific language governing permissions and 
17  * limitations under the License. 
18  * ============LICENSE_END========================================================= 
19  */ 
20
21 package org.openecomp.mso.bpmn.infrastructure;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockAAIVfModule;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDBUpdateVfModule;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetPserverByVnfId;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfsByVnfId;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockSetInMaintFlagByVnfId;
34 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData;
35 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
36 import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicySkip;
37 import static org.openecomp.mso.bpmn.mock.StubResponseAPPC.MockAppcError;
38
39 import java.io.IOException;
40 import java.util.HashMap;
41 import java.util.Map;
42 import java.util.UUID;
43
44 import org.camunda.bpm.engine.test.Deployment;
45 import org.junit.Ignore;
46 import org.junit.Test;
47 import org.openecomp.mso.bpmn.common.WorkflowTest;
48 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
49 import org.openecomp.mso.bpmn.mock.FileUtil;
50 import org.openecomp.mso.client.aai.AAIObjectType;
51 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
52 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
53
54 /**
55  * Unit test cases for VnfConfigUpdate.bpmn
56  */
57 public class VnfConfigUpdateTest extends WorkflowTest { 
58
59         public VnfConfigUpdateTest() throws IOException {
60                 
61         }
62         
63         /**
64          * Sunny day scenario.
65          * 
66          * @throws Exception
67          */
68         @Test   
69         @Ignore // 1802 merge
70         @Deployment(resources = {
71                 "process/VnfConfigUpdate.bpmn",
72                 "subprocess/RollbackVnf.bpmn",
73                 "subprocess/CompleteMsoProcess.bpmn",
74                 "subprocess/FalloutHandler.bpmn",               
75                 "subprocess/BuildingBlock/RainyDayHandler.bpmn",
76                 "subprocess/BuildingBlock/ManualHandling.bpmn",
77                 "subprocess/BuildingBlock/AppCClient.bpmn"
78                 
79                 })
80         public void sunnyDay() throws Exception {
81                                 
82                 logStart();
83                 
84                 System.setProperty("mso.config.path", "src/test/resources");
85                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "comx9906v");
86                 wireMockRule.stubFor(get(
87                                 urlPathEqualTo("/aai/v11" + path.build()))
88                                 .willReturn(
89                                         aResponse()
90                                         .withHeader("Content-Type", "application/json")
91                                         .withBodyFile("AAI/mockObject.json")
92                                         .withStatus(200)));
93                 
94                 
95                 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlByIdVipr.xml");
96                 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
97                 //MockGetGenericVnfById_404("testVnfId");               
98                 MockGetGenericVnfByIdWithDepth("comx9906v", 1, "AAI/AAI_genericVnfsByVnfIdVnfConfig.json");                     
99                 MockAAIVfModule();              
100                 MockDBUpdateVfModule(); 
101                 MockGetPserverByVnfId("comx9906v", "AAI/AAI_pserverByVnfId.json", 200);
102                 MockGetGenericVnfsByVnfId("comx9906v", "AAI/AAI_genericVnfsByVnfIdVnfConfig.json", 200);
103                 MockSetInMaintFlagByVnfId("comx9906v", "AAI/AAI_genericVnfsByVnfIdVnfConfig.json", 200);
104                 MockPolicySkip();
105                 MockAppcError();                
106                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
107                 
108                 String businessKey = UUID.randomUUID().toString();
109                 String updaetVnfRequest =
110                         FileUtil.readResourceFile("__files/InfrastructureFlows/ConfigVnf_VID_request.json");
111                 
112                 Map<String, Object> variables = setupVariablesSunnyDayVID();
113                 
114                 
115                 TestAsyncResponse asyncResponse = invokeAsyncProcess("VnfConfigUpdate",
116                         "v1", businessKey, updaetVnfRequest, variables);
117                 
118                 WorkflowResponse response = receiveResponse(businessKey, asyncResponse, 10000);
119                 
120                 String responseBody = response.getResponse();
121                 System.out.println("Workflow (Synch) Response:\n" + responseBody);              
122         
123                 // TODO add appropriate assertions
124
125                 waitForProcessEnd(businessKey, 1000000);
126                 checkVariable(businessKey, "VnfConfigUpdateSuccessIndicator", true);
127                 
128                 logEnd();
129         }
130         
131         // Active Scenario
132         private Map<String, Object> setupVariablesSunnyDayVID() {
133                                 Map<String, Object> variables = new HashMap<String, Object>();
134                                 
135                                 variables.put("requestId", "testRequestId");                            
136                                 variables.put("isDebugLogEnabled", "true");                             
137                                 variables.put("serviceInstanceId", "f70e927b-6087-4974-9ef8-c5e4d5847ca4");
138                                 variables.put("vnfId", "comx9906v");
139                                 variables.put("vnfType", "vSAMP12");                                    
140                                 variables.put("serviceType", "MOG");    
141                                                 
142                                 return variables;
143                                 
144                         }
145         
146 }