ObjectAdapter parseAsMapWithSingleValue(final JsonRepresentation arguments) { final JsonRepresentation representation = arguments.getRepresentation("value"); if (arguments.size() != 1 || representation == null) { throw RestfulObjectsApplicationException.createWithMessage(RestfulResponse.HttpStatusCode.BAD_REQUEST, "Body should be a map with a single key 'value' whose value represents an instance of type '%s'", resourceFor(objectSpec)); } return objectAdapterFor(arguments); }
ObjectAdapter parseAsMapWithSingleValue(final ObjectSpecification objectSpec, final JsonRepresentation arguments) { final JsonRepresentation representation = arguments.getRepresentation("value"); if (arguments.size() != 1 || representation == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.BAD_REQUEST, "Body should be a map with a single key 'value' whose value represents an instance of type '%s'", resourceFor(objectSpec)); } return objectAdapterFor(resourceContext, objectSpec, representation); }
ObjectAdapter parseAsMapWithSingleValue(final ObjectSpecification objectSpec, final JsonRepresentation arguments) { final JsonRepresentation representation = arguments.getRepresentation("value"); if (arguments.size() != 1 || representation == null) { throw RestfulObjectsApplicationException.createWithMessage(HttpStatusCode.BAD_REQUEST, "Body should be a map with a single key 'value' whose value represents an instance of type '%s'", resourceFor(objectSpec)); } return objectAdapterFor(resourceContext, objectSpec, arguments); }
@Test public void whenStartingWithList() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks"); final JsonRepresentation representation = listRepresentation.getRepresentation("[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void whenStartingWithList() throws IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks"); final JsonRepresentation representation = listRepresentation.getRepresentation("[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void forList() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation listRepresentation = jsonRepresentation.getRepresentation("aSubList"); assertThat(listRepresentation.isArray(), is(true)); }
@Test public void forListWithMultipleCriteriaMatchingMultiple() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void forListWithMultipleCriteriaMatchingMultiple() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("anotherSubMap.aListOfLinks[rel=multiRel method=GET]"); assertThat(representation.isArray(), is(true)); assertThat(representation.size(), is(2)); }
@Test public void forPath() throws IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("aSubMap.aLink"); assertThat(representation.isMap(), is(true)); assertThat(representation.getString("href"), is("http://foo/bar")); }
@Test public void forPath() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation representation = jsonRepresentation.getRepresentation("aSubMap.aLink"); assertThat(representation.isMap(), is(true)); assertThat(representation.getString("href"), is("http://foo/bar")); }
@Test public void forMap() throws IOException { final JsonRepresentation mapRepresentation = jsonRepresentation.getRepresentation("aLink"); assertThat(mapRepresentation.getString("rel"), is("someRel")); assertThat(mapRepresentation.isMap(), is(true)); }
@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 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 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 forValue() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("aString"); assertThat(valueRepresentation.isArray(), is(false)); assertThat(valueRepresentation.isMap(), is(false)); assertThat(valueRepresentation.isValue(), is(true)); }
@Test(expected = IllegalStateException.class) public void size_forValue() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.size(); }
@Test(expected = IllegalStateException.class) public void size_forValue() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.size(); }
@Test(expected = IllegalStateException.class) public void arrayGet_forValue() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.arrayGet(0); }
@Test(expected = IllegalStateException.class) public void arrayGet_forValue() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); final JsonRepresentation valueRepresentation = jsonRepresentation.getRepresentation("anInt"); valueRepresentation.arrayGet(0); }