本文整理汇总了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")
);
}
示例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();
}
示例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)));
}
示例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);
}
}
示例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")
);
}
示例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();
}
示例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);
}
}
示例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;
}
示例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();
}
示例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;
}
示例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"));
}
示例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();
}
示例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")
);
}
示例14: verifyRequestsClientAndProxy
import org.mockserver.integration.ClientAndServer; //导入依赖的package包/类
public void verifyRequestsClientAndProxy() {
new ClientAndServer(1080)
.verify(
request()
.withPath("/some/path"),
VerificationTimes.atLeast(2)
);
}
示例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);
}
}
}
}
}