Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

In this document we will take a look at the safety of trustworthiness of the application. The unit tests will determine if the application functions correctly. This  This is mainly focused on unit tests and what they do.

...

The token usernameErik is defined as "eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.ewogICAgIm5hbWUiOiAiRXJpayIKfQ==.2d2c39f777b16f75c701e851e9ec20d45f4134a281155e0c6f909876228d7d80"

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.

Tests

Graph tests

GraphServiceTest class

The response from the DAO is set manually, because a connection to the real database is not safe in tests. The response is the same GraphsDTO, to see if the getter works en returns the list from GraphDAO.

Name

Expected result

Parameters

Actual result

SuccessComments
1getAllGraphs()

Returns a GraphsDTO with the following information.

GraphsDTO{

name = "test"

tabID =  1

id = 1

}


Returns the expected list of DTOs.Yes
2addGraph()Throws a DatabaseException.

tabID = 1

graphID = 1

graphType = "linechart"

A DatabaseException is thrown.YesThe return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value.
3deleteGraphs()Throws a DatabaseException.

tabID = 1

graphID = 1

A DatabaseException is thrown.YesThe return value cannot be tested, since this method returns a void. That is why the Exception is checked, instead of a return value.

...

Table 3: Tests in GraphDAOTest

Tab tests

TabServiceTest class


Name

Expected result

Parameters

Actual result

SuccessComments
1



















Table 4: Tests in TabServiceTest

TabResourceTest class


Name

Expected result

Parameters

Actual result

SuccessComments
1getTabsWithGoodJWT()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
deleteGraphTest()
Returns a 200 status code back to the user.
token WrongToken
Returns a 403 response code, which means it was a FORBIDDEN request.Yes

Table 5: Tests in TabResourceTest

...


Name

Expected result

Parameters

Actual result

SuccessComments
1getUserTabsCorrectly()Expect a result that is not null.username = 'Erik'Returns something that is not null.YesThe response from the database is set manually, because a connection to the real database is not safe in tests.
2getUserTabsSqlException()A DatabaseException will be thrown after a SQLException. username = 'Erik'A DatabaseException is thrown.Yes

Table 6: Tests in TabDAOTest


Login tests

LoginServiceTest

The response from the database is set manually, because a connection to the real database is not safe in tests.

Name

Expected result

Parameters

Actual result

SuccessComments
1checkCorrectUsernameResponse()Gives the same username back as the user has given to the system.

LoginRequestDTO{

username = 'Erik'
password = 'Welkom123'

}

The class returns 'Erik', and thus gives the same username back.Yes
2checkCorrectTokenResponse()Gives a new token dedicated to a specific name.

LoginRequestDTO{

username = 'Erik'
password = 'Welkom123'

}

The class returns the same token as expected for the user given.YesThe response from the database is set manually, because a connection to the real database is not safe in tests.
3checkThrownExceptionWrongPassword()Throws a LoginCredentialsIncorrectException after wrong input of the password.

LoginRequestDTO{

username = 'Erik'
password = 'WrongPassword'

}

A LoginCredentialsIncorrectException is thrown.YesThe DAO response from the database is set manually, because a connection to the real database is not safe in tests. In this case it's set to 0, to simulate the database returning nothing.
4checkThrownExceptionWrongUser()Throws a LoginCredentialsIncorrectException after wrong input of the name.

LoginRequestDTO{

username = 'WrongUser'
password = 'Welkom123'

}

A LoginCredentialsIncorrectException is thrown.YesThe DAO response from the database is set manually, because a connection to the real database is not safe in tests. In this case it's set to 0, to simulate the database returning nothing.
5checkThrownExceptionNoUserAndPassword()Throws a LoginCredentialsIncorrectException after no input.

LoginRequestDTO{

username = ''
password = ''

}

A LoginCredentialsIncorrectException is thrown.YesThe DAO response from the database is set manually, because a connection to the real database is not safe in tests. In this case it's set to 0, to simulate the database returning nothing.
6testCreationToken()Creates a token based on the name that it has received.username = 'Erik'Creates the token from username 'Erik'.Yes

...

We manually added some return values of this function, to test if it would work. This test cannot connect to the database, since a unit test may not do this.

Name

Expected result

Parameters

Actual result

SuccessComments
1getUserCorrectly()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

Table 9: Tests in UserDAOTest

Race tests

RaceServiceTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getAllRaces()

Returns a list of DTO's. In this case we only put the following DTO inside the list.

RaceDTO{

raceID = 1

raceName = "BMW Race"

date = "2022-05-22"

}


Returns the expected RaceDTO.YesThe response from the DAO is set manually, because a connection to the real database is not safe in tests. The response is the same RaceDTO, to see if the getter works en returns the list from RaceDAO.

...


Name

Expected result

Parameters

Actual result

SuccessComments
1getAllRaces()

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
3testDataAllRaces()

Returns a list of DTO's. In this case we only put the following DTO inside the list.

RaceDTO{
raceID = 1
raceName = "BMW Race"
date = "2022-02-22"
}


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.YesFor this test we manually changed the outcome of the resultset to simulate the database sending data to the code. This also happens in the Resultset.next function, to see if the DTO's are called.

Table 12: Tests in RaceDAOTest

DtoTest

This class tests if the DTO's do not contain any logic and only getters and setters.