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;
23 import javax.xml.ws.Endpoint;
25 import org.camunda.bpm.engine.ProcessEngineServices;
26 import org.junit.rules.TestRule;
27 import org.junit.runner.Description;
28 import org.junit.runners.model.Statement;
29 import org.openecomp.mso.bpmn.common.workflow.service.SDNCAdapterCallbackServiceImpl;
32 * A JUnit rule that starts the SDNC Adapter Callback Service before
33 * every test, and tears it down after every test. Example:
36 * public final SDNCAdapterCallbackRule sdncAdapterCallbackRule =
37 * new SDNCAdapterCallbackRule(processEngineRule);
40 public class SDNCAdapterCallbackRule implements TestRule {
41 public static final String DEFAULT_ENDPOINT_URL =
42 "http://localhost:28080/mso/SDNCAdapterCallbackService";
44 private final ProcessEngineServices processEngineServices;
45 private final String endpointUrl;
47 public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices) {
48 this(processEngineServices, DEFAULT_ENDPOINT_URL);
51 public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices,
53 this.processEngineServices = processEngineServices;
54 this.endpointUrl = endpointUrl;
58 public Statement apply(final Statement baseStmt, Description description) {
59 return new Statement() {
61 public void evaluate() throws Throwable {
62 Endpoint endpoint = null;
65 SDNCAdapterCallbackServiceImpl sdncCallbackService = new SDNCAdapterCallbackServiceImpl();
66 sdncCallbackService.setProcessEngineServices4junit(processEngineServices);
68 System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
69 System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
71 System.out.println("Publishing Endpoint - " + endpointUrl);
72 endpoint = Endpoint.publish(endpointUrl, sdncCallbackService);
76 if (endpoint != null) {
77 System.out.println("Stopping Endpoint - " + endpointUrl);