2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.bpmn.common;
\r
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
\r
24 import static com.github.tomakehurst.wiremock.client.WireMock.post;
\r
25 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
\r
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
\r
28 import java.io.IOException;
\r
29 import java.util.HashMap;
\r
30 import java.util.Map;
\r
31 import java.util.UUID;
\r
33 import javax.ws.rs.core.Response;
\r
35 import org.camunda.bpm.engine.test.Deployment;
\r
36 import org.junit.Assert;
\r
37 import org.junit.Test;
\r
38 import org.openecomp.mso.bpmn.common.WorkflowTest;
\r
39 import org.openecomp.mso.bpmn.common.workflow.service.WorkflowMessageResource;
\r
40 import org.openecomp.mso.bpmn.mock.FileUtil;
\r
43 * Unit tests for SDNCAdapterRestV2.bpmn.
\r
45 * This version of SDNCAdapterRest allows for interim notifications to be sent for
\r
46 * any non-final response received from SDNC.
\r
48 public class SDNCAdapterRestV2Test extends WorkflowTest {
\r
50 private final CallbackSet callbacks = new CallbackSet();
\r
53 * Constructor. Insert callbacks.
\r
55 * @throws IOException
\r
57 public SDNCAdapterRestV2Test() throws IOException {
\r
58 String sdncCallbackFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackFinal.json");
\r
59 String sdncCallbackNonFinal = FileUtil.readResourceFile("__files/SDNCAdapterRestCallbackNonFinal.json");
\r
60 callbacks.put("nonfinal", sdncCallbackNonFinal);
\r
61 callbacks.put("final", sdncCallbackFinal);
\r
65 * Test the success path through the subflow.
\r
68 @Deployment(resources = {
\r
69 "subprocess/SDNCAdapterRestV2.bpmn",
\r
70 "subprocess/GenericNotificationService.bpmn"
\r
72 public void success() throws IOException {
\r
76 String businessKey = UUID.randomUUID().toString();
\r
77 Map<String, Object> variables = new HashMap<String, Object>();
\r
78 variables.put("mso-request-id", "a4383a52-b9de-4bc4-bedf-02f3f9466535");
\r
79 variables.put("mso-service-instance-id", "fd8bcdbb-b799-43ce-a7ff-ed8f2965a3b5");
\r
80 variables.put("isDebugLogEnabled", "true");
\r
81 variables.put("SDNCREST_Request",
\r
82 FileUtil.readResourceFile("__files/SDNCAdapterRestV2Request.json"));
\r
83 variables.put("SDNCREST_InterimNotification1",
\r
84 FileUtil.readResourceFile("__files/SDNCInterimNotification1.json"));
\r
86 invokeSubProcess("SDNCAdapterRestV2", businessKey, variables);
\r
88 injectSDNCRestCallbacks(callbacks, "nonfinal");
\r
90 // First non-final response will have done a notification
\r
91 Object interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
\r
92 Assert.assertNotNull(interimNotification);
\r
94 injectSDNCRestCallbacks(callbacks, "nonfinal");
\r
96 // Second non-final response will not have done a notification
\r
97 interimNotification = getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
\r
98 Assert.assertNull(interimNotification);
\r
100 injectSDNCRestCallbacks(callbacks, "final");
\r
102 interimNotification = this.getVariableFromHistory(businessKey, "SDNCREST_interimNotification");
\r
103 Assert.assertNull(interimNotification);
\r
105 waitForProcessEnd(businessKey, 10000);
\r
107 Assert.assertTrue(isProcessEnded(businessKey));
\r
113 * Injects a single SDNC adapter callback request. The specified callback data
\r
114 * may contain the placeholder string ((REQUEST-ID)) which is replaced with
\r
115 * the actual SDNC request ID. Note: this is not the requestId in the original
\r
117 * @param contentType the HTTP content type for the callback
\r
118 * @param content the content of the callback
\r
119 * @param timeout the timeout in milliseconds
\r
120 * @return true if the callback could be injected, false otherwise
\r
123 protected boolean injectSDNCRestCallback(String contentType, String content, long timeout) {
\r
124 String sdncRequestId = (String) getProcessVariable("SDNCAdapterRestV2",
\r
125 "SDNCAResponse_CORRELATOR", timeout);
\r
127 if (sdncRequestId == null) {
\r
131 content = content.replace("((REQUEST-ID))", sdncRequestId);
\r
132 // Deprecated usage. All test code should switch to the (( ... )) syntax.
\r
133 content = content.replace("{{REQUEST-ID}}", sdncRequestId);
\r
135 System.out.println("Injecting SDNC adapter callback");
\r
136 WorkflowMessageResource workflowMessageResource = new WorkflowMessageResource();
\r
137 workflowMessageResource.setProcessEngineServices4junit(processEngineRule);
\r
138 Response response = workflowMessageResource.deliver(contentType, "SDNCAResponse", sdncRequestId, content);
\r
139 System.out.println("Workflow response to SDNC adapter callback: " + response);
\r
144 * Defines WireMock stubs needed by these tests.
\r
146 private void mocks() {
\r
147 stubFor(post(urlEqualTo("/SDNCAdapter/v1/sdnc/services"))
\r
148 .willReturn(aResponse()
\r
150 .withHeader("Content-Type", "application/json")));
\r