@Test public void jobFail_columnNotExist() throws KettleException { doReturn( db ).when( jobEntry ).getNewDatabaseFromMeta(); doNothing().when( db ).connect( anyString(), anyString() ); doReturn( true ).when( db ).checkTableExists( anyString(), anyString() ); doReturn( false ).when( db ).checkColumnExists( anyString(), anyString(), anyString() ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be some errors", 1, result.getNrErrors() ); assertFalse( "Result should be false", result.getResult() ); verify( db, atLeastOnce() ).disconnect(); }
@Override public Result execute( Result previousResult, int nr ) throws KettleJobException { previousResult.setResult( false ); previousResult.setNrErrors( previousResult.getNrErrors() + 1 ); getLogChannel().logError( BaseMessages.getString( MissingEntry.class, "MissingEntry.Log.CannotRunJob" ) ); return previousResult; }
@Test public void jobSuccess() throws KettleException { doReturn( db ).when( jobEntry ).getNewDatabaseFromMeta(); doNothing().when( db ).connect( anyString(), anyString() ); doReturn( true ).when( db ).checkColumnExists( anyString(), anyString(), anyString() ); doReturn( true ).when( db ).checkTableExists( anyString(), anyString() ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be no error", 0, result.getNrErrors() ); assertTrue( "Result should be true", result.getResult() ); assertEquals( "Lines written", COLUMNS.length, result.getNrLinesWritten() ); verify( db, atLeastOnce() ).disconnect(); } }
@Test public void jobFail_tableNotExist() throws KettleException { when( jobEntry.getNewDatabaseFromMeta() ).thenReturn( db ); doNothing().when( db ).connect( anyString(), any() ); doReturn( false ).when( db ).checkTableExists( anyString(), anyString() ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be error", 1, result.getNrErrors() ); assertFalse( "Result should be false", result.getResult() ); verify( db, atLeastOnce() ).disconnect(); }
@Test public void testExecute() throws KettleJobException { MissingEntry entry = spy( new MissingEntry() ); when( entry.getLogChannel() ).thenReturn( mock( LogChannel.class ) ); entry.setName( "MissingTest" ); Result result = new Result(); result.setNrErrors( 0 ); result.setResult( true ); entry.execute( result, 0 ); assertEquals( 1, result.getNrErrors() ); assertEquals( false, result.getResult() ); }
private void copyResult( Trans trans ) { Result result = trans.getResult(); setLinesInput( result.getNrLinesInput() ); setLinesOutput( result.getNrLinesOutput() ); setLinesRead( result.getNrLinesRead() ); setLinesWritten( result.getNrLinesWritten() ); setLinesUpdated( result.getNrLinesUpdated() ); setLinesRejected( result.getNrLinesRejected() ); setErrors( result.getNrErrors() ); }
@Test public void jobFail_columnsArrayIsEmpty() throws KettleException { jobEntry.setArguments( null ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be error", 1, result.getNrErrors() ); assertFalse( "Result should be false", result.getResult() ); }
@Test public void testSetNrErrorsNewBehaviorFail() throws Exception { entry.setFoldername( nonEmptyDir ); Result result = entry.execute( new Result(), 0 ); assertFalse( "For non-empty folder result should be false", result.getResult() ); assertEquals( "There should be still no errors", 0, result.getNrErrors() ); }
@Test public void testFixedExistingTargetDir() throws Exception { entry.setTargetDirectory( existingDir ); Result result = entry.execute( new Result(), 0 ); assertTrue( "For existing folder should be true", result.getResult() ); assertEquals( "There should be no errors", 0, result.getNrErrors() ); }
@Test public void testFixedNonExistingTargetDir() throws Exception { entry.setTargetDirectory( existingDir + File.separator + "sub" ); Result result = entry.execute( new Result(), 0 ); assertFalse( "For non existing folder should be false", result.getResult() ); assertTrue( "There should be errors", 0 != result.getNrErrors() ); }
@Test public void jobFail_tableNameIsEmpty() throws KettleException { jobEntry.setTablename( null ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be error", 1, result.getNrErrors() ); assertFalse( "Result should be false", result.getResult() ); }
@Test public void testExecuteWithException() throws Exception { entry.setArguments( new String[] { null } ); Result res = entry.execute( new Result(), 0 ); assertFalse( "Entry should fail", res.getResult() ); assertEquals( "File with wrong name was specified. One error should be reported", 1, res.getNrErrors() ); }
@Test public void jobFail_connectionIsNull() throws KettleException { jobEntry.setDatabase( null ); final Result result = jobEntry.execute( new Result(), 0 ); assertEquals( "Should be error", 1, result.getNrErrors() ); assertFalse( "Result should be false", result.getResult() ); }
@Test public void testSetNrErrorsOldBehaviorFail() throws Exception { entry.setFoldername( nonEmptyDir ); entry.setVariable( Const.KETTLE_COMPATIBILITY_SET_ERROR_ON_SPECIFIC_JOB_ENTRIES, "Y" ); Result result = entry.execute( new Result(), 0 ); assertFalse( "For non-empty folder result should be false", result.getResult() ); assertEquals( "According to old behaviour there should be an error", 1, result.getNrErrors() ); } }
@Test public void testVariableNonExistingTargetDir() throws Exception { entry.setTargetDirectory( "${Internal.Job.Filename.Directory}/Worg" ); entry.setVariable( "Internal.Job.Filename.Directory", existingDir + File.separator + "sub" ); Result result = entry.execute( new Result(), 0 ); assertFalse( "For non existing folder should be false", result.getResult() ); assertTrue( "There should be errors", 0 != result.getNrErrors() ); }
@Test public void testPtotocolVariableNonExistingTargetDir() throws Exception { entry.setTargetDirectory( "${Internal.Job.Filename.Directory}/Worg" ); entry.setVariable( "Internal.Job.Filename.Directory", "file://" + existingDir + File.separator + "sub" ); Result result = entry.execute( new Result(), 0 ); assertFalse( "For non existing folder should be false", result.getResult() ); assertTrue( "There should be errors", 0 != result.getNrErrors() ); }
@Test public void testProtocolVariableExistingTargetDir() throws Exception { entry.setTargetDirectory( "${Internal.Job.Filename.Directory}" ); entry.setVariable( "Internal.Job.Filename.Directory", "file://" + existingDir ); Result result = entry.execute( new Result(), 0 ); assertTrue( "For existing folder should be true", result.getResult() ); assertEquals( "There should be no errors", 0, result.getNrErrors() ); }
@Test public void testVariableExistingTargetDir() throws Exception { entry.setTargetDirectory( "${Internal.Job.Filename.Directory}" ); entry.setVariable( "Internal.Job.Filename.Directory", existingDir ); Result result = entry.execute( new Result(), 0 ); assertTrue( "For existing folder should be true", result.getResult() ); assertEquals( "There should be no errors", 0, result.getNrErrors() ); }
@Test public void testNrErrorsFailureNewBehavior() throws Exception { entry.setLimit( "1" ); entry.setSuccessCondition( JobEntryEvalTableContent.SUCCESS_CONDITION_ROWS_COUNT_EQUAL ); entry.setTablename( "table" ); Result res = entry.execute( new Result(), 0 ); assertFalse( "Eval number of rows should fail", res.getResult() ); assertEquals( "No errors should be reported in result object accoding to the new behavior", res.getNrErrors(), 0 ); }
@Test public void testNrErrorsFailureOldBehavior() throws Exception { entry.setLimit( "1" ); entry.setSuccessCondition( JobEntryEvalTableContent.SUCCESS_CONDITION_ROWS_COUNT_EQUAL ); entry.setTablename( "table" ); entry.setVariable( Const.KETTLE_COMPATIBILITY_SET_ERROR_ON_SPECIFIC_JOB_ENTRIES, "Y" ); Result res = entry.execute( new Result(), 0 ); assertFalse( "Eval number of rows should fail", res.getResult() ); assertEquals( "An error should be reported in result object accoding to the old behavior", res.getNrErrors(), 1 ); }