use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method fromObjectToObjectArrayToPrimitiveScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE via PORTABLE_ARRAY to further access
// ----------------------------------------------------------------------------------------------------------
private static void fromObjectToObjectArrayToPrimitiveScenarios(List<Object[]> result) {
// FULLy initialised primitive objects accessed from object stored in array
String p = "fromObjectToObjectToPrimitiveScenarios";
NestedGroupObject nestedFullGroup = nested(group(prim(1, FULL), prim(10, FULL), prim(100, FULL)));
result.addAll(asList(scenario(nestedFullGroup, ((GroupObject) (nestedFullGroup.object)).objects, "object.objects", p), scenario(nestedFullGroup, ((GroupObject) (nestedFullGroup.object)).objects, "object.objects[any]", p), scenario(nestedFullGroup, ((GroupObject) (nestedFullGroup.object)).objects[0], "object.objects[0]", p), scenario(nestedFullGroup, ((GroupObject) (nestedFullGroup.object)).objects[1], "object.objects[1]", p), scenario(nestedFullGroup, ((GroupObject) (nestedFullGroup.object)).objects[2], "object.objects[2]", p), scenario(nestedFullGroup, null, "object.objects[12]", p)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedFullGroup, (GroupObject) nestedFullGroup.object, "object.objectArray.primitive_", p));
NestedGroupObject nestedFullEmptyNullGroup = nested(group(prim(1, FULL), prim(10, NONE), prim(100, NULL)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedFullEmptyNullGroup, (GroupObject) nestedFullEmptyNullGroup.object, "object.objectArray.primitive_", p));
// empty or null object array de-referenced further
NestedGroupObject nestedNullArrayGroup = nested(new GroupObject((PrimitiveObject[]) null));
result.addAll(asList(scenario(nestedNullArrayGroup, null, "object.objects", p), scenario(nestedNullArrayGroup, null, "object.objects[any]", p), scenario(nestedNullArrayGroup, null, "object.objects[0]", p), scenario(nestedNullArrayGroup, null, "object.objects[1]", p), scenario(nestedNullArrayGroup, null, "object.objects[2]", p)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedNullArrayGroup, (GroupObject) nestedNullArrayGroup.object, "object.objectArray.primitive_", p));
NestedGroupObject nestedEmptyArrayGroup = nested(new GroupObject(new PrimitiveObject[0]));
result.addAll(asList(scenario(nestedEmptyArrayGroup, new PrimitiveObject[0], "object.objects", p), scenario(nestedEmptyArrayGroup, null, "object.objects[any]", p), scenario(nestedEmptyArrayGroup, null, "object.objects[0]", p), scenario(nestedEmptyArrayGroup, null, "object.objects[1]", p), scenario(nestedEmptyArrayGroup, null, "object.objects[2]", p)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedEmptyArrayGroup, (GroupObject) nestedEmptyArrayGroup.object, "object.objectArray.primitive_", p));
NestedGroupObject nestedEmpty = nested(new GroupObject[0]);
result.addAll(asList(scenario(nestedEmpty, null, "object.objects", p), scenario(nestedEmpty, null, "object.objects[any]", p), scenario(nestedEmpty, null, "object.objects[0]", p), scenario(nestedEmpty, null, "object.objects[1]", p), scenario(nestedEmpty, null, "object.objects[2]", p)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedEmpty, (GroupObject) nestedEmpty.object, "object.objectArray.primitive_", p));
NestedGroupObject nestedNull = nested((GroupObject[]) null);
result.addAll(asList(scenario(nestedNull, null, "object.objects", p), scenario(nestedNull, null, "object.objects[any]", p), scenario(nestedNull, null, "object.objects[0]", p), scenario(nestedNull, null, "object.objects[1]", p), scenario(nestedNull, null, "object.objects[2]", p)));
result.addAll(expandObjectArrayPrimitiveScenario(nestedNull, (GroupObject) nestedNull.object, "object.objectArray.primitive_", p));
}
use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method fromObjectArrayAnyToObjectArrayAnyToPrimitiveScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE_ARRAY[any] via PORTABLE_ARRAY[any] to further PRIMITIVE access
// ----------------------------------------------------------------------------------------------------------
private static void fromObjectArrayAnyToObjectArrayAnyToPrimitiveScenarios(List<Object[]> result) {
String p = "fromObjectArrayAnyToObjectArrayAnyToPrimitiveScenarios";
// =============================================
// INPUT mixed
// =============================================
PrimitiveObject p1 = prim(1, NONE);
PrimitiveObject p10 = prim(10, FULL);
PrimitiveObject p20 = prim(20, FULL);
NestedGroupObject input = nested(new GroupObject[] { new GroupObject(new PrimitiveObject[0]), group(p1, p10), new GroupObject((PrimitiveObject[]) null), group(new PrimitiveObject[] { p20 }) });
result.addAll(asList(scenario(input, list(null, p1.byte_, p10.byte_, p20.byte_), "objects[any].objects[any].byte_", p), scenario(input, list(null, p1.short_, p10.short_, p20.short_), "objects[any].objects[any].short_", p), scenario(input, list(null, p1.int_, p10.int_, p20.int_), "objects[any].objects[any].int_", p), scenario(input, list(null, p1.long_, p10.long_, p20.long_), "objects[any].objects[any].long_", p), scenario(input, list(null, p1.float_, p10.float_, p20.float_), "objects[any].objects[any].float_", p), scenario(input, list(null, p1.double_, p10.double_, p20.double_), "objects[any].objects[any].double_", p), scenario(input, list(null, p1.boolean_, p10.boolean_, p20.boolean_), "objects[any].objects[any].boolean_", p), scenario(input, list(null, p1.string_, p10.string_, p20.string_), "objects[any].objects[any].string_", p)));
// =============================================
// INPUT empty
// =============================================
NestedGroupObject inputEmpty = nested(new GroupObject[0]);
result.addAll(asList(scenario(inputEmpty, null, "objects[any].objects[any].byte_", p), scenario(inputEmpty, null, "objects[any].objects[any].short_", p), scenario(inputEmpty, null, "objects[any].objects[any].int_", p), scenario(inputEmpty, null, "objects[any].objects[any].long_", p), scenario(inputEmpty, null, "objects[any].objects[any].float_", p), scenario(inputEmpty, null, "objects[any].objects[any].double_", p), scenario(inputEmpty, null, "objects[any].objects[any].boolean_", p), scenario(inputEmpty, null, "objects[any].objects[any].string_", p)));
// =============================================
// INPUT null
// =============================================
NestedGroupObject inputNull = nested((GroupObject[]) null);
result.addAll(asList(scenario(inputNull, null, "objects[any].objects[any].byte_", p), scenario(inputNull, null, "objects[any].objects[any].short_", p), scenario(inputNull, null, "objects[any].objects[any].int_", p), scenario(inputNull, null, "objects[any].objects[any].long_", p), scenario(inputNull, null, "objects[any].objects[any].float_", p), scenario(inputNull, null, "objects[any].objects[any].double_", p), scenario(inputNull, null, "objects[any].objects[any].boolean_", p), scenario(inputNull, null, "objects[any].objects[any].string_", p)));
}
use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method expandObjectArrayPrimitiveScenario.
/**
* Expands test cases for that navigate from object array to a primitive field.
* Word objectArray is replaced to: objects[0], objects[1], objects[2], objects[any]
* Word "primitive_" is replaced by each primitive type and the scenario is expanded to for each type:
* <p>
* A.) The contract is that input should somewhere on the path contain an array of Object[] which contains objects of type
* PrimitiveObject. For example: "objectArray.primitive_" will be expanded two-fold, the object array and primitive
* types will be expanded as follows:
* <ul>
* <li>objects[0].byte, objects[0].short, ... for all primitive types</li>
* <li>objects[1].byte, objects[1].short, ...</li>
* <li>objects[2].byte, objects[2].short, ...</li>
* </ul>
* <p>
* B.) Then the [any] case will be expanded too:
* <ul>
* <li>objects[any].byte, objects[any].short, ... for all primitive types</li>
* </ul>
* <p>
* The expected result should be the object that contains the object array - that's the general contract.
* The result for assertion will be automatically calculated
*/
@SuppressWarnings({ "unchecked" })
private static Collection<Object[]> expandObjectArrayPrimitiveScenario(Object input, GroupObject result, String pathToExplode, String parent) {
List<Object[]> scenarios = new ArrayList<>();
// expansion of the object array using the following quantifiers
for (String token : asList("0", "1", "2", "any")) {
String path = pathToExplode.replace("objectArray", "objects[" + token + "]");
if (token.equals("any")) {
// expansion of the primitive fields
for (CompactValueReaderTestStructure.PrimitiveFields primitiveFields : getPrimitives()) {
List resultToMatch = new ArrayList();
int objectCount = 0;
try {
objectCount = result.objects.length;
} catch (NullPointerException ignored) {
}
for (int i = 0; i < objectCount; i++) {
PrimitiveObject object = (PrimitiveObject) result.objects[i];
resultToMatch.add(object.getPrimitive(primitiveFields));
}
if (result == null || result.objects == null || result.objects.length == 0) {
resultToMatch = null;
}
scenarios.add(scenario(input, resultToMatch, path.replace("primitive_", primitiveFields.field), parent));
}
} else {
// expansion of the primitive fields
for (PrimitiveFields primitiveFields : getPrimitives()) {
Object resultToMatch = null;
try {
PrimitiveObject object = result.objects[Integer.parseInt(token)];
resultToMatch = object.getPrimitive(primitiveFields);
} catch (NullPointerException ignored) {
} catch (IndexOutOfBoundsException ignored) {
}
if (result == null || result.objects == null || result.objects.length == 0) {
resultToMatch = null;
}
scenarios.add(scenario(input, resultToMatch, path.replace("primitive_", primitiveFields.field), parent));
}
}
}
return scenarios;
}
use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method expandPrimitiveArrayScenario.
/**
* Expands test cases for primitive array data types.
* Word "primitiveArray" is replaced by each primitive array type and the scenario is expanded to for each type:
* <p>
* group A:
* <ul>
* <li>scenario(prim(FULL), prim(FULL).bytes, ByteArray, "bytes"),</li>
* <li>scenario(prim(NONE), prim(NONE).bytes, ByteArray, "bytes"),</li>
* <li>scenario(prim(NULL), prim(NULL).bytes, ByteArray, "bytes"),</li>
* <p>
* <li>scenario(prim(FULL), prim(FULL).bytes, ByteArray, "bytes[any]"),</li>
* <li>scenario(prim(NONE), prim(NONE).bytes, ByteArray, "bytes[any]"),</li>
* <li>scenario(prim(NULL), prim(NULL).bytes, ByteArray, "bytes[any]"),</li>
* </ul>
* <p>
* group B:
* <ul>
* <li>scenario(prim(FULL), prim(FULL).bytes[0], Byte, "bytes[0]"),</li>
* <li>scenario(prim(FULL), prim(FULL).bytes[1], Byte, "bytes[1]"),</li>
* <li>scenario(prim(FULL), prim(FULL).bytes[2], Byte, "bytes[2]"),</li>
* <p>
* <li>for all primitives <ul>
* <li>scenario(prim(NONE), null, Byte, "bytes[0]"),</li>
* <li>scenario(prim(NULL), null, Byte, "bytes[1]"),</li>
* </ul></li>
* <p>
* </ul>
*/
private static Collection<Object[]> expandPrimitiveArrayScenario(Object input, PrimitiveObject result, String pathToExplode, String parent) {
List<Object[]> scenarios = new ArrayList<>();
// group A:
for (CompactValueReaderTestStructure.PrimitiveFields primitiveFields : getPrimitiveArrays()) {
String path = pathToExplode.replace("primitiveArray", primitiveFields.field);
Object resultToMatch = result != null ? result.getPrimitiveArray(primitiveFields) : null;
Object resultToMatchAny = resultToMatch;
if (resultToMatchAny != null && Array.getLength(resultToMatchAny) == 0) {
resultToMatchAny = null;
}
scenarios.addAll(asList(scenario(input, resultToMatch, path, parent), scenario(input, resultToMatchAny, path + "[any]", parent)));
}
// group B:
for (CompactValueReaderTestStructure.PrimitiveFields primitiveFields : getPrimitives()) {
String path = pathToExplode.replace("primitiveArray", primitiveFields.field).replace("_", "s");
if (result == null || result.getPrimitiveArray(primitiveFields) == null || Array.getLength(result.getPrimitiveArray(primitiveFields)) == 0) {
scenarios.add(scenario(input, null, path + "[0]", parent));
} else {
scenarios.addAll(asList(scenario(input, Array.get(result.getPrimitiveArray(primitiveFields), 0), path + "[0]", parent), scenario(input, Array.get(result.getPrimitiveArray(primitiveFields), 1), path + "[1]", parent), scenario(input, Array.get(result.getPrimitiveArray(primitiveFields), 2), path + "[2]", parent)));
}
}
return scenarios;
}
use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveObject in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method fromObjectArrayToPrimitiveScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE-ARRAY to primitive and primitive-array access
// ----------------------------------------------------------------------------------------------------------
private static void fromObjectArrayToPrimitiveScenarios(List<Object[]> result) {
String p = "fromObjectArrayToPrimitiveScenarios";
// FULLy initialised primitive objects accessed from object stored in array
GroupObject fullGroupVarious = group(prim(1, FULL), prim(10, FULL), prim(100, FULL));
result.addAll(expandObjectArrayPrimitiveScenario(fullGroupVarious, fullGroupVarious, "objectArray.primitive_", p));
GroupObject fullEmptyNullGroup = group(prim(1, FULL), prim(10, NONE), prim(100, NULL));
result.addAll(expandObjectArrayPrimitiveScenario(fullEmptyNullGroup, fullEmptyNullGroup, "objectArray.primitive_", p));
// empty or null object array de-referenced further
GroupObject nullArrayGroup = new GroupObject((PrimitiveObject[]) null);
result.addAll(expandObjectArrayPrimitiveScenario(nullArrayGroup, nullArrayGroup, "objectArray.primitive_", p));
GroupObject emptyArrayGroup = new GroupObject(new PrimitiveObject[0]);
result.addAll(expandObjectArrayPrimitiveScenario(emptyArrayGroup, emptyArrayGroup, "objectArray.primitive_", p));
// FULLy initialised primitive arrays accessed from object stored in array
GroupObject fullGroup = group(prim(FULL), prim(FULL), prim(FULL));
result.addAll(expandPrimitiveArrayScenario(fullGroup, prim(FULL), "objects[0].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(fullGroup, prim(FULL), "objects[1].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(fullGroup, prim(FULL), "objects[2].primitiveArray", p));
// EMPTY primitive arrays accessed from object stored in array
GroupObject noneGroup = group(prim(NONE), prim(NONE), prim(NONE));
result.addAll(expandPrimitiveArrayScenario(noneGroup, prim(NONE), "objects[0].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(noneGroup, prim(NONE), "objects[1].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(noneGroup, prim(NONE), "objects[2].primitiveArray", p));
// NULL primitive arrays accessed from object stored in array
GroupObject nullGroup = group(prim(NULL), prim(NULL), prim(NULL));
result.addAll(expandPrimitiveArrayScenario(nullGroup, prim(NULL), "objects[0].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(nullGroup, prim(NULL), "objects[1].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(nullGroup, prim(NULL), "objects[2].primitiveArray", p));
// EMPTY object array -> de-referenced further for primitive access
result.addAll(expandPrimitiveScenario(emptyArrayGroup, null, "objects[0].primitive_", p));
result.addAll(expandPrimitiveScenario(emptyArrayGroup, null, "objects[1].primitive_", p));
result.addAll(expandPrimitiveScenario(emptyArrayGroup, null, "objects[2].primitive_", p));
result.add(scenario(emptyArrayGroup, null, "objects[0].string_", p));
result.add(scenario(emptyArrayGroup, null, "objects[1].string_", p));
// EMPTY object array -> de-referenced further for array access
result.addAll(expandPrimitiveArrayScenario(emptyArrayGroup, null, "objects[0].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(emptyArrayGroup, null, "objects[1].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(emptyArrayGroup, null, "objects[2].primitiveArray", p));
// NULL object array -> de-referenced further for primitive access
result.addAll(expandPrimitiveScenario(nullArrayGroup, null, "objects[0].primitive_", p));
result.addAll(expandPrimitiveScenario(nullArrayGroup, null, "objects[1].primitive_", p));
result.addAll(expandPrimitiveScenario(nullArrayGroup, null, "objects[2].primitive_", p));
result.add(scenario(nullArrayGroup, null, "objects[0].string_", p));
result.add(scenario(nullArrayGroup, null, "objects[1].string_", p));
// EMPTY object array -> de-referenced further for array access
result.addAll(expandPrimitiveArrayScenario(nullArrayGroup, null, "objects[0].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(nullArrayGroup, null, "objects[1].primitiveArray", p));
result.addAll(expandPrimitiveArrayScenario(nullArrayGroup, null, "objects[2].primitiveArray", p));
}
Aggregations