Class IkasanStandaloneFlowTestRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class IkasanStandaloneFlowTestRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    JUnit Rule implementation allowing flow tests to be created and executed using a builder pattern.

    The rule will take care of starting up spring context bases on IkasanApplicationFactory and Application class provided in constructor.

    The underlying Flow will be automatically stopped and checked when the rule is evaluated at the end of the test

    Author:
    Ikasan Development Team
    • Constructor Detail

      • IkasanStandaloneFlowTestRule

        public IkasanStandaloneFlowTestRule​(java.lang.String flowUnderTest,
                                            java.lang.Class<?> applicationClass)
      • IkasanStandaloneFlowTestRule

        public IkasanStandaloneFlowTestRule​(java.lang.String flowUnderTest,
                                            java.lang.Class<?> applicationClass,
                                            java.lang.String[] args)
      • IkasanStandaloneFlowTestRule

        public IkasanStandaloneFlowTestRule​(java.lang.String flowUnderTest,
                                            org.ikasan.builder.IkasanApplication ikasanApplication)
    • Method Detail

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Applies the basic flow test rules: 1. Stop the flow and assert it is stopped; or stoppedInError if withErrorEndState() was called when building 2. Assert the flowTestHarness for component invocation completeness
        Specified by:
        apply in interface org.junit.rules.TestRule
        Parameters:
        base - a base Statement
        description - a Description (not used)
        Returns:
        a Statement, wrapping the provided instance, that can be evaluated by JUnit
      • assertFlowComponentExecution

        public void assertFlowComponentExecution()
      • withFlow

        public IkasanStandaloneFlowTestRule withFlow​(org.ikasan.spec.flow.Flow flow)
        Set the flow which this Rule will check
        Parameters:
        flow - the Flow
        Returns:
        this rule
      • withErrorEndState

        public IkasanStandaloneFlowTestRule withErrorEndState()
        Indicate the flow end state will be 'stoppedInError', used in negative testing
        Returns:
        this rule
      • consumer

        public IkasanStandaloneFlowTestRule consumer​(java.lang.String name)
        Expect a consumer
        Parameters:
        name - the consumer name
        Returns:
        this rule
      • scheduledConsumer

        public IkasanStandaloneFlowTestRule scheduledConsumer​(java.lang.String name)
        Expect a consumer
        Parameters:
        name - the consumer name
        Returns:
        this rule
      • splitter

        public IkasanStandaloneFlowTestRule splitter​(java.lang.String name)
        Expect a splitter
        Parameters:
        name - the splitter name
        Returns:
        this rule
      • converter

        public IkasanStandaloneFlowTestRule converter​(java.lang.String name)
        Expect a converter
        Parameters:
        name - the converter name
        Returns:
        this rule
      • producer

        public IkasanStandaloneFlowTestRule producer​(java.lang.String name)
        Expect a producer
        Parameters:
        name - the producer name
        Returns:
        this rule
      • router

        public IkasanStandaloneFlowTestRule router​(java.lang.String name)
        Expect a SingleRecipientRouter
        Parameters:
        name - the router name
        Returns:
        this rule
      • multiRecipientRouter

        public IkasanStandaloneFlowTestRule multiRecipientRouter​(java.lang.String name)
        Expect a MultiRecipientRouter
        Parameters:
        name - the MRR name
        Returns:
        this rule
      • translator

        public IkasanStandaloneFlowTestRule translator​(java.lang.String name)
        Expect a translator
        Parameters:
        name - the translator name
        Returns:
        this rule
      • broker

        public IkasanStandaloneFlowTestRule broker​(java.lang.String name)
        Expect a broker
        Parameters:
        name - the broker name
        Returns:
        this rule
      • filter

        public IkasanStandaloneFlowTestRule filter​(java.lang.String name)
        Expect a filter
        Parameters:
        name - the filter name
        Returns:
        this rule
      • sequencer

        public IkasanStandaloneFlowTestRule sequencer​(java.lang.String name)
        Expect a sequencer
        Parameters:
        name - the sequencer name
        Returns:
        this rule
      • repeat

        public IkasanStandaloneFlowTestRule repeat​(int n)
        Repeat the current block n times;
        Parameters:
        n - number of times to repeat the block
        Returns:
        this rule
      • fireScheduledConsumer

        public void fireScheduledConsumer()
        Invoke the scheduled consumer via its triggerSchedulerNow method

        This method executes the underlying Job asynchronously

      • fireScheduledConsumerSynchronously

        public void fireScheduledConsumerSynchronously​(org.quartz.JobExecutionContext jobExecutionContext)
        Invoke the scheduled consumer with a given JobExecutionContext (can be mocked). This method executes synchronously - when the flow finished executing the given task this method will then return.
        Parameters:
        jobExecutionContext - a JobExecutionContext
      • startFlow

        public void startFlow()
        Setup the flow expectations, make sure that testHarness listener is attached to flow and start the given flow.
      • getComponent

        public java.lang.Object getComponent​(java.lang.String componentName)
        Gets component of given name from this flow.
        Parameters:
        componentName - component name to be looked up in flow
        Returns:
        component as Object
      • getComponentConfig

        public <T> T getComponentConfig​(java.lang.String componentName,
                                        java.lang.Class<T> classType)
        Gets configuration of component with given name from this flow.
        Parameters:
        componentName - component name to be looked up in flow
        classType - class Type to configuration object
        Returns:
        configuration object casted to T
      • sleep

        public void sleep​(long time)
        Sleep for a bit to let a flow execution complete
        Parameters:
        time - the number of milliseconds to sleep for
      • getIkasanApplication

        public org.ikasan.builder.IkasanApplication getIkasanApplication()