@@ -54,7 +54,7 @@ class JdbcEventPublicationRepositoryIntegrationTests {
54
54
55
55
static final PublicationTargetIdentifier TARGET_IDENTIFIER = PublicationTargetIdentifier .of ("listener" );
56
56
57
- @ JdbcTest
57
+ @ JdbcTest ( properties = "spring.modulith.events.jdbc.schema-initialization.enabled=true" )
58
58
@ Import (TestApplication .class )
59
59
@ Testcontainers (disabledWithoutDocker = true )
60
60
@ ContextConfiguration (classes = JdbcEventPublicationAutoConfiguration .class )
@@ -126,144 +126,132 @@ private void createPublicationAt(LocalDateTime publicationDate) {
126
126
repository .create (publication );
127
127
}
128
128
129
- @ Nested
130
- class Update {
131
-
132
- @ Test // GH-3
133
- void shouldUpdateSingleEventPublication () {
129
+ @ Test // GH-3
130
+ void shouldUpdateSingleEventPublication () {
134
131
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\" }" ;
139
136
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 );
144
141
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 );
147
144
148
- // Store publication
149
- repository .create (publication1 );
150
- repository .create (publication2 );
145
+ // Store publication
146
+ repository .create (publication1 );
147
+ repository .create (publication2 );
151
148
152
- // Complete publication
153
- repository .update (publication2 .markCompleted ());
149
+ // Complete publication
150
+ repository .update (publication2 .markCompleted ());
154
151
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 );
158
154
}
159
155
160
- @ Nested
161
- class FindByEventAndTargetIdentifier {
162
-
163
- @ Test // GH-3
164
- void shouldTolerateEmptyResult () {
156
+ @ Test // GH-3
157
+ void shouldTolerateEmptyResult () {
165
158
166
- var testEvent = new TestEvent ("id" );
167
- var serializedEvent = "{\" eventId\" :\" id\" }" ;
159
+ var testEvent = new TestEvent ("id" );
160
+ var serializedEvent = "{\" eventId\" :\" id\" }" ;
168
161
169
- when (serializer .serialize (testEvent )).thenReturn (serializedEvent );
162
+ when (serializer .serialize (testEvent )).thenReturn (serializedEvent );
170
163
171
- assertThat (repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER ))
172
- .isEmpty ();
173
- }
164
+ assertThat (repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER ))
165
+ .isEmpty ();
166
+ }
174
167
175
- @ Test // GH-3
176
- void shouldNotReturnCompletedEvents () {
168
+ @ Test // GH-3
169
+ void shouldNotReturnCompletedEvents () {
177
170
178
- var testEvent = new TestEvent ("id1" );
179
- var serializedEvent = "{\" eventId\" :\" id1\" }" ;
171
+ var testEvent = new TestEvent ("id1" );
172
+ var serializedEvent = "{\" eventId\" :\" id1\" }" ;
180
173
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 );
183
176
184
- var publication = CompletableEventPublication .of (testEvent , TARGET_IDENTIFIER );
177
+ var publication = CompletableEventPublication .of (testEvent , TARGET_IDENTIFIER );
185
178
186
- repository .create (publication );
187
- repository .update (publication .markCompleted ());
179
+ repository .create (publication );
180
+ repository .update (publication .markCompleted ());
188
181
189
- var actual = repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER );
182
+ var actual = repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER );
190
183
191
- assertThat (actual ).isEmpty ();
192
- }
184
+ assertThat (actual ).isEmpty ();
185
+ }
193
186
194
- @ Test // GH-3
195
- void shouldReturnTheOldestEvent () throws Exception {
187
+ @ Test // GH-3
188
+ void shouldReturnTheOldestEvent () throws Exception {
196
189
197
- var testEvent = new TestEvent ("id" );
198
- var serializedEvent = "{\" eventId\" :\" id\" }" ;
190
+ var testEvent = new TestEvent ("id" );
191
+ var serializedEvent = "{\" eventId\" :\" id\" }" ;
199
192
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 );
202
195
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 );
206
199
207
- repository .create (publicationNew );
208
- repository .create (publicationOld );
200
+ repository .create (publicationNew );
201
+ repository .create (publicationOld );
209
202
210
- var actual = repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER );
203
+ var actual = repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER );
211
204
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
+ }
217
210
218
- @ Test
219
- // GH-3
220
- void shouldSilentlyIgnoreNotSerializableEvents () {
211
+ @ Test
212
+ // GH-3
213
+ void shouldSilentlyIgnoreNotSerializableEvents () {
221
214
222
- var testEvent = new TestEvent ("id" );
223
- var serializedEvent = "{\" eventId\" :\" id\" }" ;
215
+ var testEvent = new TestEvent ("id" );
216
+ var serializedEvent = "{\" eventId\" :\" id\" }" ;
224
217
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 );
227
220
228
- // Store publication
229
- repository .create (CompletableEventPublication .of (testEvent , TARGET_IDENTIFIER ));
221
+ // Store publication
222
+ repository .create (CompletableEventPublication .of (testEvent , TARGET_IDENTIFIER ));
230
223
231
- operations .update ("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'" );
224
+ operations .update ("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'" );
232
225
233
- assertThat (repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER ))
234
- .isEmpty ();
235
- }
226
+ assertThat (repository .findIncompletePublicationsByEventAndTargetIdentifier (testEvent , TARGET_IDENTIFIER ))
227
+ .isEmpty ();
236
228
}
237
229
238
- @ Nested
239
- class DeleteCompletedPublications {
240
-
241
- @ Test // GH-20
242
- void shouldDeleteCompletedEvents () {
230
+ @ Test // GH-20
231
+ void shouldDeleteCompletedEvents () {
243
232
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\" }" ;
248
237
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 );
253
242
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 );
256
245
257
- repository .create (publication1 );
258
- repository .create (publication2 );
246
+ repository .create (publication1 );
247
+ repository .create (publication2 );
259
248
260
- repository .update (publication1 .markCompleted ());
249
+ repository .update (publication1 .markCompleted ());
261
250
262
- repository .deleteCompletedPublications ();
251
+ repository .deleteCompletedPublications ();
263
252
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 );
267
255
}
268
256
}
269
257
0 commit comments