use of com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method fromPortableToPortableToPrimitiveScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE via PORTABLE to further access
// ----------------------------------------------------------------------------------------------------------
private static void fromPortableToPortableToPrimitiveScenarios(List<Object[]> result) {
String p = "fromPortableToPortableToPrimitiveScenarios";
// FULLy initialised primitive objects accessed from portable stored in array
NestedGroupPortable nestedFullGroup = nested(group(prim(1, FULL), prim(10, FULL), prim(100, FULL)));
result.addAll(asList(scenario(nestedFullGroup, (nestedFullGroup.portable), "portable", p), scenario(nestedFullGroup, ((GroupPortable) (nestedFullGroup.portable)).portable, "portable.portable", p)));
result.addAll(expandPrimitiveScenario(nestedFullGroup, ((GroupPortable) nestedFullGroup.portable).portable, "portable.portable.primitive_", p));
result.addAll(expandPrimitiveArrayScenario(nestedFullGroup, (PrimitivePortable) ((GroupPortable) nestedFullGroup.portable).portable, "portable.portable.primitiveArray", p));
NestedGroupPortable nestedFullEmptyNullGroup = nested(group(prim(1, FULL), prim(10, NONE), prim(100, NULL)));
result.addAll(expandPrimitiveScenario(nestedFullEmptyNullGroup, ((GroupPortable) nestedFullEmptyNullGroup.portable).portable, "portable.portable.primitive_", p));
result.addAll(expandPrimitiveArrayScenario(nestedFullEmptyNullGroup, (PrimitivePortable) ((GroupPortable) nestedFullEmptyNullGroup.portable).portable, "portable.portable.primitiveArray", p));
// empty or null portable array de-referenced further
NestedGroupPortable nestedNullArrayGroup = nested(new GroupPortable((Portable[]) null));
result.addAll(asList(scenario(nestedNullArrayGroup, (nestedNullArrayGroup.portable), "portable", p), scenario(nestedNullArrayGroup, null, "portable.portable", p)));
result.addAll(expandPrimitiveScenario(nestedNullArrayGroup, null, "portable.portable.primitive_", p));
result.addAll(expandPrimitiveArrayScenario(nestedNullArrayGroup, null, "portable.portable.primitiveArray", p));
NestedGroupPortable nestedNull = nested(new Portable[0]);
result.addAll(asList(scenario(nestedNull, null, "portable", p), scenario(nestedNull, null, "portable.portable", p)));
result.addAll(expandPrimitiveScenario(nestedNull, null, "portable.portable.primitive_", p));
result.addAll(expandPrimitiveArrayScenario(nestedNull, null, "portable.portable.primitiveArray", p));
}
use of com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest 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.char_, adjustedPath + "char_"),</li>
* <li>scenario(input, result.string_, adjustedPath + "string_"),</li>
* </ul>
*/
private static Collection<Object[]> expandPrimitiveScenario(Portable input, Object result, String pathToExplode, String parent) {
List<Object[]> scenarios = new ArrayList<>();
Object adjustedResult;
for (PrimitiveFields primitiveFields : getPrimitives()) {
if (result instanceof PrimitivePortable) {
adjustedResult = ((PrimitivePortable) 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.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method fromPortableArrayToPortableArrayToPrimitiveArrayAnyScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE_ARRAY[any] via PORTABLE_ARRAY[any] to further PRIMITIVE_ARRAY[any] access
// ----------------------------------------------------------------------------------------------------------
private static void fromPortableArrayToPortableArrayToPrimitiveArrayAnyScenarios(List<Object[]> result) {
String method = "fromPortableArrayToPortableArrayToPrimitiveArrayAnyScenarios";
String p = method + " mixed";
// =============================================
// INPUT mixed
// =============================================
NestedGroupPortable input = nested(new Portable[] { new GroupPortable(new Portable[0]), group(prim(1, NONE), prim(10, FULL), prim(50, NULL)), new GroupPortable((Portable[]) null), group(prim(20, FULL), prim(70, NULL)) });
PrimitivePortable p10 = prim(10, FULL);
PrimitivePortable p20 = prim(20, FULL);
result.addAll(asList(scenario(input, list(null, p10.bytes, p20.bytes), "portables[any].portables[any].bytes[any]", p), scenario(input, list(null, p10.shorts, p20.shorts), "portables[any].portables[any].shorts[any]", p), scenario(input, list(null, p10.ints, p20.ints), "portables[any].portables[any].ints[any]", p), scenario(input, list(null, p10.longs, p20.longs), "portables[any].portables[any].longs[any]", p), scenario(input, list(null, p10.chars, p20.chars), "portables[any].portables[any].chars[any]", p), scenario(input, list(null, p10.floats, p20.floats), "portables[any].portables[any].floats[any]", p), scenario(input, list(null, p10.doubles, p20.doubles), "portables[any].portables[any].doubles[any]", p), scenario(input, list(null, p10.booleans, p20.booleans), "portables[any].portables[any].booleans[any]", p), scenario(input, list(null, p10.strings, p20.strings), "portables[any].portables[any].strings[any]", p)));
// =============================================
// INPUT empty
// =============================================
p = method + " empty";
NestedGroupPortable inputEmpty = nested(new Portable[0]);
result.addAll(asList(scenario(inputEmpty, null, "portables[any].portables[any].bytes[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].shorts[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].ints[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].longs[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].chars[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].floats[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].doubles[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].booleans[any]", p), scenario(inputEmpty, null, "portables[any].portables[any].strings[any]", p)));
// =============================================
// INPUT null
// =============================================
p = method + " null";
NestedGroupPortable inputNull = nested((Portable[]) null);
result.addAll(asList(scenario(inputNull, null, "portables[any].portables[any].bytes[any]", p), scenario(inputNull, null, "portables[any].portables[any].shorts[any]", p), scenario(inputNull, null, "portables[any].portables[any].ints[any]", p), scenario(inputNull, null, "portables[any].portables[any].longs[any]", p), scenario(inputNull, null, "portables[any].portables[any].chars[any]", p), scenario(inputNull, null, "portables[any].portables[any].floats[any]", p), scenario(inputNull, null, "portables[any].portables[any].doubles[any]", p), scenario(inputNull, null, "portables[any].portables[any].booleans[any]", p), scenario(inputNull, null, "portables[any].portables[any].strings[any]", p)));
}
use of com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method expandPortableArrayPrimitiveScenario.
/**
* Expands test cases for that navigate from portable array to a primitive field.
* Word portableArray is replaced to: portables[0], portables[1], portables[2], portables[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 Portable[] which contains objects of type
* PrimitivePortable. For example: "portableArray.primitive_" will be expanded two-fold, the portable array and primitive
* types will be expanded as follows:
* <ul>
* <li>portables[0].byte, portables[0].short, portables[0].char, ... for all primitive types</li>
* <li>portables[1].byte, portables[1].short, portables[1].char, ...</li>
* <li>portables[2].byte, portables[2].short, portables[2].char, ...</li>
* </ul>
* <p>
* B.) Then the [any] case will be expanded too:
* <ul>
* <li>portables[any].byte, portables[any].short, portables[any].char, ... for all primitive types</li>
* </ul>
* <p>
* The expected result should be the object that contains the portable array - that's the general contract.
* The result for assertion will be automatically calculated
*/
@SuppressWarnings({ "unchecked" })
private static Collection<Object[]> expandPortableArrayPrimitiveScenario(Portable input, GroupPortable result, String pathToExplode, String parent) {
List<Object[]> scenarios = new ArrayList<>();
// expansion of the portable array using the following quantifiers
for (String token : asList("0", "1", "2", "any")) {
String path = pathToExplode.replace("portableArray", "portables[" + token + "]");
if (token.equals("any")) {
// expansion of the primitive fields
for (PrimitiveFields primitiveFields : getPrimitives()) {
List resultToMatch = new ArrayList();
int portableCount = 0;
try {
portableCount = result.portables.length;
} catch (NullPointerException ignored) {
}
for (int i = 0; i < portableCount; i++) {
PrimitivePortable portable = (PrimitivePortable) result.portables[i];
resultToMatch.add(portable.getPrimitive(primitiveFields));
}
if (result == null || result.portables == null || result.portables.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 {
PrimitivePortable portable = (PrimitivePortable) result.portables[Integer.parseInt(token)];
resultToMatch = portable.getPrimitive(primitiveFields);
} catch (NullPointerException ignored) {
} catch (IndexOutOfBoundsException ignored) {
}
if (result == null || result.portables == null || result.portables.length == 0) {
resultToMatch = null;
}
scenarios.add(scenario(input, resultToMatch, path.replace("primitive_", primitiveFields.field), parent));
}
}
}
return scenarios;
}
use of com.hazelcast.internal.serialization.impl.portable.portablereader.DefaultPortableReaderTestStructure.PrimitivePortable in project hazelcast by hazelcast.
the class DefaultPortableReaderSpecTest method fromPortableArrayAnyToPortableArrayAnyToPrimitiveScenarios.
// ----------------------------------------------------------------------------------------------------------
// from PORTABLE_ARRAY[any] via PORTABLE_ARRAY[any] to further PRIMITIVE access
// ----------------------------------------------------------------------------------------------------------
private static void fromPortableArrayAnyToPortableArrayAnyToPrimitiveScenarios(List<Object[]> result) {
String p = "fromPortableArrayAnyToPortableArrayAnyToPrimitiveScenarios";
// =============================================
// INPUT mixed
// =============================================
PrimitivePortable p1 = prim(1, NONE);
PrimitivePortable p10 = prim(10, FULL);
PrimitivePortable p20 = prim(20, FULL);
NestedGroupPortable input = nested(new Portable[] { new GroupPortable(new Portable[0]), group(p1, p10), new GroupPortable((Portable[]) null), group(new PrimitivePortable[] { p20 }) });
result.addAll(asList(scenario(input, list(null, p1.byte_, p10.byte_, p20.byte_), "portables[any].portables[any].byte_", p), scenario(input, list(null, p1.short_, p10.short_, p20.short_), "portables[any].portables[any].short_", p), scenario(input, list(null, p1.int_, p10.int_, p20.int_), "portables[any].portables[any].int_", p), scenario(input, list(null, p1.long_, p10.long_, p20.long_), "portables[any].portables[any].long_", p), scenario(input, list(null, p1.char_, p10.char_, p20.char_), "portables[any].portables[any].char_", p), scenario(input, list(null, p1.float_, p10.float_, p20.float_), "portables[any].portables[any].float_", p), scenario(input, list(null, p1.double_, p10.double_, p20.double_), "portables[any].portables[any].double_", p), scenario(input, list(null, p1.boolean_, p10.boolean_, p20.boolean_), "portables[any].portables[any].boolean_", p), scenario(input, list(null, p1.string_, p10.string_, p20.string_), "portables[any].portables[any].string_", p)));
// =============================================
// INPUT empty
// =============================================
NestedGroupPortable inputEmpty = nested(new Portable[0]);
result.addAll(asList(scenario(inputEmpty, null, "portables[any].portables[any].byte_", p), scenario(inputEmpty, null, "portables[any].portables[any].short_", p), scenario(inputEmpty, null, "portables[any].portables[any].int_", p), scenario(inputEmpty, null, "portables[any].portables[any].long_", p), scenario(inputEmpty, null, "portables[any].portables[any].char_", p), scenario(inputEmpty, null, "portables[any].portables[any].float_", p), scenario(inputEmpty, null, "portables[any].portables[any].double_", p), scenario(inputEmpty, null, "portables[any].portables[any].boolean_", p), scenario(inputEmpty, null, "portables[any].portables[any].string_", p)));
// =============================================
// INPUT null
// =============================================
NestedGroupPortable inputNull = nested((Portable[]) null);
result.addAll(asList(scenario(inputNull, null, "portables[any].portables[any].byte_", p), scenario(inputNull, null, "portables[any].portables[any].short_", p), scenario(inputNull, null, "portables[any].portables[any].int_", p), scenario(inputNull, null, "portables[any].portables[any].long_", p), scenario(inputNull, null, "portables[any].portables[any].char_", p), scenario(inputNull, null, "portables[any].portables[any].float_", p), scenario(inputNull, null, "portables[any].portables[any].double_", p), scenario(inputNull, null, "portables[any].portables[any].boolean_", p), scenario(inputNull, null, "portables[any].portables[any].string_", p)));
}
Aggregations