use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testBuilderReusage.
/**
* @throws Exception If fails
*/
public void testBuilderReusage() throws Exception {
// Check: rewrite null field value.
BinaryObjectBuilder builder = newWrapper("SimpleCls1");
builder.setField("f1", null, Object.class);
assertNull(builder.build().field("f1"));
builder.setField("f1", "val1");
assertEquals("val1", builder.build().field("f1"));
// Check: rewrite non-null field value to null and back.
builder = newWrapper("SimpleCls2");
builder.setField("f1", "val1", String.class);
assertEquals("val1", builder.build().field("f1"));
builder.setField("f1", null);
assertNull(builder.build().field("f1"));
builder.setField("f1", "val2");
assertEquals("val2", builder.build().field("f1"));
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testCorrectMetadataNullField2.
/**
*/
public void testCorrectMetadataNullField2() {
BinaryObjectBuilder builder = binaries().builder("SomeType3");
builder.setField("dateField", null, Date.class);
builder.setField("objectField", null, GridBinaryTestClasses.Company.class);
BinaryObject obj = builder.build();
builder = binaries().builder(obj);
builder.setField("dateField", new Date());
builder.setField("objectField", new GridBinaryTestClasses.Company());
builder.build();
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testEnum.
/**
* Checks correct serialization/deserialization of enums in builder.
*
* @throws Exception If failed.
*/
public void testEnum() throws Exception {
BinaryObjectBuilder builder = newWrapper("TestType");
final TestEnum exp = TestEnum.A;
final TestEnum[] expArr = { TestEnum.A, TestEnum.B };
BinaryObject enumObj = builder.setField("testEnum", exp).setField("testEnumArr", expArr).build();
assertEquals(exp, ((BinaryObject) enumObj.field("testEnum")).deserialize());
Assert.assertArrayEquals(expArr, (Object[]) deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
builder = newWrapper(enumObj.type().typeName());
enumObj = builder.setField("testEnum", (Object) enumObj.field("testEnum")).setField("testEnumArr", (Object) enumObj.field("testEnumArr")).build();
assertEquals(exp, ((BinaryObject) enumObj.field("testEnum")).deserialize());
Assert.assertArrayEquals(expArr, (Object[]) deserializeEnumBinaryArray(enumObj.field("testEnumArr")));
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinaryObjectBuilderAdditionalSelfTest method testWrongMetadataNullField.
/**
*/
public void testWrongMetadataNullField() {
BinaryObjectBuilder builder = binaries().builder("SomeType");
builder.setField("dateField", null);
builder.setField("objectField", null, Integer.class);
builder.build();
try {
builder = binaries().builder("SomeType");
builder.setField("dateField", new Date());
builder.build();
} catch (BinaryObjectException ex) {
assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
}
builder = binaries().builder("SomeType");
try {
builder.setField("objectField", new GridBinaryTestClasses.Company());
builder.build();
fail("BinaryObjectBuilder accepted wrong metadata");
} catch (BinaryObjectException ex) {
assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
}
}
use of org.apache.ignite.binary.BinaryObjectBuilder in project ignite by apache.
the class BinarySimpleNameTestPropertySelfTest method checkProperty.
/**
* @param expTypeName Type name.
* @throws Exception If failed.
*/
private void checkProperty(String expTypeName) throws Exception {
String marshBackup = GridTestProperties.getProperty(MARSH_CLASS_NAME);
try {
GridTestProperties.setProperty(MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
IgniteBinary binary = startGrid().binary();
BinaryObjectBuilder builder = binary.builder("org.ignite.test.TestClass");
BinaryObject bObj = builder.build();
assertEquals(expTypeName, bObj.type().typeName());
} finally {
if (marshBackup != null)
GridTestProperties.setProperty(MARSH_CLASS_NAME, marshBackup);
}
}
Aggregations