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


Java ClientAndServer类代码示例

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


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

示例1: startServer

import org.mockserver.integration.ClientAndServer; //导入依赖的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: getCollaborators_validRepoId_successful

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Test
public void getCollaborators_validRepoId_successful() throws IOException {
    MockServerClient mockServer = ClientAndServer.startClientAndServer(8888);
    String sampleCollaborators = TestUtils.readFileFromResource(this, "tests/CollaboratorsSample.json");

    mockServer.when(
            request()
                .withPath(TestUtils.API_PREFIX + "/repos/hubturbo/tests/collaborators")
    ).respond(response().withBody(sampleCollaborators));

    Type listOfUsers = new TypeToken<List<User>>() {}.getType();
    List<User> expectedCollaborators = new Gson().fromJson(sampleCollaborators, listOfUsers);
    List<User> actualCollaborators = service.getCollaborators(RepositoryId.createFromId("hubturbo/tests"));

    assertEquals(expectedCollaborators.size(), actualCollaborators.size());

    for (int i = 0; i < expectedCollaborators.size(); i++) {
        assertEquals(expectedCollaborators.get(i).getLogin(), actualCollaborators.get(i).getLogin());
        assertEquals(expectedCollaborators.get(i).getName(), actualCollaborators.get(i).getName());
        assertEquals(true, actualCollaborators.get(i).getName() != null);
    }

    mockServer.stop();
}
 
开发者ID:HubTurbo,项目名称:HubTurbo,代码行数:25,代码来源:CollaboratorServiceExTests.java

示例3: startServer

import org.mockserver.integration.ClientAndServer; //导入依赖的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

示例4: should_return_server_version

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Test
public void should_return_server_version() throws Exception {
	// Make sure SSL works by adding MockServer CA certificate to context
	SSLSocketFactory previousFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
	HttpsURLConnection.setDefaultSSLSocketFactory(SSLFactory.getInstance().sslContext().getSocketFactory());
	ClientAndServer mockServer = ClientAndServer.startClientAndServer(port);
	try {
		// Given: the server expects a request of its version
		mockServer
				.when(request().withMethod("POST").withPath("/xmlrpc/2/db")
						.withBody(new StringBody(
								"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>server_version</methodName><params/></methodCall>")))
				.respond(response().withStatusCode(200).withBody(
						"<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><string>9.0e</string></value>\n</param>\n</params>\n</methodResponse>\n"));

		// When: Server version is requested
		Version version = OdooXmlRpcProxy.getServerVersion(RPCProtocol.RPC_HTTPS, host, port);

		// Then: the server version is returned
		assertThat(version).as("Server version").isNotNull().hasToString("9.0e");
	} finally {
		mockServer.stop();
		HttpsURLConnection.setDefaultSSLSocketFactory(previousFactory);
	}

}
 
开发者ID:DeBortoliWines,项目名称:openerp-java-api,代码行数:27,代码来源:OdooXmlRpcProxyTest.java

示例5: createExpectationClientAndServer

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
public void createExpectationClientAndServer() {
    new ClientAndServer(1080)
        .when(
            request()
                .withMethod("GET")
                .withPath("/view/cart")
                .withCookies(
                    cookie("session", "4930456C-C718-476F-971F-CB8E047AB349")
                )
                .withQueryStringParameters(
                    param("cartId", "055CA455-1DF7-45BB-8535-4F83E7266092")
                )
        )
        .respond(
            response()
                .withBody("some_response_body")
        );
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:19,代码来源:MockServerClientExamples.java

示例6: shouldStartAndStopMockServerOncePerSuite

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Test
public void shouldStartAndStopMockServerOncePerSuite() throws Throwable {
    // when
    mockServerRulePerSuite.apply(mockStatement, Description.EMPTY).evaluate();

    // then
    assertThat((ClientAndServer) mockServerClient, is(mockClientAndServer));
    assertThat(mockServerRulePerSuite.getPort(), is(httpPort));
    assertThat(mockServerRulePerSuite.getPorts(), is(new Integer[]{httpPort + 1, httpPort + 2}));
    verify(mockStatement).evaluate();
    verify(clientAndServerFactory, times(1)).newClientAndServer();
    verify(mockClientAndServer, times(0)).stop();

    reset(mockStatement, clientAndServerFactory);

    // when
    mockServerRulePerSuiteDuplicate.apply(mockStatement, Description.EMPTY).evaluate();

    // then
    assertThat((ClientAndServer) mockServerClient, is(mockClientAndServer));
    assertThat(mockServerRulePerSuiteDuplicate.getPort(), is(httpPort));
    assertThat(mockServerRulePerSuiteDuplicate.getPorts(), is(new Integer[]{httpPort + 1, httpPort + 2}));
    verify(mockStatement).evaluate();
    verify(clientAndServerFactory, times(0)).newClientAndServer();
    verify(mockClientAndServer, times(0)).stop();
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:27,代码来源:MockServerRuleTestWithMocks.java

示例7: startProxy

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@BeforeClass
public static void startProxy() throws Exception {
	if (isUsingMockServer()) {
		previousFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
		HttpsURLConnection.setDefaultSSLSocketFactory(SSLFactory.getInstance().sslContext().getSocketFactory());
		proxy = ClientAndProxy.startClientAndProxy(PortFactory.findFreePort());
		mockServer = ClientAndServer.startClientAndServer(MOCKSERVER_PORT);
	}
}
 
开发者ID:DeBortoliWines,项目名称:openerp-java-api,代码行数:10,代码来源:SessionTest.java

示例8: startServer

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@BeforeClass
public static void startServer() throws Exception {
    int port = PortFactory.findFreePort();
    System.out.println("port is " + port);
    mockServer = ClientAndServer.startClientAndServer(port);
    baseUrl = "http://localhost:" + port;
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:8,代码来源:BaseMockServerTest.java

示例9: setUp

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    webServer = new Server(0);
    webServer.start();
    webServerPort = TestUtils.findLocalHttpPort(webServer);

    mockServer = new ClientAndServer(0);
    mockServerPort = mockServer.getPort();

}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:11,代码来源:HttpFilterTest.java

示例10: setUp

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    mockServer = new ClientAndServer(0);
    mockServerPort = mockServer.getPort();
    socket = null;
    proxyServer = null;
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:8,代码来源:KeepAliveTest.java

示例11: startProxy

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@BeforeClass
public static void startProxy() throws Exception {

  int port = PortFactory.findFreePort();
  clientAndProxy = startClientAndProxy(port);
  proxy = new HttpHost("localhost", port);
  // load truststore with MockServer CA
  sslContext = SSLContexts.custom().loadTrustMaterial(new File("src/test/resources/truststore.jks"), "changeit".toCharArray()).build();
  httpClientBuilder = HttpClients.custom().setSSLContext(sslContext);
  httpclient = httpClientBuilder.build();

  serverPort = PortFactory.findFreePort();
  clientAndServer = ClientAndServer.startClientAndServer(serverPort);
  clientAndServer.when(new HttpRequest().withMethod("GET")).respond(HttpResponse.response("OK"));
}
 
开发者ID:confluentinc,项目名称:support-metrics-common,代码行数:16,代码来源:WebClientProxyTest.java

示例12: testGetReviewComments

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
/**
 * Tests that getReviewComments method correctly receives 1 page of review comments
 * returned from a MockServer that emulates GitHub API service.
 */
@Test
public void testGetReviewComments() throws IOException {
    MockServerClient mockServer = ClientAndServer.startClientAndServer(8888);
    String sampleComments = TestUtils.readFileFromResource(this, "tests/ReviewCommentsSample.json");

    mockServer.when(
            request()
                    .withPath(TestUtils.API_PREFIX + "/repos/hubturbo/hubturbo/pulls/1125/comments")
                    .withQueryStringParameters(
                            new Parameter("per_page", "100"),
                            new Parameter("page", "1")
                    )
    ).respond(response().withBody(sampleComments));

    GitHubClient client = new GitHubClient("localhost", 8888, "http");
    PullRequestServiceEx service = new PullRequestServiceEx(client);

    Type listOfComments = new TypeToken<List<ReviewComment>>() {
    }.getType();
    List<ReviewComment> expectedComments = new Gson().fromJson(sampleComments, listOfComments);
    List<ReviewComment> actualComments = service.getReviewComments(
            RepositoryId.createFromId("hubturbo/hubturbo"), 1125);

    assertEquals(expectedComments.size(), actualComments.size());

    Comparator<ReviewComment> comparator = (a, b) -> (int) (a.getId() - b.getId());
    Collections.sort(expectedComments, comparator);
    Collections.sort(actualComments, comparator);

    for (int i = 0; i < expectedComments.size(); i++) {
        assertEquals(expectedComments.get(i).getId(), actualComments.get(i).getId());
    }

    mockServer.stop();

}
 
开发者ID:HubTurbo,项目名称:HubTurbo,代码行数:41,代码来源:PullRequestServiceExTests.java

示例13: classCallback

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
public void classCallback() {
    new ClientAndServer(1080)
        .when(
            request()
                .withPath("/some.*")
        )
        .respond(
            callback()
                .withCallbackClass("org.mockserver.examples.mockserver.CallbackActionExamples$TestExpectationResponseCallback")
        );
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:12,代码来源:CallbackActionExamples.java

示例14: verifyRequestsClientAndProxy

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
public void verifyRequestsClientAndProxy() {
    new ClientAndServer(1080)
        .verify(
            request()
                .withPath("/some/path"),
            VerificationTimes.atLeast(2)
        );
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:9,代码来源:ProxyClientExamples.java

示例15: setMockServerClient

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
private void setMockServerClient(Object target, ClientAndServer clientAndServer) {
    for (Class<?> clazz = target.getClass(); !clazz.equals(Object.class); clazz = clazz.getSuperclass()) {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.getType().equals(MockServerClient.class)) {
                field.setAccessible(true);
                try {
                    field.set(target, clientAndServer);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Error setting MockServerClient field on " + target.getClass().getName(), e);
                }
            }
        }
    }
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:15,代码来源:MockServerRule.java


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