The mobile software testing team has 10 mobile phones that it needs to share for testing purposes.
- Samsung Galaxy S9
- 2x Samsung Galaxy S8
- Motorola Nexus 6
- Oneplus 9
- Apple iPhone 13
- Apple iPhone 12
- Apple iPhone 11
- iPhone X
- Nokia 3310
Please create a service that allows a phone to be booked / returned.
The following information should also be available for each phone.
- Availability (Yes / No)
- When it was booked
- Who booked the phone
Please send a notification to a message broker of your choice when a phone is either booked or returned.
The task doesn't distinguish between book of the mobile to test and collection of the same,
hence the implementation considers the \book
verb as the action to collect the mobile
by the requestor
testing it, if the mobile
is available.
The mobile is booked until the due
time.
The \return
action makes the mobile
available to be booked again if who returns
it is the same who booked it.
The \list
action returns the list of mobile devices as
AVAILABLE
if not booked/collected by anyone,IN USE
if arequestor
collected it, reporting when the book wasmade
and return isdue
.DUE
if therequestor
should have returned themobile
because now is afterdue
.
Time properties as 'book made
' and 'return due
' are expressed as
ISO 8601 local date-time strings.
The software is a Kotlin + Gradle project developed with JetBrain IDEA.
Kafka must be available, if not follow the Apache Kafka Quickstart guide to install it locally.
Create the topics book
and return
where events are produced.
bin/kafka-topics.sh --create --topic book --bootstrap-server localhost:9092
bin/kafka-topics.sh --create --topic return --bootstrap-server localhost:9092
Run two Kafka Consumer clients, one for each topic, in two different shells.
bin/kafka-console-consumer.sh --topic book --bootstrap-server localhost:9092
bin/kafka-console-consumer.sh --topic return --bootstrap-server localhost:9092
The Kafka Broker must be up and running, by default at localhost:9092
, before the application server runs.
The labels for the mobile devices are loaded as comma separated string elements by the mobiles
key in the application.properties file.
- Open a shell in the directory where the woftware was downloaded.
- Build the application server with
./gradlew bootJar
. - Start the application server with
java -jar build/libs/btcc-0.0.1-SNAPSHOT.jar
- Visit http://localhost:8080/swagger-ui/index.html how to use API end-points.
- Stop the application server pressing [CTRL+C].
At least seven mobiles must be defined to allow ControllerTest to run tests in parallel and prove concurrent requests are handled correctly.
The directory src/test/kotlin/com/github/lucanicoladebiasi/btc
has the test code
covering the required behavior.
The test code embeds an application server to test REST-API end-point and an in-memory Kafka using the port 9093 to test messaging functionalities.
Run ./gradlew test
to execute unit/integration tests.
For further reference, please consider the following sections:
- Official Gradle documentation
- Spring Boot Gradle Plugin Reference Guide
- Create an OCI image
- Spring Web
- Spring for Apache Kafka
- Spring Boot DevTools
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
These additional references should also help you: