org.mockserver.integration.ClientAndServer Java Examples
The following examples show how to use
org.mockserver.integration.ClientAndServer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 7 votes |
@Test public void getErrorTest() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("GET")) .respond(HttpResponse.response().withStatusCode(700).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals("1", httpClient.get("http://localhost:5000/hs")); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #2
Source File: PGPKeysServerClientIT.java From pgpverify-maven-plugin with Apache License 2.0 | 7 votes |
@BeforeClass public void setupMockServer() { mockServer = ClientAndServer.startClientAndServer(0); ConfigurationProperties.disableSystemOut(true); ConfigurationProperties.logLevel("WARNING"); MockServerClient mockServerClient = new MockServerClient("localhost", mockServer.getLocalPort()); mockServerClient .when(request().withPath("/sleep")) .respond(response() .withStatusCode(200) .withDelay(TimeUnit.SECONDS, 10)); mockServerClient .when(request().withPath("/404")) .respond(response().withStatusCode(404)); mockServerClient .when(request().withPath("/502")) .respond(response().withStatusCode(502)); }
Example #3
Source File: CertificateAuthoritiesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private ClientAndServer setupTestGetMetadataAllValuesSet() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"JDkpnLkaC1Q\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"caaIdentities\": [" + System.lineSeparator() + " \"happy-hacker-ca.invalid\"," + System.lineSeparator() + " \"happy-hacker2-ca.invalid\"" + System.lineSeparator() + " ]," + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"," + System.lineSeparator() + " \"website\": \"https://github.com/letsencrypt/boulder\"," + System.lineSeparator() + " \"externalAccountRequired\": true" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}"; return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .build(); }
Example #4
Source File: CollaboratorServiceExTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 6 votes |
@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(); }
Example #5
Source File: MockCruiseControl.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
public static void setupCCStopResponse(ClientAndServer ccServer) throws IOException, URISyntaxException { JsonBody jsonStop = getJsonFromResource("CC-Stop.json"); ccServer .when( request() .withMethod("POST") .withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true|false")) .withPath(CruiseControlEndpoints.STOP.path)) .respond( response() .withBody(jsonStop) .withHeaders(header("User-Task-ID", "stopped")) .withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC)); }
Example #6
Source File: MockCruiseControl.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
public static void setupCCUserTasksCompletedWithError(ClientAndServer ccServer) throws IOException, URISyntaxException { // This simulates asking for the status of a task that has Complete with error and fetch_completed_task=true JsonBody compWithErrorJson = getJsonFromResource("CC-User-task-status-completed-with-error.json"); ccServer .when( request() .withMethod("GET") .withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")) .withQueryStringParameter(Parameter.param(CruiseControlParameters.FETCH_COMPLETE.key, "true")) .withPath(CruiseControlEndpoints.USER_TASKS.path)) .respond( response() .withBody(compWithErrorJson) .withStatusCode(200) .withHeaders(header("User-Task-ID", USER_TASK_REBALANCE_NO_GOALS_RESPONSE_UTID)) .withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC)); }
Example #7
Source File: OdooXmlRpcProxyTest.java From openerp-java-api with Apache License 2.0 | 6 votes |
@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); } }
Example #8
Source File: MockCruiseControl.java From strimzi-kafka-operator with Apache License 2.0 | 6 votes |
public static void setupCCRebalanceNotEnoughDataError(ClientAndServer ccServer) throws IOException, URISyntaxException { // Rebalance response with no goal that returns an error JsonBody jsonError = getJsonFromResource("CC-Rebalance-NotEnoughValidWindows-error.json"); ccServer .when( request() .withMethod("POST") .withQueryStringParameter(Parameter.param(CruiseControlParameters.JSON.key, "true")) .withQueryStringParameter(Parameter.param(CruiseControlParameters.DRY_RUN.key, "true|false")) .withQueryStringParameter(Parameter.param(CruiseControlParameters.VERBOSE.key, "true|false")) .withPath(CruiseControlEndpoints.REBALANCE.path)) .respond( response() .withStatusCode(500) .withBody(jsonError) .withHeaders(header(CruiseControlApi.CC_REST_API_USER_ID_HEADER, REBALANCE_NOT_ENOUGH_VALID_WINDOWS_ERROR_RESPONSE_UTID)) .withDelay(TimeUnit.SECONDS, RESPONSE_DELAY_SEC)); }
Example #9
Source File: HealthCheckServiceUnitTest.java From galeb with Apache License 2.0 | 6 votes |
@BeforeClass public static void setupClass() { environmentVariables.set("ENVIRONMENT_NAME", "env1"); environmentVariables.set("ZONE_ID", "zone1"); mockServer = ClientAndServer.startClientAndServer(BACKEND_PORT); mockServer.when(HttpRequest.request() .withMethod("GET") .withPath("/") .withHeaders( Header.header("user-agent", "Galeb_HealthChecker/1.0"), Header.header(NottableString.not("cookie"))) .withKeepAlive(true)) .respond(HttpResponse.response() .withCookie(new Cookie("session", "test-cookie")) .withStatusCode(HttpStatus.OK.value())); mockTCPOnlyServer(); }
Example #10
Source File: MockServerTestHelper.java From mutual-tls-ssl with Apache License 2.0 | 6 votes |
public MockServerTestHelper(ClientType clientType) { clientAndServer = ClientAndServer.startClientAndServer(8080); mockServerClient = new MockServerClient("127.0.0.1", 8080); mockServerClient .when( HttpRequest.request() .withMethod("GET") .withPath("/api/hello") .withHeader("client-type", clientType.getValue()), Times.unlimited(), TimeToLive.unlimited()) .respond( HttpResponse.response() .withBody("Hello") .withStatusCode(200) ); }
Example #11
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 6 votes |
@Test public void postError3Test() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(200).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals(1, httpClient.post("http://localhost:5001/hs", "1", TestDemo.class).getT()); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #12
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 6 votes |
@Test public void postError2Test() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(700).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals(1, httpClient.post("http://localhost:5000/hs", "1", TestDemo.class).getT()); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #13
Source File: CertificateAuthoritiesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
private ClientAndServer setupTestGetMetadataSomeValuesSet() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"LRkPnZpS4yE\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}" + System.lineSeparator(); return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .build(); }
Example #14
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 6 votes |
@Test public void postError1Test() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(200).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals("1", httpClient.post("http://localhost:5001/hs", "1")); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #15
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 6 votes |
@Test public void postErrorTest() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(700).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals("1", httpClient.post("http://localhost:5000/hs", "1")); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #16
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 6 votes |
@Test public void getError1Test() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("GET")) .respond(HttpResponse.response().withStatusCode(700).withBody("1")); HttpClient httpClient = new HttpClient(); boolean rs = false; try { assertEquals("1", httpClient.get("http://localhost:50001/hs")); } catch (Exception e) { rs = true; } assertEquals(true, rs); } finally { mockClient.stop(true); } }
Example #17
Source File: CertificateAuthoritiesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ClientAndServer setupTestGetMetadataNoValuesSet() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"N6HzXUZ-eWI\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}" + System.lineSeparator(); return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .build(); }
Example #18
Source File: CertificateAuthoritiesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@BeforeClass public static void initTests() { server = new ClientAndServer(4001); AccessController.doPrivileged(new PrivilegedAction<Integer>() { public Integer run() { return Security.insertProviderAt(wildFlyElytronProvider, 1); } }); csUtil = new CredentialStoreUtility("target/tlstest.keystore", CS_PASSWORD); csUtil.addEntry("the-key-alias", "Elytron"); csUtil.addEntry("master-password-alias", "Elytron"); }
Example #19
Source File: KeyStoresTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ClientAndServer setupTestRevokeCertificateWithReason() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"oBarDLD1zzc\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"caaIdentities\": [" + System.lineSeparator() + " \"happy-hacker-ca.invalid\"" + System.lineSeparator() + " ]," + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"," + System.lineSeparator() + " \"website\": \"https://github.com/letsencrypt/boulder\"" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}" + System.lineSeparator(); final String NEW_NONCE_RESPONSE = "zincwFvSlMEm-Dg4LsDtx1JBKaWnu2qiBYBUG6jSZLiexMY"; final String QUERY_ACCT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImp3ayI6eyJlIjoiQVFBQiIsImt0eSI6IlJTQSIsIm4iOiJoOE9lZTViZURSZ3hOUGVfZU1FOUg2Vm83NEZ1ZzhIZ3Jpa2ZiZkNhVTNsS0Y2NDhRRzFYMWtHRFpUaEF5OGRhcUo4YnY2YzNQSmRueDJIcjhqT3psNTA5Ym5NNmNDV2Z5d1RwY0lab1V6UVFaTFlfSzhHTURBeWdsc1FySXRnQ2lRYWxJcWJ1SkVrb2MzV1FBSXhKMjN4djliSzV4blZRa1RXNHJWQkFjWU5Rd29CakdZT1dTaXpUR2ZqZ21RcVRYbG9hYW1GWkpuOTdIbmIxcWp5NVZZbTA2YnV5cXdBYUdIczFDTHUzY0xaZ1FwVkhRNGtGc3prOFlPNVVBRWppb2R1Z1dwWlVSdTlUdFJLek4wYmtFZGVRUFlWcGF1cFVxMWNxNDdScDJqcVZVWGRpUUxla3l4clFidDhBMnVHNEx6RFF1LWI0Y1pwcG16YzNobGhTR3cifSwibm9uY2UiOiJ6aW5jd0Z2U2xNRW0tRGc0THNEdHgxSkJLYVdudTJxaUJZQlVHNmpTWkxpZXhNWSIsInVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL25ldy1hY2N0In0\",\"payload\":\"eyJvbmx5UmV0dXJuRXhpc3RpbmciOnRydWV9\",\"signature\":\"bFUmpw50SUd29FFzPgpZw-lkSzl8tlO4ZEUkxRNyL3NSfBZvKDUpPA9P4gg7NkKq-kLl09O2_w_9zoDu_AxIpfylnBuQmK3PGA_f61tQHjWG41hX7NaPUqPieFiEMD4EC7-z4oEN2O79hdCLzhtujwkX8kUav7q60VoUDdmLongJkoQJYHqYJisYmmvGBf28qe3jq9KmgeLav33z8xdsg3i-Cc7jZDWdRMtY72PqEMT53WhYBof15HXrrSZf5b6AAEOX8xMfPkMvx0p_TG2RCEiYY-L7yxgE634_-ye146uUL47X7h5ajmuqu3EsOL4456cjpcKGyhpU9aAhCDKHNQ\"}"; final String QUERY_ACCT_RESPONSE_BODY= ""; final String QUERY_ACCT_REPLAY_NONCE = "taroaIprXC7Gi1SYzYi8ETK0IooQwJyv-Qsv4ALL-xw8uu0"; final String ACCT_LOCATION = "http://localhost:4001/acme/acct/5"; final String REVOKE_CERT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL2FjY3QvNSIsIm5vbmNlIjoidGFyb2FJcHJYQzdHaTFTWXpZaThFVEswSW9vUXdKeXYtUXN2NEFMTC14dzh1dTAiLCJ1cmwiOiJodHRwOi8vbG9jYWxob3N0OjQwMDEvYWNtZS9yZXZva2UtY2VydCJ9\",\"payload\":\"eyJjZXJ0aWZpY2F0ZSI6Ik1JSUZSVENDQkMyZ0F3SUJBZ0lUQVA4S2RpM2JyejdmaTlHYkpDM2pQRGxUT2pBTkJna3Foa2lHOXcwQkFRc0ZBREFmTVIwd0d3WURWUVFEREJSb01uQndlU0JvTW1OclpYSWdabUZyWlNCRFFUQWVGdzB4T1RBM01UWXhOekV5TURkYUZ3MHhPVEV3TVRReE56RXlNRGRhTUI0eEhEQWFCZ05WQkFNVEUyMXVaR1ZzYTJSdVltTnBiRzlvWnk1amIyMHdnZ0VpTUEwR0NTcUdTSWIzRFFFQkFRVUFBNElCRHdBd2dnRUtBb0lCQVFDSXhLNzVXS0dCSzJ4Y0F1QWVfTmJPRnJvcUJaU3hHUFZFOWd0Y0lMRF9HU0hSYzFWbHNmc2x1UXpsdThiSDNnaW91OFdEUU85NDNYaUxWdldJSU1oSGQ4MzJZM0xRdXMwQnlUeEtlUnVubXdhVjdHWkZoQTNr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fb3KSoz1IUOagemSZzUgbPNwIIJMSnQuRXW8ScOECssoDTy_R4OL6drkyxN8qXP7dJUQ4T4rTRBXnSEv1fUHFBZLRvVb2jqMc-Iiwp6hjdahBlWqPudiMyD8pinghyns0m5btw_OmOWERMEI4lIsOJjVg2Tu7HALDiLGSk6dyUV1HXyAeWBVr1QJBFeq2Gw3rD-26d1w\"}"; final String REVOKE_CERT_REPLAY_NONCE = "zinci0BXolnLRwsa-i7xBiVz4Zy0LDbw7hjIv9UvBDP10CQ"; return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .addNewNonceResponse(NEW_NONCE_RESPONSE) .addNewAccountRequestAndResponse(QUERY_ACCT_REQUEST_BODY, QUERY_ACCT_RESPONSE_BODY, QUERY_ACCT_REPLAY_NONCE, ACCT_LOCATION, 200) .addRevokeCertificateRequestAndResponse(REVOKE_CERT_REQUEST_BODY, REVOKE_CERT_REPLAY_NONCE, 200) .build(); }
Example #20
Source File: KeyStoresTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ClientAndServer setupTestRevokeCertificateWithoutReason() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"caaIdentities\": [" + System.lineSeparator() + " \"happy-hacker-ca.invalid\"" + System.lineSeparator() + " ]," + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"," + System.lineSeparator() + " \"website\": \"https://github.com/letsencrypt/boulder\"" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"," + System.lineSeparator() + " \"kgIgyHU3yA0\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"" + System.lineSeparator() + "}" + System.lineSeparator(); final String NEW_NONCE_RESPONSE = "taroDvhk2H7ErEkhFCq8zux1hCbY0KzFQDEFGjMaSvvCC_k"; final String QUERY_ACCT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImp3ayI6eyJlIjoiQVFBQiIsImt0eSI6IlJTQSIsIm4iOiJoOE9lZTViZURSZ3hOUGVfZU1FOUg2Vm83NEZ1ZzhIZ3Jpa2ZiZkNhVTNsS0Y2NDhRRzFYMWtHRFpUaEF5OGRhcUo4YnY2YzNQSmRueDJIcjhqT3psNTA5Ym5NNmNDV2Z5d1RwY0lab1V6UVFaTFlfSzhHTURBeWdsc1FySXRnQ2lRYWxJcWJ1SkVrb2MzV1FBSXhKMjN4djliSzV4blZRa1RXNHJWQkFjWU5Rd29CakdZT1dTaXpUR2ZqZ21RcVRYbG9hYW1GWkpuOTdIbmIxcWp5NVZZbTA2YnV5cXdBYUdIczFDTHUzY0xaZ1FwVkhRNGtGc3prOFlPNVVBRWppb2R1Z1dwWlVSdTlUdFJLek4wYmtFZGVRUFlWcGF1cFVxMWNxNDdScDJqcVZVWGRpUUxla3l4clFidDhBMnVHNEx6RFF1LWI0Y1pwcG16YzNobGhTR3cifSwibm9uY2UiOiJ0YXJvRHZoazJIN0VyRWtoRkNxOHp1eDFoQ2JZMEt6RlFERUZHak1hU3Z2Q0NfayIsInVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL25ldy1hY2N0In0\",\"payload\":\"eyJvbmx5UmV0dXJuRXhpc3RpbmciOnRydWV9\",\"signature\":\"WpICzZNwgHJckeO7fn8rytSB23poud38FEg1fwmVvd3rag-KLZ5rOrqmOzr6BIUpaY0DEeZ03QzQFYIoywVNg8Apvbh12RZvkWW_VuIfpnJOz6dWOhV-lM5aH9oVy7mW9nNVqzqlTEyWRXPGo8XSD_vWtxSu-zLbHOTvnURiiCOO3DM96xRZrnvexTI97RRO6cBrI4HzjSBpat03YOkwxEWzrbqdZD7RVgUxTh6ELK7BE1U87IF2iBO_V1VllUZdH9P2EiTtFBwj5xkBXhyeBiTj2BqWzb4-Y5o_W0b5hMX1IQiPa-zb56L-SkcEJMNu-hJSGmPy6uoRJVAwCHcP-w\"}"; final String QUERY_ACCT_RESPONSE_BODY= ""; final String QUERY_ACCT_REPLAY_NONCE = "zincgzgBIqMgfFmkcIQYn6rGST-aEs9SOGlh0b8u4QYFqiA"; final String ACCT_LOCATION = "http://localhost:4001/acme/acct/5"; final String REVOKE_CERT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImtpZCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL2FjY3QvNSIsIm5vbmNlIjoiemluY2d6Z0JJcU1nZkZta2NJUVluNnJHU1QtYUVzOVNPR2xoMGI4dTRRWUZxaUEiLCJ1cmwiOiJodHRwOi8vbG9jYWxob3N0OjQwMDEvYWNtZS9yZXZva2UtY2VydCJ9\",\"payload\":\"eyJjZXJ0aWZpY2F0ZSI6Ik1JSUZUVENDQkRXZ0F3SUJBZ0lUQVA4b01Ib3hOS19JbWdkN3lzelh3S2RXd3pBTkJna3Foa2lHOXcwQkFRc0ZBREFmTVIwd0d3WURWUVFEREJSb01uQndlU0JvTW1OclpYSWdabUZyWlNCRFFUQWVGdzB4T1RBM01UWXhOalE0TWpkYUZ3MHhPVEV3TVRReE5qUTRNamRhTUNFeEh6QWRCZ05WQkFNVEZtbHViRzVsYzJWd2NIZHJabmRsZDNaNE1pNWpiMjB3Z2dFaU1BMEdDU3FHU0liM0RRRUJBUVVBQTRJQkR3QXdnZ0VLQW9JQkFRQ1NaQllqclZ0S05jbFVhQV9nZ3hJaGNSVVdrOUVJbXBJMG5heWQwaURsYUdUWkxicTZVNHZvUWxzNkRDZmpzdzIwU2QzdTgzb2RqTDU2QUdOeHBIUzZaYTVjN3RLS1hGUm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tNe7I0VMXMqfB8ClNydSoNdAL9OB1m9syZT7ijZxq_RldTWLsCIDDdWom1xEgb3RUCpTTMUMhsTQZdf5t3y0CNa5p7wfCT8ejLcQ3aYMUm-chDjn4nC8YBdGVSlpacLdafrsDeoTFSF8yhCL9pBk_hz8FMXFKS3ctCBGVJTIHeWPWvnYJn4owEAjbmVqC_khACM-Zo7N-Gx7--47_qyG4dW2IvYansrMrlIwLlwDtmPig\"}"; final String REVOKE_CERT_REPLAY_NONCE = "taroo4s_zllDSu1x5i0l1x595sQJalOjAPXRnz6oc7vMiHc"; return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .addNewNonceResponse(NEW_NONCE_RESPONSE) .addNewAccountRequestAndResponse(QUERY_ACCT_REQUEST_BODY, QUERY_ACCT_RESPONSE_BODY, QUERY_ACCT_REPLAY_NONCE, ACCT_LOCATION, 200) .addRevokeCertificateRequestAndResponse(REVOKE_CERT_REQUEST_BODY, REVOKE_CERT_REPLAY_NONCE, 200) .build(); }
Example #21
Source File: KeyStoresTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ClientAndServer setupTestCreateAccountWithoutAgreeingToTermsOfService() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"oyv-_7dfkxs\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"caaIdentities\": [" + System.lineSeparator() + " \"happy-hacker-ca.invalid\"" + System.lineSeparator() + " ]," + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"," + System.lineSeparator() + " \"website\": \"https://github.com/letsencrypt/boulder\"" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}"; final String NEW_NONCE_RESPONSE = "zinctnSRWv_CmPz5dhMgom1tppGmuXIqB8X8pZO_0YTF1Nc"; final String NEW_ACCT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImp3ayI6eyJlIjoiQVFBQiIsImt0eSI6IlJTQSIsIm4iOiJsblhXQ1JDUUpLOW93RXMzMVZrVFNLLWZ2aDcxMDVYOVhYNUFRaVYtbXgxRkJtdU95OVBBS3JTTUlNcXR2ZXk2REhRY0gwVzc5OGp4X3MwRFFmekhCb1E1aU56YUFtVDFhMG5xN3hBemhsRGM5YXZ6WndiTDl0WW1nV3pDM0VQZm1PcXVlNTFoQkZ0VzN3X29IaHpaeTU5YUV2bmZra0hfalJLYUdZRFlPb3F4VXNfNmNXMTVGV3JmWERhOVFIUEVkUEdHTEt6ZTF1aW92bGxON2dNdWZkUFdzZElKRGhwOU1JSGhhVTZjOUZSSDhRS0I1WXlSd0dYR0ZpVmNZU1cyUWtsQkxJN0EzWkdWd2Y5YXNOR0VoUzZfRUxIc2FZVnR3LWFwd1NSSnM1ZnlwVTZidFRDS2J0dUN3X0M0T1FtQXExNDRmdkstOEJSUk1WaE56Qkh6SXcifSwibm9uY2UiOiJ6aW5jdG5TUld2X0NtUHo1ZGhNZ29tMXRwcEdtdVhJcUI4WDhwWk9fMFlURjFOYyIsInVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL25ldy1hY2N0In0\",\"payload\":\"eyJ0ZXJtc09mU2VydmljZUFncmVlZCI6ZmFsc2UsImNvbnRhY3QiOlsibWFpbHRvOmFkbWluQGFuZXhhbXBsZS5jb20iXX0\",\"signature\":\"OhI4lDd6BsTlKvqMsiBY8bCnfozYsclQPpB7apFVuP0BTfO9iUbybiZ1gHDRGsyUF84gMoBaozZX6iMIApBW9j21uQuWBCGyn-wyM_Fu6n5ruenNQPYyiQteiVYP36oXuSKT76AnsoqXbX5NHfvjOlPiREmD95sfKRuvlsDlgaRD1hGU5qFNt9gTr90vVADPrMN20O0QKSCx5d4cKjm2BvD4oM4xA-Qll2HCREeb40F7eeIGUdCxHflHQOPObm2JBHm2lhOieankj0HPunP43L607iCZ8W2DAaX6EKDfMYunnnbpj9vXkkRUm7yEi4LNRs6OS4Hc-LHqKsgWoWc3kQ\"}"; final String NEW_ACCT_RESPONSE_BODY = "{" + System.lineSeparator() + " \"type\": \"urn:ietf:params:acme:error:malformed\"," + System.lineSeparator() + " \"detail\": \"must agree to terms of service\"," + System.lineSeparator() + " \"status\": 400" + System.lineSeparator() + "}"; final String NEW_ACCT_REPLAY_NONCE = "tarobHhNBawhfG-BpSmsBEpiESawT4Aw_k-sX2rqwjl-Mac"; final String NEW_ACCT_LOCATION = ""; return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .addNewNonceResponse(NEW_NONCE_RESPONSE) .addNewAccountRequestAndResponse(NEW_ACCT_REQUEST_BODY, NEW_ACCT_RESPONSE_BODY, NEW_ACCT_REPLAY_NONCE, NEW_ACCT_LOCATION, 400, true) .build(); }
Example #22
Source File: KeyStoresTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@BeforeClass public static void initTests() throws Exception { server = new ClientAndServer(4001); setUpFiles(); AccessController.doPrivileged(new PrivilegedAction<Integer>() { public Integer run() { return Security.insertProviderAt(wildFlyElytronProvider, 1); } }); csUtil = new CredentialStoreUtility("target/tlstest.keystore", CS_PASSWORD); csUtil.addEntry("the-key-alias", "Elytron"); csUtil.addEntry("master-password-alias", "Elytron"); createServerEnvironment(); }
Example #23
Source File: BaseClientTest.java From bdt with Apache License 2.0 | 5 votes |
protected void startMockServer() throws Exception { ConfigurationProperties.logLevel("ERROR"); port = PortFactory.findFreePort(); logger.info("Starting mock server..."); mockServer = ClientAndServer.startClientAndServer(port); logger.info("Mock sever started."); }
Example #24
Source File: CertificateAuthoritiesTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private ClientAndServer setupTestCreateAccountWithoutAgreeingToTermsOfService() { // set up a mock Let's Encrypt server final String DIRECTORY_RESPONSE_BODY = "{" + System.lineSeparator() + " \"oyv-_7dfkxs\": \"https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417\"," + System.lineSeparator() + " \"keyChange\": \"http://localhost:4001/acme/key-change\"," + System.lineSeparator() + " \"meta\": {" + System.lineSeparator() + " \"caaIdentities\": [" + System.lineSeparator() + " \"happy-hacker-ca.invalid\"" + System.lineSeparator() + " ]," + System.lineSeparator() + " \"termsOfService\": \"https://boulder:4431/terms/v7\"," + System.lineSeparator() + " \"website\": \"https://github.com/letsencrypt/boulder\"" + System.lineSeparator() + " }," + System.lineSeparator() + " \"newAccount\": \"http://localhost:4001/acme/new-acct\"," + System.lineSeparator() + " \"newNonce\": \"http://localhost:4001/acme/new-nonce\"," + System.lineSeparator() + " \"newOrder\": \"http://localhost:4001/acme/new-order\"," + System.lineSeparator() + " \"revokeCert\": \"http://localhost:4001/acme/revoke-cert\"" + System.lineSeparator() + "}"; final String NEW_NONCE_RESPONSE = "zinctnSRWv_CmPz5dhMgom1tppGmuXIqB8X8pZO_0YTF1Nc"; final String NEW_ACCT_REQUEST_BODY = "{\"protected\":\"eyJhbGciOiJSUzI1NiIsImp3ayI6eyJlIjoiQVFBQiIsImt0eSI6IlJTQSIsIm4iOiJsblhXQ1JDUUpLOW93RXMzMVZrVFNLLWZ2aDcxMDVYOVhYNUFRaVYtbXgxRkJtdU95OVBBS3JTTUlNcXR2ZXk2REhRY0gwVzc5OGp4X3MwRFFmekhCb1E1aU56YUFtVDFhMG5xN3hBemhsRGM5YXZ6WndiTDl0WW1nV3pDM0VQZm1PcXVlNTFoQkZ0VzN3X29IaHpaeTU5YUV2bmZra0hfalJLYUdZRFlPb3F4VXNfNmNXMTVGV3JmWERhOVFIUEVkUEdHTEt6ZTF1aW92bGxON2dNdWZkUFdzZElKRGhwOU1JSGhhVTZjOUZSSDhRS0I1WXlSd0dYR0ZpVmNZU1cyUWtsQkxJN0EzWkdWd2Y5YXNOR0VoUzZfRUxIc2FZVnR3LWFwd1NSSnM1ZnlwVTZidFRDS2J0dUN3X0M0T1FtQXExNDRmdkstOEJSUk1WaE56Qkh6SXcifSwibm9uY2UiOiJ6aW5jdG5TUld2X0NtUHo1ZGhNZ29tMXRwcEdtdVhJcUI4WDhwWk9fMFlURjFOYyIsInVybCI6Imh0dHA6Ly9sb2NhbGhvc3Q6NDAwMS9hY21lL25ldy1hY2N0In0\",\"payload\":\"eyJ0ZXJtc09mU2VydmljZUFncmVlZCI6ZmFsc2UsImNvbnRhY3QiOlsibWFpbHRvOmFkbWluQGFuZXhhbXBsZS5jb20iXX0\",\"signature\":\"OhI4lDd6BsTlKvqMsiBY8bCnfozYsclQPpB7apFVuP0BTfO9iUbybiZ1gHDRGsyUF84gMoBaozZX6iMIApBW9j21uQuWBCGyn-wyM_Fu6n5ruenNQPYyiQteiVYP36oXuSKT76AnsoqXbX5NHfvjOlPiREmD95sfKRuvlsDlgaRD1hGU5qFNt9gTr90vVADPrMN20O0QKSCx5d4cKjm2BvD4oM4xA-Qll2HCREeb40F7eeIGUdCxHflHQOPObm2JBHm2lhOieankj0HPunP43L607iCZ8W2DAaX6EKDfMYunnnbpj9vXkkRUm7yEi4LNRs6OS4Hc-LHqKsgWoWc3kQ\"}"; final String NEW_ACCT_RESPONSE_BODY = "{" + System.lineSeparator() + " \"type\": \"urn:ietf:params:acme:error:malformed\"," + System.lineSeparator() + " \"detail\": \"must agree to terms of service\"," + System.lineSeparator() + " \"status\": 400" + System.lineSeparator() + "}"; final String NEW_ACCT_REPLAY_NONCE = "tarobHhNBawhfG-BpSmsBEpiESawT4Aw_k-sX2rqwjl-Mac"; final String NEW_ACCT_LOCATION = ""; return new AcmeMockServerBuilder(server) .addDirectoryResponseBody(DIRECTORY_RESPONSE_BODY) .addNewNonceResponse(NEW_NONCE_RESPONSE) .addNewAccountRequestAndResponse(NEW_ACCT_REQUEST_BODY, NEW_ACCT_RESPONSE_BODY, NEW_ACCT_REPLAY_NONCE, NEW_ACCT_LOCATION, 400, true) .build(); }
Example #25
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 5 votes |
@Test public void getTest() throws IOException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("GET")) .respond(HttpResponse.response().withStatusCode(200).withBody("1")); HttpClient httpClient = new HttpClient(); assertEquals("1", httpClient.get("http://localhost:5000/hs")); } finally { mockClient.stop(true); } }
Example #26
Source File: PullRequestServiceExTests.java From HubTurbo with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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(); }
Example #27
Source File: MockClientServerFacade.java From cukes with Apache License 2.0 | 5 votes |
public void startAllServers() { services.keySet().forEach(serviceName -> { int port = Integer.parseInt(worldFacade.get("http.mock.services." + serviceName + ".port") .or( () -> { throw new CukesRuntimeException("No port provided for mock service " + serviceName + ". Please provide property cukes.http.mock.services." + serviceName + ".port"); })); ClientAndServer server = ClientAndServer.startClientAndServer(port); servers.put(serviceName, server); }); }
Example #28
Source File: FileDownloadManagerIntegrationTest.java From alf.io with GNU General Public License v3.0 | 5 votes |
@BeforeClass public static void startServer() { mockServer = ClientAndServer.startClientAndServer(4242); mockServer .when(HttpRequest.request().withMethod("GET").withPath("/test.txt")) .respond(HttpResponse.response() .withStatusCode(200) .withHeader("Content-Type", "text/plain; charset=utf-8") .withBody("Hello World!")); mockServer .when(HttpRequest.request().withMethod("GET").withPath("/404")) .respond(HttpResponse.response().withStatusCode(404)); }
Example #29
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 5 votes |
@Test public void postTest() throws IOException, BrokerException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(200).withBody("1")); HttpClient httpClient = new HttpClient(); assertEquals("1", httpClient.post("http://localhost:5000/hs", "1")); } finally { mockClient.stop(true); } }
Example #30
Source File: HttpClientTest.java From pmq with Apache License 2.0 | 5 votes |
@Test public void post1Test() throws IOException, BrokerException { ClientAndServer mockClient = new ClientAndServer(5000); try { mockClient.when(HttpRequest.request().withMethod("POST")) .respond(HttpResponse.response().withStatusCode(200).withBody("{\"t\":1}")); HttpClient httpClient = new HttpClient(); assertEquals(1, httpClient.post("http://localhost:5000/hs", "1", TestDemo.class).getT()); } finally { mockClient.stop(true); } }