use of com.yahoo.document.StructDataType 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.document.StructDataType 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.document.StructDataType 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.document.StructDataType in project vespa by vespa-engine.
the class FieldValueConverterTestCase method requireThatStructElementsCanBeRemoved.
@Test
public void requireThatStructElementsCanBeRemoved() {
StructDataType type = new StructDataType("foo");
type.addField(new Field("bar", DataType.STRING));
type.addField(new Field("baz", DataType.STRING));
Struct before = type.createFieldValue();
StringFieldValue barVal = new StringFieldValue("6");
StringFieldValue bazVal = new StringFieldValue("9");
before.setFieldValue("bar", barVal);
before.setFieldValue("baz", bazVal);
FieldValue after = new SearchReplace(barVal, null).convert(before);
assertTrue(after instanceof Struct);
assertNull(((Struct) after).getFieldValue("bar"));
assertEquals(bazVal, ((Struct) after).getFieldValue("baz"));
after = new SearchReplace(bazVal, null).convert(before);
assertTrue(after instanceof Struct);
assertEquals(barVal, ((Struct) after).getFieldValue("bar"));
assertNull(((Struct) after).getFieldValue("baz"));
}
Aggregations