From 8d72bbee8d6aeb568604e7070d90c10657a766e4 Mon Sep 17 00:00:00 2001 From: Igor Dianov Date: Sat, 2 Feb 2019 20:51:01 -0800 Subject: [PATCH] Extract graphql-jpa-query-web module from starter (#74) * fix: Extract graphql-jpa-query-web module from starter * fix: (git) add .classpath to .gitignore * fix: add GraphQLControllerAutoConfigurationTest --- .gitignore | 12 +------ graphql-jpa-query-boot-starter/pom.xml | 5 +++ .../autoconfigure/EnableGraphQLJpaQuery.java | 6 ++-- .../GraphQLJpaQueryAutoConfiguration.java | 5 +-- .../EnableGraphQLJpaQueryTest.java | 2 +- .../GraphQLJpaQueryAutoConfigurationTest.java | 2 +- .../GraphQLJpaQueryStarterIT.java} | 4 +-- .../query/{web => starter}/model/Author.java | 2 +- .../query/{web => starter}/model/Book.java | 2 +- .../query/{web => starter}/model/Genre.java | 2 +- graphql-jpa-query-dependencies/pom.xml | 5 +++ graphql-jpa-query-web/pom.xml | 24 +++++++++++++ .../jpa/query/web/GraphQLController.java | 4 --- .../GraphQLControllerAutoConfiguration.java | 20 +++++++++++ .../main/resources/META-INF/spring.factories | 2 ++ .../jpa/query/web/GraphQLControllerTest.java | 0 ...raphQLControllerAutoConfigurationTest.java | 36 +++++++++++++++++++ ...ontrollerAutoConfigurationWebNoneTest.java | 36 +++++++++++++++++++ pom.xml | 1 + 19 files changed, 141 insertions(+), 29 deletions(-) rename graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/{web/GraphQLControllerIT.java => starter/GraphQLJpaQueryStarterIT.java} (97%) rename graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/{web => starter}/model/Author.java (93%) rename graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/{web => starter}/model/Book.java (93%) rename graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/{web => starter}/model/Genre.java (91%) create mode 100644 graphql-jpa-query-web/pom.xml rename {graphql-jpa-query-boot-starter => graphql-jpa-query-web}/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java (97%) create mode 100644 graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfiguration.java create mode 100644 graphql-jpa-query-web/src/main/resources/META-INF/spring.factories rename {graphql-jpa-query-boot-starter => graphql-jpa-query-web}/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerTest.java (100%) create mode 100644 graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationTest.java create mode 100644 graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationWebNoneTest.java diff --git a/.gitignore b/.gitignore index 6927f695b..bcebd1c9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ # Eclipse -#.classpath .project/ .settings/ build/ @@ -21,13 +20,4 @@ target/ # Eclipse .project .springBeans - - - -graphql-jpa-query-schema/\.classpath - -graphql-jpa-query-annotations/\.classpath - -graphql-jpa-query-example/\.classpath - -graphql-jpa-query-boot-starter/\.classpath +.classpath diff --git a/graphql-jpa-query-boot-starter/pom.xml b/graphql-jpa-query-boot-starter/pom.xml index a55a177fe..439669253 100644 --- a/graphql-jpa-query-boot-starter/pom.xml +++ b/graphql-jpa-query-boot-starter/pom.xml @@ -23,6 +23,11 @@ graphql-jpa-query-autoconfigure + + com.introproventures + graphql-jpa-query-web + + org.springframework.boot spring-boot-starter diff --git a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQuery.java b/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQuery.java index 6175ba16a..2e3ce63ce 100644 --- a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQuery.java +++ b/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQuery.java @@ -22,15 +22,15 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; +import com.introproventures.graphql.jpa.query.boot.autoconfigure.GraphQLJpaQueryAutoConfiguration.DefaultGraphQLJpaQueryConfiguration; +import com.introproventures.graphql.jpa.query.boot.autoconfigure.GraphQLJpaQueryAutoConfiguration.GraphQLJpaQuerySchemaConfigurer; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.PropertySource; -import com.introproventures.graphql.jpa.query.boot.autoconfigure.GraphQLJpaQueryAutoConfiguration.DefaultActivitiGraphQLJpaConfiguration; - @Documented @Retention( RUNTIME ) @Target( TYPE ) -@Import(DefaultActivitiGraphQLJpaConfiguration.class) +@Import({DefaultGraphQLJpaQueryConfiguration.class, GraphQLJpaQuerySchemaConfigurer.class}) @PropertySource("classpath:/com/introproventures/graphql/jpa/query/boot/autoconfigure/default.properties") public @interface EnableGraphQLJpaQuery { diff --git a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfiguration.java b/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfiguration.java index cdcdfac7d..5b63fe8fd 100644 --- a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfiguration.java +++ b/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfiguration.java @@ -23,7 +23,6 @@ import com.introproventures.graphql.jpa.query.schema.GraphQLSchemaBuilder; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -import com.introproventures.graphql.jpa.query.web.GraphQLController; import graphql.GraphQL; import graphql.schema.GraphQLSchema; import org.springframework.beans.factory.annotation.Autowired; @@ -33,7 +32,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportAware; import org.springframework.context.annotation.PropertySource; import org.springframework.core.type.AnnotationMetadata; @@ -62,9 +60,8 @@ public void configure(GraphQLShemaRegistration registry) { } @Configuration - @Import(GraphQLController.class) @EnableConfigurationProperties(GraphQLJpaQueryProperties.class) - public static class DefaultActivitiGraphQLJpaConfiguration implements ImportAware { + public static class DefaultGraphQLJpaQueryConfiguration implements ImportAware { @Autowired GraphQLJpaQueryProperties properties; diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQueryTest.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQueryTest.java index 907e4f6ff..44d6d9079 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQueryTest.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/EnableGraphQLJpaQueryTest.java @@ -30,7 +30,7 @@ import com.introproventures.graphql.jpa.query.schema.GraphQLSchemaBuilder; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -import com.introproventures.graphql.jpa.query.web.model.Author; +import com.introproventures.graphql.jpa.query.starter.model.Author; @RunWith(SpringRunner.class) @SpringBootTest( diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfigurationTest.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfigurationTest.java index bc745a814..73b89d99c 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfigurationTest.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/boot/autoconfigure/GraphQLJpaQueryAutoConfigurationTest.java @@ -30,7 +30,7 @@ import com.introproventures.graphql.jpa.query.schema.GraphQLSchemaBuilder; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder; -import com.introproventures.graphql.jpa.query.web.model.Author; +import com.introproventures.graphql.jpa.query.starter.model.Author; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerIT.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/GraphQLJpaQueryStarterIT.java similarity index 97% rename from graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerIT.java rename to graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/GraphQLJpaQueryStarterIT.java index 68ee8edc4..210212e45 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerIT.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/GraphQLJpaQueryStarterIT.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.introproventures.graphql.jpa.query.web; +package com.introproventures.graphql.jpa.query.starter; import java.io.IOException; import java.util.HashMap; @@ -41,7 +41,7 @@ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class GraphQLControllerIT { +public class GraphQLJpaQueryStarterIT { private static final String WAR_AND_PEACE = "War and Peace"; @SpringBootApplication diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Author.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Author.java similarity index 93% rename from graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Author.java rename to graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Author.java index 61379ace4..c06fd5f55 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Author.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Author.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.introproventures.graphql.jpa.query.web.model; +package com.introproventures.graphql.jpa.query.starter.model; import java.util.Collection; diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Book.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Book.java similarity index 93% rename from graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Book.java rename to graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Book.java index ecc92ebb9..4e229d9ff 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Book.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Book.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.introproventures.graphql.jpa.query.web.model; +package com.introproventures.graphql.jpa.query.starter.model; import javax.persistence.Entity; import javax.persistence.EnumType; diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Genre.java b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Genre.java similarity index 91% rename from graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Genre.java rename to graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Genre.java index 574473b71..675e3317a 100644 --- a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/model/Genre.java +++ b/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/starter/model/Genre.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.introproventures.graphql.jpa.query.web.model; +package com.introproventures.graphql.jpa.query.starter.model; public enum Genre { NOVEL, PLAY diff --git a/graphql-jpa-query-dependencies/pom.xml b/graphql-jpa-query-dependencies/pom.xml index 5846f6b8a..093c739eb 100644 --- a/graphql-jpa-query-dependencies/pom.xml +++ b/graphql-jpa-query-dependencies/pom.xml @@ -59,6 +59,11 @@ graphql-jpa-query-autoconfigure ${project.version} + + com.introproventures + graphql-jpa-query-web + ${project.version} + diff --git a/graphql-jpa-query-web/pom.xml b/graphql-jpa-query-web/pom.xml new file mode 100644 index 000000000..7eaa0e5af --- /dev/null +++ b/graphql-jpa-query-web/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + com.introproventures + graphql-jpa-query-build + 0.3.13-SNAPSHOT + ../graphql-jpa-query-build + + graphql-jpa-query-web + + + + com.introproventures + graphql-jpa-query-schema + true + + + org.springframework.boot + spring-boot-starter-web + true + + + + \ No newline at end of file diff --git a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java b/graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java similarity index 97% rename from graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java rename to graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java index c37386025..3f11450f9 100644 --- a/graphql-jpa-query-boot-starter/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java +++ b/graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/GraphQLController.java @@ -26,8 +26,6 @@ import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor; import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor; import graphql.ExecutionResult; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.http.MediaType; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; @@ -43,8 +41,6 @@ * */ @RestController -@ConditionalOnWebApplication -@ConditionalOnClass(GraphQLExecutor.class) public class GraphQLController { private static final String PATH = "${spring.graphql.jpa.query.path:/graphql}"; diff --git a/graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfiguration.java b/graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfiguration.java new file mode 100644 index 000000000..2423cd294 --- /dev/null +++ b/graphql-jpa-query-web/src/main/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfiguration.java @@ -0,0 +1,20 @@ +package com.introproventures.graphql.jpa.query.web.autoconfigure; + +import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor; +import com.introproventures.graphql.jpa.query.web.GraphQLController; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; + +@Configuration +@ConditionalOnWebApplication +@ConditionalOnClass(GraphQLExecutor.class) +public class GraphQLControllerAutoConfiguration { + + @Import(GraphQLController.class) + public static class DefaultGraphQLControllerConfiguration { + + } + +} diff --git a/graphql-jpa-query-web/src/main/resources/META-INF/spring.factories b/graphql-jpa-query-web/src/main/resources/META-INF/spring.factories new file mode 100644 index 000000000..8b767c921 --- /dev/null +++ b/graphql-jpa-query-web/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + com.introproventures.graphql.jpa.query.web.autoconfigure.GraphQLControllerAutoConfiguration \ No newline at end of file diff --git a/graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerTest.java b/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerTest.java similarity index 100% rename from graphql-jpa-query-boot-starter/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerTest.java rename to graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/GraphQLControllerTest.java diff --git a/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationTest.java b/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationTest.java new file mode 100644 index 000000000..8299c28c2 --- /dev/null +++ b/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationTest.java @@ -0,0 +1,36 @@ +package com.introproventures.graphql.jpa.query.web.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor; +import com.introproventures.graphql.jpa.query.web.GraphQLController; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment=WebEnvironment.RANDOM_PORT) +public class GraphQLControllerAutoConfigurationTest { + + @MockBean + private GraphQLExecutor graphQLExecutor; + + @Autowired + private GraphQLController graphQLController; + + @SpringBootApplication + static class Application { + + } + + @Test + public void contextLoads() { + assertThat(graphQLController).isNotNull(); + } + +} diff --git a/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationWebNoneTest.java b/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationWebNoneTest.java new file mode 100644 index 000000000..6ffa93f3f --- /dev/null +++ b/graphql-jpa-query-web/src/test/java/com/introproventures/graphql/jpa/query/web/autoconfigure/GraphQLControllerAutoConfigurationWebNoneTest.java @@ -0,0 +1,36 @@ +package com.introproventures.graphql.jpa.query.web.autoconfigure; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.introproventures.graphql.jpa.query.schema.GraphQLExecutor; +import com.introproventures.graphql.jpa.query.web.GraphQLController; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment=WebEnvironment.NONE) +public class GraphQLControllerAutoConfigurationWebNoneTest { + + @MockBean + private GraphQLExecutor graphQLExecutor; + + @Autowired(required=false) + private GraphQLController graphQLController; + + @SpringBootApplication + static class Application { + + } + + @Test + public void contextLoads() { + assertThat(graphQLController).isNull(); + } + +} diff --git a/pom.xml b/pom.xml index 2bd9f20b2..de40978e5 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,7 @@ graphql-jpa-query-dependencies graphql-jpa-query-build graphql-jpa-query-autoconfigure + graphql-jpa-query-web