@Test
public void batchResponse() throws Exception {

  final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
  ODataResponse response = new ODataResponse();
  response.setStatusCode(HttpStatusCode.OK.getStatusCode());
  response.setHeader(HttpHeader.CONTENT_TYPE, ContentType.TEXT_PLAIN.toContentTypeString());
  response.setContent(IOUtils.toInputStream("Walter Winter" + CRLF));
  parts.add(new ODataResponsePart(Collections.singletonList(response), false));
  ODataResponse changeSetResponse = new ODataResponse();
  changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
  changeSetResponse.setHeader(HttpHeader.CONTENT_ID, "1");
  parts.add(new ODataResponsePart(Collections.singletonList(changeSetResponse), true));
  BatchResponseSerializer serializer = new BatchResponseSerializer();
  final InputStream content = serializer.serialize(parts, BOUNDARY);
  assertNotNull(content);
  final BatchLineReader reader = new BatchLineReader(content);
  final List<String> body = reader.toList();
  reader.close();
  int line = 0;
  assertEquals(24, body.size());
  assertEquals("--" + BOUNDARY + CRLF, body.get(line++));
  assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
  assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++));
  assertEquals("Content-Type: text/plain" + CRLF, body.get(line++));
  assertEquals("Content-Length: 15" + CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertEquals("Walter Winter" + CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertEquals("--" + BOUNDARY + CRLF, body.get(line++));
  assertTrue(body.get(line++).startsWith("Content-Type: multipart/mixed; boundary=changeset_"));
  assertEquals(CRLF, body.get(line++));
  assertTrue(body.get(line++).startsWith("--changeset_"));
  assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
  assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
  assertEquals("Content-ID: 1" + CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++));
  assertEquals("Content-Length: 0" + CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertEquals(CRLF, body.get(line++));
  assertTrue(body.get(line++).startsWith("--changeset_"));
  assertEquals("--" + BOUNDARY + "--" + CRLF, body.get(line++));
}