diff options
Diffstat (limited to 'rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk')
4 files changed, 0 insertions, 748 deletions
diff --git a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestHttpUtil.java b/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestHttpUtil.java deleted file mode 100644 index 419d4d0..0000000 --- a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestHttpUtil.java +++ /dev/null @@ -1,266 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.baseservice.roa.util.clientsdk; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Arrays; -import java.util.Date; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -import mockit.Mocked; -import mockit.NonStrictExpectations; - -/** - * <br/> - * <p> - * </p> - * - * @author - * @version SDNO 0.5 13-Jun-2016 - */ -public class TestHttpUtil { - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @Before - public void setUp() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @After - public void tearDown() throws Exception { - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testContainsIgnoreCase() { - final String[] array = {"hello", "how", "are", "you", "?"}; - final String toFind = "Hello"; - Assert.assertTrue(HttpUtil.containsIgnoreCase(array, toFind)); - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testContainsIgnoreCaseNull() { - final String[] array = {"hello", "how", "are", "you", "?"}; - final String toFind = "Hello"; - Assert.assertFalse(HttpUtil.containsIgnoreCase(array, null)); - - array[0] = null; - Assert.assertFalse(HttpUtil.containsIgnoreCase(array, toFind)); - - Assert.assertTrue(HttpUtil.containsIgnoreCase(array, null)); - array[0] = "hello"; - array[array.length - 1] = null; - Assert.assertTrue(HttpUtil.containsIgnoreCase(array, null)); - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testJoin() { - final String[] array = {"hello", "how", "are", "you", "?"}; - String actual = HttpUtil.join(array, ","); - String expected = "hello,how,are,you,?"; - Assert.assertEquals(actual, expected); - - actual = HttpUtil.join(array, "#"); - expected = expected.replaceAll(",", "#"); - Assert.assertEquals(actual, expected); - actual = HttpUtil.join(new String[] {}, ","); - Assert.assertEquals(actual, ""); - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testParameterToString() { - // with param string. - Object param = new String("String Param"); - String actual = HttpUtil.parameterToString(param); - String expected = "String Param"; - Assert.assertEquals(expected, actual); - - // with param date. - final Date date = new Date(); - param = date; - expected = "" + date.getTime(); - actual = HttpUtil.parameterToString(param); - Assert.assertEquals(expected, actual); - - // with param collection. - final String[] array = {"hello", "how", "are", "you", "?"}; - param = Arrays.asList(array); - expected = HttpUtil.join(array, ","); - actual = HttpUtil.parameterToString(param); - Assert.assertEquals(expected, actual); - - // with param any - param = new Object() { - - @Override - public String toString() { - return "test object"; - } - }; - expected = "test object"; - actual = HttpUtil.parameterToString(param); - Assert.assertEquals(expected, actual); - - // with param null. - expected = ""; - actual = HttpUtil.parameterToString(null); - Assert.assertEquals(expected, actual); - - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testSelectHeaderAccept() { - final String[] accepts = {"application/json", "text/plain", "application/xml"}; - String expected = "application/json"; - String actual = HttpUtil.selectHeaderAccept(accepts); - Assert.assertEquals(expected, actual); - - accepts[0] = "application/x-www-form-urlencoded"; - expected = HttpUtil.join(accepts, ","); - actual = HttpUtil.selectHeaderAccept(accepts); - Assert.assertEquals(expected, actual); - - expected = null; - actual = HttpUtil.selectHeaderAccept(new String[] {}); - Assert.assertEquals(expected, actual); - - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Test - public void testSelectHeaderContentType() { - final String[] accepts = {"application/json", "text/plain", "application/xml"}; - String expected = "application/json"; - String actual = HttpUtil.selectHeaderContentType(accepts); - Assert.assertEquals(expected, actual); - - accepts[0] = "application/x-www-form-urlencoded"; - expected = "application/x-www-form-urlencoded"; - actual = HttpUtil.selectHeaderContentType(accepts); - Assert.assertEquals(expected, actual); - - expected = "application/json"; - actual = HttpUtil.selectHeaderContentType(new String[] {}); - Assert.assertEquals(expected, actual); - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testEscapeString() throws Exception { - final String str = "/this/url/to be encoded"; - final String actual = HttpUtil.escapeString(str); - final String expected = "%2Fthis%2Furl%2Fto%20be%20encoded"; - Assert.assertEquals(expected, actual); - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Ignore - @Test - public void testEscapeStringException() throws Exception { - - final String str = "/this/url/to be encoded"; - new NonStrictExpectations() { - - @Mocked - URLEncoder encoder; - - { - URLEncoder.encode(str, "utf8"); - result = new UnsupportedEncodingException(); - } - }; - - final String actual = HttpUtil.escapeString(str); - Assert.assertEquals(str, actual); - } -} diff --git a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestJsonUtil.java b/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestJsonUtil.java deleted file mode 100644 index d532b94..0000000 --- a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestJsonUtil.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.baseservice.roa.util.clientsdk; - -import org.openo.baseservice.roa.util.clientsdk.demo.JsonTestClass; - -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.type.TypeReference; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import net.sf.json.JSONObject; - -import junit.framework.Assert; - -/** - * <br/> - * <p> - * </p> - * - * @author - * @version SDNO 0.5 13-Jun-2016 - */ -public class TestJsonUtil { - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @Before - public void setUp() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @After - public void tearDown() throws Exception { - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testUnMarshalStringClassOfT() throws Exception { - final String name = "myname"; - final int id = 25; - final String jsonstr = "{\"name\": \"" + name + "\", \"id\": " + id + "}"; - - final JsonTestClass jsonObj = JsonUtil.unMarshal(jsonstr, JsonTestClass.class); - - Assert.assertNotNull(jsonObj); - Assert.assertEquals(name, jsonObj.getName()); - Assert.assertEquals(id, jsonObj.getId()); - - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testUnMarshalStringTypeReferenceOfT() throws Exception { - final String name = "myname"; - final int id = 25; - final String jsonstr = "{\"name\": \"" + name + "\", \"id\": " + id + "}"; - - final JsonTestClass jsonObj = JsonUtil.unMarshal(jsonstr, new TypeReference<JsonTestClass>() {}); - - Assert.assertNotNull(jsonObj); - Assert.assertEquals(name, jsonObj.getName()); - Assert.assertEquals(id, jsonObj.getId()); - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testMarshal() throws Exception { - final JsonTestClass jsonObj = new JsonTestClass(); - jsonObj.setId(1); - jsonObj.setName("somename"); - final String str = JsonUtil.marshal(jsonObj); - final JSONObject json = JSONObject.fromObject(str); - Assert.assertNotNull(json); - Assert.assertEquals(json.getString("name"), jsonObj.getName()); - Assert.assertEquals(json.getInt("id"), jsonObj.getId()); - - } - - /** - * <br/> - * - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testMarshalJsonObj() throws Exception { - final JSONObject jsonObj = new JSONObject(); - jsonObj.put("id", 10); - jsonObj.put("name", "some-name"); - final String str = JsonUtil.marshal(jsonObj); - final JSONObject json = JSONObject.fromObject(str); - Assert.assertNotNull(json); - Assert.assertEquals(json.getString("name"), "some-name"); - Assert.assertEquals(json.getInt("id"), 10); - - } - - /** - * <br/> - * - * @throws JsonParseException - * @throws JsonMappingException - * @throws Exception - * @since SDNO 0.5 - */ - @Test - public void testGetMapper() throws JsonParseException, JsonMappingException, Exception { - final String name = "myname"; - final int id = 25; - final ObjectMapper mapper = JsonUtil.getMapper(); - Assert.assertNotNull(mapper); - final JSONObject json = new JSONObject(); - json.put("name", name); - json.put("id", id); - final JsonTestClass jsonObj = mapper.readValue(json.toString(), JsonTestClass.class); - Assert.assertNotNull(jsonObj); - Assert.assertEquals(name, jsonObj.getName()); - Assert.assertEquals(id, jsonObj.getId()); - } -} diff --git a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestRestClientUtil.java b/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestRestClientUtil.java deleted file mode 100644 index 0fcaf40..0000000 --- a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/TestRestClientUtil.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.baseservice.roa.util.clientsdk; - -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.Restful; -import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; - -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.util.Arrays; -import java.util.Date; - -import junit.framework.Assert; -import mockit.Expectations; -import mockit.Mocked; - -/** - * <br/> - * <p> - * </p> - * - * @author - * @version SDNO 0.5 13-Jun-2016 - */ -public class TestRestClientUtil { - - @Mocked - Restful restFullMock; - - ExpectedException thrown = ExpectedException.none();; - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @BeforeClass - public static void setUpBeforeClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @AfterClass - public static void tearDownAfterClass() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @Before - public void setUp() throws Exception { - } - - /** - * <br/> - * - * @throws java.lang.Exception - * @since SDNO 0.5 - */ - @After - public void tearDown() throws Exception { - } - - /** - * <br/> - * - * @throws ServiceException - * @since SDNO 0.5 - */ - @Ignore - @Test - public void testInvokeMethod() throws ServiceException { - final String path = "test/path"; - final RestfulParametes parameters = null; - final RestfulResponse expected = new RestfulResponse(); - expected.setStatus(200); - - new Expectations() { - - { - restFullMock.get(path, parameters); - returns(expected); - - restFullMock.post(path, parameters); - returns(expected); - - restFullMock.patch(path, parameters); - returns(expected); - - restFullMock.delete(path, parameters); - returns(expected); - - restFullMock.put(path, parameters); - returns(expected); - } - }; - RestfulResponse actual = RestClientUtil.invokeMethod("GET", path, parameters, restFullMock); - Assert.assertEquals(200, actual.getStatus()); - - actual = RestClientUtil.invokeMethod("POST", path, parameters, restFullMock); - Assert.assertEquals(200, actual.getStatus()); - - actual = RestClientUtil.invokeMethod("PATCH", path, parameters, restFullMock); - Assert.assertEquals(200, actual.getStatus()); - - actual = RestClientUtil.invokeMethod("DELETE", path, parameters, restFullMock); - Assert.assertEquals(200, actual.getStatus()); - - actual = RestClientUtil.invokeMethod("PUT", path, parameters, restFullMock); - Assert.assertEquals(200, actual.getStatus()); - } - - @Ignore - @Test(expected = ServiceException.class) - public void testInvokeMethodException() throws ServiceException { - RestClientUtil.invokeMethod("UNKNOWN-METHOD", "some/path", null, restFullMock); - } - - /** - * <br/> - * - * @throws ServiceException - * @since SDNO 0.5 - */ - @Ignore - @Test(expected = ServiceException.class) - public void testInvokeAsyncMethod() throws ServiceException { - final String path = "test/path"; - final RestfulParametes parameters = null; - final RestfulAsyncCallback callback = null; - - RestClientUtil.invokeAsyncMethod("GET", path, parameters, restFullMock, callback); - - RestClientUtil.invokeAsyncMethod("POST", path, parameters, restFullMock, callback); - - RestClientUtil.invokeAsyncMethod("PATCH", path, parameters, restFullMock, callback); - - RestClientUtil.invokeAsyncMethod("DELETE", path, parameters, restFullMock, callback); - - RestClientUtil.invokeAsyncMethod("PUT", path, parameters, restFullMock, callback); - - RestClientUtil.invokeAsyncMethod("UNKNOWN", path, parameters, restFullMock, callback); - } - - /** - * <br/> - * - * @since SDNO 0.5 - */ - @Ignore - @Test - public void testIsPrimitive() { - - Assert.assertTrue(RestClientUtil.isPrimitive(Integer.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Long.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Double.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Void.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(String.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Boolean.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Byte.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Character.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Short.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(Float.class)); - - Assert.assertTrue(RestClientUtil.isPrimitive(int.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(long.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(double.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(void.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(boolean.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(byte.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(char.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(short.class)); - Assert.assertTrue(RestClientUtil.isPrimitive(float.class)); - - Assert.assertFalse(RestClientUtil.isPrimitive(Object.class)); - Assert.assertFalse(RestClientUtil.isPrimitive(Date.class)); - Assert.assertFalse(RestClientUtil.isPrimitive(Arrays.class)); - } -} diff --git a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/demo/JsonTestClass.java b/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/demo/JsonTestClass.java deleted file mode 100644 index 5833bca..0000000 --- a/rest-client/src/test/java/org/openo/baseservice/roa/util/clientsdk/demo/JsonTestClass.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (c) 2016, Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.openo.baseservice.roa.util.clientsdk.demo; - -/** - * <br/> - * <p> - * </p> - * - * @author - * @version SDNO 0.5 13-Jun-2016 - */ -public class JsonTestClass { - - /** - * - */ - private String name; - - /** - * - */ - private int id; - - /** - * Constructor<br/> - * <p> - * </p> - * - * @since SDNO 0.5 - */ - public JsonTestClass() { - } - - /** - * <br/> - * - * @return - * @since SDNO 0.5 - */ - public String getName() { - return name; - } - - /** - * <br/> - * - * @param name - * @since SDNO 0.5 - */ - public void setName(String name) { - this.name = name; - } - - /** - * <br/> - * - * @return - * @since SDNO 0.5 - */ - public int getId() { - return id; - } - - /** - * <br/> - * - * @param id - * @since SDNO 0.5 - */ - public void setId(int id) { - this.id = id; - } -} |