private void captureBodyIfRequired(HttpRealRequest realRequest, ClientDriverExpectation matchedExpectation) { ClientDriverRequest request = matchedExpectation.getPair().getRequest(); if (request.getBodyCapture() != null) { request.getBodyCapture().setBody(realRequest.getBodyContent()); } }
/** * Creates a new rule with a driver running on the specified port. * * @param port The port on which the driver should listen */ public ClientDriverRule(int port) { clientDriver = new ClientDriverFactory().createClientDriver(port); }
/** * Creates a new {@link ClientDriverRequest} object. * * @param path * The path to match * @return The newly created request */ public static ClientDriverRequest onRequestTo(Pattern path) { return new ClientDriverRequest(path); }
private boolean isSameMethod(RealRequest realRequest, ClientDriverRequest expectedRequest) { if (!realRequest.getMethod().equals(expectedRequest.getMethod())) { LOGGER.info("({} {}) REJECTED on method: expected {} != {}", realRequest.getMethod(), realRequest.getPath(), expectedRequest.getMethod(), realRequest.getMethod()); return false; } return true; }
/** * Shutdown the server and calls {@link #verify()}. */ public void shutdown() { shutdownQuietly(); verify(); }
/** * Creates a new {@link ClientDriverResponse} object with no content. * * @return The newly created response */ public static ClientDriverResponse giveEmptyResponse() { return new ClientDriverResponse(); }
/** * The base URL of the underlying ClientDriver. * * @return The base URL String <b>There is no trailing slash on this</b>. */ public String getBaseUrl() { return clientDriver.getBaseUrl(); }
/** * When you want to verify, that following request was executed, you can use this method. * Given, you have a proxy controller in your application, which checks some params, and depending on them, * send request to some local service(captured by ClientDriverRule). You are writing integration tests and you * want to verify, that when you pass something - service is not receiving requests. * @param clientDriverRequest */ public void verify(ClientDriverRequest clientDriverRequest, int times) { clientDriver.verify(clientDriverRequest, times); }
/** * The port that the underlying ClientDriver is listening too. * * @return the listening port. */ public int getPort() { return clientDriver.getPort(); }
/** * Resets the expectations and requests in the handler. */ public void reset() { clientDriver.reset(); }
/** * Make the mock not fail fast on an unexpected request. */ public void noFailFastOnUnexpectedRequest() { clientDriver.noFailFastOnUnexpectedRequest(); }
/** * Indicate that this expectation has been matched. * * @param realRequest * the request we're matching against */ public final void match(HttpRealRequest realRequest) { numberOfMatches += 1; matchedRequestHandler.onMatch(realRequest); }
private void captureBodyIfRequired(HttpRealRequest realRequest, ClientDriverExpectation matchedExpectation) { ClientDriverRequest request = matchedExpectation.getPair().getRequest(); if (request.getBodyCapture() != null) { request.getBodyCapture().setBody(realRequest.getBodyContent()); } }
private boolean isSameMethod(RealRequest realRequest, ClientDriverRequest expectedRequest) { if (!realRequest.getMethod().equals(expectedRequest.getMethod())) { LOGGER.info("({} {}) REJECTED on method: expected {} != {}", realRequest.getMethod(), realRequest.getPath(), expectedRequest.getMethod(), realRequest.getMethod()); return false; } return true; }
/** * Creates a new rule with a driver running on the specified port. * * @param port The port on which the driver should listen */ public ClientDriverRule(int port) { clientDriver = new ClientDriverFactory().createClientDriver(port); }
/** * Creates a new {@link ClientDriverResponse} object with no content. * * @return The newly created response */ public static ClientDriverResponse giveEmptyResponse() { return new ClientDriverResponse(); }
/** * Creates a new {@link ClientDriverRequest} object. * * @param path * The path to match * @return The newly created request */ public static ClientDriverRequest onRequestTo(Matcher<? extends String> path) { return new ClientDriverRequest(path); }
/** * The base URL of the underlying ClientDriver. * * @return The base URL String <b>There is no trailing slash on this</b>. */ public String getBaseUrl() { return clientDriver.getBaseUrl(); }
/** * When you want to verify, that following request was executed, you can use this method. * Given, you have a proxy controller in your application, which checks some params, and depending on them, * send request to some local service(captured by ClientDriverRule). You are writing integration tests and you * want to verify, that when you pass something - service is not receiving requests. * @param clientDriverRequest */ public void verify(ClientDriverRequest clientDriverRequest, int times) { clientDriver.verify(clientDriverRequest, times); }
/** * Creates a new {@link ClientDriverResponse} object. * * @param content * The content to return * @param contentType * The content-type of the response * @return The newly created response */ public static ClientDriverResponse giveResponseAsBytes(InputStream content, String contentType) { return new ClientDriverResponse(content, contentType); }