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