use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.GroupObject 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.GroupObject 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.GroupObject 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