Search in sources :

Example 1 with MockProvenanceRepository

use of org.apache.nifi.provenance.MockProvenanceRepository in project nifi by apache.

the class TestStandardProcessSession method setup.

@Before
public void setup() throws IOException {
    resourceClaimManager = new StandardResourceClaimManager();
    System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, TestStandardProcessSession.class.getResource("/conf/nifi.properties").getFile());
    final FlowFileEventRepository flowFileEventRepo = Mockito.mock(FlowFileEventRepository.class);
    final CounterRepository counterRepo = Mockito.mock(CounterRepository.class);
    provenanceRepo = new MockProvenanceRepository();
    final Connection connection = createConnection();
    final List<Connection> connList = new ArrayList<>();
    connList.add(connection);
    final ProcessGroup procGroup = Mockito.mock(ProcessGroup.class);
    when(procGroup.getIdentifier()).thenReturn("proc-group-identifier-1");
    connectable = Mockito.mock(Connectable.class);
    when(connectable.hasIncomingConnection()).thenReturn(true);
    when(connectable.getIncomingConnections()).thenReturn(connList);
    when(connectable.getProcessGroup()).thenReturn(procGroup);
    when(connectable.getIdentifier()).thenReturn("connectable-1");
    when(connectable.getConnectableType()).thenReturn(ConnectableType.INPUT_PORT);
    when(connectable.getComponentType()).thenReturn("Unit Test Component");
    Mockito.doAnswer(new Answer<Set<Connection>>() {

        @Override
        public Set<Connection> answer(final InvocationOnMock invocation) throws Throwable {
            final Object[] arguments = invocation.getArguments();
            final Relationship relationship = (Relationship) arguments[0];
            if (relationship == Relationship.SELF) {
                return Collections.emptySet();
            } else if (relationship == FAKE_RELATIONSHIP || relationship.equals(FAKE_RELATIONSHIP)) {
                return null;
            } else {
                return new HashSet<>(connList);
            }
        }
    }).when(connectable).getConnections(Mockito.any(Relationship.class));
    when(connectable.getConnections()).thenReturn(new HashSet<>(connList));
    contentRepo = new MockContentRepository();
    contentRepo.initialize(new StandardResourceClaimManager());
    flowFileRepo = new MockFlowFileRepository();
    context = new RepositoryContext(connectable, new AtomicLong(0L), contentRepo, flowFileRepo, flowFileEventRepo, counterRepo, provenanceRepo);
    session = new StandardProcessSession(context, () -> false);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Connection(org.apache.nifi.connectable.Connection) ArrayList(java.util.ArrayList) AtomicLong(java.util.concurrent.atomic.AtomicLong) Connectable(org.apache.nifi.connectable.Connectable) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Relationship(org.apache.nifi.processor.Relationship) StandardResourceClaimManager(org.apache.nifi.controller.repository.claim.StandardResourceClaimManager) ProcessGroup(org.apache.nifi.groups.ProcessGroup) MockProvenanceRepository(org.apache.nifi.provenance.MockProvenanceRepository) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Connectable (org.apache.nifi.connectable.Connectable)1 Connection (org.apache.nifi.connectable.Connection)1 StandardResourceClaimManager (org.apache.nifi.controller.repository.claim.StandardResourceClaimManager)1 ProcessGroup (org.apache.nifi.groups.ProcessGroup)1 Relationship (org.apache.nifi.processor.Relationship)1 MockProvenanceRepository (org.apache.nifi.provenance.MockProvenanceRepository)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1