public LinkRepresentation withRel(Rel rel) { return withRel(rel.getName()); }
@Test public void forLink_whenSimpleKey() throws IOException { link.withRel("someRel"); assertThat(jsonRepresentation.isLink("aLink"), is(true)); assertThat(jsonRepresentation.getLink("aLink"), is(link)); }
@Test public void test() throws UnsupportedEncodingException { final LinkRepresentation l = new LinkRepresentation().withRel("object").withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final String expectedValue = "%7B%22method%22%3A%22GET%22%2C%22rel%22%3A%22object%22%2C%22href%22%3A%22http%3A%2F%2Flocalhost%3A8080%2Fobjects%2FABC%3A123%22%7D"; @SuppressWarnings("unused") final String decoded = URLDecoder.decode(expectedValue, Charsets.UTF_8.name()); assertThat(l.asUrlEncoded(), is(expectedValue)); } }
@Test public void forLink_whenSimpleKey() throws JsonParseException, JsonMappingException, IOException { link.withRel("someRel"); assertThat(jsonRepresentation.isLink("aLink"), is(true)); assertThat(jsonRepresentation.getLink("aLink"), is(link)); }
@Test public void forLink_whenMultipartKey() throws JsonParseException, JsonMappingException, IOException { link.withRel("someSubRel"); assertThat(jsonRepresentation.isLink("aSubMap.aLink"), is(true)); assertThat(jsonRepresentation.getLink("aSubMap.aLink"), is(link)); }
@Test public void test() throws UnsupportedEncodingException { final LinkRepresentation l = new LinkRepresentation().withRel("object").withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET); final String expectedValue = "%7B%22method%22%3A%22GET%22%2C%22rel%22%3A%22object%22%2C%22href%22%3A%22http%3A%2F%2Flocalhost%3A8080%2Fobjects%2FABC%3A123%22%7D"; @SuppressWarnings("unused") final String decoded = URLDecoder.decode(expectedValue, Charsets.UTF_8.name()); assertThat(l.asUrlEncoded(), is(expectedValue)); } }
@Test public void forLink_whenMultipartKey() throws IOException { link.withRel("someSubRel"); assertThat(jsonRepresentation.isLink("aSubMap.aLink"), is(true)); assertThat(jsonRepresentation.getLink("aSubMap.aLink"), is(link)); }
@Test public void equalDoesNotDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("something"); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("else"); assertThat(link, is(equalTo(link2))); }
@Test public void equalDoesNotDependsOnMethodAndHref() throws UnsupportedEncodingException { final LinkRepresentation link = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("something"); final LinkRepresentation link2 = new LinkRepresentation().withHref("http://localhost:8080/objects/ABC:123").withMethod(RestfulHttpMethod.GET).withRel("else"); assertThat(link, is(equalTo(link2))); }
@Test public void withPredicate() throws IOException { // given link = new LinkRepresentation().withRel(Rel.SELF).withHref("http://foo/bar").withMethod(RestfulHttpMethod.GET); JsonRepresentation linkListRepr = JsonRepresentation.newArray(); linkListRepr.arrayAdd(link); jsonRepresentation = JsonRepresentation.newMap(); jsonRepresentation.mapPut("links", linkListRepr); // when, then assertThat(jsonRepresentation.isLink("links[rel=self]"), is(true)); assertThat(jsonRepresentation.getLink("links[rel=self]"), is(not(nullValue()))); assertThat(jsonRepresentation.isLink("links[rel=other]"), is(false)); assertThat(jsonRepresentation.getLink("links[rel=other]"), is(nullValue())); }
@Test public void withPredicate() throws JsonParseException, JsonMappingException, IOException { // given link = new LinkRepresentation().withRel(Rel.SELF).withHref("http://foo/bar").withMethod(RestfulHttpMethod.GET); JsonRepresentation linkListRepr = JsonRepresentation.newArray(); linkListRepr.arrayAdd(link); jsonRepresentation = JsonRepresentation.newMap(); jsonRepresentation.mapPut("links", linkListRepr); // when, then assertThat(jsonRepresentation.isLink("links[rel=self]"), is(true)); assertThat(jsonRepresentation.getLink("links[rel=self]"), is(not(nullValue()))); assertThat(jsonRepresentation.isLink("links[rel=other]"), is(false)); assertThat(jsonRepresentation.getLink("links[rel=other]"), is(nullValue())); }