/**
 * 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.component.jms;

import java.io.File;

import javax.jms.ConnectionFactory;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.camel.CamelContext;
import org.apache.camel.ContextTestSupport;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.converter.IOConverter;

import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;

/**
 * Unit test that we can consume JMS message and store it as file (to avoid regression bug)
 */
public class JmsRouteToFileTest extends ContextTestSupport {

    protected String componentName = "activemq";

    public void testRouteToFile() throws Exception {
        deleteDirectory("target/routetofile");

        template.sendBody("activemq:queue:hello", "Hello World");

        // pause to let file producer save the file
        Thread.sleep(1500);

        // do file assertions
        File dir = new File("./target/routetofile");
        assertTrue("Should be directory", dir.isDirectory());
        File file = dir.listFiles()[0];
        assertTrue("File should exists", file.exists());
        String body = IOConverter.toString(file);
        assertEquals("Hello World", body);
    }

    protected CamelContext createCamelContext() throws Exception {
        CamelContext camelContext = super.createCamelContext();

        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
        camelContext.addComponent(componentName, jmsComponentClientAcknowledge(connectionFactory));

        return camelContext;
    }

    protected RouteBuilder createRouteBuilder() throws Exception {
        return new RouteBuilder() {
            public void configure() throws Exception {
                from("activemq:queue:hello").to("file://target/routetofile");
            }
        };
    }
}

@@ -1079,16 +1079,69 @@
 uilder;%0A
+import org.apache.camel.component.mock.MockEndpoint;%0A
 import o
@@ -1179,16 +1179,16 @@
 verter;%0A
-
 %0Aimport 
@@ -1527,32 +1527,143 @@
 ows Exception %7B%0A
+        MockEndpoint result = getMockEndpoint(%22mock:result%22);%0A        result.expectedMessageCount(1);%0A        %0A
         deleteDi
@@ -1825,28 +1825,44 @@
     
-Thread.sleep(1500);%0A
+result.assertIsSatisfied();%0A        
 %0A   
@@ -2766,66 +2766,268 @@
     
-from(%22activemq:queue:hello%22).to(%22file://target/routetofile
+// using mock endpoint here purely for testing. You would normally write this route as%0A                // from(%22activemq:queue:hello%22).to(%22file://target/routetofile%22);%0A                from(%22activemq:queue:hello%22).to(%22file://target/routetofile%22).to(%22mock:result
 %22);%0A

Remove the Thread.sleep that was causing this test to fail on slower machines.