Remove unnecessary use of Calendar.getInstance()
[so.git] / bpmn / MSORESTClient / src / test / java / org / openecomp / mso / rest / RESTClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.rest;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25
26 import java.io.IOException;
27
28 import org.apache.http.HttpResponse;
29 import org.apache.http.HttpVersion;
30 import org.apache.http.client.ClientProtocolException;
31 import org.apache.http.client.HttpClient;
32 import org.apache.http.client.methods.HttpUriRequest;
33 import org.apache.http.entity.StringEntity;
34 import org.apache.http.message.BasicHttpResponse;
35 import org.junit.Assert;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38
39 import org.openecomp.mso.rest.APIResponse;
40 import org.openecomp.mso.rest.RESTClient;
41 import org.openecomp.mso.rest.RESTException;
42
43 /**
44  * @version 1.0
45  *
46  */
47 public class RESTClientTest {
48
49         @Test
50         public void testSimpleHTTP() throws RESTException, ClientProtocolException, IOException {
51                 HttpClient mockHttpClient = mock(HttpClient.class);
52                 HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
53                 response.setEntity(new StringEntity("test","UTF-8"));
54                 when(mockHttpClient.execute(Mockito.<HttpUriRequest>any())).thenReturn(response);
55
56                 RESTClient restClient = new RESTClient("http://localhost");
57                 restClient.setUnitTestClient(mockHttpClient);
58                 APIResponse apiResponse = restClient.get();
59                 Assert.assertEquals(200, apiResponse.getStatusCode());
60                 Assert.assertEquals("test", apiResponse.getResponseBodyAsString());
61         }
62         
63         @Test
64         public void testSimpleHTTPS() throws RESTException, ClientProtocolException, IOException {
65                 HttpClient mockHttpClient = mock(HttpClient.class);
66                 HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
67                 response.setEntity(new StringEntity("test","UTF-8"));
68                 when(mockHttpClient.execute(Mockito.<HttpUriRequest>any())).thenReturn(response);
69
70                 RESTClient restClient = new RESTClient("https://localhost");
71                 restClient.setUnitTestClient(mockHttpClient);
72                 APIResponse apiResponse = restClient.get();
73                 Assert.assertEquals(200, apiResponse.getStatusCode());
74                 Assert.assertEquals("test", apiResponse.getResponseBodyAsString());
75         }
76         
77 }