Search in sources :

Example 16 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestSiteToSiteStatusReportingTask method initTask.

public MockSiteToSiteStatusReportingTask initTask(Map<PropertyDescriptor, String> customProperties, ProcessGroupStatus pgStatus) throws InitializationException {
    final MockSiteToSiteStatusReportingTask task = new MockSiteToSiteStatusReportingTask();
    Map<PropertyDescriptor, String> properties = new HashMap<>();
    for (final PropertyDescriptor descriptor : task.getSupportedPropertyDescriptors()) {
        properties.put(descriptor, descriptor.getDefaultValue());
    }
    properties.putAll(customProperties);
    context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getStateManager()).thenReturn(new MockStateManager(task));
    Mockito.doAnswer(new Answer<PropertyValue>() {

        @Override
        public PropertyValue answer(final InvocationOnMock invocation) throws Throwable {
            final PropertyDescriptor descriptor = invocation.getArgumentAt(0, PropertyDescriptor.class);
            return new MockPropertyValue(properties.get(descriptor));
        }
    }).when(context).getProperty(Mockito.any(PropertyDescriptor.class));
    final EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(pgStatus);
    final ComponentLog logger = Mockito.mock(ComponentLog.class);
    final ReportingInitializationContext initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    Mockito.when(initContext.getLogger()).thenReturn(logger);
    task.initialize(initContext);
    return task;
}
Also used : PropertyDescriptor(org.apache.nifi.components.PropertyDescriptor) HashMap(java.util.HashMap) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) PropertyValue(org.apache.nifi.components.PropertyValue) JsonString(javax.json.JsonString) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) ComponentLog(org.apache.nifi.logging.ComponentLog) MockStateManager(org.apache.nifi.state.MockStateManager) InvocationOnMock(org.mockito.invocation.InvocationOnMock)

Example 17 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class ManagedRangerAuthorizerTest method getStandardManagedAuthorizer.

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;
}
Also used : UserGroupProviderLookup(org.apache.nifi.authorization.UserGroupProviderLookup) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) AuthorizerInitializationContext(org.apache.nifi.authorization.AuthorizerInitializationContext) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext)

Example 18 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestRangerNiFiAuthorizer method createMockConfigContext.

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;
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue) AuthorizerConfigurationContext(org.apache.nifi.authorization.AuthorizerConfigurationContext)

Example 19 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestRangerNiFiAuthorizer method testKerberosEnabledWithoutPrincipal.

@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);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Test(org.junit.Test)

Example 20 with MockPropertyValue

use of org.apache.nifi.util.MockPropertyValue in project nifi by apache.

the class TestRangerNiFiAuthorizer method testKerberosEnabled.

@Test
public void testKerberosEnabled() {
    when(configurationContext.getProperty(eq(RangerNiFiAuthorizer.RANGER_KERBEROS_ENABLED_PROP))).thenReturn(new MockPropertyValue("true"));
    nifiProperties = Mockito.mock(NiFiProperties.class);
    when(nifiProperties.getKerberosServiceKeytabLocation()).thenReturn("test");
    when(nifiProperties.getKerberosServicePrincipal()).thenReturn("test");
    authorizer = new MockRangerNiFiAuthorizer(rangerBasePlugin);
    authorizer.setNiFiProperties(nifiProperties);
    try {
        authorizer.onConfigured(configurationContext);
        Assert.fail("Should have thrown exception");
    } catch (AuthorizerCreationException e) {
        // getting a LoginException here means we attempted to login which is what we want
        boolean foundLoginException = false;
        Throwable cause = e.getCause();
        while (cause != null) {
            if (cause instanceof LoginException) {
                foundLoginException = true;
                break;
            }
            cause = cause.getCause();
        }
        assertTrue(foundLoginException);
    }
}
Also used : NiFiProperties(org.apache.nifi.util.NiFiProperties) AuthorizerCreationException(org.apache.nifi.authorization.exception.AuthorizerCreationException) LoginException(javax.security.auth.login.LoginException) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Test(org.junit.Test)

Aggregations

MockPropertyValue (org.apache.nifi.util.MockPropertyValue)23 Test (org.junit.Test)14 PropertyValue (org.apache.nifi.components.PropertyValue)10 HashMap (java.util.HashMap)5 ComponentLog (org.apache.nifi.logging.ComponentLog)5 RecordSchema (org.apache.nifi.serialization.record.RecordSchema)5 MockStateManager (org.apache.nifi.state.MockStateManager)5 AuthorizerCreationException (org.apache.nifi.authorization.exception.AuthorizerCreationException)4 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4 SchemaIdentifier (org.apache.nifi.serialization.record.SchemaIdentifier)4 NiFiProperties (org.apache.nifi.util.NiFiProperties)4 InvocationOnMock (org.mockito.invocation.InvocationOnMock)4 ArrayList (java.util.ArrayList)3 AuthorizerConfigurationContext (org.apache.nifi.authorization.AuthorizerConfigurationContext)3 ConfigurationContext (org.apache.nifi.controller.ConfigurationContext)3 EventAccess (org.apache.nifi.reporting.EventAccess)3 ReportingContext (org.apache.nifi.reporting.ReportingContext)3 ReportingInitializationContext (org.apache.nifi.reporting.ReportingInitializationContext)3 StandardPropertyValue (org.apache.nifi.attribute.expression.language.StandardPropertyValue)2 AuthorizationRequest (org.apache.nifi.authorization.AuthorizationRequest)2