use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class CopyFilesIT method testLocalFileCopy.
/**
* Tests copying a folder contents. The folders used are created in the Java's temp location using unique folder and
* file names.
*
* @throws Exception
*/
@Test
public void testLocalFileCopy() throws Exception {
String sourceFolder = TestUtilities.createTempFolder("testLocalFileCopy_source");
String destinationFolder = TestUtilities.createTempFolder("testLocalFileCopy_destination");
if (Utils.isEmpty(sourceFolder) || Utils.isEmpty(destinationFolder)) {
fail("Could not create the source and/or destination folder(s).");
}
// create a text file named testLocalFileCopy with a delimiter of ;
TestUtilities.writeTextFile(sourceFolder, "testLocalFileCopy", ";");
// the parent job
Job parentJob = new Job();
// Set up the job entry to do wildcard copy
JobEntryCopyFiles jobEntry = new JobEntryCopyFiles("Job entry copy files");
jobEntry.source_filefolder = new String[] { sourceFolder };
jobEntry.destination_filefolder = new String[] { destinationFolder };
jobEntry.wildcard = new String[] { "" };
jobEntry.setParentJob(parentJob);
// Check the result for errors.
Result result = jobEntry.execute(createStartJobEntryResult(), 1);
if (result.getNrErrors() != 0) {
fail(result.getLogText());
}
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryFTPPUTIT method reportsError_WhenLocalDirectoryIsNotSet.
@Test
public void reportsError_WhenLocalDirectoryIsNotSet() throws Exception {
entry.setLocalDirectory(null);
Result result = executeStep(entry);
assertEquals(1, result.getNrErrors());
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntrySFTPIT method getFile_WhenDestinationIsSetViaVariable.
@Test
public void getFile_WhenDestinationIsSetViaVariable() throws Exception {
final String localDir = TestUtils.createTempDir();
KettleVFS.getFileObject(localDir).createFolder();
final String myVar = "my-var";
final String sftpDir = "job-entry-sftp-test";
final String fileName = "file.txt";
uploadFile(sftpDir, fileName);
JobEntrySFTP job = new JobEntrySFTP();
job.setVariable(myVar, localDir);
Job parent = mock(Job.class);
when(parent.isStopped()).thenReturn(false);
job.setParentJob(parent);
job.setLogLevel(LogLevel.NOTHING);
job.setUserName(server.getUsername());
job.setPassword(server.getPassword());
job.setServerName("localhost");
job.setServerPort(Integer.toString(server.getPort()));
job.setScpDirectory(sftpDir);
job.setTargetDirectory(String.format("${%s}", myVar));
job.execute(new Result(), 1);
FileObject downloaded = KettleVFS.getFileObject(localDir + "/" + fileName);
assertTrue(downloaded.exists());
downloaded.delete();
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class JobEntryDummy method execute.
@Override
public Result execute(Result prev_result, int nr) {
Result result = new Result(nr);
result.setResult(false);
long filesRetrieved = 0;
logDetailed(toString(), "Start of processing");
// String substitution..
String realWildcard = environmentSubstitute(wildcard);
String realTargetDirectory = environmentSubstitute(targetDirectory);
String realSourceDirectory = environmentSubstitute(sourceDirectory);
DummyJob proc = new DummyJob(realSourceDirectory, realTargetDirectory, realWildcard);
try {
filesRetrieved = proc.process();
result.setResult(true);
result.setNrFilesRetrieved(filesRetrieved);
} catch (Exception e) {
result.setNrErrors(1);
e.printStackTrace();
logError(toString(), "Error processing DummyJob : " + e.getMessage());
}
return result;
}
use of org.pentaho.di.core.Result in project pentaho-kettle by pentaho.
the class BlackBoxIT method runTrans.
public Result runTrans(String fileName, LogChannelInterface log) throws KettleException {
// Bootstrap the Kettle API...
//
KettleEnvironment.init();
TransMeta transMeta = new TransMeta(fileName);
Trans trans = new Trans(transMeta);
Result result;
try {
trans.setLogLevel(LogLevel.ERROR);
result = trans.getResult();
} catch (Exception e) {
result = trans.getResult();
String message = "Processing has stopped because of an error: " + getPath(fileName);
addFailure(message);
log.logError(message, e);
fail(message);
return result;
}
try {
trans.initializeVariablesFrom(null);
trans.getTransMeta().setInternalKettleVariables(trans);
trans.setSafeModeEnabled(true);
// see if the transformation checks ok
List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
trans.getTransMeta().checkSteps(remarks, false, null, new Variables(), null, null);
for (CheckResultInterface remark : remarks) {
if (remark.getType() == CheckResultInterface.TYPE_RESULT_ERROR) {
// add this to the log
addFailure("Check error: " + getPath(fileName) + ", " + remark.getErrorCode());
log.logError("BlackBoxTest", "Check error: " + getPath(fileName) + ", " + remark.getErrorCode());
}
}
// allocate & run the required sub-threads
try {
trans.execute(null);
} catch (Exception e) {
addFailure("Unable to prepare and initialize this transformation: " + getPath(fileName));
log.logError("BlackBoxTest", "Unable to prepare and initialize this transformation: " + getPath(fileName));
fail("Unable to prepare and initialize this transformation: " + getPath(fileName));
return null;
}
trans.waitUntilFinished();
result = trans.getResult();
// The result flag is not set to true by a transformation - set it to true if got no errors
// FIXME: Find out if there is a better way to check if a transformation has thrown an error
result.setResult(result.getNrErrors() == 0);
return result;
} catch (Exception e) {
addFailure("Unexpected error occurred: " + getPath(fileName));
log.logError("BlackBoxTest", "Unexpected error occurred: " + getPath(fileName), e);
result.setResult(false);
result.setNrErrors(1);
fail("Unexpected error occurred: " + getPath(fileName));
return result;
}
}
Aggregations