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

Java ClientAndServer类代码示例

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

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



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


示例16: setUp

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@Before
public void setUp() {
    server = ClientAndServer.startClientAndServer();
    server
        .when(
            request()
                .withPath("/my/echo")
        )
        .respond(callback()
            .withCallbackClass("org.mockserver.integration.mocking.ConcurrencyBasicResponseMockingIntegrationTest$ClassCallback"));
    httpClient = new NettyHttpClient();
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:13,代码来源:ConcurrencyBasicResponseMockingIntegrationTest.java


示例17: startServer

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@BeforeClass
public static void startServer() {
    mockServerClient = startClientAndServer(0, PortFactory.findFreePort(), 0, PortFactory.findFreePort());
    List<Integer> boundPorts = ((ClientAndServer) mockServerClient).getLocalPorts();
    severHttpPort = boundPorts.toArray(new Integer[boundPorts.size()]);

    echoServer = new EchoServer(false);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:9,代码来源:MultiplePortMockingIntegrationTest.java


示例18: startServer

import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
@BeforeClass
public static void startServer() {
    mockServerClient = startClientAndServer();
    mockServerPort = ((ClientAndServer) mockServerClient).getLocalPort();

    echoServer = new EchoServer(false);
}
 
开发者ID:jamesdbloom,项目名称:mockserver,代码行数:8,代码来源:ClientAndServerMockingIntegrationTest.java


示例19: shouldStartAndStopMockServerWithDynamicPort

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

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


示例20: shouldStartAndStopMockServerWithSinglePort

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

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



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Cell类代码示例发布时间:2022-05-21
下一篇:
Java SunDropTargetContextPeer类代码示例发布时间: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