Skip to content

Commit

Permalink
test(integration): added test for transceiver connection type
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSafonov committed Mar 17, 2020
1 parent 00fdad0 commit 4b3c0e8
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
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);
}

}
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());
}
}
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}
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

0 comments on commit 4b3c0e8

Please sign in to comment.