Skip to content

Commit 2f93e44

Browse files
committed
GH-136 - Introduce Scenario as application module integration test API.
See the Javadoc of Scenario for details.
1 parent 9428d3b commit 2f93e44

File tree

9 files changed

+1177
-31
lines changed

9 files changed

+1177
-31
lines changed

spring-modulith-test/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
<artifactId>spring-test</artifactId>
4040
</dependency>
4141

42+
<dependency>
43+
<groupId>org.springframework</groupId>
44+
<artifactId>spring-tx</artifactId>
45+
</dependency>
46+
4247
<dependency>
4348
<groupId>org.assertj</groupId>
4449
<artifactId>assertj-core</artifactId>
@@ -59,7 +64,6 @@
5964
<dependency>
6065
<groupId>org.awaitility</groupId>
6166
<artifactId>awaitility</artifactId>
62-
<scope>test</scope>
6367
</dependency>
6468

6569
</dependencies>

spring-modulith-test/src/main/java/org/springframework/modulith/test/ApplicationModuleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
@BootstrapWith(SpringBootTestContextBootstrapper.class)
4848
@TypeExcludeFilters(ModuleTypeExcludeFilter.class)
4949
@ImportAutoConfiguration(ModuleTestAutoConfiguration.class)
50-
@ExtendWith(SpringExtension.class)
51-
@ExtendWith(PublishedEventsParameterResolver.class)
50+
@ExtendWith({ SpringExtension.class, PublishedEventsParameterResolver.class, ScenarioParameterResolver.class })
5251
@TestInstance(Lifecycle.PER_CLASS)
5352
@TestConstructor(autowireMode = AutowireMode.ALL)
5453
public @interface ApplicationModuleTest {

spring-modulith-test/src/main/java/org/springframework/modulith/test/DefaultPublishedEvents.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ private static <T> SimpleTypedPublishedEvents<T> of(Stream<T> stream) {
100100

101101
/*
102102
* (non-Javadoc)
103-
* @see org.springframework.modulith.test.PublishedEvents.TypedPublishedEvents#ofSubType(java.lang.Class)
103+
* @see org.springframework.modulith.test.PublishedEvents.TypedPublishedEvents#ofType(java.lang.Class)
104104
*/
105105
@Override
106-
public <S extends T> TypedPublishedEvents<S> ofSubType(Class<S> subType) {
106+
public <S> TypedPublishedEvents<S> ofType(Class<S> type) {
107107

108-
return SimpleTypedPublishedEvents.of(getFilteredEvents(subType::isInstance) //
109-
.map(subType::cast));
108+
return SimpleTypedPublishedEvents.of(getFilteredEvents(type::isInstance) //
109+
.map(type::cast));
110110
}
111111

112112
/*

spring-modulith-test/src/main/java/org/springframework/modulith/test/PublishedEvents.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*
2929
* @author Oliver Drotbohm
3030
*/
31-
public interface PublishedEvents {
31+
public interface PublishedEvents extends TypedEvents {
3232

3333
/**
3434
* Creates a new {@link PublishedEvents} instance for the given events.
@@ -53,35 +53,19 @@ public static PublishedEvents of(Collection<? extends Object> events) {
5353
return new DefaultPublishedEvents(events);
5454
}
5555

56-
/**
57-
* Returns all application events of the given type that were fired during the test execution.
58-
*
59-
* @param <T> the event type
60-
* @param type must not be {@literal null}.
61-
* @return
56+
/*
57+
* (non-Javadoc)
58+
* @see org.springframework.modulith.test.TypedEvents#ofType(java.lang.Class)
6259
*/
6360
<T> TypedPublishedEvents<T> ofType(Class<T> type);
6461

65-
/**
66-
* Returns whether an event of the given type was published.
67-
*
68-
* @param type must not be {@literal null}.
69-
* @return whether an event of the given type was published.
70-
*/
71-
default boolean eventOfTypeWasPublished(Class<?> type) {
72-
73-
Assert.notNull(type, "Event type must not be null!");
74-
75-
return ofType(type).iterator().hasNext();
76-
}
77-
7862
/**
7963
* All application events of a given type that were fired during a test execution.
8064
*
8165
* @author Oliver Drotbohm
8266
* @param <T> the event type
8367
*/
84-
interface TypedPublishedEvents<T> extends Iterable<T> {
68+
interface TypedPublishedEvents<T> extends Iterable<T>, TypedEvents {
8569

8670
/**
8771
* Further constrain the event type for downstream assertions.
@@ -90,7 +74,16 @@ interface TypedPublishedEvents<T> extends Iterable<T> {
9074
* @param subType the sub type
9175
* @return will never be {@literal null}.
9276
*/
93-
<S extends T> TypedPublishedEvents<S> ofSubType(Class<S> subType);
77+
default <S extends T> TypedPublishedEvents<S> ofSubType(Class<S> subType) {
78+
return ofType(subType);
79+
}
80+
81+
/*
82+
* (non-Javadoc)
83+
* @see org.springframework.modulith.test.TypedEvents#ofType(java.lang.Class)
84+
*/
85+
@Override
86+
<S> TypedPublishedEvents<S> ofType(Class<S> type);
9487

9588
/**
9689
* Returns all {@link TypedPublishedEvents} that match the given predicate.

spring-modulith-test/src/main/java/org/springframework/modulith/test/PublishedEventsAssert.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
* @author Oliver Drotbohm
3232
* @see AssertablePublishedEvents
3333
*/
34-
public class PublishedEventsAssert extends AbstractAssert<PublishedEventsAssert, PublishedEvents> {
34+
public class PublishedEventsAssert extends AbstractAssert<PublishedEventsAssert, TypedEvents> {
3535

3636
/**
3737
* Creates a new {@link PublishedEventsAssert}
3838
*
3939
* @param actual must not be {@literal null}.
4040
*/
41-
PublishedEventsAssert(AssertablePublishedEvents actual) {
41+
PublishedEventsAssert(TypedEvents actual) {
4242
super(actual, PublishedEventsAssert.class);
4343
}
4444

0 commit comments

Comments
 (0)