Ejemplo n.º 1
0
 @Test
 public void mergeWithSelfShouldReturnEqualTemplatedLink() {
   // given
   final TemplatedLink aboutLink = ABOUTPAGE_LINK;
   // when
   final ResourceLink mergedLink = aboutLink.mergeWith(aboutLink);
   // then
   assertEquals(aboutLink, mergedLink);
 }
Ejemplo n.º 2
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void mergeWithDirectLinkShouldFailWithIllegalStateException() {
   // given
   final TemplatedLink templatedLink = ABOUTPAGE_LINK;
   final DirectLink directLink = STOREFRONT_LINK;
   // when
   templatedLink.mergeWith(directLink);
   // then an exception is thrown.
 }
Ejemplo n.º 3
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void mergeWithShouldFailWithExceptionIfOtherLinksToDifferentResource() {
   // given
   final TemplatedLink aboutPageLink = ABOUTPAGE_LINK;
   final TemplatedLink otherTemplatedLink =
       templatedLink(
           RESOURCELINK_SHOP_PAGE,
           "/foo/{fooId}",
           asList(hrefVar("fooId", VAR_TYPE_PAGEID, emptyDocs())),
           Hints.hints(of(GET), asList("text/html")));
   // when
   aboutPageLink.mergeWith(otherTemplatedLink);
   // then an exception is thrown
 }
Ejemplo n.º 4
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void mergeWithShouldFailWithExceptionIfOtherDoesNotHaveSameRelationType() {
   // given
   final TemplatedLink aboutPageLink = ABOUTPAGE_LINK;
   final TemplatedLink otherTemplatedLink =
       TemplatedLink.templatedLink(
           RESOURCELINK_SHOP_STOREFRONT,
           REL_PAGE_HREF,
           asList(hrefVar("pageId", VAR_TYPE_PAGEID, emptyDocs())),
           Hints.hints(of(GET), asList("text/html")));
   // when
   aboutPageLink.mergeWith(otherTemplatedLink);
   // then an exception is thrown
 }
Ejemplo n.º 5
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void mergeWithShouldFailForDifferentHrefVars() {
   // given
   final TemplatedLink aboutPageLink = ABOUTPAGE_LINK;
   final TemplatedLink otherTemplatedLink =
       templatedLink(
           RESOURCELINK_SHOP_PAGE,
           "pages/{pageId}",
           asList(hrefVar("foo", VAR_TYPE_PAGEID)),
           Hints.hints(of(GET), asList("text/html", "application/json")));
   // when
   aboutPageLink.mergeWith(otherTemplatedLink);
   // then an exception is thrown
 }
Ejemplo n.º 6
0
 @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));
 }
Ejemplo n.º 7
0
 @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"));
 }