Gareth Western created CAMEL-8064:
-------------------------------------

             Summary: 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
            Priority: Minor


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.

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 e.g. 
MyRouteBuilder.EXIT_ENDPOINT).

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)

Reply via email to