@Test public void getServiceDocument() throws Exception { String result = mvc.perform( MockMvcRequestBuilders.get("/") .accept("application/hal+json;charset=UTF-8") ).andDo(print()) .andExpect(content() .contentTypeCompatibleWith("application/hal+json;charset=UTF-8")) .andReturn().getResponse().getContentAsString(); Resource<String> value = mapper.readValue(result, new TypeReference<Resource<String>>() { }); List<String> linkRels = value.getLinks().stream().map(link -> link.getRel()).collect(Collectors.toList()); assertThat(linkRels, Matchers.hasItem("self")); assertEquals(value.getLink("self"), value.getId()); assertTrue(value.hasLink("bookmarks")); }
@GetMapping("/") public Resource<String> getServiceDocument() throws URISyntaxException { return new Resource<>("Yummy is the best service", BasicLinkBuilder.linkToCurrentMapping().withSelfRel(), linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("bookmarks") ); }
ServiceDocumentController { @GetMapping("/") public Resource<String> getServiceDocument() throws URISyntaxException { return new Resource<>("Yummy is the best service", BasicLinkBuilder.linkToCurrentMapping().withSelfRel(), linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("bookmarks") ); } }
ServiceDocumentController { @GetMapping("/") public Resource<String> getServiceDocument() throws URISyntaxException { return new Resource<>("Yummy is the best service", BasicLinkBuilder.linkToCurrentMapping().withSelfRel(), linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("bookmarks") ); }  }
ServiceDocumentController { @GetMapping("/") public Resource<String> getServiceDocument() throws URISyntaxException { return new Resource<>("Yummy is the best service", BasicLinkBuilder.linkToCurrentMapping().withSelfRel(), linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("bookmarks") ); }  @GetMapping("/") Resource<String> getServiceDocument(); }
ServiceDocumentController { @GetMapping("/") public Resource<String> getServiceDocument() throws URISyntaxException { return new Resource<>("Yummy is the best service", BasicLinkBuilder.linkToCurrentMapping().withSelfRel(), linkTo(methodOn(BookmarksController.class).addBookmark(null)).withRel("bookmarks") ); }  @GetMapping("/") Resource<String> getServiceDocument();  }