use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.
the class StartJobServletIT method testStartJobServletEscapesHtmlWhenTransFound.
@Test
public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
Job mockJob = mock(Job.class);
JobMeta mockJobMeta = mock(JobMeta.class);
LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
mockJob.setName(ServletTestUtils.BAD_STRING);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
when(mockHttpServletRequest.getContextPath()).thenReturn(StartJobServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING);
when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
startJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
use of org.pentaho.di.job.Job 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.job.Job 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.job.Job in project pentaho-kettle by pentaho.
the class JobEntryTransIntIT method testPDI14676.
/*
* Tests whether the job can force a transformation to stop, when the job is asked to stop.
* A timeout parameter is required, to avoid a failed unit test from running forever.
*/
@Test(timeout = 30000)
public void testPDI14676() throws KettleException, IOException, InterruptedException {
String transFilename = createPDI14676Transformation();
// Setup Job
JobEntrySpecial startEntry = new JobEntrySpecial("Start", true, false);
JobEntryCopy startCopy = new JobEntryCopy(startEntry);
startCopy.setLocation(50, 50);
startCopy.setDrawn();
JobEntryTrans transEntry = new JobEntryTrans("PDI-13676 example");
transEntry.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
transEntry.setFileName(transFilename);
JobEntryCopy transCopy = new JobEntryCopy(transEntry);
transCopy.setLocation(200, 50);
transCopy.setDrawn();
JobMeta jobMeta = new JobMeta();
jobMeta.addJobEntry(startCopy);
jobMeta.addJobEntry(transCopy);
jobMeta.addJobHop(new JobHopMeta(startCopy, transCopy));
// Run job
Job jobInstance = new Job(null, jobMeta);
jobInstance.start();
// Allow job startup time
while (!jobInstance.isActive()) {
if (jobInstance.isStopped() || jobInstance.isFinished()) {
break;
}
Thread.sleep(10);
}
// Let the job run for a short period
Thread.sleep(300);
assertFalse(jobInstance.isStopped());
assertFalse(jobInstance.isFinished());
// Tell the job to stop.
jobInstance.stopAll();
assertTrue(jobInstance.isStopped());
// Allow the job's thread to stop and be cleaned up
while (!jobInstance.isFinished() || jobInstance.isActive()) {
Thread.sleep(10);
}
// Ensure that the job and the thread have both stopped
assertTrue(jobInstance.isFinished());
assertFalse(jobInstance.isAlive());
}
use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.
the class StartJobServletTest method testStartJobServletEscapesHtmlWhenTransFound.
@Test
@PrepareForTest({ Encode.class })
public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
KettleLogStore.init();
HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
Job mockJob = mock(Job.class);
JobMeta mockJobMeta = mock(JobMeta.class);
LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
mockJob.setName(ServletTestUtils.BAD_STRING_TO_TEST);
StringWriter out = new StringWriter();
PrintWriter printWriter = new PrintWriter(out);
PowerMockito.spy(Encode.class);
when(mockHttpServletRequest.getContextPath()).thenReturn(StartJobServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
startJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
Aggregations