Search in sources :

Example 21 with MockPropertyValue

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

the class ITNiFiAtlasClient method setup.

@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/" }));
}
Also used : AtlasAuthN(org.apache.nifi.atlas.security.AtlasAuthN) Basic(org.apache.nifi.atlas.security.Basic) PropertyContext(org.apache.nifi.context.PropertyContext) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) Before(org.junit.Before)

Example 22 with MockPropertyValue

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

the class ITReportLineageToAtlas method test.

private void test(TestConfiguration tc) throws InitializationException, IOException {
    final ReportLineageToAtlas reportingTask = new ReportLineageToAtlas();
    final MockComponentLog logger = new MockComponentLog("reporting-task-id", reportingTask);
    final ReportingInitializationContext initializationContext = mock(ReportingInitializationContext.class);
    when(initializationContext.getLogger()).thenReturn(logger);
    final ConfigurationContext configurationContext = new MockConfigurationContext(tc.properties, null);
    final ValidationContext validationContext = mock(ValidationContext.class);
    when(validationContext.getProperty(any())).then(invocation -> new MockPropertyValue(tc.properties.get(invocation.getArguments()[0])));
    final ReportingContext reportingContext = mock(ReportingContext.class);
    final MockStateManager stateManager = new MockStateManager(reportingTask);
    final EventAccess eventAccess = mock(EventAccess.class);
    when(reportingContext.getProperties()).thenReturn(tc.properties);
    when(reportingContext.getProperty(any())).then(invocation -> new MockPropertyValue(tc.properties.get(invocation.getArguments()[0])));
    when(reportingContext.getStateManager()).thenReturn(stateManager);
    when(reportingContext.getEventAccess()).thenReturn(eventAccess);
    when(eventAccess.getGroupStatus(eq("root"))).thenReturn(tc.rootPgStatus);
    final ProvenanceRepository provenanceRepository = mock(ProvenanceRepository.class);
    when(eventAccess.getControllerStatus()).thenReturn(tc.rootPgStatus);
    when(eventAccess.getProvenanceRepository()).thenReturn(provenanceRepository);
    when(eventAccess.getProvenanceEvents(eq(-1L), anyInt())).thenReturn(tc.provenanceRecords);
    when(provenanceRepository.getMaxEventId()).thenReturn((long) tc.provenanceRecords.size() - 1);
    when(provenanceRepository.getEvent(anyLong())).then(invocation -> tc.provenanceRecords.get(((Long) invocation.getArguments()[0]).intValue()));
    // To mock this async method invocations, keep the requested event ids in a stack.
    final ComputeLineageSubmission lineageComputationSubmission = mock(ComputeLineageSubmission.class);
    when(provenanceRepository.submitLineageComputation(anyLong(), any())).thenAnswer(invocation -> {
        requestedLineageComputationIds.push((Long) invocation.getArguments()[0]);
        return lineageComputationSubmission;
    });
    when(lineageComputationSubmission.getResult()).then(invocation -> tc.lineageResults.get(requestedLineageComputationIds.pop()));
    final ComputeLineageSubmission expandParentsSubmission = mock(ComputeLineageSubmission.class);
    when(provenanceRepository.submitExpandParents(anyLong(), any())).thenAnswer(invocation -> {
        requestedExpandParentsIds.push(((Long) invocation.getArguments()[0]));
        return expandParentsSubmission;
    });
    when(expandParentsSubmission.getResult()).then(invocation -> tc.parentLineageResults.get(requestedExpandParentsIds.pop()));
    tc.properties.put(ATLAS_NIFI_URL, "http://localhost:8080/nifi");
    tc.properties.put(ATLAS_URLS, TARGET_ATLAS_URL);
    tc.properties.put(ATLAS_USER, "admin");
    tc.properties.put(ATLAS_PASSWORD, "admin");
    tc.properties.put(new PropertyDescriptor.Builder().name("hostnamePattern.example").dynamic(true).build(), ".*");
    reportingTask.initialize(initializationContext);
    reportingTask.validate(validationContext);
    reportingTask.setup(configurationContext);
    reportingTask.onTrigger(reportingContext);
    reportingTask.onUnscheduled();
    reportingTask.onStopped();
}
Also used : EventAccess(org.apache.nifi.reporting.EventAccess) ConfigurationContext(org.apache.nifi.controller.ConfigurationContext) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) MockComponentLog(org.apache.nifi.util.MockComponentLog) ComputeLineageSubmission(org.apache.nifi.provenance.lineage.ComputeLineageSubmission) MockPropertyValue(org.apache.nifi.util.MockPropertyValue) ValidationContext(org.apache.nifi.components.ValidationContext) ReportingContext(org.apache.nifi.reporting.ReportingContext) ReportingInitializationContext(org.apache.nifi.reporting.ReportingInitializationContext) MockConfigurationContext(org.apache.nifi.util.MockConfigurationContext) MockStateManager(org.apache.nifi.state.MockStateManager) Matchers.anyLong(org.mockito.Matchers.anyLong) ProvenanceRepository(org.apache.nifi.provenance.ProvenanceRepository)

Example 23 with MockPropertyValue

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

the class ControllerServiceTestContext method setCustomValue.

public MockPropertyValue setCustomValue(PropertyDescriptor propertyDescriptor, String value) {
    final MockPropertyValue propertyValue = new MockPropertyValue(value, initializationContext);
    when(configurationContext.getProperty(eq(propertyDescriptor))).thenReturn(propertyValue);
    return propertyValue;
}
Also used : MockPropertyValue(org.apache.nifi.util.MockPropertyValue)

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