Package org.ikasan.testharness.flow.rule
Class IkasanStandaloneFlowTestRule
- java.lang.Object
-
- org.ikasan.testharness.flow.rule.IkasanStandaloneFlowTestRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class IkasanStandaloneFlowTestRule extends java.lang.Object implements org.junit.rules.TestRuleJUnit 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 Summary
Constructors Constructor Description IkasanStandaloneFlowTestRule(java.lang.String flowUnderTest, java.lang.Class<?> applicationClass)IkasanStandaloneFlowTestRule(java.lang.String flowUnderTest, java.lang.Class<?> applicationClass, java.lang.String[] args)IkasanStandaloneFlowTestRule(java.lang.String flowUnderTest, org.ikasan.builder.IkasanApplication ikasanApplication)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.junit.runners.model.Statementapply(org.junit.runners.model.Statement base, org.junit.runner.Description description)Applies the basic flow test rules: 1.voidassertFlowComponentExecution()IkasanStandaloneFlowTestRuleblockEnd()Close the current block of repeated componentsIkasanStandaloneFlowTestRuleblockStart()Start a block of repeated componentsIkasanStandaloneFlowTestRulebroker(java.lang.String name)Expect a brokerIkasanStandaloneFlowTestRuleconsumer(java.lang.String name)Expect a consumerIkasanStandaloneFlowTestRuleconverter(java.lang.String name)Expect a converterIkasanStandaloneFlowTestRulefilter(java.lang.String name)Expect a filtervoidfireScheduledConsumer()Invoke the scheduled consumer via its triggerSchedulerNow methodvoidfireScheduledConsumerSynchronously(org.quartz.JobExecutionContext jobExecutionContext)Invoke the scheduled consumer with a given JobExecutionContext (can be mocked).java.lang.ObjectgetComponent(java.lang.String componentName)Gets component of given name from this flow.<T> TgetComponentConfig(java.lang.String componentName, java.lang.Class<T> classType)Gets configuration of component with given name from this flow.org.ikasan.builder.IkasanApplicationgetIkasanApplication()IkasanStandaloneFlowTestRulemultiRecipientRouter(java.lang.String name)Expect a MultiRecipientRouterIkasanStandaloneFlowTestRuleproducer(java.lang.String name)Expect a producerIkasanStandaloneFlowTestRulerepeat(int n)Repeat the current block n times;IkasanStandaloneFlowTestRulerouter(java.lang.String name)Expect a SingleRecipientRouterIkasanStandaloneFlowTestRulescheduledConsumer(java.lang.String name)Expect a consumerIkasanStandaloneFlowTestRulesequencer(java.lang.String name)Expect a sequencervoidsleep(long time)Sleep for a bit to let a flow execution completeIkasanStandaloneFlowTestRulesplitter(java.lang.String name)Expect a splittervoidstartFlow()Setup the flow expectations, make sure that testHarness listener is attached to flow and start the given flow.IkasanStandaloneFlowTestRuletranslator(java.lang.String name)Expect a translatorIkasanStandaloneFlowTestRulewithErrorEndState()Indicate the flow end state will be 'stoppedInError', used in negative testingIkasanStandaloneFlowTestRulewithFlow(org.ikasan.spec.flow.Flow flow)Set the flow which this Rule will check
-
-
-
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:
applyin interfaceorg.junit.rules.TestRule- Parameters:
base- a base Statementdescription- 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
-
blockStart
public IkasanStandaloneFlowTestRule blockStart()
Start a block of repeated components- Returns:
- this rule
-
blockEnd
public IkasanStandaloneFlowTestRule blockEnd()
Close the current block of repeated components- 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 methodThis 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 flowclassType- 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()
-
-