2 * Copyright 2017 ZTE Corporation.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.workflow.activitiext.restservicetask;
18 import static org.hamcrest.CoreMatchers.is;
19 import static org.hamcrest.MatcherAssert.assertThat;
21 import org.apache.commons.httpclient.NameValuePair;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.Mockito;
26 import org.powermock.api.mockito.PowerMockito;
27 import org.powermock.core.classloader.annotations.PrepareForTest;
28 import org.powermock.modules.junit4.PowerMockRunner;
30 @PrepareForTest({HighLevelRestApi.class,LowLevelRestApi.class})
31 @RunWith(PowerMockRunner.class)
32 public class HighLevelRestApiTest {
34 private HighLevelRestApi highLevelRestApi;
38 highLevelRestApi = new HighLevelRestApi();
42 public void testGet() {
45 HttpResponseMessage msg = new HttpResponseMessage();
46 msg.setStatusCode(200);
47 msg.setResponseBody(null);
48 PowerMockito.mockStatic(LowLevelRestApi.class);
49 PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
51 String uri = "10.74.148.107/openoapi/catalog/v1/csars";
52 String acceptValue = "application/json";
53 String contentTypeValue = "application/json";
55 HighLevelRestApi.Get(uri, acceptValue, contentTypeValue);
56 assertThat(HighLevelRestApi.Get(uri, acceptValue, contentTypeValue), is(msg));
57 } catch (Exception e) {
58 // TODO Auto-generated catch block
64 public void testPost() {
67 HttpResponseMessage msg = new HttpResponseMessage();
68 msg.setStatusCode(200);
69 msg.setResponseBody(null);
70 PowerMockito.mockStatic(LowLevelRestApi.class);
71 PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
73 String uri = "10.74.148.107/openoapi/catalog/v1/csars";
74 String requestBody = "{'type':'NFAR'}";
75 String acceptValue = "application/json";
76 String contentTypeValue = "application/json";
78 assertThat(HighLevelRestApi.Post(uri, requestBody, acceptValue, contentTypeValue), is(msg));
79 } catch (Exception e) {
80 // TODO Auto-generated catch block
86 public void testDelete() {
89 HttpResponseMessage msg = new HttpResponseMessage();
90 msg.setStatusCode(200);
91 msg.setResponseBody(null);
92 PowerMockito.mockStatic(LowLevelRestApi.class);
93 PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
95 String uri = "10.74.148.107/openoapi/catalog/v1/csars/aa1bc611c9fbc08247d5ea71fd67ec3f";
96 String acceptValue = "application/json";
97 String contentTypeValue = "application/json";
99 assertThat(HighLevelRestApi.Delete(uri, acceptValue, contentTypeValue), is(msg));
100 } catch (Exception e) {
101 // TODO Auto-generated catch block
107 public void testPut() {
110 HttpResponseMessage msg = new HttpResponseMessage();
111 msg.setStatusCode(200);
112 msg.setResponseBody(null);
113 PowerMockito.mockStatic(LowLevelRestApi.class);
114 PowerMockito.when(LowLevelRestApi.executeHttpMethod(Mockito.anyObject())).thenReturn(msg);
116 String uri = "10.74.148.107/openoapi/catalog/v1/csars";
117 String requestBody = "{'type':'NFAR'}";
118 String acceptValue = "application/json";
119 String contentTypeValue = "application/json";
121 assertThat(HighLevelRestApi.Put(uri, requestBody, acceptValue, contentTypeValue), is(msg));
122 } catch (Exception e) {
123 // TODO Auto-generated catch block
129 public void testCreateNameValuePairArrayFromQuery() {
130 NameValuePair[] pair = new NameValuePair[2];
131 NameValuePair p1 = new NameValuePair();
133 p1.setValue("liuyao");
134 NameValuePair p2 = new NameValuePair();
141 String query = "name=liuyao&pwd=zte";
143 assertThat(highLevelRestApi.createNameValuePairArrayFromQuery(query), is(pair));