You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2019/05/27 11:12:43 UTC
[camel] branch master updated: CAMEL-13582: Camel main - init to
initialize as much as possible
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 1ba6715 CAMEL-13582: Camel main - init to initialize as much as possible
1ba6715 is described below
commit 1ba67159035f882b06be7757b25fb047c1e84069
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon May 27 13:12:26 2019 +0200
CAMEL-13582: Camel main - init to initialize as much as possible
---
.../src/main/java/org/apache/camel/main/Main.java | 8 +++++++-
.../src/test/java/org/apache/camel/main/MainIoCTest.java | 15 +++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/core/camel-core/src/main/java/org/apache/camel/main/Main.java b/core/camel-core/src/main/java/org/apache/camel/main/Main.java
index cbea1d2..ffa5e56 100644
--- a/core/camel-core/src/main/java/org/apache/camel/main/Main.java
+++ b/core/camel-core/src/main/java/org/apache/camel/main/Main.java
@@ -101,10 +101,16 @@ public class Main extends MainSupport {
// Implementation methods
// -------------------------------------------------------------------------
+
+ @Override
+ protected void doInit() throws Exception {
+ super.doInit();
+ initCamelContext();
+ }
+
@Override
protected void doStart() throws Exception {
super.doStart();
- initCamelContext();
if (getCamelContext() != null) {
try {
// if we were veto started then mark as completed
diff --git a/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java b/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
index a7e26ee..adeb94b 100644
--- a/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/main/MainIoCTest.java
@@ -26,6 +26,7 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.seda.BlockingQueueFactory;
import org.apache.camel.component.seda.PriorityBlockingQueueFactory;
import org.apache.camel.component.seda.SedaComponent;
+import org.apache.camel.model.ModelCamelContext;
import org.junit.Assert;
import org.junit.Test;
@@ -41,6 +42,20 @@ public class MainIoCTest extends Assert {
main.addRouteBuilder(MyRouteBuilder.class);
// manually bind
main.bind("myBar", new MyBar());
+
+ // should be null before init
+ assertNull(main.getCamelContext());
+ // for testing that we can init camel and it has loaded configuration and routes and whatnot
+ main.init();
+ // and now its created
+ assertNotNull(main.getCamelContext());
+ // should be 1 route model
+ assertEquals(1, main.getCamelContext().adapt(ModelCamelContext.class).getRouteDefinitions().size());
+ // and the configuration should have registered beans
+ assertNotNull(main.getCamelContext().getRegistry().lookupByName("MyCoolBean"));
+ assertEquals("Tiger", main.getCamelContext().getRegistry().lookupByName("coolStuff"));
+
+ // start it
main.start();
CamelContext camelContext = main.getCamelContext();