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.camunda.tests;
24 import static org.junit.Assert.assertEquals;
26 import java.io.IOException;
27 import java.util.Properties;
29 import org.apache.http.HttpResponse;
30 import org.apache.http.HttpStatus;
31 import org.apache.http.ProtocolVersion;
32 import org.apache.http.client.HttpClient;
33 import org.apache.http.client.methods.HttpPost;
34 import org.apache.http.entity.StringEntity;
35 import org.apache.http.message.BasicHttpResponse;
36 import org.apache.http.message.BasicStatusLine;
37 import org.codehaus.jackson.JsonGenerationException;
38 import org.codehaus.jackson.map.JsonMappingException;
39 import org.junit.Before;
40 import org.junit.Test;
41 import org.mockito.Mock;
42 import org.mockito.Mockito;
43 import org.mockito.MockitoAnnotations;
45 import org.openecomp.mso.apihandler.common.CommonConstants;
46 import org.openecomp.mso.apihandler.common.RequestClient;
47 import org.openecomp.mso.apihandler.common.RequestClientFactory;
48 import org.openecomp.mso.properties.MsoJavaProperties;
52 * This class implements test methods of Camunda Beans.
56 public class BPELRestClientTest {
61 private HttpClient mockHttpClient;
65 MockitoAnnotations.initMocks(this);
69 public void tesBPELPost() throws JsonGenerationException,
70 JsonMappingException, IOException {
73 String responseBody ="<layer3activate:service-response xmlns:layer3activate=\"http://ecomp.att.com/mso/request/layer3serviceactivate/schema/v1\""
74 + "xmlns:reqtype=\"http://ecomp.att.com/mso/request/types/v1\""
75 + "xmlns:aetgt=\"http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd\""
76 + "xmlns:types=\"http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd\">"
77 + "<reqtype:request-id>req5</reqtype:request-id>"
78 + "<reqtype:request-action>Layer3ServiceActivateRequest</reqtype:request-action>"
79 + "<reqtype:source>OMX</reqtype:source>"
80 + "<reqtype:ack-final-indicator>n</reqtype:ack-final-indicator>"
81 + "</layer3activate:service-response>";
83 HttpResponse mockResponse = createResponse(200, responseBody);
84 mockHttpClient = Mockito.mock(HttpClient.class);
85 Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
86 .thenReturn(mockResponse);
88 String reqXML = "<xml>test</xml>";
89 String orchestrationURI = "/active-bpel/services/REST/MsoLayer3ServiceActivate";
91 MsoJavaProperties props = new MsoJavaProperties();
92 props.setProperty(CommonConstants.BPEL_URL, "http://localhost:8089");
93 props.setProperty("bpelAuth", "786864AA53D0DCD881AED1154230C0C3058D58B9339D2EFB6193A0F0D82530E1");
95 RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props);
96 requestClient.setClient(mockHttpClient);
97 HttpResponse response = requestClient.post(reqXML, "reqId", "timeout", "version", null, null);
100 int statusCode = response.getStatusLine().getStatusCode();
101 assertEquals(requestClient.getType(), CommonConstants.BPEL);
102 assertEquals(statusCode, HttpStatus.SC_OK);
107 private HttpResponse createResponse(int respStatus,
109 HttpResponse response = new BasicHttpResponse(
111 new ProtocolVersion("HTTP", 1, 1), respStatus, ""));
112 response.setStatusCode(respStatus);
114 response.setEntity(new StringEntity(respBody));
115 response.setHeader("Content-Type", "text/xml");
116 } catch (Exception e) {