Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.mikesafonov:smpp-server-mock-assertj

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.mikesafonov:smpp-server-mock-assertj

AssertJ asserts for smpp-server-mock

  • 1.5.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

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

FAQs

Package last updated on 15 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc