Java Code Examples for org.springframework.hateoas.Links#of()

The following examples show how to use org.springframework.hateoas.Links#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResourceDeserializer.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Override
public EntityModel<?> deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
	ObjectNode node = p.readValueAs(ObjectNode.class);

	ObjectMapper mapper = (ObjectMapper) p.getCodec();

	RepresentationModel resource = mapper.convertValue(node, RepresentationModel.class);
	Links links = Links.of(resource.getLinks());
	
	Object content = mapper.convertValue(node, getResourceDeserializationType(links));
	return new EntityModel<>(content, links);
}
 
Example 2
Source File: DefaultTypeResolverTest.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveTypeWithResolverReturnsResolvedType() {
	Links links = Links.of(new Link("_"));
	Configuration config = Configuration.build();
	
	doReturn(TypeWithResolverSubtype.class)
		.when(Resolver.mockResolver).resolveType(TypeWithResolver.class, links, config);
	
	Class<?> type = resolver.resolveType(TypeWithResolver.class, links, config);
	
	assertThat(type, Matchers.<Class<?>>equalTo(TypeWithResolverSubtype.class));
}
 
Example 3
Source File: ResourceIdMethodHandlerTest.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeWithResourceWithSelfLinkReturnsLinkUri() {
	EntityModel<Object> resource = new EntityModel<>(new Object(), Links.of(new Link("http://www.example.com/1",
		IanaLinkRelations.SELF)));
	
	Object result = new ResourceIdMethodHandler(resource).invoke(null, null, null, null);
	
	assertThat(result, is(URI.create("http://www.example.com/1")));
}
 
Example 4
Source File: ResourceIdMethodHandlerTest.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeWithResourceWithNoSelfLinkReturnsNull() {
	EntityModel<Object> resource = new EntityModel<>(new Object(), Links.of(new Link("http://www.example.com/1",
		"some-other-rel")));
	
	Object result = new ResourceIdMethodHandler(resource).invoke(null, null, null, null);
	
	assertThat(result, is(nullValue()));
}
 
Example 5
Source File: MethodLinkUriResolverTest.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveForMethodWithNoMatchingLinkThrowsException() {
	EntityModel<Object> resource = new EntityModel<>(new Object(), Links.of(new Link("http://www.example.com",
		"other")));
	
	thrown.expect(NoSuchLinkException.class);
	thrown.expect(hasProperty("linkName", is("link1")));
	
	new MethodLinkUriResolver().resolveForMethod(resource, "link1", new Object[0]);
}
 
Example 6
Source File: MethodLinkUriResolverTest.java    From bowman with Apache License 2.0 5 votes vote down vote up
@Test
public void resolveForMethodReturnsUriWithParamsExpanded() {
	EntityModel<Object> resource = new EntityModel<>(new Object(),
		Links.of(new Link("http://www.example.com/{?x,y}",
			"link1")));
	
	URI uri = new MethodLinkUriResolver().resolveForMethod(resource, "link1", new Object[] {"1", 2});
	
	assertThat(uri, is(URI.create("http://www.example.com/?x=1&y=2")));
}
 
Example 7
Source File: OptionalLinksEntitiesAbsentLinksController.java    From bowman with Apache License 2.0 5 votes vote down vote up
@GetMapping("/{id}")
public EntityModel<OptionalLinksEntity> get(@PathVariable("id") Integer id) {
	OptionalLinksEntity entity = repository.findById(id)
		.orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
	
	return new EntityModel<>(entity, Links.of(new Link(
		String.format("http://localhost:8080/optional-links-entities/%s", id))));
}