This is a progressing project made by Ruben Brouwers for Programming 2.3 in S2 2021-2022.
Course: Programming 2.3
Name: Ruben Brouwers
Email: ruben.brouwers@student.kdg.be
ID: 0146084-02
Git Repository: prog23/Project
I continued this project on the project that I made in programming 2.1.
- JDK 11
- H2 database
- No need for PostGreSQL configuration
- Enter the command
./gradlew bootRunin the terminal within the project directory. (npm should build, and spring boot should start) - Testing you can do with the command
./gradlew test- Some of the tests fail when you run it through commandline, but succeed when you run it through intelliJ.
- Test:
- Only used in the SeedData class, when this profile is selected, that commandline runner should not execute.
Buildings can have multiple architects, architects can also have 0 or more buildings. There is also a many-to-one relationship between building type and building, a building can only have 1 type, but multiple buildings can have the same types.
My code will not be able to give a 400, because all exceptions are catched with the @ControllerAdvice and will return a HTTPStatus 500.
If this exception handler is commented out, it will give a HTTPStatus 400 (Bad Request).
GET http://localhost:6969/api/architects HTTP/1.1
Accept: application/jsonHTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 21 Feb 2022 20:48:59 GMT
Keep-Alive: timeout=60
Connection: keep-alive
[
{
"id": 1,
"nameCompany": "Zaha Hadid Architects",
"establishmentDate": "1980-01-01",
"numberOfEmployees": 900,
"buildings": [
{
"id": 2,
"name": "Vitra Fire St...A 204 will appear if there are no records of any architect in the database, very unlikely.
GET http://localhost:6969/api/architects/1 HTTP/1.1
Accept: application/jsonHTTP/1.1 200
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 21 Mar 2022 08:11:37 GMT
Keep-Alive: timeout=60
Connection: keep-alive
{
"id": 1,
"nameCompany": "Zaha Hadid Architects",
"establishmentDate": "1980-01-01",
"numberOfEmployees": 708,
"buildings": [
{
"id": 1,
"name": "Port Autho...GET http://localhost:6969/api/architects/420 HTTP/1.1
Accept: application/jsonHTTP/1.1 204
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Date: Mon, 21 Mar 2022 08:12:07 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>GET http://localhost:6969/api/buildings?location=Denmark HTTP/1.1
Accept: application/jsonHTTP/1.1 200
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Content-Type: application/json
Transfer-Encoding: chunked
Date: Mon, 21 Mar 2022 08:12:56 GMT
Keep-Alive: timeout=60
Connection: keep-alive
[
{
"id": 4,
"name": "The Uno-X Petrol Station",
"location": "DenmaGET http://localhost:6969/api/buildings?location=Hoevenen HTTP/1.1
Accept: application/jsonHTTP/1.1 204
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
Date: Mon, 21 Mar 2022 08:13:35 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>
```http request
DELETE http://localhost:6969/api/buildings/1 HTTP/1.1
Accept: application/jsonHTTP/1.1 200
Date: Mon, 21 Feb 2022 20:54:26 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>DELETE http://localhost:6969/api/buildings/420 HTTP/1.1
Accept: application/jsonHTTP/1.1 404
Date: Mon, 21 Feb 2022 20:54:53 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>POST http://localhost:6969/api/buildings HTTP/1.1
Accept: application/json
Content-Type: application/json
{
"name" : "testing",
"location" : "Antwerp, BE",
"height" : 123,
"architectsIDs" : [1],
"type" : "SLUMS"
}HTTP/1.1 201
Content-Type: application/json
Transfer-Encoding: chunked
Date: Fri, 04 Mar 2022 12:49:56 GMT
Keep-Alive: timeout=60
Connection: keep-alive
{
"id": 5,
"name": "testing",
"location": "Antwerp, BE",
"height": 123.0,
"type": {
"id": 5,
"code": "gpPUT http://localhost:6969/api/architects/1 HTTP/1.1
Content-Type: application/json
{
"id" : 1,
"numberOfEmployees" : 900
}HTTP/1.1 204
Date: Mon, 21 Feb 2022 20:57:15 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>PUT http://localhost:6969/api/architects/420 HTTP/1.1
Content-Type: application/json
{
"id" : 420,
"numberOfEmployees" : 6969
}HTTP/1.1 404
Date: Mon, 21 Feb 2022 20:57:41 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>PUT http://localhost:6969/api/architects/1 HTTP/1.1
Content-Type: application/json
{
"id" : 420,
"numberOfEmployees" : 6969
}HTTP/1.1 409
Date: Mon, 21 Feb 2022 20:58:10 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<Response body is empty>GET http://localhost:6969/api/buildings HTTP/1.1
Accept: application/jsonHTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
Date: Tue, 15 Feb 2022 21:22:59 GMT
Keep-Alive: timeout=60
Connection: keep-alive
[
{
"id": 1,
"name": "Port Authority",
"location": "Antwerp, Belgium",
"height": 46.0,
"type": {
"id": 1,
"code": "s3n",
"type": "BUSIN...GET http://localhost:6969/api/architects HTTP/1.1
Accept: application/xmlHTTP/1.1 200
Content-Type: application/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 15 Feb 2022 21:25:49 GMT
Keep-Alive: timeout=60
Connection: keep-alive
<List>
<item>
<id>1</id>
<nameCompany>Zaha Hadid Architects</nameCompany>
<establishmentDate>1980-01-01</establishmentDate>
<numberOfEmployees>6969</numberOfEmployees>
<buildings>
<buildings>
<id>1</id>
<name>Port Authori...I have added multiple icons, all of which you can find on my mainpages.
- Buildings Page
- A map icon next to the filtering on location input field.
- building.html
- Architects Page
- A people icon next to the filtering on number of employees input field.
- A buildings icon next to the filtering on company name input field.
- architect.html
I have chosen to add flatpickr and validator to my project.
To see this, you need to add a new architect, and press on the establishmentDate input field. Then you will see the flatpickr date picker.
- Adding an architect
- Source Files:
To see validator in action you will need to enter:
- a string with more than 30 characters when filtering architects on name.
- write a string with not only numbers when filtering architects on number of employees.
- Architect mainpage
- Source files:
- architects.html (Not really any validator specific code here, except the script tag which links to the JS file)
- filteringArchitects.js (here on line 16 & 76 you will find validator code)
Unauthenticated user only have access to the landing and login page (soon also the registering page). Every other pages requires authentication.
ROLE_CREATOR > ROLE_UPDATER > ROLE_USER
All what the user can do, the updater can also do, and so on...
Username: Creator
E-mail: creator@kdg.be
Password: creator
The "creator" can do everything.
Username: Updater
E-mail: updater@kdg.be
Password: updater
The "updater" can update entities (PUT architect)
- They cannot see any off the pages to add entities, including the navbar links to those pages.
- Any page, because all pages have the navbar.
- They cannot delete any entities, (not being able to see the delete buttons.)
Username: User
E-mail: user@kdg.be
Password: user
The "user" can view entities and filter on them
- They cannot see any off the pages to add entities, including the navbar links to those pages.
- Any page, because all pages have the navbar.
- They cannot delete any entities, (not being able to see the delete buttons.)
- They cannot modify any entities, (not being able to see the forms and the buttons.)
- They cannot see the login button on the landing page ones logged in.
An architect (architect firm) can have employees and a user (normal user, updater, creator) has an architect firm they "work for". Every logged in user can see these relations under the detail page of each architect, these relations can only be made upon registration, there is no way to modify it, yet...
I set my spring profile in each class separately, with the annotation:
@ActiveProfile("test")The commands to run all tests are:
./gradlew test./gradlew checkI used mocking in all my presentation layer tests, because I mock the user to pass the tests with security enabled.
But the classes where I really focussed the tests on mocking are:
- BuildingControllerTests: Line 123
- ArchitectControllerMockingTests: Line 79
As mentioned before, in all my presentation layer tests I used the role verification (as all my REST calls require authentication). But there are 2 tests dedicated to specifically that.
- ArchitectControllerMockingTests: Line 114
- BuildingControllerTests: Line 127

