Welcome to the Mocking Library project! This project showcases how to effectively mock Java libraries in a Spring Boot application using a Java agent with Byte Buddy. It's a comprehensive guide to setting up and running a mock environment for your Java applications.
Here's a quick rundown of the project structure:
app/: Contains the Spring Boot application.agent/: Houses the Java agent that intercepts and mocks library functions.docker-compose.yml: Docker Compose configuration to run both the application and the agent seamlessly.
Follow these steps to get the project up and running:
-
Build the Docker image
docker-compose build
-
Start the containers:
docker-compose up
-
Test the application by sending a POST request:
curl -X POST http://localhost:8080/api/createNewPost -H "Content-Type: application/json" -d '{"post_name":"test-post","post_contents":"This is a test post"}'
To configure the application, you'll need to set the following environment variables:
HT_MODE: The mode for the Java agent. It can be set to eitherRECORDorREPLAY.