/*
- * Copyright (c) 2016, Huawei Technologies Co., Ltd.
+ * Copyright 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.
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.ServiceUtil;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.net.URLEncoder;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpExchange;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
-import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
+import org.openo.baseservice.remoteservice.exception.ServiceException;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
-import java.net.URLEncoder;
-
-import mockit.Expectations;
import mockit.Mock;
import mockit.MockUp;
import mockit.Mocked;
* </p>
*
* @author
- * @version SDNO 0.5 13-Jun-2016
+ * @version 13-Jun-2016
*/
@RunWith(JMockit.class)
public class TestHttpRest {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@Before
public void setUp() throws Exception {
* <br/>
*
* @throws java.lang.Exception
- * @since SDNO 0.5
+ * @since
*/
@After
public void tearDown() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRest() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRestExcpetion() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testInitHttpRestNull() throws Exception {
*
* @throws NoSuchFieldException
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testCreateRestHttpContentExchange() throws NoSuchFieldException, Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStringRestfulParametes() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testGetStringRestfulParametesRestfulOptions() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testGetStringRestfulParametesEncodeError() throws Exception {
final RestfulOptions options = new RestfulOptions();
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testHeadStringRestfulParametes() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testHeadStringRestfulParametesRestfulOptions() throws Exception {
final RestfulOptions options = new RestfulOptions();
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.head("path/to/service", parametes, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* @param options
* @return
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
private HttpRest getHttpRest(final RestfulOptions options) throws ServiceException {
final HttpRest httpRest = new HttpRest();
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncGetStringRestfulParametesRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncGetStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPutStringRestfulParametes() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(-1);
- }
-
- };
final RestfulResponse response = httpRest.put("path/to/service", parametes);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPutStringRestfulParametesRestfulOptions() throws ServiceException {
parametes.put("address", null);
parametes.putHttpContextHeader("Content-Type", "");
parametes.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.put("path/to/service", parametes, null);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPutStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPutStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testPostStringRestfulParametes() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPostStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
thrown.expect(ServiceException.class);
thrown.expectMessage("request is exception");
final RestfulResponse response = httpRest.post("path/to/service", parameters, null);
* <br/>
*
* @throws Exception
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPostStringRestfulParametesRestfulAsyncCallback() throws Exception {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPostStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testDeleteStringRestfulParametes() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testDeleteStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.delete("path/to/service", parameters, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncDeleteStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncDeleteStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPatchStringRestfulParametes() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.patch("path/to/service", parameters);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
- @Ignore
@Test
public void testPatchStringRestfulParametesRestfulOptions() throws ServiceException {
final RestfulOptions options = new RestfulOptions();
parameters.setRawData("{ \"data\"=\"sample JSON data\"");
parameters.putHttpContextHeader("Content-Type", "");
parameters.putHttpContextHeader("Accept-Encoding", "");
- new Expectations() {
-
- ServiceUtil serviceUtil;
-
- {
- serviceUtil = new ServiceUtil(anyString, anyString);
- serviceUtil.getServiceHost();
- returns("127.0.0.1");
-
- serviceUtil.getServicePort();
- returns(10);
- }
-
- };
final RestfulResponse response = httpRest.patch("path/to/service", parameters, options);
assertEquals(HttpExchange.STATUS_COMPLETED, response.getStatus());
}
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPatchStringRestfulParametesRestfulAsyncCallback() throws ServiceException {
* <br/>
*
* @throws ServiceException
- * @since SDNO 0.5
+ * @since
*/
@Test
public void testAsyncPatchStringRestfulParametesRestfulOptionsRestfulAsyncCallback() throws ServiceException {