Skip to content

MSroczynski3/Mock-Service

Repository files navigation

Mock Service

A Spring Boot application for creating and managing HTTP mocks using WireMock and MongoDB.

🚀 Tech Stack

  • Java 24 - Latest Java features and performance improvements
  • Spring Boot 3.5.4 - Modern Spring framework with enhanced capabilities
  • Gradle (Kotlin DSL) - Type-safe build automation
  • WireMock 3.13.1 - Powerful HTTP service virtualization
  • MongoDB - Flexible document storage for mock configurations
  • Spring Boot Actuator - Production-ready monitoring and health checks
  • Lombok - Reduced boilerplate code
  • Testcontainers - Integration testing with real services

📋 Prerequisites

  • Java 24 or higher
  • Docker Desktop - Required for running tests (uses Testcontainers for MongoDB)
  • MongoDB (optional for basic testing - can be configured later)
  • Git for version control

Docker Setup

The project uses Testcontainers for integration testing, which requires Docker to be running:

  1. Install Docker Desktop for your operating system
  2. Start Docker Desktop and ensure it's running
  3. Verify Docker is running: docker info should not show connection errors

⚠️ Important: Tests will fail if Docker is not running, as they use MongoDB containers for testing.

🏃‍♂️ Quick Start

1. Clone the Repository

git clone <your-repo-url>
cd Mock-Service

2. Build the Project

./gradlew build

3. Run the Application

./gradlew bootRun

4. Verify It's Working

Open another terminal and run:

curl http://localhost:8080/actuator/health

Expected response:

{"status":"UP"}

🛠️ Development Commands

Command Description
./gradlew build Build the project and run tests
./gradlew bootRun Start the application with hot reload
./gradlew test Run all tests
./gradlew clean Clean build artifacts
./gradlew clean build Clean and build from scratch

🔗 API Endpoints

Health & Monitoring

  • Health Check: GET /actuator/health
  • Application Info: GET /actuator/info
  • Metrics: GET /actuator/metrics

Mock Management

Coming soon - Mock CRUD operations

🏗️ Project Structure

Mock-Service/
├── src/
│   ├── main/
│   │   ├── java/com/example/mockservice/
│   │   │   └── MockServiceApplication.java
│   │   └── resources/
│   │       ├── application.properties
│   │       ├── static/
│   │       └── templates/
│   └── test/
│       └── java/com/example/mockservice/
├── gradle/
├── build.gradle.kts
├── settings.gradle.kts
└── README.md

⚙️ Configuration

The application uses application.properties for configuration. Key settings:

  • Server Port: 8080 (default)
  • MongoDB: Auto-configuration (when available)
  • Actuator: Health endpoints enabled

🧪 Testing

Prerequisites for Testing

⚠️ Docker must be running before executing tests, as they use Testcontainers to spin up MongoDB containers.

Running Tests

# Ensure Docker Desktop is running first
docker info

# Run all tests
./gradlew test

Test Structure

The project includes:

  • Unit tests for core functionality
  • Integration tests with Testcontainers
  • MongoDB integration testing using Docker containers

Troubleshooting Tests

If tests fail with Docker-related errors:

  1. Ensure Docker Desktop is installed and running
  2. Verify Docker connectivity: docker info
  3. On Windows: Check that Docker Desktop is using the correct engine (WSL2 or Hyper-V)

🐳 Docker Support

Coming soon - Docker containerization

📚 Features Roadmap

  • Basic WireMock integration
  • MongoDB mock storage
  • REST API for mock management
  • Web UI for mock configuration
  • Request/Response logging
  • Mock templates and scenarios
  • API documentation with Swagger

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🆘 Troubleshooting

Common Issues

Build fails with Java version error:

  • Ensure Java 24 is installed and JAVA_HOME is set correctly

Tests fail with Docker/Testcontainers errors:

  • Ensure Docker Desktop is installed and running
  • Run docker info to verify Docker connectivity
  • On Windows: Make sure Docker Desktop is using the correct engine

WireMock HttpServerFactory errors:

  • This project uses wiremock-standalone for better Java 21+ compatibility
  • If you see "Jetty 11 is not present" errors, ensure you're using the standalone version
  • The standalone version includes all necessary HTTP server dependencies

Application won't start - MongoDB connection error:

  • MongoDB connection is optional for basic functionality
  • Configure spring.data.mongodb.uri in application.properties if needed

Port 8080 already in use:

  • Change the port in application.properties: server.port=8081

Happy Mocking! 🎭

About

Mock Service to enhance your testing experience in systems with 3rd party dependencies.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages