AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / RollbackVnfTest.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.StubResponseDatabase.MockGetServiceResourcesCatalogData;
39 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
40 import static org.openecomp.mso.bpmn.mock.StubResponsePolicy.MockPolicySkip;
41 import static org.openecomp.mso.bpmn.mock.StubResponseAPPC.MockAppcError;
42
43 import java.io.IOException;
44 import java.util.HashMap;
45 import java.util.Map;
46 import java.util.UUID;
47
48 import org.camunda.bpm.engine.test.Deployment;
49 import org.junit.Assert;
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 RollbackVnf.bpmn
61  */
62 public class RollbackVnfTest extends WorkflowTest {     
63
64         public RollbackVnfTest() throws IOException {
65                 
66         }
67         
68         /**
69          * Sunny day scenario.
70          * 
71          * @throws Exception
72          */
73         @Test   
74
75         
76         @Deployment(resources = {               
77                 "subprocess/RollbackVnf.bpmn",          
78                 "subprocess/BuildingBlock/AppCClient.bpmn"
79                 
80                 })
81         public void sunnyDay() throws Exception {
82                                 
83                 //logStart();
84                 System.setProperty("mso.config.path", "src/test/resources");
85                 AAIResourceUri path = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "skask");
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                 MockGetGenericVnfByIdWithDepth("skask", 1, "VfModularity/GenericVnf.xml");              
97                 MockAAIVfModule();                      
98                 MockGetGenericVnfsByVnfId("skask", "AAI/AAI_genericVnfsByVnfId.json", 200);
99                 MockSetInMaintFlagByVnfId("skask", "AAI/AAI_genericVnfsByVnfId.json", 200);             
100                 MockAppcError();                
101         
102                 String businessKey = UUID.randomUUID().toString();
103                 Map<String, Object> variables = setupVariablesSunnyDayVID();
104                 
105                 invokeSubProcess("RollbackVnf", businessKey,  variables);       
106                 
107                 // TODO add appropriate assertions
108
109                 waitForProcessEnd(businessKey, 10000);
110                 Assert.assertTrue(isProcessEnded(businessKey));
111         //      assertVariables("true", "true", "false", "true", "Success", null);
112                 
113                 //logEnd();
114         }
115         
116         // Active Scenario
117         private Map<String, Object> setupVariablesSunnyDayVID() {
118                                 Map<String, Object> variables = new HashMap<String, Object>();
119                                 
120                                 variables.put("msoRequestId", "testRequestId");                         
121                                 variables.put("isDebugLogEnabled", "true");                             
122                                 variables.put("vnfId", "skask");
123                                 variables.put("rollbackVnfStop", true);
124                                 variables.put("rollbackVnfLock", true);
125                                 variables.put("rollbackQuiesceTraffic", false);
126                                 variables.put("rollbackSetClosedLoopDisabledFlag", true);
127                                 variables.put("rollbackSetVnfInMaintenanceFlag", true);
128                                 variables.put("errorCode", "1005");                                     
129                                                 
130                                 return variables;
131                                 
132                         }
133         
134 }