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


Java MockClientHttpRequest类代码示例

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


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

示例1: run

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Override
public void run() {
    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    response.getHeaders().add("X-RateLimit-Remaining", "50");
    response.getHeaders().add("X-RateLimit-Reset", String.valueOf((System.currentTimeMillis() / 1000) + 1));

    try {
        when(execution.execute(request, new byte[0])).thenReturn(response);

        this.interceptor.intercept(request, new byte[0], execution);
    } catch (IOException e) {
    } finally {
        this.latch.countDown();
    }
}
 
开发者ID:pivotalsoftware,项目名称:github-cla-integration,代码行数:19,代码来源:RateLimitingClientHttpRequestInterceptorTest.java

示例2: block

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void block() throws InterruptedException, IOException {
    CountDownLatch latch = new CountDownLatch(1);

    MockClientHttpRequest request = new MockClientHttpRequest();
    MockClientHttpResponse response = new MockClientHttpResponse(new byte[0], HttpStatus.OK);
    ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);

    request.setMethod(HttpMethod.GET);
    request.setURI(URI.create("http://localhost"));

    when(execution.execute(request, new byte[0])).thenReturn(response);

    new Thread(new Trigger(this.interceptor, latch)).start();
    latch.await();

    this.interceptor.intercept(request, new byte[0], execution);
}
 
开发者ID:pivotalsoftware,项目名称:github-cla-integration,代码行数:19,代码来源:RateLimitingClientHttpRequestInterceptorTest.java

示例3: canBufferResponses

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void canBufferResponses() throws IOException
{
	MockClientHttpRequest request = new MockClientHttpRequest();
	MockClientHttpResponse response = new MockClientHttpResponse(singleUseStream("hello".getBytes()), OK);
	request.setResponse(response);
	when(requestFactory.createRequest(URI.create("http://example.com"), GET)).thenReturn(request);
	
	loggingCustomizer.customize(restTemplate);
	
	ClientHttpResponse actualResponse = restTemplate.getRequestFactory()
		.createRequest(URI.create("http://example.com"), GET)
		.execute();
	assertThat(copyToByteArray(actualResponse.getBody()), equalTo("hello".getBytes()));
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:16,代码来源:LoggingCustomizerTest.java

示例4: canLogRequestUsingDefaultCharset

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void canLogRequestUsingDefaultCharset() throws IOException, URISyntaxException
{
	MockClientHttpRequest request = new MockClientHttpRequest(POST, new URI("/hello"));
	byte[] body = "world £".getBytes(ISO_8859_1);
	when(execution.execute(request, body)).thenReturn(new MockClientHttpResponse(new byte[0], OK));
	
	loggingInterceptor.intercept(request, body, execution);
	
	verify(log).debug("Request: POST /hello world £");
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:12,代码来源:LoggingInterceptorTest.java

示例5: canLogRequestUsingCharset

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void canLogRequestUsingCharset() throws IOException, URISyntaxException
{
	MockClientHttpRequest request = new MockClientHttpRequest(POST, new URI("/hello"));
	request.getHeaders().setContentType(parseMediaType("text/plain;charset=UTF-8"));
	byte[] body = "world £".getBytes(UTF_8);
	when(execution.execute(request, body)).thenReturn(new MockClientHttpResponse(new byte[0], OK));
	
	loggingInterceptor.intercept(request, body, execution);
	
	verify(log).debug("Request: POST /hello world £");
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:13,代码来源:LoggingInterceptorTest.java

示例6: canLogResponseUsingDefaultCharset

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void canLogResponseUsingDefaultCharset() throws IOException, URISyntaxException
{
	MockClientHttpRequest request = new MockClientHttpRequest();
	byte[] body = "hello £".getBytes(ISO_8859_1);
	when(execution.execute(request, new byte[0])).thenReturn(new MockClientHttpResponse(body, OK));
	
	loggingInterceptor.intercept(request, new byte[0], execution);
	
	verify(log).debug("Response: 200 hello £");
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:12,代码来源:LoggingInterceptorTest.java

示例7: canLogResponseUsingCharset

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Test
public void canLogResponseUsingCharset() throws IOException, URISyntaxException
{
	MockClientHttpRequest request = new MockClientHttpRequest();
	byte[] body = "hello £".getBytes(UTF_8);
	MockClientHttpResponse response = new MockClientHttpResponse(body, OK);
	response.getHeaders().setContentType(parseMediaType("text/plain;charset=UTF-8"));
	when(execution.execute(request, new byte[0])).thenReturn(response);
	
	loggingInterceptor.intercept(request, new byte[0], execution);
	
	verify(log).debug("Response: 200 hello £");
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:14,代码来源:LoggingInterceptorTest.java

示例8: aqlContent

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
private RequestMatcher aqlContent(String buildName, String buildNumber) {
	return (request) -> {
		String body = ((MockClientHttpRequest) request).getBodyAsString();
		Matcher matcher = AQL_PATTERN.matcher(body);
		assertThat(matcher.matches()).isTrue();
		String actualJson = matcher.group(1);
		String expectedJson = "{\"@build.name\": \"" + buildName
				+ "\", \"@build.number\": \"" + buildNumber + "\"}";
		assertJson(expectedJson, actualJson);
	};
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:12,代码来源:HttpArtifactoryBuildRunsTests.java

示例9: jsonContent

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
private RequestMatcher jsonContent(Resource expected) {
	return (request) -> {
		String actualJson = ((MockClientHttpRequest) request).getBodyAsString();
		String expectedJson = FileCopyUtils.copyToString(new InputStreamReader(
				expected.getInputStream(), Charset.forName("UTF-8")));
		assertJson(actualJson, expectedJson);
	};
}
 
开发者ID:spring-io,项目名称:artifactory-resource,代码行数:9,代码来源:HttpArtifactoryBuildRunsTests.java

示例10: node

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Apply the XPath and assert it with the given {@code Matcher<Node>}.
 */
public <T> RequestMatcher node(final Matcher<? super Node> matcher) {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.assertNode(request.getBodyAsBytes(), DEFAULT_ENCODING, matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:XpathRequestMatchers.java

示例11: exists

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Assert that content exists at the given XPath.
 */
public <T> RequestMatcher exists() {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.exists(request.getBodyAsBytes(), DEFAULT_ENCODING);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:XpathRequestMatchers.java

示例12: doesNotExist

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Assert that content does not exist at the given XPath.
 */
public <T> RequestMatcher doesNotExist() {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.doesNotExist(request.getBodyAsBytes(), DEFAULT_ENCODING);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:XpathRequestMatchers.java

示例13: nodeCount

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Apply the XPath and assert the number of nodes found with the given
 * {@code Matcher<Integer>}.
 */
public <T> RequestMatcher nodeCount(final Matcher<Integer> matcher) {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.assertNodeCount(request.getBodyAsBytes(), DEFAULT_ENCODING, matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:XpathRequestMatchers.java

示例14: string

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Apply the XPath and assert the String content found with the given matcher.
 */
public <T> RequestMatcher string(final Matcher<? super String> matcher) {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.assertString(request.getBodyAsBytes(), DEFAULT_ENCODING, matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:XpathRequestMatchers.java

示例15: number

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Apply the XPath and assert the number found with the given matcher.
 */
public <T> RequestMatcher number(final Matcher<? super Double> matcher) {
	return new AbstractXpathRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xpathHelper.assertNumber(request.getBodyAsBytes(), DEFAULT_ENCODING, matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:XpathRequestMatchers.java


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