Github user YolandaMDavis commented on a diff in the pull request: https://github.com/apache/nifi/pull/501#discussion_r66415203 --- Diff: nifi-api/src/test/java/org/apache/nifi/registry/TestVariableRegistry.java --- @@ -0,0 +1,126 @@ +/* + * 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.registry; + +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class TestVariableRegistry { + + @Test + public void testReadMap(){ + Map<String,String> variables1 = new HashMap<>(); + variables1.put("fake.property.1","fake test value"); + + Map<String,String> variables2 = new HashMap<>(); + variables1.put("fake.property.2","fake test value"); + + VariableRegistry registry = VariableRegistryFactory.getInstance(variables1,variables2); + + Map<String,String> variables = registry.getVariables(); + assertTrue(variables.size() == 2); + assertTrue(variables.get("fake.property.1").equals("fake test value")); + assertTrue(registry.getVariableValue("fake.property.2").equals("fake test value")); + } + + @Test + public void testReadProperties(){ + Properties properties = new Properties(); + properties.setProperty("fake.property.1","fake test value"); + VariableRegistry registry = VariableRegistryFactory.getInstance(properties); + Map<String,String> variables = registry.getVariables(); + assertTrue(variables.get("fake.property.1").equals("fake test value")); + } + + @Test + public void testReadFiles(){ + final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); + final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); + VariableRegistry registry = VariableRegistryFactory.getInstance(fooPath.toFile(),testPath.toFile()); + Map<String,String> variables = registry.getVariables(); + assertTrue(variables.size() == 3); + assertTrue(variables.get("fake.property.1").equals("test me out 1")); + assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); + } + + @Test + public void testReadPaths(){ + final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); + final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); + VariableRegistry registry = VariableRegistryFactory.getInstance(fooPath,testPath); + Map<String,String> variables = registry.getVariables(); + assertTrue(variables.size() == 3); + assertTrue(variables.get("fake.property.1").equals("test me out 1")); + assertTrue(variables.get("fake.property.3").equals("test me out 3, test me out 4")); + } + + @Test + public void testAddRegistry(){ + + final Map<String,String> variables1 = new HashMap<>(); + variables1.put("fake.property.1","fake test value"); + + + final Path fooPath = Paths.get("src/test/resources/TestVariableRegistry/foobar.properties"); + VariableRegistry pathRegistry = VariableRegistryFactory.getInstance(fooPath); + + final Path testPath = Paths.get("src/test/resources/TestVariableRegistry/test.properties"); + VariableRegistry fileRegistry = VariableRegistryFactory.getInstance(testPath.toFile()); + + Properties properties = new Properties(); + properties.setProperty("fake.property.5","test me out 5"); + VariableRegistry propRegistry = VariableRegistryFactory.getInstance(properties); + + propRegistry.addRegistry(pathRegistry); + propRegistry.addRegistry(fileRegistry); + + Map<String,String> variables = propRegistry.getVariables(); + assertTrue(variables.size() == 4); --- End diff -- Actually based on my updated comment on the map size (see above) yes this would fail if we based sizing on distinct keys. I think originally size was based on actually entries (in Query.java implementation).
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. ---