Search in sources :

Example 11 with SchemaIdentifier

use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.

the class TestHortonworksAttributeSchemaReferenceWriter method testValidateWithInvalidSchema.

@Test(expected = SchemaNotFoundException.class)
public void testValidateWithInvalidSchema() throws SchemaNotFoundException {
    final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name("test").build();
    final RecordSchema recordSchema = createRecordSchema(schemaIdentifier);
    final SchemaAccessWriter schemaAccessWriter = new HortonworksAttributeSchemaReferenceWriter();
    schemaAccessWriter.validateSchema(recordSchema);
}
Also used : SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 12 with SchemaIdentifier

use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.

the class TestSchemaNameAsAttribute method testValidateSchemaWhenValid.

@Test
public void testValidateSchemaWhenValid() throws SchemaNotFoundException {
    final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name("person").id(1L).build();
    final RecordSchema schema = new SimpleRecordSchema(fields, schemaIdentifier);
    schemaAccessWriter.validateSchema(schema);
}
Also used : SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 13 with SchemaIdentifier

use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.

the class TestSchemaNameAsAttribute method testWriteOnlyName.

@Test
public void testWriteOnlyName() {
    final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name("person").id(1L).build();
    final RecordSchema schema = new SimpleRecordSchema(fields, schemaIdentifier);
    final Map<String, String> attributes = schemaAccessWriter.getAttributes(schema);
    Assert.assertEquals(1, attributes.size());
    Assert.assertEquals(schemaIdentifier.getName().get(), attributes.get(SchemaNameAsAttribute.SCHEMA_NAME_ATTRIBUTE));
}
Also used : SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 14 with SchemaIdentifier

use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.

the class TestSchemaNameAsAttribute method testValidateSchemaWhenNoName.

@Test(expected = SchemaNotFoundException.class)
public void testValidateSchemaWhenNoName() throws SchemaNotFoundException {
    final SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().id(1L).build();
    final RecordSchema schema = new SimpleRecordSchema(fields, schemaIdentifier);
    schemaAccessWriter.validateSchema(schema);
}
Also used : SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) SimpleRecordSchema(org.apache.nifi.serialization.SimpleRecordSchema) Test(org.junit.Test)

Example 15 with SchemaIdentifier

use of org.apache.nifi.serialization.record.SchemaIdentifier in project nifi by apache.

the class TestSchemaNamePropertyStrategy method testNameAndVersion.

@Test
public void testNameAndVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("1");
    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(schemaRegistry, nameValue, branchValue, versionValue);
    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder().name(nameValue.getValue()).version(versionValue.asInteger()).build();
    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier)))).thenReturn(recordSchema);
    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) SchemaIdentifier(org.apache.nifi.serialization.record.SchemaIdentifier) RecordSchema(org.apache.nifi.serialization.record.RecordSchema) Test(org.junit.Test)

Aggregations

SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)37 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)28 Test (org.junit.Test)22 SimpleRecordSchema (org.apache.nifi.serialization.SimpleRecordSchema)12 OptionalLong (java.util.OptionalLong)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 OptionalInt (java.util.OptionalInt)5 Schema (org.apache.avro.Schema)5 PropertyValue (org.apache.nifi.components.PropertyValue)5 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)5 SchemaMetadataInfo (com.hortonworks.registries.schemaregistry.SchemaMetadataInfo)4 SchemaVersionInfo (com.hortonworks.registries.schemaregistry.SchemaVersionInfo)4 ByteBuffer (java.nio.ByteBuffer)4 SchemaMetadata (com.hortonworks.registries.schemaregistry.SchemaMetadata)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)3 InitializationException (org.apache.nifi.reporting.InitializationException)3 SchemaNotFoundException (org.apache.nifi.schema.access.SchemaNotFoundException)3