use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testJacksonDataCodec.
@Test
public void testJacksonDataCodec() throws IOException {
JacksonDataCodec codec = new JacksonDataCodec();
testDataCodec(codec, referenceDataMap1);
DataList list1 = codec.bytesToList("[7,27,279]".getBytes());
assertEquals(list1, new DataList(Arrays.asList(7, 27, 279)));
DataList list2 = new DataList(Arrays.asList(321, 21, 1));
assertEquals(codec.listToBytes(list2), "[321,21,1]".getBytes());
DataMap map3 = getMapFromJson(codec, "{ \"a\" : null }");
// out.println(map3.getError());
assertSame(map3.get("a"), Data.NULL);
DataMap map4 = getMapFromJson(codec, "{ \"b\" : 123456789012345678901234567890 }");
// out.println(map4.getError());
assertTrue(map4.getError().indexOf(" value: 123456789012345678901234567890, token: VALUE_NUMBER_INT, number type: BIG_INTEGER not parsed.") != -1);
DataMap map5 = getMapFromJson(codec, "{ \"a\" : null, \"b\" : 123456789012345678901234567890 }");
// out.println(map5.getError());
assertTrue(map5.getError().indexOf(" value: 123456789012345678901234567890, token: VALUE_NUMBER_INT, number type: BIG_INTEGER not parsed.") != -1);
// Test comments
codec.setAllowComments(true);
DataMap map6 = getMapFromJson(codec, "/* abc */ { \"a\" : \"b\" }");
assertEquals(map6.get("a"), "b");
// Test getStringEncoding
String encoding = codec.getStringEncoding();
assertEquals(encoding, "UTF-8");
assertEquals(encoding, JsonEncoding.UTF8.getJavaName());
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testJacksonDataCodecErrorEmptyInput.
@Test(expectedExceptions = IOException.class)
public void testJacksonDataCodecErrorEmptyInput() throws IOException {
final JacksonDataCodec codec = new JacksonDataCodec();
final ByteArrayInputStream in = new ByteArrayInputStream(new byte[0]);
codec.readMap(in);
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestData method testJacksonDataCodecErrorToMap.
@Test(expectedExceptions = DataDecodingException.class)
public void testJacksonDataCodecErrorToMap() throws IOException {
final JacksonDataCodec codec = new JacksonDataCodec();
codec.bytesToMap("[1, 2, 3]".getBytes());
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsWithDefaultsDeser.
@Test
public void testBoundedCostBackupRequestsWithDefaultsDeser() throws IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(3);
brc.setOperation("BATCH_GET");
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
@SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
assertNotNull(strategy);
assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
use of com.linkedin.data.codec.JacksonDataCodec in project rest.li by linkedin.
the class TestBackupRequestsStrategyFactory method testBoundedCostBackupRequestsDeser.
@Test
public void testBoundedCostBackupRequestsDeser() throws IOException {
BackupRequestsConfiguration brc = new BackupRequestsConfiguration();
BoundedCostBackupRequests bcbr = new BoundedCostBackupRequests();
bcbr.setCost(3);
bcbr.setHistoryLength(4096);
bcbr.setMaxBurst(16);
bcbr.setMinBackupDelayMs(5);
bcbr.setRequiredHistoryLength(65536);
brc.setOperation("BATCH_GET");
brc.setStrategy(BackupRequestsConfiguration.Strategy.create(bcbr));
String json = new JacksonDataCodec().mapToString(brc.data());
@SuppressWarnings("unchecked") Map<String, Object> map = JacksonUtil.getObjectMapper().readValue(json, Map.class);
BackupRequestsStrategy strategy = BackupRequestsStrategyFactory.tryCreate(map);
assertNotNull(strategy);
assertTrue(strategy instanceof BoundedCostBackupRequestsStrategy);
BoundedCostBackupRequestsStrategy boundedCostStrategy = (BoundedCostBackupRequestsStrategy) strategy;
assertEquals(boundedCostStrategy.getHistoryLength(), (int) bcbr.getHistoryLength());
assertEquals(boundedCostStrategy.getMinBackupDelayNano(), (long) bcbr.getMinBackupDelayMs() * 1000L * 1000L);
assertEquals(boundedCostStrategy.getRequiredHistory(), (int) bcbr.getRequiredHistoryLength());
assertEquals(boundedCostStrategy.getPercent(), (double) bcbr.getCost());
}
Aggregations