use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.
the class ForEachTestCase method requireThatStructContentCanBeConverted.
@Test
public void requireThatStructContentCanBeConverted() {
StructDataType type = new StructDataType("my_type");
type.addField(new Field("my_str", DataType.STRING));
Struct struct = new Struct(type);
struct.setFieldValue("my_str", new StringFieldValue(" foo "));
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(struct);
new ForEachExpression(new TrimExpression()).execute(ctx);
FieldValue val = ctx.getValue();
assertTrue(val instanceof Struct);
assertEquals(type, val.getDataType());
assertEquals(new StringFieldValue("foo"), ((Struct) val).getFieldValue("my_str"));
}
use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.
the class ForEachTestCase method requireThatIncompatibleStructFieldsFailToValidate.
@Test
public void requireThatIncompatibleStructFieldsFailToValidate() {
StructDataType type = new StructDataType("my_type");
type.addField(new Field("my_int", DataType.INT));
VerificationContext ctx = new VerificationContext(new SimpleTestAdapter());
ctx.setValue(type);
try {
new ForEachExpression(new ToArrayExpression()).verify(ctx);
fail();
} catch (VerificationException e) {
assertEquals("Expected int output, got Array<int>.", e.getMessage());
}
}
use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.
the class ForEachTestCase method requireThatIncompatibleStructFieldsFailToExecute.
@Test
public void requireThatIncompatibleStructFieldsFailToExecute() {
StructDataType type = new StructDataType("my_type");
type.addField(new Field("my_int", DataType.INT));
Struct struct = new Struct(type);
struct.setFieldValue("my_int", new IntegerFieldValue(69));
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(struct);
try {
new ForEachExpression(new ToArrayExpression()).execute(ctx);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Class class com.yahoo.document.datatypes.Array not applicable to an class " + "com.yahoo.document.datatypes.IntegerFieldValue instance.", e.getMessage());
}
}
use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.
the class ForEachTestCase method requireThatArrayCanBeConverted.
@Test
public void requireThatArrayCanBeConverted() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
Array<StringFieldValue> before = new Array<>(DataType.getArray(DataType.STRING));
before.add(new StringFieldValue("6"));
before.add(new StringFieldValue("9"));
ctx.setValue(before);
new ForEachExpression(new ToIntegerExpression()).execute(ctx);
FieldValue val = ctx.getValue();
assertTrue(val instanceof Array);
Array after = (Array) val;
assertEquals(2, after.size());
assertEquals(new IntegerFieldValue(6), after.get(0));
assertEquals(new IntegerFieldValue(9), after.get(1));
}
use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.
the class ForEachTestCase method requireThatEmptyArrayCanBeConverted.
@Test
public void requireThatEmptyArrayCanBeConverted() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new Array<StringFieldValue>(DataType.getArray(DataType.STRING)));
new ForEachExpression(new ToIntegerExpression()).execute(ctx);
FieldValue val = ctx.getValue();
assertTrue(val instanceof Array);
assertEquals(DataType.INT, ((Array) val).getDataType().getNestedType());
assertTrue(((Array) val).isEmpty());
}
Aggregations