Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / mso-infrastructure-bpmn / src / test / java / org / onap / so / bpmn / common / SDNCAdapterCallbackRule.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.bpmn.common;
22
23 import javax.xml.ws.Endpoint;
24 import org.camunda.bpm.engine.ProcessEngineServices;
25 import org.junit.rules.TestRule;
26 import org.junit.runner.Description;
27 import org.junit.runners.model.Statement;
28 import org.onap.so.bpmn.common.workflow.service.SDNCAdapterCallbackServiceImpl;
29
30 /**
31  * A JUnit rule that starts the SDNC Adapter Callback Service before every test, and tears it down after every test.
32  * Example:
33  * 
34  * <pre>
35  * &#64;Rule
36  * public final SDNCAdapterCallbackRule sdncAdapterCallbackRule = new SDNCAdapterCallbackRule(processEngineRule);
37  * </pre>
38  */
39 public class SDNCAdapterCallbackRule implements TestRule {
40     public static final String DEFAULT_ENDPOINT_URL = "http://localhost:28080/mso/SDNCAdapterCallbackService";
41
42     private final ProcessEngineServices processEngineServices;
43     private final String endpointUrl;
44
45     public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices) {
46         this(processEngineServices, DEFAULT_ENDPOINT_URL);
47     }
48
49     public SDNCAdapterCallbackRule(ProcessEngineServices processEngineServices, String endpointUrl) {
50         this.processEngineServices = processEngineServices;
51         this.endpointUrl = endpointUrl;
52     }
53
54     @Override
55     public Statement apply(final Statement baseStmt, Description description) {
56         return new Statement() {
57             @Override
58             public void evaluate() throws Throwable {
59                 Endpoint endpoint = null;
60
61                 try {
62                     SDNCAdapterCallbackServiceImpl sdncCallbackService = new SDNCAdapterCallbackServiceImpl();
63                     sdncCallbackService.setProcessEngineServices4junit(processEngineServices);
64
65                     System.setProperty("com.sun.xml.ws.transport.http.HttpAdapter.dump", "true");
66                     System.setProperty("com.sun.xml.internal.ws.transport.http.HttpAdapter.dump", "true");
67
68                     System.out.println("Publishing Endpoint - " + endpointUrl);
69                     endpoint = Endpoint.publish(endpointUrl, sdncCallbackService);
70
71                     baseStmt.evaluate();
72                 } finally {
73                     if (endpoint != null) {
74                         System.out.println("Stopping Endpoint - " + endpointUrl);
75                         endpoint.stop();
76                     }
77                 }
78             }
79         };
80     }
81 }