Add async test for serverless-web
This commit is contained in:
@@ -65,8 +65,6 @@ public final class ProxyMvc {
|
||||
|
||||
private static Log LOG = LogFactory.getLog(ProxyMvc.class);
|
||||
|
||||
static final String MVC_RESULT_ATTRIBUTE = ProxyMvc.class.getName().concat(".MVC_RESULT_ATTRIBUTE");
|
||||
|
||||
private final DispatcherServlet dispatcher;
|
||||
|
||||
private final ConfigurableWebApplicationContext applicationContext;
|
||||
@@ -142,8 +140,6 @@ public final class ProxyMvc {
|
||||
|
||||
|
||||
public void service(HttpServletRequest request, HttpServletResponse response, CountDownLatch latch) throws Exception {
|
||||
((ProxyHttpServletRequest) request).setAsyncStarted(true);
|
||||
|
||||
ProxyFilterChain filterChain = new ProxyFilterChain(this.dispatcher);
|
||||
filterChain.doFilter(request, response);
|
||||
|
||||
@@ -190,7 +186,6 @@ public final class ProxyMvc {
|
||||
ProxyFilterChain(DispatcherServlet servlet) {
|
||||
List<Filter> filters = new ArrayList<>();
|
||||
servlet.getServletContext().getFilterRegistrations().values().forEach(fr -> filters.add(((ProxyFilterRegistration) fr).getFilter()));
|
||||
//servlet.getWebApplicationContext().getBeansOfType(Filter.class).values().forEach(f -> filters.add(f));
|
||||
Assert.notNull(filters, "filters cannot be null");
|
||||
Assert.noNullElements(filters, "filters cannot contain null values");
|
||||
this.filters = initFilterList(servlet, filters.toArray(new Filter[] {}));
|
||||
|
||||
@@ -134,4 +134,22 @@ public class RequestResponseTests {
|
||||
assertThat(pet.getName()).isNotEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatePostAsyncWithBody() throws Exception {
|
||||
ProxyHttpServletRequest request = new ProxyHttpServletRequest(null, "POST", "/petsAsync/");
|
||||
String jsonPet = "{\n"
|
||||
+ " \"id\":\"1234\",\n"
|
||||
+ " \"breed\":\"Canish\",\n"
|
||||
+ " \"name\":\"Foo\",\n"
|
||||
+ " \"date\":\"2012-04-23T18:25:43.511Z\"\n"
|
||||
+ "}";
|
||||
request.setContent(jsonPet.getBytes());
|
||||
request.setContentType("application/json");
|
||||
ProxyHttpServletResponse response = new ProxyHttpServletResponse();
|
||||
mvc.service(request, response);
|
||||
Pet pet = mapper.readValue(response.getContentAsByteArray(), Pet.class);
|
||||
assertThat(pet).isNotNull();
|
||||
assertThat(pet.getName()).isNotEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,12 +28,27 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
|
||||
@RestController
|
||||
@EnableWebMvc
|
||||
public class PetsController {
|
||||
|
||||
@RequestMapping(path = "/petsAsync/", method = RequestMethod.POST)
|
||||
public DeferredResult<Pet> createPetAsync(@RequestBody Pet newPet) {
|
||||
if (newPet.getName() == null || newPet.getBreed() == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Pet dbPet = newPet;
|
||||
dbPet.setId(UUID.randomUUID().toString());
|
||||
DeferredResult<Pet> result = new DeferredResult<Pet>();
|
||||
result.setResult(dbPet);
|
||||
return result;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/pets/", method = RequestMethod.POST)
|
||||
public Pet createPet(@RequestBody Pet newPet) {
|
||||
if (newPet.getName() == null || newPet.getBreed() == null) {
|
||||
|
||||
Reference in New Issue
Block a user