use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class OutputAssert method assertExecute.
public static void assertExecute(OutputExpression exp) {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter(new Field(exp.getFieldName(), DataType.STRING)));
ctx.setValue(new StringFieldValue("69"));
ctx.execute(exp);
FieldValue out = ctx.getInputValue(exp.getFieldName());
assertTrue(out instanceof StringFieldValue);
assertEquals("69", ((StringFieldValue) out).getString());
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class SetVarTestCase method requireThatSymbolIsWritten.
@Test
public void requireThatSymbolIsWritten() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new IntegerFieldValue(69));
new SetVarExpression("out").execute(ctx);
FieldValue val = ctx.getVariable("out");
assertTrue(val instanceof IntegerFieldValue);
assertEquals(69, ((IntegerFieldValue) val).getInteger());
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class ToStringTestCase method requireThatValueIsConverted.
@Test
public void requireThatValueIsConverted() {
ExecutionContext ctx = new ExecutionContext(new SimpleTestAdapter());
ctx.setValue(new IntegerFieldValue(69)).execute(new ToStringExpression());
FieldValue val = ctx.getValue();
assertTrue(val instanceof StringFieldValue);
assertEquals("69", ((StringFieldValue) val).getString());
}
use of com.yahoo.document.datatypes.FieldValue 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());
}
use of com.yahoo.document.datatypes.FieldValue in project vespa by vespa-engine.
the class DocumentFieldTemplate method hit.
@Override
public void hit(Context context, Writer writer) throws IOException {
DocumentHit hit = (DocumentHit) context.get("hit");
Document doc = hit.getDocument();
// Assume field existence has been checked before we ever get here.
// Also assume that relevant encoding/content type is set
// appropriately according to the request and the field's content
// type, as this is immutable in the template set.
FieldValue value = doc.getFieldValue(field);
if (field.getDataType() == DataType.RAW) {
ByteWriter bw = (ByteWriter) writer;
bw.append(((Raw) value).getByteBuffer().array());
} else {
writer.write(XML.xmlEscape(value.toString(), false));
}
}
Aggregations