Skip to content

Commit

Permalink
completes Integration Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangsa committed Dec 29, 2024
1 parent 0910e3a commit 3c44d99
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<spring-boot.version>3.4.0</spring-boot.version>
<spring-cloud.version>2023.0.3</spring-cloud.version>
<spring-cloud.version>2024.0.0</spring-cloud.version>
<spring-cloud-stream-schema.version>2.2.1.RELEASE</spring-cloud-stream-schema.version>
<avro.version>1.11.4</avro.version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import io.zenwave360.modulith.events.scs.config.EventSerializerConfiguration;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.Message;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.verify;

@SpringBootTest(classes = { TestsConfiguration.class })
@Import({ EventSerializerConfiguration.class })
@Transactional
Expand All @@ -16,17 +25,27 @@ public class SCSAvroEventExternalizerTest {
@Autowired
TestsConfiguration.CustomerEventsProducer customerEventsProducer;

@Autowired
JdbcTemplate jdbcTemplate;
@MockitoSpyBean
private StreamBridge streamBridge;

@Test
void testExternalizeAvroEvent() throws InterruptedException {
var event = new io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent();
event.setName("John Doe");

customerEventsProducer.onCustomerEventAvro(event);

// Wait for the event to be externalized
Thread.sleep(5000);
// TODO: Assert that the event was externalized
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
verify(streamBridge).send(Mockito.eq("customers-avro-out-0"), Mockito.argThat(message -> {
if (message instanceof Message<?>) {
var payload = ((Message<?>) message).getPayload();
return payload instanceof io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent
&& "John Doe".equals(((io.zenwave360.modulith.events.scs.dtos.avro.CustomerEvent) payload).getName());
}
return false;
}));
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@

import io.zenwave360.modulith.events.scs.config.EventSerializerConfiguration;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.Message;
import org.springframework.test.context.bean.override.mockito.MockitoSpyBean;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.mockito.Mockito.verify;

@SpringBootTest(classes = { TestsConfiguration.class })
@Import({ EventSerializerConfiguration.class })
@Transactional
Expand All @@ -16,16 +25,25 @@ public class SCSJsonEventExternalizerTest {
@Autowired
TestsConfiguration.CustomerEventsProducer customerEventsProducer;

@Autowired
JdbcTemplate jdbcTemplate;
@MockitoSpyBean
private StreamBridge streamBridge;

@Test
void testExternalizeJsonEvent() throws InterruptedException {
var event = new io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent().withName("John Doe");
customerEventsProducer.onCustomerEventJson(event);

// Wait for the event to be externalized
Thread.sleep(5000);
// TODO: Assert that the event was externalized
await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
verify(streamBridge).send(Mockito.eq("customers-json-out-0"), Mockito.argThat(message -> {
if (message instanceof Message<?>) {
var payload = ((Message<?>) message).getPayload();
return payload instanceof io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent
&& "John Doe".equals(((io.zenwave360.modulith.events.scs.dtos.json.CustomerEvent) payload).getName());
}
return false;
}));
});
}

}

0 comments on commit 3c44d99

Please sign in to comment.