@VisibleForTesting Job createJob( Repository repository, JobMeta jobMeta, LoggingObjectInterface parentLogging ) { return new Job( repository, jobMeta, parentLogging ); }
private Job createJob() { Job job = new Job( ); job = spy( job ); return job; } }
/** * This test demonstrates the issue fixed in PDI-17398. * When a job is scheduled twice, it gets the same log channel Id and both logs get merged */ @Test public void testTwoJobsGetSameLogChannelId() { Repository repository = mock( Repository.class ); JobMeta meta = mock( JobMeta.class ); Job job1 = new Job( repository, meta ); Job job2 = new Job( repository, meta ); assertEquals( job1.getLogChannelId(), job2.getLogChannelId() ); }
@Test public void testNewJobWithContainerObjectId() { Repository repository = mock( Repository.class ); JobMeta meta = mock( JobMeta.class ); String carteId = UUID.randomUUID().toString(); doReturn( carteId ).when( meta ).getContainerObjectId(); Job job = new Job( repository, meta ); assertEquals( carteId, job.getContainerObjectId() ); }
@Before public void setUp() { entry = new JobEntryCopyFiles(); Job parentJob = new Job(); entry.setParentJob( parentJob ); JobMeta mockJobMeta = mock( JobMeta.class ); mockNamedClusterEmbedManager = mock( NamedClusterEmbedManager.class ); when( mockJobMeta.getNamedClusterEmbedManager() ).thenReturn( mockNamedClusterEmbedManager ); entry.setParentJobMeta( mockJobMeta ); entry = spy( entry ); }
/** * This test demonstrates the fix for PDI-17398. * Two schedules -> two Carte object Ids -> two log channel Ids */ @Test public void testTwoJobsGetDifferentLogChannelIdWithDifferentCarteId() { Repository repository = mock( Repository.class ); JobMeta meta1 = mock( JobMeta.class ); JobMeta meta2 = mock( JobMeta.class ); String carteId1 = UUID.randomUUID().toString(); String carteId2 = UUID.randomUUID().toString(); doReturn( carteId1 ).when( meta1 ).getContainerObjectId(); doReturn( carteId2 ).when( meta2 ).getContainerObjectId(); Job job1 = new Job( repository, meta1 ); Job job2 = new Job( repository, meta2 ); assertNotEquals( job1.getContainerObjectId(), job2.getContainerObjectId() ); assertNotEquals( job1.getLogChannelId(), job2.getLogChannelId() ); }
public Job executeFilesystemBasedCommand( final String initialDir, final String filename ) throws Exception { if ( Utils.isEmpty( filename ) ) { return null; } blockAndThrow( getKettleInit() ); String fileName = filename; // If the filename starts with scheme like zip:, then isAbsolute() will return false even though // the path following the zip is absolute path. Check for isAbsolute only if the fileName does not start with scheme if ( !KettleVFS.startsWithScheme( fileName ) && !FileUtil.isFullyQualified( fileName ) ) { fileName = initialDir + fileName; } JobMeta jobMeta = new JobMeta( fileName, null, null ); return new Job( null, jobMeta ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntryFolderIsEmpty(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); JobMeta mockJobMeta = mock( JobMeta.class ); entry.setParentJobMeta( mockJobMeta ); job.setStopped( false ); File dir = Files.createTempDirectory( "dir", new FileAttribute<?>[0] ).toFile(); dir.deleteOnExit(); emptyDir = dir.getPath(); dir = Files.createTempDirectory( "dir", new FileAttribute<?>[0] ).toFile(); dir.deleteOnExit(); nonEmptyDir = dir.getPath(); File file = File.createTempFile( "existingFile", "ext", dir ); file.deleteOnExit(); }
Job job = new Job( rep, meta ); job.setInternalKettleVariables( null );
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntryFilesExist(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); JobMeta mockJobMeta = mock( JobMeta.class ); entry.setParentJobMeta( mockJobMeta ); job.setStopped( false ); existingFile1 = TestUtils.createRamFile( getClass().getSimpleName() + "/existingFile1.ext", entry ); existingFile2 = TestUtils.createRamFile( getClass().getSimpleName() + "/existingFile2.ext", entry ); }
@Test public void testHTTPResultDefaultRows() throws IOException { File localFileForUpload = getInputFile( "existingFile1", ".tmp" ); File tempFileForDownload = File.createTempFile( "downloadedFile1", ".tmp" ); localFileForUpload.deleteOnExit(); tempFileForDownload.deleteOnExit(); Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile", localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() }; RowMeta rowMetaDefault = new RowMeta(); rowMetaDefault.addValueMeta( new ValueMetaString( "URL" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "UPLOAD" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "DESTINATION" ) ); List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>(); rows.add( new RowMetaAndData( rowMetaDefault, r ) ); Result previousResult = new Result(); previousResult.setRows( rows ); JobEntryHTTP http = new JobEntryHTTP(); http.setParentJob( new Job() ); http.setRunForEveryRow( true ); http.setAddFilenameToResult( false ); http.execute( previousResult, 0 ); assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithFilename( ) { Job jobTest = new Job( ); boolean hasFilename = true; boolean hasRepoDir = false; jobTest.copyVariablesFrom( null ); jobTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobTest.setInternalEntryCurrentDirectory( hasFilename, hasRepoDir ); assertEquals( "file:///C:/SomeFilenameDirectory", jobTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Before public void setUp() { Job parentJob = new Job( null, new JobMeta() ); jobEntry = spy( new JobEntryColumnsExist( "" ) ); parentJob.getJobMeta().addJobEntry( new JobEntryCopy( jobEntry ) ); parentJob.setStopped( false ); jobEntry.setParentJob( parentJob ); parentJob.setLogLevel( LogLevel.NOTHING ); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); jobEntry.setDatabase( dbMeta ); db = spy( new Database( jobEntry, dbMeta ) ); jobEntry.setParentJob( parentJob ); jobEntry.setTablename( TABLENAME ); jobEntry.setArguments( COLUMNS ); jobEntry.setSchemaname( SCHEMANAME ); }
@Test public void testSetInternalEntryCurrentDirectoryWithRepository( ) { Job jobTest = new Job( ); boolean hasFilename = false; boolean hasRepoDir = true; jobTest.copyVariablesFrom( null ); jobTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobTest.setInternalEntryCurrentDirectory( hasFilename, hasRepoDir ); assertEquals( "/SomeRepDirectory", jobTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testSetInternalEntryCurrentDirectoryWithoutFilenameOrRepository( ) { Job jobTest = new Job( ); jobTest.copyVariablesFrom( null ); boolean hasFilename = false; boolean hasRepoDir = false; jobTest.setVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY, "Original value defined at run execution" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_FILENAME_DIRECTORY, "file:///C:/SomeFilenameDirectory" ); jobTest.setVariable( Const.INTERNAL_VARIABLE_JOB_REPOSITORY_DIRECTORY, "/SomeRepDirectory" ); jobTest.setInternalEntryCurrentDirectory( hasFilename, hasRepoDir ); assertEquals( "Original value defined at run execution", jobTest.getVariable( Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY ) ); }
@Test public void testHTTPResultCustomRows() throws IOException { File localFileForUpload = getInputFile( "existingFile2", ".tmp" ); File tempFileForDownload = File.createTempFile( "downloadedFile2", ".tmp" ); localFileForUpload.deleteOnExit(); tempFileForDownload.deleteOnExit(); Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile", localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() }; RowMeta rowMetaDefault = new RowMeta(); rowMetaDefault.addValueMeta( new ValueMetaString( "MyURL" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "MyUpload" ) ); rowMetaDefault.addValueMeta( new ValueMetaString( "MyDestination" ) ); List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>(); rows.add( new RowMetaAndData( rowMetaDefault, r ) ); Result previousResult = new Result(); previousResult.setRows( rows ); JobEntryHTTP http = new JobEntryHTTP(); http.setParentJob( new Job() ); http.setRunForEveryRow( true ); http.setAddFilenameToResult( false ); http.setUrlFieldname( "MyURL" ); http.setUploadFieldname( "MyUpload" ); http.setDestinationFieldname( "MyDestination" ); http.execute( previousResult, 0 ); assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new JobEntrySetVariables(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); }
@Test public void testConfigureParameters() throws Exception { JobMeta jobMeta = new JobMeta(); jobMeta.addParameterDefinition( TEST_PARAM_NAME, DEFAULT_PARAM_VALUE, "This tests a default parameter" ); assertEquals( "Default parameter was not set correctly on JobMeta", DEFAULT_PARAM_VALUE, jobMeta.getParameterDefault( TEST_PARAM_NAME ) ); assertEquals( "Parameter value should be blank in JobMeta", "", jobMeta.getParameterValue( TEST_PARAM_NAME ) ); Job job = new Job( null, jobMeta ); job.copyParametersFrom( jobMeta ); assertEquals( "Default parameter was not set correctly on Job", DEFAULT_PARAM_VALUE, job.getParameterDefault( TEST_PARAM_NAME ) ); assertEquals( "Parameter value should be blank in Job", "", job.getParameterValue( TEST_PARAM_NAME ) ); }
@Before public void setUp() throws Exception { MockDriver.registerInstance(); Job job = new Job( null, new JobMeta() ); entry = new JobEntryEvalTableContent(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); DatabaseMeta dbMeta = new DatabaseMeta(); dbMeta.setDatabaseType( "mock-db" ); entry.setDatabase( dbMeta ); }
@Before public void setUp() throws Exception { job = new Job( null, new JobMeta() ); entry = new MockedJobEntryFTP(); job.getJobMeta().addJobEntry( new JobEntryCopy( entry ) ); entry.setParentJob( job ); job.setStopped( false ); entry.setServerName( "some.server" ); entry.setUserName( "anonymous" ); entry.setFtpDirectory( "." ); entry.setWildcard( "robots.txt" ); entry.setBinaryMode( false ); entry.setSuccessCondition( "success_if_no_errors" ); existingDir = TestUtils.createTempDir(); }