use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class BytesToJsonConverterTest method testConverter.
@Test
public void testConverter() throws DataConversionException, IOException {
BytesToJsonConverter converter = new BytesToJsonConverter();
WorkUnitState state = new WorkUnitState();
JsonObject record = converter.convertRecord("dummySchema", IOUtils.toByteArray(this.getClass().getResourceAsStream("/converter/jsonToAvroRecord.json")), state).iterator().next();
Assert.assertEquals(record.get("longField").getAsLong(), 1234L);
Assert.assertEquals(record.get("nestedRecords").getAsJsonObject().get("nestedField2").getAsString(), "test2");
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class ObjectStoreDeleteConverterTest method convertStringObjId.
@Test
public void convertStringObjId() throws Exception {
WorkUnitState wu = new WorkUnitState();
wu.setProp(ObjectStoreDeleteConverter.OBJECT_ID_FIELD, "objectId");
ObjectStoreDeleteConverter converter = new ObjectStoreDeleteConverter();
converter.init(wu);
Schema schema = new Schema.Parser().parse("{ \"type\" : \"record\", \"name\" : \"test_schema\", \"namespace\" : \"com.gobblin.test\", " + "\"fields\" : [ { \"name\" : \"objectId\", \"type\" : \"string\"} ], \"doc:\" : \"\" }");
GenericRecord datum = new GenericData.Record(schema);
String objId = "abcd";
datum.put("objectId", objId);
Assert.assertEquals(Iterables.getFirst(converter.convertRecord(converter.convertSchema(schema, wu), datum, wu), null).getObjectId(), objId.getBytes());
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class ObjectStoreDeleteConverterTest method convertLongObjId.
@Test
public void convertLongObjId() throws Exception {
WorkUnitState wu = new WorkUnitState();
wu.setProp(ObjectStoreDeleteConverter.OBJECT_ID_FIELD, "objectId");
ObjectStoreDeleteConverter converter = new ObjectStoreDeleteConverter();
converter.init(wu);
Schema schema = new Schema.Parser().parse("{ \"type\" : \"record\", \"name\" : \"test_schema\", \"namespace\" : \"com.gobblin.test\", " + "\"fields\" : [ { \"name\" : \"objectId\", \"type\" : \"long\"} ], \"doc:\" : \"\" }");
GenericRecord datum = new GenericData.Record(schema);
long objId = 1234l;
datum.put("objectId", objId);
Assert.assertEquals(Iterables.getFirst(converter.convertRecord(converter.convertSchema(schema, wu), datum, wu), null).getObjectId(), Longs.toByteArray(objId));
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class ObjectToStringConverterTest method testConvertRecord.
/**
* Test for {@link ObjectToStringConverter#convertRecord(Class, Object, WorkUnitState)}. Checks that the convertRecord
* method properly converts an {@link Object} to its String equivalent.
*/
@Test
public void testConvertRecord() throws DataConversionException {
WorkUnitState workUnitState = new WorkUnitState();
ObjectToStringConverter converter = new ObjectToStringConverter();
converter.init(workUnitState);
// Test that an Integer can properly be converted to a String
Integer integerValue = new Integer(1);
Iterator<String> itr = converter.convertRecord(String.class, integerValue, workUnitState).iterator();
Assert.assertTrue(itr.hasNext());
Assert.assertEquals(itr.next(), "1");
Assert.assertTrue(!itr.hasNext());
// Test that a Long can properly be converted to a String
Long longValue = new Long(2);
itr = converter.convertRecord(String.class, longValue, workUnitState).iterator();
Assert.assertTrue(itr.hasNext());
Assert.assertEquals(itr.next(), "2");
Assert.assertTrue(!itr.hasNext());
}
use of org.apache.gobblin.configuration.WorkUnitState in project incubator-gobblin by apache.
the class StringFilterConverterTest method testConvertRecordWithNoRegex.
/**
* Test for {@link StringFilterConverter#convertRecord(Class, String, WorkUnitState)} with a blank regex.
*/
@Test
public void testConvertRecordWithNoRegex() throws DataConversionException {
WorkUnitState workUnitState = new WorkUnitState();
StringFilterConverter converter = new StringFilterConverter();
converter.init(workUnitState);
String test = "HelloWorld";
Iterator<String> itr = converter.convertRecord(String.class, test, workUnitState).iterator();
Assert.assertTrue(!itr.hasNext());
}
Aggregations