AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / VnfInPlaceUpdateTest.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.put;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
29 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockAAIVfModule;
30 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockDBUpdateVfModule;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithDepth;
32 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfByIdWithPriority;
33 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
34 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
35 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetPserverByVnfId;
36 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetGenericVnfsByVnfId;
37 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockSetInMaintFlagByVnfId;
38 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetDefaultCloudRegionByCloudRegionId;
39 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData;
40 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
41 import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicySkip;
42 import static org.openecomp.mso.bpmn.mock.StubResponseAPPC.MockAppcError;
43
44 import java.io.IOException;
45 import java.util.HashMap;
46 import java.util.Map;
47 import java.util.UUID;
48
49 import org.camunda.bpm.engine.test.Deployment;
50 import org.junit.Ignore;
51 import org.junit.Test;
52 import org.openecomp.mso.bpmn.common.WorkflowTest;
53 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
54 import org.openecomp.mso.bpmn.mock.FileUtil;
55 import org.openecomp.mso.client.aai.AAIObjectType;
56 import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri;
57 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
58
59 /**
60  * Unit test cases for VnfInPlaceUpdate.bpmn
61  */
62 public class VnfInPlaceUpdateTest extends WorkflowTest {        
63
64         public VnfInPlaceUpdateTest() throws IOException {
65                 
66         }
67         
68         /**
69          * Sunny day scenario.
70          * 
71          * @throws Exception
72          */
73         @Test   
74
75         
76         @Deployment(resources = {
77                 "process/VnfInPlaceUpdate.bpmn",                
78                 "subprocess/CompleteMsoProcess.bpmn",
79                 "subprocess/FalloutHandler.bpmn",               
80                 "subprocess/BuildingBlock/RainyDayHandler.bpmn",
81                 "subprocess/BuildingBlock/ManualHandling.bpmn",
82                 "subprocess/BuildingBlock/AppCClient.bpmn"
83                 
84                 })
85         public void sunnyDay() throws Exception {
86                                 
87                 logStart();
88                 System.setProperty("mso.config.path", "src/test/resources");
89                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "skask");
90                 wireMockRule.stubFor(get(
91                                 urlPathEqualTo("/aai/v11" + path.build()))
92                                 .willReturn(
93                                         aResponse()
94                                         .withHeader("Content-Type", "application/json")
95                                         .withBodyFile("AAI/mockObject.json")
96                                         .withStatus(200)));
97                 
98                 //
99                 
100                 //AAIResourceUri path1 = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", "RESOURCE");
101                 //wireMockRule.stubFor(put(
102                 //              urlMatching("/aai/v10/query/pservers-fromVnf"))
103                 //              .willReturn(
104                 //                      aResponse()
105                 //                      .withHeader("Content-Type", "application/json")
106                 //                      .withBodyFile("AAI/AAI_pserversByVnfId.json")
107                 //                      .withStatus(200)));
108                 
109                 MockNodeQueryServiceInstanceById("MIS%2F1604%2F0026%2FSW_INTERNET", "GenericFlows/getSIUrlByIdVipr.xml");
110                 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getServiceInstance.xml");
111                 //MockGetGenericVnfById_404("testVnfId");               
112                 MockGetGenericVnfByIdWithDepth("skask", 1, "AAI/AAI_genericVnfsByVnfId.json");          
113                 MockAAIVfModule();              
114                 MockDBUpdateVfModule(); 
115                 MockGetPserverByVnfId("skask", "AAI/AAI_pserverByVnfId.json", 200);             
116                 MockSetInMaintFlagByVnfId("skask", "AAI/AAI_genericVnfsByVnfId.json", 200);
117                 MockGetGenericVnfsByVnfId("skask", "AAI/AAI_genericVnfsByVnfId.json", 200);
118                 MockGetDefaultCloudRegionByCloudRegionId("mdt1", "AAI/AAI_defaultCloudRegionByCloudRegionId.json", 200);
119                 MockPolicySkip();
120                 MockAppcError();                
121                 mockUpdateRequestDB(200, "Database/DBUpdateResponse.xml");
122                 
123                 String businessKey = UUID.randomUUID().toString();
124                 String updaetVnfRequest =
125                         FileUtil.readResourceFile("__files/InfrastructureFlows/VnfInPlaceUpdate_VID_request.json");
126                 
127                 Map<String, Object> variables = setupVariablesSunnyDayVID();
128                 
129                 
130                 TestAsyncResponse asyncResponse = invokeAsyncProcess("VnfInPlaceUpdate",
131                         "v1", businessKey, updaetVnfRequest, variables);
132                 
133                 WorkflowResponse response = receiveResponse(businessKey, asyncResponse, 100000);
134                 
135                 String responseBody = response.getResponse();
136                 System.out.println("Workflow (Synch) Response:\n" + responseBody);              
137         
138                 // TODO add appropriate assertions
139
140                 waitForProcessEnd(businessKey, 100000);
141                 checkVariable(businessKey, "VnfInPlaceUpdateSuccessIndicator", true);
142                 
143                 logEnd();
144         }
145         
146         // Active Scenario
147         private Map<String, Object> setupVariablesSunnyDayVID() {
148                                 Map<String, Object> variables = new HashMap<String, Object>();
149                                 
150                                 variables.put("requestId", "testRequestId");                            
151                                 variables.put("isDebugLogEnabled", "true");                             
152                                 variables.put("serviceInstanceId", "f70e927b-6087-4974-9ef8-c5e4d5847ca4");
153                                 variables.put("vnfId", "skask");                        
154                                                 
155                                 return variables;
156                                 
157                         }
158         
159 }