diff --git a/pom.xml b/pom.xml index 43023f79..c82d5a92 100644 --- a/pom.xml +++ b/pom.xml @@ -631,6 +631,13 @@ 3.1.0 provided + + + com.tngtech.archunit + archunit + 0.9.3 + test + diff --git a/src/main/java/org/springframework/hateoas/Affordance.java b/src/main/java/org/springframework/hateoas/Affordance.java index 9dd89556..37dd2c0b 100644 --- a/src/main/java/org/springframework/hateoas/Affordance.java +++ b/src/main/java/org/springframework/hateoas/Affordance.java @@ -23,7 +23,6 @@ import java.util.Map; import org.springframework.core.ResolvableType; import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.util.Assert; @@ -37,20 +36,23 @@ import org.springframework.util.Assert; @Value public class Affordance { - private static List factories = SpringFactoriesLoader.loadFactories(AffordanceModelFactory.class, Affordance.class.getClassLoader()); + private static List factories = SpringFactoriesLoader + .loadFactories(AffordanceModelFactory.class, Affordance.class.getClassLoader()); /** * Collection of {@link AffordanceModel}s related to this affordance. */ private final Map affordanceModels = new HashMap<>(); - public Affordance(String name, Link link, HttpMethod httpMethod, ResolvableType inputType, List queryMethodParameters, ResolvableType outputType) { + public Affordance(String name, Link link, HttpMethod httpMethod, ResolvableType inputType, + List queryMethodParameters, ResolvableType outputType) { Assert.notNull(httpMethod, "httpMethod must not be null!"); Assert.notNull(queryMethodParameters, "queryMethodParameters must not be null!"); for (AffordanceModelFactory factory : factories) { - this.affordanceModels.put(factory.getMediaType(), factory.getAffordanceModel(name, link, httpMethod, inputType, queryMethodParameters, outputType)); + this.affordanceModels.put(factory.getMediaType(), + factory.getAffordanceModel(name, link, httpMethod, inputType, queryMethodParameters, outputType)); } } diff --git a/src/main/java/org/springframework/hateoas/core/AffordanceModelFactory.java b/src/main/java/org/springframework/hateoas/AffordanceModelFactory.java similarity index 90% rename from src/main/java/org/springframework/hateoas/core/AffordanceModelFactory.java rename to src/main/java/org/springframework/hateoas/AffordanceModelFactory.java index 7e16bc6d..1c25d7f1 100644 --- a/src/main/java/org/springframework/hateoas/core/AffordanceModelFactory.java +++ b/src/main/java/org/springframework/hateoas/AffordanceModelFactory.java @@ -13,15 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.hateoas.core; +package org.springframework.hateoas; import java.util.List; import java.util.Optional; import org.springframework.core.ResolvableType; -import org.springframework.hateoas.AffordanceModel; -import org.springframework.hateoas.Link; -import org.springframework.hateoas.QueryParameter; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.plugin.core.Plugin; diff --git a/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonAffordanceModelFactory.java b/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonAffordanceModelFactory.java index ad7726e2..aa2ddc63 100644 --- a/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonAffordanceModelFactory.java +++ b/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonAffordanceModelFactory.java @@ -21,10 +21,10 @@ import java.util.List; import org.springframework.core.ResolvableType; import org.springframework.hateoas.AffordanceModel; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.QueryParameter; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModelFactory.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModelFactory.java index d6e996c3..91a01ade 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModelFactory.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsAffordanceModelFactory.java @@ -21,10 +21,10 @@ import java.util.List; import org.springframework.core.ResolvableType; import org.springframework.hateoas.AffordanceModel; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.QueryParameter; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; diff --git a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java index 1eefca0f..2c0377dd 100755 --- a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java +++ b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java @@ -31,9 +31,9 @@ import javax.servlet.http.HttpServletRequest; import org.springframework.context.ApplicationContext; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.hateoas.Affordance; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.TemplateVariables; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.hateoas.core.AnnotationMappingDiscoverer; import org.springframework.hateoas.core.DummyInvocationUtils; import org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation; diff --git a/src/main/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilder.java b/src/main/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilder.java index 5a7fd7ef..52f6a53b 100644 --- a/src/main/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilder.java +++ b/src/main/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilder.java @@ -22,9 +22,9 @@ import java.util.stream.Collectors; import org.springframework.core.ResolvableType; import org.springframework.hateoas.Affordance; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.QueryParameter; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.hateoas.core.DummyInvocationUtils.MethodInvocation; import org.springframework.hateoas.core.MappingDiscoverer; import org.springframework.hateoas.core.MethodParameters; diff --git a/src/main/java/org/springframework/hateoas/uber/UberAffordanceModelFactory.java b/src/main/java/org/springframework/hateoas/uber/UberAffordanceModelFactory.java index 6467d3e1..a19cf97c 100644 --- a/src/main/java/org/springframework/hateoas/uber/UberAffordanceModelFactory.java +++ b/src/main/java/org/springframework/hateoas/uber/UberAffordanceModelFactory.java @@ -21,10 +21,10 @@ import java.util.List; import org.springframework.core.ResolvableType; import org.springframework.hateoas.AffordanceModel; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.QueryParameter; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; diff --git a/src/main/kotlin/org/springframework/hateoas/AffordanceBuilderDsl.kt b/src/main/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDsl.kt similarity index 93% rename from src/main/kotlin/org/springframework/hateoas/AffordanceBuilderDsl.kt rename to src/main/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDsl.kt index 8fd9e62c..343a1cd8 100644 --- a/src/main/kotlin/org/springframework/hateoas/AffordanceBuilderDsl.kt +++ b/src/main/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDsl.kt @@ -14,9 +14,10 @@ * limitations under the License. */ -package org.springframework.hateoas +package org.springframework.hateoas.mvc -import org.springframework.hateoas.mvc.ControllerLinkBuilder +import org.springframework.hateoas.Affordance +import org.springframework.hateoas.Link import org.springframework.hateoas.mvc.ControllerLinkBuilder.afford import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn diff --git a/src/main/kotlin/org/springframework/hateoas/LinkBuilderDsl.kt b/src/main/kotlin/org/springframework/hateoas/mvc/LinkBuilderDsl.kt similarity index 94% rename from src/main/kotlin/org/springframework/hateoas/LinkBuilderDsl.kt rename to src/main/kotlin/org/springframework/hateoas/mvc/LinkBuilderDsl.kt index 426a1d45..63afd382 100644 --- a/src/main/kotlin/org/springframework/hateoas/LinkBuilderDsl.kt +++ b/src/main/kotlin/org/springframework/hateoas/mvc/LinkBuilderDsl.kt @@ -14,11 +14,14 @@ * limitations under the License. */ -package org.springframework.hateoas +package org.springframework.hateoas.mvc +import org.springframework.hateoas.Link +import org.springframework.hateoas.ResourceSupport import org.springframework.hateoas.mvc.ControllerLinkBuilder import org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo import org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn + import kotlin.reflect.KClass /** diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories index bd21abff..e6bfa01d 100644 --- a/src/main/resources/META-INF/spring.factories +++ b/src/main/resources/META-INF/spring.factories @@ -1 +1 @@ -org.springframework.hateoas.core.AffordanceModelFactory=org.springframework.hateoas.hal.forms.HalFormsAffordanceModelFactory,org.springframework.hateoas.collectionjson.CollectionJsonAffordanceModelFactory,org.springframework.hateoas.uber.UberAffordanceModelFactory +org.springframework.hateoas.AffordanceModelFactory=org.springframework.hateoas.hal.forms.HalFormsAffordanceModelFactory,org.springframework.hateoas.collectionjson.CollectionJsonAffordanceModelFactory,org.springframework.hateoas.uber.UberAffordanceModelFactory diff --git a/src/test/java/org/springframework/hateoas/ArchitectureTest.java b/src/test/java/org/springframework/hateoas/ArchitectureTest.java new file mode 100644 index 00000000..6390b6f2 --- /dev/null +++ b/src/test/java/org/springframework/hateoas/ArchitectureTest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.hateoas; + +import org.junit.Test; + +import com.tngtech.archunit.core.domain.JavaClasses; +import com.tngtech.archunit.core.importer.ClassFileImporter; +import com.tngtech.archunit.core.importer.ImportOption; +import com.tngtech.archunit.core.importer.ImportOptions; +import com.tngtech.archunit.library.dependencies.SliceRule; +import com.tngtech.archunit.library.dependencies.SlicesRuleDefinition; + +/** + * Tests to verify certain architectural assumptions. + * + * @author Oliver Gierke + */ +public class ArchitectureTest { + + ImportOptions options = new ImportOptions().with(ImportOption.Predefined.DONT_INCLUDE_TESTS); + JavaClasses classes = new ClassFileImporter(options) // + .importPackages("org.springframework.hateoas"); + + @Test + public void assertNoCyclicPackageDependencies() { + + SliceRule rule = SlicesRuleDefinition.slices() // + .matching("org.springframework.(**)..") // + .should().beFreeOfCycles(); + + rule.check(classes); + } +} diff --git a/src/test/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilderUnitTest.java b/src/test/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilderUnitTest.java index 823b306c..771e9d5c 100644 --- a/src/test/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilderUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mvc/SpringMvcAffordanceBuilderUnitTest.java @@ -24,9 +24,9 @@ import org.junit.Test; import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; import org.springframework.hateoas.AffordanceModel; +import org.springframework.hateoas.AffordanceModelFactory; import org.springframework.hateoas.Link; import org.springframework.hateoas.QueryParameter; -import org.springframework.hateoas.core.AffordanceModelFactory; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.plugin.core.OrderAwarePluginRegistry; diff --git a/src/test/kotlin/org/springframework/hateoas/AffordanceBuilderDslUnitTest.kt b/src/test/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDslUnitTest.kt similarity index 98% rename from src/test/kotlin/org/springframework/hateoas/AffordanceBuilderDslUnitTest.kt rename to src/test/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDslUnitTest.kt index 21567901..81a12dd5 100644 --- a/src/test/kotlin/org/springframework/hateoas/AffordanceBuilderDslUnitTest.kt +++ b/src/test/kotlin/org/springframework/hateoas/mvc/AffordanceBuilderDslUnitTest.kt @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.springframework.hateoas +package org.springframework.hateoas.mvc import org.assertj.core.api.Assertions.assertThat import org.junit.Test +import org.springframework.hateoas.* import org.springframework.http.HttpMethod import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* diff --git a/src/test/kotlin/org/springframework/hateoas/LinkBuilderDslUnitTest.kt b/src/test/kotlin/org/springframework/hateoas/mvc/LinkBuilderDslUnitTest.kt similarity index 97% rename from src/test/kotlin/org/springframework/hateoas/LinkBuilderDslUnitTest.kt rename to src/test/kotlin/org/springframework/hateoas/mvc/LinkBuilderDslUnitTest.kt index 764ca14e..68dc7d73 100644 --- a/src/test/kotlin/org/springframework/hateoas/LinkBuilderDslUnitTest.kt +++ b/src/test/kotlin/org/springframework/hateoas/mvc/LinkBuilderDslUnitTest.kt @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -package org.springframework.hateoas +package org.springframework.hateoas.mvc import org.assertj.core.api.Assertions.assertThat import org.junit.Test +import org.springframework.hateoas.* import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.*