我编写了一个简单的apache camel项目,最终将部署在FUSE容器中。现在,我只是想让基本的单元测试工作。我使用示例here作为起点。
我编写了单元测试,但是当我包含蓝图文件时,我在测试输出中得到以下条目:
Bundle TestMainRoute is waiting for namespace handlers [http://camel.apache.org/schema/blueprint]
测试失败并显示以下堆栈跟踪:
java.lang.RuntimeException: Gave up waiting for service (objectClass=org.apache.camel.CamelContext)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:240)
at org.apache.camel.test.blueprint.CamelBlueprintHelper.getOsgiService(CamelBlueprintHelper.java:202)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.createCamelContext(CamelBlueprintTestSupport.java:352)
at org.apache.camel.test.junit4.CamelTestSupport.doSetUp(CamelTestSupport.java:247)
at org.apache.camel.test.junit4.CamelTestSupport.setUp(CamelTestSupport.java:217)
at org.apache.camel.test.blueprint.CamelBlueprintTestSupport.setUp(CamelBlueprintTestSupport.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
我的xml非常简单:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<routeContext id="validationRoute" xmlns="http://camel.apache.org/schema/blueprint" >
<route id="validation">
<from uri="direct:validation" />
<log message="validating..." />
</route>
</routeContext>
代码如下:
public class RouteTest extends CamelBlueprintTestSupport {
@Test
public void testValidationRoute() throws Exception {
DefaultExchange r1 = new DefaultExchange(context);
r1.getIn().setBody("");
Exchange response1 = template.send("direct:validation", r1);
}
protected String getBlueprintDescriptor() {
return "OSGI-INF/blueprint/blueprint.xml";
} }
注意验证路线由我的主要驼峰上下文引用:
public class IntegrationFramework extends RouteBuilder {
public void configure() {
from("netty-http:http://localhost:8457/broker/router.jsp").convertBodyTo(String.class)
.log("http router "+simple("${body}").getText())
.to("direct:validation");
}
我有其他单元测试和日志记录,表明这部分正在运行。
答案 0 :(得分:0)
我有相同的错误,但是@mdarwin之后又有另一个设置,所以我也想与您分享我的解决方案。
我以camel-archetype-blueprint开始了一个项目,所以我的命名空间如下:
blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd
http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/schemas/blueprint-cm/blueprint-cm-1.1.0.xsd">
一开始它是一个非常简单的带有计时器和文件端点的蓝图,因此此处的实现并不重要。我将捆绑软件部署到Karaf,并为此安装了 aries-blueprint 功能。
我想念的也感到很ham愧的是也安装了camel。为此,我必须添加存储库并安装它,因为您可以阅读here:
feature:repo-add camel
feature:install camel
现在有名称空间处理程序了。
我认为这很明显,但是仍然需要花费几分钟才能弄清楚。
答案 1 :(得分:-1)
事实证明,routeContext仅存在于xml dsl的上下文中,并且无法从Java DSL引用。我认为这是一个错误,因为它限制了混合xml和java配置的灵活性。
通过将routeContext更改为camelContext,可以解决问题。
另请参阅此问题:Camel: importing routeContext into an external camelContext