Skip to content

Commit 0dd2200

Browse files
committed
GH-195 - Unnest test cases to make sure we run the right profiles.
Remove the nesting of the test classes as they will be executed without profiles activated.
1 parent 068916a commit 0dd2200

File tree

2 files changed

+103
-99
lines changed

2 files changed

+103
-99
lines changed

spring-modulith-events/spring-modulith-events-jdbc/src/test/java/org/springframework/modulith/events/jdbc/JdbcEventPublicationRepositoryIntegrationTests.java

Lines changed: 87 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class JdbcEventPublicationRepositoryIntegrationTests {
5454

5555
static final PublicationTargetIdentifier TARGET_IDENTIFIER = PublicationTargetIdentifier.of("listener");
5656

57-
@JdbcTest
57+
@JdbcTest(properties = "spring.modulith.events.jdbc.schema-initialization.enabled=true")
5858
@Import(TestApplication.class)
5959
@Testcontainers(disabledWithoutDocker = true)
6060
@ContextConfiguration(classes = JdbcEventPublicationAutoConfiguration.class)
@@ -126,144 +126,132 @@ private void createPublicationAt(LocalDateTime publicationDate) {
126126
repository.create(publication);
127127
}
128128

129-
@Nested
130-
class Update {
131-
132-
@Test // GH-3
133-
void shouldUpdateSingleEventPublication() {
129+
@Test // GH-3
130+
void shouldUpdateSingleEventPublication() {
134131

135-
var testEvent1 = new TestEvent("id1");
136-
var testEvent2 = new TestEvent("id2");
137-
var serializedEvent1 = "{\"eventId\":\"id1\"}";
138-
var serializedEvent2 = "{\"eventId\":\"id2\"}";
132+
var testEvent1 = new TestEvent("id1");
133+
var testEvent2 = new TestEvent("id2");
134+
var serializedEvent1 = "{\"eventId\":\"id1\"}";
135+
var serializedEvent2 = "{\"eventId\":\"id2\"}";
139136

140-
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
141-
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
142-
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
143-
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
137+
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
138+
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
139+
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
140+
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
144141

145-
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
146-
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
142+
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
143+
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
147144

148-
// Store publication
149-
repository.create(publication1);
150-
repository.create(publication2);
145+
// Store publication
146+
repository.create(publication1);
147+
repository.create(publication2);
151148

152-
// Complete publication
153-
repository.update(publication2.markCompleted());
149+
// Complete publication
150+
repository.update(publication2.markCompleted());
154151

155-
assertThat(repository.findIncompletePublications()).hasSize(1)
156-
.element(0).extracting(EventPublication::getEvent).isEqualTo(testEvent1);
157-
}
152+
assertThat(repository.findIncompletePublications()).hasSize(1)
153+
.element(0).extracting(EventPublication::getEvent).isEqualTo(testEvent1);
158154
}
159155

160-
@Nested
161-
class FindByEventAndTargetIdentifier {
162-
163-
@Test // GH-3
164-
void shouldTolerateEmptyResult() {
156+
@Test // GH-3
157+
void shouldTolerateEmptyResult() {
165158

166-
var testEvent = new TestEvent("id");
167-
var serializedEvent = "{\"eventId\":\"id\"}";
159+
var testEvent = new TestEvent("id");
160+
var serializedEvent = "{\"eventId\":\"id\"}";
168161

169-
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
162+
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
170163

171-
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
172-
.isEmpty();
173-
}
164+
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
165+
.isEmpty();
166+
}
174167

175-
@Test // GH-3
176-
void shouldNotReturnCompletedEvents() {
168+
@Test // GH-3
169+
void shouldNotReturnCompletedEvents() {
177170

178-
var testEvent = new TestEvent("id1");
179-
var serializedEvent = "{\"eventId\":\"id1\"}";
171+
var testEvent = new TestEvent("id1");
172+
var serializedEvent = "{\"eventId\":\"id1\"}";
180173

181-
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
182-
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
174+
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
175+
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
183176

184-
var publication = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
177+
var publication = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
185178

186-
repository.create(publication);
187-
repository.update(publication.markCompleted());
179+
repository.create(publication);
180+
repository.update(publication.markCompleted());
188181

189-
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
182+
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
190183

191-
assertThat(actual).isEmpty();
192-
}
184+
assertThat(actual).isEmpty();
185+
}
193186

194-
@Test // GH-3
195-
void shouldReturnTheOldestEvent() throws Exception {
187+
@Test // GH-3
188+
void shouldReturnTheOldestEvent() throws Exception {
196189

197-
var testEvent = new TestEvent("id");
198-
var serializedEvent = "{\"eventId\":\"id\"}";
190+
var testEvent = new TestEvent("id");
191+
var serializedEvent = "{\"eventId\":\"id\"}";
199192

200-
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
201-
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
193+
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
194+
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
202195

203-
var publicationOld = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
204-
Thread.sleep(10);
205-
var publicationNew = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
196+
var publicationOld = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
197+
Thread.sleep(10);
198+
var publicationNew = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
206199

207-
repository.create(publicationNew);
208-
repository.create(publicationOld);
200+
repository.create(publicationNew);
201+
repository.create(publicationOld);
209202

210-
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
203+
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
211204

212-
assertThat(actual).hasValueSatisfying(it -> {
213-
assertThat(it.getPublicationDate()) //
214-
.isCloseTo(publicationOld.getPublicationDate(), within(1, ChronoUnit.MILLIS));
215-
});
216-
}
205+
assertThat(actual).hasValueSatisfying(it -> {
206+
assertThat(it.getPublicationDate()) //
207+
.isCloseTo(publicationOld.getPublicationDate(), within(1, ChronoUnit.MILLIS));
208+
});
209+
}
217210

218-
@Test
219-
// GH-3
220-
void shouldSilentlyIgnoreNotSerializableEvents() {
211+
@Test
212+
// GH-3
213+
void shouldSilentlyIgnoreNotSerializableEvents() {
221214

222-
var testEvent = new TestEvent("id");
223-
var serializedEvent = "{\"eventId\":\"id\"}";
215+
var testEvent = new TestEvent("id");
216+
var serializedEvent = "{\"eventId\":\"id\"}";
224217

225-
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
226-
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
218+
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
219+
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
227220

228-
// Store publication
229-
repository.create(CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER));
221+
// Store publication
222+
repository.create(CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER));
230223

231-
operations.update("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'");
224+
operations.update("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'");
232225

233-
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
234-
.isEmpty();
235-
}
226+
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
227+
.isEmpty();
236228
}
237229

238-
@Nested
239-
class DeleteCompletedPublications {
240-
241-
@Test // GH-20
242-
void shouldDeleteCompletedEvents() {
230+
@Test // GH-20
231+
void shouldDeleteCompletedEvents() {
243232

244-
var testEvent1 = new TestEvent("abc");
245-
var serializedEvent1 = "{\"eventId\":\"abc\"}";
246-
var testEvent2 = new TestEvent("def");
247-
var serializedEvent2 = "{\"eventId\":\"def\"}";
233+
var testEvent1 = new TestEvent("abc");
234+
var serializedEvent1 = "{\"eventId\":\"abc\"}";
235+
var testEvent2 = new TestEvent("def");
236+
var serializedEvent2 = "{\"eventId\":\"def\"}";
248237

249-
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
250-
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
251-
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
252-
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
238+
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
239+
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
240+
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
241+
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
253242

254-
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
255-
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
243+
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
244+
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
256245

257-
repository.create(publication1);
258-
repository.create(publication2);
246+
repository.create(publication1);
247+
repository.create(publication2);
259248

260-
repository.update(publication1.markCompleted());
249+
repository.update(publication1.markCompleted());
261250

262-
repository.deleteCompletedPublications();
251+
repository.deleteCompletedPublications();
263252

264-
assertThat(operations.query("SELECT * FROM EVENT_PUBLICATION", (rs, __) -> rs.getString("SERIALIZED_EVENT")))
265-
.hasSize(1).element(0).isEqualTo(serializedEvent2);
266-
}
253+
assertThat(operations.query("SELECT * FROM EVENT_PUBLICATION", (rs, __) -> rs.getString("SERIALIZED_EVENT")))
254+
.hasSize(1).element(0).isEqualTo(serializedEvent2);
267255
}
268256
}
269257

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
4+
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
5+
<encoder>
6+
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="error">
11+
<appender-ref ref="console" />
12+
</root>
13+
14+
<!--<logger name="org.springframework.modulith" level="info" />-->
15+
16+
</configuration>

0 commit comments

Comments
 (0)