camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jean-Yves BESSON (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (CAMEL-10241) MockEndpointAndSkip and DirtiesContext not working
Date Wed, 17 Aug 2016 13:40:20 GMT

    [ https://issues.apache.org/jira/browse/CAMEL-10241?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15424530#comment-15424530
] 

Jean-Yves BESSON commented on CAMEL-10241:
------------------------------------------

Hi,

I run your tests on my side and got the same results. I found a possible answer : the loader
CamelSpringDelegatingTestContextLoader.class which is responsible of annotation post-processing
when spring context is loaded is in conflict with another loader defined in @SpringApplicationConfiguration.

If you remove @SpringApplicationConfiguration and @EnableAutoConfiguration every works nicely
with @DirtiesContext and @MockEndpoints. Here is my code, based on camel-spring-javaconfig
:

@RunWith(CamelSpringBootJUnit4ClassRunner.class)
@MockEndpointsAndSkip("direct:b")
@ContextConfiguration(classes = {MockTest.Config.class}, loader = CamelSpringDelegatingTestContextLoader.class)
@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
public class MockTest {

    @Produce(uri = "direct:a")
    private ProducerTemplate producer;

    @EndpointInject(uri = "mock:end")
    private MockEndpoint end;

    @EndpointInject(uri = "mock:direct:b")
    private MockEndpoint directB;

    @Autowired
    private CamelContext context;

    @Configuration
    public static class Config extends SingleRouteCamelConfiguration {

        @Override
        public RouteBuilder route() {

            return new RouteBuilder() {

                @Override
                public void configure() throws Exception {
                    this.from("direct:a").to("direct:b").routeId("route1");
                    this.from("direct:b").to("mock:end").routeId("route2");
                }

            };

        };

    }

    @Test
    public void testMock() throws InterruptedException {

        this.end.expectedMessageCount(0);
        this.directB.expectedBodiesReceived("hello");

        this.producer.sendBody("hello");

        MockEndpoint.assertIsSatisfied(this.context);
    }

    @Test
    public void testMock2() throws InterruptedException {

        this.end.expectedMessageCount(0);
        this.directB.expectedBodiesReceived("hello");

        this.producer.sendBody("hello");

        MockEndpoint.assertIsSatisfied(this.context);
    }
}

> MockEndpointAndSkip and DirtiesContext not working
> --------------------------------------------------
>
>                 Key: CAMEL-10241
>                 URL: https://issues.apache.org/jira/browse/CAMEL-10241
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-test
>    Affects Versions: 2.17.3
>         Environment: java8
> spring boot 1.3.6
>            Reporter: Minh Tran
>            Priority: Minor
>
> MockEndpointAndSkip does not seem to get re-applied after each test when used in conjunction
with DirtiesContext. Here is a unit test exhibiting the problem
> {noformat}
> @RunWith(CamelSpringBootJUnit4ClassRunner.class)
> @SpringApplicationConfiguration
> @MockEndpointsAndSkip("direct:b")
> @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
> public class MockTest {
> 	@Produce(uri = "direct:a")
> 	private ProducerTemplate producer;
> 	@EndpointInject(uri = "mock:end")
> 	private MockEndpoint end;
> 	@EndpointInject(uri = "mock:direct:b")
> 	private MockEndpoint directB;
> 	@Autowired
> 	private CamelContext context;
> 	@Configuration
> 	@EnableAutoConfiguration
> 	public static class Config extends SpringRouteBuilder {
> 		@Override
> 		public void configure() throws Exception {
> 			from("direct:a").to("direct:b");
> 			from("direct:b").to("mock:end");
> 		}
> 	}
> 	@Test
> 	public void testMock() throws InterruptedException {
> 		end.expectedMessageCount(0);
> 		directB.expectedBodiesReceived("hello");
> 		producer.sendBody("hello");
> 		MockEndpoint.assertIsSatisfied(context);
> 	}
> 	@Test
> 	public void testMock2() throws InterruptedException {
> 		end.expectedMessageCount(0);
> 		directB.expectedBodiesReceived("hello");
> 		producer.sendBody("hello");
> 		MockEndpoint.assertIsSatisfied(context);
> 	}
> }
> {noformat}
> testMock and testMock2 are exactly the same and if run individually, they pass. However
if you run both, the second one will always fail. Running them both inside eclipse and from
maven command line exhibit the same behaviour. 
> The error I get is
> {noformat}
> java.lang.AssertionError: mock://end Received message count. Expected: <0> but
was: <1>
> {noformat}
> Which must mean that the skipping isn’t working. Here’s the tracer output to confirm
> {noformat}
> org.apache.camel.processor.interceptor.Tracer - ID-minhmac-local-51406-1470352938165-1-2
>>> (route3) from(direct://a) --> direct://b <<< Pattern:InOnly, Headers:{breadcrumbId=ID-minhmac-local-51406-1470352938165-1-1},
BodyType:String, Body:hello
> org.apache.camel.processor.interceptor.Tracer - ID-minhmac-local-51406-1470352938165-1-2
>>> (route4) direct://b --> mock://end <<< Pattern:InOnly, Headers:{breadcrumbId=ID-minhmac-local-51406-1470352938165-1-1},
BodyType:String, Body:hello
> {noformat}
> If you remove the DirtiesContext, then both tests passes. My suspicion is that there
is a bug when re-applying the MockEndpointAndSkip when the spring context is being rebuilt
between tests.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message