paulcwarren/spring-content

Multipart request to create entity and content in one request fail to create entity when file is missing

Closed this issue · 0 comments

Describe the bug
If no file is provided in the multipart request to create entity and content, the creation of the self-link fails because the Id property is null.

  • The Id property is null because savedEntity is not yet persisted with repository.save()
  • When providing a file, savedEntity is persisted during setContent()

To Reproduce

@Test
void postMultipartEntityAndContent_noFile_http201() throws Exception {
    mockMvc.perform(multipart(HttpMethod.POST, "/invoices")
                    .param("number", INVOICE_NUMBER)
                    .param("customer", "/customers/" + CUSTOMER_ID))
            .andExpect(status().isCreated());
}

Results in: IllegalArgumentException: Id must be assignable to Serializable: null

Expected behavior
Entity gets created without the content property set