37
37
import org .springframework .hateoas .PagedResources .PageMetadata ;
38
38
import org .springframework .hateoas .Resource ;
39
39
import org .springframework .hateoas .ResourceSupport ;
40
+ import org .springframework .hateoas .ResourceSupportUnitTest ;
40
41
import org .springframework .hateoas .Resources ;
41
42
import org .springframework .hateoas .UriTemplate ;
42
43
import org .springframework .hateoas .core .AnnotationRelProvider ;
43
44
import org .springframework .hateoas .core .EmbeddedWrappers ;
44
45
import org .springframework .hateoas .hal .HalConfiguration .RenderSingleLinks ;
45
46
import org .springframework .hateoas .hal .Jackson2HalModule .HalHandlerInstantiator ;
47
+ import org .springframework .hateoas .support .Author ;
46
48
47
49
import com .fasterxml .jackson .databind .ObjectMapper ;
48
50
@@ -58,14 +60,14 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg
58
60
static final String SINGLE_LINK_REFERENCE = "{\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}" ;
59
61
static final String LIST_LINK_REFERENCE = "{\" _links\" :{\" self\" :[{\" href\" :\" localhost\" },{\" href\" :\" localhost2\" }]}}" ;
60
62
61
- static final String SIMPLE_EMBEDDED_RESOURCE_REFERENCE = "{\" _embedded \" :{\" content \" :[ \" first \" , \" second \" ]} ,\" _links \" :{\" self \" :{ \" href \" : \" localhost \" } }}" ;
62
- static final String SINGLE_EMBEDDED_RESOURCE_REFERENCE = "{\" _embedded \" :{\" content \" :[ {\" text \" :\" test1 \" ,\" number \" :1, \" _links \" :{\" self \" :{ \" href \" : \" localhost \" }}}]} ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}" ;
63
- static final String LIST_EMBEDDED_RESOURCE_REFERENCE = "{\" _embedded\" :{\" content\" :[{\" text\" :\" test1\" ,\" number\" :1,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}},{\" text\" :\" test2\" ,\" number\" :2,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}]}, \" _links \" :{ \" self \" :{ \" href \" : \" localhost \" } }}" ;
63
+ static final String SIMPLE_EMBEDDED_RESOURCE_REFERENCE = "{\" _links \" :{\" self \" :{ \" href \" : \" localhost \" }} ,\" _embedded \" :{\" content \" :[ \" first \" , \" second \" ] }}" ;
64
+ static final String SINGLE_EMBEDDED_RESOURCE_REFERENCE = "{\" _links \" :{\" self \" :{\" href \" :\" localhost \" }} ,\" _embedded \" :{ \" content \" :[ {\" text \" :\" test1 \" , \" number \" :1 ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}] }}" ;
65
+ static final String LIST_EMBEDDED_RESOURCE_REFERENCE = "{\" _links \" :{ \" self \" :{ \" href \" : \" localhost \" }}, \" _embedded\" :{\" content\" :[{\" text\" :\" test1\" ,\" number\" :1,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}},{\" text\" :\" test2\" ,\" number\" :2,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}]}}" ;
64
66
65
- static final String ANNOTATED_EMBEDDED_RESOURCE_REFERENCE = "{\" _embedded \" :{\" pojos \" :[ {\" text \" :\" test1 \" ,\" number \" :1, \" _links \" :{\" self \" :{ \" href \" : \" localhost \" }}}]} ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}" ;
67
+ static final String ANNOTATED_EMBEDDED_RESOURCE_REFERENCE = "{\" _links \" :{\" self \" :{\" href \" :\" localhost \" }} ,\" _embedded \" :{ \" pojos \" :[ {\" text \" :\" test1 \" , \" number \" :1 ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}] }}" ;
66
68
static final String ANNOTATED_EMBEDDED_RESOURCES_REFERENCE = "{\" _embedded\" :{\" pojos\" :[{\" text\" :\" test1\" ,\" number\" :1,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}},{\" text\" :\" test2\" ,\" number\" :2,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}]}}" ;
67
69
68
- static final String ANNOTATED_PAGED_RESOURCES = "{\" _embedded \" :{\" pojos \" :[ {\" text \" :\" test1 \" ,\" number \" :1, \" _links \" :{ \" self \" :{ \" href \" :\" localhost \" }}}, {\" text\" :\" test2 \" ,\" number\" :2 ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}}]}, \" _links \" :{ \" next \" :{ \" href \" :\" foo \" }, \" prev \" :{\" href\" :\" bar \" }},\" page\" :{\" size\" :2,\" totalElements\" :4,\" totalPages\" :2,\" number\" :0}}" ;
70
+ static final String ANNOTATED_PAGED_RESOURCES = "{\" _links \" :{\" next \" :{\" href \" :\" foo \" } ,\" prev \" :{ \" href \" :\" bar \" }}, \" _embedded \" :{ \" pojos \" :[ {\" text\" :\" test1 \" ,\" number\" :1 ,\" _links\" :{\" self\" :{\" href\" :\" localhost\" }}},{ \" text \" :\" test2 \" , \" number \" :2, \" _links \" :{ \" self \" :{\" href\" :\" localhost \" }}}] },\" page\" :{\" size\" :2,\" totalElements\" :4,\" totalPages\" :2,\" number\" :0}}" ;
69
71
70
72
static final Links PAGINATION_LINKS = new Links (new Link ("foo" , Link .REL_NEXT ), new Link ("bar" , Link .REL_PREVIOUS ));
71
73
@@ -127,6 +129,20 @@ public void rendersWithOneExtraRFC5988Attribute() throws Exception {
127
129
assertThat (write (resourceSupport )).isEqualTo (SINGLE_WITH_ONE_EXTRA_ATTRIBUTES );
128
130
}
129
131
132
+ @ Test
133
+ public void rendersEmbeddedResourceSupportAsEmbedded () throws Exception {
134
+
135
+ ResourceSupport resourceSupport = new ResourceSupport ();
136
+
137
+ Author author = new Author ("Alan Watts" , "January 6, 1915" , "November 16, 1973" );
138
+ author .add (new Link ("/people/alan-watts" ).withSelfRel ());
139
+
140
+ resourceSupport .addEmbeddedResource ("author" , author );
141
+ resourceSupport .add (new Link ("/blog-post" ).withSelfRel (), new Link ("/people/alan-watts" ).withRel ("author" ));
142
+
143
+ assertThat (write (resourceSupport )).isEqualTo ("{\" _links\" :{\" self\" :{\" href\" :\" /blog-post\" },\" author\" :{\" href\" :\" /people/alan-watts\" }},\" _embedded\" :{\" author\" :{\" name\" :\" Alan Watts\" ,\" born\" :\" January 6, 1915\" ,\" died\" :\" November 16, 1973\" ,\" _links\" :{\" self\" :{\" href\" :\" /people/alan-watts\" }}}}}" );
144
+ }
145
+
130
146
@ Test
131
147
public void deserializeSingleLink () throws Exception {
132
148
ResourceSupport expected = new ResourceSupport ();
0 commit comments