From 17d41435d8dc37eec8536f02ed38f6200801812d Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Sun, 27 May 2018 16:05:03 -0400 Subject: [PATCH] NIFI-5244 Fixed a bug in MockSchemaRegistry that prevented it from loading using the schema name strategy. --- .../nifi-mock-record-utils/pom.xml | 74 +++++++++++++++++++ .../record/MockSchemaRegistry.java | 2 +- .../record/TestMockSchemaRegistry.groovy | 46 ++++++++++++ 3 files changed, 121 insertions(+), 1 deletion(-) create mode 100644 nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/test/groovy/org/apache/nifi/serialization/record/TestMockSchemaRegistry.groovy diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/pom.xml b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/pom.xml index 8bb0b1459e10..b9bcaa8334a5 100644 --- a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/pom.xml +++ b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/pom.xml @@ -46,5 +46,79 @@ org.apache.nifi nifi-record + + org.apache.nifi + nifi-avro-record-utils + 1.7.0-SNAPSHOT + test + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.5 + + + add-source + generate-sources + + add-source + + + + src/main/groovy + + + + + add-test-source + generate-test-sources + + add-test-source + + + + src/test/groovy + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + groovy-tests + + testCompile + + + groovy-eclipse-compiler + + + + + 1.8 + 1.8 + + + + org.codehaus.groovy + groovy-eclipse-compiler + 2.9.2-01 + + + org.codehaus.groovy + groovy-eclipse-batch + 2.4.3-01 + + + + + diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/main/java/org/apache/nifi/serialization/record/MockSchemaRegistry.java b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/main/java/org/apache/nifi/serialization/record/MockSchemaRegistry.java index a5ec246bb9d7..4d4ffe5f207c 100644 --- a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/main/java/org/apache/nifi/serialization/record/MockSchemaRegistry.java +++ b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/main/java/org/apache/nifi/serialization/record/MockSchemaRegistry.java @@ -46,7 +46,7 @@ private RecordSchema retrieveSchemaByName(final SchemaIdentifier schemaIdentifie throw new org.apache.nifi.schema.access.SchemaNotFoundException("Cannot retrieve schema because Schema Name is not present"); } - return schemaNameMap.get(schemaName); + return schemaNameMap.get(schemaName.get()); } private RecordSchema retrieveSchemaByIdAndVersion(final SchemaIdentifier schemaIdentifier) throws IOException, SchemaNotFoundException { diff --git a/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/test/groovy/org/apache/nifi/serialization/record/TestMockSchemaRegistry.groovy b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/test/groovy/org/apache/nifi/serialization/record/TestMockSchemaRegistry.groovy new file mode 100644 index 000000000000..0266851f9583 --- /dev/null +++ b/nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-mock-record-utils/src/test/groovy/org/apache/nifi/serialization/record/TestMockSchemaRegistry.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.nifi.serialization.record + +import org.apache.avro.Schema +import org.apache.nifi.avro.AvroTypeUtil +import org.junit.Assert +import org.junit.Test +import static groovy.json.JsonOutput.* + +class TestMockSchemaRegistry { + @Test + void testGetSchemaByName() { + def registry = new MockSchemaRegistry() + def schema = prettyPrint(toJson([ + name: "TestSchema", + type: "record", + fields: [ + [ name: "msg", type: "string" ] + ] + ])) + def recordSchema = AvroTypeUtil.createSchema(new Schema.Parser().parse(schema)) + registry.addSchema("simple", recordSchema) + + def identifier = SchemaIdentifier.builder().name("simple").build() + def result = registry.retrieveSchemaByName(identifier) + + Assert.assertNotNull("Failed to load schema.", result) + Assert.assertEquals(result.fieldNames, recordSchema.fieldNames) + } +}