Search in sources :

Example 21 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class GuardTestCase method requireThatLanguageCanBeSetByUpdate.

@Test
public void requireThatLanguageCanBeSetByUpdate() throws ParseException {
    DocumentType docType = new DocumentType("my_input");
    docType.addField(new Field("my_str", DataType.STRING));
    DocumentUpdate docUpdate = new DocumentUpdate(docType, "doc:scheme:");
    docUpdate.addFieldUpdate(FieldUpdate.createAssign(docType.getField("my_str"), new StringFieldValue("foo")));
    SimpleAdapterFactory factory = new SimpleAdapterFactory();
    List<UpdateAdapter> lst = factory.newUpdateAdapterList(docUpdate);
    assertEquals(1, lst.size());
    ExecutionContext ctx = new ExecutionContext(lst.get(0));
    Expression.fromString("guard { 'en' | set_language }").execute(ctx);
    assertEquals(Language.ENGLISH, ctx.getLanguage());
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) UpdateAdapter(com.yahoo.vespa.indexinglanguage.UpdateAdapter) SimpleAdapterFactory(com.yahoo.vespa.indexinglanguage.SimpleAdapterFactory) Test(org.junit.Test)

Example 22 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class HexEncodeTestCase method requireThatInputIsEncoded.

@Test
public void requireThatInputIsEncoded() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new LongFieldValue(489210573L));
    new HexEncodeExpression().execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertEquals("1d28c2cd", ((StringFieldValue) val).getString());
}
Also used : SimpleTestAdapter(com.yahoo.vespa.indexinglanguage.SimpleTestAdapter) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) FieldValue(com.yahoo.document.datatypes.FieldValue) LongFieldValue(com.yahoo.document.datatypes.LongFieldValue) Test(org.junit.Test)

Example 23 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class LowerCaseTestCase method requireThatStringIsLowerCased.

@Test
public void requireThatStringIsLowerCased() {
    ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
    ctx.setValue(new StringFieldValue("FOO"));
    new LowerCaseExpression().execute(ctx);
    FieldValue val = ctx.getValue();
    assertTrue(val instanceof StringFieldValue);
    assertEquals("foo", ((StringFieldValue) val).getString());
}
Also used : 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 24 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class ScriptTestCase method requireThatIfExpressionPassesOriginalInputAlong.

@Test
public void requireThatIfExpressionPassesOriginalInputAlong() throws ParseException {
    Document input = new Document(type, "doc:scheme:");
    Document output = Expression.execute(Expression.fromString("'foo' | if (1 < 2) { 'bar' | index 'out-1' } else { 'baz' | index 'out-1' } | index 'out-1'"), input);
    assertNotNull(output);
    assertEquals(new StringFieldValue("foo"), output.getFieldValue("out-1"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Example 25 with StringFieldValue

use of com.yahoo.document.datatypes.StringFieldValue in project vespa by vespa-engine.

the class ScriptTestCase method requireThatFactoryMethodWorks.

@Test
public void requireThatFactoryMethodWorks() throws ParseException {
    Document input = new Document(type, "doc:scheme:");
    input.setFieldValue("in-1", new StringFieldValue("FOO"));
    Document output = Expression.execute(Expression.fromString("input 'in-1' | { index 'out-1'; lowercase | index 'out-2' }"), input);
    assertNotNull(output);
    assertEquals(new StringFieldValue("FOO"), output.getFieldValue("out-1"));
    assertEquals(new StringFieldValue("foo"), output.getFieldValue("out-2"));
}
Also used : StringFieldValue(com.yahoo.document.datatypes.StringFieldValue) Document(com.yahoo.document.Document) Test(org.junit.Test)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)210 Test (org.junit.Test)136 FieldValue (com.yahoo.document.datatypes.FieldValue)49 SimpleTestAdapter (com.yahoo.vespa.indexinglanguage.SimpleTestAdapter)40 IntegerFieldValue (com.yahoo.document.datatypes.IntegerFieldValue)37 Document (com.yahoo.document.Document)30 Array (com.yahoo.document.datatypes.Array)25 DocumentType (com.yahoo.document.DocumentType)21 LongFieldValue (com.yahoo.document.datatypes.LongFieldValue)21 Struct (com.yahoo.document.datatypes.Struct)21 DocumentPut (com.yahoo.document.DocumentPut)20 GrowableByteBuffer (com.yahoo.io.GrowableByteBuffer)20 MapFieldValue (com.yahoo.document.datatypes.MapFieldValue)18 SpanTree (com.yahoo.document.annotation.SpanTree)15 FieldUpdate (com.yahoo.document.update.FieldUpdate)15 DocumentUpdate (com.yahoo.document.DocumentUpdate)12 Field (com.yahoo.document.Field)12 Annotation (com.yahoo.document.annotation.Annotation)12 FloatFieldValue (com.yahoo.document.datatypes.FloatFieldValue)12 HashMap (java.util.HashMap)12