use of io.cdap.cdap.etl.mock.common.MockLookupProvider in project hydrator-plugins by cdapio.
the class JavaScriptTransformTest method testLookup.
@Test
public void testLookup() throws Exception {
JavaScriptTransform.Config config = new JavaScriptTransform.Config("function transform(x, emitter, ctx) { " + "var single = ctx.getLookup('purchases').lookup('abc');" + "var batch = ctx.getLookup('purchases').lookup(['abc', 'sdf']);" + "x.stringField = '1_' + single + ' 2_' + batch['abc'] + batch['sdf'] + '::' + batch.abc;" + "emitter.emit(x);" + "}", null, new LookupConfig(ImmutableMap.of("purchases", new LookupTableConfig(LookupTableConfig.TableType.DATASET))));
Transform<StructuredRecord, StructuredRecord> transform = new JavaScriptTransform(config);
transform.initialize(new MockTransformContext("somestage", new HashMap<String, String>(), new MockLookupProvider(TEST_LOOKUP)));
MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
transform.transform(STRING_RECORD, emitter);
StructuredRecord output = emitter.getEmitted().get(0);
// check record1
Assert.assertEquals(STRING_SCHEMA, output.getSchema());
Assert.assertEquals("1_abc 2_abcsdf::abc", output.get("stringField"));
}
Aggregations