org.apache.nifi.util.MockPropertyValue Java Examples

The following examples show how to use org.apache.nifi.util.MockPropertyValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRangerNiFiAuthorizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutKeytab() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #2
Source File: TestPrometheusRecordSink.java    From nifi with Apache License 2.0 6 votes vote down vote up
private PrometheusRecordSink initTask() throws InitializationException {

        final ComponentLog logger = mock(ComponentLog.class);
        final PrometheusRecordSink task = new PrometheusRecordSink();
        ConfigurationContext context = mock(ConfigurationContext.class);
        final StateManager stateManager = new MockStateManager(task);

        final PropertyValue pValue = mock(StandardPropertyValue.class);
        when(context.getProperty(PrometheusMetricsUtil.METRICS_ENDPOINT_PORT)).thenReturn(new MockPropertyValue(portString));
        when(context.getProperty(PrometheusRecordSink.SSL_CONTEXT)).thenReturn(pValue);
        when(pValue.asControllerService(SSLContextService.class)).thenReturn(null);

        final ControllerServiceInitializationContext initContext = new MockControllerServiceInitializationContext(task, UUID.randomUUID().toString(), logger, stateManager);
        task.initialize(initContext);
        task.onScheduled(context);

        return task;
    }
 
Example #3
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameAndBlankBranch() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue("  ");
    final PropertyValue versionValue = new MockPropertyValue(null);

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder()
            .name(nameValue.getValue())
            .build();

    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier))))
            .thenReturn(recordSchema);

    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
 
Example #4
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameAndBranch() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue("test");
    final PropertyValue versionValue = new MockPropertyValue(null);

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder()
            .name(nameValue.getValue())
            .branch(branchValue.getValue())
            .build();

    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier))))
            .thenReturn(recordSchema);

    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
 
Example #5
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameAndBlankVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("   ");

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder()
            .name(nameValue.getValue())
            .build();

    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier))))
            .thenReturn(recordSchema);

    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
 
Example #6
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameAndVersion() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue("1");

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder()
            .name(nameValue.getValue())
            .version(versionValue.asInteger())
            .build();

    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier))))
            .thenReturn(recordSchema);

    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
 
Example #7
Source File: TestSchemaNamePropertyStrategy.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testNameOnly() throws SchemaNotFoundException, IOException {
    final PropertyValue nameValue = new MockPropertyValue("person");
    final PropertyValue branchValue = new MockPropertyValue(null);
    final PropertyValue versionValue = new MockPropertyValue(null);

    final SchemaNamePropertyStrategy schemaNamePropertyStrategy = new SchemaNamePropertyStrategy(
            schemaRegistry, nameValue, branchValue, versionValue);

    final SchemaIdentifier expectedSchemaIdentifier = SchemaIdentifier.builder()
            .name(nameValue.getValue())
            .build();

    when(schemaRegistry.retrieveSchema(argThat(new SchemaIdentifierMatcher(expectedSchemaIdentifier))))
            .thenReturn(recordSchema);

    final RecordSchema retrievedSchema = schemaNamePropertyStrategy.getSchema(Collections.emptyMap(), null, recordSchema);
    assertNotNull(retrievedSchema);
}
 
Example #8
Source File: TestSFTPTransfer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnsureDirectoryExistsBlindlyAlreadyExisted() throws IOException, SFTPException {
    final ProcessContext processContext = mock(ProcessContext.class);
    when(processContext.getProperty(SFTPTransfer.DISABLE_DIRECTORY_LISTING)).thenReturn(new MockPropertyValue("true"));

    final SFTPClient sftpClient = mock(SFTPClient.class);
    // If the dir existed, a failure exception is thrown, but should be swallowed.
    doThrow(new SFTPException(Response.StatusCode.FAILURE, "Failure")).when(sftpClient).mkdir(eq("/dir1/dir2/dir3"));

    final SFTPTransfer sftpTransfer = createSftpTransfer(processContext, sftpClient);
    final MockFlowFile flowFile = new MockFlowFile(0);
    final File remoteDir = new File("/dir1/dir2/dir3");
    sftpTransfer.ensureDirectoryExists(flowFile, remoteDir);

    // stat should not be called.
    verify(sftpClient, times(0)).stat(eq("/dir1/dir2/dir3"));
    verify(sftpClient).mkdir(eq("/dir1/dir2/dir3")); // dir3 was created blindly.
}
 
Example #9
Source File: TestSFTPTransfer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testEnsureDirectoryExistsBlindlyFailed() throws IOException, SFTPException {
    final ProcessContext processContext = mock(ProcessContext.class);
    when(processContext.getProperty(SFTPTransfer.DISABLE_DIRECTORY_LISTING)).thenReturn(new MockPropertyValue("true"));

    final SFTPClient sftpClient = mock(SFTPClient.class);
    doThrow(new SFTPException(Response.StatusCode.PERMISSION_DENIED, "Permission denied")).when(sftpClient).mkdir(eq("/dir1/dir2/dir3"));

    final SFTPTransfer sftpTransfer = createSftpTransfer(processContext, sftpClient);
    final MockFlowFile flowFile = new MockFlowFile(0);
    final File remoteDir = new File("/dir1/dir2/dir3");
    try {
        sftpTransfer.ensureDirectoryExists(flowFile, remoteDir);
        fail("Should fail");
    } catch (IOException e) {
        assertEquals("Could not blindly create remote directory due to Permission denied", e.getMessage());
    }

    // stat should not be called.
    verify(sftpClient, times(0)).stat(eq("/dir1/dir2/dir3"));
    verify(sftpClient).mkdir(eq("/dir1/dir2/dir3")); // dir3 was created blindly.
}
 
Example #10
Source File: TestRangerNiFiAuthorizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutKeytabOrPrincipal() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("");
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #11
Source File: TestRangerNiFiAuthorizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutPrincipal() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #12
Source File: TestRangerNiFiAuthorizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutKeytab() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #13
Source File: TestRangerNiFiAuthorizer.java    From nifi with Apache License 2.0 6 votes vote down vote up
private AuthorizerConfigurationContext createMockConfigContext() {
    AuthorizerConfigurationContext configurationContext = Mockito.mock(AuthorizerConfigurationContext.class);

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SECURITY_PATH_PROP)))
            .thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-security.xml"));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_AUDIT_PATH_PROP)))
            .thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-audit.xml"));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_APP_ID_PROP)))
            .thenReturn(new MockPropertyValue(appId));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SERVICE_TYPE_PROP)))
            .thenReturn(new MockPropertyValue(serviceType));

    return configurationContext;
}
 
Example #14
Source File: ManagedRangerAuthorizerTest.java    From nifi with Apache License 2.0 6 votes vote down vote up
private ManagedRangerAuthorizer getStandardManagedAuthorizer(final UserGroupProvider userGroupProvider) {
    final ManagedRangerAuthorizer managedAuthorizer = new ManagedRangerAuthorizer();

    final AuthorizerConfigurationContext configurationContext = mock(AuthorizerConfigurationContext.class);
    when(configurationContext.getProperty(eq("User Group Provider"))).thenReturn(new MockPropertyValue("user-group-provider", null));
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SECURITY_PATH_PROP))).thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-security.xml"));
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_AUDIT_PATH_PROP))).thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-audit.xml"));
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_APP_ID_PROP))).thenReturn(new MockPropertyValue(appId));
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SERVICE_TYPE_PROP))).thenReturn(new MockPropertyValue(serviceType));

    final UserGroupProviderLookup userGroupProviderLookup = mock(UserGroupProviderLookup.class);
    when(userGroupProviderLookup.getUserGroupProvider("user-group-provider")).thenReturn(userGroupProvider);

    final AuthorizerInitializationContext initializationContext = mock(AuthorizerInitializationContext.class);
    when(initializationContext.getUserGroupProviderLookup()).thenReturn(userGroupProviderLookup);

    managedAuthorizer.initialize(initializationContext);
    managedAuthorizer.onConfigured(configurationContext);

    return managedAuthorizer;
}
 
Example #15
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws IOException {
    authContext = Mockito.mock(AuthorizerConfigurationContext.class);
    initContext = Mockito.mock(UserGroupProviderInitializationContext.class);

    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.REFRESH_DELAY_PROPERTY))).thenReturn(new MockPropertyValue("10 sec"));
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.EXCLUDE_GROUP_PROPERTY))).thenReturn(new MockPropertyValue(".*d$"));
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.EXCLUDE_USER_PROPERTY))).thenReturn(new MockPropertyValue("^s.*"));

    localProvider = new ShellUserGroupProvider();
    try {
        localProvider.initialize(initContext);
        localProvider.onConfigured(authContext);
    } catch (final Exception exc) {
        systemCheckFailed = true;
        logger.error("setup() exception: " + exc + "; tests cannot run on this system.");
        return;
    }
    Assert.assertEquals(10000, localProvider.getRefreshDelay());
}
 
Example #16
Source File: TestDataDogReportingTask.java    From nifi with Apache License 2.0 6 votes vote down vote up
private void initContexts() {
    configurationContext = Mockito.mock(ConfigurationContext.class);
    context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getProperty(DataDogReportingTask.ENVIRONMENT))
            .thenReturn(new MockPropertyValue(env, null));
    Mockito.when(context.getProperty(DataDogReportingTask.METRICS_PREFIX))
            .thenReturn(new MockPropertyValue(prefix, null));
    Mockito.when(context.getProperty(DataDogReportingTask.API_KEY))
            .thenReturn(new MockPropertyValue("agent", null));
    Mockito.when(context.getProperty(DataDogReportingTask.DATADOG_TRANSPORT))
            .thenReturn(new MockPropertyValue("DataDog Agent", null));
    EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(status);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);

    logger = Mockito.mock(Logger.class);
    initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    //Mockito.when(initContext.getLogger()).thenReturn(logger);
    metricsMap = new ConcurrentHashMap<>();
    metricRegistry = Mockito.mock(MetricRegistry.class);
    virtualMachineMetrics = JmxJvmMetrics.getInstance();
    metricsService = Mockito.mock(MetricsService.class);

}
 
Example #17
Source File: TestDataDogReportingTask.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void initContexts() {
    configurationContext = Mockito.mock(ConfigurationContext.class);
    context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getProperty(DataDogReportingTask.ENVIRONMENT))
            .thenReturn(new MockPropertyValue(env, null));
    Mockito.when(context.getProperty(DataDogReportingTask.METRICS_PREFIX))
            .thenReturn(new MockPropertyValue(prefix, null));
    Mockito.when(context.getProperty(DataDogReportingTask.API_KEY))
            .thenReturn(new MockPropertyValue("agent", null));
    Mockito.when(context.getProperty(DataDogReportingTask.DATADOG_TRANSPORT))
            .thenReturn(new MockPropertyValue("DataDog Agent", null));
    EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(status);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);

    logger = Mockito.mock(Logger.class);
    initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    //Mockito.when(initContext.getLogger()).thenReturn(logger);
    metricsMap = new ConcurrentHashMap<>();
    metricRegistry = Mockito.mock(MetricRegistry.class);
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    metricsService = Mockito.mock(MetricsService.class);

}
 
Example #18
Source File: TestRangerNiFiAuthorizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutPrincipal() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #19
Source File: TestRangerNiFiAuthorizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testKerberosEnabledWithoutKeytabOrPrincipal() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP)))
            .thenReturn(new MockPropertyValue("true"));

    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("");
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("");

    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);

    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // want to make sure this exception is from our authorizer code
        verifyOnlyAuthorizeCreationExceptions(e);
    }
}
 
Example #20
Source File: TestRangerNiFiAuthorizer.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private AuthorizerConfigurationContext createMockConfigContext() {
    AuthorizerConfigurationContext configurationContext = Mockito.mock(AuthorizerConfigurationContext.class);

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SECURITY_PATH_PROP)))
            .thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-security.xml"));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_AUDIT_PATH_PROP)))
            .thenReturn(new MockPropertyValue("src/test/resources/ranger/ranger-nifi-audit.xml"));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_APP_ID_PROP)))
            .thenReturn(new MockPropertyValue(appId));

    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_SERVICE_TYPE_PROP)))
            .thenReturn(new MockPropertyValue(serviceType));

    return configurationContext;
}
 
Example #21
Source File: TestReportLineageToAtlas.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void testConnectAndReadTimeout(Map<PropertyDescriptor, String> properties, Integer expectedConnectTimeout, Integer expectedReadTimeout) throws Exception {
    // GIVEN
    reportingContext = mock(ReportingContext.class);
    when(reportingContext.getProperties()).thenReturn(properties);
    when(reportingContext.getProperty(any())).then(invocation -> new MockPropertyValue(properties.get(invocation.getArguments()[0])));

    ConfigurationContext configurationContext = new MockConfigurationContext(properties, null);

    testSubject.initialize(initializationContext);
    testSubject.setup(configurationContext);

    // WHEN
    NiFiAtlasClient niFiAtlasClient = testSubject.createNiFiAtlasClient(reportingContext);

    // THEN
    Field fieldAtlasClient = niFiAtlasClient.getClass().getDeclaredField("atlasClient");
    fieldAtlasClient.setAccessible(true);
    AtlasClientV2 atlasClient = (AtlasClientV2) fieldAtlasClient.get(niFiAtlasClient);

    Field fieldAtlasClientContext = atlasClient.getClass().getSuperclass().getDeclaredField("atlasClientContext");
    fieldAtlasClientContext.setAccessible(true);
    Object atlasClientContext = fieldAtlasClientContext.get(atlasClient);

    Method getClient = atlasClientContext.getClass().getMethod("getClient");
    getClient.setAccessible(true);
    Client jerseyClient = (Client) getClient.invoke(atlasClientContext);
    Map<String, Object> jerseyProperties = jerseyClient.getProperties();

    Integer actualConnectTimeout = (Integer) jerseyProperties.get("com.sun.jersey.client.property.connectTimeout");
    Integer actualReadTimeout = (Integer) jerseyProperties.get("com.sun.jersey.client.property.readTimeout");

    assertEquals(expectedConnectTimeout, actualConnectTimeout);
    assertEquals(expectedReadTimeout, actualReadTimeout);
}
 
Example #22
Source File: TestStandardS3EncryptionService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws InitializationException {
    service = new StandardS3EncryptionService();
    context = Mockito.mock(ConfigurationContext.class);

    strategyName = AmazonS3EncryptionService.STRATEGY_NAME_NONE;
    keyIdOrMaterial = "test-key-id";
    kmsRegion = "us-west-1";

    Mockito.when(context.getProperty(StandardS3EncryptionService.ENCRYPTION_STRATEGY)).thenReturn(new MockPropertyValue(strategyName));
    Mockito.when(context.getProperty(StandardS3EncryptionService.ENCRYPTION_VALUE)).thenReturn(new MockPropertyValue(keyIdOrMaterial));
    Mockito.when(context.getProperty(StandardS3EncryptionService.KMS_REGION)).thenReturn(new MockPropertyValue(kmsRegion));
    service.onConfigured(context);
}
 
Example #23
Source File: ITNiFiAtlasClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    // Add your atlas server ip address into /etc/hosts as atlas.example.com
    PropertyContext propertyContext = mock(PropertyContext.class);
    when(propertyContext.getProperty(ReportLineageToAtlas.ATLAS_USER)).thenReturn(new MockPropertyValue("admin"));
    when(propertyContext.getProperty(ReportLineageToAtlas.ATLAS_PASSWORD)).thenReturn(new MockPropertyValue("admin"));
    final AtlasAuthN atlasAuthN = new Basic();
    atlasAuthN.configure(propertyContext);

    atlasClient = new NiFiAtlasClient(atlasAuthN.createClient(new String[]{"http://atlas.example.com:21000/"}));
}
 
Example #24
Source File: TestSFTPTransfer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnsureDirectoryExistsBlindlyNotExisted() throws IOException, SFTPException {
    final ProcessContext processContext = mock(ProcessContext.class);
    when(processContext.getProperty(SFTPTransfer.DISABLE_DIRECTORY_LISTING)).thenReturn(new MockPropertyValue("true"));

    final SFTPClient sftpClient = mock(SFTPClient.class);
    final SFTPTransfer sftpTransfer = createSftpTransfer(processContext, sftpClient);
    final MockFlowFile flowFile = new MockFlowFile(0);
    final File remoteDir = new File("/dir1/dir2/dir3");
    sftpTransfer.ensureDirectoryExists(flowFile, remoteDir);

    // stat should not be called.
    verify(sftpClient, times(0)).stat(eq("/dir1/dir2/dir3"));
    verify(sftpClient).mkdir(eq("/dir1/dir2/dir3")); // dir3 was created blindly.
}
 
Example #25
Source File: TestSFTPTransfer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testEnsureDirectoryExistsBlindlyParentNotExisted() throws IOException, SFTPException {
    final ProcessContext processContext = mock(ProcessContext.class);
    when(processContext.getProperty(SFTPTransfer.DISABLE_DIRECTORY_LISTING)).thenReturn(new MockPropertyValue("true"));

    final SFTPClient sftpClient = mock(SFTPClient.class);
    final AtomicInteger mkdirCount = new AtomicInteger(0);
    doAnswer(invocation -> {
        final int cnt = mkdirCount.getAndIncrement();
        if (cnt == 0) {
            // If the parent dir does not exist, no such file exception is thrown.
            throw new SFTPException(Response.StatusCode.NO_SUCH_FILE, "Failure");
        } else {
            logger.info("Created the dir successfully for the 2nd time");
        }
        return true;
    }).when(sftpClient).mkdir(eq("/dir1/dir2/dir3"));

    final SFTPTransfer sftpTransfer = createSftpTransfer(processContext, sftpClient);
    final MockFlowFile flowFile = new MockFlowFile(0);
    final File remoteDir = new File("/dir1/dir2/dir3");
    sftpTransfer.ensureDirectoryExists(flowFile, remoteDir);

    // stat should not be called.
    verify(sftpClient, times(0)).stat(eq("/dir1/dir2/dir3"));
    // dir3 was created blindly, but failed for the 1st time, and succeeded for the 2nd time.
    verify(sftpClient, times(2)).mkdir(eq("/dir1/dir2/dir3"));
    verify(sftpClient).mkdir(eq("/dir1/dir2")); // dir2 was created successfully.
}
 
Example #26
Source File: ITPutS3Object.java    From nifi with Apache License 2.0 5 votes vote down vote up
private static TestRunner createEncryptionTestRunner(Processor processor, String strategyName, String keyIdOrMaterial) throws InitializationException {
    final TestRunner runner = TestRunners.newTestRunner(processor);
    final ConfigurationContext context = mock(ConfigurationContext.class);

    runner.setProperty(PutS3Object.CREDENTIALS_FILE, CREDENTIALS_FILE);
    runner.setProperty(PutS3Object.REGION, REGION);
    runner.setProperty(PutS3Object.BUCKET, BUCKET_NAME);

    if (strategyName != null) {
        final StandardS3EncryptionService service = new StandardS3EncryptionService();
        runner.addControllerService(PutS3Object.ENCRYPTION_SERVICE.getName(), service);
        runner.setProperty(PutS3Object.ENCRYPTION_SERVICE, service.getIdentifier());

        runner.setProperty(service, StandardS3EncryptionService.ENCRYPTION_STRATEGY, strategyName);
        runner.setProperty(service, StandardS3EncryptionService.ENCRYPTION_VALUE, keyIdOrMaterial);
        runner.setProperty(service, StandardS3EncryptionService.KMS_REGION, REGION);

        when(context.getProperty(StandardS3EncryptionService.ENCRYPTION_STRATEGY)).thenReturn(new MockPropertyValue(strategyName));
        when(context.getProperty(StandardS3EncryptionService.ENCRYPTION_VALUE)).thenReturn(new MockPropertyValue(keyIdOrMaterial));
        when(context.getProperty(StandardS3EncryptionService.KMS_REGION)).thenReturn(new MockPropertyValue(REGION));

        service.onConfigured(context);
        runner.enableControllerService(service);
    }

    return runner;
}
 
Example #27
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidDelayIntervalThrowsException() throws AuthorizerCreationException {
    final AuthorizerConfigurationContext authContext = Mockito.mock(AuthorizerConfigurationContext.class);
    final ShellUserGroupProvider localProvider = new ShellUserGroupProvider();
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.REFRESH_DELAY_PROPERTY))).thenReturn(new MockPropertyValue("Not an interval"));

    expectedException.expect(AuthorizerCreationException.class);
    expectedException.expectMessage("The Refresh Delay 'Not an interval' is not a valid time interval.");

    localProvider.onConfigured(authContext);
}
 
Example #28
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testMissingExcludeExpressionsAllowed() throws AuthorizerCreationException {
    AuthorizerConfigurationContext authContext = Mockito.mock(AuthorizerConfigurationContext.class);
    ShellUserGroupProvider localProvider = new ShellUserGroupProvider();
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.REFRESH_DELAY_PROPERTY))).thenReturn(new MockPropertyValue("3 minutes"));

    localProvider.onConfigured(authContext);
    verifyUsersAndUsersMinimumCount(localProvider);
}
 
Example #29
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidUserExcludeExpressionsThrowsException() throws AuthorizerCreationException {
    AuthorizerConfigurationContext authContext = Mockito.mock(AuthorizerConfigurationContext.class);
    ShellUserGroupProvider localProvider = new ShellUserGroupProvider();
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.REFRESH_DELAY_PROPERTY))).thenReturn(new MockPropertyValue("3 minutes"));
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.EXCLUDE_USER_PROPERTY))).thenReturn(new MockPropertyValue("*"));

    expectedException.expect(AuthorizerCreationException.class);
    expectedException.expectMessage("Dangling meta character");
    localProvider.onConfigured(authContext);
}
 
Example #30
Source File: ShellUserGroupProviderIT.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidGroupExcludeExpressionsThrowsException() throws AuthorizerCreationException {
    AuthorizerConfigurationContext authContext = Mockito.mock(AuthorizerConfigurationContext.class);
    ShellUserGroupProvider localProvider = new ShellUserGroupProvider();
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.REFRESH_DELAY_PROPERTY))).thenReturn(new MockPropertyValue("3 minutes"));
    Mockito.when(authContext.getProperty(Mockito.eq(ShellUserGroupProvider.EXCLUDE_GROUP_PROPERTY))).thenReturn(new MockPropertyValue("(3"));

    expectedException.expect(AuthorizerCreationException.class);
    expectedException.expectMessage("Unclosed group near index");
    localProvider.onConfigured(authContext);


}