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


Java HttpResponse类代码示例

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


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

示例1: startServer

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void startServer() {
  mockServer = ClientAndServer.startClientAndServer(7755);

  MockServerClient client = new MockServerClient("localhost", 7755)
    .reset();

  client.when(HttpRequest.request()
        .withMethod("PUT")
        .withPath("/v0.3/traces")
        .withHeaders(new Header("Content-Type", "application/msgpack")),
        Times.exactly(1), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
    .respond(HttpResponse.response()
        .withStatusCode(200)
        .withHeaders(new Header("Content-Type", "text/plain"))
        .withBody("OK\n")
    );
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:18,代码来源:WriterBackoffTest.java

示例2: emulateV0_2

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void emulateV0_2() {
  MockServerClient client = new MockServerClient("localhost", APM_PORT).reset();

  client.when(
      HttpRequest.request()
          .withMethod("PUT")
          .withPath("/v0.3/traces"), Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
      .respond(HttpResponse.response()
          .withStatusCode(404)
          .withHeaders(new Header("Content-Type", "text/plain")));

  client.when(
      HttpRequest.request()
          .withMethod("PUT")
          .withPath("/v0.2/traces"), Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
      .respond(HttpResponse.response()
          .withStatusCode(200)
          .withHeaders(new Header("Content-Type", "text/plain"))
          .withBody("OK\n").withDelay(new Delay(TimeUnit.MILLISECONDS, 20)));
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:22,代码来源:HelloIT.java

示例3: emulateV0_2

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void emulateV0_2() {
  MockServerClient client = new MockServerClient("localhost", APM_PORT)
    .reset();

  client
    .when(HttpRequest.request().withMethod("PUT").withPath("/v0.3/traces"),
        Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
    .respond(HttpResponse.response().withStatusCode(404)
      .withHeaders(new Header("Content-Type", "text/plain"))
  );

  client
    .when(HttpRequest.request().withMethod("PUT").withPath("/v0.2/traces"),
      Times.unlimited(), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
    .respond(HttpResponse.response().withStatusCode(200)
      .withHeaders(new Header("Content-Type", "text/plain")).withBody("OK\n")
      .withDelay(new Delay(TimeUnit.MILLISECONDS, 20)));
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:20,代码来源:HelloIT.java

示例4: emailUser

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void emailUser(MockServerClient mockServerClient) {

        mockServerClient.
        dumpToLog().
        when(
            HttpRequest.request()
            .withMethod("POST")
            .withCookie(Cookie.cookie("session", "0a1bc2a7-11ef-4781-9c06-8d9b42719797"))
            .withCookie(Cookie.cookie("username", "jdoe"))
            .withPath("/user/email")
            .withBody("{\"name\":\"John Doe\"}"),
            Times.unlimited()
        ).respond(
            HttpResponse.response()
            .withStatusCode(200)
            
        );        
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:19,代码来源:MockServerInitializationClass.java

示例5: mutateUser

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void mutateUser(MockServerClient mockServerClient) {

    mockServerClient.
    dumpToLog().
    when(
        HttpRequest.request()
        .withMethod("PUT")
        .withCookie(Cookie.cookie("session", "aa8a2e85-412e-46a2-889f-b2c133a59c89"))
        .withPath("/user")
        .withBody("{\"name\":\"John Doe\"}"),
        Times.unlimited()
    ).respond(
        HttpResponse.response()
        .withStatusCode(200)
        
    );        
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:18,代码来源:MockServerInitializationClass.java

示例6: getUsers

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUsers(MockServerClient mockServerClient) {

        mockServerClient
        .dumpToLog()
        .when(
            HttpRequest.request()
            .withMethod("GET")
            .withPath("/user")
            .withHeader(Header.header("X-SESSION-ID", "020835c7-cf7e-4ba5-b117-4402e5d79079"))
            .withQueryStringParameter(Parameter.param("byUsername", "jdoe")),
            Times.unlimited()
        ).respond(
            HttpResponse.response()
            .withStatusCode(200)
            .withBody("{ \"users\" : [{ \"name\" : \"John Doe\" }] }")
        );
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:18,代码来源:MockServerInitializationClass.java

示例7: getUser

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUser(MockServerClient mockServerClient) {

        mockServerClient
        .dumpToLog()
        .when(
            HttpRequest.request()
            .withMethod("GET")
            .withHeader(Header.header("X-SESSION-ID", "55892d6d-77df-4617-b728-6f5de97f5752"))
            .withPath("/user/jdoe"),
            Times.unlimited()
        ).respond(
            HttpResponse.response()
            .withStatusCode(200)
            .withBody("{ \"name\" : \"John Doe\" }")
        );
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:17,代码来源:MockServerInitializationClass.java

示例8: getCachedUser

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getCachedUser(MockServerClient mockServerClient) {

        mockServerClient
        .dumpToLog()
        .when(
            HttpRequest.request()
            .withMethod("GET")
            .withHeader(Header.header("X-SESSION-ID", "55892d6d-77df-4617-b728-6f5de97f5752"))
            .withPath("/user/bdoe"),
            Times.unlimited()
        ).respond(
            HttpResponse.response()
            .withStatusCode(200)
            .withHeader(Header.header("Cache-Control","no-transform,public,max-age=300,s-maxage=900"))
            .withBody("{ \"name\" : \"Bob Doe\" }")
        );
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:18,代码来源:MockServerInitializationClass.java

示例9: getUserAddress

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getUserAddress(MockServerClient mockServerClient) {

        mockServerClient
        .dumpToLog()
        .when(
            HttpRequest.request()
            .withMethod("GET")
            .withHeader(Header.header("Cache-Control", "no-cache"))
            .withPath("/user/address/jdoe"),
            Times.unlimited()
        ).respond(
            HttpResponse.response()
            .withStatusCode(200)
            .withBody("{ \"address\" : \"1060 W Addison St, Chicago, IL 60613\" }")
        );
    }
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:17,代码来源:MockServerInitializationClass.java

示例10: getRoleUsers

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void getRoleUsers(MockServerClient mockServerClient) {

    mockServerClient
    .dumpToLog()
    .when(
        HttpRequest.request()
        .withMethod("GET")
        .withPath("/user/role")
        .withQueryStringParameter(Parameter.param("byRole", "vanessa")),
        Times.unlimited()
    ).respond(
        HttpResponse.response()
        .withStatusCode(200)
        .withBody("{ \"users\" : [] }")
    );
}
 
开发者ID:kenzanlabs,项目名称:bowtie,代码行数:17,代码来源:MockServerInitializationClass.java

示例11: testEnableAuth

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Test
public void testEnableAuth() throws Exception {
  VaultConfiguration conf = VaultConfigurationBuilder.newVaultConfiguration()
      .withAddress(address)
      .withToken(token)
      .build();

  new MockServerClient(localhost, mockServerRule.getPort())
      .when(
      HttpRequest.request()
          .withMethod("POST")
          .withHeader(tokenHeader)
          .withPath("/v1/sys/auth/app-id")
          .withBody("{\"type\":\"app-id\"}"),
      Times.exactly(1)
  )
  .respond(
      HttpResponse.response()
          .withStatusCode(HttpStatusCode.NO_CONTENT_204.code())
          .withHeader(contentJson)
  );

  VaultClient vault = new VaultClient(conf);
  assertTrue(vault.sys().auth().enable("app-id", "app-id"));
}
 
开发者ID:streamsets,项目名称:datacollector,代码行数:26,代码来源:TestAuth.java

示例12: addEndpoint

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void addEndpoint(String baseURL, String endpointName, MockServerClient mockServerClient) {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("mock_responses/" + endpointName + "_response.json")) {
        String response = getStringFromResource(is);
        mockServerClient.when(HttpRequest.request()
                .withMethod("POST")
                .withPath(baseURL + endpointName))
                .respond(HttpResponse.response()
                        .withStatusCode(200)
                        .withHeaders(
                                new Header(HttpHeaders.CONTENT_TYPE, "application/json")
                        )
                        .withBody(response));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:17,代码来源:MockRosetteInitialization.java

示例13: addSentimentADM

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void addSentimentADM(String baseURL, MockServerClient mockServerClient) {
    try (InputStream is = getClass().getClassLoader().getResourceAsStream("mock_responses/sentiment_adm_response.json")) {
        String response = getStringFromResource(is);
        mockServerClient.when(HttpRequest.request()
                .withMethod("POST")
                .withPath(baseURL + "sentiment").withQueryStringParameter(new Parameter("output", "rosette")))
                .respond(HttpResponse.response()
                        .withStatusCode(200)
                        .withHeaders(
                                new Header(HttpHeaders.CONTENT_TYPE, "application/json")
                        )
                        .withBody(response));
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }
}
 
开发者ID:rosette-api,项目名称:rosette-elasticsearch-plugin,代码行数:17,代码来源:MockRosetteInitialization.java

示例14: startServer

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
@Before
public void startServer() {
  mockServer = ClientAndServer.startClientAndServer(7755);

  new MockServerClient("localhost", 7755)
      .when(HttpRequest.request().withMethod("PUT"), 
          Times.exactly(1),
          TimeToLive.exactly(TimeUnit.MINUTES, 1l))
      .respond(HttpResponse.response().withStatusCode(200)
          .withHeaders(new Header("Content-Type", "text/plain")).withBody("OK\n")
          .withDelay(new Delay(TimeUnit.SECONDS, 1)));
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:13,代码来源:ApmApiTest.java

示例15: expectations

import org.mockserver.model.HttpResponse; //导入依赖的package包/类
private void expectations(int status) {
  MockServerClient client = new MockServerClient("localhost", 7755)
    .reset();

  client.when(HttpRequest.request()
        .withMethod("PUT")
        .withPath("/v0.3/traces")
        .withHeaders(new Header("Content-Type", "application/msgpack")),
        Times.exactly(1), TimeToLive.exactly(TimeUnit.MINUTES, 1l))
    .respond(HttpResponse.response()
        .withStatusCode(status)
        .withHeaders(new Header("Content-Type", "text/plain"))
    );
  client.when(HttpRequest.request()
        .withMethod("PUT")
        .withPath("/v0.2/traces")
        .withHeaders(new Header("Content-Type", "application/json")),
        Times.exactly(1),
        TimeToLive.exactly(TimeUnit.MINUTES, 1l))
    .respond(HttpResponse.response()
        .withStatusCode(200)
        .withHeaders(new Header("Content-Type", "text/plain"))
        .withBody("OK\n")
    );
}
 
开发者ID:chonton,项目名称:apm-client,代码行数:26,代码来源:WriterTest.java


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