
package org.apache.camel.component.file;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.camel.ContextTestSupport;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;

/**
 * Simple unit test to produce a new file
 */
public class NewFileProduceTest extends ContextTestSupport {

    @Override
    public boolean isUseRouteBuilder() {
        return false;
    }

    public void testNewFileProducer() throws Exception {
        deleteDirectory("target/producefile");

        FileComponent comp = new FileComponent();
        comp.setCamelContext(context);

        Endpoint endpoint = comp.createEndpoint("file://target/producefile", "target/producefile", new HashMap<String, Object>());
        template.send(endpoint, new Processor() {
            public void process(Exchange exchange) throws Exception {
                exchange.getIn().setHeader(Exchange.FILE_NAME, "bye.txt");
                exchange.getIn().setBody("Bye World");
            }
        });

        File file = new File("target/producefile/bye.txt");
        file = file.getAbsoluteFile();
        assertTrue("The file should have been created", file.exists());
    }

}
