本文整理汇总了Java中org.springframework.test.web.client.match.MockRestRequestMatchers类的典型用法代码示例。如果您正苦于以下问题:Java MockRestRequestMatchers类的具体用法?Java MockRestRequestMatchers怎么用?Java MockRestRequestMatchers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockRestRequestMatchers类属于org.springframework.test.web.client.match包,在下文中一共展示了MockRestRequestMatchers类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testStandardTags
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void testStandardTags() {
String url = "http://localhost/foo";
{
mockServer.expect(MockRestRequestMatchers.requestTo(url))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess());
client.getForEntity(url, String.class);
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(5, mockSpan.tags().size());
Assert.assertEquals(RestTemplateSpanDecorator.StandardTags.COMPONENT_NAME,
mockSpan.tags().get(Tags.COMPONENT.getKey()));
Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(url, mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(200, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertEquals(0, mockSpan.logEntries().size());
}
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:25,代码来源:AbstractTracingClientTest.java
示例2: patchRequest
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void patchRequest() throws Exception {
this.mockServer
.expect(method(PATCH))
.andExpect(requestTo("http://localhost/original/patch"))
.andExpect(header(PROXY_METADATA, PROXY_METADATA_VALUE))
.andExpect(header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE))
.andExpect(MockRestRequestMatchers.content().contentType(TEXT_PLAIN))
.andExpect(MockRestRequestMatchers.content().string(BODY_VALUE))
.andRespond(withSuccess(BODY_VALUE, TEXT_PLAIN));
this.mockMvc
.perform(patch("http://localhost/route-service/patch")
.header(FORWARDED_URL, "http://localhost/original/patch")
.header(PROXY_METADATA, PROXY_METADATA_VALUE)
.header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE)
.contentType(TEXT_PLAIN)
.content(BODY_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentType(TEXT_PLAIN))
.andExpect(content().string(BODY_VALUE));
this.mockServer.verify();
}
开发者ID:nebhale,项目名称:route-service-example,代码行数:25,代码来源:ControllerTest.java
示例3: testStandardTagsWithPort
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void testStandardTagsWithPort() {
String url = "http://localhost:4000/foo";
{
mockServer.expect(MockRestRequestMatchers.requestTo(url))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess());
client.getForEntity(url, String.class);
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(6, mockSpan.tags().size());
Assert.assertEquals(RestTemplateSpanDecorator.StandardTags.COMPONENT_NAME,
mockSpan.tags().get(Tags.COMPONENT.getKey()));
Assert.assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(url, mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(200, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertEquals(4000, mockSpan.tags().get(Tags.PEER_PORT.getKey()));
Assert.assertEquals(0, mockSpan.logEntries().size());
}
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:26,代码来源:AbstractTracingClientTest.java
示例4: testParentSpan
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void testParentSpan() {
{
ActiveSpan parent = mockTracer.buildSpan("parent").startActive();
String url = "http://localhost/foo";
mockServer.expect(MockRestRequestMatchers.requestTo(url))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess());
client.getForEntity(url, String.class);
parent.deactivate();
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
Assert.assertEquals(mockSpans.get(0).parentId(), mockSpans.get(1).context().spanId());
Assert.assertEquals(mockSpans.get(0).context().traceId(), mockSpans.get(1).context().traceId());
}
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:20,代码来源:AbstractTracingClientTest.java
示例5: interceptRestTemplate
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void interceptRestTemplate() {
mockServer.expect(MockRestRequestMatchers.requestTo("/test/123"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess("OK",
MediaType.APPLICATION_JSON));
String result = restTemplate.getForObject("/test/{id}", String.class, 123);
assertThat(registry.find("http.client.requests").meters())
.anySatisfy(m -> assertThat(stream(m.getId().getTags().spliterator(), false).map(Tag::getKey)).doesNotContain("bucket"));
assertThat(registry.find("http.client.requests")
.tags("method", "GET", "uri", "/test/{id}", "status", "200")
.timer().count()).isEqualTo(1L);
assertThat(result).isEqualTo("OK");
mockServer.verify();
}
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:21,代码来源:MetricsRestTemplateCustomizerTest.java
示例6: normalizeUriToContainLeadingSlash
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
/**
* Issue #283
*/
@Test
public void normalizeUriToContainLeadingSlash() {
mockServer.expect(MockRestRequestMatchers.requestTo("test/123"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withSuccess("OK",
MediaType.APPLICATION_JSON));
String result = restTemplate.getForObject("test/{id}", String.class, 123);
assertThat(registry.find("http.client.requests").tags("uri", "/test/{id}").timer())
.isNotNull();
assertThat(result).isEqualTo("OK");
mockServer.verify();
}
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:19,代码来源:MetricsRestTemplateCustomizerTest.java
示例7: postRequest
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void postRequest() throws Exception {
this.mockServer
.expect(method(POST))
.andExpect(requestTo("http://localhost/original/post"))
.andExpect(header(PROXY_METADATA, PROXY_METADATA_VALUE))
.andExpect(header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE))
.andExpect(MockRestRequestMatchers.content().contentType(TEXT_PLAIN))
.andExpect(MockRestRequestMatchers.content().string(BODY_VALUE))
.andRespond(withSuccess(BODY_VALUE, TEXT_PLAIN));
this.mockMvc
.perform(post("http://localhost/route-service/post")
.header(FORWARDED_URL, "http://localhost/original/post")
.header(PROXY_METADATA, PROXY_METADATA_VALUE)
.header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE)
.contentType(TEXT_PLAIN)
.content(BODY_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentType(TEXT_PLAIN))
.andExpect(content().string(BODY_VALUE));
this.mockServer.verify();
}
开发者ID:nebhale,项目名称:route-service-example,代码行数:25,代码来源:ControllerTest.java
示例8: putRequest
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void putRequest() throws Exception {
this.mockServer
.expect(method(PUT))
.andExpect(requestTo("http://localhost/original/put"))
.andExpect(header(PROXY_METADATA, PROXY_METADATA_VALUE))
.andExpect(header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE))
.andExpect(MockRestRequestMatchers.content().contentType(TEXT_PLAIN))
.andExpect(MockRestRequestMatchers.content().string(BODY_VALUE))
.andRespond(withSuccess(BODY_VALUE, TEXT_PLAIN));
this.mockMvc
.perform(put("http://localhost/route-service/put")
.header(FORWARDED_URL, "http://localhost/original/put")
.header(PROXY_METADATA, PROXY_METADATA_VALUE)
.header(PROXY_SIGNATURE, PROXY_SIGNATURE_VALUE)
.contentType(TEXT_PLAIN)
.content(BODY_VALUE))
.andExpect(status().isOk())
.andExpect(content().contentType(TEXT_PLAIN))
.andExpect(content().string(BODY_VALUE));
this.mockServer.verify();
}
开发者ID:nebhale,项目名称:route-service-example,代码行数:25,代码来源:ControllerTest.java
示例9: compareAndSwapWithPrevExistAndSetTtl
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void compareAndSwapWithPrevExistAndSetTtl() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60&prevExist=false"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
.andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
.andExpect(MockRestRequestMatchers.content().string("value=Hello+world"))
.andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_delete.json"),
MediaType.APPLICATION_JSON));
EtcdResponse response = client.compareAndSwap("sample", "Hello world", 60, false);
Assert.assertNotNull("response", response);
server.verify();
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:15,代码来源:EtcdClientTest.java
示例10: should_delete_message_after_fetching
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void should_delete_message_after_fetching() throws WhatsAppConnectionException {
final MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate);
mockServer.expect(MockRestRequestMatchers.requestTo("base/messages/inbox")) //
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) //
.andRespond(MockRestResponseCreators.withSuccess("[{" + //
" \"_id\" : \"42\", " + //
"\"_from\" : \"41214214\", " + //
"\"participant\" : \"41214214\", " + //
"\"body\" : \"41214214\" " + //
"}]", MediaType.APPLICATION_JSON));
mockServer.expect(MockRestRequestMatchers.requestTo("base/messages/inbox/42")) //
.andExpect(MockRestRequestMatchers.method(HttpMethod.DELETE)) //
.andRespond(MockRestResponseCreators.withSuccess("", MediaType.APPLICATION_JSON));
final GroupMessage[] messages = cut.fetchGroupMessages();
assertThat(messages, is(not(emptyArray())));
mockServer.verify();
}
开发者ID:learning-spring-boot,项目名称:contest-votesapp,代码行数:24,代码来源:YowsupRestClientTest.java
示例11: testGsonSerialization
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void testGsonSerialization()
{
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Authorization", "Basic ABCDE");
HttpEntity<TestNegotiatorQuery> entity = new HttpEntity<>(testNegotiatorQuery, headers);
server.expect(once(), requestTo("http://directory.url/request"))
.andExpect(method(HttpMethod.POST))
.andExpect(content().string("{\"URL\":\"url\",\"nToken\":\"ntoken\"}"))
.andExpect(MockRestRequestMatchers.header("Authorization", "Basic ABCDE"))
.andRespond(withCreatedEntity(URI.create("http://directory.url/request/DEF")));
String redirectURL = restTemplate.postForLocation("http://directory.url/request", entity).toASCIIString();
assertEquals(redirectURL, "http://directory.url/request/DEF");
// Verify all expectations met
server.verify();
}
开发者ID:molgenis,项目名称:molgenis,代码行数:21,代码来源:HttpClientConfigTest.java
示例12: testInject
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void testInject() {
String url = "http://localhost:4000/foo";
mockServer.expect(MockRestRequestMatchers.requestTo(url))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(new ResponseCreator() {
@Override
public ClientHttpResponse createResponse(ClientHttpRequest request) throws IOException {
MockClientHttpResponse response =
new MockClientHttpResponse(new byte[1], HttpStatus.OK);
response.getHeaders().add("traceId", request.getHeaders()
.getFirst("traceId"));
response.getHeaders().add("spanId", request.getHeaders()
.getFirst("spanId"));
return response;
}
});
ResponseEntity<String> responseEntity = client.getForEntity(url, String.class);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
Assert.assertEquals(mockSpans.get(0).context().traceId(),
Long.parseLong(responseEntity.getHeaders().getFirst("traceId")));
Assert.assertEquals(mockSpans.get(0).context().spanId(),
Long.parseLong(responseEntity.getHeaders().getFirst("spanId")));
}
开发者ID:opentracing-contrib,项目名称:java-spring-web,代码行数:29,代码来源:AbstractTracingClientTest.java
示例13: loadDataRequestsDataInFormatSpecifiedInParameters
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void loadDataRequestsDataInFormatSpecifiedInParameters() {
mockServer.expect(requestTo(URL)).andExpect(method(HttpMethod.GET)).andExpect(MockRestRequestMatchers.header(
HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE))
.andRespond(withSuccess(DATA, MediaType.APPLICATION_JSON));
final Map<String, String> params = new HashMap<>();
params.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE);
final String result = dataLoader.loadData(URL, params);
assertEquals(DATA, result);
}
开发者ID:kbss-cvut,项目名称:reporting-tool,代码行数:11,代码来源:RemoteDataLoaderTest.java
示例14: loadDataPassesQueryParamsToTheService
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void loadDataPassesQueryParamsToTheService() {
final String url = URL + "?a=1&b=2";
mockServer.expect(requestTo(url)).andExpect(method(HttpMethod.GET)).andExpect(MockRestRequestMatchers.header(
HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE))
.andRespond(withSuccess(DATA, MediaType.APPLICATION_JSON));
final Map<String, String> params = new HashMap<>();
params.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE);
params.put("a", "1");
params.put("b", "2");
final String result = dataLoader.loadData(URL, params);
assertEquals(DATA, result);
}
开发者ID:kbss-cvut,项目名称:reporting-tool,代码行数:14,代码来源:RemoteDataLoaderTest.java
示例15: loadDataPassesQueryParamsCorrectlyIfTheUrlAlreadyContainsQueryParam
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void loadDataPassesQueryParamsCorrectlyIfTheUrlAlreadyContainsQueryParam() {
final String url = "http://localhost/formGen?id=generate376Forms-0.2";
final String expectedUrl = url + "&a=1&b=2";
mockServer.expect(requestTo(expectedUrl)).andExpect(method(HttpMethod.GET)).andExpect(MockRestRequestMatchers.header(
HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE))
.andRespond(withSuccess(DATA, MediaType.APPLICATION_JSON));
final Map<String, String> params = new HashMap<>();
params.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_VALUE);
params.put("a", "1");
params.put("b", "2");
final String result = dataLoader.loadData(url, params);
assertEquals(DATA, result);
}
开发者ID:kbss-cvut,项目名称:reporting-tool,代码行数:15,代码来源:RemoteDataLoaderTest.java
示例16: get
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void get() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators
.withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON));
EtcdResponse response = client.get("sample");
Assert.assertNotNull("response", response);
server.verify();
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:12,代码来源:EtcdClientTest.java
示例17: getWithResourceAccessException
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test(expected = EtcdException.class)
public void getWithResourceAccessException() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET))
.andRespond(MockRestResponseCreators.withStatus(HttpStatus.NOT_FOUND)
.contentType(MediaType.APPLICATION_JSON)
.body(new ClassPathResource("EtcdClientTest_get.json")));
try {
client.get("sample");
} finally {
server.verify();
}
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:15,代码来源:EtcdClientTest.java
示例18: getRecursive
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void getRecursive() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?recursive=true"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.GET)).andRespond(MockRestResponseCreators
.withSuccess(new ClassPathResource("EtcdClientTest_get.json"), MediaType.APPLICATION_JSON));
EtcdResponse response = client.get("sample", true);
Assert.assertNotNull("response", response);
server.verify();
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:12,代码来源:EtcdClientTest.java
示例19: put
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void put() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
.andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
.andExpect(MockRestRequestMatchers.content().string("value=Hello+world"))
.andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"),
MediaType.APPLICATION_JSON));
EtcdResponse response = client.put("sample", "Hello world");
Assert.assertNotNull("response", response);
server.verify();
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:15,代码来源:EtcdClientTest.java
示例20: putWithSetTtl
import org.springframework.test.web.client.match.MockRestRequestMatchers; //导入依赖的package包/类
@Test
public void putWithSetTtl() throws EtcdException {
server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl=60"))
.andExpect(MockRestRequestMatchers.method(HttpMethod.PUT))
.andExpect(MockRestRequestMatchers.content().contentType(MediaType.APPLICATION_FORM_URLENCODED))
.andExpect(MockRestRequestMatchers.content().string("value=Hello+world"))
.andRespond(MockRestResponseCreators.withSuccess(new ClassPathResource("EtcdClientTest_set.json"),
MediaType.APPLICATION_JSON));
EtcdResponse response = client.put("sample", "Hello world", 60);
Assert.assertNotNull("response", response);
server.verify();
}
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:15,代码来源:EtcdClientTest.java
注:本文中的org.springframework.test.web.client.match.MockRestRequestMatchers类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论