elimu-ai / webapp

🖥 Web application for hosting Android applications and educational content
https://hin.elimu.ai
MIT License
31 stars 57 forks source link

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

Open nya-elimu opened 3 years ago

nya-elimu commented 3 years ago

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

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


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

macdude357 commented 3 years ago

@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?

nya-elimu commented 3 years ago

@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 commented 2 years ago

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