314f8e90750c818b11ef2afaff783d2ea6ef8ff4
[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.mockUpdateRequestDB;
33 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
34
35 import java.io.IOException;
36 import java.util.HashMap;
37 import java.util.Map;
38 import java.util.UUID;
39
40 import org.camunda.bpm.engine.test.Deployment;
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.workflow.service.WorkflowResponse;
45 import org.openecomp.mso.bpmn.mock.FileUtil;
46
47 /**
48  * Unit test cases for CreateGenericALaCarteServiceInstance.bpmn
49  */
50 public class CreateGenericALaCarteServiceInstanceTest extends WorkflowTest {
51
52     private final CallbackSet callbacks = new CallbackSet();
53
54     public CreateGenericALaCarteServiceInstanceTest() throws IOException {
55         callbacks.put("assign", FileUtil.readResourceFile("__files/VfModularity/SDNCSITopologyAssignCallback.xml"));
56     }
57
58     /**
59      * Sunny day VID scenario.
60      *
61      * @throws Exception
62      */
63     //@Ignore // File not found - unable to run the test.  Also, Stubs need updating..
64     @Test
65     @Deployment(resources = {
66             "process/CreateGenericALaCarteServiceInstance.bpmn",
67             "subprocess/DoCreateServiceInstance.bpmn",
68             "subprocess/DoCreateServiceInstanceRollback.bpmn",
69             "subprocess/SDNCAdapterV1.bpmn",
70             "subprocess/GenericPutService.bpmn",
71             "subprocess/GenericGetService.bpmn",
72             "subprocess/CompleteMsoProcess.bpmn",
73             "subprocess/FalloutHandler.bpmn"})
74     public void sunnyDayAlaCarte() throws Exception {
75
76         logStart();
77
78         //AAI
79         MockGetCustomer("MCBH-1610", "CreateServiceInstance/createServiceInstance_queryGlobalCustomerId_AAIResponse_Success.xml");
80         MockPutServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "");
81         MockGetServiceInstance("MCBH-1610", "viprsvc", "RaaTest-1-id", "GenericFlows/getServiceInstance.xml");
82         MockNodeQueryServiceInstanceByName("RAATest-1", null);
83         MockNodeQueryServiceInstanceById("RaaTest-1-id", null);
84         //SDNC
85         mockSDNCAdapter(200);
86         //DB
87         mockUpdateRequestDB(200, "DBUpdateResponse.xml");
88
89
90         String businessKey = UUID.randomUUID().toString();
91
92         //String createVfModuleRequest = FileUtil.readResourceFile("__files/SIRequest.json");
93
94         Map<String, String> variables = setupVariables();
95         WorkflowResponse workflowResponse = executeWorkFlow(processEngineRule, "CreateGenericALaCarteServiceInstance", variables);
96         waitForWorkflowToFinish(processEngineRule, workflowResponse.getProcessInstanceID());
97
98         String workflowResp = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "WorkflowResponse");
99         //assertNotNull(workflowResp);
100         System.out.println("Workflow (Synch) Response:\n" + workflowResp);
101         String workflowException = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "WorkflowException");
102         String completionReq = BPMNUtil.getVariable(processEngineRule, "CreateGenericALaCarteServiceInstance", "completionRequest");
103         System.out.println("completionReq:\n" + completionReq);
104         System.out.println("workflowException:\n" + workflowException);
105         assertNotNull(completionReq);
106         assertEquals(null, workflowException);
107
108
109         //injectSDNCCallbacks(callbacks, "assign");
110
111         logEnd();
112     }
113
114     // Success Scenario
115     private Map<String, String> setupVariables() {
116         Map<String, String> variables = new HashMap<>();
117         variables.put("isDebugLogEnabled", "true");
118         variables.put("bpmnRequest", getRequest());
119         variables.put("mso-request-id", "RaaCSIRequestId-1");
120         variables.put("serviceInstanceId", "RaaTest-1-id");
121         return variables;
122     }
123
124     public String getRequest() {
125         String request = "{\"requestDetails\":{\"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\":[]}}}";
126         return request;
127     }
128
129 }