[MSO-8] Update the maven dependency
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / openecomp / mso / bpmn / common / SDNCAdapterCallbackRule.java
1 package org.openecomp.mso.bpmn.common;
2
3 import javax.xml.ws.Endpoint;
4
5 import org.camunda.bpm.engine.ProcessEngineServices;
6 import org.junit.rules.TestRule;
7 import org.junit.runner.Description;
8 import org.junit.runners.model.Statement;
9 import org.openecomp.mso.bpmn.common.workflow.service.SDNCAdapterCallbackServiceImpl;
10
11 /**
12  * A JUnit rule that starts the SDNC Adapter Callback Service before
13  * every test, and tears it down after every test.  Example:
14  * <pre>
15  *     @Rule
16  *     public final SDNCAdapterCallbackRule sdncAdapterCallbackRule =
17  *         new SDNCAdapterCallbackRule(processEngineRule);
18  * </pre>
19  */
20 public class SDNCAdapterCallbackRule implements TestRule {
21         public static final String DEFAULT_ENDPOINT_URL =
22                 "http://localhost:28080/mso/SDNCAdapterCallbackService";
23
24         private final ProcessEngineServices processEngineServices;
25         private final String endpointUrl;
26
27         public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices) {
28                 this(processEngineServices, DEFAULT_ENDPOINT_URL);
29         }
30
31         public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices,
32                         String endpointUrl) {
33                 this.processEngineServices = processEngineServices;
34                 this.endpointUrl = endpointUrl;
35         }
36
37         @Override
38         public Statement apply(final Statement baseStmt, Description description) {
39                 return new Statement() {
40                         @Override
41                         public void evaluate() throws Throwable {
42                                 Endpoint endpoint = null;
43
44                                 try {
45                                         SDNCAdapterCallbackServiceImpl sdncCallbackService = new SDNCAdapterCallbackServiceImpl();
46                                         sdncCallbackService.setProcessEngineServices4junit(processEngineServices);
47
48                                         System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
49                                         System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
50
51                                         System.out.println("Publishing Endpoint - " + endpointUrl);
52                                         endpoint = Endpoint.publish(endpointUrl, sdncCallbackService);
53
54                                         baseStmt.evaluate();
55                                 } finally {
56                                         if (endpoint != null) {
57                                                 System.out.println("Stopping Endpoint - " + endpointUrl);
58                                                 endpoint.stop();
59                                         }
60                                 }
61                         }
62                 };
63         }
64 }