MultiStatusResponse { public static MultiStatusResponse fromJson(ObjectMapper mapper, InputStream stream) throws IOException { List<Map<String, Object>> responses = mapper.readValue(stream, REF_MULTI_RESPONSE); try { Map<String, Integer> responseMap = responses.stream() .map(map -> new AbstractMap.SimpleEntry<>(extractResourceId(map), extractStatus(map))) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); return new MultiStatusResponse(responseMap); } catch (IllegalArgumentException e) { throw new IOException("Failed to parse JSON response", e); } } MultiStatusResponse(Map<String, Integer> responses); static MultiStatusResponse fromJson(ObjectMapper mapper, InputStream stream); Map<String, Integer> getResponses(); int responseCount(); boolean isAllSuccess(); boolean hasResourceId(String resId); int getStatus(String resId); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test(expected = IOException.class) public void testFromJsonInvalidStatusCodes() throws IOException { String json = "[{\"resourceId\": \"res-1234\"," + "\"status\": \"invalidStatus\"}]"; InputStream stream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); MultiStatusResponse.fromJson(new ObjectMapper(), stream); }
@Test(expected = IOException.class) public void testFromJsonMissingResourceId() throws IOException { String json = "[{\"noResourceId\": \"res-undefined\"," + "\"status\": 200}]"; InputStream stream = new ByteArrayInputStream(json.getBytes(StandardCharsets.UTF_8)); MultiStatusResponse.fromJson(new ObjectMapper(), stream); }