#1080 - Improved configuration setup and documentation on EntityLinks.

We now explicitly only enable EntityLinks in WebMVC environments. This is also now reflected properly in the reference documentation.
This commit is contained in:
Oliver Drotbohm
2019-09-26 15:21:35 +02:00
parent 26a0dd8794
commit 30ddf1873c
4 changed files with 26 additions and 15 deletions

View File

@@ -18,9 +18,12 @@ package org.springframework.hateoas.config;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType;
import org.springframework.hateoas.server.EntityLinks;
import org.springframework.hateoas.support.WebStack;
/**
@@ -35,7 +38,7 @@ class WebStackImportSelectorUnitTest {
@Test // #973
void activatesAllWebStacksByDefault() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(DefaultHypermedia.class);
AnnotationMetadata metadata = AnnotationMetadata.introspect(DefaultHypermedia.class);
assertThat(selector.selectImports(metadata))
.containsExactlyInAnyOrderElementsOf(WebStackImportSelector.CONFIGS.values());
@@ -44,7 +47,7 @@ class WebStackImportSelectorUnitTest {
@Test // #973
void activatesWebMvcOnlyifConfigured() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(WebMvcHypermedia.class);
AnnotationMetadata metadata = AnnotationMetadata.introspect(WebMvcHypermedia.class);
assertThat(selector.selectImports(metadata)).containsExactly(WebStackImportSelector.CONFIGS.get(WebStack.WEBMVC));
}
@@ -52,7 +55,7 @@ class WebStackImportSelectorUnitTest {
@Test // #973
void activatesWebFluxOnlyIfConfigured() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(WebFluxHypermedia.class);
AnnotationMetadata metadata = AnnotationMetadata.introspect(WebFluxHypermedia.class);
assertThat(selector.selectImports(metadata)).containsExactly(WebStackImportSelector.CONFIGS.get(WebStack.WEBFLUX));
}
@@ -60,13 +63,23 @@ class WebStackImportSelectorUnitTest {
@Test // #973
void rejectsNoStacksSelected() {
AnnotationMetadata metadata = new StandardAnnotationMetadata(NoStacksHypermedia.class);
AnnotationMetadata metadata = AnnotationMetadata.introspect(NoStacksHypermedia.class);
assertThatExceptionOfType(IllegalStateException.class) //
.isThrownBy(() -> selector.selectImports(metadata)) //
.withMessageContaining(NoStacksHypermedia.class.getName());
}
@Test // #1080
void noEntityLinksRegisteredForWebFluxBootstrap() throws Exception {
try (ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(WebFluxHypermedia.class)) {
assertThatExceptionOfType(NoSuchBeanDefinitionException.class) //
.isThrownBy(() -> context.getBean(EntityLinks.class));
}
}
@EnableHypermediaSupport(type = HypermediaType.HAL)
static class DefaultHypermedia {}