本文整理汇总了Java中org.mockserver.integration.ClientAndServer.startClientAndServer方法的典型用法代码示例。如果您正苦于以下问题:Java ClientAndServer.startClientAndServer方法的具体用法?Java ClientAndServer.startClientAndServer怎么用?Java ClientAndServer.startClientAndServer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mockserver.integration.ClientAndServer
的用法示例。
在下文中一共展示了ClientAndServer.startClientAndServer方法的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: 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;
}
示例6: 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"));
}
示例7: 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();
}
示例8: 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);
}
}
示例9: 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();
}
示例10: startServer
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@BeforeClass
public static void startServer() {
mockServer = ClientAndServer.startClientAndServer(7755);
}
示例11: beforeClass
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@BeforeClass
public void beforeClass() {
mockServer = ClientAndServer.startClientAndServer(port);
}
示例12: startServer
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Before
public void startServer() {
server = ClientAndServer.startClientAndServer(PortFactory.findFreePort());
serverUrl = "http://127.0.0.1:" + server.getPort();
}
示例13: startServer
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Before
public void startServer() {
server = ClientAndServer.startClientAndServer(PortFactory.findFreePort());
serverUrl = "127.0.0.1:" + server.getPort();
}
示例14: start
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@BeforeClass
public void start() {
int port = PortFactory.findFreePort();
tokenEndpointUri = "https://localhost:" + port + "/oauth2/token";
mockServer = ClientAndServer.startClientAndServer(port);
}
示例15: setup
import org.mockserver.integration.ClientAndServer; //导入方法依赖的package包/类
@Before
public void setup() {
mockServer = ClientAndServer.startClientAndServer(port);
}