From 4b3c0e87c9dc2e62eb760e558a2c2146f8232151 Mon Sep 17 00:00:00 2001 From: msafonov Date: Tue, 17 Mar 2020 10:26:29 +0300 Subject: [PATCH] test(integration): added test for transceiver connection type --- build.gradle | 1 + .../transceiver/TransceiverConfiguration.java | 20 +++++ .../smpp/transceiver/TransceiverTest.java | 87 +++++++++++++++++++ .../application-transceiver.properties | 5 ++ .../bootstrap-transceiver.properties | 2 + 5 files changed, 115 insertions(+) create mode 100644 src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverConfiguration.java create mode 100644 src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverTest.java create mode 100644 src/testIntegration/resources/application-transceiver.properties create mode 100644 src/testIntegration/resources/bootstrap-transceiver.properties diff --git a/build.gradle b/build.gradle index b4470d7..654b245 100644 --- a/build.gradle +++ b/build.gradle @@ -78,6 +78,7 @@ dependencies { testIntegrationImplementation platform("org.springframework.cloud:spring-cloud-dependencies:Hoxton.SR3") testIntegrationImplementation("org.springframework.cloud:spring-cloud-starter") + testIntegrationImplementation("org.awaitility:awaitility:4.0.1") testIntegrationImplementation("com.github.mikesafonov:smpp-server-mock-assertj:1.5.0") testIntegrationImplementation("com.github.mikesafonov:smpp-server-mock-junit:1.5.0") testIntegrationImplementation("com.github.mikesafonov:smpp-server-mock-spring-boot:1.5.0") diff --git a/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverConfiguration.java b/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverConfiguration.java new file mode 100644 index 0000000..9707e9b --- /dev/null +++ b/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverConfiguration.java @@ -0,0 +1,20 @@ +package com.github.mikesafonov.smpp.transceiver; + +import com.github.mikesafonov.smpp.core.reciever.DeliveryReportConsumer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import static org.mockito.Mockito.mock; + +/** + * @author Mike Safonov + */ +@Configuration +public class TransceiverConfiguration { + + @Bean + public DeliveryReportConsumer deliveryReportConsumer() { + return mock(DeliveryReportConsumer.class); + } + +} diff --git a/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverTest.java b/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverTest.java new file mode 100644 index 0000000..9861d34 --- /dev/null +++ b/src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverTest.java @@ -0,0 +1,87 @@ +package com.github.mikesafonov.smpp.transceiver; + +import com.github.mikesafonov.smpp.api.SenderManager; +import com.github.mikesafonov.smpp.assertj.SmppAssertions; +import com.github.mikesafonov.smpp.config.SmppAutoConfiguration; +import com.github.mikesafonov.smpp.core.dto.DeliveryReport; +import com.github.mikesafonov.smpp.core.dto.Message; +import com.github.mikesafonov.smpp.core.dto.MessageResponse; +import com.github.mikesafonov.smpp.core.reciever.DeliveryReportConsumer; +import com.github.mikesafonov.smpp.server.MockSmppServer; +import com.github.mikesafonov.smpp.server.MockSmppServerHolder; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.*; +import org.mockito.ArgumentCaptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.verify; + +/** + * @author Mike Safonov + */ +@ActiveProfiles("transceiver") +@SpringBootTest(classes = {TransceiverConfiguration.class, SmppAutoConfiguration.class}) +@TestPropertySource( + locations = "classpath:application-transceiver.properties") +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TransceiverTest { + @Autowired + private SenderManager senderManager; + + @Autowired + private DeliveryReportConsumer deliveryReportConsumer; + + @Autowired + private MockSmppServerHolder smppServerHolder; + private Message message; + + @BeforeEach + void clearAll() { + smppServerHolder.clearAll(); + message = Message.simple("my message") + .from("3322") + .to("2233") + .build(); + } + + @AfterAll + void stopAll() { + smppServerHolder.stopAll(); + } + + @Test + void shouldOpenOneConnection() { + MockSmppServer smppServer = smppServerHolder.getByName("one").get(); + assertThat(smppServer).extracting("handler.sessions.size").isEqualTo(1); + } + + @Test + void shouldSendMessage() { + senderManager.getByName("one").send(message); + SmppAssertions.assertThat(smppServerHolder).serverByName("one").hasSingleMessage() + .hasDest("2233") + .hasSource("3322") + .hasText("my message") + .hasDeliveryReport(); + } + + @Test + void shouldReceiveDeliveryReport() { + MessageResponse response = senderManager.getByName("one").send(message); + ArgumentCaptor captor = ArgumentCaptor.forClass(DeliveryReport.class); + + await().atMost(1, TimeUnit.SECONDS) + .untilAsserted(() -> verify(deliveryReportConsumer).accept(captor.capture())); + + DeliveryReport report = captor.getValue(); + + assertEquals(response.getSmscMessageID(), report.getMessageId()); + assertEquals("one", report.getResponseClientId()); + } +} diff --git a/src/testIntegration/resources/application-transceiver.properties b/src/testIntegration/resources/application-transceiver.properties new file mode 100644 index 0000000..6e90603 --- /dev/null +++ b/src/testIntegration/resources/application-transceiver.properties @@ -0,0 +1,5 @@ +smpp.defaults.connectionType=transceiver +smpp.connections.one.credentials.host=${smpp.mocks.one.host} +smpp.connections.one.credentials.username=${smpp.mocks.one.system-id} +smpp.connections.one.credentials.password=${smpp.mocks.one.password} +smpp.connections.one.credentials.port=${smpp.mocks.one.port} diff --git a/src/testIntegration/resources/bootstrap-transceiver.properties b/src/testIntegration/resources/bootstrap-transceiver.properties new file mode 100644 index 0000000..ba28a8b --- /dev/null +++ b/src/testIntegration/resources/bootstrap-transceiver.properties @@ -0,0 +1,2 @@ +smpp.mocks.one.password=pass +smpp.mocks.one.system-id=user