Search in sources :

Example 1 with NiFiUrlValidator

use of org.apache.nifi.reporting.AbstractSiteToSiteReportingTask.NiFiUrlValidator in project nifi by apache.

the class TestSiteToSiteBulletinReportingTask method testUrls.

@Test
public void testUrls() throws IOException {
    final ValidationContext context = Mockito.mock(ValidationContext.class);
    Mockito.when(context.newPropertyValue(Mockito.anyString())).then(new Answer<PropertyValue>() {

        @Override
        public PropertyValue answer(InvocationOnMock invocation) throws Throwable {
            String value = (String) invocation.getArguments()[0];
            return new StandardPropertyValue(value, null);
        }
    });
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080", context).isValid());
    assertFalse(new NiFiUrlValidator().validate("url", "", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi,https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "https://localhost:8080/nifi, https://localhost:8080/nifi", context).isValid());
    assertFalse(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi, https://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi,http://localhost:8080/nifi", context).isValid());
    assertTrue(new NiFiUrlValidator().validate("url", "http://localhost:8080/nifi,http://localhost:8080", context).isValid());
}
Also used : InvocationOnMock(org.mockito.invocation.InvocationOnMock) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) StandardPropertyValue(org.apache.nifi.attribute.expression.language.StandardPropertyValue) ValidationContext(org.apache.nifi.components.ValidationContext) NiFiUrlValidator(org.apache.nifi.reporting.AbstractSiteToSiteReportingTask.NiFiUrlValidator) Test(org.junit.Test)

Aggregations

StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)1 PropertyValue (org.apache.nifi.components.PropertyValue)1 ValidationContext (org.apache.nifi.components.ValidationContext)1 NiFiUrlValidator (org.apache.nifi.reporting.AbstractSiteToSiteReportingTask.NiFiUrlValidator)1 MockPropertyValue (org.apache.nifi.util.MockPropertyValue)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1