Open nya-elimu opened 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-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:
Submit the "Create Word" form without willing any of the details:
The Word will still be stored in the database, and will erroneously appear in the list of Words:
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
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
This version of the hibernate-validator will result in validation to stop working, so we need to handle this before bumping the version.
@NotNull
and@NotEmpty
.@NotNull
/@NotEmpty
properties.@Ignore
annotation from this unit test: https://github.com/elimu-ai/webapp/blob/master/src/test/java/ai/elimu/dao/ContributorDaoTest.java#L26See https://hibernate.org/validator/documentation/migration-guide/
Relates to https://github.com/elimu-ai/webapp/pull/1211