Support for returning response bodies on deletion of item resources.

RepositoryRestConfiguration now allows to configure to return a response body for the deletion of item resources. The controller implementation follows the same patter we have already established for creation and updates: unless explicitly enabled or disabled we now consider the presence of an accept header as indicator of whether a response body should be rendered.

This could be a "breaking" change for clients having explicitly expected 204 until now even for requests with an Accept header. If that's an issue, those should either explicitly disable the setting, do not submit an Accept header or loosen their expectations to expect either 200 or 2xx as indicator of success in general.

Fixes #2225.
This commit is contained in:
Oliver Drotbohm
2023-02-21 17:25:28 +01:00
parent 7c0fc837a3
commit d02d1bb0c1
4 changed files with 76 additions and 8 deletions

View File

@@ -29,7 +29,6 @@ import org.springframework.data.map.repository.config.EnableMapRepositories;
import org.springframework.data.rest.tests.AbstractWebIntegrationTests;
import org.springframework.data.rest.tests.TestMvcClient;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -37,7 +36,6 @@ import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@@ -140,7 +138,7 @@ class SecurityIntegrationTests extends AbstractWebIntegrationTests {
SecurityContextHolder.clearContext();
mvc.perform(delete(href).with(user("user").roles("USER", "ADMIN")))
.andExpect(status().is(HttpStatus.NO_CONTENT.value()));
.andExpect(status().is2xxSuccessful());
}
@Test // DATAREST-327
@@ -205,7 +203,7 @@ class SecurityIntegrationTests extends AbstractWebIntegrationTests {
SecurityContextHolder.clearContext();
mvc.perform(delete(href).with(user("user").roles("USER", "ADMIN")))
.andExpect(status().is(HttpStatus.NO_CONTENT.value()));
.andExpect(status().is2xxSuccessful());
}
@Test // DATAREST-327
@@ -240,7 +238,6 @@ class SecurityIntegrationTests extends AbstractWebIntegrationTests {
String href = assertHasJsonPathValue("$._embedded.orders[0]._links.self.href", response);
mvc.perform(get(href).with(user("user").roles("USER")))
.andDo(MockMvcResultHandlers.print())
.andExpect(status().isForbidden());
}
}