-
-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tests for REST controllers fail when the size of the test data set exceeds the page request size in PageRequestVM #220
Comments
The pagination shows the correct number of items in the HTML. It gets the total from the response header (see Note also that this problem also affects tests that check for the existence of an entity by getting the whole array and then searching it for the entity. If the entity is outside the page boundary, the test fails even though it is actually in the database. |
Added bug bounty to get this fixed. Please submit a PR if you have time. |
I am currently working on this issue. Using The thing about retrieving the entity from a paged response is more tricky. e.g. @Test
public void createMyEntityA() {
var databaseSizeBeforeCreate = getDatabaseSize();
// Create the MyEntityA
myEntityA =
given()
.auth()
.preemptive()
.oauth2(adminToken)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.body(myEntityA)
.when()
.post("/api/my-entity-as")
.then()
.statusCode(CREATED.getStatusCode())
.extract()
.as(ENTITY_TYPE);
// Validate the MyEntityA in the database
var myEntityAList = given()
.auth()
.preemptive()
.oauth2(adminToken)
.accept(APPLICATION_JSON)
.when()
.get("/api/my-entity-as")
.then()
.statusCode(OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract()
.as(LIST_OF_ENTITY_TYPE);
assertThat(myEntityAList).hasSize(databaseSizeBeforeCreate + 1);
var testMyEntityA = myEntityAList.stream().filter(it -> myEntityA.id.equals(it.id)).findFirst().get();
assertThat(testMyEntityA.fieldName).isEqualTo(DEFAULT_FIELD_NAME);
} Alternative: @Test
public void createMyEntityA() {
var databaseSizeBeforeCreate = getDatabaseSize();
// Create the MyEntityA
myEntityA =
given()
.auth()
.preemptive()
.oauth2(adminToken)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.body(myEntityA)
.when()
.post("/api/my-entity-as")
.then()
.statusCode(CREATED.getStatusCode())
.extract()
.as(ENTITY_TYPE);
// Validate the MyEntityA in the database
var testMyEntityA = given()
.auth()
.preemptive()
.oauth2(adminToken)
.accept(APPLICATION_JSON)
.when()
.get("/api/my-entity-as/{id}", myEntityA.id)
.then()
.statusCode(OK.getStatusCode())
.contentType(APPLICATION_JSON)
.extract()
.as(ENTITY_TYPE);
var databaseSizeAfterCreate = getDatabaseSize();
assertThat(databaseSizeAfterCreate).isEqualTo(databaseSizeBeforeCreate + 1);
assertThat(testMyEntityA.fieldName).isEqualTo(DEFAULT_FIELD_NAME);
} This would introduce an extra request, to get Thoughts on this? |
Describe the bug
Tests for REST controllers fail when the size of the test data set exceeds the page request size in PageRequestVM when pagination is implemented.
The tests fail because they use the size of the array returned by the
.get("/api/<%= entityApiUrl %>")
clause as a proxy for the size of the dataset in the database.This is not correct because the size of the array is limited to the page request size in PageRequestVM if pagination is implemented.
If the number of test data items exceeds the page request size (default is 50), the tests that use the array fail because the size is either larger than expected, or the entity cannot be found because it is outside the page that is returned.
To Reproduce
Expected behavior
All tests should pass irrespective of the test dataset size.
Screenshots
For example, the REST test for delete failes with:
Desktop (please complete the following information):
Not relevant
Smartphone (please complete the following information):
Not relevant
Additional context
None
The text was updated successfully, but these errors were encountered: