/*
 * 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
 *
 *      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.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.bam;

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.SpringTestSupport;
import static org.apache.camel.util.Time.seconds;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.orm.jpa.JpaTemplate;
import org.springframework.transaction.support.TransactionTemplate;

/**
 * @version $Revision: $
 */
public class BamRouteTest extends SpringTestSupport {
    protected Object body = "<hello>world!</hello>";
    protected JpaTemplate jpaTemplate;
    protected MockEndpoint overdueEndpoint;
    protected TransactionTemplate transactionTemplate;

    public void testRoute() throws Exception {
        overdueEndpoint.expectedMessageCount(1);

        template.sendBody("direct:a", body, "foo", "a");

        overdueEndpoint.assertIsSatisfied(5000);
    }

    protected ClassPathXmlApplicationContext createApplicationContext() {
        return new ClassPathXmlApplicationContext("org/apache/camel/bam/spring.xml");
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        camelContext.addRoutes(createRouteBuilder());

        overdueEndpoint = (MockEndpoint) resolveMandatoryEndpoint("mock:overdue");
    }

    protected RouteBuilder createRouteBuilder() throws Exception {
        jpaTemplate = getMandatoryBean(JpaTemplate.class, "jpaTemplate");
        transactionTemplate = getMandatoryBean(TransactionTemplate.class, "transactionTemplate");

        // START SNIPPET: example
        return new ProcessBuilder(jpaTemplate, transactionTemplate) {
            public void configure() throws Exception {

                // lets define some activities
                ActivityBuilder a = activity("direct:a").name("a")
                        .correlate(header("foo"));

                ActivityBuilder b = activity("direct:b").name("b")
                        .correlate(header("foo"));

                // now lets add some rules
                b.starts().after(a.completes())
                        .expectWithin(seconds(1))
                        .errorIfOver(seconds(2)).to("mock:overdue");
            }
        };
        // END SNIPPET: example
    }

    @Override
    protected int getExpectedRouteCount() {
        return 0;
    }
}

@@ -838,38 +838,151 @@
 ort 
-org.apache.camel.builder.Route
+static org.apache.camel.builder.xml.XPathBuilder.xpath;%0Aimport org.apache.camel.builder.RouteBuilder;%0Aimport org.apache.camel.builder.xml.XPath
 Buil
@@ -1139,16 +1139,72 @@
 econds;%0A
+import org.apache.camel.model.language.XPathExpression;%0A
 import o
@@ -1478,246 +1478,200 @@
 t %7B%0A
+%0A
     p
-rotected Object body = %22%3Chello%3Eworld!%3C/hello%3E%22;%0A    protected JpaTemplate jpaTemplate;%0A    protected MockEndpoint overdueEndpoint;%0A    protected TransactionTemplate transactionTemplate;%0A%0A    public void testRoute() throws Exception %7B
+ublic void testSendingToFirstActivityOnlyResultsInOverdueMessage() throws Exception %7B%0A        MockEndpoint overdueEndpoint = resolveMandatoryEndpoint(%22mock:overdue%22, MockEndpoint.class);
 %0A   
@@ -1759,23 +1759,39 @@
 a%22, 
-body, %22foo%22, %22a
+%22%3Chello id='123'%3Eworld!%3C/hello%3E
 %22);%0A
@@ -2097,17 +2097,16 @@
 etUp();%0A
-%0A
         
@@ -2154,92 +2154,8 @@
 ());
-%0A%0A        overdueEndpoint = (MockEndpoint) resolveMandatoryEndpoint(%22mock:overdue%22);
 %0A   
@@ -2233,16 +2233,28 @@
         
+JpaTemplate 
 jpaTempl
@@ -2319,16 +2319,36 @@
         
+TransactionTemplate 
 transact
@@ -2735,35 +2735,41 @@
  .correlate(
-header(%22foo
+xpath(%22/hello/@id
 %22));%0A%0A      
@@ -2868,19 +2868,25 @@
 ate(
-header(%22foo
+xpath(%22/hello/@id
 %22));

simplified the test case so its easier to read