You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/10/04 10:46:11 UTC

[GitHub] [nifi] gresockj commented on a change in pull request #5432: NIFI-9272: When determining if Property dependency is satisfied, cons…

gresockj commented on a change in pull request #5432:
URL: https://github.com/apache/nifi/pull/5432#discussion_r721246691



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardValidationContext.java
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.processor;
+
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.controller.PropertyConfiguration;
+import org.apache.nifi.controller.service.ControllerServiceProvider;
+import org.apache.nifi.parameter.StandardParameterTokenList;
+import org.apache.nifi.processor.util.StandardValidators;
+import org.apache.nifi.registry.VariableRegistry;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+public class TestStandardValidationContext {
+
+    @Test
+    public void testPropertyDependencySatisfied() {
+        final ControllerServiceProvider csProvider = mock(ControllerServiceProvider.class);
+
+        final PropertyDescriptor descriptorA = new PropertyDescriptor.Builder()
+            .name("A")
+            .allowableValues("abc", "xyz")
+            .defaultValue("abc")
+            .build();
+        final PropertyConfiguration configurationA = new PropertyConfiguration("abc", new StandardParameterTokenList("abc", Collections.emptyList()), Collections.emptyList());
+
+        final PropertyDescriptor descriptorB = new PropertyDescriptor.Builder()
+            .name("B")
+            .required(true)
+            .dependsOn(descriptorA, "abc")
+            .addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
+            .build();
+        final PropertyConfiguration configurationB = null;
+
+        final Function<String, PropertyDescriptor> propertyLookup = propName -> propName.equals("A") ? descriptorA : null;
+
+        final Map<PropertyDescriptor, PropertyConfiguration> properties = new HashMap<>();
+        properties.put(descriptorA, configurationA);
+        properties.put(descriptorB, configurationB);
+
+        StandardValidationContext context = new StandardValidationContext(csProvider, properties, null, "1234", "12345", VariableRegistry.EMPTY_REGISTRY, null, false);
+
+        // Property B's dependency should be satisfied because A = "abc"
+        assertTrue(context.isDependencySatisfied(descriptorB, propertyLookup));

Review comment:
       Just curious, are there any lines in this test that should fail prior to this PR?  I just ran this unit test against the code from `main` and it passed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org