-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL: Make sure the context terminate
Signed-off-by: Phillip Kruger <[email protected]> (cherry picked from commit 48787de)
- Loading branch information
1 parent
c28193b
commit f23ca08
Showing
2 changed files
with
95 additions
and
5 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...ent/src/test/java/io/quarkus/smallrye/graphql/deployment/GraphQLTerminateContextTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.quarkus.smallrye.graphql.deployment; | ||
|
||
import static io.quarkus.smallrye.graphql.deployment.AbstractGraphQLTest.MEDIATYPE_JSON; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Query; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.restassured.RestAssured; | ||
import io.smallrye.mutiny.Uni; | ||
import io.vertx.ext.web.RoutingContext; | ||
|
||
/** | ||
* Testing that the context terminate | ||
*/ | ||
public class GraphQLTerminateContextTest extends AbstractGraphQLTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest test = new QuarkusUnitTest() | ||
.withApplicationRoot((JavaArchive jar) -> jar | ||
.addClasses(TestTerminateContextResource.class) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")); | ||
|
||
@Test | ||
public void testWhoAmI() { | ||
runTestWith("user1"); | ||
runTestWith("user2"); | ||
runTestWith("user2"); | ||
} | ||
|
||
public void runTestWith(String expectedUser) { | ||
String fooRequest = getPayload("{\n" + | ||
" whoami {\n" + | ||
" name\n" + | ||
" }\n" + | ||
"}"); | ||
|
||
RestAssured.given().when() | ||
.accept(MEDIATYPE_JSON) | ||
.contentType(MEDIATYPE_JSON) | ||
.body(fooRequest) | ||
.with().header("X-Test", expectedUser) | ||
.post("/graphql") | ||
.then() | ||
.assertThat() | ||
.statusCode(200) | ||
.and() | ||
.log().body().and() | ||
.body("data.whoami.name", Matchers.equalTo(expectedUser)); | ||
} | ||
|
||
@GraphQLApi | ||
public static class TestTerminateContextResource { | ||
|
||
@Inject | ||
RoutingContext ctx; | ||
|
||
@Query | ||
public Uni<YouAre> whoami() { | ||
return Uni.createFrom().item(() -> { | ||
YouAre youAre = new YouAre(); | ||
youAre.name = ctx.request().headers().get("X-Test"); | ||
return youAre; | ||
}); | ||
} | ||
} | ||
|
||
public static class YouAre { | ||
public String name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters