JAVA-2420 Merge spring-apache-camel and spring-boot-camel modules (#13409)
* JAVA-2420 Merge spring-apache-camel and spring-boot-camel modules * JAVA-2420 Migrate spring-boot-camel to spring-apache camel * JAVA-2420 Update README.md file * JAVA-2420 Remove spring-boot-camel --------- Co-authored-by: timis1 <noreplay@yahoo.com>
This commit is contained in:
@@ -1 +0,0 @@
|
||||
/output/
|
||||
@@ -1,30 +0,0 @@
|
||||
## Spring Boot Camel
|
||||
|
||||
This module contains articles about Spring Boot with Apache Camel
|
||||
|
||||
### Example for the Article on Camel API with SpringBoot
|
||||
|
||||
To start, run:
|
||||
|
||||
`mvn spring-boot:run`
|
||||
|
||||
Then, make a POST http request to:
|
||||
|
||||
`http://localhost:8080/camel/api/bean`
|
||||
|
||||
Include the HEADER: Content-Type: application/json,
|
||||
|
||||
and a BODY Payload like:
|
||||
|
||||
`{"id": 1,"name": "World"}`
|
||||
|
||||
We will get a return code of 201 and the response: `Hello, World` - if the transform() method from Application class is uncommented and the process() method is commented
|
||||
|
||||
or return code of 201 and the response: `{"id": 10,"name": "Hello, World"}` - if the transform() method from Application class is commented and the process() method is uncommented
|
||||
|
||||
## Relevant articles:
|
||||
|
||||
- [Apache Camel with Spring Boot](https://www.baeldung.com/apache-camel-spring-boot)
|
||||
- [Apache Camel Routes Testing in Spring Boot](https://www.baeldung.com/spring-boot-apache-camel-routes-testing)
|
||||
- [Apache Camel Conditional Routing](https://www.baeldung.com/spring-apache-camel-conditional-routing)
|
||||
- [Apache Camel Exception Handling](https://www.baeldung.com/java-apache-camel-exception-handling)
|
||||
@@ -1,80 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>spring-boot-camel</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-boot-camel</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring-boot-modules</groupId>
|
||||
<artifactId>spring-boot-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-servlet-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-jackson-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-swagger-java-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel.springboot</groupId>
|
||||
<artifactId>camel-spring-boot-starter</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.camel</groupId>
|
||||
<artifactId>camel-test-spring-junit5</artifactId>
|
||||
<version>${camel.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<defaultGoal>spring-boot:run</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.camel.boot.testing.GreetingsFileSpringApplication</mainClass>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<camel.version>3.15.0</camel.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
-107
@@ -1,107 +0,0 @@
|
||||
package com.baeldung.camel;
|
||||
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.apache.camel.component.servlet.CamelHttpTransportServlet;
|
||||
import org.apache.camel.impl.DefaultCamelContext;
|
||||
import org.apache.camel.model.rest.RestBindingMode;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.aop.AopAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.security.oauth2.resource.servlet.OAuth2ResourceServerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.embedded.EmbeddedWebServerFactoryCustomizerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.websocket.servlet.WebSocketServletAutoConfiguration;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@SpringBootApplication(exclude = { WebSocketServletAutoConfiguration.class, AopAutoConfiguration.class, OAuth2ResourceServerAutoConfiguration.class, EmbeddedWebServerFactoryCustomizerAutoConfiguration.class })
|
||||
@ComponentScan(basePackages = "com.baeldung.camel")
|
||||
public class Application {
|
||||
|
||||
@Value("${server.port}")
|
||||
String serverPort;
|
||||
|
||||
@Value("${baeldung.api.path}")
|
||||
String contextPath;
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
ServletRegistrationBean servletRegistrationBean() {
|
||||
ServletRegistrationBean servlet = new ServletRegistrationBean(new CamelHttpTransportServlet(), contextPath + "/*");
|
||||
servlet.setName("CamelServlet");
|
||||
return servlet;
|
||||
}
|
||||
|
||||
@Component
|
||||
class RestApi extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() {
|
||||
|
||||
CamelContext context = new DefaultCamelContext();
|
||||
|
||||
// http://localhost:8080/camel/api-doc
|
||||
restConfiguration().contextPath(contextPath) //
|
||||
.port(serverPort)
|
||||
.enableCORS(true)
|
||||
.apiContextPath("/api-doc")
|
||||
.apiProperty("api.title", "Test REST API")
|
||||
.apiProperty("api.version", "v1")
|
||||
.apiProperty("cors", "true") // cross-site
|
||||
.apiContextRouteId("doc-api")
|
||||
.component("servlet")
|
||||
.bindingMode(RestBindingMode.json)
|
||||
.dataFormatProperty("prettyPrint", "true");
|
||||
/**
|
||||
The Rest DSL supports automatic binding json/xml contents to/from
|
||||
POJOs using Camels Data Format.
|
||||
By default the binding mode is off, meaning there is no automatic
|
||||
binding happening for incoming and outgoing messages.
|
||||
You may want to use binding if you develop POJOs that maps to
|
||||
your REST services request and response types.
|
||||
*/
|
||||
|
||||
rest("/api/").description("Teste REST Service")
|
||||
.id("api-route")
|
||||
.post("/bean")
|
||||
.produces(MediaType.APPLICATION_JSON)
|
||||
.consumes(MediaType.APPLICATION_JSON)
|
||||
// .get("/hello/{place}")
|
||||
.bindingMode(RestBindingMode.auto)
|
||||
.type(MyBean.class)
|
||||
.enableCORS(true)
|
||||
// .outType(OutBean.class)
|
||||
|
||||
.to("direct:remoteService");
|
||||
|
||||
from("direct:remoteService").routeId("direct-route")
|
||||
.tracing()
|
||||
.log(">>> ${body.id}")
|
||||
.log(">>> ${body.name}")
|
||||
// .transform().simple("blue ${in.body.name}")
|
||||
.process(new Processor() {
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
MyBean bodyIn = (MyBean) exchange.getIn()
|
||||
.getBody();
|
||||
|
||||
ExampleServices.example(bodyIn);
|
||||
|
||||
exchange.getIn()
|
||||
.setBody(bodyIn);
|
||||
}
|
||||
})
|
||||
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(201));
|
||||
}
|
||||
}
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.camel;
|
||||
|
||||
/**
|
||||
* a Mock class to show how some other layer
|
||||
* (a persistence layer, for instance)
|
||||
* could be used insida a Camel
|
||||
*
|
||||
*/
|
||||
public class ExampleServices {
|
||||
|
||||
public static void example(MyBean bodyIn) {
|
||||
bodyIn.setName( "Hello, " + bodyIn.getName() );
|
||||
bodyIn.setId(bodyIn.getId()*10);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
package com.baeldung.camel;
|
||||
|
||||
public class MyBean {
|
||||
private Integer id;
|
||||
private String name;
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
-19
@@ -1,19 +0,0 @@
|
||||
package com.baeldung.camel.boot.testing;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class GreetingsFileRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start")
|
||||
.routeId("greetings-route")
|
||||
.setBody(constant("Hello Baeldung Readers!"))
|
||||
.to("file:output");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.camel.boot.testing;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class GreetingsFileSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(GreetingsFileSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalBeanRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional-bean")
|
||||
.routeId("conditional-bean-route")
|
||||
.choice()
|
||||
.when(method(FruitBean.class, "isApple"))
|
||||
.setHeader("favourite", simple("Apples"))
|
||||
.to("mock:result")
|
||||
.otherwise()
|
||||
.setHeader("favourite", header("fruit"))
|
||||
.to("mock:result")
|
||||
.end();
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalBodyRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional")
|
||||
.routeId("conditional-body-route")
|
||||
.choice()
|
||||
.when(body().contains("Baeldung"))
|
||||
.setBody(simple("Goodbye, Baeldung!"))
|
||||
.to("mock:result-body")
|
||||
.otherwise()
|
||||
.to("mock:result-body")
|
||||
.end();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-23
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ConditionalHeaderRouter extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-conditional-header")
|
||||
.routeId("conditional-header-route")
|
||||
.choice()
|
||||
.when(header("fruit").isEqualTo("Apple"))
|
||||
.setHeader("favourite", simple("Apples"))
|
||||
.to("mock:result")
|
||||
.otherwise()
|
||||
.setHeader("favourite", header("fruit"))
|
||||
.to("mock:result")
|
||||
.end();
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ConditionalRoutingSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ConditionalRoutingSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
-15
@@ -1,15 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
|
||||
public class FruitBean {
|
||||
|
||||
private FruitBean() {
|
||||
}
|
||||
|
||||
public static boolean isApple(Exchange exchange) {
|
||||
return "Apple".equals(exchange.getIn()
|
||||
.getHeader("fruit"));
|
||||
}
|
||||
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class ExceptionHandlingSpringApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(ExceptionHandlingSpringApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionHandlingWithDoTryRoute extends RouteBuilder {
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-handling-exception")
|
||||
.routeId("exception-handling-route")
|
||||
.doTry()
|
||||
.process(new IllegalArgumentExceptionThrowingProcessor())
|
||||
.to("mock:received")
|
||||
.doCatch(IOException.class, IllegalArgumentException.class)
|
||||
.to("mock:caught")
|
||||
.doFinally()
|
||||
.to("mock:finally")
|
||||
.end();
|
||||
|
||||
}
|
||||
}
|
||||
-24
@@ -1,24 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionHandlingWithExceptionClauseRoute extends RouteBuilder {
|
||||
|
||||
@Autowired
|
||||
private ExceptionLoggingProcessor exceptionLogger;
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
onException(IllegalArgumentException.class).process(exceptionLogger)
|
||||
.handled(true)
|
||||
.to("mock:handled");
|
||||
|
||||
from("direct:start-exception-clause")
|
||||
.routeId("exception-clause-route")
|
||||
.process(new IllegalArgumentExceptionThrowingProcessor())
|
||||
.to("mock:received");
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionLoggingProcessor implements Processor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionLoggingProcessor.class);
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
Map<String, Object> headersMap = exchange.getIn().getHeaders();
|
||||
|
||||
if (!headersMap.isEmpty()) {
|
||||
headersMap.entrySet()
|
||||
.stream()
|
||||
.forEach(e -> LOGGER.info("Header key [{}] -||- Header value [{}]", e.getKey(), e.getValue()));
|
||||
} else {
|
||||
LOGGER.info("Empty header");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.apache.camel.builder.RouteBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ExceptionThrowingRoute extends RouteBuilder {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionThrowingRoute.class);
|
||||
|
||||
@Override
|
||||
public void configure() throws Exception {
|
||||
|
||||
from("direct:start-exception")
|
||||
.routeId("exception-throwing-route")
|
||||
.process(new Processor() {
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
LOGGER.error("Exception Thrown");
|
||||
throw new IllegalArgumentException("An exception happened on purpose");
|
||||
|
||||
}
|
||||
}).to("mock:received");
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.Processor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class IllegalArgumentExceptionThrowingProcessor implements Processor {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionLoggingProcessor.class);
|
||||
|
||||
@Override
|
||||
public void process(Exchange exchange) throws Exception {
|
||||
LOGGER.error("Exception Thrown");
|
||||
throw new IllegalArgumentException("An exception happened on purpose");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
logging.config=classpath:logback.xml
|
||||
|
||||
# the options from org.apache.camel.spring.boot.CamelConfigurationProperties can be configured here
|
||||
camel.springboot.name=MyCamel
|
||||
|
||||
# lets listen on all ports to ensure we can be invoked from the pod IP
|
||||
server.address=0.0.0.0
|
||||
management.address=0.0.0.0
|
||||
|
||||
# lets use a different management port in case you need to listen to HTTP requests on 8080
|
||||
management.port=8081
|
||||
|
||||
# disable all management enpoints except health
|
||||
endpoints.enabled = true
|
||||
endpoints.health.enabled = true
|
||||
|
||||
spring.main.allow-bean-definition-overriding=true
|
||||
@@ -1,27 +0,0 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
# for example purposes of Camel version 2.18 and below
|
||||
baeldung:
|
||||
api:
|
||||
path: '/camel'
|
||||
|
||||
camel:
|
||||
springboot:
|
||||
# The Camel context name
|
||||
name: ServicesRest
|
||||
|
||||
# Binding health checks to a different port
|
||||
management:
|
||||
port: 8081
|
||||
|
||||
# disable all management enpoints except health
|
||||
endpoints:
|
||||
enabled: false
|
||||
health:
|
||||
enabled: true
|
||||
|
||||
# The application configuration properties
|
||||
quickstart:
|
||||
generateOrderPeriod: 10s
|
||||
processOrderPeriod: 30s
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!-- encoders are assigned the type
|
||||
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import com.baeldung.camel.Application;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class SpringContextTest {
|
||||
|
||||
@Test
|
||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
||||
}
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
package com.baeldung.camel.boot.testing;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
|
||||
import org.apache.camel.test.spring.junit5.MockEndpoints;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
@MockEndpoints("file:output")
|
||||
class GreetingsFileRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:file:output")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedBodiesReceived("Hello Baeldung Readers!");
|
||||
|
||||
template.sendBody("direct:start", null);
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ConditionalBeanRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendBodyWithFruit_thenFavouriteHeaderReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedHeaderReceived("favourite", "Apples");
|
||||
|
||||
template.sendBodyAndHeader("direct:start-conditional-bean", null, "fruit", "Apple");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ConditionalBodyRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result-body")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendBodyWithBaeldung_thenGoodbyeMessageReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedBodiesReceived("Goodbye, Baeldung!");
|
||||
|
||||
template.sendBody("direct:start-conditional", "Hello Baeldung Readers!");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.baeldung.camel.conditional;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ConditionalHeaderRouterUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:result")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendBodyWithFruit_thenFavouriteHeaderReceivedSuccessfully() throws InterruptedException {
|
||||
mock.expectedHeaderReceived("favourite", "Banana");
|
||||
|
||||
template.sendBodyAndHeader("direct:start-conditional-header", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ExceptionHandlingWithDoTryRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:caught")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendHeaders_thenExceptionRaisedAndHandledSuccessfully() throws Exception {
|
||||
mock.expectedMessageCount(1);
|
||||
|
||||
template.sendBodyAndHeader("direct:start-handling-exception", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
-30
@@ -1,30 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import org.apache.camel.EndpointInject;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
import org.apache.camel.component.mock.MockEndpoint;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ExceptionHandlingWithExceptionClauseRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@EndpointInject("mock:handled")
|
||||
private MockEndpoint mock;
|
||||
|
||||
@Test
|
||||
void whenSendHeaders_thenExceptionRaisedAndHandledSuccessfully() throws Exception {
|
||||
mock.expectedMessageCount(1);
|
||||
|
||||
template.sendBodyAndHeader("direct:start-exception-clause", null, "fruit", "Banana");
|
||||
|
||||
mock.assertIsSatisfied();
|
||||
}
|
||||
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.apache.camel.CamelContext;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.apache.camel.ExchangePattern;
|
||||
import org.apache.camel.ProducerTemplate;
|
||||
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.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@CamelSpringBootTest
|
||||
class ExceptionThrowingRouteUnitTest {
|
||||
|
||||
@Autowired
|
||||
private ProducerTemplate template;
|
||||
|
||||
@Test
|
||||
void whenSendBody_thenExceptionRaisedSuccessfully() {
|
||||
CamelContext context = template.getCamelContext();
|
||||
Exchange exchange = context.getEndpoint("direct:start-exception")
|
||||
.createExchange(ExchangePattern.InOut);
|
||||
|
||||
exchange.getIn().setBody("Hello Baeldung");
|
||||
Exchange out = template.send("direct:start-exception", exchange);
|
||||
|
||||
assertTrue(out.isFailed(), "Should be failed");
|
||||
assertTrue(out.getException() instanceof IllegalArgumentException, "Should be IllegalArgumentException");
|
||||
assertEquals("An exception happened on purpose", out.getException().getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
package com.baeldung.camel.exception;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class IllegalArgumentExceptionThrowingProcessorUnitTest {
|
||||
|
||||
@Test
|
||||
void whenProcessed_thenIllegalArgumentExceptionRaisedSuccessfully() {
|
||||
assertThrows(IllegalArgumentException.class, () -> {
|
||||
new IllegalArgumentExceptionThrowingProcessor().process(null);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user