Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package graphql.kickstart.altair.boot.test;

import org.junit.After;
import org.junit.jupiter.api.AfterEach;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.AnnotationConfigRegistry;
Expand All @@ -26,7 +26,7 @@ protected AbstractAutoConfigurationTest(Class<? extends AbstractApplicationConte
this.autoConfiguration = autoConfiguration;
}

@After
@AfterEach
public void tearDown() {
if (this.context != null) {
this.context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import graphql.kickstart.altair.boot.AltairAutoConfiguration;
import graphql.kickstart.altair.boot.AltairController;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

/**
* @author Andrew Potter
*/
Expand Down Expand Up @@ -42,13 +44,14 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon
public void altairLoads() {
load(EnabledConfiguration.class);

Assert.assertNotNull(this.getContext().getBean(AltairController.class));
assertThat(this.getContext().getBean(AltairController.class)).isNotNull();
}

@Test(expected = NoSuchBeanDefinitionException.class)
@Test
public void altairDoesNotLoad() {
load(DisabledConfiguration.class);

this.getContext().getBean(AltairController.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.getContext().getBean(AltairController.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package com.graphql.sample.boot

import com.graphql.spring.boot.test.GraphQLTestTemplate
import com.graphql.spring.boot.test.GraphQLTest
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Test
import org.junit.runner.RunWith
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.test.context.junit4.SpringRunner
import org.springframework.test.context.junit.jupiter.SpringExtension

@RunWith(SpringRunner::class)
@ExtendWith(SpringExtension::class)
@GraphQLTest
class GraphQLServletTest {

Expand All @@ -21,8 +20,8 @@ class GraphQLServletTest {
@Test
fun `query over HTTP POST multipart with variables returns data requires multipartconfig`() {
val response = graphQLTestTemplate.postMultipart("query echo(\$string: String!)", """{"string":"echo"}""")
assertNotNull(response)
assertEquals(HttpStatus.OK, response.statusCode)
assertThat(response).isNotNull
assertThat(response.statusCode).isEqualTo(HttpStatus.OK)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@
import com.graphql.spring.boot.test.GraphQLResponse;
import com.graphql.spring.boot.test.GraphQLTestTemplate;
import com.graphql.spring.boot.test.GraphQLTest;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.io.IOException;

import static graphql.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@GraphQLTest
public class GraphQLToolsSampleApplicationTest {

@Autowired
private GraphQLTestTemplate graphQLTestTemplate;

@Test
@Ignore
@Disabled
public void get_comments() throws IOException {
GraphQLResponse response = graphQLTestTemplate.postForResource("graphql/post-get-comments.graphql");
assertNotNull(response);
assertTrue(response.isOk());
assertEquals("1", response.get("$.data.post.id"));
assertThat(response.isOk()).isTrue();
assertThat(response.get("$.data.post.id")).isEqualTo("1");
}

@Test
Expand All @@ -42,17 +42,17 @@ public void get_comments_withFragments() throws IOException {
fragments.add("graphql/all-comment-fields-fragment.graphql");
GraphQLResponse response = graphQLTestTemplate.postForResource("graphql/post-get-comments-with-fragment.graphql", fragments);
assertNotNull(response);
assertTrue(response.isOk());
assertEquals("1", response.get("$.data.post.id"));
assertThat((response.isOk())).isTrue();
assertThat(response.get("$.data.post.id")).isEqualTo("1");
}

@Test
public void create_post() throws IOException {
ObjectNode variables = new ObjectMapper().createObjectNode();
variables.put("text", "lorem ipsum dolor sit amet");
GraphQLResponse response = graphQLTestTemplate.perform("graphql/create-post.graphql", variables);
assertNotNull(response);
assertNotNull(response.get("$.data.createPost.id"));
assertThat(response).isNotNull();
assertThat(response.get("$.data.createPost.id")).isNotNull();
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.graphql.sample.boot;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest
@Disabled
public class SpringBootTestWithoutWebEnvironmentTest {

@Test
@Ignore
public void loads_without_complaining_about_missing_ServerContainer() {

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package graphql.servlet.examples.dataloader.requestscope;

import com.fasterxml.jackson.databind.JsonNode;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTest {

Expand Down Expand Up @@ -42,14 +41,13 @@ public void testRequestScope() {
headers.add("content-type", "application/graphql");
ResponseEntity<JsonNode> response = this.restTemplate.postForEntity("/graphql", new HttpEntity<>(requestGraphQL, headers), JsonNode.class);

assertEquals(response.getBody().toString(), "{\"data\":{\"walmartCustomers\":[{\"customerId\":101,\"name\":\"Customer Name 1\"},{\"customerId\":102,\"name\":\"Customer Name 2\"},{\"customerId\":103,\"name\":\"Customer Name 3\"},{\"customerId\":104,\"name\":\"Customer Name 4\"}]}}");
assertThat(response.getBody().toString()).isEqualTo("{\"data\":{\"walmartCustomers\":[{\"customerId\":101,\"name\":\"Customer Name 1\"},{\"customerId\":102,\"name\":\"Customer Name 2\"},{\"customerId\":103,\"name\":\"Customer Name 3\"},{\"customerId\":104,\"name\":\"Customer Name 4\"}]}}");

repository.updateUsernameForId(101, "New Name 1");

response = this.restTemplate.postForEntity("/graphql", new HttpEntity<>(requestGraphQL, headers), JsonNode.class);

assertEquals(response.getBody().toString(), "{\"data\":{\"walmartCustomers\":[{\"customerId\":101,\"name\":\"New Name 1\"},{\"customerId\":102,\"name\":\"Customer Name 2\"},{\"customerId\":103,\"name\":\"Customer Name 3\"},{\"customerId\":104,\"name\":\"Customer Name 4\"}]}}");
;
assertThat(response.getBody().toString()).isEqualTo("{\"data\":{\"walmartCustomers\":[{\"customerId\":101,\"name\":\"New Name 1\"},{\"customerId\":102,\"name\":\"Customer Name 2\"},{\"customerId\":103,\"name\":\"Customer Name 3\"},{\"customerId\":104,\"name\":\"Customer Name 4\"}]}}");
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package graphql.kickstart.graphiql.boot;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
import org.springframework.context.annotation.Import;
import org.springframework.http.MediaType;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.WebTestClient;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@WebFluxTest
public class ReactiveGraphiQLControllerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package graphql.kickstart.graphiql.boot;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.MockMvc;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@RunWith(SpringRunner.class)
@ExtendWith(SpringExtension.class)
@WebMvcTest
public class ServletGraphiQLControllerTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package graphql.kickstart.graphiql.boot.test;

import org.junit.After;
import org.junit.jupiter.api.AfterEach;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.AnnotationConfigRegistry;
Expand All @@ -26,7 +26,7 @@ protected AbstractAutoConfigurationTest(Class<? extends AbstractApplicationConte
this.autoConfiguration = autoConfiguration;
}

@After
@AfterEach
public void tearDown() {
if (this.context != null) {
this.context.close();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

import graphql.kickstart.graphiql.boot.GraphiQLAutoConfiguration;
import graphql.kickstart.graphiql.boot.GraphiQLController;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

/**
* @author Andrew Potter
*/
Expand Down Expand Up @@ -42,13 +44,14 @@ public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderCon
public void graphiqlLoads() {
load(EnabledConfiguration.class);

Assert.assertNotNull(this.getContext().getBean(GraphiQLController.class));
assertThat(this.getContext().getBean(GraphiQLController.class)).isNotNull();
}

@Test(expected = NoSuchBeanDefinitionException.class)
@Test
public void graphiqlDoesNotLoad() {
load(DisabledConfiguration.class);

this.getContext().getBean(GraphiQLController.class);
assertThatExceptionOfType(NoSuchBeanDefinitionException.class)
.isThrownBy(() -> this.getContext().getBean(GraphiQLController.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import javax.servlet.ServletContext;
import javax.websocket.server.ServerContainer;
import org.junit.After;

import org.junit.jupiter.api.AfterEach;
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand Down Expand Up @@ -34,7 +35,7 @@ protected AbstractAutoConfigurationTest(Class<? extends AbstractApplicationConte
this.autoConfiguration = autoConfiguration;
}

@After
@AfterEach
public void tearDown() {
if (this.context != null) {
this.context.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package graphql.kickstart.tools.boot;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import graphql.kickstart.tools.GraphQLQueryResolver;
import java.io.IOException;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.context.annotation.Configuration;

import static org.assertj.core.api.Assertions.assertThat;

public class ClasspathResourceSchemaStringProviderTest extends AbstractAutoConfigurationTest {

private ClasspathResourceSchemaStringProvider schemaStringProvider;
Expand All @@ -19,12 +19,12 @@ public ClasspathResourceSchemaStringProviderTest() {
super(GraphQLJavaToolsAutoConfiguration.class);
}

@Before
@BeforeEach
public void setup() {
System.setProperty("graphql.tools.schemaLocationPattern", "graphql/*.gqls");
}

@After
@AfterEach
public void clear() {
System.clearProperty("graphql.tools.schemaLocationPattern");
}
Expand All @@ -35,8 +35,8 @@ public void schemaStrings() throws IOException {
schemaStringProvider = getContext().getBean(ClasspathResourceSchemaStringProvider.class);

List<String> schemaStrings = schemaStringProvider.schemaStrings();
assertEquals(1, schemaStrings.size());
assertTrue(schemaStrings.get(0).contains("schemaLocationTest"));
assertThat(schemaStrings).hasSize(1);
assertThat(schemaStrings.get(0)).contains("schemaLocationTest");
}

@Configuration
Expand Down
Loading