Merge "Reorder modifiers"
[so.git] / mso-api-handlers / mso-api-handler-common / src / test / java / org / openecomp / mso / camunda / tests / BPELRestClientTest.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.openecomp.mso.camunda.tests;
22
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.IOException;
27
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;
45
46 import com.fasterxml.jackson.core.JsonGenerationException;
47 import com.fasterxml.jackson.databind.JsonMappingException;
48
49
50 /**
51  * This class implements test methods of Camunda Beans.
52  * 
53  *
54  */
55 public class BPELRestClientTest {
56
57
58
59         @Mock
60         private HttpClient mockHttpClient;
61
62         @Before
63         public void setUp() {
64                 MockitoAnnotations.initMocks(this);
65         }
66
67         @Test
68         public void tesBPELPost() throws JsonGenerationException,
69         JsonMappingException, IOException {
70
71
72                 String responseBody ="<layer3activate:service-response xmlns:layer3activate=\"http://org.openecomp/mso/request/layer3serviceactivate/schema/v1\""
73                                                                                                 + "xmlns:reqtype=\"http://org.openecomp/mso/request/types/v1\""
74                                                                                                 + "xmlns:aetgt=\"http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd\""
75                                                                                                 + "xmlns:types=\"http://schemas.activebpel.org/REST/2007/12/01/aeREST.xsd\">"
76                                                                                                 + "<reqtype:request-id>req5</reqtype:request-id>"
77                                                                                                 + "<reqtype:request-action>Layer3ServiceActivateRequest</reqtype:request-action>"
78                                                                                                 + "<reqtype:source>OMX</reqtype:source>"
79                                                                                                 + "<reqtype:ack-final-indicator>n</reqtype:ack-final-indicator>"
80                                                                                                 + "</layer3activate:service-response>";
81                 
82                 HttpResponse mockResponse = createResponse(200, responseBody);
83                 mockHttpClient = Mockito.mock(HttpClient.class);
84                 Mockito.when(mockHttpClient.execute(Mockito.any(HttpPost.class)))
85                 .thenReturn(mockResponse);
86
87                 String reqXML = "<xml>test</xml>";
88                 String orchestrationURI = "/active-bpel/services/REST/MsoLayer3ServiceActivate";
89
90                 MsoJavaProperties props = new MsoJavaProperties();
91                 props.setProperty(CommonConstants.BPEL_URL, "http://localhost:8089");
92                 props.setProperty("bpelAuth", "786864AA53D0DCD881AED1154230C0C3058D58B9339D2EFB6193A0F0D82530E1");
93
94                 RequestClient requestClient = RequestClientFactory.getRequestClient(orchestrationURI, props);
95                 requestClient.setClient(mockHttpClient);
96                 HttpResponse response = requestClient.post(reqXML, "reqId", "timeout", "version", null, null);
97
98
99                 int statusCode = response.getStatusLine().getStatusCode();
100                 assertEquals(requestClient.getType(), CommonConstants.BPEL);
101                 assertEquals(statusCode, HttpStatus.SC_OK);
102
103
104         }
105
106         private HttpResponse createResponse(int respStatus, 
107                         String respBody) {
108                 HttpResponse response = new BasicHttpResponse(
109                                 new BasicStatusLine(
110                                                 new ProtocolVersion("HTTP", 1, 1), respStatus, ""));
111                 response.setStatusCode(respStatus);
112                 try {
113                         response.setEntity(new StringEntity(respBody));
114                         response.setHeader("Content-Type", "text/xml");
115                 } catch (Exception e) {
116                         e.printStackTrace();
117                 }
118                 return response;
119         }
120
121
122
123
124
125 }