use of org.apache.camel.component.exec.ExecResult in project camel by apache.
the class ExecDocumentationExamplesTest method testExecWinAnt.
/**
* The test assumes that Apache ant is installed
*/
@Test
@Ignore
public void testExecWinAnt() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT);
assertTrue("You must create a sample build file!", f.exists());
ExecResult body = templateExecAnt.requestBody((Object) "test", ExecResult.class);
String stdout = IOUtils.toString(body.getStdout());
assertNull(body.getStderr());
assertTrue("The ant script should print" + TEST_MSG, stdout.contains(TEST_MSG));
f.delete();
}
use of org.apache.camel.component.exec.ExecResult in project camel by apache.
the class ExecDocumentationExamplesTest method testWinJavaVersionWorkingDir.
@Test
@Ignore
public void testWinJavaVersionWorkingDir() throws Exception {
ExecResult body = templateJavaVersionWorkingDir.requestBody((Object) "test", ExecResult.class);
InputStream out = body.getStdout();
InputStream err = body.getStderr();
// Strange that Sun Java 1.5 writes the -version in the syserr
assertNull(out);
assertNotNull(err);
String outerr = IOUtils.toString(err);
log.info("Received stderr: " + outerr);
assertTrue(outerr.contains("java version"));
}
use of org.apache.camel.component.exec.ExecResult in project camel by apache.
the class ExecDocumentationExamplesTest method testJavaVersion.
/**
* The test assumes, that java is in the system path
*/
@Test
@Ignore
public void testJavaVersion() throws Exception {
ExecResult body = templateJavaVersion.requestBody((Object) "test", ExecResult.class);
InputStream out = body.getStdout();
InputStream err = body.getStderr();
// Strange that Sun Java 1.5 writes the -version in the syserr
assertNull(out);
assertNotNull(err);
String outString = IOUtils.toString(err);
log.info("Received stdout: " + outString);
assertTrue(outString.contains("java version"));
}
use of org.apache.camel.component.exec.ExecResult in project camel by apache.
the class ExecDocumentationExamplesTest method testExecLinuxWordCount.
@Test
@Ignore
public void testExecLinuxWordCount() throws Exception {
// use type conversion here
ExecResult body = templateWordCount.requestBody((Object) "test", ExecResult.class);
assertNotNull(body);
}
use of org.apache.camel.component.exec.ExecResult in project camel by apache.
the class ExecDocumentationExamplesTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
// word count
from("direct:wordCount").to("exec:wc?args=--words /usr/share/dict/words").process(new Processor() {
public void process(Exchange exchange) throws Exception {
// By default, the body is ExecResult instance
assertIsInstanceOf(ExecResult.class, exchange.getIn().getBody());
// Use the Camel Exec String type converter to
// convert the ExecResult to String
// In this case, the stdout is considered as output
String wordCountOutput = exchange.getIn().getBody(String.class);
// do something with the output
log.info(wordCountOutput);
}
});
// example 1 in the component docs
from("direct:javaVersion").to("exec:java?args=-version -server");
// example 2 in the component docs
from("direct:javaVersionWorkingDir").to("exec:" + buildJavaExecutablePath() + "?args=-version -Duser.name=Camel&workingDir=C:/temp");
// advanced, test ant
from("direct:execAnt").to("exec:ant.bat?args=-f " + ANT_BUILD_FILE_NAME);
// advanced, test ant with out file
from("direct:execAntWithOutFile").to("exec:ant.bat?args=-f " + ANT_BUILD_FILE_NAME + " -l " + ANT_OUT_FILE_NAME + "&outFile=" + ANT_OUT_FILE_NAME).process(new Processor() {
public void process(Exchange exchange) throws Exception {
InputStream outFile = exchange.getIn().getBody(InputStream.class);
// do something with the out file here
log.info(IOUtils.toString(outFile));
}
});
}
};
}
Aggregations