AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / CreateGenericALaCarteServiceInstanceTest.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 org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.openecomp.mso.bpmn.common.BPMNUtil.executeWorkFlow;
26 import static org.openecomp.mso.bpmn.common.BPMNUtil.waitForWorkflowToFinish;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetCustomer;
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.MockNodeQueryServiceInstanceByName;
31 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
32 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.MockGetServiceResourcesCatalogData;
33 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
34 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
35
36 import java.io.IOException;
37 import java.util.HashMap;
38 import java.util.Map;
39 import java.util.UUID;
40
41 import org.camunda.bpm.engine.test.Deployment;
42 import org.junit.Ignore;
43 import org.junit.Test;
44 import org.openecomp.mso.bpmn.common.BPMNUtil;
45 import org.openecomp.mso.bpmn.common.WorkflowTest;
46 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowResponse;
47 import org.openecomp.mso.bpmn.mock.FileUtil;
48
49 /**
50  * Unit test cases for CreateGenericALaCarteServiceInstance.bpmn
51  */
52 public class CreateGenericALaCarteServiceInstanceTest extends WorkflowTest {
53
54         private final CallbackSet callbacks = new CallbackSet();
55
56         public CreateGenericALaCarteServiceInstanceTest() throws IOException {
57                 callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCSITopologyAssignCallback.xml"));
58         }
59
60         /**
61          * Sunny day VID scenario.
62          *
63          * @throws Exception
64          */
65         //@Ignore // File not found - unable to run the test.  Also, Stubs need updating..
66         @Test
67         @Ignore // 1802 merge
68         @Deployment(resources = {
69                         "process/CreateGenericALaCarteServiceInstance.bpmn",
70                         "subprocess/BuildingBlock/DecomposeService.bpmn",
71                         "subprocess/DoCreateServiceInstance.bpmn",
72                         "subprocess/DoCreateServiceInstanceRollback.bpmn",
73                         "subprocess/SDNCAdapterV1.bpmn",
74                         "subprocess/GenericPutService.bpmn",
75                         "subprocess/GenericGetService.bpmn",
76                         "subprocess/CompleteMsoProcess.bpmn",
77                         "subprocess/FalloutHandler.bpmn" })
78         public void sunnyDayAlaCarte() throws Exception {
79
80                 logStart();
81
82                 //AAI
83                 MockGetCustomer("MCBH-1610", "CreateServiceInstance/createServiceInstance_queryGlobalCustomerId_AAIResponse_Success.xml");
84                 MockPutServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "");
85                 MockGetServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "GenericFlows/getServiceInstance.xml");
86                 MockNodeQueryServiceInstanceByName("RAATest-1", null);
87                 MockNodeQueryServiceInstanceById("RaaTest-1-id", null);
88                 //SDNC
89                 mockSDNCAdapter(200);
90                 //DB
91                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef","2","/VIPR/getCatalogServiceResourcesData.json");
92                 mockUpdateRequestDB(200, "DBUpdateResponse.xml");
93                 MockGetServiceResourcesCatalogData("uuid-miu-svc-011-abcdef","InfrastructureFlows/DoCreateServiceInstance_request.json");
94
95
96                 String businessKey = UUID.randomUUID().toString();
97
98                 //String createVfModuleRequest = FileUtil.readResourceFile("__files/SIRequest.json");
99
100                 Map<String, String> variables = setupVariables();
101                 WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateGenericALaCarteServiceInstance", variables);
102                 waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
103
104                 String workflowResp = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "WorkflowResponse");
105                 //assertNotNull(workflowResp);
106                 System.out.println("Workflow (Synch) Response:\n" + workflowResp);
107                 String workflowException = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "WorkflowException");
108                 String completionReq = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "completionRequest");
109                 System.out.println("completionReq:\n" + completionReq);
110                 System.out.println("workflowException:\n" + workflowException);
111                 assertNotNull(completionReq);
112                 assertEquals(null, workflowException);
113
114
115                 //injectSDNCCallbacks(callbacks, "assign");
116
117                 logEnd();
118         }
119
120         // Success Scenario
121         private Map<String, String> setupVariables() {
122                 Map<String, String> variables = new HashMap<>();
123                 variables.put("isDebugLogEnabled", "true");
124                 variables.put("bpmnRequest", getRequest());
125                 variables.put("mso-request-id", "RaaCSIRequestId-1");
126                 variables.put("serviceInstanceId","RaaTest-1-id");
127                 variables.put("sdncVersion", "1802");
128                 variables.put("serviceInstanceName", "some-junk-name");
129                 return variables;
130         }
131
132         public String getRequest() {
133                 String request = "{\"requestDetails\":{\"project\": {\"projectName\": \"projectName\"},\"owningEntity\": {\"owningEntityId\": \"randomStrings\",\"owningEntityName\": \"randomStrings\"},\"modelInfo\":{\"modelType\":\"service\",\"modelInvariantUuid\":\"uuid-miu-svc-011-abcdef\",\"modelVersionUuid\":\"ASDC_TOSCA_UUID\",\"modelName\":\"SIModelName1\",\"modelVersion\":\"2\"},\"subscriberInfo\":{\"globalSubscriberId\":\"MCBH-1610\",\"subscriberName\":\"Kaneohe\"},\"requestInfo\":{\"instanceName\":\"RAATest-1\",\"source\":\"VID\",\"suppressRollback\":\"true\",\"productFamilyId\":\"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\"},\"cloudConfiguration\":{\"lcpCloudRegionId\":\"mdt1\",\"tenantId\":\"8b1df54faa3b49078e3416e21370a3ba\"},\"requestParameters\":{\"subscriptionServiceType\":\"viprsvc\",\"aLaCarte\":\"false\",\"userParams\":[]}}}";
134                 return request;
135         }
136
137 }