Creating Mock APIs. Spring SOAP Web Services.

Link to the full version of the project on GitHub:
Github MockSoapRestProject

Linr to version Spring MVC / Gradle:
Github MockSoapRestGradle

Previously, we discussed creating a stub for modular REST API tests using Spring Web Services tools. (Link to the previous article). Today, we will address a similar request, but with a twist. In this case, the stub will function as a SOAP service, while management desires to handle REST requests and integrate Swagger for manual testing control and automation purposes.

By connecting Swagger to the stub, we can effectively manage it as both a manual testing tool and an automated testing framework. This integration allows us to control the stub’s behavior, perform manual tests, and seamlessly incorporate it into our automated testing workflows. Let’s explore how to achieve this functionality and enhance our testing capabilities.

Some documentation:
Standards.REST
Simple Object Access Protocol (SOAP)

Task: The task is to create a stub for the SOAP API of the Countrycode service. We will accomplish this using Spring Boot, by writing a REST API Web Service for management and a SOAP API for handling the stub service responses. Additionally, we will integrate Swagger documentation to enhance the API’s documentation and testing capabilities. Finally, we will generate a deployable artifact in the form of a war file for easy application deployment.

To complete this task, follow the steps outlined below:

  1. Utilize Spring Boot to create a new project.
  2. Implement the REST API Web Service for management, allowing control over the stub’s behavior.
  3. Create the SOAP API for handling the stub service responses, providing the necessary service functionality.
  4. Integrate Swagger documentation to facilitate API documentation and testing.
  5. Build the project and generate a war file, which can be deployed to a server or container.

By following these steps, you will have a complete stub of the SOAP API for the Countrycode service. The REST API Web Service will provide management capabilities, the SOAP API will handle the stub responses, and Swagger integration will enhance documentation and testing. With the generated war file, you can easily deploy the application and start utilizing the stub service.

Web service and WSDL, as long as it’s working and free. SOAP Web service

Used:

Spring Boot SOAP API API RESTFull JAXB Swagger2

Traditionally, when creating a Maven project, we start by adding the necessary dependencies to the pom.xml file. To simplify this process, we can leverage Spring Initializr, which provides a convenient web-based service for generating the initial project structure and automatically adding the required dependencies.

Project structure:

The project structure for creating a stub of the SOAP API for the Countrycode service can be organized as follows:

  1. ru.gotoqa.mock.configuration: This package contains Swagger and Spring Bean configuration classes. Here, you can define the necessary configurations for integrating Swagger with your project and managing Spring Beans.

  2. ru.gotoqa.mock.core: This package houses the core logic of the stub. It includes the creation and operation of filters and the setup of responses. Here, you can implement the logic for handling incoming requests, filtering them as needed, and generating appropriate responses.

  3. ru.gotoqa.mock.endpoint: In this package, you’ll find the REST stub control call points and the mock SOAP responses. This is where you can define REST endpoints for managing the stub’s behavior and configure mock SOAP responses for testing purposes.

  4. ru.gotoqa.mock.entity: This package serves as a catalog for deserializing POJO entities for JSON/XML. You can utilize libraries like maven-jaxb2-plugin for autogeneration of these entities.

  5. resources.messages: This directory contains examples of service requests and responses. It can be helpful for testing and documentation purposes, showcasing the expected structure and content of messages exchanged with the stub.

  6. resources.static: This directory is parsed by Spring Boot by default and can include a demo HTML page or any other static files you want to provide along with the application.

  7. resources.wsdl: This directory holds the WSDL file (Web Service Definition Language) for the SOAP API. It defines the structure and operations supported by the SOAP service.

  8. application.properties: This configuration file is specific to Spring Boot and allows you to define various properties for your application, such as database connections, server settings, and more.

By organizing your project structure in this manner, you can effectively manage the different components of your stub application and keep the codebase clean and maintainable.

I described WSDL class generation in detail in an article earlier: here

Conditional task. Mock query response: CountryCurrency и CapitalCity

Swagger documentation and control of the plug is available at: http://127.0.0.1:9091/swagger-ui.html

Principle of operation:
1. Set the rule with a query: /filter/capitalCity/createRule
2. Call the CapitalCity service at the address: http://127.0.0.1:9091/mock-soap

You can also see all logged calls to the service: /filter/capitalCity/showCapitalCityRequestStorage

Launch from the terminal: mvn spring-boot:run

Congratulations on creating a powerful stub for the SOAP API of the Countrycode service using Spring Boot! The stub includes a REST API Web Service for management and a SOAP API for handling responses. Integration of Swagger documentation enhances API documentation and testing. Access the project code on GitHub, understand the project structure and tools used. Deploy the application easily with the generated war file. Thank you for reading, and we hope this article efficiently helps you create your SOAP API stub.

Link to the full version of the project on GitHub:
Github MockSoapRestProject

Linr to version Spring MVC / Gradle:
Github MockSoapRestGradle

Related Posts