use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestArrayTemplate method testBytesArray.
@Test
public void testBytesArray() {
ArrayDataSchema schema = (ArrayDataSchema) DataTemplateUtil.parseSchema("{ \"type\" : \"array\", \"items\" : \"bytes\" }");
List<ByteString> input = Arrays.asList(ByteString.copyAvroString("1", false), ByteString.copyAvroString("3", false), ByteString.copyAvroString("5", false), ByteString.copyAvroString("7", false), ByteString.copyAvroString("11", false));
List<ByteString> adds = Arrays.asList(ByteString.copyAvroString("13", false), ByteString.copyAvroString("17", false), ByteString.copyAvroString("19", false));
List<Object> badInput = asList(true, 99, 999L, 88.0f, 888.0, "\u0100", new StringMap(), new StringArray(), null);
List<Object> badOutput = asList(true, 99, 999L, 88.0f, 888.0, "\u0100", new DataMap(), new DataList());
testArray(BytesArray.class, schema, input, adds);
testArrayBadInput(BytesArray.class, schema, input, badInput, badOutput);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestRecordAndUnionTemplate method testBytesField.
@Test
public void testBytesField() {
List<ByteString> good = Arrays.asList(ByteString.copyAvroString("11", false), ByteString.copyAvroString("22", false), ByteString.copyAvroString("33", false));
Foo foo = new Foo();
for (ByteString byteString : good) {
foo.setBytes(byteString);
assertEquals(foo.getBytes(), byteString);
assertTrue(foo.hasBytes());
assertEquals(foo.toString(), "{bytes=" + byteString + '}');
Exception exc = null;
try {
// clone
Foo fooClone = foo.clone();
assertEquals(foo, fooClone);
fooClone.removeBytes();
assertTrue(foo.hasBytes());
assertEquals(foo.getBytes(), byteString);
assertFalse(fooClone.hasBytes());
// copy
Foo fooCopy = foo.copy();
assertEquals(foo, fooCopy);
assertTrue(TestUtil.noCommonDataComplex(fooCopy.data(), foo.data()));
fooCopy.removeBytes();
assertTrue(foo.hasBytes());
assertEquals(foo.getBytes(), byteString);
assertFalse(fooCopy.hasBytes());
} catch (CloneNotSupportedException e) {
exc = e;
}
assertTrue(exc == null);
foo.removeBytes();
assertFalse(foo.hasBytes());
assertEquals(foo.toString(), "{}");
}
List<?> badInput = asList(false, 33, "\u0100", new DataList());
DataMap map = new DataMap();
foo = new Foo(map);
for (Object bad : badInput) {
map.put("bytes", bad);
Exception exc = null;
try {
foo.getBytes();
} catch (Exception e) {
exc = e;
}
assertTrue(exc != null);
assertTrue(exc instanceof TemplateOutputCastException);
}
List<?> castFrom = asList("88");
List<?> castTo = asList(ByteString.copyAvroString("88", false));
for (int i = 0; i < castFrom.size(); ++i) {
map.put("bytes", castFrom.get(i));
ByteString result = foo.getBytes();
assertEquals(result, castTo.get(i));
}
// legacy test
ByteString[] t = { ByteString.copyAvroString("apple", false), ByteString.copyAvroString("orange", false), ByteString.copyAvroString("banana", false) };
foo = new Foo();
foo.set1Bytes(t[0]);
assertEquals(foo.getBytes(), t[0]);
foo.set2Bytes(t[1]);
assertEquals(foo.getBytes(), t[1]);
foo.set2Bytes(t[2], SetMode.DISALLOW_NULL);
assertEquals(foo.getBytes(), t[2]);
foo.set2Bytes(null, SetMode.REMOVE_IF_NULL);
assertFalse(foo.hasBytes());
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class TestRecordAndUnionTemplate method testFixedField.
@Test
public void testFixedField() {
List<FixedType> good = Arrays.asList(new FixedType(ByteString.copyAvroString("abcd", false)), new FixedType(ByteString.copyAvroString("1234", false)));
for (FixedType fixed : good) {
Exception exc = null;
try {
FixedTemplate clone = fixed.clone();
assertSame(clone.data(), fixed.data());
assertSame(clone.schema(), fixed.schema());
} catch (CloneNotSupportedException e) {
exc = e;
}
assert exc == null;
}
Foo foo = new Foo();
for (FixedType fixedType : good) {
foo.setFixed(fixedType);
assertEquals(foo.getFixed(), fixedType);
assertEquals(foo.getFixed().bytes(), fixedType.bytes());
assertSame(foo.getFixed().bytes(), fixedType.bytes());
assertTrue(foo.hasFixed());
assertEquals(foo.toString(), "{fixed=" + fixedType.bytes() + '}');
Exception exc = null;
try {
// clone
Foo fooClone = foo.clone();
assertEquals(foo, fooClone);
assertSame(fooClone.getFixed(), foo.getFixed());
fooClone.removeFixed();
assertTrue(foo.hasFixed());
assertEquals(foo.getFixed(), fixedType);
assertFalse(fooClone.hasFixed());
// copy
Foo fooCopy = foo.copy();
assertEquals(foo, fooCopy);
assertTrue(TestUtil.noCommonDataComplex(fooCopy.data(), foo.data()));
assertNotSame(fooCopy.getFixed(), foo.getFixed());
fooCopy.removeFixed();
assertTrue(foo.hasFixed());
assertEquals(foo.getFixed(), fixedType);
assertFalse(fooCopy.hasFixed());
} catch (CloneNotSupportedException e) {
exc = e;
}
assertTrue(exc == null);
foo.removeFixed();
assertFalse(foo.hasFixed());
assertEquals(foo.toString(), "{}");
}
List<?> badInput = asList(false, "abc", new DataMap(), ByteString.empty(), ByteString.copyAvroString("abc", false));
DataMap map = new DataMap();
foo = new Foo(map);
for (Object bad : badInput) {
map.put("fixed", bad);
Exception exc = null;
try {
foo.getFixed();
} catch (Exception e) {
exc = e;
}
assertTrue(exc != null);
assertTrue(exc instanceof TemplateOutputCastException);
}
List<?> castFrom = asList("8888");
List<?> castTo = asList(ByteString.copyAvroString("8888", false));
for (int i = 0; i < castFrom.size(); ++i) {
map.put("fixed", castFrom.get(i));
ByteString result = foo.getFixed().bytes();
assertEquals(result, castTo.get(i));
}
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class FullEntityReader method onDone.
public void onDone() {
ByteString entity = _builder.build();
_callback.onSuccess(entity);
}
use of com.linkedin.data.ByteString in project rest.li by linkedin.
the class FullEntityObserver method onDone.
@Override
public void onDone() {
final ByteString entity = _builder.build();
_callback.onSuccess(entity);
}
Aggregations