Search in sources :

Example 96 with ByteString

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);
}
Also used : ByteString(com.linkedin.data.ByteString) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 97 with ByteString

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);
}
Also used : ByteString(com.linkedin.data.ByteString) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 98 with ByteString

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);
}
Also used : ByteString(com.linkedin.data.ByteString) ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 99 with ByteString

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);
}
Also used : ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 100 with 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);
}
Also used : ByteString(com.linkedin.data.ByteString) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

ByteString (com.linkedin.data.ByteString)152 Test (org.testng.annotations.Test)77 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 MimeMultipart (javax.mail.internet.MimeMultipart)31 MimeBodyPart (javax.mail.internet.MimeBodyPart)26 DataMap (com.linkedin.data.DataMap)25 RestResponse (com.linkedin.r2.message.rest.RestResponse)25 StreamResponse (com.linkedin.r2.message.stream.StreamResponse)22 FullEntityReader (com.linkedin.r2.message.stream.entitystream.FullEntityReader)22 RestRequest (com.linkedin.r2.message.rest.RestRequest)21 StreamRequest (com.linkedin.r2.message.stream.StreamRequest)21 URI (java.net.URI)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 RequestContext (com.linkedin.r2.message.RequestContext)18 RestRequestBuilder (com.linkedin.r2.message.rest.RestRequestBuilder)18 Callback (com.linkedin.common.callback.Callback)17 StreamRequestBuilder (com.linkedin.r2.message.stream.StreamRequestBuilder)14 RestException (com.linkedin.r2.message.rest.RestException)12 HashMap (java.util.HashMap)12 DataList (com.linkedin.data.DataList)11