@Test public void testSuccessHttpResponse() throws Exception { List<TestDoc> objects = Arrays.asList(new TestDoc("0", "rev0"), new TestDoc("1", "rev1"), new TestDoc("2", "rev2")); BulkOperationResponseHandler h = new BulkOperationResponseHandler(objects, new ObjectMapper()); List<DocumentOperationResult> errors = h.success(ResponseOnFileStub.newInstance(202, "bulk_response.json")); assertEquals(1, errors.size()); assertEquals("0", errors.get(0).getId()); assertEquals("conflict", errors.get(0).getError()); assertEquals("Document update conflict.", errors.get(0).getReason()); assertEquals("1", objects.get(1).getId()); assertEquals("new_rev1", objects.get(1).getRevision()); assertEquals("2", objects.get(2).getId()); assertEquals("new_rev2", objects.get(2).getRevision()); }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") public List<DocumentOperationResult> success(HttpResponse hr) throws Exception { JsonParser jp = objectMapper.getFactory().createParser(hr.getContent()); List<DocumentOperationResult> result = new ArrayList<DocumentOperationResult>(); Iterator<?> objectsIter = objects == null ? null : objects.iterator(); while (jp.nextToken() != null) { switch (jp.getCurrentToken()) { case START_OBJECT: jp.nextToken(); if ("ok".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); } jp.nextToken(); String id = jp.getText(); jp.nextToken(); String nextField = jp.getCurrentName(); if ("error".equals(nextField)) { result.add(readError(jp, objectsIter, id)); } else { setIdAndRevision(jp, objectsIter, id); } } } return result; }
BulkOperationResponseHandler extends StdResponseHandler<List<DocumentOperationResult>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") public List<DocumentOperationResult> success(HttpResponse hr) throws Exception { JsonParser jp = objectMapper.getFactory().createParser(hr.getContent()); List<DocumentOperationResult> result = new ArrayList<DocumentOperationResult>(); Iterator<?> objectsIter = objects == null ? null : objects.iterator(); while (jp.nextToken() != null) { switch (jp.getCurrentToken()) { case START_OBJECT: jp.nextToken(); if ("ok".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); } jp.nextToken(); String id = jp.getText(); jp.nextToken(); String nextField = jp.getCurrentName(); if ("error".equals(nextField)) { result.add(readError(jp, objectsIter, id)); } else { setIdAndRevision(jp, objectsIter, id); } } } return result; } }
BulkOperationResponseHandler extends StdResponseHandler<List<DocumentOperationResult>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") public List<DocumentOperationResult> success(HttpResponse hr) throws Exception { JsonParser jp = objectMapper.getFactory().createParser(hr.getContent()); List<DocumentOperationResult> result = new ArrayList<DocumentOperationResult>(); Iterator<?> objectsIter = objects == null ? null : objects.iterator(); while (jp.nextToken() != null) { switch (jp.getCurrentToken()) { case START_OBJECT: jp.nextToken(); if ("ok".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); } jp.nextToken(); String id = jp.getText(); jp.nextToken(); String nextField = jp.getCurrentName(); if ("error".equals(nextField)) { result.add(readError(jp, objectsIter, id)); } else { setIdAndRevision(jp, objectsIter, id); } } } return result; } BulkOperationResponseHandler(ObjectMapper om);  BulkOperationResponseHandler(Collection<?> objects,ObjectMapper om); }
BulkOperationResponseHandler extends StdResponseHandler<List<DocumentOperationResult>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") public List<DocumentOperationResult> success(HttpResponse hr) throws Exception { JsonParser jp = objectMapper.getFactory().createParser(hr.getContent()); List<DocumentOperationResult> result = new ArrayList<DocumentOperationResult>(); Iterator<?> objectsIter = objects == null ? null : objects.iterator(); while (jp.nextToken() != null) { switch (jp.getCurrentToken()) { case START_OBJECT: jp.nextToken(); if ("ok".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); } jp.nextToken(); String id = jp.getText(); jp.nextToken(); String nextField = jp.getCurrentName(); if ("error".equals(nextField)) { result.add(readError(jp, objectsIter, id)); } else { setIdAndRevision(jp, objectsIter, id); } } } return result; } BulkOperationResponseHandler(ObjectMapper om);  BulkOperationResponseHandler(Collection<?> objects,ObjectMapper om); @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") List<DocumentOperationResult> success(HttpResponse hr); }
BulkOperationResponseHandler extends StdResponseHandler<List<DocumentOperationResult>> { @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") public List<DocumentOperationResult> success(HttpResponse hr) throws Exception { JsonParser jp = objectMapper.getFactory().createParser(hr.getContent()); List<DocumentOperationResult> result = new ArrayList<DocumentOperationResult>(); Iterator<?> objectsIter = objects == null ? null : objects.iterator(); while (jp.nextToken() != null) { switch (jp.getCurrentToken()) { case START_OBJECT: jp.nextToken(); if ("ok".equals(jp.getCurrentName())) { jp.nextToken(); jp.nextToken(); } jp.nextToken(); String id = jp.getText(); jp.nextToken(); String nextField = jp.getCurrentName(); if ("error".equals(nextField)) { result.add(readError(jp, objectsIter, id)); } else { setIdAndRevision(jp, objectsIter, id); } } } return result; } BulkOperationResponseHandler(ObjectMapper om);  BulkOperationResponseHandler(Collection<?> objects,ObjectMapper om); @Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="SF_SWITCH_NO_DEFAULT") List<DocumentOperationResult> success(HttpResponse hr);  }