Search in sources :

Example 21 with JsonSchema

use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithMapOfRecords.

@Test
public void schemaWithMapOfRecords() throws Exception {
    String testName = "schemaWithMapOfRecords";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    MapConverter converter = new MapConverter(new JsonSchema(schema), state);
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : MapConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.MapConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 22 with JsonSchema

use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithComplexUnion.

@Test
public void schemaWithComplexUnion() throws Exception {
    String testName = "schemaWithComplexUnion";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonArray expected = getExpectedSchema(testName).getAsJsonArray();
    UnionConverter converter = new UnionConverter(new JsonSchema(schema), state);
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) UnionConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.UnionConverter) Test(org.testng.annotations.Test)

Example 23 with JsonSchema

use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithRecordOfMap.

@Test
public void schemaWithRecordOfMap() throws Exception {
    String testName = "schemaWithRecordOfMap";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    RecordConverter converter = new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "something"));
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 24 with JsonSchema

use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithRecordOfRecordCheckNamespace.

@Test
public void schemaWithRecordOfRecordCheckNamespace() throws Exception {
    String testName = "schemaWithRecordOfRecordCheckNamespace";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    RecordConverter converter = new RecordConverter(new JsonSchema(schema), state, buildNamespace(state.getExtract().getNamespace(), "person"));
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
    Assert.assertEquals(converter.schema().getField("someperson").schema().getNamespace(), "namespace.person.myrecord");
    Assert.assertEquals(converter.schema().getNamespace(), "namespace.person");
}
Also used : RecordConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter) JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 25 with JsonSchema

use of org.apache.gobblin.converter.json.JsonSchema in project incubator-gobblin by apache.

the class JsonElementConversionFactoryTest method schemaWithArrayOfRecords.

@Test
public void schemaWithArrayOfRecords() throws Exception {
    String testName = "schemaWithArrayOfRecords";
    JsonObject schema = getSchemaData(testName).getAsJsonObject();
    JsonObject expected = getExpectedSchema(testName).getAsJsonObject();
    JsonSchema jsonSchema = new JsonSchema(schema);
    jsonSchema.setColumnName("dummy1");
    ArrayConverter converter = new ArrayConverter(jsonSchema, state);
    Assert.assertEquals(avroSchemaToJsonElement(converter), expected);
}
Also used : JsonSchema(org.apache.gobblin.converter.json.JsonSchema) JsonObject(com.google.gson.JsonObject) ArrayConverter(org.apache.gobblin.converter.avro.JsonElementConversionFactory.ArrayConverter) Test(org.testng.annotations.Test)

Aggregations

JsonSchema (org.apache.gobblin.converter.json.JsonSchema)26 JsonObject (com.google.gson.JsonObject)25 Test (org.testng.annotations.Test)24 RecordConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.RecordConverter)11 JsonArray (com.google.gson.JsonArray)7 ArrayConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.ArrayConverter)5 MapConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.MapConverter)5 UnionConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.UnionConverter)2 Schema (org.apache.avro.Schema)1 SchemaConversionException (org.apache.gobblin.converter.SchemaConversionException)1 EnumConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.EnumConverter)1 StringConverter (org.apache.gobblin.converter.avro.JsonElementConversionFactory.StringConverter)1