smpp-server-mock-spring-boot

Spring boot starter to setup test smpp server for integration testing

License

License

MIT
Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

com.github.mikesafonov
ArtifactId

ArtifactId

smpp-server-mock-spring-boot
Last Version

Last Version

1.5.0
Release Date

Release Date

Type

Type

jar
Description

Description

smpp-server-mock-spring-boot
Spring boot starter to setup test smpp server for integration testing
Project URL

Project URL

https://github.com/MikeSafonov/smpp-server-mock
Project Organization

Project Organization

com.github.mikesafonov
Source Code Management

Source Code Management

https://github.com/MikeSafonov/smpp-server-mock

Download smpp-server-mock-spring-boot

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.mikesafonov/smpp-server-mock-spring-boot/ -->
<dependency>
    <groupId>com.github.mikesafonov</groupId>
    <artifactId>smpp-server-mock-spring-boot</artifactId>
    <version>1.5.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.mikesafonov/smpp-server-mock-spring-boot/
implementation 'com.github.mikesafonov:smpp-server-mock-spring-boot:1.5.0'
// https://jarcasting.com/artifacts/com.github.mikesafonov/smpp-server-mock-spring-boot/
implementation ("com.github.mikesafonov:smpp-server-mock-spring-boot:1.5.0")
'com.github.mikesafonov:smpp-server-mock-spring-boot:jar:1.5.0'
<dependency org="com.github.mikesafonov" name="smpp-server-mock-spring-boot" rev="1.5.0">
  <artifact name="smpp-server-mock-spring-boot" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.mikesafonov', module='smpp-server-mock-spring-boot', version='1.5.0')
)
libraryDependencies += "com.github.mikesafonov" % "smpp-server-mock-spring-boot" % "1.5.0"
[com.github.mikesafonov/smpp-server-mock-spring-boot "1.5.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.github.mikesafonov : smpp-server-mock-core jar 1.5.0

runtime (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-dependencies jar 2.2.5.RELEASE
org.springframework.cloud : spring-cloud-dependencies jar Hoxton.SR3

test (4)

Group / Artifact Type Version
org.assertj : assertj-core jar 3.15.0
org.junit.jupiter : junit-jupiter jar 5.6.0
org.mockito : mockito-core jar 3.3.0
org.springframework.boot : spring-boot-starter-test jar 2.2.5.RELEASE

Project Modules

There are no modules declared in this project.

smpp-server-mock

codecov Travis-CI Conventional Commits

Quality Gate Status Reliability Rating Maintainability Rating Security Rating

Bugs Code Smells Vulnerabilities

Duplicated Lines (%) Lines of Code Technical Debt

This project helps to write integration test for applications uses SMPP connection.

smpp-server-mock comes with:

Core

smpp-server-mock-core consist of two main classes: MockSmppServer and MockSmppServerHolder.

MockSmppServer represents smpp server which listening connections, received request, produce response and keep requests in in-memory queue QueueSmppSessionHandler.

Using JUnit 5 extension

Add JUnit 5 test dependencies:

Maven:

<dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>5.6.0</version>
    <scope>test</scope>
</dependency>

Gradle:

dependencies{
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.0")
}

Add extension dependency com.github.mikesafonov:smpp-server-mock-junit:

Maven:

<dependency>
    <groupId>com.github.mikesafonov</groupId>
    <artifactId>smpp-server-mock-junit</artifactId>
    <version>${version}</version>
    <scope>test</scope>
</dependency>

Gradle:

dependencies{
    testImplementation("com.github.mikesafonov:smpp-server-mock-junit:${version}")
}

Test example:

@ExtendWith(MockSmppExtension.class)
public class MyTest {
    @SmppServer(systemId = "customSystemId", password = "password")
    MockSmppServer mockSmppServer;
    
    @Test
    void shouldSendSms(){
        // create some class to send SMS and connect to mock server, example:
        MySmsSender sender = new MySmsSender("localhost", mockSmppServer.getPort(), 
                                "customSystemId", "password");
        sender.sendSms("message", "number");
        
        List<SubmitSm> messages = mockSmppServer.getSubmitSmMessages();
        SubmitSm message = messages.get(0);

        assertEquals("number", message.getDestAddress().getAddress());
    }       
}

You may set clearAfterTest to true in SmppServer if you want to clear all incoming requests after each test run.

By default clearAfterTest is false.

Using AssertJ assertions

com.github.mikesafonov:smpp-server-mock-assertj helps to write more intuitive assertions for SMPP objects.

To start using AssertJ assertions you need to:

  • add assertj-core dependency
  • add com.github.mikesafonov:smpp-server-mock-assertj dependency

Maven:

<dependency>
    <groupId>com.github.mikesafonov</groupId>
    <artifactId>smpp-server-mock-assertj</artifactId>
    <version>${version}</version>
    <scope>test</scope>
</dependency>

Gradle:

dependencies{
    testImplementation("com.github.mikesafonov:smpp-server-mock-assertj:${version}")
}

Assertions for MockSmppServer:

SmppAssertions.assertThat(mockSmppServer)
                .hasPort(2000)
                .hasName("myserver")
                .hasSystemId("systemId")
                .hasSingleMessage() // assert for single SubmitSm
                .hasSingleCancelMessage() // assert for single CancelSm
                .messages()// assert for list of SubmitSm
                .cancelMessages()// assert for list of CancelSm
                .requests();//assert for list of any request

Assertions for SubmitSm:

SmppAssertions.assertThat(mockSmppServer)
                    .hasSingleMessage()
                    .hasDest("number")
                    .hasText("message")
                    .hasEsmClass(esmClass)
                    .hasDeliveryReport()
                    .doesNotHaveDeliveryReport()
                    .hasSource("someSource");

or

SmppAssertions.assertThat(submitSm)
                    .hasDest("number")
                    .hasText("message")
                    .hasEsmClass(esmClass)
                    .hasDeliveryReport()
                    .doesNotHaveDeliveryReport()
                    .hasSource("someSource");

Assertions for CancelSm:

SmppAssertions.assertThat(mockSmppServer)
                .hasSingleCancelMessage()
                .hasDest("number")
                .hasId("messageId")
                .hasSource("someSource");

or

SmppAssertions.assertThat(cancelSm)
                .hasDest("number")
                .hasId("messageId")
                .hasSource("someSource");

Assertions for list of SubmitSm:

SmppAssertions.assertThat(mockSmppServer)
                .messages()
                .containsDest(destAddress)
                .containsText(text)
                .containsEsmClass(esmClass)
                .containsSource(sourceAddress);

or

SmppAssertions.assertThatSubmit(listOfSubmitSm)
                .containsDest(destAddress)
                .containsText(text)
                .containsEsmClass(esmClass)
                .containsSource(sourceAddress);

Assertions for list of CancelSm:

SmppAssertions.assertThat(mockSmppServer)
                .cancelMessages()
                .containsDest(destAddress)
                .containsId(messageId)
                .containsSource(sourceAddress);

or

SmppAssertions.assertThat(listOfCancelSm)
                .containsDest(destAddress)
                .containsId(messageId)
                .containsSource(sourceAddress);

Assertions for MockSmppServerHolder:

SmppAssertions.assertThat(holder)
                .allStarted() // verify that all MockSmppServer started
                .serverByName("first); // find MockSmppServer by name and return assertions

Using Spring Boot Starter

Spring boot starter are used to bootstrap MockSmppServer servers using spring cloud bootstrap phase.

Add spring-cloud and spring-boot-starter-test test dependencies:

Maven:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter</artifactId>
    <version>cloud-version</version>     
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <version>version</version>     
    <scope>test</scope>
</dependency>

Gradle:

dependencies{
    testImplementation("org.springframework.cloud:spring-cloud-starter:${cloud-version}")
    testImplementation("org.springframework.boot:spring-boot-starter-test:${version}")
}

Add extension dependency com.github.mikesafonov:smpp-server-mock-spring-boot:

Maven:

<dependency>
    <groupId>com.github.mikesafonov</groupId>
    <artifactId>smpp-server-mock-spring-boot</artifactId>
    <version>${version}</version>
    <scope>test</scope>
</dependency>

Gradle:

dependencies{
    testImplementation("com.github.mikesafonov:smpp-server-mock-spring-boot:${version}")
}

The starter consumes properties:

smpp.mocks.<server name>.port (optional, default random)

smpp.mocks.<server name>.password

smpp.mocks.<server name>.system-id

The starter produces properties:

smpp.mocks.<server name>.host (always localhost)

smpp.mocks.<server name>.port

smpp.mocks.<server name>.password

smpp.mocks.<server name>.system-id

Example

bootstrap.properties:

smpp.mocks.one.password=test
smpp.mocks.one.system-id=user

application.properties:

# some properties to smpp connection in your app
my.smpp.connection.host=${smpp.mocks.one.host}
my.smpp.connection.port=${smpp.mocks.one.port}
my.smpp.connection.password=${smpp.mocks.one.password}
my.smpp.connection.systemId=${smpp.mocks.one.system-id}

test:

    @SpringBootTest
    class SingleServer extends BaseSmppTest {
        @Autowired
        protected MockSmppServerHolder holder;
        
        @Test
        void shouldRunExpectedSmppServer() {
            // test logic
            List<PduRequest> requests = 
                    holder.getByName("one").get().getRequests();
            // verify smpp requests
        }
    }

Build

Build from source

You can build application using following command:

./gradlew clean build -x signArchives

Requirements:

JDK >= 1.8

Unit tests

You can run unit tests using following command:

./gradlew test

Mutation tests

You can run mutation tests using following command:

./grdlew pitest

You will be able to find pitest report in build/reports/pitest/ folder.

Contributing

Feel free to contribute. New feature proposals and bug fixes should be submitted as GitHub pull requests. Fork the repository on GitHub, prepare your change on your forked copy, and submit a pull request.

IMPORTANT!

Before contributing please read about Conventional Commits / Conventional Commits RU

Versions

Version
1.5.0
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0