• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java MockClientHttpRequest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: booleanValue

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


示例17: match

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
@Override
public final void match(ClientHttpRequest request) throws IOException, AssertionError {
	try {
		MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
		matchInternal(mockRequest);
	}
	catch (Exception e) {
		throw new AssertionError("Failed to parse XML request content: " + e.getMessage());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:XpathRequestMatchers.java


示例18: string

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Get the body of the request as a UTF-8 string and appply the given {@link Matcher}.
 */
public RequestMatcher string(final Matcher<? super String> matcher) {
	return new RequestMatcher() {
		@Override
		public void match(ClientHttpRequest request) throws IOException, AssertionError {
			MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
			assertThat("Request content", mockRequest.getBodyAsString(), matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ContentRequestMatchers.java


示例19: bytes

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Compare the body of the request to the given byte array.
 */
public RequestMatcher bytes(final byte[] expectedContent) {
	return new RequestMatcher() {
		@Override
		public void match(ClientHttpRequest request) throws IOException, AssertionError {
			MockClientHttpRequest mockRequest = (MockClientHttpRequest) request;
			assertEquals("Request content", expectedContent, mockRequest.getBodyAsBytes());
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:ContentRequestMatchers.java


示例20: node

import org.springframework.mock.http.client.MockClientHttpRequest; //导入依赖的package包/类
/**
 * Parse the request content as {@link Node} and apply the given {@link Matcher}.
 */
public RequestMatcher node(final Matcher<? super Node> matcher) {
	return new AbstractXmlRequestMatcher() {
		@Override
		protected void matchInternal(MockClientHttpRequest request) throws Exception {
			xmlHelper.assertNode(request.getBodyAsString(), matcher);
		}
	};
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:ContentRequestMatchers.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ElasticsearchClusterRunner类代码示例发布时间:2022-05-21
下一篇:
Java EmptyArrays类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap