private static String linkFromFormalArgs(final String argumentsQueryString, final String paramName) { final JsonRepresentation arguments = DomainResourceHelper.readQueryStringAsMap(argumentsQueryString); if (!arguments.isLink(paramName)) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Args should contain a link '%s'", paramName); } return arguments.getLink(paramName).getHref(); }
private static String linkFromFormalArgs(final String argumentsAsQueryString, final String paramName) { final JsonRepresentation arguments = Util.readQueryStringAsMap(argumentsAsQueryString); if (!arguments.isLink(paramName)) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Args should contain a link '%s'", paramName); } return arguments.getLink(paramName).getHref(); }
private static String linkFromFormalArgs(final String argumentsQueryString, final String paramName) { final JsonRepresentation arguments = DomainResourceHelper.readQueryStringAsMap(argumentsQueryString); if (!arguments.isLink(paramName)) { throw RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "Args should contain a link '%s'", paramName); } return arguments.getLink(paramName).getHref(); }
@Test public void forNonExistent() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.isLink("doesNotExist"), is(false)); assertThat(jsonRepresentation.getLink("doesNotExist"), is(nullValue())); }
@Test public void forNonExistent() throws IOException { assertThat(jsonRepresentation.isLink("doesNotExist"), is(false)); assertThat(jsonRepresentation.getLink("doesNotExist"), is(nullValue())); }
@Test public void forValue() throws IOException { assertThat(jsonRepresentation.isLink("anInt"), is(false)); try { jsonRepresentation.getLink("anInt"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'anInt' is a value that does not represent a link")); } }
@Test public void forMap() throws IOException { assertThat(jsonRepresentation.isLink("aSubMap"), is(false)); try { jsonRepresentation.getLink("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is a map that does not fully represent a link")); } }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.isLink("aSubList"), is(false)); try { jsonRepresentation.getLink("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is an array that does not represent a link")); } }
@Test public void forList() throws IOException { assertThat(jsonRepresentation.isLink("aSubList"), is(false)); try { jsonRepresentation.getLink("aSubList"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubList' is an array that does not represent a link")); } }
@Test public void forValue() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.isLink("anInt"), is(false)); try { jsonRepresentation.getLink("anInt"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'anInt' is a value that does not represent a link")); } }
@Test public void forMap() throws JsonParseException, JsonMappingException, IOException { assertThat(jsonRepresentation.isLink("aSubMap"), is(false)); try { jsonRepresentation.getLink("aSubMap"); fail(); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), is("'aSubMap' is a map that does not fully represent a 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 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 IOException { link.withRel("someSubRel"); assertThat(jsonRepresentation.isLink("aSubMap.aLink"), is(true)); assertThat(jsonRepresentation.getLink("aSubMap.aLink"), is(link)); }
@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 forListWithMultipleCriteriaMatchingOne() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel data=someData]"); assertThat(representation.isLink(), is(true)); assertThat(representation.asLink().getHref(), is("http://foo/bar/multiRel1")); }
@Test public void forListWithMultipleCriteriaMatchingOne() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel data=someData]"); assertThat(representation.isLink(), is(true)); assertThat(representation.asLink().getHref(), is("http://foo/bar/multiRel1")); }
@Test public void forListWithSingleCriteriaMatchingOne() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=aRel]"); assertThat(representation.isLink(), is(true)); assertThat(representation.asLink().getHref(), is("http://foo/bar")); }
@Test public void forListWithSingleCriteriaMatchingOne() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=aRel]"); assertThat(representation.isLink(), is(true)); assertThat(representation.asLink().getHref(), is("http://foo/bar")); }
@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())); }