-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(integration): added test for transceiver connection type
- Loading branch information
1 parent
00fdad0
commit 4b3c0e8
Showing
5 changed files
with
115 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
...estIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverConfiguration.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,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); | ||
} | ||
|
||
} |
87 changes: 87 additions & 0 deletions
87
src/testIntegration/java/com/github/mikesafonov/smpp/transceiver/TransceiverTest.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,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<DeliveryReport> 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()); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/testIntegration/resources/application-transceiver.properties
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,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} |
2 changes: 2 additions & 0 deletions
2
src/testIntegration/resources/bootstrap-transceiver.properties
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,2 @@ | ||
smpp.mocks.one.password=pass | ||
smpp.mocks.one.system-id=user |