io.restassured.filter.Filter Java Examples

The following examples show how to use io.restassured.filter.Filter. 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: RestAssuredEdgeGridFilterTest.java    From AkamaiOPEN-edgegrid-java with Apache License 2.0 6 votes vote down vote up
@Test
public void replacesProvidedHostHeader() throws URISyntaxException, IOException,
        RequestSigningException {


    RestAssured.given()
            .relaxedHTTPSValidation()
            .header("Host", "ignored-hostname.com")
            .filter(new RestAssuredEdgeGridFilter(credential))
            .filter(new Filter() {
                @Override
                public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                    MatcherAssert.assertThat(requestSpec.getHeaders().getList("Host").size(),
                            CoreMatchers.equalTo(1));
                    MatcherAssert.assertThat(requestSpec.getHeaders().get("Host").getValue(),
                            CoreMatchers.equalTo(credential.getHost()));

                    return ctx.next(requestSpec, responseSpec);
                }
            })
            .get();


}
 
Example #2
Source File: RestAssuredEdgeGridFilterIntegrationTest.java    From AkamaiOPEN-edgegrid-java with Apache License 2.0 6 votes vote down vote up
@Test
public void replacesProvidedHostHeader() throws URISyntaxException, IOException,
        RequestSigningException {


    RestAssured.given()
            .relaxedHTTPSValidation()
            .header("Host", "ignored-hostname.com")
            .filter(new RestAssuredEdgeGridFilter(credential))
            .filter(new Filter() {
                @Override
                public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                    MatcherAssert.assertThat(requestSpec.getHeaders().getList("Host").size(),
                            CoreMatchers.equalTo(1));
                    MatcherAssert.assertThat(requestSpec.getHeaders().get("Host").getValue(),
                            CoreMatchers.equalTo(credential.getHost()));

                    return ctx.next(requestSpec, responseSpec);
                }
            })
            .get();


}
 
Example #3
Source File: LoadRunnerFeature.java    From cukes with Apache License 2.0 5 votes vote down vote up
@Override
public void run(RunNotifier notifier) {
    RestAssured.filters(filter);
    filter.createLoadRunnerAction();
    super.run(notifier);

    try {
        File dir = new File(LOADRUNNER_OUTPUT_DIR);
        if (!dir.exists()) {
            boolean mkdirsFailed = !dir.mkdirs();
            if (mkdirsFailed) throw new CukesRuntimeException("Failed to create Folder: " + LOADRUNNER_OUTPUT_DIR);
        }

        String fileName = createName(extractFeatureName()) + ".c";
        File file = new File(LOADRUNNER_OUTPUT_DIR + File.separator + fileName);
        OutputStream out = new FileOutputStream(file);
        filter.dump(out);
        out.close();

        logger.info(file.getAbsolutePath());

        ArrayList<Filter> filtersCopy = new ArrayList<Filter>(RestAssured.filters());
        filtersCopy.remove(filter);
        RestAssured.replaceFiltersWith(filtersCopy);
    } catch (Exception e) {
        throw new CukesRuntimeException(e);
    }
}
 
Example #4
Source File: RestAssuredIntegrationTest.java    From AkamaiOPEN-edgegrid-java with Apache License 2.0 5 votes vote down vote up
@Test
public void replaceProvidedHostHeaderOnlyInApacheClient() throws URISyntaxException, IOException,
        RequestSigningException {

    wireMockServer.stubFor(get(urlPathEqualTo("/billing-usage/v1/reportSources"))
            .withHeader("Authorization", matching(".*"))
            .willReturn(aResponse()
                    .withStatus(200)));

    getBaseRequestSpecification()
            .header("Host", "ignored-hostname.com")
            .filter(new Filter() {
                @Override
                public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
                    MatcherAssert.assertThat(requestSpec.getHeaders().getList("Host").size(),
                            CoreMatchers.equalTo(1));
                    MatcherAssert.assertThat(requestSpec.getHeaders().get("Host").getValue(),
                            CoreMatchers.equalTo("ignored-hostname.com"));
                    return ctx.next(requestSpec, responseSpec);
                }
            })
            .get("/billing-usage/v1/reportSources");


    List<LoggedRequest> loggedRequests = wireMockServer.findRequestsMatching(RequestPattern
            .everything()).getRequests();
    MatcherAssert.assertThat(loggedRequests.get(0).getHeader("Host"),
            CoreMatchers.equalTo(SERVICE_MOCK));

}
 
Example #5
Source File: AbstractDocumentationTests.java    From spring-cloud-netflix with Apache License 2.0 4 votes vote down vote up
private RequestSpecification spec(Filter... filters) {
	return spec(null, filters);
}