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;
28 import org.apache.http.HttpResponse;
29 import org.apache.http.HttpStatus;
30 import org.apache.http.ProtocolVersion;
31 import org.apache.http.client.HttpClient;
32 import org.apache.http.client.methods.HttpPost;
33 import org.apache.http.entity.StringEntity;
34 import org.apache.http.message.BasicHttpResponse;
35 import org.apache.http.message.BasicStatusLine;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mock;
39 import org.mockito.Mockito;
40 import org.mockito.MockitoAnnotations;
41 import org.openecomp.mso.apihandler.common.CommonConstants;
42 import org.openecomp.mso.apihandler.common.RequestClient;
43 import org.openecomp.mso.apihandler.common.RequestClientFactory;
44 import org.openecomp.mso.properties.MsoJavaProperties;
46 import com.fasterxml.jackson.core.JsonGenerationException;
47 import com.fasterxml.jackson.databind.JsonMappingException;
51 * This class implements test methods of Camunda Beans.
55 public class CamundaClientTest {
60 private HttpClient mockHttpClient;
64 MockitoAnnotations.initMocks(this);
68 public void tesCamundaPost() throws JsonGenerationException,
69 JsonMappingException, IOException {
72 String responseBody ="{\"links\":[{\"method\":\"GET\",\"href\":\"http://localhost:9080/engine-rest/process-instance/2047c658-37ae-11e5-9505-7a1020524153\",\"rel\":\"self\"}],\"id\":\"2047c658-37ae-11e5-9505-7a1020524153\",\"definitionId\":\"dummy:10:73298961-37ad-11e5-9505-7a1020524153\",\"businessKey\":null,\"caseInstanceId\":null,\"ended\":true,\"suspended\":false}";
74 HttpResponse mockResponse = createResponse(200, responseBody);
75 mockHttpClient = Mockito.mock(HttpClient.class);
76 Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
77 .thenReturn(mockResponse);
79 String reqXML = "<xml>test</xml>";
80 String orchestrationURI = "/engine-rest/process-definition/key/dummy/start";
82 MsoJavaProperties props = new MsoJavaProperties();
83 props.setProperty(CommonConstants.CAMUNDA_URL, "http://localhost:8089");
85 RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props);
86 requestClient.setClient(mockHttpClient);
87 HttpResponse response = requestClient.post(reqXML, "reqId", "timeout", "version", null, null);
90 int statusCode = response.getStatusLine().getStatusCode();
91 assertEquals(requestClient.getType(), CommonConstants.CAMUNDA);
92 assertEquals(statusCode, HttpStatus.SC_OK);
94 props.setProperty (CommonConstants.CAMUNDA_AUTH, "ABCD1234");
95 requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props);
96 requestClient.setClient(mockHttpClient);
97 response = requestClient.post(null, "reqId", null, null, null, null);
98 assertEquals(requestClient.getType(), CommonConstants.CAMUNDA);
99 assertEquals(statusCode, HttpStatus.SC_OK);
102 private HttpResponse createResponse(int respStatus,
104 HttpResponse response = new BasicHttpResponse(
106 new ProtocolVersion("HTTP", 1, 1), respStatus, ""));
107 response.setStatusCode(respStatus);
109 response.setEntity(new StringEntity(respBody));
110 response.setHeader("Content-Type", "application/json");
111 } catch (Exception e) {