-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAMEL-19182: camel-platform-http-starter - Async processing with Spri…
…ng Boot - Spring MVC automatically detects CompletableFuture return type of the handler method and executes asynchronously; @responsebody on the handler method to disable attempts to resolve mvc view from a response. - testing async execution with MockMvc - @EnableAutoConfiguration instead of @SpringBootApplication on test classes to not scan another tests' configurations
- Loading branch information
Showing
7 changed files
with
129 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
...apache/camel/component/platform/http/springboot/PlatformHttpAsyncRequestHandlingTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.component.platform.http.springboot; | ||
|
||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.spring.boot.CamelAutoConfiguration; | ||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.annotation.DirtiesContext; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
@EnableAutoConfiguration | ||
@DirtiesContext | ||
@CamelSpringBootTest | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = { CamelAutoConfiguration.class, | ||
SpringBootPlatformHttpRestDSLTest.class, PlatformHttpAsyncRequestHandlingTest.TestConfiguration.class, | ||
PlatformHttpComponentAutoConfiguration.class, SpringBootPlatformHttpAutoConfiguration.class, }) | ||
@AutoConfigureMockMvc | ||
public class PlatformHttpAsyncRequestHandlingTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
public void testGet() throws Exception { | ||
MvcResult mvcResult = mockMvc.perform(get("/myget")) | ||
.andExpect(status().isOk()) | ||
.andExpect(request().asyncStarted()) | ||
.andReturn(); | ||
|
||
mockMvc.perform(asyncDispatch(mvcResult)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("get")); | ||
} | ||
|
||
@Test | ||
public void testPost() throws Exception { | ||
MvcResult mvcResult = mockMvc.perform(post("/mypost").content("hello")) | ||
.andExpect(status().isOk()) | ||
.andExpect(request().asyncStarted()) | ||
.andReturn(); | ||
|
||
mockMvc.perform(asyncDispatch(mvcResult)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().string("HELLO")); | ||
} | ||
|
||
// ************************************* | ||
// Config | ||
// ************************************* | ||
@Configuration | ||
public static class TestConfiguration { | ||
|
||
@Bean | ||
public RouteBuilder servletPlatformHttpRouteBuilder() { | ||
return new RouteBuilder() { | ||
@Override | ||
public void configure() throws Exception { | ||
from("platform-http:/myget").setBody().constant("get"); | ||
from("platform-http:/mypost").transform().body(String.class, b -> b.toUpperCase()); | ||
} | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
components-starter/camel-platform-http-starter/src/test/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
logging.level.org.springframework.web: DEBUG | ||
logging.level.org.springframework.boot.web: DEBUG |