You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Gareth Western (JIRA)" <ji...@apache.org> on 2014/11/24 09:55:12 UTC

[jira] [Commented] (CAMEL-8064) MockEndpointsAndSkip annotation does not resolve property placeholders

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

Gareth Western commented on CAMEL-8064:
---------------------------------------

Looks like a straightforward change (reviewed in Fisheye). Thanks for the rapid fix!

> MockEndpointsAndSkip annotation does not resolve property placeholders
> ----------------------------------------------------------------------
>
>                 Key: CAMEL-8064
>                 URL: https://issues.apache.org/jira/browse/CAMEL-8064
>             Project: Camel
>          Issue Type: Improvement
>    Affects Versions: 2.13.2
>            Reporter: Gareth Western
>            Assignee: Willem Jiang
>            Priority: Minor
>             Fix For: 2.14.1, 2.15.0, 2.13.4
>
>
> We are using property placeholders in our route configuration in order to switch components in our unit tests. For example:
> {code}
>         from(MyRouteBuilder.ENTRY_ENDPOINT)
>             .routeId("some.route")
>             .process(doSomething())
>             .to(MyRouteBuilder.EXIT_ENDPOINT);
> {code}
> Where ENTRY_ENDPOINT = "{{entry.endpoint.uri}}"
> and EXIT_ENDPOINT = "{{exit.endpoint.uri}}"
> Then, in production, the Camel context is initialized with a properties file where the URIs use the "jms" component, while in our unit tests we initialise the context with a 'test' properties file where the URIs use the "direct" component. For example:
> {code}
> # test.properties
> entry.endpoint.uri = direct:myRouteBuilder.entry
> exit.endpoint.uri = direct:myRouteBuilder.exit
> {code}
> A typical RouteBuilder unit test looks something like this:
> {code}
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @ContextConfiguration(
>         classes = { MyRouteBuilderTest.TestConfig.class },
>         loader = CamelSpringDelegatingTestContextLoader.class
> )
> @MockEndpointsAndSkip(value =  "direct:myRouteBuilder.exit")
> public class MyRouteBuilderTest {
>     @Produce(uri = MyRouteBuilder.ENTRY_ENDPOINT)
>     private ProducerTemplate myRouteBuilderProducer;
>     @EndpointInject(uri = "mock:" + MyRouteBuilder.EXIT_ENDPOINT)
>     private MockEndpoint mockOutputServiceEndpoint;
>     @Autowired
>     private CamelContext camelContext;
>     @Test
>     public void testSomething() {
>         ....
>     }
>     @Configuration
>     public static class TestConfig extends SingleRouteCamelConfiguration {
>         @Override
>         protected void setupCamelContext(CamelContext camelContext) throws Exception {
>             super.setupCamelContext(camelContext);
>             PropertiesComponent prop = camelContext.getComponent("properties", PropertiesComponent.class);
>             prop.setLocation("myRouteBuilder.test.properties");
>         }
>         @Override
>         public RouteBuilder route() {
>             return new MyRouteBuilder();
>         }
>     }
> {code}
> The issue we're having is that the @MockEndpointsAndSkip annotation on the test class does not resolve property placeholders, therefore we have to write the resolved value instead of the property placeholder value (which is a public static variable in the RouteBuilder implementation) I.e. we want to use MyRouteBuilder.EXIT_ENDPOINT instead of "direct:myRouteBuilder.exit".
> It would be nicer to avoid having duplicate extra hard-coded Strings if possible, so that if the endpoint uri value is updated in the property file then all the tests don't also have to be updated.



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