Containerization feature of SO
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / SDNCAdapterRestV2IT.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.onap.so.bpmn.common;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.Map;
31 import java.util.UUID;
32
33 import org.junit.Assert;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.onap.so.BaseIntegrationTest;
37 import org.onap.so.bpmn.mock.FileUtil;
38 import org.onap.so.logger.MsoLogger;
39
40 /**
41  * Unit tests for SDNCAdapterRestV2.bpmn.
42  *
43  * This version of SDNCAdapterRest allows for interim notifications to be sent for
44  * any non-final response received from SDNC.
45  */
46
47 public class SDNCAdapterRestV2IT extends BaseIntegrationTest {
48
49         private final CallbackSet callbacks = new CallbackSet();
50
51         MsoLogger logger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL,SDNCAdapterRestV2IT.class);
52
53
54         /**
55          * Constructor. Insert callbacks.
56          *
57          * @throws IOException
58          */
59         public SDNCAdapterRestV2IT() throws IOException {
60                 String sdncCallbackFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackFinal.json");
61                 String sdncCallbackNonFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackNonFinal.json");
62                 callbacks.put("nonfinal", sdncCallbackNonFinal);
63                 callbacks.put("final", sdncCallbackFinal);
64         }
65
66         /**
67          * Test the success path through the subflow.
68          */
69         @Test
70         @Ignore
71         public void success() throws IOException {
72                 logStart();
73                 mocks();
74
75                 String businessKey = UUID.randomUUID().toString();
76                 Map<String, Object> variables = new HashMap<String, Object>();
77                 variables.put("mso-request-id", "a4383a52-b9de-4bc4-bedf-02f3f9466535");
78                 variables.put("mso-service-instance-id", "fd8bcdbb-b799-43ce-a7ff-ed8f2965a3b5");
79                 variables.put("isDebugLogEnabled", "true");
80                 variables.put("SDNCREST_Request",
81                         FileUtil.readResourceFile("__files/SDNCAdapterRestV2Request.json"));
82                 variables.put("SDNCREST_InterimNotification1",
83                         FileUtil.readResourceFile("__files/SDNCInterimNotification1.json"));
84
85                 invokeSubProcess("SDNCAdapterRestV2", businessKey, variables);
86
87                 injectSDNCRestCallbacks(callbacks, "nonfinal");
88
89                 // First non-final response will have done a notification
90                 Object interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
91                 Assert.assertNotNull(interimNotification);
92
93                 injectSDNCRestCallbacks(callbacks, "nonfinal");
94
95                 // Second non-final response will not have done a notification
96                 interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
97                 Assert.assertNull(interimNotification);
98
99                 injectSDNCRestCallbacks(callbacks, "final");
100
101                 interimNotification = this.getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
102                 Assert.assertNull(interimNotification);
103
104                 waitForProcessEnd(businessKey, 10000);
105
106                 Assert.assertTrue(isProcessEnded(businessKey));
107
108                 logEnd();
109         }
110
111         /**
112          * Defines WireMock stubs needed by these tests.
113          */
114         private void mocks() {
115                 stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc"))
116                         .willReturn(aResponse()
117                                 .withStatus(202)
118                                 .withHeader("Content-Type", "application/json")));
119         }
120 }