-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
168 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
dina-messaging/src/test/java/ca/gc/aafc/dina/messaging/ErrorHandlingProducerIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package ca.gc.aafc.dina.messaging; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.amqp.core.ReturnedMessage; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
import org.testcontainers.containers.RabbitMQContainer; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
@SpringBootTest( | ||
properties = { | ||
"dina.messaging.isProducer=true", | ||
"dina.messaging.isConsumer=false" | ||
} | ||
) | ||
@Import(ErrorHandlingProducerIT.RabbitTemplateTestConfig.class) | ||
public class ErrorHandlingProducerIT { | ||
|
||
public static final RabbitMQContainer rabbitMQContainer = new RabbitMQContainer("rabbitmq:3.8.20-management-alpine"); | ||
|
||
@Inject | ||
private RabbitTemplateTestConfig rabbitTemplateTestConfig; | ||
|
||
@Inject | ||
private RabbitTemplate rabbitTemplate; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
rabbitMQContainer.start(); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
rabbitMQContainer.stop(); | ||
} | ||
|
||
@DynamicPropertySource | ||
static void registerRabbitMQProperties(DynamicPropertyRegistry registry) { | ||
registry.add("rabbitmq.host", rabbitMQContainer::getHost); | ||
registry.add("rabbitmq.port", rabbitMQContainer::getAmqpPort); | ||
registry.add("rabbitmq.username", rabbitMQContainer::getAdminUsername); | ||
registry.add("rabbitmq.password", rabbitMQContainer::getAdminPassword); | ||
} | ||
|
||
@Test | ||
public void sendMessageToNonExistentQueue_receiverReceives() throws InterruptedException { | ||
DinaTestMessage myMessage = new DinaTestMessage("test-message Queue non-existing"); | ||
rabbitTemplate.convertAndSend("non-existing", myMessage); | ||
|
||
assertTrue(rabbitTemplateTestConfig.getLatch().await(1000, TimeUnit.MILLISECONDS)); | ||
assertNotNull(rabbitTemplateTestConfig.getReturnedMessage()); | ||
} | ||
|
||
@TestConfiguration | ||
public static class RabbitTemplateTestConfig { | ||
|
||
private final CountDownLatch latch = new CountDownLatch(1); | ||
private ReturnedMessage returnedMessage; | ||
|
||
public CountDownLatch getLatch() { | ||
return latch; | ||
} | ||
|
||
public ReturnedMessage getReturnedMessage() { | ||
return returnedMessage; | ||
} | ||
|
||
@Bean | ||
public RabbitTemplate.ReturnsCallback returnCallback() { | ||
return m -> { | ||
returnedMessage = m; | ||
latch.countDown(); | ||
}; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dina-messaging/src/test/java/ca/gc/aafc/dina/messaging/MessagingTestApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package ca.gc.aafc.dina.messaging; | ||
|
||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; | ||
|
||
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class) | ||
public class MessagingTestApplication { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...messaging/src/test/java/ca/gc/aafc/dina/messaging/message/ObjectExportNotificationIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package ca.gc.aafc.dina.messaging.message; | ||
|
||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
|
||
import ca.gc.aafc.dina.testsupport.TestResourceHelper; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class ObjectExportNotificationIT { | ||
|
||
@Test | ||
public void testSerDe() throws JsonProcessingException { | ||
|
||
ObjectExportNotification oen = ObjectExportNotification.builder() | ||
.uuid(UUID.randomUUID()) | ||
.username("user") | ||
.toa("toa").build(); | ||
|
||
String asJson = TestResourceHelper.OBJECT_MAPPER.writeValueAsString(oen); | ||
|
||
ObjectExportNotification oen2 = TestResourceHelper.OBJECT_MAPPER.readValue(asJson, ObjectExportNotification.class); | ||
assertEquals(oen, oen2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters