[OLINGO472] BatchResponseWriter tests improved

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Christian Holzer 2015-01-12 15:00:21 +01:00 committed by Christian Amend
parent 883c89c140
commit c096bbf15c
3 changed files with 62 additions and 16 deletions

View File

@ -80,7 +80,6 @@ public class BatchResponseSerializer {
}
builder.append(getCloseDelimiter(changeSetBoundary));
builder.append(CRLF);
}
private void appendBodyPart(ODataResponse response, StringBuilder builder, boolean isChangeSet)

View File

@ -153,7 +153,7 @@ public class MockedBatchHandlerTest {
reader.close();
int line = 0;
assertEquals(63, responseContent.size());
assertEquals(62, responseContent.size());
// Check change set
assertTrue(responseContent.get(line++).contains("--batch_"));
@ -187,7 +187,6 @@ public class MockedBatchHandlerTest {
} else {
fail();
}
assertEquals(CRLF, responseContent.get(line++));
}
@ -196,9 +195,8 @@ public class MockedBatchHandlerTest {
assertTrue(responseContent.get(line++).contains("--changeset_"));
// Close batch
assertEquals(CRLF, responseContent.get(line++));
assertTrue(responseContent.get(line++).contains("--batch_"));
assertEquals(63, line);
assertEquals(62, line);
}
@Test
@ -305,7 +303,7 @@ public class MockedBatchHandlerTest {
reader.close();
int line = 0;
assertEquals(49, responseContent.size());
assertEquals(47, responseContent.size());
// Check first change set
assertTrue(responseContent.get(line++).contains("--batch_"));
@ -333,7 +331,6 @@ public class MockedBatchHandlerTest {
assertTrue(responseContent.get(line++).contains("--changeset_"));
// Check second change set
assertEquals(CRLF, responseContent.get(line++));
assertTrue(responseContent.get(line++).contains("--batch_"));
assertTrue(responseContent.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
@ -359,10 +356,9 @@ public class MockedBatchHandlerTest {
assertTrue(responseContent.get(line++).contains("--changeset_"));
// Close batch
assertEquals(CRLF, responseContent.get(line++));
assertTrue(responseContent.get(line++).contains("--batch_"));
assertEquals(49, line);
assertEquals(47, line);
}
@Test
@ -425,7 +421,7 @@ public class MockedBatchHandlerTest {
reader.close();
int line = 0;
assertEquals(45, responseContent.size());
assertEquals(44, responseContent.size());
// Check change set
assertTrue(responseContent.get(line++).contains("--batch_"));
@ -462,9 +458,8 @@ public class MockedBatchHandlerTest {
assertTrue(responseContent.get(line++).contains("--changeset_"));
// Close batch
assertEquals(CRLF, responseContent.get(line++));
assertTrue(responseContent.get(line++).contains("--batch_"));
assertEquals(45, line);
assertEquals(44, line);
}
@Test(expected = BatchDeserializerException.class)

View File

@ -70,7 +70,7 @@ public class BatchResponseSerializerTest {
reader.close();
int line = 0;
assertEquals(25, body.size());
assertEquals(24, body.size());
assertTrue(body.get(line++).contains("--batch_"));
assertEquals("Content-Type: application/http" + CRLF, body.get(line++));
assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++));
@ -94,10 +94,63 @@ public class BatchResponseSerializerTest {
assertEquals(CRLF, body.get(line++));
assertEquals(CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--changeset_"));
assertEquals(CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--batch_"));
}
@Test
public void testBatchResponseWithEndingCRLF() throws Exception {
final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
ODataResponse response = new ODataResponse();
response.setStatusCode(HttpStatusCode.OK.getStatusCode());
response.setHeader(HttpHeader.CONTENT_TYPE, "application/json");
response.setContent(IOUtils.toInputStream("Walter Winter"));
List<ODataResponse> responses = new ArrayList<ODataResponse>(1);
responses.add(response);
parts.add(new ODataResponsePart(responses, false));
ODataResponse changeSetResponse = new ODataResponse();
changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode());
changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1");
responses = new ArrayList<ODataResponse>(1);
responses.add(changeSetResponse);
parts.add(new ODataResponsePart(responses, true));
BatchResponseSerializer serializer = new BatchResponseSerializer();
final InputStream content = serializer.serialize(parts, BOUNDARY);
assertNotNull(content);
final BufferedReaderIncludingLineEndings reader =
new BufferedReaderIncludingLineEndings(new InputStreamReader(content));
final List<String> body = reader.toList();
reader.close();
int line = 0;
assertEquals(23, body.size());
assertTrue(body.get(line++).contains("--batch_"));
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: application/json" + CRLF, body.get(line++));
assertEquals("Content-Length: 13" + CRLF, body.get(line++));
assertEquals(CRLF, body.get(line++));
assertEquals("Walter Winter" + CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--batch_"));
assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
assertEquals(CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--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++).contains("--changeset_"));
assertTrue(body.get(line++).contains("--batch_"));
}
@Test
public void testResponse() throws Exception {
List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>();
@ -155,7 +208,7 @@ public class BatchResponseSerializerTest {
reader.close();
int line = 0;
assertEquals(15, body.size());
assertEquals(14, body.size());
assertTrue(body.get(line++).contains("--batch_"));
assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_"));
assertEquals(CRLF, body.get(line++));
@ -169,7 +222,6 @@ public class BatchResponseSerializerTest {
assertEquals(CRLF, body.get(line++));
assertEquals(CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--changeset_"));
assertEquals(CRLF, body.get(line++));
assertTrue(body.get(line++).contains("--batch_"));
}
}