当前位置: 首页>>代码示例>>Java>>正文


Java HttpTesting类代码示例

本文整理汇总了Java中com.google.api.client.testing.http.HttpTesting的典型用法代码示例。如果您正苦于以下问题:Java HttpTesting类的具体用法?Java HttpTesting怎么用?Java HttpTesting使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpTesting类属于com.google.api.client.testing.http包,在下文中一共展示了HttpTesting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: buildHttpResponse

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
/**
 * Builds a HttpResponse with the given string response.
 *
 * @param header header value to provide or null if none.
 * @param uploadId upload id to provide in the url upload id param or null if none.
 * @param uploadType upload type to provide in url upload type param or null if none.
 * @return HttpResponse with the given parameters
 * @throws IOException
 */
private HttpResponse buildHttpResponse(String header, String uploadId, String uploadType)
    throws IOException {
  MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
  MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
  builder.setLowLevelHttpResponse(resp);
  resp.setStatusCode(200);
  GenericUrl url = new GenericUrl(HttpTesting.SIMPLE_URL);
  if (header != null) {
    resp.addHeader("X-GUploader-UploadID", header);
  }
  if (uploadId != null) {
    url.put("upload_id", uploadId);
  }
  if (uploadType != null) {
    url.put("uploadType", uploadType);
  }
  return builder.build().createRequestFactory().buildGetRequest(url).execute();
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:UploadIdResponseInterceptorTest.java

示例2: makeResponseException

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
/** Returns a valid GoogleJsonResponseException for the given status code and error message.  */
private GoogleJsonResponseException makeResponseException(
    final int statusCode,
    final String message) throws Exception {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      return new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          MockLowLevelHttpResponse response = new MockLowLevelHttpResponse();
          response.setStatusCode(statusCode);
          response.setContentType(Json.MEDIA_TYPE);
          response.setContent(String.format(
              "{\"error\":{\"code\":%d,\"message\":\"%s\",\"domain\":\"global\","
              + "\"reason\":\"duplicate\"}}",
              statusCode,
              message));
          return response;
        }};
    }};
  HttpRequest request = transport.createRequestFactory()
      .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
      .setThrowExceptionOnExecuteError(false);
  return GoogleJsonResponseException.from(new JacksonFactory(), request.execute());
}
 
开发者ID:google,项目名称:nomulus,代码行数:27,代码来源:DirectoryGroupsConnectionTest.java

示例3: testHandleResponse

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testHandleResponse() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(true);
		labelResponse.setMeta(meta);
		Boolean retry = responseHandler.handleResponse(req, labelResponse, true);
		assertTrue(retry);
		assertEquals(new Long(1000), sleeper.getDelay());
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:19,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例4: testExponentialDelay

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testExponentialDelay() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(true);
		labelResponse.setMeta(meta);
		Boolean retry = null;
		Long delay = new Long(1000);
		for(int i = 0; i < 5; i++) {
			retry = responseHandler.handleResponse(req, labelResponse, true);
			assertEquals(delay, sleeper.getDelay());
			delay *= 2;
		}
		assertTrue(retry);
		
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:25,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例5: testRetryStopOnSixth

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testRetryStopOnSixth() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(true);
		labelResponse.setMeta(meta);
		Boolean retry = null;
		for(int i = 0; i < 6; i++) {
			retry = responseHandler.handleResponse(req, labelResponse, true);
		}
		assertFalse(retry);
		
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:22,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例6: testNotRetryable

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testNotRetryable() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(false);
		labelResponse.setMeta(meta);
		Boolean retry = null;
		retry = responseHandler.handleResponse(req, labelResponse, true);
		assertFalse(retry);
		
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:20,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例7: testRetryableNullInResponse

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testRetryableNullInResponse() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(null);
		labelResponse.setMeta(meta);
		Boolean retry = null;
		retry = responseHandler.handleResponse(req, labelResponse, true);
		assertFalse(retry);
		
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:20,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例8: testDoNotRetry

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testDoNotRetry() {
	HttpRequest req;
	try {
		req = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
		req.setNumberOfRetries(5);
		LabelResponse labelResponse = new LabelResponse();
		Meta meta = new Meta();
		meta.setCode(200);
		meta.setRetryable(true);
		labelResponse.setMeta(meta);
		Boolean retry = null;
		retry = responseHandler.handleResponse(req, labelResponse, false);
		assertFalse(retry);
		
		//responseHandler.handleResponse(req, labelResponse, true);
	} catch (IOException e) {
	}	
}
 
开发者ID:postmen,项目名称:postmen-sdk-java,代码行数:20,代码来源:PostmenUnsuccessfulResponseHandlerTest.java

示例9: testPostIOError

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testPostIOError() throws InterruptedException, ExecutionException, TimeoutException {

	Jups jups = new Jups(HttpTesting.SIMPLE_URL, "APP_ID", "SECRET");
    jups.mHttpTransport = new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    throw new IOException("test");
                }
            };
        }
    };

    String result = jups.send(new PushNotification("MASTER_VARIANT_ID", "VARIANT_ID", "ALERT_MESSAGE", "SOUND"), "TEST_UUID");
    assertEquals("Push notification should have failed", result, "failed");
}
 
开发者ID:SLAMon,项目名称:SLAMon,代码行数:20,代码来源:JupsTest.java

示例10: testSuccessResult

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testSuccessResult() throws InterruptedException, ExecutionException, TimeoutException {

    Afm afm = Afm.get(HttpTesting.SIMPLE_URL);
    JsonMockHttpTransport mockTransport = new JsonMockHttpTransport(succeeded_task_json);
    afm.mHttpTransport = mockTransport;

    FutureCallback result = new FutureCallback();
    afm.postTask(new Task("TASK_UUID", "TEST_UUID", "wait", 1), result);

    Task resultTask = result.task.get(5000, TimeUnit.MILLISECONDS);
    assertNotNull("Task should have been returned", resultTask);
    assertTrue("Task should have succeeded", result.succeeded);
    assertNull("Result should not contain error.", resultTask.task_error);
    assertEquals("Afm should have only made 2 requests.", 2, mockTransport.getRequestsCount());
    checkTaskBasics(resultTask);
    assertNotNull("Task should have result data", resultTask.task_result);
    assertEquals("result value should match", new BigDecimal(2), resultTask.task_result.get("waited"));
    assertEquals("int result value should have zero", 0, ((BigDecimal) resultTask.task_result.get("waited")).scale());
    assertEquals("result value should match", new BigDecimal(2.5), resultTask.task_result.get("waited-double"));
    assertNotEquals("double return value should not have zero scale", 0, ((BigDecimal) resultTask.task_result.get("waited-double")).scale());
    assertEquals("result value should match", "string-value", resultTask.task_result.get("string-value"));
}
 
开发者ID:SLAMon,项目名称:SLAMon,代码行数:24,代码来源:AfmTest.java

示例11: testFailedResult

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testFailedResult() throws InterruptedException, ExecutionException, TimeoutException {

    Afm afm = Afm.get(HttpTesting.SIMPLE_URL);
    JsonMockHttpTransport mockTransport = new JsonMockHttpTransport(failed_task_json);
    afm.mHttpTransport = mockTransport;

    FutureCallback result = new FutureCallback();
    afm.postTask(new Task("TASK_UUID", "TEST_UUID", "wait", 1), result);

    Task resultTask = result.task.get(5000, TimeUnit.MILLISECONDS);
    assertFalse("Task should have failed", result.succeeded);
    assertNotNull("Task should have been returned.", resultTask);
    assertNotNull("Error should be set.", resultTask.task_error);
    assertEquals("Error message should match definition.", resultTask.task_error, "error description");
    assertEquals("Afm should have only made 2 requests.", 2, mockTransport.getRequestsCount());
    checkTaskBasics(resultTask);
}
 
开发者ID:SLAMon,项目名称:SLAMon,代码行数:19,代码来源:AfmTest.java

示例12: testResultTimeout

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test(expected = TimeoutException.class)
public void testResultTimeout() throws InterruptedException, ExecutionException, TimeoutException {

    Afm afm = Afm.get(HttpTesting.SIMPLE_URL);
    JsonMockHttpTransport mockTransport = new JsonMockHttpTransport(waiting_task_json);
    afm.mHttpTransport = mockTransport;

    FutureCallback result = new FutureCallback();
    afm.postTask(new Task("TASK_UUID", "TEST_UUID", "wait", 1), result);

    try {
        result.task.get(5000, TimeUnit.MILLISECONDS);
    } catch (TimeoutException e) {
        assertTrue("Afm should have made multiple requests to poll results.", mockTransport.getRequestsCount() > 2);
        throw e;
    }
}
 
开发者ID:SLAMon,项目名称:SLAMon,代码行数:18,代码来源:AfmTest.java

示例13: testPostIOError

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
@Test
public void testPostIOError() throws InterruptedException, ExecutionException, TimeoutException {

    Afm afm = Afm.get(HttpTesting.SIMPLE_URL);
    afm.mHttpTransport = new MockHttpTransport() {
        @Override
        public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
            return new MockLowLevelHttpRequest() {
                @Override
                public LowLevelHttpResponse execute() throws IOException {
                    throw new IOException("test");
                }
            };
        }
    };

    FutureCallback result = new FutureCallback();
    afm.postTask(new Task("TASK_UUID", "TEST_UUID", "wait", 1), result);

    Task resultTask = result.task.get(5000, TimeUnit.MILLISECONDS);
    assertFalse("Task should have failed", result.succeeded);
    assertNotNull("Task should have been returned.", resultTask);
    assertNotNull("Error should be set.", resultTask.task_error);
}
 
开发者ID:SLAMon,项目名称:SLAMon,代码行数:25,代码来源:AfmTest.java

示例14: makeHttpException

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
HttpResponseException makeHttpException(int status) throws IOException {
  MockHttpTransport.Builder builder = new MockHttpTransport.Builder();
  MockLowLevelHttpResponse resp = new MockLowLevelHttpResponse();
  resp.setStatusCode(status);
  builder.setLowLevelHttpResponse(resp);
  try {
    HttpResponse res =
        builder.build()
            .createRequestFactory()
            .buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL)
            .execute();
    return new HttpResponseException(res);
  } catch (HttpResponseException exception) {
    return exception; // Throws the exception we want anyway, so just return it.
  }
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:17,代码来源:RetryDeterminerTest.java

示例15: createFakeResponse

import com.google.api.client.testing.http.HttpTesting; //导入依赖的package包/类
private HttpResponse createFakeResponse(final String responseHeader, final String responseValue,
                                        final InputStream content) throws IOException {
  HttpTransport transport = new MockHttpTransport() {
    @Override
    public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
      MockLowLevelHttpRequest req = new MockLowLevelHttpRequest() {
        @Override
        public LowLevelHttpResponse execute() throws IOException {
          return new MockLowLevelHttpResponse()
              .addHeader(responseHeader, responseValue)
              .setContent(content);
        }
      };
      return req;
    }
  };
  HttpRequest request =
      transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
  return request.execute();
}
 
开发者ID:GoogleCloudPlatform,项目名称:bigdata-interop,代码行数:21,代码来源:GoogleCloudStorageTest.java


注:本文中的com.google.api.client.testing.http.HttpTesting类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。