Search in sources :

Example 31 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class StatementTestCase method requireThatStatementIsExecuted.

@Test
public void requireThatStatementIsExecuted() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    StatementExpression statement = newStatement(new SetValueExpression(new IntegerFieldValue(69)));
    newStatement(statement).execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof IntegerFieldValue);
    assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) IntegerFieldValue(com.yahoo.document.datatypes.IntegerFieldValue) Test(org.junit.Test)

Example 32 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class SelectInputTestCase method assertSelect.

private static void assertSelect(List<String> inputField, List<String> availableFields, String expected) {
    SimpleTestAdapter adapter = new SimpleTestAdapter();
    ExecutionContext ctx = new ExecutionContext(adapter);
    for (String fieldName : availableFields) {
        adapter.createField(new Field(fieldName, DataType.STRING));
        ctx.setOutputValue(null, fieldName, new StringFieldValue(fieldName));
    }
    List<Pair<String, Expression>> cases = new LinkedList<>();
    for (String fieldName : inputField) {
        cases.add(new Pair<String, Expression>(fieldName, new SetVarExpression("out")));
    }
    new SelectInputExpression(cases).execute(ctx);
    assertEquals(expected != null ? new StringFieldValue(expected) : null, ctx.getVariable("out"));
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LinkedList(java.util.LinkedList) Pair(com.yahoo.collections.Pair)

Example 33 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class SelectInputTestCase method requireThatExpressionCanBeVerified.

@Test
public void requireThatExpressionCanBeVerified() {
    SimpleTestAdapter adapter = new SimpleTestAdapter();
    adapter.createField(new Field("my_int", DataType.INT));
    adapter.createField(new Field("my_str", DataType.STRING));
    Expression exp = newSelectInput(new AttributeExpression("my_int"), "my_int");
    assertVerify(adapter, null, exp);
    assertVerify(adapter, DataType.INT, exp);
    assertVerify(adapter, DataType.STRING, exp);
    assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_str"), "Can not assign string to field 'my_int' which is int.");
    assertVerifyThrows(adapter, newSelectInput(new AttributeExpression("my_int"), "my_unknown"), "Field 'my_unknown' not found.");
}
Also used : Field(com.yahoo.document.Field) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Example 34 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class SplitTestCase method requireThatEmptyInputProducesEmptyArray.

@Test
public void requireThatEmptyInputProducesEmptyArray() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue(""));
    new SplitExpression(";").execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val.getDataType().equals(DataType.getArray(DataType.STRING)));
    assertTrue(val instanceof Array);
    assertEquals(0, ((Array) val).size());
}
Also used : Array(com.yahoo.document.datatypes.Array) SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) Test(org.junit.Test)

Example 35 with SimpleTestAdapter

use of com.yahoo.vespa.indexinglanguage.SimpleTestAdapter in project vespa by vespa-engine.

the class SplitTestCase method requireThatNullInputProducesNullOutput.

@Test
public void requireThatNullInputProducesNullOutput() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    new SplitExpression(";").execute(ctx);
    assertNull(ctx.getValue());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) Test(org.junit.Test)

Aggregations

SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)67 Test (org.junit.Test)59 StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)42 FieldValue (com.yahoo.document.datatypes.FieldValue)30 Field (com.yahoo.document.Field)14 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)14 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)7 Array (com.yahoo.document.datatypes.Array)4 StructDataType (com.yahoo.document.StructDataType)3 SimpleLinguistics (com.yahoo.language.simple.SimpleLinguistics)3 Pair (com.yahoo.collections.Pair)1 ArrayDataType (com.yahoo.document.ArrayDataType)1 WeightedSetDataType (com.yahoo.document.WeightedSetDataType)1 ByteFieldValue (com.yahoo.document.datatypes.ByteFieldValue)1 DoubleFieldValue (com.yahoo.document.datatypes.DoubleFieldValue)1 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)1 StructuredFieldValue (com.yahoo.document.datatypes.StructuredFieldValue)1 WeightedSet (com.yahoo.document.datatypes.WeightedSet)1 AnnotatorConfig (com.yahoo.vespa.indexinglanguage.linguistics.AnnotatorConfig)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1