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