use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveFields in project hazelcast by hazelcast.
the class CompactStreamSerializerValueReaderSpecTest method expandPrimitiveScenario.
/**
* Expands test cases for primitive non-array data types.
* Word "primitive_" from the pathToExplode is replaced by each primitive type and the scenario is expanded to:
* <ul>
* <li>scenario(input, result.byte_, adjustedPath + "byte_"),</li>
* <li>scenario(input, result.short_, adjustedPath + "short_"),</li>
* <li>scenario(input, result.int_, adjustedPath + "int_"),</li>
* <li>scenario(input, result.long_, adjustedPath + "long_"),</li>
* <li>scenario(input, result.float_, adjustedPath + "float_"),</li>
* <li>scenario(input, result.double_, adjustedPath + "double_"),</li>
* <li>scenario(input, result.boolean_, adjustedPath + "boolean_"),</li>
* <li>scenario(input, result.string_, adjustedPath + "string_"),</li>
* </ul>
*/
private static Collection<Object[]> expandPrimitiveScenario(Object input, Object result, String pathToExplode, String parent) {
List<Object[]> scenarios = new ArrayList<>();
Object adjustedResult;
for (PrimitiveFields primitiveFields : getPrimitives()) {
if (result instanceof PrimitiveObject) {
adjustedResult = ((PrimitiveObject) result).getPrimitive(primitiveFields);
} else {
adjustedResult = result;
}
// generic method case
scenarios.add(scenario(input, adjustedResult, pathToExplode.replace("primitive_", primitiveFields.field), parent));
}
return scenarios;
}
use of com.hazelcast.internal.serialization.impl.compact.reader.CompactValueReaderTestStructure.PrimitiveFields 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.PrimitiveFields 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;
}
Aggregations