This service simulates an imaginary robotic hoover navigating a room and cleaning dirt patches based on input instructions. The hoover moves within a defined grid room, cleans patches of dirt it encounters, and reports its final position and the number of patches cleaned.
- Java 17: For implementing the application logic.
- Spring Boot: To build the RESTful API service.
- Maven: For project management and building.
- JUnit 5: For writing and running tests.
- SLF4J with Logback: For logging.
- Lombok: To reduce boilerplate code.
- Java 17+: Ensure Java is installed and JAVA_HOME is set.
- Maven 3+: For building the project.
- Git: To clone the repository.
Clone the public GitHub repository:
git clone https://github.com/gmitaros/robotic-hoover-service.git
cd robotic-hoover-service
Navigate to the project directory and run:
mvn clean install
Start the application using the Spring Boot plugin:
java -jar target/robotichoover-0.0.1-SNAPSHOT.jar
The service will start and listen on http://localhost:8080.
The service expects a JSON payload with the following structure:
- roomSize: An array [X, Y] defining the dimensions of the room.
- coords: An array [X, Y] specifying the hoover's initial position.
- patches: An array of [X, Y] positions where patches of dirt are located.
- instructions: A string of characters representing movement instructions.
Example:
{
"roomSize": [5, 5],
"coords": [1, 2],
"patches": [
[1, 0],
[2, 2],
[2, 3]
],
"instructions": "NNESEESWNWW"
}
The service returns a JSON payload with:
- coords: The final coordinates of the hoover after executing the instructions.
- patches: The number of patches of dirt the hoover cleaned. Example:
{
"coords": [1, 3],
"patches": 1
}
Use curl or any API testing tool (e.g., Postman):
curl -L 'http://localhost:8080/clean' -H 'Content-Type: application/json' -d '{
"roomSize": [
5,
5
],
"coords": [
1,
2
],
"patches": [
[
1,
0
],
[
2,
2
],
[
2,
3
]
],
"instructions": "NNESEESWNWW"
}'
{
"coords": [1, 3],
"patches": 1
}
Unit tests are located in src/test/java
. To run unit tests:
mvn test
Integration tests are included to verify the application's behavior as a whole.
To run integration tests:
mvn verify
You can generate a test coverage report using JaCoCo:
mvn clean verify jacoco:report
The report will be generated at target/site/jacoco/index.html.
This project uses GitHub Actions for continuous integration. The build status is indicated by the badge above. Every push and pull request triggers the workflow, which builds the project and runs all tests.
- Valid Instructions:
N
(North),S
(South),E
(East),W
(West) - Invalid Instructions: Any character not among the valid instructions is ignored.
- Logging: Invalid instructions are logged as warnings on the server side.
- Response: The service does not indicate to the client which instructions were invalid unless specified.
The application uses SLF4J with Logback for logging. Logging configurations are defined in src/main/resources/application.properties
.
By default, the root logging level is set to INFO
, and the application package com.gmitaros.robotichoover
is set to DEBUG
for detailed logs.
To adjust the logging levels, modify application.properties
:
# Set the root logging level (ERROR, WARN, INFO, DEBUG, TRACE)
logging.level.root=INFO
# Set the logging level for the application package
logging.level.com.gmitaros.robotichoover=DEBUG
- RESTful API: Implemented using Spring Boot to provide a simple and scalable RESTful interface.
- JSON Payloads: Uses JSON for input and output for ease of integration and testing.
- Grid Coordinates: The room is represented as a grid with the origin
(0, 0)
at the bottom-left corner. - Room Boundaries: The hoover cannot move beyond the defined room dimensions.
- Hoover Behavior:
- Always on and starts cleaning immediately.
- Cleans a patch when it moves over it.
- Can clean a patch only once.
- Instruction Processing: Invalid instructions are ignored, and the hoover continues processing the rest.
- Input Validation: Basic validation is performed to ensure essential fields are present.
- Error Handling: The service responds with appropriate HTTP status codes and messages for invalid inputs.
- Controller Layer: Handles HTTP requests and responses.
- Service Layer: Contains the business logic for processing the hoover's movement and cleaning.
- Model Classes: Define the data structures for input and output payloads.
- Exception Handling: Custom exceptions and handlers are used for better error management.
- Logging: Integrated at various levels to trace the computation and aid in debugging.
src/
├── main/
│ ├── java/com/gmitaros/robotichoover/
│ │ ├── controller/
│ │ │ └── CleaningController.java
│ │ ├── model/
│ │ │ ├── InputPayload.java
│ │ │ ├── OutputPayload.java
│ │ │ └── Position.java
│ │ ├── service/
│ │ │ └── CleaningService.java
│ │ └── exception/
│ │ └── GlobalExceptionHandler.java
│ └── resources/
│ └── application.properties
└── test/
├── java/com/gmitaros/robotichoover/
│ ├── controller/
│ │ └── CleaningControllerIntegrationTest.java
│ └── service/
│ └── CleaningServiceTest.java
└── resources/