use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDataMapConverter method testDataMapToPSONByteString.
@Test
public void testDataMapToPSONByteString() throws MimeTypeParseException, IOException {
DataMap testDataMap = createTestDataMap();
byte[] expectedBytes = PSON_DATA_CODEC.mapToBytes(testDataMap);
Map<String, String> headers = Collections.singletonMap(RestConstants.HEADER_CONTENT_TYPE, "application/x-pson");
ByteString byteString = DataMapConverter.dataMapToByteString(headers, testDataMap);
Assert.assertEquals(byteString.copyBytes(), expectedBytes);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDataMapConverter method testDataMapToJSONByteStringWithUnsupportedContentType.
@Test
public void testDataMapToJSONByteStringWithUnsupportedContentType() throws MimeTypeParseException, IOException {
// unsupport content type should fallback to JSON
DataMap testDataMap = createTestDataMap();
byte[] expectedBytes = JACKSON_DATA_CODEC.mapToBytes(testDataMap);
Map<String, String> headers = Collections.singletonMap(RestConstants.HEADER_CONTENT_TYPE, "mysuperkool/xson");
ByteString byteString = DataMapConverter.dataMapToByteString(headers, testDataMap);
Assert.assertEquals(byteString.copyBytes(), expectedBytes);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDataMapConverter method testDataMapToJSONByteString.
@Test
public void testDataMapToJSONByteString() throws MimeTypeParseException, IOException {
DataMap testDataMap = createTestDataMap();
byte[] expectedBytes = JACKSON_DATA_CODEC.mapToBytes(testDataMap);
Map<String, String> headers = Collections.singletonMap(RestConstants.HEADER_CONTENT_TYPE, "application/json");
ByteString byteString = DataMapConverter.dataMapToByteString(headers, testDataMap);
Assert.assertEquals(byteString.copyBytes(), expectedBytes);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDataMapConverter method testByteStringToDataMapWithInvalidContentType.
@Test(expectedExceptions = IOException.class)
public void testByteStringToDataMapWithInvalidContentType() throws MimeTypeParseException, IOException {
DataMap dataMap = createTestDataMap();
ByteString byteString = ByteString.copy(JACKSON_DATA_CODEC.mapToBytes(dataMap));
bytesToDataMap("application/x-pson", byteString);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestDataMapConverter method testByteStringToDataMapWithNonParsableContentType.
@Test(expectedExceptions = MimeTypeParseException.class)
public void testByteStringToDataMapWithNonParsableContentType() throws MimeTypeParseException, IOException {
DataMap dataMap = createTestDataMap();
ByteString byteString = ByteString.copy(JACKSON_DATA_CODEC.mapToBytes(dataMap));
bytesToDataMap("foo=bar", byteString);
}
Aggregations