/** * Creates a JsonHome document from a collection of ResourceLinks. The link-relation types of the * resources must be unique, otherwise an IllegalArgumentException is thrown. * * @param resources collection of resource links. * @return JsonHome */ public static JsonHome jsonHome(final Collection<? extends ResourceLink> resources) { final Map<URI, ResourceLink> resourceMap = new HashMap<URI, ResourceLink>(resources.size()); for (final ResourceLink resource : resources) { if (resourceMap.containsKey(resource.getLinkRelationType())) { throw new IllegalArgumentException( "Unable to construct JsonHome. Link-relation types must be unique."); } resourceMap.put(resource.getLinkRelationType(), resource); } return new JsonHome(resourceMap); }
@Test public void mergeWithShouldMergeAllowsSpec() { // given final TemplatedLink aboutPageLink = ABOUTPAGE_LINK; final TemplatedLink otherTemplatedLink = templatedLink( RESOURCELINK_SHOP_PAGE, REL_PAGE_HREF, asList(hrefVar("pageId", VAR_TYPE_PAGEID, emptyDocs())), Hints.hints(of(PUT), asList("text/html", "application/json"))); // when final ResourceLink resourceLink = aboutPageLink.mergeWith(otherTemplatedLink); // then assertEquals(resourceLink.getHints().getAllows(), of(GET, PUT)); }
protected AbstractClientResource( Resource referrer, ResourceLink resouceLink, Class<? extends T> entityClass, ClientUtil clientUtil, boolean invokeGet, ClientFactory clientFactory) throws IllegalArgumentException, UniformInterfaceException { this( referrer, resouceLink.getUri(), resouceLink.getMimeType(), entityClass, clientUtil, invokeGet, clientFactory, true); }
@Test(enabled = false) public void mergeWithShouldMergeAcceptPost() { // given final TemplatedLink thisTemplatedLink = templatedLink( RESOURCELINK_SHOP_PAGE, REL_PAGE_HREF, asList(hrefVar("pageId", VAR_TYPE_PAGEID)), Hints.hints( of(GET, POST), asList("application/foo"), Collections.<String>emptyList(), asList("application/json"), Collections.<Precondition>emptyList(), Status.OK, emptyDocs())); final TemplatedLink thatTemplatedLink = templatedLink( RESOURCELINK_SHOP_PAGE, REL_PAGE_HREF, asList(hrefVar("pageId", VAR_TYPE_PAGEID)), Hints.hints( of(GET, POST), asList("application/foo"), Collections.<String>emptyList(), asList("application/foo"), Collections.<Precondition>emptyList(), Status.OK, emptyDocs())); // when final ResourceLink resourceLink = thisTemplatedLink.mergeWith(thatTemplatedLink); // then final Hints hints = resourceLink.getHints(); assertEquals(hints.getRepresentations(), asList("application/foo")); assertEquals(hints.getAcceptPost(), asList("application/json", "application/foo")); }
public JsonHomeBuilder addResources(final Collection<ResourceLink> resources) { for (final ResourceLink resource : resources) { this.resources.put(resource.getLinkRelationType(), resource); } return this; }
public JsonHomeBuilder addResource(final ResourceLink resource) { this.resources.put(resource.getLinkRelationType(), resource); return this; }