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); }
@Test public void nonEmptyArray() throws IOException { final JsonRepresentation array = jsonRepresentation.getArray("aStringArray"); assertThat(array, is(not(nullValue()))); assertThat(array.size(), is(3)); }
@Test public void emptyArray() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation array = jsonRepresentation.getArray("anEmptyArray"); assertThat(array, is(not(nullValue()))); assertThat(array.size(), is(0)); }
@Test public void getProperties() throws JsonParseException, JsonMappingException, IOException { final JsonRepresentation properties = representation.getProperties(); final JsonRepresentation members = representation.getMembers(); assertThat(members.size(), is(12)); assertThat(properties.isMap(), is(true)); assertThat(properties.size(), is(10)); }
@Test public void size_forEmptyList() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyList.json")); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void size_forEmptyMap() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyMap.json")); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void size_forNonEmptyMap() throws JsonParseException, JsonMappingException, IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); assertThat(jsonRepresentation.size(), is(16)); }
@Test public void whenNull() throws Exception { representation = DomainResourceHelper.readAsMap(null); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void newArray() throws Exception { final JsonRepresentation jsonRepresentation = JsonRepresentation.newArray(); assertThat(jsonRepresentation.isArray(), is(true)); assertThat(jsonRepresentation.size(), is(0)); }
@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 whenWhitespaceOnlyString() throws Exception { representation = DomainResourceHelper.readAsMap(" \t "); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void whenEmptyString() throws Exception { representation = DomainResourceHelper.readAsMap(""); assertThat(representation.isMap(), is(true)); assertThat(representation.size(), is(0)); }
@Test public void size_forEmptyMap() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("emptyMap.json")); assertThat(jsonRepresentation.size(), is(0)); }
@Test public void size_forNonEmptyMap() throws IOException { jsonRepresentation = new JsonRepresentation(readJson("map.json")); assertThat(jsonRepresentation.size(), is(17)); }
@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(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 public void newArrayInitialSize() throws Exception { final JsonRepresentation jsonRepresentation = JsonRepresentation.newArray(2); assertThat(jsonRepresentation.size(), is(2)); assertThat(jsonRepresentation.arrayGet(0).isNull(), is(true)); assertThat(jsonRepresentation.arrayGet(1).isNull(), is(true)); }