-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added feature to add extensions to SmallRyeContext object, added tests
- Loading branch information
Showing
7 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
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
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
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
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
16 changes: 16 additions & 0 deletions
16
server/integration-tests/src/test/java/io/smallrye/graphql/tests/extensions/Shirt.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,16 @@ | ||
package io.smallrye.graphql.tests.extensions; | ||
|
||
public class Shirt { | ||
private long size; | ||
|
||
public Shirt() { | ||
} | ||
|
||
public long getSize() { | ||
return size; | ||
} | ||
|
||
public void setSize(long size) { | ||
this.size = size; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...r/integration-tests/src/test/java/io/smallrye/graphql/tests/extensions/ShirtResource.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,24 @@ | ||
package io.smallrye.graphql.tests.extensions; | ||
|
||
import java.util.List; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.eclipse.microprofile.graphql.GraphQLApi; | ||
import org.eclipse.microprofile.graphql.Query; | ||
|
||
import io.smallrye.graphql.execution.context.SmallRyeContext; | ||
|
||
@GraphQLApi | ||
public class ShirtResource { | ||
|
||
@Inject | ||
SmallRyeContext smallRyeContext; | ||
|
||
@Query | ||
public List<Shirt> getShirts() { | ||
smallRyeContext.addExtension("bar", "This is test for extensions"); | ||
smallRyeContext.addExtension("foo", 3.14159); | ||
return null; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...tests/src/test/java/io/smallrye/graphql/tests/extensions/UserSupportedExtensionsTest.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,42 @@ | ||
package io.smallrye.graphql.tests.extensions; | ||
|
||
import java.net.URL; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.arquillian.container.test.api.RunAsClient; | ||
import org.jboss.arquillian.junit.Arquillian; | ||
import org.jboss.arquillian.test.api.ArquillianResource; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.asset.EmptyAsset; | ||
import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import io.smallrye.graphql.tests.GraphQLAssured; | ||
|
||
@RunWith(Arquillian.class) | ||
@RunAsClient | ||
public class UserSupportedExtensionsTest { | ||
|
||
@Deployment | ||
public static WebArchive deployment() { | ||
return ShrinkWrap.create(WebArchive.class, "user-extensions.war") | ||
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml") | ||
.addClasses(Shirt.class, ShirtResource.class); | ||
} | ||
|
||
@ArquillianResource | ||
URL testingURL; | ||
|
||
@Test | ||
public void userAddedExtension() { | ||
GraphQLAssured graphQLAssured = new GraphQLAssured(testingURL); | ||
String request = "query { shirts { size } }"; | ||
String response = graphQLAssured.post(request); | ||
MatcherAssert.assertThat(response, Matchers.containsString("\"extensions\":")); | ||
MatcherAssert.assertThat(response, Matchers.containsString("\"bar\":\"This is test for extensions\"")); | ||
MatcherAssert.assertThat(response, Matchers.containsString("\"foo\":3.14159")); | ||
} | ||
} |