Skip to content

Commit

Permalink
replace usage of RestAssured with Apache HTTP Client
Browse files Browse the repository at this point in the history
This is to workaround RestAssured's dependency on Jakarta EE 8 [1].
See rest-assured/rest-assured#1510.
  • Loading branch information
Ladicek committed Jan 6, 2022
1 parent c2536ce commit aceb5b7
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions tests/src/test/java/io/smallrye/context/test/FullStackTest.java
@@ -1,7 +1,9 @@
package io.smallrye.context.test;

import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -15,6 +17,11 @@
import jakarta.transaction.TransactionManager;
import jakarta.ws.rs.container.CompletionCallback;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.jboss.resteasy.cdi.CdiInjectorFactory;
import org.jboss.resteasy.cdi.ResteasyCdiExtension;
import org.jboss.resteasy.core.ResteasyContext;
Expand All @@ -32,7 +39,6 @@

import com.arjuna.ats.jta.logging.jtaLogger;

import io.restassured.RestAssured;
import io.smallrye.context.test.util.AbstractTest;
import io.vertx.core.Vertx;
import io.vertx.core.VertxOptions;
Expand Down Expand Up @@ -176,9 +182,29 @@ public void after() {
}

@Test
public void fullStack() {
RestAssured.when().get("/test").then().statusCode(200).body(is("OK"));
RestAssured.when().get("/test/async").then().statusCode(500);
RestAssured.when().get("/test/async-working").then().statusCode(200).body(is("OK"));
public void fullStack() throws IOException {
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
try (CloseableHttpResponse response = client.execute(new HttpGet("http://localhost:8080/test"))) {
assertEquals(200, response.getStatusLine().getStatusCode());
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
assertEquals("OK", body);
}

try (CloseableHttpResponse response = client.execute(new HttpGet("http://localhost:8080/test/async"))) {
assertEquals(500, response.getStatusLine().getStatusCode());
}

try (CloseableHttpResponse response = client.execute(new HttpGet("http://localhost:8080/test/async-working"))) {
assertEquals(200, response.getStatusLine().getStatusCode());
String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
assertEquals("OK", body);
}
}

// TODO RestAssured depends on on Jakarta EE 8 classes (JAX-B specifically)
// see https://github.com/rest-assured/rest-assured/issues/1510
//RestAssured.when().get("/test").then().statusCode(200).body(is("OK"));
//RestAssured.when().get("/test/async").then().statusCode(500);
//RestAssured.when().get("/test/async-working").then().statusCode(200).body(is("OK"));
}
}

0 comments on commit aceb5b7

Please sign in to comment.