Author:
Name |
Student number |
---|---|
679586 |
Teachers:
Name |
Function |
---|---|
Skills begeleider | |
Procesbegeleider |
Klas |
ITA-OOSE-A |
---|---|
Groepsnaam | Smalltalk |
Course | OOSE |
Datum |
|
Versie |
1.27 |
In this document we will take a look at the trustworthiness of the application. The unit tests will determine if the application functions correctly. This is mainly focused on unit tests and what they do.
One of the requirements from Regterschot Racing was that the application needs to be safe, so that no-one is allowed on the appplication, except for those with the permission to be in the application.
The code also needs to work and be well documented. This document will show which code works and what all the tests are. If there is a failed test, it will be explained on why this happens.
The token usernameErik is defined as "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.ewogICAgIm5hbWUiOiAiRXJpayIKfQ==.2d2c39f777b16f75c701e851e9ec20d45f4134a281155e0c6f909876228d7d80".
1. DAO Response
The response from the database is set manually, because testing is not a valid reason to change data in the database. Whenever a call is made to the DAO, the response will be set manually aswell, to prevent the test from testing more than one class.
2. Tests
2.1. Graph tests
2.1.1. GraphServiceTest class
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getAllGraphs() |
Returns a GraphsDTO with the following information. GraphsDTO{ |
Returns the expected list of DTOs. | Yes | ||
2 | addGraph() | Throws a DatabaseException. |
tabID = 1 graphID = 1 graphType = "linechart" |
A DatabaseException is thrown. | Yes | The return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value. The method can however be tested by the mockito.verify function. |
3 | deleteGraphs() | Throws a DatabaseException. |
tabID = 1 graphID = 1 |
A DatabaseException is thrown. | Yes | The return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value. The method can however be tested by the mockito.verify function. |
Table 1: Tests in GraphServiceTest
2.1.2. GraphResourceTest class
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | addGraphTest() | Returns a 200 status code back to the user. |
tabID = 1 graphID = 1 graphType = "line" |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 |
deleteGraphTest() |
Returns a 200 status code back to the user. | Returns a 200 response code, which means that the response is OK. | Yes (see comments) |
This method does work, but doesn't test if it works with a wrong input given. This is because the thrown exception gets mapped by the mapper with the Provider annotation. This test strictly tests if the mapper does return the 403 code given by the user. |
Table 2: Tests in GraphDAOTest
2.1.3. GraphDAOTest class
Name |
Expected result |
Parameters |
Actual result |
Success |
Comments |
|
---|---|---|---|---|---|---|
1 | getGraphs() | All graphs with tabID are shown. | tabID = 1 | All graphs with the given tabID, are returned to the user. | Yes | |
2 | getUserTabsSqlException() | A DatabaseException will be thrown after a SQLException. | tabID = 1 | A SQLException is thrown. | Yes | |
3 | addGraphsTestSqlException() | A DatabaseException will be thrown after a SQLException. | tabID = 1 graphID = 1 graphType = "Linechart" |
A SQLException is thrown. | Yes | |
4 | deleteGraphsTest() | A DatabaseException will be thrown after a SQLException. |
tabID = 1 |
A SQLException is thrown. | Yes | |
5 | addGraph() | The method is verified by mockito verify. | tabID = 1 graphID = 1 graphType = "Linechart" |
The method is verified, which means that the method gets called and does not cause an exception. | Yes | |
6 | deleteGraph() | The method is verified by mockito verify. | tabID = 1 graphID = 1 |
The method is verified, which means that the method gets called and does not cause an exception. | Yes |
Table 3: Tests in GraphDAOTest
2.2. Tab tests
2.2.1. TabServiceTest class
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getAllTabsTest() | GraphsDTO{ name = "test" tabID = 1 id = 1 } |
||||
2 | deleteTabTest() | Throws a DatabaseException. |
tabID = 1 |
A DatabaseException is thrown. | Yes | The return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value. The method is also checked with the mockito.verify function. |
3 | createTabTest() |
Throws a DatabaseException. |
user = "testUser" tabName = "testTab" raceID = 1 |
A DatabaseException is thrown. | Yes | The return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value. The method is also checked with the mockito.verify function. |
Table 4: Tests in TabServiceTest
2.2.2. TabResourceTest class
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getTabsWithGoodJWT() | Returns a 200 status code back to the user. |
token = usernameErik |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 | createTabTest() | Returns a 200 status code back to the user. |
token = usernameErik |
Returns a 200 response code, which means that the response is OK. | Yes | |
3 | deleteTabTest() | Returns a 200 status code back to the user. |
token = usernameErik |
Returns a 200 response code, which means that the response is OK. | Yes | |
4 | getTabsWithBadJWT() | Returns a 403 status code back to the user. | token = "WrongToken" | Returns a 403 status code back to the user. | Yes | |
5 | createTabTestBadJWT() | Returns a 403 status code back to the user. | token = "WrongToken" tabName = "testTab" raceID = 1 |
Returns a 403 status code back to the user. | Yes | |
6 | deleteTabTestBadJWT() | Returns a 403 status code back to the user. | token = "WrongToken" tabID = 1 |
Returns a 403 status code back to the user. | Yes |
Table 5: Tests in TabResourceTest
2.2.3. TabDAOTest class
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getUserTabsCorrectly() | Expect a result that is not null. | username = 'Erik' | Returns something that is not null. | Yes | |
2 | getUserTabsSqlException() | A DatabaseException will be thrown after a SQLException. | username = 'Erik' | A DatabaseException is thrown. | Yes | |
3 | deleteTabTest() | A DatabaseException will be thrown after a SQLException. | tabID = 1 | A DatabaseException is thrown. | Yes | |
4 | createTabTest() | The method is verified by mockito verify. | username = "Erik" tabName = "testTab" raceID = 1 |
The method is verified, which means that the method gets called and does not cause an exception. | Yes | |
5 | createTabTestSqlException | A DatabaseException will be thrown after a SQLException. | username = "Erik" tabName = "testTab" raceID = 1 |
A DatabaseException is thrown. | Yes |
Table 6: Tests in TabDAOTest
2.3. Login tests
2.3.1. LoginServiceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | checkCorrectUsernameResponse() | Gives the same username back as the user has given to the system. |
LoginRequestDTO{ username = 'Erik' } |
The class returns 'Erik', and thus gives the same username back. | Yes | |
2 | checkCorrectTokenResponse() | Gives a new token dedicated to a specific name. |
LoginRequestDTO{ username = 'Erik' } |
The class returns the same token as expected for the user given. | Yes | |
3 | checkThrownExceptionWrongPassword() | Throws a LoginCredentialsIncorrectException after wrong input of the password. |
LoginRequestDTO{ username = 'Erik' } |
A LoginCredentialsIncorrectException is thrown. | Yes | The DAO response is set to 0, to simulate the database returning nothing. |
4 | checkThrownExceptionWrongUser() | Throws a LoginCredentialsIncorrectException after wrong input of the name. |
LoginRequestDTO{ username = 'WrongUser' } |
A LoginCredentialsIncorrectException is thrown. | Yes | The DAO response is set to 0, to simulate the database returning nothing. |
5 | checkThrownExceptionNoUserAndPassword() | Throws a LoginCredentialsIncorrectException after no input. |
LoginRequestDTO{ username = '' } |
A LoginCredentialsIncorrectException is thrown. | Yes | The DAO response is set to 0, to simulate the database returning nothing. |
6 | testCreationToken() | Creates a token based on the name that it has received. | username = 'Erik' | Creates the token from username 'Erik'. | Yes |
Table 7: Tests in LoginServiceTest
2.3.2. LoginResourceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getUserHTMLcodeWithCorrectInformation() | Returns a 200 status code back to the user. |
LoginRequestDTO{ username = 'Erik' } |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 |
getUserHTMLcodeWithIncorrectInformation() |
Returns a 403 status code back to the user. | Returns a 403 response code, which means it was a FORBIDDEN request. | Yes (see comments) |
This method does work, but doesn't test if it works with a wrong input given. This is because the thrown exception gets mapped by the mapper with the Provider annotation. This test strictly tests if the mapper does return the 403 code given by the user. | |
3 | checkExceptionThrown() | Throws a LoginCredentialsIncorrectException after wrong input of the password in resource. |
LoginRequestDTO{ username = 'Erik' } |
A LoginCredentialsIncorrectException is thrown. | Yes |
Table 8: Tests in LoginResourceTest
2.3.3. UserDAOTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getUserCorrectly() | Expect a result that is not null. |
username = 'Erik' |
Returns something that is not null. | Yes | |
2 |
getUserSqlException() |
Throws a SQLException that in return throws a DatabaseException. | username = 'Erik' | A DatabaseException is thrown. | Yes |
|
3 | getUserIDCorrectly() | Returns a one back. |
Table 9: Tests in UserDAOTest
2.4. Race tests
2.4.1. RaceServiceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getAllRaces() |
Returns a list of DTO's. In this case we only put the following DTO inside the list. RaceDTO{ |
Returns the expected RaceDTO. | Yes |
Table 10: Tests in RaceServiceTest
2.4.2. RaceResourceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getRacesWithGoodJWT() |
A 200 response code. |
token = usernameErik |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 | returnsAllRaces() |
Returns a list of DTO's. In this case we only put the following DTO inside the list. RaceDTO{ |
token = usernameErik | Returns the expected list of DTO's. It does however, return it in an object type. It does return the same information as provided with the DTO, it still gives out a success. | Yes | The response from the service is set manually. This is done to prevent the test from executing code beyond the resource. If this is not set manually, it would test the DAO, service class and the database, which is not necessary for this class. These tests are done in their own classes seperate from this class. |
3 | getRacesWithBadJWT() | A 403 response code. | token = "WrongToken" | Returns a 403 response code, which means it was a FORBIDDEN request. | Yes |
Table 11: Tests in RaceResourceTest
2.4.3. RaceDAOTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getAllRaces() |
Expect a result that is not null. |
|
Returns something that is not null. | Yes | |
2 |
getAllRacesSqlException() |
Throws a SQLException that in return throws a DatabaseException. |
A DatabaseException is thrown. | Yes | ||
3 | testDataAllRaces() |
Returns a list of DTO's. In this case we only put the following DTO inside the list. |
Returns the expected list of DTOs. For this check the asserts check if the data inside the DTOs are the same. This includes: the raceid, the name of the race and the date. | Yes |
Table 12: Tests in RaceDAOTest
2.5. SensorWithGraph tests
2.5.1. SensorServiceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getAllSensors() |
Returns a list of DTO's. In this case we only put the following DTO inside the list. SensorWithGraphDTO{ |
Returns the expected list of DTO's with the correct DTO inside the list. | Yes |
Table 13: Test in SensorServiceTest
2.5.2. SensorWithGraphResourceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getGraphDataWithGoodJWT() |
A 200 response code. |
token = usernameErik |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 | returnsAllSensors() |
Returns a list of DTO's. In this case we only put the following SensorWithGraphDTO's inside the list. sensorDTO{ sensorDTO2{ |
token = usernameErik | Returns the expected list of DTO's. It does however, return it in an object type. It does return the same information as provided with the DTO, it still gives out a success. | Yes | The response from the service is set manually. This is done to prevent the test from executing code beyond the resource. If this is not set manually, it would test the DAO, service class and the database, which is not necessary for this class. These tests are done in their own classes seperate from this class. |
3 | getGraphDataWithBadJWT() | A 403 response code. | token = "WrongToken" | Returns a 403 response code, which means it was a FORBIDDEN request. | Yes |
Table 14: Tests in SensorWithGraphResourceTest
2.5.3. SensorWithGraphDAOTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getSensorLinkedWithGraphsCorrectly() |
Expect a result that is not null. |
|
Returns something that is not null. | Yes | |
2 |
getUserTabsSQLException() |
Throws a SQLException that in return throws a DatabaseException. |
A DatabaseException is thrown. | Yes |
Table 15: Tests in SensorWithGraphDAOTest
2.6. GaugeGraphSettings tests
2.6.1. SensorSettingsResourceTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getSettingsWithGoodJWT() | A 200 response code. | token = usernameErik sensor = "Oil temperature" |
Returns a 200 response code, which means that the response is OK. | Yes | |
2 | getSettingsWithWithWrongJWT() | A 403 response code. | token = "WrongToken" sensor = "Oil temperature" |
Returns a 403 response code, which means it was a FORBIDDEN request. | Yes |
Table 16: Tests in SensorSettingsResourceTest
2.6.2. GaugeGraphSettingsDAOTest
Name |
Expected result |
Parameters |
Actual result |
Success | Comments | |
---|---|---|---|---|---|---|
1 | getSensorSettingsForGauge() |
Expect a result that is not null. |
|
Returns something that is not null. | Yes | |
2 |
getSensorSettingsForLinechart() |
Expect a result that is not null. |
A DatabaseException is thrown. | Yes | ||
3 | getSensorSettingsForGaugeException() | Throws a SQLException that in return throws a DatabaseException. | A DatabaseException is thrown. | Yes |
Table 17: Tests in GaugeGraphSettingsDAOTest
2.7. DtoTest
This class tests if the DTO's do not contain any logic and only getters and setters. The testPojoStructureAndBehavior() function executes this test. Pojo is a dependency that can be used for this kind of testing.
3. Conclusion
The application contains 52 unit tests that cover about 87.2% of the application. All tests are succesful and only test the classes and methods that they are meant to test. With these statistics we can call this application reliable, secured, maintained and mostly covered.