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());
}
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());
}
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());
}
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"));
}
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"));
}
Aggregations