16
16
package org .springframework .hateoas .server .mvc ;
17
17
18
18
import static org .assertj .core .api .AssertionsForInterfaceTypes .*;
19
+ import static org .springframework .hateoas .MappingTestUtils .*;
19
20
import static org .springframework .hateoas .MediaTypes .*;
20
21
import static org .springframework .hateoas .server .mvc .WebMvcLinkBuilder .*;
21
- import static org .springframework .hateoas .support .MappingUtils .*;
22
22
import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .*;
23
23
import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .*;
24
24
import static org .springframework .test .web .servlet .setup .MockMvcBuilders .*;
33
33
import org .springframework .beans .factory .annotation .Autowired ;
34
34
import org .springframework .context .annotation .Bean ;
35
35
import org .springframework .context .annotation .Configuration ;
36
- import org .springframework .core .io .ClassPathResource ;
37
36
import org .springframework .hateoas .Link ;
38
37
import org .springframework .hateoas .LinkRelation ;
39
38
import org .springframework .hateoas .ModelBuilder2 ;
@@ -68,13 +67,17 @@ public class Embedded2IntegrationTest {
68
67
69
68
private @ Autowired WebApplicationContext context ;
70
69
private MockMvc mockMvc ;
70
+ private ContextualMapper contextualMapper ;
71
71
72
72
@ BeforeEach
73
73
public void setUp () {
74
+
74
75
this .mockMvc = webAppContextSetup (this .context ).build ();
76
+ this .contextualMapper = createMapper (getClass ());
77
+
75
78
}
76
79
77
- @ Test
80
+ @ Test // #864
78
81
public void embeddedSpecUsingAPIs () throws Exception {
79
82
80
83
String results = this .mockMvc .perform (get ("/author/1" ).accept (HAL_JSON )) //
@@ -83,10 +86,10 @@ public void embeddedSpecUsingAPIs() throws Exception {
83
86
.getResponse () //
84
87
.getContentAsString ();
85
88
86
- assertThat (results ).isEqualTo (read ( new ClassPathResource ( "hal-embedded-author-illustrator.json" , getClass ()) ));
89
+ assertThat (results ).isEqualTo (contextualMapper . readFile ( "hal-embedded-author-illustrator.json" ));
87
90
}
88
91
89
- @ Test
92
+ @ Test // #864
90
93
public void singleItem () throws Exception {
91
94
92
95
String results = this .mockMvc .perform (get ("/other-author" ).accept (HAL_JSON )) //
@@ -95,10 +98,10 @@ public void singleItem() throws Exception {
95
98
.getResponse () //
96
99
.getContentAsString ();
97
100
98
- assertThat (results ).isEqualTo (read ( new ClassPathResource ( "hal-single-item.json" , getClass ()) ));
101
+ assertThat (results ).isEqualTo (contextualMapper . readFile ( "hal-single-item.json" ));
99
102
}
100
103
101
- @ Test
104
+ @ Test // #864
102
105
public void collection () throws Exception {
103
106
104
107
String results = this .mockMvc .perform (get ("/authors" ).accept (HAL_JSON )) //
@@ -107,9 +110,7 @@ public void collection() throws Exception {
107
110
.getResponse () //
108
111
.getContentAsString ();
109
112
110
- System .out .println (results );
111
-
112
- assertThat (results ).isEqualTo (read (new ClassPathResource ("hal-embedded-collection.json" , getClass ())));
113
+ assertThat (results ).isEqualTo (contextualMapper .readFile ("hal-embedded-collection.json" ));
113
114
}
114
115
115
116
@ RestController
@@ -122,7 +123,7 @@ RepresentationModel<?> singleItem() {
122
123
123
124
return ModelBuilder2 //
124
125
.entity (new Author ("Alan Watts" , "January 6, 1915" , "November 16, 1973" )) //
125
- .link (new Link ("/people/alan-watts" )) //
126
+ .link (Link . of ("/people/alan-watts" )) //
126
127
.build ();
127
128
}
128
129
@@ -158,15 +159,15 @@ RepresentationModel<?> authorDetails(@PathVariable int id) {
158
159
return ModelBuilder2 //
159
160
.subModel (LinkRelation .of ("author" ), ModelBuilder2 //
160
161
.entity (new Author ("Alan Watts" , "January 6, 1915" , "November 16, 1973" )) //
161
- .link (new Link ("/people/alan-watts" )) //
162
+ .link (Link . of ("/people/alan-watts" )) //
162
163
.build ())
163
164
.subModel (LinkRelation .of ("illustrator" ), ModelBuilder2 //
164
165
.entity (new Author ("John Smith" , null , null )) //
165
- .link (new Link ("/people/john-smith" )) //
166
+ .link (Link . of ("/people/john-smith" )) //
166
167
.build ())
167
- .link (new Link ("/books/the-way-of-zen" )) //
168
- .link (new Link ("/people/alan-watts" , LinkRelation .of ("author" ))) //
169
- .link (new Link ("/people/john-smith" , LinkRelation .of ("illustrator" ))) //
168
+ .link (Link . of ("/books/the-way-of-zen" )) //
169
+ .link (Link . of ("/people/alan-watts" , LinkRelation .of ("author" ))) //
170
+ .link (Link . of ("/people/john-smith" , LinkRelation .of ("illustrator" ))) //
170
171
.build ();
171
172
}
172
173
}
0 commit comments