2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.bpmn.common;
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;
30 import java.io.IOException;
31 import java.util.HashMap;
33 import java.util.UUID;
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;
44 * Unit tests for SDNCAdapterRestV2.bpmn.
46 * This version of SDNCAdapterRest allows for interim notifications to be sent for
47 * any non-final response received from SDNC.
50 public class SDNCAdapterRestV2IT extends BaseIntegrationTest {
52 private final CallbackSet callbacks = new CallbackSet();
54 Logger logger = LoggerFactory.getLogger(SDNCAdapterRestV2IT.class);
58 * Constructor. Insert callbacks.
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);
70 * Test the success path through the subflow.
74 public void success() throws IOException {
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"));
88 invokeSubProcess("SDNCAdapterRestV2", businessKey, variables);
90 injectSDNCRestCallbacks(callbacks, "nonfinal");
92 // First non-final response will have done a notification
93 Object interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
94 Assert.assertNotNull(interimNotification);
96 injectSDNCRestCallbacks(callbacks, "nonfinal");
98 // Second non-final response will not have done a notification
99 interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
100 Assert.assertNull(interimNotification);
102 injectSDNCRestCallbacks(callbacks, "final");
104 interimNotification = this.getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
105 Assert.assertNull(interimNotification);
107 waitForProcessEnd(businessKey, 10000);
109 Assert.assertTrue(isProcessEnded(businessKey));
115 * Defines WireMock stubs needed by these tests.
117 private void mocks() {
118 stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc"))
119 .willReturn(aResponse()
121 .withHeader("Content-Type", "application/json")));