Class Scenario
java.lang.Object
org.springframework.modulith.test.Scenario
A DSL to define integration testing scenarios for application modules. A
Scenario
starts with a stimulus on
the system, usually a component invocation (see stimulate(Function)
or event publication (see
publish(Object...)
) and a definition of the expected outcome. That can be a state change observed by
invoking application module components (see Scenario.When.andWaitForStateChange(Supplier)
) or another event being
published (see Scenario.When.andWaitForEventOfType(Class)
), concluded by additional verifications.
Scenario
can be used as JUnit test method parameter in ApplicationModuleTest
s.
- Author:
- Oliver Drotbohm
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionScenario
(TransactionTemplate transactionTemplate, ApplicationEventPublisher publisher, AssertablePublishedEvents events) Creates a newScenario
for the givenTransactionTemplate
,ApplicationEventPublisher
andAssertablePublishedEvents
. -
Method Summary
Modifier and TypeMethodDescriptionPublishes the given event.Publishes the event provided by the givenSupplier
.(package private) Scenario
setDefaultCustomizer
(Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) Extension hook to allow registration of a global customizer.Stimulates the system by executing the givenRunnable
.Stimulate the system using the givenTransactionOperations
andApplicationEventPublisher
.<S> Scenario.When<S>
Stimulate the system using the givenTransactionOperations
andApplicationEventPublisher
and produce a result.<S> Scenario.When<S>
stimulate
(Function<TransactionOperations, S> function) Stimulates the system using the given function providing access to theTransactionOperations
and keeping the supplied value around for later verification.<S> Scenario.When<S>
Stimulates the system using the givenSupplier
and keeping the supplied value around for later verification.
-
Constructor Details
-
Scenario
Scenario(TransactionTemplate transactionTemplate, ApplicationEventPublisher publisher, AssertablePublishedEvents events) Creates a newScenario
for the givenTransactionTemplate
,ApplicationEventPublisher
andAssertablePublishedEvents
.- Parameters:
transactionTemplate
- must not be null.publisher
- must not be null.events
- must not be null.
-
-
Method Details
-
publish
Publishes the given event. The event will be published in a transaction to make sure that transactional event listeners are invoked as well.- Parameters:
event
- must not be null.- Returns:
- will never be null.
-
publish
Publishes the event provided by the givenSupplier
. The event will be published in a transaction to make sure that transactional event listeners are invoked as well.- Parameters:
event
- must not be null.- Returns:
- will never be null.
-
stimulate
Stimulates the system by executing the givenRunnable
.- Parameters:
runnable
- must not be null.- Returns:
- will never be null.
-
stimulate
Stimulates the system using the givenSupplier
and keeping the supplied value around for later verification.- Type Parameters:
S
- the type of the value returned by the stimulus.- Parameters:
supplier
- must not be null.- Returns:
- will never be null.
- See Also:
-
stimulate
Stimulates the system using the given function providing access to theTransactionOperations
and keeping the supplied value around for later verification.- Type Parameters:
S
- the type of the value returned by the stimulus.- Parameters:
function
- must not be null.- Returns:
- will never be null.
-
stimulate
public Scenario.When<Void> stimulate(BiConsumer<TransactionOperations, ApplicationEventPublisher> stimulus) Stimulate the system using the givenTransactionOperations
andApplicationEventPublisher
. Usually a method on some application service or event publication is triggered.- Parameters:
stimulus
- must not be null.- Returns:
- will never be null.
-
stimulate
public <S> Scenario.When<S> stimulate(BiFunction<TransactionOperations, ApplicationEventPublisher, S> stimulus) Stimulate the system using the givenTransactionOperations
andApplicationEventPublisher
and produce a result. Usually a method on some application service or event publication is triggered.- Type Parameters:
S
- the type of the result.- Parameters:
stimulus
- must not be null.- Returns:
- will never be null.
-
setDefaultCustomizer
Scenario setDefaultCustomizer(Function<org.awaitility.core.ConditionFactory, org.awaitility.core.ConditionFactory> customizer) Extension hook to allow registration of a global customizer. If none configured we will fall back toFunction.identity()
.- Parameters:
customizer
- must not be null.- See Also:
-