This project exposes REST services to enable various read operations to an Oracle DB hosted on AWS.
All REST endpoints are secured using basic authentication.
The project is built with the following:
The project is tested with :
-
Extract the zip file employee-manager-master.zip
-
Navigate to the project directory:
cd employee-manager-master
- Update application.properties
Update src/main/java/application.properties and src/test/java/application.properties to contain the connection credentials which should have been provided separately:
spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
- Using Maven, to start the Spring Boot application and enable the REST services, from the directory employee-manager-master run :
mvn spring-boot:run
-
Open the project using an IDE (tested with IntelliJ).
-
To download the maven dependencies right click on the project and select Maven -> Reload project:
- To run the project run the Spring Boot main class located at /src/main/java/EmployeeManagerApplication.java
To run all tests execute the following command from employee-manager-master directory:
mvn test
In addition, the REST services have been tested using the Firefox browser and Postman.
It is required to send the authorisation parameter values for each request. On the authorisation tab set the username/password field values to user/pass:
and click "Send":
Invoking a REST service will prompt a login popup, set the username/password field values to user/pass and press "OK":
The REST service requests available from a local String Boot running instance are:
http://localhost:8080/department
http://localhost:8080/badges
http://localhost:8080/badges/active
http://localhost:8080/badges?badge_number=badge_number
http://localhost:8080/job_titles
http://localhost:8080/job_titles/department_name
http://localhost:8080/employees
http://localhost:8080/employees/active
http://localhost:8080/employees?department_name=department_name
Swagger is enabled for this project:
To view the available services point Firefox to the Swagger URL:
http://localhost:8080/swagger-ui/
A login popup will display prior to Swagger loading, set the username/password field values to user/pass and press "OK":
For any Maven related issues deleting and re-downloading the project dependencies usually resolves. Re-downloading all dependencies can take some time. For Unix based systems to delete the Maven repository navigate to Maven home and execute the command:
rm -R repository/
By default Maven home is usually set to /<USER_HOME>/.m2
The project can be improved in the following areas:
-
A Spring JPA object model can be mapped to reflect a DB schema. The mapping enables the use of cross table JPA queries to extract DB data and omits writing native queries for cross-table joins. An improvement to this project is instead of mapping each table to a single entity, use JPA to model the relationship's between tables.
-
Instead of using an in memory data structure to store the code -> country mappings, cache the mappings with persistent storage.
-
Extend the test coverage to ensure the JSON response data structure from each REST service is correct. For example, the below test checks that the "Software" value is mapped to the "department_name" key at index 0 in the response to the "/job_titles" REST service:
given().auth()
.basic("user", "pass").get("/job_titles").then()
.statusCode(200)
.body("size()", is(12))
.body("[0].department_name", equalTo("Software"));
- Extend the mocking of services to test invalid http status 404 returns, for example, apply below test logic to all REST services tests where applicable:
when(badgeService.getActiveBadges()).thenReturn(Collections.emptyList());
given().when().auth()
.basic("user", "pass").get("/badges/active").then()
.statusCode(HttpStatus.NOT_FOUND.value());
- Extend the test coverage to verify the custom exception CountryCodeServiceException is thrown when expected.
-
Country codes that do not contain a mapping for the REST service: https://restcountries.eu are set to "NA". For example, the country code "irl" is not available from https://restcountries.eu, the request https://restcountries.eu/rest/v2/name/irl responds with 404 (not found).
-
Interpreting the requirements doc I assume /:department_name is /department_name and is a URL path variable. For example, to view all job titles from the HR department use:
http://localhost:8080/job_titles/HR
-
I assume the request parameters badge_number & department_name for the requests ""/badges?badge_number=[badge_number]" and "/employees?department_name=[department_name]" match on single value and not a list of values.
-
For testing I assume the DB state is immutable, therefore the REST service's response JSON is integration tested.