io.restassured.config.RestAssuredConfig Java Examples
The following examples show how to use
io.restassured.config.RestAssuredConfig.
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: VerifySSLComponentTest.java From riposte with Apache License 2.0 | 8 votes |
@Test public void verify_get(){ String responseString= given() .config(RestAssuredConfig.newConfig().sslConfig(new SSLConfig().relaxedHTTPSValidation())) .baseUri("https://127.0.0.1") .port(serverConfig.endpointsSslPort()) .basePath(SSLTestEndpoint.MATCHING_PATH) .log().all() .when() .get() .then() .log().all() .statusCode(200) .extract().asString(); assertThat(responseString).isEqualTo(RESPONSE_STRING); }
Example #2
Source File: IncompletePostTestCase.java From quarkus with Apache License 2.0 | 6 votes |
@Test public void testIncompleteWrite() throws Exception { PostEndpoint.invoked = false; //make sure incomplete writes do not block threads //and that incoplete data is not delivered to the endpoint for (int i = 0; i < 1000; ++i) { Socket socket = new Socket(url.getHost(), url.getPort()); socket.getOutputStream().write( "POST /post HTTP/1.1\r\nHost: localhost\r\nContent-length:10\r\n\r\ntest".getBytes(StandardCharsets.UTF_8)); socket.getOutputStream().flush(); socket.getOutputStream().close(); socket.close(); } Assertions.assertFalse(PostEndpoint.invoked); RestAssuredConfig config = RestAssured.config() .httpClient(HttpClientConfig.httpClientConfig() .setParam(CoreConnectionPNames.CONNECTION_TIMEOUT, 1000) .setParam(CoreConnectionPNames.SO_TIMEOUT, 1000)); RestAssured.given().config(config).get("/post").then().body(Matchers.is("ok")); }
Example #3
Source File: VerifyProxySSLComponentTest.java From riposte with Apache License 2.0 | 6 votes |
@Test public void verify_get() { String responseString = given() .config(RestAssuredConfig.newConfig().sslConfig(new SSLConfig().relaxedHTTPSValidation())) .baseUri("http://127.0.0.1") .port(proxyServerConfig.endpointsPort()) .basePath(RouterEndpoint.MATCHING_PATH) .log().all() .when() .get() .then() .log().all() .statusCode(200) .extract().asString(); assertThat(responseString).isEqualTo(RESPONSE_STRING); }
Example #4
Source File: CurlLoggingRestAssuredConfigFactory.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static HttpClientConfig.HttpClientFactory getHttpClientFactory(RestAssuredConfig config) { try { Field f = HttpClientConfig.class.getDeclaredField("httpClientFactory"); f.setAccessible(true); HttpClientConfig httpClientConfig = config.getHttpClientConfig(); HttpClientConfig.HttpClientFactory httpClientFactory = (HttpClientConfig.HttpClientFactory) f.get(httpClientConfig); f.setAccessible(false); return httpClientFactory; } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } }
Example #5
Source File: AbstractApiMethod.java From carina with Apache License 2.0 | 5 votes |
public void setSSLContext(SSLContext sslContext) { SSLSocketFactory socketFactory = new SSLSocketFactory(sslContext); SSLConfig sslConfig = new SSLConfig(); sslConfig = sslConfig.sslSocketFactory(socketFactory); RestAssuredConfig cfg = new RestAssuredConfig(); cfg = cfg.sslConfig(sslConfig); request = request.config(cfg); }
Example #6
Source File: RestAssuredIntegrationTest.java From AkamaiOPEN-edgegrid-java with Apache License 2.0 | 5 votes |
private static RestAssuredConfig getRestAssuredConfig(final ClientCredential credential) { return RestAssuredConfig.config().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(new HttpClientConfig.HttpClientFactory() { @Override public HttpClient createHttpClient() { final DefaultHttpClient client = new DefaultHttpClient(); client.addRequestInterceptor(new ApacheHttpClientEdgeGridInterceptor(credential)); client.setRoutePlanner(new ApacheHttpClientEdgeGridRoutePlanner(credential)); return client; } })); }
Example #7
Source File: RestAssuredConfiguration.java From cukes with Apache License 2.0 | 5 votes |
private RestAssuredConfig buildRestAssuredConfig() { RestAssuredConfig config = newConfig() .jsonConfig(jsonConfig().numberReturnType(JsonPathConfig.NumberReturnType.BIG_DECIMAL)) .redirect(redirectConfig().followRedirects(world.getBoolean(CukesOptions.FOLLOW_REDIRECTS, true))); if(logStream != null) config = config.logConfig(logConfig().defaultStream(logStream)); if (!world.getBoolean(CukesOptions.GZIP_SUPPORT, true)) { config = config.decoderConfig(decoderConfig().contentDecoders(DEFLATE)); } config = config.sslConfig(new SSLConfig().allowAllHostnames()); return config; }
Example #8
Source File: CurlLoggingInterceptorTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void shouldLogStacktraceWhenEnabled() { // given log = TestLoggerFactory.getTestLogger("curl"); log.clearAll(); Options options = Options.builder().logStacktrace().build(); RestAssuredConfig restAssuredConfig = getRestAssuredConfig(new CurlLoggingInterceptor(options)); // when //@formatter:off given() .redirects().follow(false) .baseUri(MOCK_BASE_URI) .port(MOCK_PORT) .config(restAssuredConfig) .when() .get("/shouldLogStacktraceWhenEnabled") .then() .statusCode(200); //@formatter:on // then assertThat(log.getAllLoggingEvents().size(), is(1)); LoggingEvent firstEvent = log.getLoggingEvents().get(0); assertThat(firstEvent.getLevel(), is(Level.DEBUG)); assertThat(firstEvent.getMessage(), both(startsWith("curl")).and(containsString("generated")) .and(containsString(("java.lang.Thread.getStackTrace")))); }
Example #9
Source File: CurlLoggingInterceptorTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void shouldLogDebugMessageWithCurlCommand() { // given log = TestLoggerFactory.getTestLogger("curl"); log.clearAll(); Options OPTIONS = Options.builder().dontLogStacktrace().build(); RestAssuredConfig restAssuredConfig = getRestAssuredConfig(new CurlLoggingInterceptor(OPTIONS)); // when //@formatter:off given() .redirects().follow(false) .baseUri(MOCK_BASE_URI) .port(MOCK_PORT) .config(restAssuredConfig) .when() .get("/") .then() .statusCode(200); //@formatter:on // then assertThat(log.getLoggingEvents().size(), is(1)); LoggingEvent firstEvent = log.getLoggingEvents().get(0); assertThat(firstEvent.getLevel(), is(Level.DEBUG)); assertThat(firstEvent.getMessage(), startsWith("curl")); }
Example #10
Source File: CurlLoggingInterceptorTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static RestAssuredConfig getRestAssuredConfig( CurlLoggingInterceptor curlLoggingInterceptor) { return config() .httpClient(httpClientConfig() .reuseHttpClientInstance() .httpClientFactory(new MyHttpClientFactory(curlLoggingInterceptor))); }
Example #11
Source File: CurlLoggingRestAssuredConfigFactoryTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void shouldIncludeCurlInterceptorWhenUpdatingExistingConfig() { HttpClientConfig httpClientConfig = HttpClientConfig.httpClientConfig() .setParam("TestParam", "TestValue") .httpClientFactory( new HttpClientConfig.HttpClientFactory() { @Override public HttpClient createHttpClient() { DefaultHttpClient client = new DefaultHttpClient(); client.addRequestInterceptor(new MyRequestInerceptor()); return client; } } ); final RestAssuredConfig config = RestAssuredConfig.config() .httpClient(httpClientConfig); RestAssuredConfig updatedConfig = CurlLoggingRestAssuredConfigFactory.updateConfig(config, Options.builder().build()); // original configuration has not been modified assertThat(updatedConfig, not(equalTo(config))); AbstractHttpClient clientConfig = (AbstractHttpClient) config.getHttpClientConfig().httpClientInstance(); assertThat(clientConfig, not(new ContainsRequestInterceptor(CurlLoggingInterceptor.class))); assertThat(clientConfig, new ContainsRequestInterceptor(MyRequestInerceptor.class)); assertThat(updatedConfig.getHttpClientConfig().params().get("TestParam"), equalTo("TestValue")); // curl logging interceptor is included AbstractHttpClient updateClientConfig = (AbstractHttpClient) updatedConfig.getHttpClientConfig().httpClientInstance(); assertThat(updateClientConfig, new ContainsRequestInterceptor(CurlLoggingInterceptor.class)); // original interceptors are preserved in new configuration assertThat(updateClientConfig, new ContainsRequestInterceptor(MyRequestInerceptor.class)); // original parameters are preserved in new configuration assertThat(updatedConfig.getHttpClientConfig().params().get("TestParam"), equalTo("TestValue")); }
Example #12
Source File: CurlLoggingRestAssuredConfigFactory.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Updates a given REST-assured configuration to generate curl command using custom options. * * @param config an original configuration to update * @param options options defining curl generation * @return updated configuration; note original configuration remain unchanged. */ public static RestAssuredConfig updateConfig(RestAssuredConfig config, Options options) { HttpClientConfig.HttpClientFactory originalFactory = getHttpClientFactory(config); return config .httpClient(config.getHttpClientConfig() .reuseHttpClientInstance() .httpClientFactory(new MyHttpClientFactory(originalFactory, new CurlLoggingInterceptor(options)))); }
Example #13
Source File: VerifyResponseSenderExceptionBehaviorComponentTest.java From riposte with Apache License 2.0 | 5 votes |
private RestAssuredConfig noRetryRestAssuredConfig() { return RestAssuredConfig .config() .httpClient(HttpClientConfig.httpClientConfig().httpClientFactory( () -> { DefaultHttpClient result = new DefaultHttpClient(); result.setHttpRequestRetryHandler((exception, executionCount, context) -> false); return result; }) ); }
Example #14
Source File: JLineupWebApplicationTests.java From jlineup with Apache License 2.0 | 5 votes |
@Before public void setUp() { RestAssured.port = port; RestAssured.config = RestAssuredConfig.config().objectMapperConfig(new ObjectMapperConfig().jackson2ObjectMapperFactory( (cls, charset) -> objectMapper )); }
Example #15
Source File: AccessLogFileTestCase.java From quarkus with Apache License 2.0 | 5 votes |
@Test public void testSingleLogMessageToFile() throws IOException, InterruptedException { // issue the request with a specific HTTP protocol version, so that we can then verify // the protocol value logged in the access log file final RestAssuredConfig http10Config = RestAssured.config().httpClient( new HttpClientConfig().setParam(CoreProtocolPNames.PROTOCOL_VERSION, new ProtocolVersion("HTTP", 1, 0))); final RequestSpecification requestSpec = new RequestSpecBuilder().setConfig(http10Config).build(); final String paramValue = UUID.randomUUID().toString(); RestAssured.given(requestSpec).get("/does-not-exist?foo=" + paramValue); Awaitility.given().pollInterval(100, TimeUnit.MILLISECONDS) .atMost(10, TimeUnit.SECONDS) .untilAsserted(new ThrowingRunnable() { @Override public void run() throws Throwable { try (Stream<Path> files = Files.list(logDirectory)) { Assertions.assertEquals(1, (int) files.count()); } Path path = logDirectory.resolve("server.log"); Assertions.assertTrue(Files.exists(path)); String data = new String(Files.readAllBytes(path), StandardCharsets.UTF_8); Assertions.assertTrue(data.contains("404")); Assertions.assertTrue(data.contains("/does-not-exist")); Assertions.assertTrue(data.contains("?foo=" + paramValue), "access log is missing query params"); Assertions.assertFalse(data.contains("?foo=" + paramValue + "?foo=" + paramValue), "access log contains duplicated query params"); Assertions.assertTrue(data.contains("HTTP/1.0"), "HTTP/1.0 protocol value is missing in the access log"); } }); }
Example #16
Source File: IntegrationTest.java From prebid-server-java with Apache License 2.0 | 5 votes |
static RequestSpecification spec(int port) { return new RequestSpecBuilder() .setBaseUri("http://localhost") .setPort(port) .setConfig(RestAssuredConfig.config() .objectMapperConfig(new ObjectMapperConfig(new Jackson2Mapper((aClass, s) -> mapper)))) .build(); }
Example #17
Source File: ArtifactsResourceTest.java From apicurio-registry with Apache License 2.0 | 5 votes |
@Test public void testWsdlArtifact() throws Exception { String artifactId = "testWsdlArtifact"; ArtifactType artifactType = ArtifactType.WSDL; String artifactContent = resourceToString("sample.wsdl"); // Create OpenAPI artifact (from YAML) given() .config(RestAssuredConfig.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs(CT_XML, ContentType.TEXT))) .when() .contentType(CT_XML) .header("X-Registry-ArtifactId", artifactId) .header("X-Registry-ArtifactType", artifactType.name()) .body(artifactContent) .post("/artifacts") .then() .statusCode(200) .body("id", equalTo(artifactId)) .body("type", equalTo(artifactType.name())); this.waitForArtifact(artifactId); // Get the artifact content (should be XML) given() .when() .pathParam("artifactId", "testWsdlArtifact") .get("/artifacts/{artifactId}") .then() .statusCode(200) .header("Content-Type", Matchers.containsString(CT_XML)); }
Example #18
Source File: ArtifactsResourceTest.java From apicurio-registry with Apache License 2.0 | 4 votes |
@Test public void testYamlContentType() throws Exception { String artifactId = "testYamlContentType"; ArtifactType artifactType = ArtifactType.OPENAPI; String artifactContent = resourceToString("openapi-empty.yaml"); // Create OpenAPI artifact (from YAML) given() .config(RestAssuredConfig.config().encoderConfig(EncoderConfig.encoderConfig().encodeContentTypeAs(CT_YAML, ContentType.TEXT))) .when() .contentType(CT_YAML) .header("X-Registry-ArtifactId", artifactId) .header("X-Registry-ArtifactType", artifactType.name()) .body(artifactContent) .post("/artifacts") .then() .statusCode(200) .body("id", equalTo(artifactId)) .body("name", equalTo("Empty API")) .body("description", equalTo("An example API design using OpenAPI.")) .body("type", equalTo(artifactType.name())); this.waitForArtifact(artifactId); // Get the artifact content (should be JSON) given() .when() .pathParam("artifactId", "testYamlContentType") .get("/artifacts/{artifactId}") .then() .statusCode(200) .header("Content-Type", Matchers.containsString(CT_JSON)) .body("openapi", equalTo("3.0.2")) .body("info.title", equalTo("Empty API")); }
Example #19
Source File: CurlLoggingRestAssuredConfigFactoryTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test public void shouldIncludeCurlInterceptorWhenCreatingConfig() { RestAssuredConfig updatedConfig = CurlLoggingRestAssuredConfigFactory.createConfig(); AbstractHttpClient updateClientConfig = (AbstractHttpClient) updatedConfig.getHttpClientConfig().httpClientInstance(); assertThat(updateClientConfig, new ContainsRequestInterceptor(CurlLoggingInterceptor.class)); }
Example #20
Source File: UsingWithRestAssuredTest.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 4 votes |
private RestAssuredConfig getRestAssuredConfig(Consumer<String> curlConsumer) { return config() .httpClient(httpClientConfig() .reuseHttpClientInstance().httpClientFactory(new MyHttpClientFactory(curlConsumer))); }
Example #21
Source File: RestAssuredConfiguration.java From cukes with Apache License 2.0 | 4 votes |
public RestAssuredConfig getConfig() { if (restAssuredConfig == null) { restAssuredConfig = buildRestAssuredConfig(); } return restAssuredConfig; }
Example #22
Source File: RequestBody.java From cukes with Apache License 2.0 | 4 votes |
public RequestBody(String contentType, String content) { setRpr(new ResponseParserRegistrar()); setConfig(new RestAssuredConfig()); setContentType(contentType); setContent(content); }
Example #23
Source File: WebAdminUtils.java From james-project with Apache License 2.0 | 4 votes |
public static RestAssuredConfig defaultConfig() { return newConfig().encoderConfig(encoderConfig().defaultContentCharset(StandardCharsets.UTF_8)); }
Example #24
Source File: CurlLoggingRestAssuredConfigFactory.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Updates a given REST-assured configuration to generate curl command using default options. * * @param config an original configuration to update * @return updated configuration; note original configuration remain unchanged. */ public static RestAssuredConfig updateConfig(RestAssuredConfig config) { return updateConfig(config, getDefaultOptions()); }
Example #25
Source File: CurlLoggingRestAssuredConfigFactory.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a REST-assured configuration to generate curl command using custom options. * * @param options options defining curl generation * @return new configuration. */ public static RestAssuredConfig createConfig(Options options) { return updateConfig(RestAssuredConfig.config(), options); }
Example #26
Source File: CurlLoggingRestAssuredConfigFactory.java From curl-logger with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Creates a REST-assured configuration to generate curl command using default options. * * @return new configuration. */ public static RestAssuredConfig createConfig() { return createConfig(getDefaultOptions()); }