|
18 | 18 |
|
19 | 19 | import java.io.IOException;
|
20 | 20 | import java.util.HashMap;
|
| 21 | +import java.util.List; |
21 | 22 | import java.util.Map;
|
22 | 23 |
|
23 | 24 | import org.junit.Test;
|
|
29 | 30 | import org.springframework.restdocs.operation.OperationResponseFactory;
|
30 | 31 |
|
31 | 32 | import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
| 33 | +import static org.assertj.core.api.Assertions.assertThat; |
32 | 34 | import static org.mockito.Mockito.mock;
|
33 | 35 | import static org.mockito.Mockito.verify;
|
34 | 36 |
|
|
40 | 42 | public class ContentTypeLinkExtractorTests {
|
41 | 43 |
|
42 | 44 | private final OperationResponseFactory responseFactory = new OperationResponseFactory();
|
| 45 | + private final String halBody = "{ \"_links\" : { \"someRel\" : { \"href\" : \"someHref\" }} }"; |
43 | 46 |
|
44 | 47 | @Test
|
45 | 48 | public void extractionFailsWithNullContentType() {
|
@@ -71,4 +74,22 @@ public void extractorCalledWithCompatibleContextType() throws IOException {
|
71 | 74 | verify(extractor).extractLinks(response);
|
72 | 75 | }
|
73 | 76 |
|
| 77 | + @Test |
| 78 | + public void extractsLinksFromVndHalMediaType() throws IOException { |
| 79 | + HttpHeaders httpHeaders = new HttpHeaders(); |
| 80 | + httpHeaders.setContentType(MediaType.parseMediaType("application/vnd.hal+json")); |
| 81 | + OperationResponse response = this.responseFactory.create(HttpStatus.OK, httpHeaders, halBody.getBytes()); |
| 82 | + Map<String, List<Link>> links = new ContentTypeLinkExtractor().extractLinks(response); |
| 83 | + assertThat(links).containsKey("someRel"); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + public void extractsLinksFromHalFormsMediaType() throws IOException { |
| 88 | + HttpHeaders httpHeaders = new HttpHeaders(); |
| 89 | + httpHeaders.setContentType(MediaType.parseMediaType("application/prs.hal-forms+json")); |
| 90 | + OperationResponse response = this.responseFactory.create(HttpStatus.OK, httpHeaders, halBody.getBytes()); |
| 91 | + Map<String, List<Link>> links = new ContentTypeLinkExtractor().extractLinks(response); |
| 92 | + assertThat(links).containsKey("someRel"); |
| 93 | + } |
| 94 | + |
74 | 95 | }
|
0 commit comments