This is a simple test task.
To run the project please do
mvn clean test jetty:run
After successful run it is possible to perform tests.
Any of the following curl
invocations can be changed into the following way to pretty-print the JSON response:
$ curl ...| jq .
But it may require installing jq
in your system (Example: $ sudo apt-get install jq
on Ubuntu)
Also, it is possible to show the requests and headers sent/received during curl communications bu using -v
option
$ curl -v ...
Request:
$ curl -s -u admin:admin --digest -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "Hail to the king!",
"count": 1
}
Request:
$ curl -s -u user:user --digest -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "Welcome user!",
"count": 1
}
Request:
$ curl -s -u other:other --digest -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "User other does not have access"
}
Request:
$ curl -s -X POST -u admin:admin --digest -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "Method not supported"
}
Request:
$ curl -s -u bogus:user --digest -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "Access denied"
}
Request:
$ curl -s -H "Content-Type: application/json" http://localhost:8080/
Expected response:
{
"message": "Access denied"
}