f6c5d904bd3772f02c0feadc798f384d7e8fef92
[so.git] / bpmn / MSOInfrastructureBPMN / src / test / java / org / openecomp / mso / bpmn / infrastructure / DoCreateServiceInstanceTest.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.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetCustomer;
25 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockGetServiceInstance;
26 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceById;
27 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockNodeQueryServiceInstanceByName;
28 import static org.openecomp.mso.bpmn.mock.StubResponseAAI.MockPutServiceInstance;
29 import static org.openecomp.mso.bpmn.mock.StubResponseDatabase.mockUpdateRequestDB;
30 import static org.openecomp.mso.bpmn.mock.StubResponseSDNCAdapter.mockSDNCAdapter;
31
32 import java.io.IOException;
33 import java.util.HashMap;
34 import java.util.Map;
35 import java.util.UUID;
36
37 import org.camunda.bpm.engine.test.Deployment;
38 import org.junit.Assert;
39 import org.junit.Test;
40 import org.openecomp.mso.bpmn.common.BPMNUtil;
41 import org.openecomp.mso.bpmn.common.WorkflowTest;
42
43 /**
44  * Unit test cases for DoCreateServiceInstance.bpmn
45  */
46 public class DoCreateServiceInstanceTest extends WorkflowTest {
47         private static final String EOL = "\n";
48         private final CallbackSet callbacks = new CallbackSet();
49         private final String sdncAdapterCallback =
50                         "<output xmlns=\"com:att:sdnctl:l3api\">" + EOL +
51                         "  <svc-request-id>((REQUEST-ID))</svc-request-id>" + EOL +
52                         "  <ack-final-indicator>Y</ack-final-indicator>" + EOL +
53                         "</output>" + EOL;
54                 
55         public DoCreateServiceInstanceTest() throws IOException {
56                 callbacks.put("assign", sdncAdapterCallback);
57         }
58                 
59         /**
60          * Sunny day VID scenario.
61          *
62          * @throws Exception
63          */
64         //@Ignore // File not found - unable to run the test.  Also, Stubs need updating..
65         @Test
66         @Deployment(resources = {
67                         "subprocess/DoCreateServiceInstance.bpmn",
68                         "subprocess/SDNCAdapterV1.bpmn",
69                         "subprocess/GenericGetService.bpmn",
70                         "subprocess/GenericPutService.bpmn",
71                         "subprocess/CompleteMsoProcess.bpmn",
72                         "subprocess/DoCreateServiceInstanceRollback.bpmn",
73                         "subprocess/FalloutHandler.bpmn" })
74         public void sunnyDay() throws Exception {
75
76                 logStart();
77
78                 //AAI
79                 MockGetCustomer("MCBH-1610", "CreateServiceInstance/createServiceInstance_queryGlobalCustomerId_AAIResponse_Success.xml");
80                 MockPutServiceInstance("MCBH-1610", "viprsvc", "RaaTest-si-id", "");
81                 MockGetServiceInstance("MCBH-1610", "viprsvc", "RaaTest-si-id", "GenericFlows/getServiceInstance.xml");
82                 MockNodeQueryServiceInstanceByName("RAATest-si", "");
83                 
84                 MockNodeQueryServiceInstanceById("RaaTest-si-id", "");
85                 MockGetServiceInstance("SDN-ETHERNET-INTERNET", "123456789", "MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getSINoRelations.xml");
86                 MockNodeQueryServiceInstanceById("MIS%252F1604%252F0026%252FSW_INTERNET", "GenericFlows/getSIUrlById.xml");
87                 //SDNC
88                 mockSDNCAdapter(200);
89                 //DB
90                 mockUpdateRequestDB(200, "DBUpdateResponse.xml");
91                 String businessKey = UUID.randomUUID().toString();
92
93                 Map<String, Object> variables = new HashMap<>();
94                 setupVariables(variables);
95                 invokeSubProcess("DoCreateServiceInstance", businessKey, variables);
96                 injectSDNCCallbacks(callbacks, "assign");
97                 waitForProcessEnd(businessKey, 10000);
98                 Assert.assertTrue(isProcessEnded(businessKey));
99                 String workflowException = BPMNUtil.getVariable(processEngineRule, "DoCreateServiceInstance", "WorkflowException");
100                 System.out.println("workflowException:\n" + workflowException);
101                 assertEquals(null, workflowException);
102
103                 logEnd();
104         }
105
106         // Success Scenario
107         private void setupVariables(Map<String, Object> variables) {
108                 variables.put("mso-request-id", "RaaDSITest1");
109                 variables.put("isDebugLogEnabled", "true");
110                 variables.put("msoRequestId", "RaaDSITestRequestId-1");
111                 variables.put("serviceInstanceId","RaaTest-si-id");
112                 variables.put("serviceModelInfo", "{\"modelType\":\"service\",\"modelInvariantUuid\":\"uuid-miu-svc-011-abcdef\",\"modelVersionUuid\":\"ASDC_TOSCA_UUID\",\"modelName\":\"SIModelName1\",\"modelVersion\":\"2\"}");
113                 variables.put("productFamilyId", "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb");
114                 variables.put("globalSubscriberId", "MCBH-1610");
115                 variables.put("subscriptionServiceType", "viprsvc");
116                 variables.put("instanceName", "RAATest-1");
117         }
118 }