bf3fefdf9c36f99f4f91f6d39b634168ba7de7fb
[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  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.common;
24
25 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
28
29 import java.io.IOException;
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.UUID;
33
34 import org.junit.Assert;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.onap.so.BaseIntegrationTest;
38 import org.onap.so.bpmn.mock.FileUtil;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
41
42 /**
43  * Unit tests for SDNCAdapterRestV2.bpmn.
44  *
45  * This version of SDNCAdapterRest allows for interim notifications to be sent for
46  * any non-final response received from SDNC.
47  */
48
49 public class SDNCAdapterRestV2IT extends BaseIntegrationTest {
50
51         private final CallbackSet callbacks = new CallbackSet();
52
53         Logger logger = LoggerFactory.getLogger(SDNCAdapterRestV2IT.class);
54
55
56         /**
57          * Constructor. Insert callbacks.
58          *
59          * @throws IOException
60          */
61         public SDNCAdapterRestV2IT() throws IOException {
62                 String sdncCallbackFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackFinal.json");
63                 String sdncCallbackNonFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackNonFinal.json");
64                 callbacks.put("nonfinal", sdncCallbackNonFinal);
65                 callbacks.put("final", sdncCallbackFinal);
66         }
67
68         /**
69          * Test the success path through the subflow.
70          */
71         @Test
72         @Ignore
73         public void success() throws IOException {
74                 logStart();
75                 mocks();
76
77                 String businessKey = UUID.randomUUID().toString();
78                 Map<String, Object> variables = new HashMap<String, Object>();
79                 variables.put("mso-request-id", "a4383a52-b9de-4bc4-bedf-02f3f9466535");
80                 variables.put("mso-service-instance-id", "fd8bcdbb-b799-43ce-a7ff-ed8f2965a3b5");
81                 variables.put("isDebugLogEnabled", "true");
82                 variables.put("SDNCREST_Request",
83                         FileUtil.readResourceFile("__files/SDNCAdapterRestV2Request.json"));
84                 variables.put("SDNCREST_InterimNotification1",
85                         FileUtil.readResourceFile("__files/SDNCInterimNotification1.json"));
86
87                 invokeSubProcess("SDNCAdapterRestV2", businessKey, variables);
88
89                 injectSDNCRestCallbacks(callbacks, "nonfinal");
90
91                 // First non-final response will have done a notification
92                 Object interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
93                 Assert.assertNotNull(interimNotification);
94
95                 injectSDNCRestCallbacks(callbacks, "nonfinal");
96
97                 // Second non-final response will not have done a notification
98                 interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
99                 Assert.assertNull(interimNotification);
100
101                 injectSDNCRestCallbacks(callbacks, "final");
102
103                 interimNotification = this.getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
104                 Assert.assertNull(interimNotification);
105
106                 waitForProcessEnd(businessKey, 10000);
107
108                 Assert.assertTrue(isProcessEnded(businessKey));
109
110                 logEnd();
111         }
112
113         /**
114          * Defines WireMock stubs needed by these tests.
115          */
116         private void mocks() {
117                 wireMockServer.stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc"))
118                         .willReturn(aResponse()
119                                 .withStatus(202)
120                                 .withHeader("Content-Type", "application/json")));
121         }
122 }