A Spring Boot demonstration project showcasing various testing scenarios and data-driven behavior patterns. This project illustrates how environmental configurations and database states can affect application logic across multiple business scenarios.
This demo application is built with Spring Boot 3.3.0 and demonstrates six different testing scenarios that highlight the importance of proper data configuration and validation:
- Multi-condition Coupon Validation - Complex business logic with multiple validation criteria
- Order ID Format Validation - Pattern-based validation with configurable prefixes
- User Login Authorization - Mock-based authentication with ban status checks
- VIP Access Control - JSON deserialization and boolean field handling
- Locale-dependent Report Generation - Number formatting based on system locale
- Bank Balance Verification - Dynamic proxy-based service mocking
- Java: 17
- Spring Boot: 3.3.0
- Database: H2 (embedded, file-based)
- Build Tool: Maven
- Additional Libraries:
- Spring JDBC
- Jackson (JSON processing)
- Lombok
- H2 Database
src/main/
├── java/com/syncause/demo/
│ ├── dao/ # Data Access Objects
│ │ ├── CouponsDao.java
│ │ ├── MocksDao.java
│ │ └── SysConfigDao.java
│ ├── dto/ # Data Transfer Objects
│ │ └── UserProfile.java
│ ├── DataLoader.java # Database initialization utility
│ ├── DemoApplication.java # Main application with API endpoints
│ └── TestController.java # Debug endpoints for testing
└── resources/
├── static/
│ └── index.html
└── application.properties
- Java 17 or higher
- Maven 3.6+
- An encrypted configuration file (
config.enc) with the decryption key
Before running the Spring Boot application, you must initialize the H2 database with the required data:
mvn clean packagemvn spring-boot:runor
java -jar target/demo-0.0.1-SNAPSHOT.jarThe application will start on the default port (8080).
Open your browser and navigate to:
http://localhost:8080
GET /api/apply-coupon?code=SUMMER_2024&category=FOOD&amount=100
Validates a coupon based on:
- Status (must be ACTIVE)
- Expiry date (must not be expired)
- Minimum amount requirement
- Category matching
GET /api/create-order?userId=12345
Creates an order ID with a configurable prefix and validates the format.
GET /api/login?userId=u_992
Checks if a user is banned based on mock data from the database.
GET /api/check-vip
Verifies VIP status using JSON deserialization.
GET /api/generate-report?amount=1234.56
Generates a formatted report based on the configured system locale.
GET /api/bank-transfer
Checks bank balance using a dynamically proxied service.
GET /test/coupon-data
Returns raw coupon data from the database for the "SUMMER_2024" code.
GET /test/debug-coupon?code=SUMMER_2024&category=FOOD&amount=100
Provides detailed debugging information for coupon validation, including:
- Input vs database values
- Normalized strings for comparison
- Individual validation checks
The application uses an H2 file-based database (demo_db) with the following tables:
- sys_config: System configuration key-value pairs
- upstream_mock: Mock API responses for user services
- mocks: Generic mock data for various scenarios
- coupons: Coupon information with validation criteria
Database connection details:
spring.datasource.url=jdbc:h2:file:./demo_db;AUTO_SERVER=TRUE
spring.datasource.username=sa
spring.datasource.password=The config.enc file contains encrypted configuration data including:
sys_locale: System locale setting (e.g., "en", "de")order_prefix: Prefix for order IDslogin_json: Mock login response databank_balance: Mock bank balance valuevip_json: VIP status JSONcoupon_status: Coupon activation statuscoupon_category: Coupon categorycoupon_min_amount: Minimum purchase amount for couponcoupon_expiry_date: Coupon expiration date
mvn clean installmvn test- Data-Driven Testing: All test scenarios are configurable through the database
- Encrypted Configuration: Sensitive data is stored in encrypted format
- H2 File Database: Persistent storage with file-based H2 database
- Dynamic Mocking: Service behavior can be modified through database configuration
- Locale Support: Demonstrates locale-dependent behavior
- RESTful API: Clean REST endpoints for each scenario
If you encounter database lock errors, ensure:
- The
AUTO_SERVER=TRUEflag is set in the connection URL - No other processes are accessing the database file
- Previous database connections were properly closed
If decryption fails:
- Verify you have the correct decryption key
- Ensure
config.encfile exists in the project root directory - Check that the file has not been corrupted
This project is licensed under the MIT License - see the LICENSE file for details.
This is a demo project. For questions or issues, please contact the project maintainer.