Class StandardProcessorTestRunner

java.lang.Object
org.apache.nifi.util.StandardProcessorTestRunner
All Implemented Interfaces:
TestRunner

public class StandardProcessorTestRunner extends Object implements TestRunner
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private boolean
     
    private boolean
     
    private final MockProcessContext
     
    private final Map<String,String>
     
    private final Map<String,MockComponentLog>
     
    private final Map<String,MockStateManager>
     
    private boolean
     
    private final Map<String,String>
     
    private final MockFlowFileQueue
     
    private final AtomicLong
     
    private final AtomicInteger
     
    private final org.apache.nifi.kerberos.KerberosContext
     
    private final MockComponentLog
     
    private int
     
    private final org.apache.nifi.processor.Processor
     
    private final MockStateManager
     
    private long
     
     
    private final SharedSessionState
     
    private final boolean
     
    private boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor)
     
    StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName)
     
    StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, org.apache.nifi.kerberos.KerberosContext kerberosContext)
     
    StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, MockComponentLog logger)
     
    StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, MockComponentLog logger, org.apache.nifi.kerberos.KerberosContext kerberosContext)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addConnection(String relationshipName)
    Indicates to the Framework that the configured processor has a connection for the Relationship with the given name.
    void
    addConnection(org.apache.nifi.processor.Relationship relationship)
    Indicates to the Framework that the configured processor has a connection for the given Relationship.
    void
    addControllerService(String identifier, org.apache.nifi.controller.ControllerService service)
    Adds the given ControllerService to this TestRunner so that the configured Processor can access it using the given identifier.
    void
    addControllerService(String identifier, org.apache.nifi.controller.ControllerService service, Map<String,String> properties)
    Adds the given ControllerService to this TestRunner so that the configured Processor can access it using the given identifier.
    void
    assertAllConditionsMet(String relationshipName, Predicate<MockFlowFile> predicate)
    Asserts that all FlowFiles meet all conditions.
    void
    assertAllConditionsMet(org.apache.nifi.processor.Relationship relationship, Predicate<MockFlowFile> predicate)
    Asserts that all FlowFiles meet all conditions.
    void
    assertAllFlowFiles(org.apache.nifi.processor.Relationship relationship, FlowFileValidator validator)
    Asserts that all FlowFiles that were transferred in the given relationship are compliant with the given validator.
    void
    Asserts that all FlowFiles that were transferred are compliant with the given validator.
    void
    Asserts that all FlowFiles that were transferred contain the given attribute.
    void
    assertAllFlowFilesContainAttribute(org.apache.nifi.processor.Relationship relationship, String attributeName)
    Asserts that all FlowFiles that were transferred to the given relationship contain the given attribute.
    void
    Asserts that all FlowFiles that were transferred were transferred to the given relationship
    void
    assertAllFlowFilesTransferred(String relationship, int count)
    Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal to count
    void
    assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship)
    Asserts that all FlowFiles that were transferred were transferred to the given relationship
    void
    assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship, int count)
    Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal to count
    void
    assertAttributes(org.apache.nifi.processor.Relationship relationship, Set<String> checkedAttributeNames, Set<Map<String,String>> expectedAttributes)
    Asserts that flowfiles on a given relationship have a certain set of attributes.
    void
    assertContents(org.apache.nifi.processor.Relationship relationship, List<String> expectedContent)
    Asserts that flowfiles on a given relationship have certain contents.
    void
    Assert that the currently configured set of properties/annotation data are NOT valid
    void
    assertNotValid(org.apache.nifi.controller.ControllerService service)
    Assert that the currently configured set of properties/annotation data are NOT valid for the given Controller Service.
    void
    Assert that the number of FlowFiles that were penalized is equal to the given count
    void
    assertProvenanceEvent(org.apache.nifi.provenance.ProvenanceEventType eventType)
    Assert that provenance event was created with the specified event type.
    void
    Assert that there are no FlowFiles left on the input queue.
    void
    Assert that there is at least one FlowFile left on the input queue.
    void
    assertTransferCount(String relationship, int count)
    Assert that the number of FlowFiles transferred to the given relationship is equal to the given count
    void
    assertTransferCount(org.apache.nifi.processor.Relationship relationship, int count)
    Assert that the number of FlowFiles transferred to the given relationship is equal to the given count
    void
    Assert that the currently configured set of properties/annotation data are valid
    void
    assertValid(org.apache.nifi.controller.ControllerService service)
    Assert that the currently configured set of properties/annotation data are valid for the given Controller Service.
    void
    Clears all set properties from the ProcessContext.
    void
    Clears the Provenance Events that have been emitted by the Processor
    void
    Allow for clearing the queue from all remaining flow files.
    void
    Resets the Transfer Counts that indicate how many FlowFiles have been transferred to each Relationship and removes from memory any FlowFiles that have been transferred to this Relationships.
    void
    disableControllerService(org.apache.nifi.controller.ControllerService service)
    Marks the Controller Service as disabled so that it cannot be used by other components.
    void
    enableControllerService(org.apache.nifi.controller.ControllerService service)
    Marks the Controller Service as enabled so that it can be used by other components.
    void
    enforceReadStreamsClosed(boolean enforce)
    By default, if ProcessSession.read(FlowFile) is called, the InputStream that is returned MUST be closed by the processor under test or calls to ProcessSession.commit() will throw an Exception.
    enqueue(byte[] data)
    Copies the content from the given byte array into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
    enqueue(byte[] data, Map<String,String> attributes)
    Copies the content from the given byte array into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
    Reads the content from the given InputStream into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
    enqueue(InputStream data, Map<String,String> attributes)
    Reads the content from the given InputStream into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
    Creates a FlowFile with the content set to the given string (in UTF-8 format), with no attributes, and adds this FlowFile to the Processor's Input Queue
    enqueue(String data, Map<String,String> attributes)
    Creates a FlowFile with the content set to the given string (in UTF-8 format), with the given attributes, and adds this FlowFile to the Processor's Input Queue
    enqueue(Path path)
    Reads the content from the given Path into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
    enqueue(Path path, Map<String,String> attributes)
    Reads the content from the given Path into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
    void
    enqueue(org.apache.nifi.flowfile.FlowFile... flowFiles)
    Enqueues the given FlowFiles into the Processor's input queue
    getConfigToUpdate(org.apache.nifi.controller.ControllerService service)
     
    byte[]
    Copies the contents of the given MockFlowFile into a byte array and returns that byte array.
    org.apache.nifi.controller.ControllerService
     
    <T extends org.apache.nifi.controller.ControllerService>
    T
    getControllerService(String identifier, Class<T> serviceType)
     
    Returns the MockComponentLog that is used by the specified controller service.
     
    Returns the current value of the variable with the given name
    Returns a List of FlowFiles in the order in which they were transferred to the given relationship
    getFlowFilesForRelationship(org.apache.nifi.processor.Relationship relationship)
    Returns a List of FlowFiles in the order in which they were transferred to the given relationship
    Returns the MockComponentLog that is used by the Processor under test.
    Returns the current value for the given parameter name from the simulated Parameter Context
    Returns a List of FlowFiles in the order in which they were transferred that were penalized
     
    org.apache.nifi.processor.Processor
     
    org.apache.nifi.processor.ProcessSessionFactory
     
    List<org.apache.nifi.provenance.ProvenanceEventRecord>
    Returns a List of all ProvenanceEventRecords that were emitted by the Processor
    org.apache.nifi.controller.queue.QueueSize
     
    int
     
     
    getStateManager(org.apache.nifi.controller.ControllerService controllerService)
    Returns the State Manager for the given Controller Service.
    int
     
    boolean
    isControllerServiceEnabled(org.apache.nifi.controller.ControllerService service)
     
    boolean
     
    boolean
     
    boolean
     
    Causes the TestRunner to call the Processor's Processor.migrateProperties(PropertyConfiguration) method.
    Causes the TestRunner to call the Processor's Processor.migrateRelationships(RelationshipConfiguration) method.
    void
    removeConnection(String relationshipName)
    Removes the connection for the relationship with the given name from the configured processor.
    void
    removeConnection(org.apache.nifi.processor.Relationship relationship)
    Removes the connection for the given Relationship from the configured processor.
    void
    removeControllerService(org.apache.nifi.controller.ControllerService service)
    Removes the Controller Service from the TestRunner.
    boolean
    Removes the property from the ProcessContext, effectively setting its value to null, or the property's default value, if it has one.
    boolean
    removeProperty(org.apache.nifi.components.PropertyDescriptor descriptor)
    Removes the PropertyDescriptor from the ProcessContext, effectively setting its value to null, or the property's default value, if it has one.
    boolean
    removeProperty(org.apache.nifi.controller.ControllerService service, String propertyName)
    Removes the PropertyDescriptor from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.
    boolean
    removeProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property)
    Removes the PropertyDescriptor from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.
    void
    run()
    Performs exactly the same operation as calling TestRunner.run(int) with a value of 1.
    void
    run(int iterations)
    Performs the same operation as calling TestRunner.run(int, boolean) with a value of true
    void
    run(int iterations, boolean stopOnFinish)
    performs the same operation as calling TestRunner.run(int, boolean, boolean) with a value of iterations, stopOnFinish, true
    void
    run(int iterations, boolean stopOnFinish, boolean initialize)
    This method runs the Processor iterations times, using the sequence of steps below: If initialize is true, run all methods on the Processor that are annotated with the @OnScheduled annotation.
    void
    run(int iterations, boolean stopOnFinish, boolean initialize, long runWait)
    This method runs the Processor iterations times, using the sequence of steps below: If initialize is true, run all methods on the Processor that are annotated with the @OnScheduled annotation.
    void
    setAllowRecursiveReads(boolean allowRecursiveReads)
    Specifies whether the TestRunner will allow ProcessSession.read() multiple times for the same FlowFile while an InputStream is already open.
    void
    setAllowSynchronousSessionCommits(boolean allowSynchronousSessionCommits)
    Specifies whether the TestRunner will allow ProcessSession.commit() to be called.
    void
    setAnnotationData(String annotationData)
    Sets the annotation data.
    void
    setAnnotationData(org.apache.nifi.controller.ControllerService service, String annotationData)
    Sets the annotation data of the given service to the provided annotation data.
    void
    setClustered(boolean clustered)
     
    void
    setConnected(boolean isConnected)
     
    void
    Sets the value of the variable with the given name to be the given value.
    void
    setIncomingConnection(boolean hasIncomingConnection)
    Indicates to the framework that the configured processor has one or more incoming connections.
    void
    setIsConfiguredForClustering(boolean isConfiguredForClustering)
     
    void
    setNonLoopConnection(boolean hasNonLoopConnection)
    Indicates to the framework that the configured processor has one or more incoming connections for which the processor is not also the source.
    void
    Sets a parameter with the given name and value into the simulated Parameter Context.
    void
    setPrimaryNode(boolean primaryNode)
     
    org.apache.nifi.components.ValidationResult
    setProperty(String propertyName, String propertyValue)
    Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator.
    org.apache.nifi.components.ValidationResult
    setProperty(org.apache.nifi.components.PropertyDescriptor descriptor, String value)
    Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator.
    org.apache.nifi.components.ValidationResult
    setProperty(org.apache.nifi.components.PropertyDescriptor descriptor, org.apache.nifi.components.DescribedValue value)
    Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator.
    org.apache.nifi.components.ValidationResult
    setProperty(org.apache.nifi.controller.ControllerService service, String propertyName, String value)
    Sets the property with the given name on the given ControllerService
    org.apache.nifi.components.ValidationResult
    setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, String value)
    Sets the given property on the given ControllerService
    org.apache.nifi.components.ValidationResult
    setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, org.apache.nifi.components.DescribedValue value)
    Sets the given property on the given ControllerService
    void
    setRelationshipAvailable(String relationshipName)
    Indicates to the Framework that the given Relationship with the given name should be considered "available", meaning that the queues of all Connections that contain this Relationship are not full.
    void
    setRelationshipAvailable(org.apache.nifi.processor.Relationship relationship)
    Indicates to the Framework that the given Relationship should be considered "available", meaning that the queues of all Connections that contain this Relationship are not full.
    void
    Indicates to the Framework that the Relationship with the given name should NOT be considered "available", meaning that the queue of at least one Connection that contain this Relationship is full.
    void
    setRelationshipUnavailable(org.apache.nifi.processor.Relationship relationship)
    Indicates to the Framework that the given Relationship should NOT be considered "available", meaning that the queue of at least one Connection that contain this Relationship is full.
    void
    setRunSchedule(long runSchedule)
    Set the Run Schedule parameter (in milliseconds).
    void
    setThreadCount(int threadCount)
    Updates the number of threads that will be used to run the Processor when calling the TestRunner.run() or TestRunner.run(int) methods.
    void
    setValidateExpressionUsage(boolean validate)
    Specifies whether or not the TestRunner will validate the use of Expression Language.
    void
    Invokes all methods on the Processor that are annotated with the @OnShutdown annotation.
    void
    Invokes all methods on the Processor that are annotated with the @OnStopped annotation.
    void
    Invokes all methods on the Processor that are annotated with the @OnUnscheduled annotation.
    Collection<org.apache.nifi.components.ValidationResult>
    Validates the currently configured set of properties/annotation data
    Collection<org.apache.nifi.components.ValidationResult>
    validate(org.apache.nifi.controller.ControllerService service)
    Validates the currently configured set of properties/annotation data for the given Controller Service.
    List<org.apache.nifi.components.ConfigVerificationResult>
    verify(Map<String,String> variables)
    Verifies the currently configured set of properties/annotation data
    List<org.apache.nifi.components.ConfigVerificationResult>
    verify(org.apache.nifi.controller.ControllerService service, Map<String,String> variables)
    Verifies the currently configured set of properties/annotation data for the given Controller Service.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • processor

      private final org.apache.nifi.processor.Processor processor
    • context

      private final MockProcessContext context
    • kerberosContext

      private final org.apache.nifi.kerberos.KerberosContext kerberosContext
    • flowFileQueue

      private final MockFlowFileQueue flowFileQueue
    • sharedState

      private final SharedSessionState sharedState
    • idGenerator

      private final AtomicLong idGenerator
    • triggerSerially

      private final boolean triggerSerially
    • processorStateManager

      private final MockStateManager processorStateManager
    • controllerServiceStateManagers

      private final Map<String,MockStateManager> controllerServiceStateManagers
    • numThreads

      private int numThreads
    • sessionFactory

      private MockSessionFactory sessionFactory
    • allowSynchronousSessionCommits

      private boolean allowSynchronousSessionCommits
    • allowRecursiveReads

      private boolean allowRecursiveReads
    • runSchedule

      private long runSchedule
    • invocations

      private final AtomicInteger invocations
    • controllerServiceLoggers

      private final Map<String,MockComponentLog> controllerServiceLoggers
    • logger

      private final MockComponentLog logger
    • enforceReadStreamsClosed

      private boolean enforceReadStreamsClosed
    • validateExpressionUsage

      private boolean validateExpressionUsage
    • environmentVariables

      private final Map<String,String> environmentVariables
    • contextParameters

      private final Map<String,String> contextParameters
  • Constructor Details

    • StandardProcessorTestRunner

      StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor)
    • StandardProcessorTestRunner

      StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName)
    • StandardProcessorTestRunner

      StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, org.apache.nifi.kerberos.KerberosContext kerberosContext)
    • StandardProcessorTestRunner

      StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, MockComponentLog logger)
    • StandardProcessorTestRunner

      StandardProcessorTestRunner(org.apache.nifi.processor.Processor processor, String processorName, MockComponentLog logger, org.apache.nifi.kerberos.KerberosContext kerberosContext)
  • Method Details

    • enforceReadStreamsClosed

      public void enforceReadStreamsClosed(boolean enforce)
      Description copied from interface: TestRunner
      By default, if ProcessSession.read(FlowFile) is called, the InputStream that is returned MUST be closed by the processor under test or calls to ProcessSession.commit() will throw an Exception. This method allows the developer to indicate explicitly that they do or do not want this functionality. The ProcessSession that is used in the framework when running NiFi does not enforce this, as the framework itself tracks the InputStreams that it returns and ensures that they are properly closed on session commit or rollback. However, it is considered a best practice for Processors to close the streams themselves whenever they are no longer needed. There may be cases, however, where this is not feasible or easy and this method provides developers the ability to indicate that by disabling enforcement so that the framework will handle this.
      Specified by:
      enforceReadStreamsClosed in interface TestRunner
      Parameters:
      enforce - true if calls to session.commit() should fail if the read streams are not properly closed.
    • setValidateExpressionUsage

      public void setValidateExpressionUsage(boolean validate)
      Description copied from interface: TestRunner
      Specifies whether or not the TestRunner will validate the use of Expression Language. By default, the value is true, which means that an Exception will be thrown if the Processor attempts to obtain the configured value of a Property without calling evaluateAttributeExpressions on the Property Value or if evaluateAttributeExpressions is called but the PropertyDescriptor indicates that the Expression Language is not supported.

      See Also: PropertyDescriptor.Builder.expressionLanguageSupported(ExpressionLanguageScope)

      Specified by:
      setValidateExpressionUsage in interface TestRunner
      Parameters:
      validate - whether there is any need to validate the EL was used
    • setAllowSynchronousSessionCommits

      public void setAllowSynchronousSessionCommits(boolean allowSynchronousSessionCommits)
      Description copied from interface: TestRunner
      Specifies whether the TestRunner will allow ProcessSession.commit() to be called. By default, the value is false, meaning that any call to ProcessSession.commit() will throw an Exception. See JavaDocs for ProcessSession.commit() for more information
      Specified by:
      setAllowSynchronousSessionCommits in interface TestRunner
      Parameters:
      allowSynchronousSessionCommits - whether to allow asynchronous session commits (i.e., calls to ProcessSession.commit())
    • setAllowRecursiveReads

      public void setAllowRecursiveReads(boolean allowRecursiveReads)
      Description copied from interface: TestRunner
      Specifies whether the TestRunner will allow ProcessSession.read() multiple times for the same FlowFile while an InputStream is already open. By default, the value is false, meaning that any call to ProcessSession.read() for a FlowFile already being read will throw an Exception. See JavaDocs for ProcessSession.read(FlowFile) for more information
      Specified by:
      setAllowRecursiveReads in interface TestRunner
      Parameters:
      allowRecursiveReads - whether to allow recursive reads of a FlowFile (i.e., calls to ProcessSession.read())
    • getProcessor

      public org.apache.nifi.processor.Processor getProcessor()
      Specified by:
      getProcessor in interface TestRunner
      Returns:
      the Processor for which this TestRunner is configured
    • getProcessContext

      public MockProcessContext getProcessContext()
      Specified by:
      getProcessContext in interface TestRunner
      Returns:
      the ProcessContext that this TestRunner will use to invoke the onTrigger method
    • isYieldCalled

      public boolean isYieldCalled()
      Specified by:
      isYieldCalled in interface TestRunner
    • run

      public void run()
      Description copied from interface: TestRunner
      Performs exactly the same operation as calling TestRunner.run(int) with a value of 1.
      Specified by:
      run in interface TestRunner
    • run

      public void run(int iterations)
      Description copied from interface: TestRunner
      Performs the same operation as calling TestRunner.run(int, boolean) with a value of true
      Specified by:
      run in interface TestRunner
      Parameters:
      iterations - number of iterations
    • run

      public void run(int iterations, boolean stopOnFinish)
      Description copied from interface: TestRunner
      performs the same operation as calling TestRunner.run(int, boolean, boolean) with a value of iterations, stopOnFinish, true
      Specified by:
      run in interface TestRunner
      Parameters:
      iterations - number of iterations
      stopOnFinish - flag to stop when finished
    • run

      public void run(int iterations, boolean stopOnFinish, boolean initialize)
      Description copied from interface: TestRunner
      This method runs the Processor iterations times, using the sequence of steps below:
      • If initialize is true, run all methods on the Processor that are annotated with the @OnScheduled annotation. If any of these methods throws an Exception, the Unit Test will fail.
      • Schedule the onTrigger method to be invoked iterations times. The number of threads used to run these iterations is determined by the ThreadCount of this TestRunner. By default, the value is set to 1, but it can be modified by calling the TestRunner.setThreadCount(int) method.
      • As soon as the first thread finishes its execution of onTrigger, all methods on the Processor that are annotated with the @OnUnscheduled annotation are invoked. If any of these methods throws an Exception, the Unit Test will fail.
      • Waits for all threads to finish execution.
      • If and only if the value of shutdown is true: Call all methods on the Processor that is annotated with the @OnStopped annotation.
      Specified by:
      run in interface TestRunner
      Parameters:
      iterations - number of iterations
      stopOnFinish - whether or not to run the Processor methods that are annotated with @OnStopped
      initialize - true if must initialize
    • run

      public void run(int iterations, boolean stopOnFinish, boolean initialize, long runWait)
      Description copied from interface: TestRunner
      This method runs the Processor iterations times, using the sequence of steps below:
      • If initialize is true, run all methods on the Processor that are annotated with the @OnScheduled annotation. If any of these methods throws an Exception, the Unit Test will fail.
      • Schedule the onTrigger method to be invoked iterations times. The number of threads used to run these iterations is determined by the ThreadCount of this TestRunner. By default, the value is set to 1, but it can be modified by calling the TestRunner.setThreadCount(int) method.
      • As soon as the first thread finishes its execution of onTrigger, all methods on the Processor that are annotated with the @OnUnscheduled annotation are invoked. If any of these methods throws an Exception, the Unit Test will fail.
      • Waits for all threads to finish execution.
      • If and only if the value of shutdown is true: Call all methods on the Processor that is annotated with the @OnStopped annotation.
      Specified by:
      run in interface TestRunner
      Parameters:
      iterations - number of iterations
      stopOnFinish - whether or not to run the Processor methods that are annotated with @OnStopped
      initialize - true if must initialize
      runWait - indicates the amount of time in milliseconds that the framework should wait for processors to stop running before calling the @OnUnscheduled annotation
    • unSchedule

      public void unSchedule()
      Description copied from interface: TestRunner
      Invokes all methods on the Processor that are annotated with the @OnUnscheduled annotation. If any of these methods throws an Exception, the Unit Test will fail
      Specified by:
      unSchedule in interface TestRunner
    • stop

      public void stop()
      Description copied from interface: TestRunner
      Invokes all methods on the Processor that are annotated with the @OnStopped annotation. If any of these methods throws an Exception, the Unit Test will fail
      Specified by:
      stop in interface TestRunner
    • shutdown

      public void shutdown()
      Description copied from interface: TestRunner
      Invokes all methods on the Processor that are annotated with the @OnShutdown annotation. If any of these methods throws an Exception, the Unit Test will fail
      Specified by:
      shutdown in interface TestRunner
    • getProcessSessionFactory

      public org.apache.nifi.processor.ProcessSessionFactory getProcessSessionFactory()
      Specified by:
      getProcessSessionFactory in interface TestRunner
      Returns:
      the ProcessSessionFactory that this TestRunner will use to invoke the Processor.onTrigger(ProcessContext, ProcessSessionFactory) method
    • assertAllFlowFilesTransferred

      public void assertAllFlowFilesTransferred(String relationship)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred were transferred to the given relationship
      Specified by:
      assertAllFlowFilesTransferred in interface TestRunner
      Parameters:
      relationship - to verify
    • assertAllFlowFilesTransferred

      public void assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred were transferred to the given relationship
      Specified by:
      assertAllFlowFilesTransferred in interface TestRunner
      Parameters:
      relationship - to verify
    • assertAllFlowFilesTransferred

      public void assertAllFlowFilesTransferred(String relationship, int count)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal to count
      Specified by:
      assertAllFlowFilesTransferred in interface TestRunner
      Parameters:
      relationship - to verify
      count - number of expected transfers
    • assertAllFlowFilesContainAttribute

      public void assertAllFlowFilesContainAttribute(String attributeName)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred contain the given attribute.
      Specified by:
      assertAllFlowFilesContainAttribute in interface TestRunner
      Parameters:
      attributeName - attribute to look for
    • assertAllFlowFilesContainAttribute

      public void assertAllFlowFilesContainAttribute(org.apache.nifi.processor.Relationship relationship, String attributeName)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred to the given relationship contain the given attribute.
      Specified by:
      assertAllFlowFilesContainAttribute in interface TestRunner
      Parameters:
      relationship - relationship to check
      attributeName - attribute to look for
    • assertAllFlowFiles

      public void assertAllFlowFiles(FlowFileValidator validator)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred are compliant with the given validator.
      Specified by:
      assertAllFlowFiles in interface TestRunner
      Parameters:
      validator - validator to use
    • assertAllFlowFiles

      public void assertAllFlowFiles(org.apache.nifi.processor.Relationship relationship, FlowFileValidator validator)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred in the given relationship are compliant with the given validator.
      Specified by:
      assertAllFlowFiles in interface TestRunner
      Parameters:
      validator - validator to use
    • assertAttributes

      public void assertAttributes(org.apache.nifi.processor.Relationship relationship, Set<String> checkedAttributeNames, Set<Map<String,String>> expectedAttributes)
      Description copied from interface: TestRunner
      Asserts that flowfiles on a given relationship have a certain set of attributes.
      Specified by:
      assertAttributes in interface TestRunner
      Parameters:
      relationship - The relationship on which to check the attributes of flowfiles
      checkedAttributeNames - The names of attributes that should be checked
      expectedAttributes - The expected attributes of all flowfiles
    • assertContents

      public void assertContents(org.apache.nifi.processor.Relationship relationship, List<String> expectedContent)
      Description copied from interface: TestRunner
      Asserts that flowfiles on a given relationship have certain contents.
      Specified by:
      assertContents in interface TestRunner
      Parameters:
      relationship - The relationship on which to check the contents of flowfiles
      expectedContent - The expected contents of all flowfiles
    • assertAllFlowFilesTransferred

      public void assertAllFlowFilesTransferred(org.apache.nifi.processor.Relationship relationship, int count)
      Description copied from interface: TestRunner
      Asserts that all FlowFiles that were transferred were transferred to the given relationship and that the number of FlowFiles transferred is equal to count
      Specified by:
      assertAllFlowFilesTransferred in interface TestRunner
      Parameters:
      relationship - to verify
      count - number of expected transfers
    • assertTransferCount

      public void assertTransferCount(org.apache.nifi.processor.Relationship relationship, int count)
      Description copied from interface: TestRunner
      Assert that the number of FlowFiles transferred to the given relationship is equal to the given count
      Specified by:
      assertTransferCount in interface TestRunner
      Parameters:
      relationship - to verify
      count - number of expected transfers
    • assertTransferCount

      public void assertTransferCount(String relationship, int count)
      Description copied from interface: TestRunner
      Assert that the number of FlowFiles transferred to the given relationship is equal to the given count
      Specified by:
      assertTransferCount in interface TestRunner
      Parameters:
      relationship - to verify
      count - number of expected transfers
    • assertPenalizeCount

      public void assertPenalizeCount(int count)
      Description copied from interface: TestRunner
      Assert that the number of FlowFiles that were penalized is equal to the given count
      Specified by:
      assertPenalizeCount in interface TestRunner
      Parameters:
      count - number of expected penalized
    • assertValid

      public void assertValid()
      Description copied from interface: TestRunner
      Assert that the currently configured set of properties/annotation data are valid
      Specified by:
      assertValid in interface TestRunner
    • validate

      public Collection<org.apache.nifi.components.ValidationResult> validate()
      Description copied from interface: TestRunner
      Validates the currently configured set of properties/annotation data
      Specified by:
      validate in interface TestRunner
      Returns:
      a Collection of ValidationResult
    • verify

      public List<org.apache.nifi.components.ConfigVerificationResult> verify(Map<String,String> variables)
      Description copied from interface: TestRunner
      Verifies the currently configured set of properties/annotation data
      Specified by:
      verify in interface TestRunner
      Parameters:
      variables - the variables to use for verification
      Returns:
      a Collection of ConfigVerificationResult
    • isValid

      public boolean isValid()
      Specified by:
      isValid in interface TestRunner
    • assertNotValid

      public void assertNotValid()
      Description copied from interface: TestRunner
      Assert that the currently configured set of properties/annotation data are NOT valid
      Specified by:
      assertNotValid in interface TestRunner
    • isQueueEmpty

      public boolean isQueueEmpty()
      Specified by:
      isQueueEmpty in interface TestRunner
      Returns:
      true if the Input Queue to the Processor is empty, false otherwise
    • assertQueueEmpty

      public void assertQueueEmpty()
      Description copied from interface: TestRunner
      Assert that there are no FlowFiles left on the input queue.
      Specified by:
      assertQueueEmpty in interface TestRunner
    • assertQueueNotEmpty

      public void assertQueueNotEmpty()
      Description copied from interface: TestRunner
      Assert that there is at least one FlowFile left on the input queue.
      Specified by:
      assertQueueNotEmpty in interface TestRunner
    • clearTransferState

      public void clearTransferState()
      Description copied from interface: TestRunner
      Resets the Transfer Counts that indicate how many FlowFiles have been transferred to each Relationship and removes from memory any FlowFiles that have been transferred to this Relationships. This method should be called between successive calls to run if the output is to be examined after each run.
      Specified by:
      clearTransferState in interface TestRunner
    • enqueue

      public void enqueue(org.apache.nifi.flowfile.FlowFile... flowFiles)
      Description copied from interface: TestRunner
      Enqueues the given FlowFiles into the Processor's input queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      flowFiles - to enqueue
    • enqueue

      public MockFlowFile enqueue(Path path) throws IOException
      Description copied from interface: TestRunner
      Reads the content from the given Path into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      path - to read content from
      Throws:
      IOException - if unable to read content
    • enqueue

      public MockFlowFile enqueue(Path path, Map<String,String> attributes) throws IOException
      Description copied from interface: TestRunner
      Reads the content from the given Path into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      path - to read content from
      attributes - attributes to use for new flow file
      Throws:
      IOException - if unable to read content
    • enqueue

      public MockFlowFile enqueue(byte[] data)
      Description copied from interface: TestRunner
      Copies the content from the given byte array into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - to enqueue
    • enqueue

      public MockFlowFile enqueue(String data)
      Description copied from interface: TestRunner
      Creates a FlowFile with the content set to the given string (in UTF-8 format), with no attributes, and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - to enqueue
    • enqueue

      public MockFlowFile enqueue(byte[] data, Map<String,String> attributes)
      Description copied from interface: TestRunner
      Copies the content from the given byte array into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - to enqueue
      attributes - to use for enqueued item
    • enqueue

      public MockFlowFile enqueue(String data, Map<String,String> attributes)
      Description copied from interface: TestRunner
      Creates a FlowFile with the content set to the given string (in UTF-8 format), with the given attributes, and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - to enqueue
      attributes - to use for enqueued item
    • enqueue

      public MockFlowFile enqueue(InputStream data)
      Description copied from interface: TestRunner
      Reads the content from the given InputStream into memory and creates a FlowFile from this content with no attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - to source data from
    • enqueue

      public MockFlowFile enqueue(InputStream data, Map<String,String> attributes)
      Description copied from interface: TestRunner
      Reads the content from the given InputStream into memory and creates a FlowFile from this content with the given attributes and adds this FlowFile to the Processor's Input Queue
      Specified by:
      enqueue in interface TestRunner
      Parameters:
      data - source of data
      attributes - to use for flow files
    • getContentAsByteArray

      public byte[] getContentAsByteArray(MockFlowFile flowFile)
      Description copied from interface: TestRunner
      Copies the contents of the given MockFlowFile into a byte array and returns that byte array.
      Specified by:
      getContentAsByteArray in interface TestRunner
      Parameters:
      flowFile - to get content for
      Returns:
      byte array of flowfile content
    • getFlowFilesForRelationship

      public List<MockFlowFile> getFlowFilesForRelationship(String relationship)
      Description copied from interface: TestRunner
      Returns a List of FlowFiles in the order in which they were transferred to the given relationship
      Specified by:
      getFlowFilesForRelationship in interface TestRunner
      Parameters:
      relationship - to get flowfiles for
      Returns:
      flowfiles transferred to given relationship
    • getFlowFilesForRelationship

      public List<MockFlowFile> getFlowFilesForRelationship(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Returns a List of FlowFiles in the order in which they were transferred to the given relationship
      Specified by:
      getFlowFilesForRelationship in interface TestRunner
      Parameters:
      relationship - to get flowfiles for
      Returns:
      flowfiles transferred to given relationship
    • getPenalizedFlowFiles

      public List<MockFlowFile> getPenalizedFlowFiles()
      Description copied from interface: TestRunner
      Returns a List of FlowFiles in the order in which they were transferred that were penalized
      Specified by:
      getPenalizedFlowFiles in interface TestRunner
      Returns:
      flowfiles that were penalized
    • getQueueSize

      public org.apache.nifi.controller.queue.QueueSize getQueueSize()
      Specified by:
      getQueueSize in interface TestRunner
      Returns:
      the current size of the Processor's Input Queue
    • clearQueue

      public void clearQueue()
      Description copied from interface: TestRunner
      Allow for clearing the queue from all remaining flow files.
      Specified by:
      clearQueue in interface TestRunner
    • getCounterValue

      public Long getCounterValue(String name)
      Specified by:
      getCounterValue in interface TestRunner
      Parameters:
      name - of counter
      Returns:
      the current value of the counter with the specified name, or null if no counter exists with the specified name
    • getRemovedCount

      public int getRemovedCount()
      Specified by:
      getRemovedCount in interface TestRunner
      Returns:
      the number of FlowFiles that have been removed from the system
    • setAnnotationData

      public void setAnnotationData(String annotationData)
      Description copied from interface: TestRunner
      Sets the annotation data.
      Specified by:
      setAnnotationData in interface TestRunner
      Parameters:
      annotationData - data
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(String propertyName, String propertyValue)
      Description copied from interface: TestRunner
      Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator. Otherwise, Assertions.fail() is called, causing the unit test to fail
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      propertyName - name
      propertyValue - value
      Returns:
      result
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.components.PropertyDescriptor descriptor, String value)
      Description copied from interface: TestRunner
      Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator. Otherwise, Assertions.fail() is called, causing the unit test to fail
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      descriptor - descriptor
      value - value
      Returns:
      result
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.components.PropertyDescriptor descriptor, org.apache.nifi.components.DescribedValue value)
      Description copied from interface: TestRunner
      Updates the value of the property with the given PropertyDescriptor to the specified value IF and ONLY IF the value is valid according to the descriptor's validator. Otherwise, Assertions.fail() is called, causing the unit test to fail
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      descriptor - descriptor
      value - allowable valu
      Returns:
      result
    • setThreadCount

      public void setThreadCount(int threadCount)
      Description copied from interface: TestRunner
      Updates the number of threads that will be used to run the Processor when calling the TestRunner.run() or TestRunner.run(int) methods.
      Specified by:
      setThreadCount in interface TestRunner
      Parameters:
      threadCount - num threads
    • getThreadCount

      public int getThreadCount()
      Specified by:
      getThreadCount in interface TestRunner
      Returns:
      the currently configured number of threads that will be used to runt he Processor when calling the TestRunner.run() or TestRunner.run(int) methods
    • setRelationshipAvailable

      public void setRelationshipAvailable(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Indicates to the Framework that the given Relationship should be considered "available", meaning that the queues of all Connections that contain this Relationship are not full. This is generally used only when dealing with Processors that use the TriggerWhenAnyDestinationAvailable annotation.
      Specified by:
      setRelationshipAvailable in interface TestRunner
      Parameters:
      relationship - to mark as available
    • setRelationshipAvailable

      public void setRelationshipAvailable(String relationshipName)
      Description copied from interface: TestRunner
      Indicates to the Framework that the given Relationship with the given name should be considered "available", meaning that the queues of all Connections that contain this Relationship are not full. This is generally used only when dealing with Processors that use the TriggerWhenAnyDestinationAvailable
      Specified by:
      setRelationshipAvailable in interface TestRunner
      Parameters:
      relationshipName - relationship name
    • setRelationshipUnavailable

      public void setRelationshipUnavailable(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Indicates to the Framework that the given Relationship should NOT be considered "available", meaning that the queue of at least one Connection that contain this Relationship is full. This is generally used only when dealing with Processors that use the TriggerWhenAnyDestinationAvailable annotation.
      Specified by:
      setRelationshipUnavailable in interface TestRunner
      Parameters:
      relationship - to mark as unavailable
    • setRelationshipUnavailable

      public void setRelationshipUnavailable(String relationshipName)
      Description copied from interface: TestRunner
      Indicates to the Framework that the Relationship with the given name should NOT be considered "available", meaning that the queue of at least one Connection that contain this Relationship is full. This is generally used only when dealing with Processors that use the TriggerWhenAnyDestinationAvailable
      Specified by:
      setRelationshipUnavailable in interface TestRunner
      Parameters:
      relationshipName - name of relationship.
    • setIncomingConnection

      public void setIncomingConnection(boolean hasIncomingConnection)
      Description copied from interface: TestRunner
      Indicates to the framework that the configured processor has one or more incoming connections.
      Specified by:
      setIncomingConnection in interface TestRunner
      Parameters:
      hasIncomingConnection - whether or not the configured processor should behave as though it has an incoming connection
    • setNonLoopConnection

      public void setNonLoopConnection(boolean hasNonLoopConnection)
      Description copied from interface: TestRunner
      Indicates to the framework that the configured processor has one or more incoming connections for which the processor is not also the source.
      Specified by:
      setNonLoopConnection in interface TestRunner
      Parameters:
      hasNonLoopConnection - whether or not the configured processor should behave as though it has a non-looping incoming connection
    • addConnection

      public void addConnection(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Indicates to the Framework that the configured processor has a connection for the given Relationship.
      Specified by:
      addConnection in interface TestRunner
      Parameters:
      relationship - that has a connection
    • addConnection

      public void addConnection(String relationshipName)
      Description copied from interface: TestRunner
      Indicates to the Framework that the configured processor has a connection for the Relationship with the given name.
      Specified by:
      addConnection in interface TestRunner
      Parameters:
      relationshipName - name of relationship that has a connection
    • removeConnection

      public void removeConnection(org.apache.nifi.processor.Relationship relationship)
      Description copied from interface: TestRunner
      Removes the connection for the given Relationship from the configured processor.
      Specified by:
      removeConnection in interface TestRunner
      Parameters:
      relationship - to remove
    • removeConnection

      public void removeConnection(String relationshipName)
      Description copied from interface: TestRunner
      Removes the connection for the relationship with the given name from the configured processor.
      Specified by:
      removeConnection in interface TestRunner
      Parameters:
      relationshipName - name of the relationship to remove
    • addControllerService

      public void addControllerService(String identifier, org.apache.nifi.controller.ControllerService service) throws org.apache.nifi.reporting.InitializationException
      Description copied from interface: TestRunner
      Adds the given ControllerService to this TestRunner so that the configured Processor can access it using the given identifier. The ControllerService is not expected to be initialized, as the framework will create the appropriate ControllerServiceInitializationContext and initialize the ControllerService with no specified properties. This will call any method on the given Controller Service that is annotated with the @OnAdded annotation.
      Specified by:
      addControllerService in interface TestRunner
      Parameters:
      identifier - of service
      service - the service
      Throws:
      org.apache.nifi.reporting.InitializationException - ie
    • addControllerService

      public void addControllerService(String identifier, org.apache.nifi.controller.ControllerService service, Map<String,String> properties) throws org.apache.nifi.reporting.InitializationException
      Description copied from interface: TestRunner
      Adds the given ControllerService to this TestRunner so that the configured Processor can access it using the given identifier. The ControllerService is not expected to be initialized, as the framework will create the appropriate ControllerServiceInitializationContext and initialize the ControllerService with the given properties. This will call any method on the given Controller Service that is annotated with the @OnAdded annotation.
      Specified by:
      addControllerService in interface TestRunner
      Parameters:
      identifier - of service
      service - the service
      properties - service properties
      Throws:
      org.apache.nifi.reporting.InitializationException - ie
    • assertNotValid

      public void assertNotValid(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner
      Assert that the currently configured set of properties/annotation data are NOT valid for the given Controller Service.
      Specified by:
      assertNotValid in interface TestRunner
      Parameters:
      service - the service to validate
    • assertValid

      public void assertValid(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner
      Assert that the currently configured set of properties/annotation data are valid for the given Controller Service.
      Specified by:
      assertValid in interface TestRunner
      Parameters:
      service - the service to validate
    • validate

      public Collection<org.apache.nifi.components.ValidationResult> validate(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner
      Validates the currently configured set of properties/annotation data for the given Controller Service.
      Specified by:
      validate in interface TestRunner
      Parameters:
      service - the service to validate
      Returns:
      a Collection of ValidationResult
    • verify

      public List<org.apache.nifi.components.ConfigVerificationResult> verify(org.apache.nifi.controller.ControllerService service, Map<String,String> variables)
      Description copied from interface: TestRunner
      Verifies the currently configured set of properties/annotation data for the given Controller Service.
      Specified by:
      verify in interface TestRunner
      Parameters:
      variables - the variables to use for verification
      Returns:
      a Collection of ConfigVerificationResult
    • disableControllerService

      public void disableControllerService(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner

      Marks the Controller Service as disabled so that it cannot be used by other components.

      This method will result in calling any method in the Controller Service that is annotated with the @OnDisabled annotation.

      Specified by:
      disableControllerService in interface TestRunner
      Parameters:
      service - the service to disable
    • enableControllerService

      public void enableControllerService(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner

      Marks the Controller Service as enabled so that it can be used by other components.

      This method will result in calling any method in the Controller Service that is annotated with the @OnEnabled annotation.

      Specified by:
      enableControllerService in interface TestRunner
      Parameters:
      service - the service to enable
    • isControllerServiceEnabled

      public boolean isControllerServiceEnabled(org.apache.nifi.controller.ControllerService service)
      Specified by:
      isControllerServiceEnabled in interface TestRunner
      Parameters:
      service - the service
      Returns:
      true if the given Controller Service is enabled, false if it is disabled
    • removeControllerService

      public void removeControllerService(org.apache.nifi.controller.ControllerService service)
      Description copied from interface: TestRunner

      Removes the Controller Service from the TestRunner. This will call any method on the ControllerService that is annotated with the @OnRemoved annotation.

      Specified by:
      removeControllerService in interface TestRunner
      Parameters:
      service - the service
    • setAnnotationData

      public void setAnnotationData(org.apache.nifi.controller.ControllerService service, String annotationData)
      Description copied from interface: TestRunner
      Sets the annotation data of the given service to the provided annotation data.
      Specified by:
      setAnnotationData in interface TestRunner
      Parameters:
      service - to modify
      annotationData - the data
    • getConfigToUpdate

      private ControllerServiceConfiguration getConfigToUpdate(org.apache.nifi.controller.ControllerService service)
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, org.apache.nifi.components.DescribedValue value)
      Description copied from interface: TestRunner
      Sets the given property on the given ControllerService
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      service - to modify
      property - to modify
      value - value to use
      Returns:
      result
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property, String value)
      Description copied from interface: TestRunner
      Sets the given property on the given ControllerService
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      service - to modify
      property - to modify
      value - value to use
      Returns:
      result
    • setProperty

      public org.apache.nifi.components.ValidationResult setProperty(org.apache.nifi.controller.ControllerService service, String propertyName, String value)
      Description copied from interface: TestRunner
      Sets the property with the given name on the given ControllerService
      Specified by:
      setProperty in interface TestRunner
      Parameters:
      service - to modify
      propertyName - to modify
      value - value to use
      Returns:
      result
    • getControllerService

      public org.apache.nifi.controller.ControllerService getControllerService(String identifier)
      Specified by:
      getControllerService in interface TestRunner
      Parameters:
      identifier - of controller service
      Returns:
      the ControllerService that is registered with the given identifier, or null if no Controller Service exists with the given identifier
    • getControllerService

      public <T extends org.apache.nifi.controller.ControllerService> T getControllerService(String identifier, Class<T> serviceType)
      Specified by:
      getControllerService in interface TestRunner
      Type Parameters:
      T - type of service
      Parameters:
      identifier - identifier of service
      serviceType - type of service
      Returns:
      the ControllerService that is registered with the given identifier, cast as the provided service type, or null if no Controller Service exists with the given identifier
    • removeProperty

      public boolean removeProperty(org.apache.nifi.components.PropertyDescriptor descriptor)
      Description copied from interface: TestRunner
      Removes the PropertyDescriptor from the ProcessContext, effectively setting its value to null, or the property's default value, if it has one.
      Specified by:
      removeProperty in interface TestRunner
      Parameters:
      descriptor - of property to remove
      Returns:
      true if removed, false if the property was not set
    • removeProperty

      public boolean removeProperty(String property)
      Description copied from interface: TestRunner
      Removes the property from the ProcessContext, effectively setting its value to null, or the property's default value, if it has one.
      Specified by:
      removeProperty in interface TestRunner
      Parameters:
      property - name of the property to remove
      Returns:
      true if removed, false if the property was not set
    • removeProperty

      public boolean removeProperty(org.apache.nifi.controller.ControllerService service, org.apache.nifi.components.PropertyDescriptor property)
      Description copied from interface: TestRunner
      Removes the PropertyDescriptor from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.
      Specified by:
      removeProperty in interface TestRunner
      Parameters:
      service - the controller service to remove the property from
      property - of property to remove
      Returns:
      true if removed, false if the property was not set
    • removeProperty

      public boolean removeProperty(org.apache.nifi.controller.ControllerService service, String propertyName)
      Description copied from interface: TestRunner
      Removes the PropertyDescriptor from the ControllerService, effectively setting its value to null, or the property's default value, if it has one.
      Specified by:
      removeProperty in interface TestRunner
      Parameters:
      service - the controller service to remove the property from
      propertyName - name of the property to remove
      Returns:
      true if removed, false if the property was not set
    • clearProperties

      public void clearProperties()
      Description copied from interface: TestRunner
      Clears all set properties from the ProcessContext.
      Specified by:
      clearProperties in interface TestRunner
    • getProvenanceEvents

      public List<org.apache.nifi.provenance.ProvenanceEventRecord> getProvenanceEvents()
      Description copied from interface: TestRunner
      Returns a List of all ProvenanceEventRecords that were emitted by the Processor
      Specified by:
      getProvenanceEvents in interface TestRunner
      Returns:
      a List of all Provenance Events that were emitted by the Processor
    • clearProvenanceEvents

      public void clearProvenanceEvents()
      Description copied from interface: TestRunner
      Clears the Provenance Events that have been emitted by the Processor
      Specified by:
      clearProvenanceEvents in interface TestRunner
    • getStateManager

      public MockStateManager getStateManager()
      Specified by:
      getStateManager in interface TestRunner
      Returns:
      the State Manager that is used to stored and retrieve state
    • getStateManager

      public MockStateManager getStateManager(org.apache.nifi.controller.ControllerService controllerService)
      Returns the State Manager for the given Controller Service.
      Specified by:
      getStateManager in interface TestRunner
      Parameters:
      controllerService - the Controller Service whose State Manager should be returned
      Returns:
      the State Manager for the given Controller Service
    • getLogger

      public MockComponentLog getLogger()
      Description copied from interface: TestRunner
      Returns the MockComponentLog that is used by the Processor under test.
      Specified by:
      getLogger in interface TestRunner
      Returns:
      the logger
    • getControllerServiceLogger

      public MockComponentLog getControllerServiceLogger(String identifier)
      Description copied from interface: TestRunner
      Returns the MockComponentLog that is used by the specified controller service.
      Specified by:
      getControllerServiceLogger in interface TestRunner
      Parameters:
      identifier - a controller service identifier
      Returns:
      the logger
    • setClustered

      public void setClustered(boolean clustered)
      Specified by:
      setClustered in interface TestRunner
      Parameters:
      clustered - Specify if this test emulates running in a clustered environment
    • setIsConfiguredForClustering

      public void setIsConfiguredForClustering(boolean isConfiguredForClustering)
      Specified by:
      setIsConfiguredForClustering in interface TestRunner
      Parameters:
      isConfiguredForClustering - Specify if this test emulates running in an environment where the expected cluster state equals with the argument.
    • setPrimaryNode

      public void setPrimaryNode(boolean primaryNode)
      Specified by:
      setPrimaryNode in interface TestRunner
      Parameters:
      primaryNode - Specify if this test emulates running as a primary node
    • setConnected

      public void setConnected(boolean isConnected)
      Specified by:
      setConnected in interface TestRunner
      Parameters:
      isConnected - Specify if this test emulates ongoing cluster connection
    • getEnvironmentVariableValue

      public String getEnvironmentVariableValue(String name)
      Description copied from interface: TestRunner
      Returns the current value of the variable with the given name
      Specified by:
      getEnvironmentVariableValue in interface TestRunner
      Parameters:
      name - the name of the variable whose value should be returned.
      Returns:
      the current value of the variable with the given name or null if no value is currently set
    • setEnvironmentVariableValue

      public void setEnvironmentVariableValue(String name, String value)
      Description copied from interface: TestRunner
      Sets the value of the variable with the given name to be the given value. This exposes the variable for use by the Expression Language. NOTE - this method is only for testing purposes as we only support variables coming from environment and system variables. This usage is to avoid the need to set env/sys variables in the tests.
      Specified by:
      setEnvironmentVariableValue in interface TestRunner
      Parameters:
      name - the name of the variable to set
      value - the value of the variable
    • getParameterContextValue

      public String getParameterContextValue(String name)
      Description copied from interface: TestRunner
      Returns the current value for the given parameter name from the simulated Parameter Context
      Specified by:
      getParameterContextValue in interface TestRunner
      Parameters:
      name - the name of the parameter from the Parameter Context whose value should be returned.
      Returns:
      the current value for the given parameter name from the simulated Parameter Context or null if no value is currently set
    • setParameterContextValue

      public void setParameterContextValue(String name, String value)
      Description copied from interface: TestRunner
      Sets a parameter with the given name and value into the simulated Parameter Context. This makes available the parameter to the properties of the component being tested through parameter referencing such as #{name}.
      Specified by:
      setParameterContextValue in interface TestRunner
      Parameters:
      name - the name of the parameter to set
      value - the value of the parameter to set
    • assertAllConditionsMet

      public void assertAllConditionsMet(String relationshipName, Predicate<MockFlowFile> predicate)
      Asserts that all FlowFiles meet all conditions.
      Specified by:
      assertAllConditionsMet in interface TestRunner
      Parameters:
      relationshipName - relationship name
      predicate - conditions
    • assertAllConditionsMet

      public void assertAllConditionsMet(org.apache.nifi.processor.Relationship relationship, Predicate<MockFlowFile> predicate)
      Asserts that all FlowFiles meet all conditions.
      Specified by:
      assertAllConditionsMet in interface TestRunner
      Parameters:
      relationship - relationship
      predicate - conditions
    • setRunSchedule

      public void setRunSchedule(long runSchedule)
      Set the Run Schedule parameter (in milliseconds). If set, this will be the duration between two calls of the onTrigger method.
      Specified by:
      setRunSchedule in interface TestRunner
      Parameters:
      runSchedule - Run schedule duration in milliseconds.
    • assertProvenanceEvent

      public void assertProvenanceEvent(org.apache.nifi.provenance.ProvenanceEventType eventType)
      Description copied from interface: TestRunner
      Assert that provenance event was created with the specified event type.
      Specified by:
      assertProvenanceEvent in interface TestRunner
      Parameters:
      eventType - Provenance event type
    • migrateProperties

      public PropertyMigrationResult migrateProperties()
      Description copied from interface: TestRunner
      Causes the TestRunner to call the Processor's Processor.migrateProperties(PropertyConfiguration) method. The effects that are caused by calling the method are applied, as they would be in a running NiFi instance. Unlike in a running NiFi instance, though, the operations that were performed are captured so that they can be examined and assertions made about the migration that occurred.
      Specified by:
      migrateProperties in interface TestRunner
      Returns:
      the results of migrating properties
    • migrateRelationships

      public RelationshipMigrationResult migrateRelationships()
      Description copied from interface: TestRunner
      Causes the TestRunner to call the Processor's Processor.migrateRelationships(RelationshipConfiguration) method. The effects that are caused by calling the method are applied, as they would be in a running NiFi instance. Unlike in a running NiFi instance, though, the operations that were performed are captured so that they can be examined and assertions made about the migration that occurred.
      Specified by:
      migrateRelationships in interface TestRunner
      Returns:
      the results of migrating relationships