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


Java MockRestResponseCreators类代码示例

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


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

示例1: testStandardTags

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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: testStandardTagsWithPort

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例3: testParentSpan

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例4: interceptRestTemplate

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例5: normalizeUriToContainLeadingSlash

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例6: compareAndSwapWithPrevExistAndSetTtl

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例7: should_delete_message_after_fetching

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例8: testSuccessGetProviderDetailsFromId

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的package包/类
@Parameters({ "null", "http://endpoint.com" })
@Test
public void testSuccessGetProviderDetailsFromId(@Nullable String oneZoneEndpoint)
    throws IOException {

  String spaceId = UUID.randomUUID().toString();

  ProviderDetails providerDetail = generateProviderDetails();
  String providerId = providerDetail.getProviderId();

  String endpoint = generateExpectedOneZoneEndpoint(oneZoneEndpoint);
  mockServer
      .expect(requestTo(
          endpoint + onezoneBasePath + "spaces/" + spaceId + "/providers/" + providerId))
      .andExpect(method(HttpMethod.GET))
      .andExpect(header("macaroon", onedataToken))
      .andRespond(MockRestResponseCreators.withSuccess(JsonUtility.serializeJson(providerDetail),
          MediaType.APPLICATION_JSON_UTF8));

  assertThat(oneDataService.getProviderDetailsFromId(endpoint, onedataToken, spaceId, providerId))
      .isEqualTo(providerDetail);
  mockServer.verify();
}
 
开发者ID:indigo-dc,项目名称:orchestrator,代码行数:24,代码来源:OneDataServiceTest.java

示例9: testFailGetProviderDetailsFromId

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的package包/类
@Parameters({ "null", "http://endpoint.com" })
@Test
public void testFailGetProviderDetailsFromId(@Nullable String oneZoneEndpoint) {

  String spaceId = UUID.randomUUID().toString();
  String providerId = UUID.randomUUID().toString();

  String endpoint = generateExpectedOneZoneEndpoint(oneZoneEndpoint);

  mockServer
      .expect(requestTo(
          endpoint + onezoneBasePath + "spaces/" + spaceId + "/providers/" + providerId))
      .andExpect(method(HttpMethod.GET))
      .andExpect(header("macaroon", onedataToken))
      .andRespond(MockRestResponseCreators.withBadRequest());

  assertThatThrownBy(
      () -> oneDataService.getProviderDetailsFromId(endpoint, onedataToken, spaceId, providerId))
          .isInstanceOf(DeploymentException.class);
  mockServer.verify();
}
 
开发者ID:indigo-dc,项目名称:orchestrator,代码行数:22,代码来源:OneDataServiceTest.java

示例10: get

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例11: getWithResourceAccessException

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例12: getRecursive

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例13: put

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例14: putWithSetTtl

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的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

示例15: putWithUnsetTtl

import org.springframework.test.web.client.response.MockRestResponseCreators; //导入依赖的package包/类
@Test
public void putWithUnsetTtl() throws EtcdException {
	server.expect(MockRestRequestMatchers.requestTo("http://localhost:2379/v2/keys/sample?ttl="))
			.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", -1);
	Assert.assertNotNull("response", response);

	server.verify();
}
 
开发者ID:zalando-stups,项目名称:spring-boot-etcd,代码行数:15,代码来源:EtcdClientTest.java


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