Versions Compared

Key

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

AuthorsAuthor:

Name

Student number

679586

...

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.

...


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. The method can however be tested by the mockito.verify function.
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. The method can however be tested by the mockito.verify function.

...


Name

Expected result

Parameters

Actual result

Success

Comments

1getGraphs()All graphs with tabID are shown.tabID = 1All graphs with the given tabID, are returned to the user.Yes
2getUserTabsSqlException()A DatabaseException will be thrown after a SQLException. tabID = 1A SQLException is thrown.Yes
3addGraphsTestSqlException()A DatabaseException will be thrown after a SQLException. tabID = 1
graphID = 1
graphType = "Linechart"
A SQLException is thrown.Yes
4deleteGraphsTest()A DatabaseException will be thrown after a SQLException. 

tabID = 1
graphID = 1

A SQLException is thrown.Yes
5addGraph()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
6deleteGraph()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

Tab tests

TabServiceTest class


Name

Expected result

Parameters

Actual result

SuccessComments
1getAllTabsTest()GraphsDTO{
name = "test"
tabID =  1
id = 1
}




2deleteTabTest()Throws a DatabaseException.

tabID = 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. The method is also checked with the mockito.verify function.
3createTabTest()

Throws a DatabaseException.

user = "testUser"
tabName = "testTab"
raceID = 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. The method is also checked with the mockito.verify function.

Table 4: Tests in TabServiceTest

...


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
2createTabTest()Returns a 200 status code back to the user.

token = usernameErik
tabName = "testTab"
raceID = 1

Returns a 200 response code, which means that the response is OK.Yes
3deleteTabTestdeleteGraphTest()Returns a 200 status code back to the user.

token

WrongToken

= usernameErik
tabID = 1

Returns a 403 200 response code, which means it was a FORBIDDEN requestthat the response is OK.Yes
4getTabsWithBadJWT()Returns a 403 status code back to the user.token = "WrongToken"Returns a 403 status code back to the user.Yes
5createTabTestBadJWT()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
6deleteTabTestBadJWT()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

...


Name

Expected result

Parameters

Actual result

SuccessComments
1getUserTabsCorrectly()Expect a result that is not null.username = 'Erik'Returns something that is not null.Yes
2getUserTabsSqlException()A DatabaseException will be thrown after a SQLException. username = 'Erik'A DatabaseException is thrown.Yes
3deleteTabTest()A DatabaseException will be thrown after a SQLException. tabID = 1A DatabaseException is thrown.Yes
4createTabTest()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
5createTabTestSqlExceptionA DatabaseException will be thrown after a SQLException. username = "Erik"
tabName = "testTab"
raceID = 1
A DatabaseException is thrown.Yes

Table 6: Tests in TabDAOTest

...


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

3getUserIDCorrectly()Returns a one back.



Table 9: Tests in UserDAOTest

...


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.

Table 10: Tests in RaceServiceTest

...

Table 12: Tests in RaceDAOTest

SensorWithGraph tests

SensorServiceTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getAllSensors() 

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

SensorWithGraphDTO{
sensorID= 1
sensorName= "Oil"
graphTypeDTOList = new Arraylist<>()
}


Returns the expected list of DTO's with the correct DTO inside the list.Yes

Table 13: Test in SensorServiceTest

SensorWithGraphResourceTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getGraphDataWithGoodJWT()

A 200 response code.

token = usernameErik

Returns a 200 response code, which means that the response is OK.Yes
2returnsAllSensors()

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

sensorDTO{
sensorID= 1
sensorName= "Oil"
graphTypeDTOList = new Arraylist<>()
}

sensorDTO2{
sensorID= 2
sensorName= "Not Oil"
graphTypeDTOList = new Arraylist<>()
}

token = usernameErikReturns 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.YesThe 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.
3getGraphDataWithBadJWT()A 403 response code.token = "WrongToken"Returns a 403 response code, which means it was a FORBIDDEN request.Yes

Table 14: Tests in SensorWithGraphResourceTest

SensorWithGraphDAOTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getSensorLinkedWithGraphsCorrectly()

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

GaugeGraphSettings tests

SensorSettingsResourceTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getSettingsWithGoodJWT()A 200 response code.token = usernameErik
sensor = "Oil temperature"
Returns a 200 response code, which means that the response is OK.Yes
2getSettingsWithWithWrongJWT()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

GaugeGraphSettingsDAOTest


Name

Expected result

Parameters

Actual result

SuccessComments
1getSensorSettingsForGauge()

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
3getSensorSettingsForGaugeException()Throws a SQLException that in return throws a DatabaseException.
A DatabaseException is thrown.Yes

Table 17: Tests in GaugeGraphSettingsDAOTest

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.

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.