@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas.mediatype.collectionjson;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.hateoas.IanaLinkRelations;
|
||||
import org.springframework.hateoas.Link;
|
||||
import org.springframework.hateoas.MediaTypes;
|
||||
import org.springframework.hateoas.client.LinkDiscoverer;
|
||||
import org.springframework.hateoas.client.LinkDiscovererUnitTest;
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.mediatype.hal;
|
||||
|
||||
import org.springframework.hateoas.LinkRelation;
|
||||
import org.springframework.hateoas.server.LinkRelationProvider;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class HalTestUtils {
|
||||
|
||||
public enum DefaultLinkRelationProvider implements LinkRelationProvider {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
return LinkRelation.of("content");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.plugin.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(LookupContext delimiter) {
|
||||
return delimiter.isCollectionRelationLookup();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -52,7 +52,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
* @author Greg Turnquist
|
||||
* @author Jeffrey Walraven
|
||||
*/
|
||||
public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingIntegrationTest {
|
||||
class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingIntegrationTest {
|
||||
|
||||
static final String SINGLE_LINK_REFERENCE = "{\"_links\":{\"self\":{\"href\":\"localhost\"}}}";
|
||||
static final String LIST_LINK_REFERENCE = "{\"_links\":{\"self\":[{\"href\":\"localhost\"},{\"href\":\"localhost2\"}]}}";
|
||||
@@ -85,11 +85,11 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
|
||||
void setUpModule() {
|
||||
|
||||
LinkRelationProvider provider = new DelegatingLinkRelationProvider(new AnnotationLinkRelationProvider(),
|
||||
DefaultLinkRelationProvider.INSTANCE);
|
||||
HalTestUtils.DefaultLinkRelationProvider.INSTANCE);
|
||||
|
||||
mapper.registerModule(new Jackson2HalModule());
|
||||
mapper.setHandlerInstantiator(
|
||||
new HalHandlerInstantiator(provider, CurieProvider.NONE, MessageResolver.DEFAULTS_ONLY, new HalConfiguration()));
|
||||
mapper.setHandlerInstantiator(new HalHandlerInstantiator(provider, CurieProvider.NONE,
|
||||
MessageResolver.DEFAULTS_ONLY, new HalConfiguration()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -480,8 +480,9 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
|
||||
|
||||
AnnotationLinkRelationProvider provider = new AnnotationLinkRelationProvider();
|
||||
|
||||
mapper.setHandlerInstantiator(new HalHandlerInstantiator(provider, CurieProvider.NONE, MessageResolver.DEFAULTS_ONLY,
|
||||
new HalConfiguration().withRenderSingleLinksFor("foo", RenderSingleLinks.AS_ARRAY)));
|
||||
mapper
|
||||
.setHandlerInstantiator(new HalHandlerInstantiator(provider, CurieProvider.NONE, MessageResolver.DEFAULTS_ONLY,
|
||||
new HalConfiguration().withRenderSingleLinksFor("foo", RenderSingleLinks.AS_ARRAY)));
|
||||
|
||||
RepresentationModel<?> resource = new RepresentationModel<>();
|
||||
resource.add(new Link("/some-href", "foo"));
|
||||
@@ -570,36 +571,4 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
|
||||
|
||||
return mapper;
|
||||
}
|
||||
|
||||
public enum DefaultLinkRelationProvider implements LinkRelationProvider {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.LinkRelationProvider#getItemResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getItemResourceRelFor(Class<?> type) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.hateoas.server.LinkRelationProvider#getCollectionResourceRelFor(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
public LinkRelation getCollectionResourceRelFor(Class<?> type) {
|
||||
return LinkRelation.of("content");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.plugin.core.Plugin#supports(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(LookupContext delimiter) {
|
||||
return delimiter.isCollectionRelationLookup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.springframework.http.HttpMethod;
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class HalFormsTemplateBuilderUnitTest {
|
||||
class HalFormsTemplateBuilderUnitTest {
|
||||
|
||||
@ParameterizedTest(name = "Detects regex pattern ''{1}'' for property ''{0}''")
|
||||
@CsvSource({ "number, [0-9]{16}", "overridden, foo", "annotated, bar" })
|
||||
@@ -79,7 +79,8 @@ public class HalFormsTemplateBuilderUnitTest {
|
||||
.withName("post") //
|
||||
.toLink());
|
||||
|
||||
HalFormsTemplateBuilder builder = new HalFormsTemplateBuilder(new HalFormsConfiguration(), MessageResolver.DEFAULTS_ONLY);
|
||||
HalFormsTemplateBuilder builder = new HalFormsTemplateBuilder(new HalFormsConfiguration(),
|
||||
MessageResolver.DEFAULTS_ONLY);
|
||||
|
||||
Map<String, HalFormsTemplate> templates = builder.findTemplates(model);
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ import org.springframework.hateoas.mediatype.Affordances;
|
||||
import org.springframework.hateoas.mediatype.MessageResolver;
|
||||
import org.springframework.hateoas.mediatype.hal.CurieProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.DefaultCurieProvider;
|
||||
import org.springframework.hateoas.mediatype.hal.Jackson2HalIntegrationTest;
|
||||
import org.springframework.hateoas.mediatype.hal.HalTestUtils;
|
||||
import org.springframework.hateoas.mediatype.hal.SimpleAnnotatedPojo;
|
||||
import org.springframework.hateoas.mediatype.hal.SimplePojo;
|
||||
import org.springframework.hateoas.mediatype.hal.forms.Jackson2HalFormsModule.HalFormsHandlerInstantiator;
|
||||
@@ -82,15 +82,11 @@ class Jackson2HalFormsIntegrationTest extends AbstractJackson2MarshallingIntegra
|
||||
new Link("bar", IanaLinkRelations.PREV) //
|
||||
);
|
||||
|
||||
// MessageSource messageSource = mock(MessageSource.class);
|
||||
|
||||
@BeforeEach
|
||||
void setUpModule() {
|
||||
|
||||
// TestAffordances.enableMediaTypes(MediaTypes.HAL_FORMS_JSON);
|
||||
|
||||
LinkRelationProvider provider = new DelegatingLinkRelationProvider(new AnnotationLinkRelationProvider(),
|
||||
Jackson2HalIntegrationTest.DefaultLinkRelationProvider.INSTANCE);
|
||||
HalTestUtils.DefaultLinkRelationProvider.INSTANCE);
|
||||
|
||||
mapper.registerModule(new Jackson2HalFormsModule());
|
||||
mapper.setHandlerInstantiator(new HalFormsHandlerInstantiator( //
|
||||
|
||||
Reference in New Issue
Block a user