Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stojsavljevic committed Dec 26, 2023
1 parent 9989987 commit 9e62e54
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,31 @@ class GraphqlDgsApplicationTests {

@Test
void test_query_all_authors() {
List<String> authorNames = dgsQueryExecutor
List<String> authorNames = this.dgsQueryExecutor
.executeAndExtractJsonPath(TestQueries.QUERY_ALL_AUTHORS, TestQueries.JSON_PATH_ALL_AUTHOR_NAMES);

validateAuthorNames(authorNames);
}

@Test
void test_query_all_posts() {
List<String> titles = dgsQueryExecutor
List<String> titles = this.dgsQueryExecutor
.executeAndExtractJsonPath(TestQueries.QUERY_ALL_POSTS, TestQueries.JSON_PATH_ALL_POST_TITLES);

validatePostTitles(titles);
}

@Test
void test_create_post() {
Post post = dgsQueryExecutor
Post post = this.dgsQueryExecutor
.executeAndExtractJsonPathAsObject(TestQueries.MUTATION_CREATE_POST, TestQueries.JSON_PATH_CREATE_POST, Post.class);

validateNewPost(post);
}

@Test
void test_subscription() {
ExecutionResult executionResult = dgsQueryExecutor.execute(TestQueries.SUBSCRIPTION_GET_RANDOM_POST);
ExecutionResult executionResult = this.dgsQueryExecutor.execute(TestQueries.SUBSCRIPTION_GET_RANDOM_POST);
Publisher<ExecutionResult> publisher = executionResult.getData();

StepVerifier.withVirtualTime(() -> publisher, 1)
Expand All @@ -70,7 +70,7 @@ void test_subscription() {
@SuppressWarnings("unchecked")
private Post toPost(ExecutionResult result) {
Map<String, Object> data = (Map<String, Object>) result.getData();
return objectMapper.convertValue(data.get("randomPost"), Post.class);
return this.objectMapper.convertValue(data.get("randomPost"), Post.class);
}

public static void validateAuthorNames(List<String> authorNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
class GraphQLKickstartDemoTest {

@Autowired
private GraphQLTestTemplate graphQLTestTemplate;
GraphQLTestTemplate graphQLTestTemplate;

@Autowired
GraphQLTestSubscription graphQLTestSubscription;

@Test
void test_query_all_authors() throws IOException {

GraphQLResponse response = graphQLTestTemplate.postForString(TestQueries.QUERY_ALL_AUTHORS);
GraphQLResponse response = this.graphQLTestTemplate.postForString(TestQueries.QUERY_ALL_AUTHORS);
List<String> authorNames = response.getList(TestQueries.JSON_PATH_ALL_AUTHOR_NAMES, String.class);

validateAuthorNames(authorNames);
Expand All @@ -41,7 +41,7 @@ void test_query_all_authors() throws IOException {
@Test
void test_query_all_posts() throws IOException {

GraphQLResponse response = graphQLTestTemplate.postForString(TestQueries.QUERY_ALL_POSTS);
GraphQLResponse response = this.graphQLTestTemplate.postForString(TestQueries.QUERY_ALL_POSTS);
List<String> titles = response.getList(TestQueries.JSON_PATH_ALL_POST_TITLES, String.class);

validatePostTitles(titles);
Expand All @@ -50,7 +50,7 @@ void test_query_all_posts() throws IOException {
@Test
void test_create_post() throws IOException {

GraphQLResponse response = graphQLTestTemplate.postForString(TestQueries.MUTATION_CREATE_POST);
GraphQLResponse response = this.graphQLTestTemplate.postForString(TestQueries.MUTATION_CREATE_POST);
Post post= response.get(TestQueries.JSON_PATH_CREATE_POST, Post.class);

validateNewPost(post);
Expand All @@ -60,7 +60,7 @@ void test_create_post() throws IOException {
void test_subscription() {

final GraphQLResponse graphQLResponse =
graphQLTestSubscription
this.graphQLTestSubscription
.init()
.start("subscription-get-post.graphql")
.awaitAndGetNextResponse(Duration.ofSeconds(5));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.graphql.test.tester.GraphQlTester;
Expand All @@ -23,7 +22,6 @@
import com.alex.graphql.core.util.TestQueries;

@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureHttpGraphQlTester
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
@ActiveProfiles("no-security")
public class GraphqlSpringApplicationTest {
Expand All @@ -37,14 +35,14 @@ public class GraphqlSpringApplicationTest {
// testing with reactive client over websocket:
@BeforeAll
void setUp() {
this.graphQlTester = WebSocketGraphQlTester.builder(URI.create(baseUrl), new ReactorNettyWebSocketClient())
this.graphQlTester = WebSocketGraphQlTester.builder(URI.create(this.baseUrl), new ReactorNettyWebSocketClient())
.build();
}

@Test
void test_query_all_authors() throws Exception {

Response response = graphQlTester.document(TestQueries.QUERY_ALL_AUTHORS).execute();
Response response = this.graphQlTester.document(TestQueries.QUERY_ALL_AUTHORS).execute();
List<String> authorNames = response.path(TestQueries.JSON_PATH_ALL_AUTHOR_NAMES).entityList(String.class).get();

validateAuthorNames(authorNames);
Expand All @@ -53,7 +51,7 @@ void test_query_all_authors() throws Exception {
@Test
void test_query_all_posts() throws Exception {

Response response = graphQlTester.document(TestQueries.QUERY_ALL_POSTS).execute();
Response response = this.graphQlTester.document(TestQueries.QUERY_ALL_POSTS).execute();
List<String> titles = response.path(TestQueries.JSON_PATH_ALL_POST_TITLES).entityList(String.class).get();

validatePostTitles(titles);
Expand All @@ -62,7 +60,7 @@ void test_query_all_posts() throws Exception {
@Test
void test_create_post() {

Response response = graphQlTester.document(TestQueries.MUTATION_CREATE_POST).execute();
Response response = this.graphQlTester.document(TestQueries.MUTATION_CREATE_POST).execute();
Post post = response.path(TestQueries.JSON_PATH_CREATE_POST).entity(Post.class).get();

validateNewPost(post);
Expand All @@ -71,7 +69,7 @@ void test_create_post() {
@Test
void test_subscriptions() throws Exception {

Post post = graphQlTester.document(TestQueries.SUBSCRIPTION_GET_RANDOM_POST).executeSubscription()
Post post = this.graphQlTester.document(TestQueries.SUBSCRIPTION_GET_RANDOM_POST).executeSubscription()
.toFlux("randomPost", Post.class).blockFirst();

assertThat(post.getTitle()).isEqualTo(TestQueries.BOOK_1_TITLE);
Expand Down

0 comments on commit 9e62e54

Please sign in to comment.