2 * Copyright (c) 2016, Huawei Technologies Co., Ltd.
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.
17 package org.openo.baseservice.roa.util.clientsdk;
19 import org.openo.baseservice.remoteservice.exception.ServiceException;
20 import org.openo.baseservice.roa.util.restclient.Restful;
21 import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback;
22 import org.openo.baseservice.roa.util.restclient.RestfulParametes;
23 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
25 import org.junit.After;
26 import org.junit.AfterClass;
27 import org.junit.Before;
28 import org.junit.BeforeClass;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.junit.rules.ExpectedException;
33 import java.util.Arrays;
34 import java.util.Date;
36 import junit.framework.Assert;
37 import mockit.Expectations;
46 * @version SDNO 0.5 13-Jun-2016
48 public class TestRestClientUtil {
53 ExpectedException thrown = ExpectedException.none();;
58 * @throws java.lang.Exception
62 public static void setUpBeforeClass() throws Exception {
68 * @throws java.lang.Exception
72 public static void tearDownAfterClass() throws Exception {
78 * @throws java.lang.Exception
82 public void setUp() throws Exception {
88 * @throws java.lang.Exception
92 public void tearDown() throws Exception {
98 * @throws ServiceException
103 public void testInvokeMethod() throws ServiceException {
104 final String path = "test/path";
105 final RestfulParametes parameters = null;
106 final RestfulResponse expected = new RestfulResponse();
107 expected.setStatus(200);
112 restFullMock.get(path, parameters);
115 restFullMock.post(path, parameters);
118 restFullMock.patch(path, parameters);
121 restFullMock.delete(path, parameters);
124 restFullMock.put(path, parameters);
128 RestfulResponse actual = RestClientUtil.invokeMethod("GET", path, parameters, restFullMock);
129 Assert.assertEquals(200, actual.getStatus());
131 actual = RestClientUtil.invokeMethod("POST", path, parameters, restFullMock);
132 Assert.assertEquals(200, actual.getStatus());
134 actual = RestClientUtil.invokeMethod("PATCH", path, parameters, restFullMock);
135 Assert.assertEquals(200, actual.getStatus());
137 actual = RestClientUtil.invokeMethod("DELETE", path, parameters, restFullMock);
138 Assert.assertEquals(200, actual.getStatus());
140 actual = RestClientUtil.invokeMethod("PUT", path, parameters, restFullMock);
141 Assert.assertEquals(200, actual.getStatus());
145 @Test(expected = ServiceException.class)
146 public void testInvokeMethodException() throws ServiceException {
147 RestClientUtil.invokeMethod("UNKNOWN-METHOD", "some/path", null, restFullMock);
153 * @throws ServiceException
157 @Test(expected = ServiceException.class)
158 public void testInvokeAsyncMethod() throws ServiceException {
159 final String path = "test/path";
160 final RestfulParametes parameters = null;
161 final RestfulAsyncCallback callback = null;
163 RestClientUtil.invokeAsyncMethod("GET", path, parameters, restFullMock, callback);
165 RestClientUtil.invokeAsyncMethod("POST", path, parameters, restFullMock, callback);
167 RestClientUtil.invokeAsyncMethod("PATCH", path, parameters, restFullMock, callback);
169 RestClientUtil.invokeAsyncMethod("DELETE", path, parameters, restFullMock, callback);
171 RestClientUtil.invokeAsyncMethod("PUT", path, parameters, restFullMock, callback);
173 RestClientUtil.invokeAsyncMethod("UNKNOWN", path, parameters, restFullMock, callback);
183 public void testIsPrimitive() {
185 Assert.assertTrue(RestClientUtil.isPrimitive(Integer.class));
186 Assert.assertTrue(RestClientUtil.isPrimitive(Long.class));
187 Assert.assertTrue(RestClientUtil.isPrimitive(Double.class));
188 Assert.assertTrue(RestClientUtil.isPrimitive(Void.class));
189 Assert.assertTrue(RestClientUtil.isPrimitive(String.class));
190 Assert.assertTrue(RestClientUtil.isPrimitive(Boolean.class));
191 Assert.assertTrue(RestClientUtil.isPrimitive(Byte.class));
192 Assert.assertTrue(RestClientUtil.isPrimitive(Character.class));
193 Assert.assertTrue(RestClientUtil.isPrimitive(Short.class));
194 Assert.assertTrue(RestClientUtil.isPrimitive(Float.class));
196 Assert.assertTrue(RestClientUtil.isPrimitive(int.class));
197 Assert.assertTrue(RestClientUtil.isPrimitive(long.class));
198 Assert.assertTrue(RestClientUtil.isPrimitive(double.class));
199 Assert.assertTrue(RestClientUtil.isPrimitive(void.class));
200 Assert.assertTrue(RestClientUtil.isPrimitive(boolean.class));
201 Assert.assertTrue(RestClientUtil.isPrimitive(byte.class));
202 Assert.assertTrue(RestClientUtil.isPrimitive(char.class));
203 Assert.assertTrue(RestClientUtil.isPrimitive(short.class));
204 Assert.assertTrue(RestClientUtil.isPrimitive(float.class));
206 Assert.assertFalse(RestClientUtil.isPrimitive(Object.class));
207 Assert.assertFalse(RestClientUtil.isPrimitive(Date.class));
208 Assert.assertFalse(RestClientUtil.isPrimitive(Arrays.class));