webapp icon indicating copy to clipboard operation
webapp copied to clipboard

Handle upgrade of hibernate-validator from 6.1.7.Final to 7.0.1.Final

Open nya-elimu opened this issue 3 years ago • 3 comments

This version of the hibernate-validator will result in validation to stop working, so we need to handle this before bumping the version.

  • [ ] Find a way to upgrade Hibernate validation to the latest version without breaking the functionality of annotations like @NotNull and @NotEmpty.
  • [ ] Add unit tests for verifying that it is not possible to store entities with missing @NotNull/@NotEmpty properties.
  • [ ] Remove the @Ignore annotation from this unit test: https://github.com/elimu-ai/webapp/blob/master/src/test/java/ai/elimu/dao/ContributorDaoTest.java#L26

See https://hibernate.org/validator/documentation/migration-guide/


Relates to https://github.com/elimu-ai/webapp/pull/1211

nya-elimu avatar May 24 '21 08:05 nya-elimu

@nya-elimuai I upgraded the version locally but don't see any test errors. Is there a test that should fail to demonstrate the issue with upgrading?

macdude357 avatar May 24 '21 19:05 macdude357

@nya-elimuai I upgraded the version locally but don't see any test errors. Is there a test that should fail to demonstrate the issue with upgrading?

@macdude357 Apologies for lack of details in this issue. So let me help you out with a little information 🙂

One way to test this error is to launch the webapp, go to http://localhost:8080/webapp/content/word/list, and then adding a new Word without including any of the compulsory fields (those marked with @NotEmpty or @NotNull).

Here is how to reproduce:

  1. Submit the "Create Word" form without willing any of the details:

    Screen Shot 2021-05-25 at 7 29 52 AM
  2. The Word will still be stored in the database, and will erroneously appear in the list of Words:

    Screen Shot 2021-05-25 at 7 30 10 AM

And your point about unit tests not failing is a good one. Actually, we should add a couple of unit tests to cover this specific issue. By for example trying to store a Word in the database without first populating the required properties, and then use something like @Test(expected=ConstraintViolationException.class).

CC @UmenR

nya-elimu avatar May 25 '21 05:05 nya-elimu

As a related topic, also note that Hibernate validation is currently not working in our MockMvc unit tests: https://github.com/elimu-ai/webapp/blob/main/src/test/java/ai/elimu/web/content/word/WordCreateControllerTest.java#L53

@Test
    public void testHandleSubmit_emptyText() throws Exception {
        RequestBuilder requestBuilder = MockMvcRequestBuilders
                .post("/content/word/create")
                .param("timeStart", String.valueOf(System.currentTimeMillis()))
                .param("text", "")
                .contentType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
//        MvcResult mvcResult = mockMvc.perform(requestBuilder).andReturn();
//        assertEquals(HttpStatus.BAD_REQUEST.value(), mvcResult.getResponse().getStatus());
//        assertEquals("content/word/create", mvcResult.getModelAndView().getViewName());
    }

More info here: https://stackoverflow.com/questions/24049480/spring-mockmvc-doesnt-consider-validation-in-my-test

nya-elimu avatar Jul 22 '22 07:07 nya-elimu