Skip to content

Commit

Permalink
GH-195 - Unnest test cases to make sure we run the right profiles.
Browse files Browse the repository at this point in the history
Remove the nesting of the test classes as they will be executed without profiles activated.
  • Loading branch information
odrotbohm committed Jun 23, 2023
1 parent 068916a commit 0dd2200
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class JdbcEventPublicationRepositoryIntegrationTests {

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

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

@Nested
class Update {

@Test // GH-3
void shouldUpdateSingleEventPublication() {
@Test // GH-3
void shouldUpdateSingleEventPublication() {

var testEvent1 = new TestEvent("id1");
var testEvent2 = new TestEvent("id2");
var serializedEvent1 = "{\"eventId\":\"id1\"}";
var serializedEvent2 = "{\"eventId\":\"id2\"}";
var testEvent1 = new TestEvent("id1");
var testEvent2 = new TestEvent("id2");
var serializedEvent1 = "{\"eventId\":\"id1\"}";
var serializedEvent2 = "{\"eventId\":\"id2\"}";

when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);

var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);

// Store publication
repository.create(publication1);
repository.create(publication2);
// Store publication
repository.create(publication1);
repository.create(publication2);

// Complete publication
repository.update(publication2.markCompleted());
// Complete publication
repository.update(publication2.markCompleted());

assertThat(repository.findIncompletePublications()).hasSize(1)
.element(0).extracting(EventPublication::getEvent).isEqualTo(testEvent1);
}
assertThat(repository.findIncompletePublications()).hasSize(1)
.element(0).extracting(EventPublication::getEvent).isEqualTo(testEvent1);
}

@Nested
class FindByEventAndTargetIdentifier {

@Test // GH-3
void shouldTolerateEmptyResult() {
@Test // GH-3
void shouldTolerateEmptyResult() {

var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";
var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";

when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);

assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
.isEmpty();
}
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
.isEmpty();
}

@Test // GH-3
void shouldNotReturnCompletedEvents() {
@Test // GH-3
void shouldNotReturnCompletedEvents() {

var testEvent = new TestEvent("id1");
var serializedEvent = "{\"eventId\":\"id1\"}";
var testEvent = new TestEvent("id1");
var serializedEvent = "{\"eventId\":\"id1\"}";

when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);

var publication = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
var publication = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);

repository.create(publication);
repository.update(publication.markCompleted());
repository.create(publication);
repository.update(publication.markCompleted());

var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);

assertThat(actual).isEmpty();
}
assertThat(actual).isEmpty();
}

@Test // GH-3
void shouldReturnTheOldestEvent() throws Exception {
@Test // GH-3
void shouldReturnTheOldestEvent() throws Exception {

var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";
var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";

when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);

var publicationOld = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
Thread.sleep(10);
var publicationNew = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
var publicationOld = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);
Thread.sleep(10);
var publicationNew = CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER);

repository.create(publicationNew);
repository.create(publicationOld);
repository.create(publicationNew);
repository.create(publicationOld);

var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);
var actual = repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER);

assertThat(actual).hasValueSatisfying(it -> {
assertThat(it.getPublicationDate()) //
.isCloseTo(publicationOld.getPublicationDate(), within(1, ChronoUnit.MILLIS));
});
}
assertThat(actual).hasValueSatisfying(it -> {
assertThat(it.getPublicationDate()) //
.isCloseTo(publicationOld.getPublicationDate(), within(1, ChronoUnit.MILLIS));
});
}

@Test
// GH-3
void shouldSilentlyIgnoreNotSerializableEvents() {
@Test
// GH-3
void shouldSilentlyIgnoreNotSerializableEvents() {

var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";
var testEvent = new TestEvent("id");
var serializedEvent = "{\"eventId\":\"id\"}";

when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);
when(serializer.serialize(testEvent)).thenReturn(serializedEvent);
when(serializer.deserialize(serializedEvent, TestEvent.class)).thenReturn(testEvent);

// Store publication
repository.create(CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER));
// Store publication
repository.create(CompletableEventPublication.of(testEvent, TARGET_IDENTIFIER));

operations.update("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'");
operations.update("UPDATE EVENT_PUBLICATION SET EVENT_TYPE='abc'");

assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
.isEmpty();
}
assertThat(repository.findIncompletePublicationsByEventAndTargetIdentifier(testEvent, TARGET_IDENTIFIER))
.isEmpty();
}

@Nested
class DeleteCompletedPublications {

@Test // GH-20
void shouldDeleteCompletedEvents() {
@Test // GH-20
void shouldDeleteCompletedEvents() {

var testEvent1 = new TestEvent("abc");
var serializedEvent1 = "{\"eventId\":\"abc\"}";
var testEvent2 = new TestEvent("def");
var serializedEvent2 = "{\"eventId\":\"def\"}";
var testEvent1 = new TestEvent("abc");
var serializedEvent1 = "{\"eventId\":\"abc\"}";
var testEvent2 = new TestEvent("def");
var serializedEvent2 = "{\"eventId\":\"def\"}";

when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);
when(serializer.serialize(testEvent1)).thenReturn(serializedEvent1);
when(serializer.deserialize(serializedEvent1, TestEvent.class)).thenReturn(testEvent1);
when(serializer.serialize(testEvent2)).thenReturn(serializedEvent2);
when(serializer.deserialize(serializedEvent2, TestEvent.class)).thenReturn(testEvent2);

var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);
var publication1 = CompletableEventPublication.of(testEvent1, TARGET_IDENTIFIER);
var publication2 = CompletableEventPublication.of(testEvent2, TARGET_IDENTIFIER);

repository.create(publication1);
repository.create(publication2);
repository.create(publication1);
repository.create(publication2);

repository.update(publication1.markCompleted());
repository.update(publication1.markCompleted());

repository.deleteCompletedPublications();
repository.deleteCompletedPublications();

assertThat(operations.query("SELECT * FROM EVENT_PUBLICATION", (rs, __) -> rs.getString("SERIALIZED_EVENT")))
.hasSize(1).element(0).isEqualTo(serializedEvent2);
}
assertThat(operations.query("SELECT * FROM EVENT_PUBLICATION", (rs, __) -> rs.getString("SERIALIZED_EVENT")))
.hasSize(1).element(0).isEqualTo(serializedEvent2);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>

<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d %5p %40.40c:%4L - %m%n</pattern>
</encoder>
</appender>

<root level="error">
<appender-ref ref="console" />
</root>

<!--<logger name="org.springframework.modulith" level="info" />-->

</configuration>

0 comments on commit 0dd2200

Please sign in to comment.