Search in sources :

Example 1 with BinaryBuilderEnum

use of org.apache.ignite.internal.binary.builder.BinaryBuilderEnum in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testSimpleTypeFieldRead.

/**
     * @throws Exception If failed.
     */
public void testSimpleTypeFieldRead() throws Exception {
    GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
    exp.setDefaultData();
    BinaryObjectBuilder mutPo = wrap(exp);
    for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
        Object expVal = field.get(exp);
        Object actVal = mutPo.getField(field.getName());
        switch(field.getName()) {
            case "anEnum":
                assertEquals(((BinaryBuilderEnum) actVal).getOrdinal(), ((Enum) expVal).ordinal());
                break;
            case "enumArr":
                {
                    BinaryBuilderEnum[] actArr = (BinaryBuilderEnum[]) actVal;
                    Enum[] expArr = (Enum[]) expVal;
                    assertEquals(expArr.length, actArr.length);
                    for (int i = 0; i < actArr.length; i++) assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
                    break;
                }
        }
    }
}
Also used : BinaryBuilderEnum(org.apache.ignite.internal.binary.builder.BinaryBuilderEnum) Field(java.lang.reflect.Field) BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryBuilderEnum(org.apache.ignite.internal.binary.builder.BinaryBuilderEnum) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 2 with BinaryBuilderEnum

use of org.apache.ignite.internal.binary.builder.BinaryBuilderEnum in project ignite by apache.

the class BinaryObjectBuilderAdditionalSelfTest method testEnumArrayModification.

/**
     *
     */
public void testEnumArrayModification() {
    GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
    obj.enumArr = new GridBinaryTestClasses.TestObjectEnum[] { GridBinaryTestClasses.TestObjectEnum.A, GridBinaryTestClasses.TestObjectEnum.B };
    BinaryObjectBuilderImpl mutObj = wrap(obj);
    BinaryBuilderEnum[] arr = mutObj.getField("enumArr");
    arr[0] = new BinaryBuilderEnum(mutObj.typeId(), GridBinaryTestClasses.TestObjectEnum.B);
    GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
    Assert.assertArrayEquals(new GridBinaryTestClasses.TestObjectEnum[] { GridBinaryTestClasses.TestObjectEnum.A, GridBinaryTestClasses.TestObjectEnum.B }, res.enumArr);
}
Also used : BinaryObjectBuilderImpl(org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl) BinaryBuilderEnum(org.apache.ignite.internal.binary.builder.BinaryBuilderEnum) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Aggregations

BinaryBuilderEnum (org.apache.ignite.internal.binary.builder.BinaryBuilderEnum)2 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)2 Field (java.lang.reflect.Field)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)1 BinaryObjectBuilderImpl (org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl)1