use of io.cdap.cdap.etl.mock.transform.MockTransformContext in project hydrator-plugins by cdapio.
the class DecoderTest method testHexDecoder.
@Test
public void testHexDecoder() throws Exception {
String test = "This is a test for testing hex decoding";
Transform<StructuredRecord, StructuredRecord> encoder = new Encoder(new Encoder.Config("a:HEX", OUTPUT.toString()));
TransformContext encoderContext = new MockTransformContext();
encoder.initialize(encoderContext);
MockEmitter<StructuredRecord> emitterEncoded = new MockEmitter<>();
encoder.transform(StructuredRecord.builder(INPUT).set("a", test).set("b", "2").set("c", "3").set("d", "4").set("e", "5").build(), emitterEncoded);
Hex hex = new Hex();
byte[] expected = hex.encode(test.getBytes("UTF-8"));
byte[] actual = emitterEncoded.getEmitted().get(0).get("a");
Assert.assertEquals(2, emitterEncoded.getEmitted().get(0).getSchema().getFields().size());
Assert.assertArrayEquals(expected, actual);
Transform<StructuredRecord, StructuredRecord> decoder = new Decoder(new Decoder.Config("a:HEX", OUTPUTSTR.toString()));
MockTransformContext context = new MockTransformContext();
decoder.initialize(context);
MockEmitter<StructuredRecord> emitterDecoded = new MockEmitter<>();
decoder.transform(emitterEncoded.getEmitted().get(0), emitterDecoded);
Assert.assertEquals(2, emitterDecoded.getEmitted().get(0).getSchema().getFields().size());
Assert.assertEquals(test, emitterDecoded.getEmitted().get(0).get("a"));
Assert.assertEquals(0, encoderContext.getFailureCollector().getValidationFailures().size());
}
use of io.cdap.cdap.etl.mock.transform.MockTransformContext in project hydrator-plugins by cdapio.
the class DecompressorTest method testGZipCompress.
@Test
public void testGZipCompress() throws Exception {
String decompressTester = "This is a test for testing gzip compression";
Transform<StructuredRecord, StructuredRecord> transform = new Decompressor(new Decompressor.Config("a:GZIP", OUTPUT.toString()));
MockTransformContext context = new MockTransformContext();
transform.initialize(context);
MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
byte[] compressed = gzip(decompressTester.getBytes());
transform.transform(StructuredRecord.builder(INPUT).set("a", compressed).set("b", "2").set("c", "3").set("d", "4").set("e", "5").build(), emitter);
String actual = emitter.getEmitted().get(0).get("a");
Assert.assertEquals(2, emitter.getEmitted().get(0).getSchema().getFields().size());
Assert.assertEquals(decompressTester, actual);
}
use of io.cdap.cdap.etl.mock.transform.MockTransformContext in project hydrator-plugins by cdapio.
the class EncoderTest method testBase32Encoder.
@Test
public void testBase32Encoder() throws Exception {
String test = "This is a test for testing base32 encoding";
Transform<StructuredRecord, StructuredRecord> transform = new Encoder(new Encoder.Config("a:BASE32", OUTPUT.toString()));
TransformContext context = new MockTransformContext();
transform.initialize(context);
MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
transform.transform(StructuredRecord.builder(INPUT).set("a", test).set("b", "2").set("c", "3").set("d", "4").set("e", "5").build(), emitter);
Base32 base32 = new Base32();
byte[] expected = base32.encode(test.getBytes("UTF-8"));
byte[] actual = emitter.getEmitted().get(0).get("a");
Assert.assertEquals(2, emitter.getEmitted().get(0).getSchema().getFields().size());
Assert.assertArrayEquals(expected, actual);
Assert.assertEquals(0, context.getFailureCollector().getValidationFailures().size());
}
use of io.cdap.cdap.etl.mock.transform.MockTransformContext in project hydrator-plugins by cdapio.
the class EncoderTest method testStringBase32Encoder.
@Test
public void testStringBase32Encoder() throws Exception {
String test = "This is a test for testing base32 encoding";
Transform<StructuredRecord, StructuredRecord> transform = new Encoder(new Encoder.Config("a:BASE32", OUTPUTSTR.toString()));
TransformContext context = new MockTransformContext();
transform.initialize(context);
MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
transform.transform(StructuredRecord.builder(INPUT).set("a", test).set("b", "2").set("c", "3").set("d", "4").set("e", "5").build(), emitter);
Base32 base32 = new Base32();
String expected = base32.encodeAsString(test.getBytes("UTF-8"));
String actual = emitter.getEmitted().get(0).get("a");
Assert.assertEquals(2, emitter.getEmitted().get(0).getSchema().getFields().size());
Assert.assertEquals(expected, actual);
Assert.assertEquals(0, context.getFailureCollector().getValidationFailures().size());
}
use of io.cdap.cdap.etl.mock.transform.MockTransformContext in project hydrator-plugins by cdapio.
the class EncoderTest method testBase64StringEncoder.
@Test
public void testBase64StringEncoder() throws Exception {
String test = "This is a test for testing base64 encoding";
Transform<StructuredRecord, StructuredRecord> transform = new Encoder(new Encoder.Config("a:STRING_BASE64", OUTPUTSTR.toString()));
TransformContext context = new MockTransformContext();
transform.initialize(context);
MockEmitter<StructuredRecord> emitter = new MockEmitter<>();
transform.transform(StructuredRecord.builder(INPUT).set("a", test).set("b", "2").set("c", "3").set("d", "4").set("e", "5").build(), emitter);
Base64 base64 = new Base64();
String expected = base64.encodeAsString(test.getBytes("UTF-8"));
String actual = emitter.getEmitted().get(0).get("a");
Assert.assertEquals(2, emitter.getEmitted().get(0).getSchema().getFields().size());
Assert.assertEquals(expected, actual);
Assert.assertEquals(0, context.getFailureCollector().getValidationFailures().size());
}
Aggregations