Search in sources :

Example 66 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class GetHDFSTest method testValidators.

@Test
public void testValidators() {
    GetHDFS proc = new TestableGetHDFS(kerberosProperties);
    TestRunner runner = TestRunners.newTestRunner(proc);
    Collection<ValidationResult> results;
    ProcessContext pc;
    results = new HashSet<>();
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        Assert.assertTrue(vr.toString().contains("is invalid because Directory is required"));
    }
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "target");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(0, results.size());
    results = new HashSet<>();
    runner.setProperty(GetHDFS.DIRECTORY, "/target");
    runner.setProperty(GetHDFS.MIN_AGE, "10 secs");
    runner.setProperty(GetHDFS.MAX_AGE, "5 secs");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        Assert.assertTrue(vr.toString().contains("is invalid because Minimum File Age cannot be greater than Maximum File Age"));
    }
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) ValidationResult(org.apache.nifi.components.ValidationResult) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) MockProcessContext(org.apache.nifi.util.MockProcessContext) Test(org.junit.Test)

Example 67 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class PutHDFSTest method testValidators.

@Test
public void testValidators() {
    PutHDFS proc = new TestablePutHDFS(kerberosProperties);
    TestRunner runner = TestRunners.newTestRunner(proc);
    Collection<ValidationResult> results;
    ProcessContext pc;
    results = new HashSet<>();
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because Directory is required"));
    }
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "target");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    assertEquals(0, results.size());
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.REPLICATION_FACTOR, "-1");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because short integer must be greater than zero"));
    }
    proc = new TestablePutHDFS(kerberosProperties);
    runner = TestRunners.newTestRunner(proc);
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.REPLICATION_FACTOR, "0");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because short integer must be greater than zero"));
    }
    proc = new TestablePutHDFS(kerberosProperties);
    runner = TestRunners.newTestRunner(proc);
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.UMASK, "-1");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because octal umask [-1] cannot be negative"));
    }
    proc = new TestablePutHDFS(kerberosProperties);
    runner = TestRunners.newTestRunner(proc);
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.UMASK, "18");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because [18] is not a valid short octal number"));
    }
    results = new HashSet<>();
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.UMASK, "2000");
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        assertTrue(vr.toString().contains("is invalid because octal umask [2000] is not a valid umask"));
    }
    results = new HashSet<>();
    proc = new TestablePutHDFS(kerberosProperties);
    runner = TestRunners.newTestRunner(proc);
    runner.setProperty(PutHDFS.DIRECTORY, "/target");
    runner.setProperty(PutHDFS.COMPRESSION_CODEC, CompressionCodec.class.getName());
    runner.enqueue(new byte[0]);
    pc = runner.getProcessContext();
    if (pc instanceof MockProcessContext) {
        results = ((MockProcessContext) pc).validate();
    }
    Assert.assertEquals(1, results.size());
    for (ValidationResult vr : results) {
        Assert.assertTrue(vr.toString().contains("is invalid because Given value not found in allowed set"));
    }
}
Also used : TestRunner(org.apache.nifi.util.TestRunner) CompressionCodec(org.apache.hadoop.io.compress.CompressionCodec) ValidationResult(org.apache.nifi.components.ValidationResult) MockProcessContext(org.apache.nifi.util.MockProcessContext) ProcessContext(org.apache.nifi.processor.ProcessContext) MockProcessContext(org.apache.nifi.util.MockProcessContext) Test(org.junit.Test)

Example 68 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class TestEventTypeValidator method inputWithMultipleInvalidEventTypeShouldProperlyDisplayEventsInExplanation.

@Test
public void inputWithMultipleInvalidEventTypeShouldProperlyDisplayEventsInExplanation() throws Exception {
    String subject = "subject";
    String input = "append, CREATE, invalidValue1, rename, metadata, unlink, invalidValue2";
    ValidationResult result = eventTypeValidator.validate(subject, input, context);
    assertEquals("subject", result.getSubject());
    assertEquals("append, CREATE, invalidValue1, rename, metadata, unlink, invalidValue2", result.getInput());
    assertEquals("The following are not valid event types: [invalidValue1, invalidValue2]", result.getExplanation());
    assertFalse(result.isValid());
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 69 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class TestEventTypeValidator method emptyInputShouldProperlyFail.

@Test
public void emptyInputShouldProperlyFail() throws Exception {
    String subject = "subject";
    String input = "";
    ValidationResult result = eventTypeValidator.validate(subject, input, context);
    assertEquals("subject", result.getSubject());
    assertEquals("", result.getInput());
    assertEquals("Empty event types are not allowed.", result.getExplanation());
    assertFalse(result.isValid());
}
Also used : ValidationResult(org.apache.nifi.components.ValidationResult) Test(org.junit.Test)

Example 70 with ValidationResult

use of org.apache.nifi.components.ValidationResult in project nifi by apache.

the class StandardProcessorNode method isValid.

@Override
public boolean isValid() {
    try {
        final ValidationContext validationContext = getValidationContext();
        final Collection<ValidationResult> validationResults = super.validate(validationContext);
        for (final ValidationResult result : validationResults) {
            if (!result.isValid()) {
                return false;
            }
        }
        for (final Relationship undef : getUndefinedRelationships()) {
            if (!isAutoTerminated(undef)) {
                return false;
            }
        }
        switch(getInputRequirement()) {
            case INPUT_ALLOWED:
                break;
            case INPUT_FORBIDDEN:
                {
                    if (!getIncomingNonLoopConnections().isEmpty()) {
                        return false;
                    }
                    break;
                }
            case INPUT_REQUIRED:
                {
                    if (getIncomingNonLoopConnections().isEmpty()) {
                        return false;
                    }
                    break;
                }
        }
    } catch (final Throwable t) {
        LOG.warn("Failed during validation", t);
        return false;
    }
    return true;
}
Also used : Relationship(org.apache.nifi.processor.Relationship) ValidationResult(org.apache.nifi.components.ValidationResult) ValidationContext(org.apache.nifi.components.ValidationContext)

Aggregations

ValidationResult (org.apache.nifi.components.ValidationResult)179 Test (org.junit.Test)80 ArrayList (java.util.ArrayList)64 TestRunner (org.apache.nifi.util.TestRunner)46 ValidationContext (org.apache.nifi.components.ValidationContext)37 MockProcessContext (org.apache.nifi.util.MockProcessContext)26 TdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.api.TdchConnectionService)23 Validator (org.apache.nifi.components.Validator)21 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)20 DevTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DevTdchConnectionService)18 DummyTdchConnectionService (com.thinkbiganalytics.kylo.nifi.teradata.tdch.core.controllerservice.DummyTdchConnectionService)18 HashSet (java.util.HashSet)18 ProcessContext (org.apache.nifi.processor.ProcessContext)15 File (java.io.File)12 HashMap (java.util.HashMap)12 Collection (java.util.Collection)11 SSLContextService (org.apache.nifi.ssl.SSLContextService)11 Map (java.util.Map)10 List (java.util.List)9 ComponentLog (org.apache.nifi.logging.ComponentLog)9