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/06/06 10:59:23 UTC
[camel] 02/02: CAMEL-13491: Fixed CS. And some smaller improvements
between camel-test and camel-test-spring
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
commit c1c47a02c0cb0ac49ac65aed87fa3339b2b68ecc
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Jun 6 10:13:51 2019 +0200
CAMEL-13491: Fixed CS. And some smaller improvements between camel-test and camel-test-spring
---
.../camel/test/spring/CamelSpringTestSupport.java | 15 ++---------
.../apache/camel/test/patterns/SimpleMockTest.java | 29 +++++++++++++++++++---
.../camel/test/junit4/CamelTearDownRule.java | 11 +++++---
.../apache/camel/test/junit4/CamelTestSupport.java | 14 +++++------
4 files changed, 42 insertions(+), 27 deletions(-)
diff --git a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestSupport.java b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestSupport.java
index 0b2914f..4e8ff41 100644
--- a/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestSupport.java
+++ b/components/camel-test-spring/src/main/java/org/apache/camel/test/spring/CamelSpringTestSupport.java
@@ -21,7 +21,7 @@ import java.util.HashSet;
import java.util.List;
import org.apache.camel.CamelContext;
-import org.apache.camel.spring.CamelBeanPostProcessor;
+import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.spring.SpringCamelContext;
import org.apache.camel.test.ExcludingPackageScanClassResolver;
import org.apache.camel.test.junit4.CamelTestSupport;
@@ -44,23 +44,12 @@ public abstract class CamelSpringTestSupport extends CamelTestSupport {
protected AbstractApplicationContext applicationContext;
protected abstract AbstractApplicationContext createApplicationContext();
- /**
- * Lets post process this test instance to process any Camel annotations.
- * Note that using Spring Test or Guice is a more powerful approach.
- */
@Override
public void postProcessTest() throws Exception {
- super.postProcessTest();
if (isCreateCamelContextPerClass()) {
applicationContext = threadAppContext.get();
}
-
- // use the bean post processor from camel-spring
- CamelBeanPostProcessor processor = new CamelBeanPostProcessor();
- processor.setApplicationContext(applicationContext);
- processor.setCamelContext(context);
- processor.postProcessBeforeInitialization(this, getClass().getName());
- processor.postProcessAfterInitialization(this, getClass().getName());
+ super.postProcessTest();
}
@Override
diff --git a/components/camel-test-spring/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java b/components/camel-test-spring/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
index 27bf096..c257e68 100644
--- a/components/camel-test-spring/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
+++ b/components/camel-test-spring/src/test/java/org/apache/camel/test/patterns/SimpleMockTest.java
@@ -16,6 +16,10 @@
*/
package org.apache.camel.test.patterns;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Produce;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractApplicationContext;
@@ -23,6 +27,12 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SimpleMockTest extends CamelSpringTestSupport {
+ @EndpointInject("mock:result")
+ protected MockEndpoint resultEndpoint;
+
+ @Produce("direct:start")
+ protected ProducerTemplate template;
+
@Override
protected AbstractApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("org/apache/camel/test/patterns/SimpleMockTest.xml");
@@ -30,11 +40,24 @@ public class SimpleMockTest extends CamelSpringTestSupport {
@Test
public void testMock() throws Exception {
- getMockEndpoint("mock:result").expectedBodiesReceived("Hello World");
+ String expectedBody = "Hello World";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
+
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
+
+ resultEndpoint.assertIsSatisfied();
+ }
+
+ @Test
+ public void testMockAgain() throws Exception {
+ String expectedBody = "Bye World";
+
+ resultEndpoint.expectedBodiesReceived(expectedBody);
- template.sendBody("direct:start", "Hello World");
+ template.sendBodyAndHeader(expectedBody, "foo", "bar");
- assertMockEndpointsSatisfied();
+ resultEndpoint.assertIsSatisfied();
}
}
diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTearDownRule.java b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTearDownRule.java
index 23c89b8..2d2dd1f 100644
--- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTearDownRule.java
+++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTearDownRule.java
@@ -1,13 +1,13 @@
-/**
+/*
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
@@ -18,6 +18,9 @@ package org.apache.camel.test.junit4;
import org.junit.rules.ExternalResource;
+/**
+ * A JUnit rule to tear down Camel when using createCamelContextPerClass=true.
+ */
public class CamelTearDownRule extends ExternalResource {
private final ThreadLocal<CamelTestSupport> testSupport;
diff --git a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
index ce1ca20..1b5fb54 100644
--- a/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
+++ b/components/camel-test/src/main/java/org/apache/camel/test/junit4/CamelTestSupport.java
@@ -72,7 +72,6 @@ import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.component.properties.PropertiesComponent;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.JndiRegistry;
-import org.apache.camel.impl.engine.DefaultCamelBeanPostProcessor;
import org.apache.camel.impl.engine.InterceptSendToMockEndpointStrategy;
import org.apache.camel.model.Model;
import org.apache.camel.model.ModelCamelContext;
@@ -80,6 +79,7 @@ import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.processor.interceptor.BreakpointSupport;
import org.apache.camel.processor.interceptor.DefaultDebugger;
import org.apache.camel.reifier.RouteReifier;
+import org.apache.camel.spi.CamelBeanPostProcessor;
import org.apache.camel.spi.Language;
import org.apache.camel.spi.Registry;
import org.apache.camel.support.EndpointHelper;
@@ -105,6 +105,7 @@ public abstract class CamelTestSupport extends TestSupport {
*/
public static final String ROUTE_COVERAGE_ENABLED = "CamelTestRouteCoverage";
+ // CHECKSTYLE:OFF
private static final Logger LOG = LoggerFactory.getLogger(CamelTestSupport.class);
private static ThreadLocal<ModelCamelContext> threadCamelContext = new ThreadLocal<>();
private static ThreadLocal<ProducerTemplate> threadTemplate = new ThreadLocal<>();
@@ -116,7 +117,6 @@ public abstract class CamelTestSupport extends TestSupport {
protected volatile FluentProducerTemplate fluentTemplate;
protected volatile ConsumerTemplate consumer;
protected volatile Service camelContextService;
- protected boolean dumpRouteStats;
private boolean useRouteBuilder = true;
private final DebugBreakpoint breakpoint = new DebugBreakpoint();
private final StopWatch watch = new StopWatch();
@@ -126,6 +126,7 @@ public abstract class CamelTestSupport extends TestSupport {
private CamelTestWatcher camelTestWatcher = new CamelTestWatcher();
@ClassRule
public static final CamelTearDownRule CAMEL_TEAR_DOWN_RULE = new CamelTearDownRule(INSTANCE);
+ // CHECKSTYLE:ON
/**
* Use the RouteBuilder or not
@@ -732,18 +733,17 @@ public abstract class CamelTestSupport extends TestSupport {
}
/**
- * Applies the {@link DefaultCamelBeanPostProcessor} to this instance.
+ * Applies the {@link CamelBeanPostProcessor} to this instance.
*
* Derived classes using IoC / DI frameworks may wish to turn this into a NoOp such as for CDI
* we would just use CDI to inject this
*/
protected void applyCamelPostProcessor() throws Exception {
- // use the default bean post processor from camel-core if the test class is not dependency injected already by Spring
+ // use the bean post processor if the test class is not dependency injected already by Spring Framework
boolean spring = hasClassAnnotation("org.springframework.boot.test.context.SpringBootTest", "org.springframework.context.annotation.ComponentScan");
if (!spring) {
- DefaultCamelBeanPostProcessor processor = new DefaultCamelBeanPostProcessor(context);
- processor.postProcessBeforeInitialization(this, getClass().getName());
- processor.postProcessAfterInitialization(this, getClass().getName());
+ context.getExtension(ExtendedCamelContext.class).getBeanPostProcessor().postProcessBeforeInitialization(this, getClass().getName());
+ context.getExtension(ExtendedCamelContext.class).getBeanPostProcessor().postProcessAfterInitialization(this, getClass().getName());
}
}