Search in sources :

Example 1 with UpdateAdapter

use of com.yahoo.vespa.indexinglanguage.UpdateAdapter 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)

Aggregations

StringFieldValue (com.yahoo.document.datatypes.StringFieldValue)1 SimpleAdapterFactory (com.yahoo.vespa.indexinglanguage.SimpleAdapterFactory)1 UpdateAdapter (com.yahoo.vespa.indexinglanguage.UpdateAdapter)1 Test (org.junit.Test)1