Skip to content
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

Integration test not reliable with UUID as primary key #25387

Closed
emilpaw opened this issue Mar 1, 2024 · 4 comments
Closed

Integration test not reliable with UUID as primary key #25387

emilpaw opened this issue Mar 1, 2024 · 4 comments

Comments

@emilpaw
Copy link
Contributor

emilpaw commented Mar 1, 2024

Overview of the issue

While working on jhipster/generator-jhipster-quarkus#220 I noticed that JHipster generates tests as such:

    @Test
    @Transactional
    void getAllMyEntityAS() throws Exception {
        // Initialize the database
        myEntityARepository.saveAndFlush(myEntityA);

        // Get all the myEntityAList
        restMyEntityAMockMvc
            .perform(get(ENTITY_API_URL + "?sort=id,desc"))
            .andExpect(status().isOk())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
            .andExpect(jsonPath("$.[*].id").value(hasItem(myEntityA.getId().intValue())))
            .andExpect(jsonPath("$.[*].fieldName").value(hasItem(DEFAULT_FIELD_NAME)));
    }

I assume that ?sort=id,desc was used so that in the case of pagination, it can be assured that the newly created entity will be in the returned page. This works for the default Long IDs because they are auto incremented and as such sortable, but this does not hold true for UUIDs. So, in the case UUID is selected as the ID type, the newly created entity could possibly not be in the returned page and the test would fail.

Motivation for or Use Case

The tests should work reliably regardless of the chosen options.

Reproduce the error

Use an entity with UUID as the type. e.g.

entity MyEntityA {
    id UUID
}
Related issues

#13258

Suggest a Fix

I'm happy to help with working on the solution, but I am not sure what a good way to solve this is.

Loading all the entities by iterating over the pages could work, but this would introduce a lot of code.

JHipster Version(s)

v8.1.0

JHipster configuration
JDL entity definitions
@ChangelogDate("20240301122015")
entity MyEntityA {
  id UUID
}

paginate MyEntityA with pagination
search MyEntityA with no

@mshima

This comment was marked as resolved.

@mshima

This comment was marked as resolved.

@mshima
Copy link
Member

mshima commented Mar 7, 2024

I think the test doesn’t need to test specific values.
Need to test fields content type like optional/required, number/string and pattern.

Copy link
Contributor

github-actions bot commented Sep 4, 2024

This issue is stale because it has been open for too long without any activity.
Due to the moving nature of jhipster generated application, bugs can become invalid.
If this issue still applies please comment otherwise it will be closed in 7 days

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
@mraible mraible added this to the 8.7.1 milestone Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants