method2testcases
stringlengths 118
6.63k
|
---|
### Question:
ValueMetaInternetAddress extends ValueMetaDate { @Override public byte[] getBinaryString( Object object ) throws KettleValueException { if ( isStorageBinaryString() && identicalFormat ) { return (byte[]) object; } if ( object == null ) { return null; } switch ( storageType ) { case STORAGE_TYPE_NORMAL: return convertStringToBinaryString( getString( object ) ); case STORAGE_TYPE_BINARY_STRING: return convertStringToBinaryString( getString( convertStringToInternetAddress( convertBinaryStringToString( (byte[]) object ) ) ) ); case STORAGE_TYPE_INDEXED: return convertStringToBinaryString( convertInternetAddressToString( (InetAddress) index[( (Integer) object )] ) ); default: throw new KettleValueException( toString() + " : Unknown storage type " + storageType + " specified." ); } } ValueMetaInternetAddress(); ValueMetaInternetAddress( String name ); @Override int compare( Object data1, Object data2 ); InetAddress getInternetAddress( Object object ); @Override Date getDate( Object object ); @Override Long getInteger( Object object ); @Override Double getNumber( Object object ); @Override BigDecimal getBigNumber( Object object ); @Override Boolean getBoolean( Object object ); @Override String getString( Object object ); @Override byte[] getBinaryString( Object object ); @Override Object convertDataFromString( String pol, ValueMetaInterface convertMeta, String nullIf, String ifNull,
int trim_type ); @Override Object convertData( ValueMetaInterface meta2, Object data2 ); @Override Object cloneValueData( Object object ); @Override ValueMetaInterface getValueFromSQLType( DatabaseMeta databaseMeta, String name, ResultSetMetaData rm,
int index, boolean ignoreLength, boolean lazyConversion ); @Override Object getValueFromResultSet( DatabaseInterface databaseInterface, ResultSet resultSet, int index ); @Override void setPreparedStatementValue( DatabaseMeta databaseMeta, PreparedStatement preparedStatement,
int index, Object data ); @Override String getDatabaseColumnTypeDefinition( DatabaseInterface databaseInterface, String tk, String pk,
boolean use_autoinc, boolean add_fieldname, boolean add_cr ); @Override Class<?> getNativeDataTypeClass(); }### Answer:
@Test public void testGetBinaryString() throws KettleValueException, UnknownHostException { ValueMetaInternetAddress vmInet = new ValueMetaInternetAddress(); final ValueMetaString vmString = new ValueMetaString(); vmInet.setStorageMetadata( vmString ); InetAddress inetAddress = InetAddress.getByName( "127.0.0.1" ); byte[] output = vmInet.getBinaryString( inetAddress ); assertNotNull( output ); assertArrayEquals( vmString.getBinaryString( "127.0.0.1" ), output ); assertEquals( inetAddress, vmInet.convertBinaryStringToNativeType( output ) ); vmInet.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); output = vmInet.getBinaryString( vmString.getBinaryString( "127.0.0.1" ) ); assertNotNull( output ); assertArrayEquals( vmString.getBinaryString( "127.0.0.1" ), output ); assertEquals( inetAddress, vmInet.convertBinaryStringToNativeType( output ) ); vmInet.setStorageType( ValueMetaInterface.STORAGE_TYPE_INDEXED ); vmInet.setIndex( new InetAddress[] { inetAddress } ); assertArrayEquals( vmString.getBinaryString( "127.0.0.1" ), vmInet.getBinaryString( 0 ) ); assertEquals( inetAddress, vmInet.convertBinaryStringToNativeType( output ) ); try { vmInet.getBinaryString( 1 ); fail(); } catch ( ArrayIndexOutOfBoundsException e ) { } } |
### Question:
ValueMetaFactory { public static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ) throws KettlePluginException { return cloneValueMeta( source, source.getType() ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testClone() throws KettleException { ValueMetaInterface original = new ValueMetaString(); original.setCollatorLocale( Locale.CANADA ); original.setCollatorStrength( 3 ); ValueMetaInterface cloned = ValueMetaFactory.cloneValueMeta( original ); assertNotNull( cloned ); assertNotSame( original, cloned ); valueMetaDeepEquals( original, cloned ); } |
### Question:
ValueMetaFactory { public static String[] getValueMetaNames() { List<String> strings = new ArrayList<String>(); List<PluginInterface> plugins = pluginRegistry.getPlugins( ValueMetaPluginType.class ); for ( PluginInterface plugin : plugins ) { int id = Integer.valueOf( plugin.getIds()[0] ); if ( id > 0 && id != ValueMetaInterface.TYPE_SERIALIZABLE ) { strings.add( plugin.getName() ); } } return strings.toArray( new String[strings.size()] ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGetValueMetaNames() { List<String> dataTypes = Arrays.<String>asList( ValueMetaFactory.getValueMetaNames() ); assertTrue( dataTypes.contains( "Number" ) ); assertTrue( dataTypes.contains( "String" ) ); assertTrue( dataTypes.contains( "Date" ) ); assertTrue( dataTypes.contains( "Boolean" ) ); assertTrue( dataTypes.contains( "Integer" ) ); assertTrue( dataTypes.contains( "BigNumber" ) ); assertFalse( dataTypes.contains( "Serializable" ) ); assertTrue( dataTypes.contains( "Binary" ) ); assertTrue( dataTypes.contains( "Timestamp" ) ); assertTrue( dataTypes.contains( "Internet Address" ) ); } |
### Question:
ValueMetaFactory { public static String[] getAllValueMetaNames() { List<String> strings = new ArrayList<String>(); List<PluginInterface> plugins = pluginRegistry.getPlugins( ValueMetaPluginType.class ); for ( PluginInterface plugin : plugins ) { String id = plugin.getIds()[0]; if ( !( "0".equals( id ) ) ) { strings.add( plugin.getName() ); } } return strings.toArray( new String[strings.size()] ); } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGetAllValueMetaNames() { List<String> dataTypes = Arrays.<String>asList( ValueMetaFactory.getAllValueMetaNames() ); assertTrue( dataTypes.contains( "Number" ) ); assertTrue( dataTypes.contains( "String" ) ); assertTrue( dataTypes.contains( "Date" ) ); assertTrue( dataTypes.contains( "Boolean" ) ); assertTrue( dataTypes.contains( "Integer" ) ); assertTrue( dataTypes.contains( "BigNumber" ) ); assertTrue( dataTypes.contains( "Serializable" ) ); assertTrue( dataTypes.contains( "Binary" ) ); assertTrue( dataTypes.contains( "Timestamp" ) ); assertTrue( dataTypes.contains( "Internet Address" ) ); } |
### Question:
ValueMetaFactory { public static String getValueMetaName( int type ) { for ( PluginInterface plugin : pluginRegistry.getPlugins( ValueMetaPluginType.class ) ) { if ( Integer.toString( type ).equals( plugin.getIds()[0] ) ) { return plugin.getName(); } } return "-"; } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGetValueMetaName() { assertEquals( "-", ValueMetaFactory.getValueMetaName( Integer.MIN_VALUE ) ); assertEquals( "None", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_NONE ) ); assertEquals( "Number", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_NUMBER ) ); assertEquals( "String", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_STRING ) ); assertEquals( "Date", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_DATE ) ); assertEquals( "Boolean", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_BOOLEAN ) ); assertEquals( "Integer", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_INTEGER ) ); assertEquals( "BigNumber", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_BIGNUMBER ) ); assertEquals( "Serializable", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_SERIALIZABLE ) ); assertEquals( "Binary", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_BINARY ) ); assertEquals( "Timestamp", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_TIMESTAMP ) ); assertEquals( "Internet Address", ValueMetaFactory.getValueMetaName( ValueMetaInterface.TYPE_INET ) ); } |
### Question:
ValueMetaFactory { public static int getIdForValueMeta( String valueMetaName ) { for ( PluginInterface plugin : pluginRegistry.getPlugins( ValueMetaPluginType.class ) ) { if ( valueMetaName != null && valueMetaName.equalsIgnoreCase( plugin.getName() ) ) { return Integer.valueOf( plugin.getIds()[0] ); } } return ValueMetaInterface.TYPE_NONE; } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGetIdForValueMeta() { assertEquals( ValueMetaInterface.TYPE_NONE, ValueMetaFactory.getIdForValueMeta( null ) ); assertEquals( ValueMetaInterface.TYPE_NONE, ValueMetaFactory.getIdForValueMeta( "" ) ); assertEquals( ValueMetaInterface.TYPE_NONE, ValueMetaFactory.getIdForValueMeta( "None" ) ); assertEquals( ValueMetaInterface.TYPE_NUMBER, ValueMetaFactory.getIdForValueMeta( "Number" ) ); assertEquals( ValueMetaInterface.TYPE_STRING, ValueMetaFactory.getIdForValueMeta( "String" ) ); assertEquals( ValueMetaInterface.TYPE_DATE, ValueMetaFactory.getIdForValueMeta( "Date" ) ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, ValueMetaFactory.getIdForValueMeta( "Boolean" ) ); assertEquals( ValueMetaInterface.TYPE_INTEGER, ValueMetaFactory.getIdForValueMeta( "Integer" ) ); assertEquals( ValueMetaInterface.TYPE_BIGNUMBER, ValueMetaFactory.getIdForValueMeta( "BigNumber" ) ); assertEquals( ValueMetaInterface.TYPE_SERIALIZABLE, ValueMetaFactory.getIdForValueMeta( "Serializable" ) ); assertEquals( ValueMetaInterface.TYPE_BINARY, ValueMetaFactory.getIdForValueMeta( "Binary" ) ); assertEquals( ValueMetaInterface.TYPE_TIMESTAMP, ValueMetaFactory.getIdForValueMeta( "Timestamp" ) ); assertEquals( ValueMetaInterface.TYPE_INET, ValueMetaFactory.getIdForValueMeta( "Internet Address" ) ); } |
### Question:
ValueMetaFactory { public static List<ValueMetaInterface> getValueMetaPluginClasses() throws KettlePluginException { List<ValueMetaInterface> list = new ArrayList<ValueMetaInterface>(); List<PluginInterface> plugins = pluginRegistry.getPlugins( ValueMetaPluginType.class ); for ( PluginInterface plugin : plugins ) { ValueMetaInterface valueMetaInterface = (ValueMetaInterface) pluginRegistry.loadClass( plugin ); list.add( valueMetaInterface ); } return list; } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGetValueMetaPluginClasses() throws KettlePluginException { List<ValueMetaInterface> dataTypes = ValueMetaFactory.getValueMetaPluginClasses(); boolean numberExists = false; boolean stringExists = false; boolean dateExists = false; boolean booleanExists = false; boolean integerExists = false; boolean bignumberExists = false; boolean serializableExists = false; boolean binaryExists = false; boolean timestampExists = false; boolean inetExists = false; for ( ValueMetaInterface obj : dataTypes ) { if ( obj instanceof ValueMetaNumber ) { numberExists = true; } if ( obj.getClass().equals( ValueMetaString.class ) ) { stringExists = true; } if ( obj.getClass().equals( ValueMetaDate.class ) ) { dateExists = true; } if ( obj.getClass().equals( ValueMetaBoolean.class ) ) { booleanExists = true; } if ( obj.getClass().equals( ValueMetaInteger.class ) ) { integerExists = true; } if ( obj.getClass().equals( ValueMetaBigNumber.class ) ) { bignumberExists = true; } if ( obj.getClass().equals( ValueMetaSerializable.class ) ) { serializableExists = true; } if ( obj.getClass().equals( ValueMetaBinary.class ) ) { binaryExists = true; } if ( obj.getClass().equals( ValueMetaTimestamp.class ) ) { timestampExists = true; } if ( obj.getClass().equals( ValueMetaInternetAddress.class ) ) { inetExists = true; } } assertTrue( numberExists ); assertTrue( stringExists ); assertTrue( dateExists ); assertTrue( booleanExists ); assertTrue( integerExists ); assertTrue( bignumberExists ); assertTrue( serializableExists ); assertTrue( binaryExists ); assertTrue( timestampExists ); assertTrue( inetExists ); } |
### Question:
MessageEventService { public void fireEvent( final Message event ) throws MessageEventFireEventException { if ( event != null ) { if ( containsHandlerFor( event ) ) { final Collection<MessageEventHandler> handlers = getHandlersFor( event ); if ( handlers != null && handlers.size() > 0 ) { MessageEventFireEventException messageEventFireEventException = null; for ( final MessageEventHandler handler : handlers ) { try { handler.execute( event ); } catch ( final Exception e ) { if ( messageEventFireEventException == null ) { messageEventFireEventException = new MessageEventFireEventException( "Unable to execute some handler." ); } messageEventFireEventException.addHandlerException( e ); } } if ( messageEventFireEventException != null ) { throw messageEventFireEventException; } } } } else { throw new MessageEventFireEventException( "Unable to fire a null event" ); } } MessageEventService(); void fireEvent( final Message event ); final void addHandler( final Message eventType, final MessageEventHandler handler ); final boolean hasHandlers( final Message eventType ); List<MessageEventHandler> getHandlersFor( final Message eventType ); }### Answer:
@Test( expected = MessageEventFireEventException.class ) public void testFireEventNull() throws KettleException { messageEventService.fireEvent( null ); }
@Test public void testOperationFireEvent() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.OPERATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); }
@Test( expected = MessageEventFireEventException.class ) public void testOperationFireEventThrowException() throws KettleException { addHandlers( operationMessageEvent, messageEventHandler, messageEventHandler2 ); doThrow( new RuntimeException( "Test" ) ).when( messageEventHandler ).execute( any( Message.class ) ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.OPERATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler, never() ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); }
@Test public void testStopMessageFireEvent() throws KettleException { addHandlers( new StopMessage( "" ), messageEventHandler, messageEventHandler2 ); StopMessage msg = new StopMessage( "User request" ); messageEventService.fireEvent( msg ); verify( messageEventHandler ).execute( msg ); verify( messageEventHandler2 ).execute( msg ); }
@Test public void testTransformationFireEvent() throws Exception { addHandlers( transformationMessageEvent, messageEventHandler, messageEventHandler2 ); LogEvent logEvent = new LogEvent<>( new RemoteSource( ModelType.TRANSFORMATION, "Operation_ID" ), logEntry ); messageEventService.fireEvent( logEvent ); verify( messageEventHandler ).execute( logEvent ); verify( messageEventHandler2 ).execute( logEvent ); } |
### Question:
ValueMetaFactory { public static ValueMetaInterface guessValueMetaInterface( Object object ) { if ( object instanceof Number ) { if ( object instanceof BigDecimal ) { return new ValueMetaBigNumber(); } else if ( object instanceof Double ) { return new ValueMetaNumber(); } else if ( object instanceof Long ) { return new ValueMetaInteger(); } } else if ( object instanceof String ) { return new ValueMetaString(); } else if ( object instanceof Date ) { return new ValueMetaDate(); } else if ( object instanceof Boolean ) { return new ValueMetaBoolean(); } else if ( object instanceof byte[] ) { return new ValueMetaBinary(); } return null; } static ValueMetaInterface createValueMeta( String name, int type, int length, int precision ); static ValueMetaInterface createValueMeta( String name, int type ); static ValueMetaInterface createValueMeta( int type ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source ); static ValueMetaInterface cloneValueMeta( ValueMetaInterface source, int targetType ); static String[] getValueMetaNames(); static String[] getAllValueMetaNames(); static String getValueMetaName( int type ); static int getIdForValueMeta( String valueMetaName ); static List<ValueMetaInterface> getValueMetaPluginClasses(); static ValueMetaInterface guessValueMetaInterface( Object object ); static PluginRegistry pluginRegistry; }### Answer:
@Test public void testGuessValueMetaInterface() { assertTrue( ValueMetaFactory.guessValueMetaInterface( new BigDecimal( 1.0 ) ) instanceof ValueMetaBigNumber ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new Double( 1.0 ) ) instanceof ValueMetaNumber ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new Long( 1 ) ) instanceof ValueMetaInteger ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new String() ) instanceof ValueMetaString ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new Date() ) instanceof ValueMetaDate ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new Boolean( false ) ) instanceof ValueMetaBoolean ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new Boolean( true ) ) instanceof ValueMetaBoolean ); assertTrue( ValueMetaFactory.guessValueMetaInterface( false ) instanceof ValueMetaBoolean ); assertTrue( ValueMetaFactory.guessValueMetaInterface( true ) instanceof ValueMetaBoolean ); assertTrue( ValueMetaFactory.guessValueMetaInterface( new byte[10] ) instanceof ValueMetaBinary ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( null ) ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( new Short( (short) 1 ) ) ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( new Byte( (byte) 1 ) ) ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( new Float( 1.0 ) ) ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( new StringBuilder() ) ); assertEquals( null, ValueMetaFactory.guessValueMetaInterface( (byte) 1 ) ); } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ) { if ( compatibleToSuperPattern ) { return super.format( timestamp, toAppendTo, pos ); } StringBuffer dateBuffer; String nan; if ( timestamp instanceof Timestamp ) { Timestamp tmp = (Timestamp) timestamp; Date date = new Date( tmp.getTime() ); dateBuffer = super.format( date, toAppendTo, pos ); nan = formatNanoseconds( tmp.getNanos() ); } else { dateBuffer = super.format( timestamp, toAppendTo, pos ); String milliseconds = defaultMillisecondDateFormat.format( timestamp ); nan = formatNanoseconds( Integer.valueOf( milliseconds ) * Math.pow( 10, 6 ) ); } int placeholderPosition = replaceHolder( dateBuffer, false ); return dateBuffer.insert( pos.getBeginIndex() + placeholderPosition, nan ); } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testFormat() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); checkFormat( "KETTLE.LONG" ); checkFormat( "LOCALE.DATE", new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ) ); checkFormat( "KETTLE" ); checkFormat( "DB.DEFAULT" ); checkFormat( "LOCALE.DEFAULT" ); } }
@Test public void testFormat() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org.apache.hop/core/row/value/timestamp/messages/testdates", locale ); checkFormat( "HOP.LONG" ); checkFormat( "LOCALE.DATE", new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ) ); checkFormat( "HOP" ); checkFormat( "DB.DEFAULT" ); checkFormat( "LOCALE.DEFAULT" ); } } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public Date parse( String text, ParsePosition pos ) { String timestampFormatDate; Date tempDate; if ( compatibleToSuperPattern ) { tempDate = super.parse( text, pos ); return new Timestamp( tempDate.getTime() ); } StringBuilder dateText = new StringBuilder( text.substring( pos.getIndex() ) ); ParsePosition positionError = new ParsePosition( 0 ); tempDate = super.parse( dateText.toString(), positionError ); if ( tempDate != null ) { pos.setErrorIndex( pos.getIndex() ); return null; } int startNanosecondsPosition = positionError.getErrorIndex(); int endNanosecondsPosition = endNanosecondPatternPosition - startNanosecondPatternPosition + 1 + startNanosecondsPosition; endNanosecondsPosition = ( endNanosecondsPosition >= dateText.length() ) ? dateText.length() : endNanosecondsPosition; String nanoseconds = String.valueOf( dateText.subSequence( startNanosecondsPosition, endNanosecondsPosition ) ); dateText.delete( startNanosecondsPosition, endNanosecondsPosition ); ParsePosition position = new ParsePosition( 0 ); dateText.append( NANOSECOND_PLACEHOLDER ); tempDate = super.parse( dateText.toString(), position ); if ( tempDate == null ) { pos.setErrorIndex( position.getErrorIndex() ); return null; } timestampFormatDate = defaultTimestampFormat.format( tempDate ); String result = timestampFormatDate + '.' + nanoseconds; Timestamp res = Timestamp.valueOf( timestampFormatDate + '.' + nanoseconds ); pos.setIndex( pos.getIndex() + result.length() ); return res; } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testParse() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); checkParseKettle(); checkParseKettleLong(); checkParseDbDefault(); checkParseLocaleDefault(); } }
@Test public void testParse() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org.apache.hop/core/row/value/timestamp/messages/testdates", locale ); checkParseHop(); checkParseHopLong(); checkParseDbDefault(); checkParseLocaleDefault(); } } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public String toPattern() { return originalPattern; } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testToPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); String patternExample = tdb.getString( "PATTERN.KETTLE" ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DATE" ), stf.toPattern() ); stf = new SimpleTimestampFormat( patternExample, Locale.GERMANY ); assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() ); stf = new SimpleTimestampFormat( patternExample, Locale.US ); assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() ); } }
@Test public void testToPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/apache/hop/core/row/value/timestamp/messages/testdates", locale ); String patternExample = tdb.getString( "PATTERN.HOP" ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DATE" ), stf.toPattern() ); stf = new SimpleTimestampFormat( patternExample, Locale.GERMANY ); assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() ); stf = new SimpleTimestampFormat( patternExample, Locale.US ); assertEquals( locale.toLanguageTag(), patternExample, stf.toPattern() ); } } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public String toLocalizedPattern() { if ( compatibleToSuperPattern ) { return super.toLocalizedPattern(); } else { StringBuffer pattern = new StringBuffer( super.toLocalizedPattern() ); int placeholderPosition = replaceHolder( pattern, true ); for ( int i = placeholderPosition; i <= endNanosecondPatternPosition - startNanosecondPatternPosition + placeholderPosition; i++ ) { pattern.insert( i, patternNanosecond ); } return pattern.toString(); } } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testToLocalizedPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.COMPILED" ), stf.toLocalizedPattern() ); String patternExample = tdb.getString( "PATTERN.KETTLE" ); stf = new SimpleTimestampFormat( patternExample ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.COMPILED_DATE" ), stf.toLocalizedPattern() ); } }
@Test public void testToLocalizedPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/apache/hop/core/row/value/timestamp/messages/testdates", locale ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.COMPILED" ), stf.toLocalizedPattern() ); String patternExample = tdb.getString( "PATTERN.HOP" ); stf = new SimpleTimestampFormat( patternExample ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.COMPILED_DATE" ), stf.toLocalizedPattern() ); } } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public void applyPattern( String pattern ) { DateFormatSymbols formatSymbols = super.getDateFormatSymbols(); init( pattern, formatSymbols, false ); } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testApplyPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); String patternExample = tdb.getString( "PATTERN.KETTLE" ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DATE" ), stf.toPattern() ); stf.applyPattern( patternExample ); checkFormat( "KETTLE", stf ); } }
@Test public void testApplyPattern() throws Exception { for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/apache/hop/core/row/value/timestamp/messages/testdates", locale ); String patternExample = tdb.getString( "PATTERN.HOP" ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DATE" ), stf.toPattern() ); stf.applyPattern( patternExample ); checkFormat( "HOP", stf ); } } |
### Question:
SimpleTimestampFormat extends SimpleDateFormat { @Override public void applyLocalizedPattern( String pattern ) { DateFormatSymbols formatSymbols = super.getDateFormatSymbols(); init( pattern, formatSymbols, true ); } SimpleTimestampFormat( String pattern ); SimpleTimestampFormat( String pattern, Locale locale ); SimpleTimestampFormat( String pattern, DateFormatSymbols formatSymbols ); @Override void setDateFormatSymbols( DateFormatSymbols newFormatSymbols ); @Override StringBuffer format( Date timestamp, StringBuffer toAppendTo, FieldPosition pos ); @Override AttributedCharacterIterator formatToCharacterIterator( Object obj ); @Override Date parse( String text, ParsePosition pos ); @Override String toPattern(); @Override String toLocalizedPattern(); @Override void applyPattern( String pattern ); @Override void applyLocalizedPattern( String pattern ); @Override Date parse( String source ); @Override Object parseObject( String source, ParsePosition pos ); static final String DEFAULT_TIMESTAMP_FORMAT; }### Answer:
@Test public void testApplyLocalizedPattern() throws Exception { Locale.setDefault( Locale.Category.FORMAT, Locale.US ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/pentaho/di/core/row/value/timestamp/messages/testdates", locale ); stf.applyLocalizedPattern( tdb.getString( "PATTERN.LOCALE.DEFAULT" ) ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DEFAULT" ), stf.toLocalizedPattern() ); checkFormat( "LOCALE.DEFAULT", stf ); } }
@Test public void testApplyLocalizedPattern() throws Exception { Locale.setDefault( Locale.Category.FORMAT, Locale.US ); SimpleTimestampFormat stf = new SimpleTimestampFormat( new SimpleDateFormat().toPattern() ); for ( Locale locale : locales ) { Locale.setDefault( Locale.Category.FORMAT, locale ); tdb = ResourceBundle.getBundle( "org/apache/hop/core/row/value/timestamp/messages/testdates", locale ); stf.applyLocalizedPattern( tdb.getString( "PATTERN.LOCALE.DEFAULT" ) ); assertEquals( locale.toLanguageTag(), tdb.getString( "PATTERN.LOCALE.DEFAULT" ), stf.toLocalizedPattern() ); checkFormat( "LOCALE.DEFAULT", stf ); } } |
### Question:
WriterOutputStream extends OutputStream { @Override public void write( int b ) throws IOException { write( new byte[] { (byte) b, } ); } WriterOutputStream( Writer writer ); WriterOutputStream( Writer writer, String encoding ); @Override void write( int b ); @Override void write( byte[] b, int off, int len ); @Override void write( byte[] b ); @Override void close(); @Override void flush(); Writer getWriter(); String getEncoding(); }### Answer:
@Test public void testWrite() throws IOException { WriterOutputStream stream = new WriterOutputStream( writer ); stream.write( 68 ); stream.write( "value".getBytes(), 1, 3 ); stream.write( "value".getBytes() ); stream.flush(); stream.close(); verify( writer ).append( new String( new byte[] { (byte) 68 } ) ); verify( writer ).append( "alu" ); verify( writer ).append( "value" ); verify( writer ).flush(); verify( writer ).close(); assertNull( stream.getWriter() ); writer = mock( Writer.class ); WriterOutputStream streamWithEncoding = new WriterOutputStream( writer, encoding ); streamWithEncoding.write( "value".getBytes( encoding ) ); verify( writer ).append( "value" ); } |
### Question:
PluginFolder implements PluginFolderInterface { @Override public FileObject[] findJarFiles() throws KettleFileException { return findJarFiles( searchLibDir ); } PluginFolder( String folder, boolean pluginXmlFolder, boolean pluginAnnotationsFolder ); PluginFolder( String folder, boolean pluginXmlFolder, boolean pluginAnnotationsFolder,
boolean searchLibDir ); @Override String toString(); static List<PluginFolderInterface> populateFolders( String xmlSubfolder ); @Override FileObject[] findJarFiles(); FileObject[] findJarFiles( final boolean includeLibJars ); @Override String getFolder(); void setFolder( String folder ); @Override boolean isPluginXmlFolder(); void setPluginXmlFolder( boolean pluginXmlFolder ); @Override boolean isPluginAnnotationsFolder(); void setPluginAnnotationsFolder( boolean pluginAnnotationsFolder ); }### Answer:
@Test public void testFindJarFiles_DirWithJarInNameNotAdded() throws IOException, KettleFileException { Files.createDirectories( PATH_TO_DIR_WITH_JAR_IN_NAME ); FileObject[] findJarFiles = plFolder.findJarFiles(); assertNotNull( findJarFiles ); assertEquals( 0, findJarFiles.length ); }
@Test public void testFindJarFiles_DirWithJarInNameNotAddedAndTxtFileNotAdded() throws IOException, KettleFileException { Files.createDirectories( PATH_TO_DIR_WITH_JAR_IN_NAME ); Files.createFile( PATH_TO_NOT_JAR_FILE ); FileObject[] findJarFiles = plFolder.findJarFiles(); assertNotNull( findJarFiles ); assertEquals( 0, findJarFiles.length ); }
@Test public void testFindJarFiles_SeveralJarsInDifferentDirs() throws IOException, KettleFileException { Files.createDirectories( PATH_TO_DIR_WITH_JAR_IN_NAME ); Files.createFile( PATH_TO_JAR_FILE1 ); Files.createFile( PATH_TO_NOT_JAR_FILE ); Files.createDirectories( PATH_TO_TEST_DIR_NAME ); Files.createFile( PATH_TO_JAR_FILE2 ); Files.createFile( PATH_TO_NOT_JAR_FILE_IN_TEST_DIR ); Files.createFile( Paths.get( BASE_TEMP_DIR, PLUGINS_DIR_NAME, JAR_FILE2_NAME ) ); Files.createFile( Paths.get( BASE_TEMP_DIR, PLUGINS_DIR_NAME, NOT_JAR_FILE_NAME ) ); FileObject[] findJarFiles = plFolder.findJarFiles(); assertNotNull( findJarFiles ); assertEquals( 3, findJarFiles.length ); }
@Test public void testFindJarFiles_DirWithKettleIgnoreFileIgnored() throws IOException, KettleFileException { Files.createDirectories( PATH_TO_TEST_DIR_NAME ); Files.createFile( PATH_TO_JAR_FILE2 ); Files.createFile( PATH_TO_KETTLE_IGNORE_FILE ); FileObject[] findJarFiles = plFolder.findJarFiles(); assertNotNull( findJarFiles ); assertEquals( 0, findJarFiles.length ); }
@Test public void testFindJarFiles_LibDirIgnored() throws IOException, KettleFileException { Files.createDirectories( Paths.get( BASE_TEMP_DIR, PLUGINS_DIR_NAME, "lib" ) ); Files.createFile( PATH_TO_JAR_IN_LIB_DIR ); FileObject[] findJarFiles = plFolder.findJarFiles(); assertNotNull( findJarFiles ); assertEquals( 0, findJarFiles.length ); }
@Test public void testFindJarFiles_ExceptionThrows() { String nullFolder = null; String expectedMessage = "Unable to list jar files in plugin folder '" + nullFolder + "'"; plFolder = new PluginFolder( nullFolder, false, true ); try { plFolder.findJarFiles(); fail( "KettleFileException was not occured but expected." ); } catch ( KettleFileException e ) { assertTrue( e instanceof KettleFileException ); assertTrue( e.getLocalizedMessage().trim().startsWith( expectedMessage ) ); } } |
### Question:
NamedParamsDefault implements NamedParams { @Override public void addParameterDefinition( String key, String defValue, String description ) throws DuplicateParamException { if ( params.get( key ) == null ) { OneNamedParam oneParam = new OneNamedParam(); oneParam.key = key; oneParam.defaultValue = defValue; oneParam.description = description; oneParam.value = ""; params.put( key, oneParam ); } else { throw new DuplicateParamException( "Duplicate parameter '" + key + "' detected." ); } } NamedParamsDefault(); @Override void addParameterDefinition( String key, String defValue, String description ); @Override String getParameterDescription( String key ); @Override String getParameterValue( String key ); @Override String getParameterDefault( String key ); @Override String[] listParameters(); @Override void setParameterValue( String key, String value ); @Override void eraseParameters(); @Override void clearParameters(); @Override void activateParameters(); @Override void copyParametersFrom( NamedParams aParam ); }### Answer:
@Test( expected = DuplicateParamException.class ) public void testAddParameterDefinitionWithException() throws DuplicateParamException { namedParams.addParameterDefinition( "key", "value", "description" ); namedParams.addParameterDefinition( "key", "value", "description" ); } |
### Question:
NamedParamsDefault implements NamedParams { @Override public void copyParametersFrom( NamedParams aParam ) { if ( params != null && aParam != null ) { params.clear(); String[] keys = aParam.listParameters(); for ( int idx = 0; idx < keys.length; idx++ ) { String desc; try { desc = aParam.getParameterDescription( keys[idx] ); } catch ( UnknownParamException e ) { desc = ""; } String defValue; try { defValue = aParam.getParameterDefault( keys[idx] ); } catch ( UnknownParamException e ) { defValue = ""; } String value; try { value = aParam.getParameterValue( keys[idx] ); } catch ( UnknownParamException e ) { value = ""; } try { addParameterDefinition( keys[idx], defValue, desc ); } catch ( DuplicateParamException e ) { } setParameterValue( keys[idx], value ); } } } NamedParamsDefault(); @Override void addParameterDefinition( String key, String defValue, String description ); @Override String getParameterDescription( String key ); @Override String getParameterValue( String key ); @Override String getParameterDefault( String key ); @Override String[] listParameters(); @Override void setParameterValue( String key, String value ); @Override void eraseParameters(); @Override void clearParameters(); @Override void activateParameters(); @Override void copyParametersFrom( NamedParams aParam ); }### Answer:
@Test public void testCopyParametersFromNullChecks() throws Exception { namedParams.copyParametersFrom( null ); NamedParams namedParams2 = new NamedParamsDefault(); ( (NamedParamsDefault) namedParams ).params = null; namedParams.copyParametersFrom( namedParams2 ); }
@Test public void testCopyParametersFrom() throws Exception { NamedParams namedParams2 = new NamedParamsDefault(); namedParams2.addParameterDefinition( "key", "default value", "description" ); namedParams2.setParameterValue( "key", "value" ); assertNull( namedParams.getParameterValue( "key" ) ); namedParams.copyParametersFrom( namedParams2 ); assertEquals( "value", namedParams.getParameterValue( "key" ) ); } |
### Question:
PDIClassLoader extends URLClassLoader { @Override protected synchronized Class<?> loadClass( String name, boolean resolve ) throws ClassNotFoundException { try { return super.loadClass( name, resolve ); } catch ( NoClassDefFoundError e ) { return super.findClass( name ); } } PDIClassLoader( URL[] url, ClassLoader parent ); PDIClassLoader( ClassLoader parent ); }### Answer:
@Test public void testLoadClass() throws Exception { final String classToLoad = "dummy.Class"; final AtomicBoolean loadClassCalled = new AtomicBoolean(); ClassLoader parent = new ClassLoader() { @Override protected Class<?> loadClass( String name, boolean resolve ) throws ClassNotFoundException { if ( name.equals( classToLoad ) && !resolve ) { loadClassCalled.set( true ); } throw new NoClassDefFoundError(); } }; PDIClassLoader cl = new PDIClassLoader( parent ); try { cl.loadClass( classToLoad, true ); fail( "This class doesn't exist" ); } catch ( ClassNotFoundException cnfe ) { assertTrue( loadClassCalled.get() ); } } |
### Question:
LongHashIndex { public Long get( long key ) throws KettleValueException { int hashCode = generateHashCode( key ); int indexPointer = indexFor( hashCode, index.length ); LongHashIndexEntry check = index[indexPointer]; while ( check != null ) { if ( check.hashCode == hashCode && check.equalsKey( key ) ) { return check.value; } check = check.nextEntry; } return null; } LongHashIndex( int size ); LongHashIndex(); int getSize(); boolean isEmpty(); Long get( long key ); void put( long key, Long value ); static int generateHashCode( Long key ); static int indexFor( int hash, int length ); }### Answer:
@Test public void testGet() throws KettleValueException { LongHashIndex index = new LongHashIndex(); index.put( 1L, 1L ); assertThat( "Element has uncorrect value.", index.get( 1L ), equalTo( 1L ) ); } |
### Question:
LongHashIndex { public boolean isEmpty() { return size == 0; } LongHashIndex( int size ); LongHashIndex(); int getSize(); boolean isEmpty(); Long get( long key ); void put( long key, Long value ); static int generateHashCode( Long key ); static int indexFor( int hash, int length ); }### Answer:
@Test public void testIsEmpty() throws KettleValueException { LongHashIndex index = new LongHashIndex(); assertThat( "Empty index should return true.", index.isEmpty(), is( true ) ); index.put( 1L, 1L ); assertThat( "Not empty index should return false.", index.isEmpty(), is( false ) ); }
@Test public void testIsEmpty() throws HopValueException { LongHashIndex index = new LongHashIndex(); assertThat( "Empty index should return true.", index.isEmpty(), is( true ) ); index.put( 1L, 1L ); assertThat( "Not empty index should return false.", index.isEmpty(), is( false ) ); } |
### Question:
ByteArrayHashIndex { public int getSize() { return size; } ByteArrayHashIndex( RowMetaInterface keyRowMeta, int size ); ByteArrayHashIndex( RowMetaInterface keyRowMeta ); int getSize(); boolean isEmpty(); byte[] get( byte[] key ); void put( byte[] key, byte[] value ); static int generateHashCode( byte[] key, RowMetaInterface rowMeta ); }### Answer:
@Test public void testArraySizeConstructor() { ByteArrayHashIndex obj = new ByteArrayHashIndex( new RowMeta(), 1 ); assertEquals( 1, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 2 ); assertEquals( 2, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 3 ); assertEquals( 4, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 12 ); assertEquals( 16, obj.getSize() ); obj = new ByteArrayHashIndex( new RowMeta(), 99 ); assertEquals( 128, obj.getSize() ); } |
### Question:
Variables implements VariableSpace { @Override public void initializeVariablesFrom( VariableSpace parent ) { this.parent = parent; Set<String> systemPropertiesNames = System.getProperties().stringPropertyNames(); for ( String key : systemPropertiesNames ) { getProperties().put( key, System.getProperties().getProperty( key ) ); } if ( parent != null ) { copyVariablesFrom( parent ); } if ( injection != null ) { properties.putAll( injection ); injection = null; } initialized = true; } Variables(); @Override void copyVariablesFrom( VariableSpace space ); @Override VariableSpace getParentVariableSpace(); @Override void setParentVariableSpace( VariableSpace parent ); @Override String getVariable( String variableName, String defaultValue ); @Override String getVariable( String variableName ); @Override boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ); @Override void initializeVariablesFrom( VariableSpace parent ); @Override String[] listVariables(); @Override void setVariable( String variableName, String variableValue ); @Override String environmentSubstitute( String aString ); @Override String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ); @Override String[] environmentSubstitute( String[] string ); @Override void shareVariablesWith( VariableSpace space ); @Override void injectVariables( Map<String, String> prop ); static synchronized VariableSpace getADefaultVariableSpace(); }### Answer:
@Test public void testinItializeVariablesFrom() { final Variables variablesMock = mock( Variables.class ); doCallRealMethod().when( variablesMock ).initializeVariablesFrom( any( VariableSpace.class ) ); @SuppressWarnings( "unchecked" ) final Map<String, String> propertiesMock = mock( Map.class ); when( variablesMock.getProperties() ).thenReturn( propertiesMock ); doAnswer( new Answer<Map<String, String>>() { final String keyStub = "key"; @Override public Map<String, String> answer( InvocationOnMock invocation ) throws Throwable { if ( System.getProperty( keyStub ) == null ) { modifySystemproperties(); } if ( invocation.getArguments()[ 1 ] != null ) { propertiesMock.put( (String) invocation.getArguments()[ 0 ], System.getProperties().getProperty( (String) invocation.getArguments()[ 1 ] ) ); } return propertiesMock; } } ).when( propertiesMock ).put( anyString(), anyString() ); variablesMock.initializeVariablesFrom( null ); } |
### Question:
Variables implements VariableSpace { @Override public String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ) throws KettleValueException { if ( aString == null || aString.length() == 0 ) { return aString; } return StringUtil.substituteField( aString, rowMeta, rowData ); } Variables(); @Override void copyVariablesFrom( VariableSpace space ); @Override VariableSpace getParentVariableSpace(); @Override void setParentVariableSpace( VariableSpace parent ); @Override String getVariable( String variableName, String defaultValue ); @Override String getVariable( String variableName ); @Override boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ); @Override void initializeVariablesFrom( VariableSpace parent ); @Override String[] listVariables(); @Override void setVariable( String variableName, String variableValue ); @Override String environmentSubstitute( String aString ); @Override String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ); @Override String[] environmentSubstitute( String[] string ); @Override void shareVariablesWith( VariableSpace space ); @Override void injectVariables( Map<String, String> prop ); static synchronized VariableSpace getADefaultVariableSpace(); }### Answer:
@Test public void testFieldSubstitution() throws KettleValueException { Object[] rowData = new Object[]{ "DataOne", "DataTwo" }; RowMeta rm = new RowMeta(); rm.addValueMeta( new ValueMetaString( "FieldOne" ) ); rm.addValueMeta( new ValueMetaString( "FieldTwo" ) ); Variables vars = new Variables(); assertNull( vars.fieldSubstitute( null, rm, rowData ) ); assertEquals( "", vars.fieldSubstitute( "", rm, rowData ) ); assertEquals( "DataOne", vars.fieldSubstitute( "?{FieldOne}", rm, rowData ) ); assertEquals( "TheDataOne", vars.fieldSubstitute( "The?{FieldOne}", rm, rowData ) ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void setDeckChildIndex() { getControls(); int originalSelection = ( dialogDeck == null ? -1 : dialogDeck.getSelectedIndex() ); boolean passed = true; if ( originalSelection == 3 ) { passed = checkPoolingParameters(); } if ( passed ) { int selected = deckOptionsBox.getSelectedIndex(); if ( selected < 0 ) { selected = 0; deckOptionsBox.setSelectedIndex( 0 ); } dialogDeck.setSelectedIndex( selected ); } else { dialogDeck.setSelectedIndex( originalSelection ); deckOptionsBox.setSelectedIndex( originalSelection ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testSetDeckChildIndex() throws Exception { } |
### Question:
Variables implements VariableSpace { @Override public String environmentSubstitute( String aString ) { if ( aString == null || aString.length() == 0 ) { return aString; } return StringUtil.environmentSubstitute( aString, properties ); } Variables(); @Override void copyVariablesFrom( VariableSpace space ); @Override VariableSpace getParentVariableSpace(); @Override void setParentVariableSpace( VariableSpace parent ); @Override String getVariable( String variableName, String defaultValue ); @Override String getVariable( String variableName ); @Override boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ); @Override void initializeVariablesFrom( VariableSpace parent ); @Override String[] listVariables(); @Override void setVariable( String variableName, String variableValue ); @Override String environmentSubstitute( String aString ); @Override String fieldSubstitute( String aString, RowMetaInterface rowMeta, Object[] rowData ); @Override String[] environmentSubstitute( String[] string ); @Override void shareVariablesWith( VariableSpace space ); @Override void injectVariables( Map<String, String> prop ); static synchronized VariableSpace getADefaultVariableSpace(); }### Answer:
@Test public void testEnvironmentSubstitute() { Variables vars = new Variables(); vars.setVariable( "VarOne", "DataOne" ); vars.setVariable( "VarTwo", "DataTwo" ); assertNull( vars.environmentSubstitute( (String) null ) ); assertEquals( "", vars.environmentSubstitute( "" ) ); assertEquals( "DataTwo", vars.environmentSubstitute( "${VarTwo}" ) ); assertEquals( "DataTwoEnd", vars.environmentSubstitute( "${VarTwo}End" ) ); assertEquals( 0, vars.environmentSubstitute( new String[0] ).length ); assertArrayEquals( new String[]{ "DataOne", "TheDataOne" }, vars.environmentSubstitute( new String[]{ "${VarOne}", "The${VarOne}" } ) ); } |
### Question:
LifecycleException extends Exception { public boolean isSevere() { return severe; } LifecycleException( boolean severe ); LifecycleException( String message, boolean severe ); LifecycleException( Throwable cause, boolean severe ); LifecycleException( String message, Throwable cause, boolean severe ); boolean isSevere(); }### Answer:
@Test public void testIsSevere() throws Exception { assertTrue( exception.isSevere() ); }
@Test public void testThrowableMessageCtor() { Throwable t = mock( Throwable.class ); exception = new LifecycleException( "message", t, true ); assertEquals( t, exception.getCause() ); assertEquals( "message", exception.getMessage() ); assertTrue( exception.isSevere() ); } |
### Question:
LifeEventInfo { public State getState() { return state; } void setHint( Hint hint ); String getMessage(); void setMessage( String message ); boolean hasHint( Hint h ); State getState(); void setState( State state ); String getName(); void setName( String name ); }### Answer:
@Test public void testGetState() throws Exception { assertNull( info.getState() ); info.setState( LifeEventInfo.State.FAIL ); assertEquals( LifeEventInfo.State.FAIL, info.getState() ); } |
### Question:
LifeEventInfo { public String getName() { return name; } void setHint( Hint hint ); String getMessage(); void setMessage( String message ); boolean hasHint( Hint h ); State getState(); void setState( State state ); String getName(); void setName( String name ); }### Answer:
@Test public void testGetName() throws Exception { assertNull( info.getName() ); info.setName( "name" ); assertEquals( "name", info.getName() ); } |
### Question:
ResultFile implements Cloneable { public RowMetaAndData getRow() { RowMetaAndData row = new RowMetaAndData(); row.addValue( new ValueMetaString( "type" ), getTypeDesc() ); row.addValue( new ValueMetaString( "filename" ), file.getName().getBaseName() ); row.addValue( new ValueMetaString( "path" ), file.getName().getURI() ); row.addValue( new ValueMetaString( "parentorigin" ), originParent ); row.addValue( new ValueMetaString( "origin" ), origin ); row.addValue( new ValueMetaString( "comment" ), comment ); row.addValue( new ValueMetaDate( "timestamp" ), timestamp ); return row; } ResultFile( int type, FileObject file, String originParent, String origin ); ResultFile( Node node ); @Override String toString(); String getComment(); void setComment( String comment ); FileObject getFile(); void setFile( FileObject file ); String getOrigin(); void setOrigin( String origin ); String getOriginParent(); void setOriginParent( String originParent ); int getType(); void setType( int type ); String getTypeDesc(); String getTypeCode(); static final int getType( String typeString ); static final String getTypeCode( int fileType ); static final String getTypeDesc( int fileType ); static final String[] getAllTypeDesc(); Date getTimestamp(); void setTimestamp( Date timestamp ); RowMetaAndData getRow(); String getXML(); static final int FILE_TYPE_GENERAL; static final int FILE_TYPE_LOG; static final int FILE_TYPE_ERRORLINE; static final int FILE_TYPE_ERROR; static final int FILE_TYPE_WARNING; static final String[] fileTypeCode; static final String[] fileTypeDesc; }### Answer:
@Test public void testGetRow() throws KettleFileException, FileSystemException { File tempDir = new File( new TemporaryFolder().toString() ); FileObject tempFile = KettleVFS.createTempFile( "prefix", "suffix", tempDir.toString() ); Date timeBeforeFile = Calendar.getInstance().getTime(); ResultFile resultFile = new ResultFile( ResultFile.FILE_TYPE_GENERAL, tempFile, "myOriginParent", "myOrigin" ); Date timeAfterFile = Calendar.getInstance().getTime(); assertNotNull( resultFile ); RowMetaInterface rm = resultFile.getRow().getRowMeta(); assertEquals( 7, rm.getValueMetaList().size() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 0 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 1 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 2 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 3 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 4 ).getType() ); assertEquals( ValueMetaInterface.TYPE_STRING, rm.getValueMeta( 5 ).getType() ); assertEquals( ValueMetaInterface.TYPE_DATE, rm.getValueMeta( 6 ).getType() ); assertEquals( ResultFile.FILE_TYPE_GENERAL, resultFile.getType() ); assertEquals( "myOrigin", resultFile.getOrigin() ); assertEquals( "myOriginParent", resultFile.getOriginParent() ); assertTrue( "ResultFile timestamp is created in the expected window", timeBeforeFile.compareTo( resultFile.getTimestamp() ) <= 0 && timeAfterFile.compareTo( resultFile.getTimestamp() ) >= 0 ); tempFile.delete(); tempDir.delete(); } |
### Question:
SlaveConnectionManager { public static SlaveConnectionManager getInstance() { if ( slaveConnectionManager == null ) { slaveConnectionManager = new SlaveConnectionManager(); } return slaveConnectionManager; } private SlaveConnectionManager(); static SlaveConnectionManager getInstance(); HttpClient createHttpClient(); HttpClient createHttpClient( String user, String password ); HttpClient createHttpClient( String user, String password,
String proxyHost, int proxyPort, AuthScope authScope ); void shutdown(); }### Answer:
@Test public void shouldOverrideDefaultSSLContextByDefault() throws Exception { System.clearProperty( "javax.net.ssl.keyStore" ); SlaveConnectionManager instance = SlaveConnectionManager.getInstance(); assertNotEquals( defaultContext, SSLContext.getDefault() ); }
@Test public void shouldNotOverrideDefaultSSLContextIfKeystoreIsSet() throws Exception { System.setProperty( "javax.net.ssl.keyStore", "NONE" ); SlaveConnectionManager instance = SlaveConnectionManager.getInstance(); assertEquals( defaultContext, SSLContext.getDefault() ); } |
### Question:
HttpUtil { public static String decodeBase64ZippedString( String loggingString64 ) throws IOException { if ( loggingString64 == null || loggingString64.isEmpty() ) { return ""; } StringWriter writer = new StringWriter(); byte[] bytes64 = Base64.decodeBase64( loggingString64.getBytes() ); ByteArrayInputStream zip = new ByteArrayInputStream( bytes64 ); GZIPInputStream unzip = null; InputStreamReader reader = null; BufferedInputStream in = null; try { unzip = new GZIPInputStream( zip, HttpUtil.ZIP_BUFFER_SIZE ); in = new BufferedInputStream( unzip, HttpUtil.ZIP_BUFFER_SIZE ); reader = new InputStreamReader( in, Const.XML_ENCODING ); writer = new StringWriter(); char[] buff = new char[ HttpUtil.ZIP_BUFFER_SIZE ]; for ( int length = 0; ( length = reader.read( buff ) ) > 0; ) { writer.write( buff, 0, length ); } } finally { if ( reader != null ) { try { reader.close(); } catch ( IOException e ) { } } if ( in != null ) { try { in.close(); } catch ( IOException e ) { } } if ( unzip != null ) { try { unzip.close(); } catch ( IOException e ) { } } } return writer.toString(); } static String constructUrl( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments ); static String constructUrl( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments, boolean isSecure ); static String getPortSpecification( VariableSpace space, String port ); static String decodeBase64ZippedString( String loggingString64 ); static String encodeBase64ZippedString( String in ); static final int ZIP_BUFFER_SIZE; }### Answer:
@Test public final void testDecodeBase64ZippedString() throws IOException, NoSuchAlgorithmException { String enc64 = this.canonicalBase64Encode( STANDART ); String decoded = HttpUtil.decodeBase64ZippedString( enc64 ); Assert.assertEquals( "Strings are the same after transformation", STANDART, decoded ); } |
### Question:
HttpUtil { public static String constructUrl( VariableSpace space, String hostname, String port, String webAppName, String serviceAndArguments ) throws UnsupportedEncodingException { return constructUrl( space, hostname, port, webAppName, serviceAndArguments, false ); } static String constructUrl( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments ); static String constructUrl( VariableSpace space, String hostname, String port, String webAppName,
String serviceAndArguments, boolean isSecure ); static String getPortSpecification( VariableSpace space, String port ); static String decodeBase64ZippedString( String loggingString64 ); static String encodeBase64ZippedString( String in ); static final int ZIP_BUFFER_SIZE; }### Answer:
@Test public void testConstructUrl() throws Exception { Variables variables = new Variables(); String expected = "hostname:1234/webAppName?param=value"; Assert.assertEquals( "http: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value" ) ); Assert.assertEquals( "http: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value", false ) ); Assert.assertEquals( "https: HttpUtil.constructUrl( variables, "hostname", String.valueOf( 1234 ), "webAppName", "?param=value", true ) ); } |
### Question:
ZipFileMeta extends BaseStepMeta implements StepMetaInterface { public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException { readData( stepnode ); } ZipFileMeta(); String getDynamicSourceFileNameField(); void setDynamicSourceFileNameField( String sourcefilenamefield ); String getBaseFolderField(); void setBaseFolderField( String baseFolderField ); String getMoveToFolderField(); void setMoveToFolderField( String movetofolderfield ); String getDynamicTargetFileNameField(); void setDynamicTargetFileNameField( String targetfilenamefield ); boolean isaddTargetFileNametoResult(); boolean isOverwriteZipEntry(); boolean isCreateParentFolder(); boolean isKeepSouceFolder(); void setKeepSouceFolder( boolean value ); void setaddTargetFileNametoResult( boolean addresultfilenames ); void setOverwriteZipEntry( boolean overwritezipentry ); void setCreateParentFolder( boolean createparentfolder ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); int getOperationType(); static int getOperationTypeByDesc( String tt ); void setOperationType( int operationType ); static String getOperationTypeDesc( int i ); static final String[] operationTypeDesc; static final String[] operationTypeCode; static final int OPERATION_TYPE_NOTHING; static final int OPERATION_TYPE_MOVE; static final int OPERATION_TYPE_DELETE; }### Answer:
@Test public void testLoadAndGetXml() throws Exception { ZipFileMeta zipFileMeta = new ZipFileMeta(); Node stepnode = getTestNode(); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); IMetaStore metaStore = mock( IMetaStore.class ); StepMeta mockParentStepMeta = mock( StepMeta.class ); zipFileMeta.setParentStepMeta( mockParentStepMeta ); TransMeta mockTransMeta = mock( TransMeta.class ); NamedClusterEmbedManager embedManager = mock( NamedClusterEmbedManager.class ); when( mockParentStepMeta.getParentTransMeta() ).thenReturn( mockTransMeta ); when( mockTransMeta.getNamedClusterEmbedManager() ).thenReturn( embedManager ); zipFileMeta.loadXML( stepnode, Collections.singletonList( dbMeta ), metaStore ); assertXmlOutputMeta( zipFileMeta ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void onPoolingCheck() { if ( poolingCheck != null ) { boolean dis = !poolingCheck.isChecked(); if ( poolSizeBox != null ) { poolSizeBox.setDisabled( dis ); } if ( maxPoolSizeBox != null ) { maxPoolSizeBox.setDisabled( dis ); } if ( poolSizeLabel != null ) { poolSizeLabel.setDisabled( dis ); } if ( maxPoolSizeLabel != null ) { maxPoolSizeLabel.setDisabled( dis ); } if ( poolParameterTree != null ) { poolParameterTree.setDisabled( dis ); } if ( poolingParameterDescriptionLabel != null ) { poolingParameterDescriptionLabel.setDisabled( dis ); } if ( poolingDescriptionLabel != null ) { poolingDescriptionLabel.setDisabled( dis ); } if ( poolingDescription != null ) { poolingDescription.setDisabled( dis ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testOnPoolingCheck() throws Exception { } |
### Question:
ZipFileMeta extends BaseStepMeta implements StepMetaInterface { public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta, Trans trans ) { return new ZipFile( stepMeta, stepDataInterface, cnr, transMeta, trans ); } ZipFileMeta(); String getDynamicSourceFileNameField(); void setDynamicSourceFileNameField( String sourcefilenamefield ); String getBaseFolderField(); void setBaseFolderField( String baseFolderField ); String getMoveToFolderField(); void setMoveToFolderField( String movetofolderfield ); String getDynamicTargetFileNameField(); void setDynamicTargetFileNameField( String targetfilenamefield ); boolean isaddTargetFileNametoResult(); boolean isOverwriteZipEntry(); boolean isCreateParentFolder(); boolean isKeepSouceFolder(); void setKeepSouceFolder( boolean value ); void setaddTargetFileNametoResult( boolean addresultfilenames ); void setOverwriteZipEntry( boolean overwritezipentry ); void setCreateParentFolder( boolean createparentfolder ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); int getOperationType(); static int getOperationTypeByDesc( String tt ); void setOperationType( int operationType ); static String getOperationTypeDesc( int i ); static final String[] operationTypeDesc; static final String[] operationTypeCode; static final int OPERATION_TYPE_NOTHING; static final int OPERATION_TYPE_MOVE; static final int OPERATION_TYPE_DELETE; }### Answer:
@Test public void testGetStep() throws Exception { StepMeta stepInfo = mock( StepMeta.class ); when( stepInfo.getName() ).thenReturn( "Zip Step Name" ); StepDataInterface stepData = mock( StepDataInterface.class ); TransMeta transMeta = mock( TransMeta.class ); when( transMeta.findStep( "Zip Step Name" ) ).thenReturn( stepInfo ); Trans trans = mock( Trans.class ); ZipFileMeta zipFileMeta = new ZipFileMeta(); ZipFile zipFile = (ZipFile) zipFileMeta.getStep( stepInfo, stepData, 0, transMeta, trans ); assertEquals( stepInfo, zipFile.getStepMeta() ); assertEquals( stepData, zipFile.getStepDataInterface() ); assertEquals( transMeta, zipFile.getTransMeta() ); assertEquals( trans, zipFile.getTrans() ); assertEquals( 0, zipFile.getCopy() ); } |
### Question:
TextFileOutput extends BaseStep implements StepInterface { protected boolean closeFile() { boolean retval = false; try { if ( data.writer != null ) { data.writer.flush(); if ( data.cmdProc != null ) { if ( log.isDebug() ) { logDebug( "Closing output stream" ); } data.writer.close(); if ( log.isDebug() ) { logDebug( "Closed output stream" ); } } } data.writer = null; if ( data.cmdProc != null ) { if ( log.isDebug() ) { logDebug( "Ending running external command" ); } int procStatus = data.cmdProc.waitFor(); try { data.cmdProc.getErrorStream().close(); data.cmdProc.getOutputStream().flush(); data.cmdProc.getOutputStream().close(); data.cmdProc.getInputStream().close(); } catch ( IOException e ) { if ( log.isDetailed() ) { logDetailed( "Warning: Error closing streams: " + e.getMessage() ); } } data.cmdProc = null; if ( log.isBasic() && procStatus != 0 ) { logBasic( "Command exit status: " + procStatus ); } } else { if ( log.isDebug() ) { logDebug( "Closing normal file ..." ); } if ( data.out != null ) { data.out.close(); } if ( data.fos != null ) { data.fos.close(); data.fos = null; } } retval = true; } catch ( Exception e ) { logError( "Exception trying to close file: " + e.toString() ); setErrors( 1 ); retval = false; } return retval; } TextFileOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void writeRowToFile( RowMetaInterface rowMeta, Object[] r ); String buildFilename( String filename, boolean ziparchive ); void openNewFile( String baseFilename ); boolean checkPreviouslyOpened( String filename ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); boolean containsSeparatorOrEnclosure( byte[] source, byte[] separator, byte[] enclosure ); public TextFileOutputMeta meta; public TextFileOutputData data; }### Answer:
@Test public void testCloseFileDataOutIsNullCase() { textFileOutput = new TextFileOutput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); textFileOutput.data = Mockito.mock( TextFileOutputData.class ); Assert.assertNull( textFileOutput.data.out ); textFileOutput.closeFile(); }
@Test public void testCloseFileDataOutIsNotNullCase() throws IOException { textFileOutput = new TextFileOutput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); textFileOutput.data = Mockito.mock( TextFileOutputData.class ); textFileOutput.data.out = Mockito.mock( CompressionOutputStream.class ); textFileOutput.closeFile(); Mockito.verify( textFileOutput.data.out, Mockito.times( 1 ) ).close(); } |
### Question:
TextFileOutput extends BaseStep implements StepInterface { public void writeRowToFile( RowMetaInterface rowMeta, Object[] r ) throws KettleStepException { try { if ( meta.getOutputFields() == null || meta.getOutputFields().length == 0 ) { for ( int i = 0; i < rowMeta.size(); i++ ) { if ( i > 0 && data.binarySeparator.length > 0 ) { data.writer.write( data.binarySeparator ); } ValueMetaInterface v = rowMeta.getValueMeta( i ); Object valueData = r[i]; writeField( v, valueData, null ); } data.writer.write( data.binaryNewline ); } else { for ( int i = 0; i < meta.getOutputFields().length; i++ ) { if ( i > 0 && data.binarySeparator.length > 0 ) { data.writer.write( data.binarySeparator ); } ValueMetaInterface v = rowMeta.getValueMeta( data.fieldnrs[i] ); Object valueData = r[data.fieldnrs[i]]; writeField( v, valueData, data.binaryNullValue[i] ); } data.writer.write( data.binaryNewline ); } incrementLinesOutput(); } catch ( Exception e ) { throw new KettleStepException( "Error writing line", e ); } } TextFileOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void writeRowToFile( RowMetaInterface rowMeta, Object[] r ); String buildFilename( String filename, boolean ziparchive ); void openNewFile( String baseFilename ); boolean checkPreviouslyOpened( String filename ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); boolean containsSeparatorOrEnclosure( byte[] source, byte[] separator, byte[] enclosure ); public TextFileOutputMeta meta; public TextFileOutputData data; }### Answer:
@Test public void testFastDumpDisableStreamEncodeTest() throws Exception { textFileOutput = new TextFileOutputTestHandler( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); textFileOutput.meta = stepMockHelper.processRowsStepMetaInterface; String testString = "ÖÜä"; String inputEncode = "UTF-8"; String outputEncode = "Windows-1252"; Object[] rows = {testString.getBytes( inputEncode )}; ValueMetaBase valueMetaInterface = new ValueMetaBase( "test", ValueMetaInterface.TYPE_STRING ); valueMetaInterface.setStringEncoding( inputEncode ); valueMetaInterface.setStorageType( ValueMetaInterface.STORAGE_TYPE_BINARY_STRING ); valueMetaInterface.setStorageMetadata( new ValueMetaString() ); TextFileOutputData data = new TextFileOutputData(); data.binarySeparator = " ".getBytes(); data.binaryEnclosure = "\"".getBytes(); data.binaryNewline = "\n".getBytes(); textFileOutput.data = data; RowMeta rowMeta = new RowMeta(); rowMeta.addValueMeta( valueMetaInterface ); Mockito.doReturn( outputEncode ).when( stepMockHelper.processRowsStepMetaInterface ).getEncoding(); textFileOutput.data.writer = Mockito.mock( BufferedOutputStream.class ); textFileOutput.writeRowToFile( rowMeta, rows ); Mockito.verify( textFileOutput.data.writer, Mockito.times( 1 ) ).write( testString.getBytes( outputEncode ) ); } |
### Question:
Rest extends BaseStep implements StepInterface { MultivaluedMapImpl createMultivalueMap( String paramName, String paramValue ) { MultivaluedMapImpl queryParams = new MultivaluedMapImpl(); queryParams.add( paramName, UriComponent.encode( paramValue, UriComponent.Type.QUERY_PARAM ) ); return queryParams; } Rest( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testCreateMultivalueMap() { StepMeta stepMeta = new StepMeta(); stepMeta.setName( "TestRest" ); TransMeta transMeta = new TransMeta(); transMeta.setName( "TestRest" ); transMeta.addStep( stepMeta ); Rest rest = new Rest( stepMeta, Mockito.mock( StepDataInterface.class ), 1, transMeta, Mockito.mock( Trans.class ) ); MultivaluedMapImpl map = rest.createMultivalueMap( "param1", "{a:{[val1]}}" ); String val1 = map.getFirst( "param1" ); Assert.assertTrue( val1.contains( "%7D" ) ); } |
### Question:
JoinRows extends BaseStep implements StepInterface { public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { meta = (JoinRowsMeta) smi; data = (JoinRowsData) sdi; if ( data.file != null ) { for ( int i = 1; i < data.file.length; i++ ) { if ( data.file[i] != null ) { data.file[i].delete(); } } } super.dispose( meta, data ); } JoinRows( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); @SuppressWarnings( "unchecked" ) void initialize(); Object[] getRowData( int filenr ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); @Override void batchComplete(); }### Answer:
@Test public void checkThatMethodPerformedWithoutError() throws Exception { getJoinRows().dispose( meta, data ); }
@Test public void disposeDataFiles() throws Exception { File mockFile1 = mock( File.class ); File mockFile2 = mock( File.class ); data.file = new File[] {null, mockFile1, mockFile2}; getJoinRows().dispose( meta, data ); verify( mockFile1, times( 1 ) ).delete(); verify( mockFile2, times( 1 ) ).delete(); } |
### Question:
JoinRows extends BaseStep implements StepInterface { public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { meta = (JoinRowsMeta) smi; data = (JoinRowsData) sdi; if ( first ) { first = false; initialize(); } if ( data.caching ) { if ( !cacheInputRow() ) { return false; } } else { if ( !outputRow() ) { return false; } } return true; } JoinRows( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); @SuppressWarnings( "unchecked" ) void initialize(); Object[] getRowData( int filenr ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); @Override void batchComplete(); }### Answer:
@Test public void testJoinRowsStep() throws Exception { JoinRowsMeta joinRowsMeta = new JoinRowsMeta(); joinRowsMeta.setMainStepname( "main step name" ); joinRowsMeta.setPrefix( "out" ); joinRowsMeta.setCacheSize( 3 ); JoinRowsData joinRowsData = new JoinRowsData(); JoinRows joinRows = getJoinRows(); joinRows.getTrans().setRunning( true ); joinRows.init( joinRowsMeta, joinRowsData ); List<RowSet> rowSets = new ArrayList<>(); rowSets.add( getRowSetWithData( 3, "main --", true ) ); rowSets.add( getRowSetWithData( 3, "secondary --", false ) ); joinRows.setInputRowSets( rowSets ); RowStepCollector rowStepCollector = new RowStepCollector(); joinRows.addRowListener( rowStepCollector ); joinRows.getLogChannel().setLogLevel( LogLevel.ROWLEVEL ); KettleLogStore.init(); while ( true ) { if ( !joinRows.processRow( joinRowsMeta, joinRowsData ) ) { break; } } rowStepCollector.getRowsWritten(); assertEquals( 9, rowStepCollector.getRowsWritten().size() ); assertEquals( 6, rowStepCollector.getRowsRead().size() ); Object[][] expectedResult = createExpectedResult(); List<Object[]> rowWritten = rowStepCollector.getRowsWritten().stream().map( RowMetaAndData::getData ).collect( Collectors.toList() ); for ( int i = 0; i < 9; i++ ) { assertTrue( Arrays.equals( expectedResult[i], rowWritten.get( i ) ) ); } } |
### Question:
DataHandler extends AbstractXulEventHandler { public void onClusterCheck() { if ( clusteringCheck != null ) { boolean dis = !clusteringCheck.isChecked(); if ( clusterParameterTree != null ) { clusterParameterTree.setDisabled( dis ); } if ( clusterParameterDescriptionLabel != null ) { clusterParameterDescriptionLabel.setDisabled( dis ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testOnClusterCheck() throws Exception { } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public void setSelectName( String[] selectName ) { resizeSelectFields( selectName.length ); for ( int i = 0; i < selectFields.length; i++ ) { selectFields[i].setName( selectName[i] ); } } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void setSelectName() { selectValuesMeta.setSelectName( new String[] { FIRST_FIELD, SECOND_FIELD } ); assertArrayEquals( new String[] { FIRST_FIELD, SECOND_FIELD }, selectValuesMeta.getSelectName() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public String[] getSelectName() { String[] selectName = new String[selectFields.length]; for ( int i = 0; i < selectName.length; i++ ) { selectName[i] = selectFields[i].getName(); } return selectName; } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void getSelectName() { assertArrayEquals( new String[0], selectValuesMeta.getSelectName() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public void setSelectRename( String[] selectRename ) { if ( selectRename.length > selectFields.length ) { resizeSelectFields( selectRename.length ); } for ( int i = 0; i < selectFields.length; i++ ) { if ( i < selectRename.length ) { selectFields[i].setRename( selectRename[i] ); } else { selectFields[i].setRename( null ); } } } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void setSelectRename() { selectValuesMeta.setSelectRename( new String[] { FIRST_FIELD, SECOND_FIELD } ); assertArrayEquals( new String[] { FIRST_FIELD, SECOND_FIELD }, selectValuesMeta.getSelectRename() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public String[] getSelectRename() { String[] selectRename = new String[selectFields.length]; for ( int i = 0; i < selectRename.length; i++ ) { selectRename[i] = selectFields[i].getRename(); } return selectRename; } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void getSelectRename() { assertArrayEquals( new String[0], selectValuesMeta.getSelectRename() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public void setSelectLength( int[] selectLength ) { if ( selectLength.length > selectFields.length ) { resizeSelectFields( selectLength.length ); } for ( int i = 0; i < selectFields.length; i++ ) { if ( i < selectLength.length ) { selectFields[i].setLength( selectLength[i] ); } else { selectFields[i].setLength( UNDEFINED ); } } } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void setSelectLength() { selectValuesMeta.setSelectLength( new int[] { 1, 2 } ); assertArrayEquals( new int[] { 1, 2 }, selectValuesMeta.getSelectLength() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public int[] getSelectLength() { int[] selectLength = new int[selectFields.length]; for ( int i = 0; i < selectLength.length; i++ ) { selectLength[i] = selectFields[i].getLength(); } return selectLength; } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void getSelectLength() { assertArrayEquals( new int[0], selectValuesMeta.getSelectLength() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public void setSelectPrecision( int[] selectPrecision ) { if ( selectPrecision.length > selectFields.length ) { resizeSelectFields( selectPrecision.length ); } for ( int i = 0; i < selectFields.length; i++ ) { if ( i < selectPrecision.length ) { selectFields[i].setPrecision( selectPrecision[i] ); } else { selectFields[i].setPrecision( UNDEFINED ); } } } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void setSelectPrecision() { selectValuesMeta.setSelectPrecision( new int[] { 1, 2 } ); assertArrayEquals( new int[] { 1, 2 }, selectValuesMeta.getSelectPrecision() ); } |
### Question:
SelectValuesMeta extends BaseStepMeta implements StepMetaInterface { public int[] getSelectPrecision() { int[] selectPrecision = new int[selectFields.length]; for ( int i = 0; i < selectPrecision.length; i++ ) { selectPrecision[i] = selectFields[i].getPrecision(); } return selectPrecision; } SelectValuesMeta(); String[] getDeleteName(); void setDeleteName( String[] deleteName ); void setSelectName( String[] selectName ); String[] getSelectName(); void setSelectRename( String[] selectRename ); String[] getSelectRename(); void setSelectLength( int[] selectLength ); int[] getSelectLength(); void setSelectPrecision( int[] selectPrecision ); int[] getSelectPrecision(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrFields, int nrRemove, int nrMeta ); @Override Object clone(); @Override void setDefault(); void getSelectFields( RowMetaInterface inputRowMeta, String name ); void getDeleteFields( RowMetaInterface inputRowMeta ); @Deprecated void getMetadataFields( RowMetaInterface inputRowMeta, String name ); void getMetadataFields( RowMetaInterface inputRowMeta, String name, VariableSpace space ); @Override void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); @Override StepDataInterface getStepData(); boolean isSelectingAndSortingUnspecifiedFields(); void setSelectingAndSortingUnspecifiedFields( boolean selectingAndSortingUnspecifiedFields ); SelectMetadataChange[] getMeta(); void setMeta( SelectMetadataChange[] meta ); @Override boolean supportsErrorHandling(); SelectField[] getSelectFields(); void setSelectFields( SelectField[] selectFields ); List<FieldnameLineage> getFieldnameLineage(); static final int UNDEFINED; }### Answer:
@Test public void getSelectPrecision() { assertArrayEquals( new int[0], selectValuesMeta.getSelectPrecision() ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void onCancel() { close(); } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testOnCancel() throws Exception { } |
### Question:
SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkRemoteFilenameField( String remoteFilenameFieldName, SFTPPutData data ) throws KettleStepException { remoteFilenameFieldName = environmentSubstitute( remoteFilenameFieldName ); if ( !Utils.isEmpty( remoteFilenameFieldName ) ) { data.indexOfRemoteFilename = getInputRowMeta().indexOfValue( remoteFilenameFieldName ); if ( data.indexOfRemoteFilename == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", remoteFilenameFieldName ) ); } } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void checkRemoteFilenameField_FieldNameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkRemoteFilenameField( "", data ); assertEquals( -1, data.indexOfSourceFileFieldName ); }
@Test( expected = KettleStepException.class ) public void checkRemoteFilenameField_FieldNameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkRemoteFilenameField( "remoteFileName", new SFTPPutData() ); }
@Test public void checkRemoteFilenameField_FieldNameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "remoteFileName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkRemoteFilenameField( "remoteFileName", data ); assertEquals( 1, data.indexOfRemoteFilename ); } |
### Question:
SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkSourceFileField( String sourceFilenameFieldName, SFTPPutData data ) throws KettleStepException { sourceFilenameFieldName = environmentSubstitute( sourceFilenameFieldName ); if ( Utils.isEmpty( sourceFilenameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.SourceFileNameFieldMissing" ) ); } data.indexOfSourceFileFieldName = getInputRowMeta().indexOfValue( sourceFilenameFieldName ); if ( data.indexOfSourceFileFieldName == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", sourceFilenameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test( expected = KettleStepException.class ) public void checkSourceFileField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkSourceFileField( "", data ); }
@Test( expected = KettleStepException.class ) public void checkSourceFileField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkSourceFileField( "sourceFile", new SFTPPutData() ); }
@Test public void checkSourceFileField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "sourceFileFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkSourceFileField( "sourceFileFieldName", data ); assertEquals( 1, data.indexOfSourceFileFieldName ); } |
### Question:
SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkRemoteFoldernameField( String remoteFoldernameFieldName, SFTPPutData data ) throws KettleStepException { remoteFoldernameFieldName = environmentSubstitute( remoteFoldernameFieldName ); if ( Utils.isEmpty( remoteFoldernameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.RemoteFolderNameFieldMissing" ) ); } data.indexOfRemoteDirectory = getInputRowMeta().indexOfValue( remoteFoldernameFieldName ); if ( data.indexOfRemoteDirectory == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", remoteFoldernameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test( expected = KettleStepException.class ) public void checkRemoteFoldernameField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkRemoteFoldernameField( "", data ); }
@Test( expected = KettleStepException.class ) public void checkRemoteFoldernameField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkRemoteFoldernameField( "remoteFolder", new SFTPPutData() ); }
@Test public void checkRemoteFoldernameField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "remoteFoldernameFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkRemoteFoldernameField( "remoteFoldernameFieldName", data ); assertEquals( 1, data.indexOfRemoteDirectory ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void onOK() { DatabaseMeta database = new DatabaseMeta(); this.getInfo( database ); boolean passed = checkPoolingParameters(); if ( !passed ) { return; } String[] remarks = database.checkParameters(); String message = ""; if ( remarks.length != 0 ) { for ( int i = 0; i < remarks.length; i++ ) { message = message.concat( "* " ).concat( remarks[i] ).concat( System.getProperty( "line.separator" ) ); } showMessage( message, false ); } else { if ( databaseMeta == null ) { databaseMeta = new DatabaseMeta(); } this.getInfo( databaseMeta ); databaseMeta.setChanged(); close(); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testOnOK() throws Exception { } |
### Question:
SFTPPut extends BaseStep implements StepInterface { @VisibleForTesting void checkDestinationFolderField( String realDestinationFoldernameFieldName, SFTPPutData data ) throws KettleStepException { realDestinationFoldernameFieldName = environmentSubstitute( realDestinationFoldernameFieldName ); if ( Utils.isEmpty( realDestinationFoldernameFieldName ) ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Log.DestinatFolderNameFieldNameMissing" ) ); } data.indexOfMoveToFolderFieldName = getInputRowMeta().indexOfValue( realDestinationFoldernameFieldName ); if ( data.indexOfMoveToFolderFieldName == -1 ) { throw new KettleStepException( BaseMessages.getString( PKG, "SFTPPut.Error.CanNotFindField", realDestinationFoldernameFieldName ) ); } } SFTPPut( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test( expected = KettleStepException.class ) public void checkDestinationFolderField_NameIsBlank() throws Exception { SFTPPutData data = new SFTPPutData(); step.checkDestinationFolderField( "", data ); }
@Test( expected = KettleStepException.class ) public void checkDestinationFolderField_NameIsSet_NotFound() throws Exception { step.setInputRowMeta( new RowMeta() ); step.checkDestinationFolderField( "destinationFolder", new SFTPPutData() ); }
@Test public void checkDestinationFolderField_NameIsSet_Found() throws Exception { RowMeta rowMeta = rowOfStringsMeta( "some field", "destinationFolderFieldName" ); step.setInputRowMeta( rowMeta ); SFTPPutData data = new SFTPPutData(); step.checkDestinationFolderField( "destinationFolderFieldName", data ); assertEquals( 1, data.indexOfMoveToFolderFieldName ); } |
### Question:
SystemDataMeta extends BaseStepMeta implements StepMetaInterface { @Override public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException { readData( stepnode ); } SystemDataMeta(); String[] getFieldName(); void setFieldName( String[] fieldName ); SystemDataTypes[] getFieldType(); void setFieldType( SystemDataTypes[] fieldType ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int count ); @Override Object clone(); static final SystemDataTypes getType( String type ); static final String getTypeDesc( SystemDataTypes t ); @Override void setDefault(); @Override void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); @Override Map<String, String> getUsedArguments(); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); @Override StepDataInterface getStepData(); @Override boolean equals( Object o ); @Override int hashCode(); }### Answer:
@Test public void testLoadXML() throws Exception { SystemDataMeta systemDataMeta = new SystemDataMeta(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse( new InputSource( new StringReader( expectedXML ) ) ); Node node = document; IMetaStore store = null; systemDataMeta.loadXML( node, null, store ); assertEquals( expectedSystemDataMeta, systemDataMeta ); } |
### Question:
SystemDataMeta extends BaseStepMeta implements StepMetaInterface { @Override public String getXML() { StringBuilder retval = new StringBuilder(); retval.append( " <fields>" + Const.CR ); for ( int i = 0; i < fieldName.length; i++ ) { retval.append( " <field>" + Const.CR ); retval.append( " " + XMLHandler.addTagValue( "name", fieldName[i] ) ); retval.append( " " + XMLHandler.addTagValue( "type", fieldType[i] != null ? fieldType[i].getCode() : "" ) ); retval.append( " </field>" + Const.CR ); } retval.append( " </fields>" + Const.CR ); return retval.toString(); } SystemDataMeta(); String[] getFieldName(); void setFieldName( String[] fieldName ); SystemDataTypes[] getFieldType(); void setFieldType( SystemDataTypes[] fieldType ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int count ); @Override Object clone(); static final SystemDataTypes getType( String type ); static final String getTypeDesc( SystemDataTypes t ); @Override void setDefault(); @Override void getFields( RowMetaInterface row, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override String getXML(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); @Override Map<String, String> getUsedArguments(); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); @Override StepDataInterface getStepData(); @Override boolean equals( Object o ); @Override int hashCode(); }### Answer:
@Test public void testGetXML() throws Exception { String generatedXML = expectedSystemDataMeta.getXML(); assertEquals( expectedXML.replaceAll( "\n", "" ).replaceAll( "\r", "" ), generatedXML.replaceAll( "\n", "" ) .replaceAll( "\r", "" ) ); } |
### Question:
SystemData extends BaseStep implements StepInterface { public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { Object[] row; if ( data.readsRows ) { row = getRow(); if ( row == null ) { setOutputDone(); return false; } if ( first ) { first = false; data.outputRowMeta = getInputRowMeta().clone(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } } else { row = new Object[] {}; incrementLinesRead(); if ( first ) { first = false; data.outputRowMeta = new RowMeta(); meta.getFields( data.outputRowMeta, getStepname(), null, null, this, repository, metaStore ); } } RowMetaInterface imeta = getInputRowMeta(); if ( imeta == null ) { imeta = new RowMeta(); this.setInputRowMeta( imeta ); } row = getSystemData( imeta, row ); if ( log.isRowLevel() ) { logRowlevel( "System info returned: " + data.outputRowMeta.getString( row ) ); } putRow( data.outputRowMeta, row ); if ( !data.readsRows ) { setOutputDone(); return false; } return true; } SystemData( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testProcessRow() throws Exception { SystemDataData systemDataData = new SystemDataData(); SystemDataMeta systemDataMeta = new SystemDataMeta(); systemDataMeta.allocate( 2 ); String[] names = systemDataMeta.getFieldName(); SystemDataTypes[] types = systemDataMeta.getFieldType(); names[0] = "hostname"; names[1] = "hostname_real"; types[0] = SystemDataMeta.getType( SystemDataMeta.getTypeDesc( SystemDataTypes.TYPE_SYSTEM_INFO_HOSTNAME ) ); types[1] = SystemDataMeta.getType( SystemDataMeta.getTypeDesc( SystemDataTypes.TYPE_SYSTEM_INFO_HOSTNAME_REAL ) ); SystemDataHandler systemData = new SystemDataHandler( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); Object[] expectedRow = new Object[] { Const.getHostname(), Const.getHostnameReal() }; RowMetaInterface inputRowMeta = mock( RowMetaInterface.class ); when( inputRowMeta.clone() ).thenReturn( inputRowMeta ); when( inputRowMeta.size() ).thenReturn( 2 ); systemDataData.outputRowMeta = inputRowMeta; systemData.init( systemDataMeta, systemDataData ); assertFalse( systemData.processRow( systemDataMeta, systemDataData ) ); Object[] out = systemData.getOutputRow(); assertArrayEquals( expectedRow, out ); } |
### Question:
MissingTransStep extends DummyTrans { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { if ( super.init( smi, sdi ) ) { logError( BaseMessages.getString( PKG, "MissingTransStep.Log.CannotRunTrans" ) ); } return false; } MissingTransStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testInit() { StepMetaInterface stepMetaInterface = new AbstractStepMeta() { @Override public void setDefault() { } @Override public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ) { return null; } }; StepMeta stepMeta = new StepMeta(); stepMeta.setName( "TestMetaStep" ); StepDataInterface stepDataInterface = mock( StepDataInterface.class ); Trans trans = new Trans(); LogChannel log = mock( LogChannel.class ); doAnswer( new Answer<Void>() { public Void answer( InvocationOnMock invocation ) { return null; } } ).when( log ).logError( anyString() ); trans.setLog( log ); TransMeta transMeta = new TransMeta(); transMeta.addStep( stepMeta ); MissingTransStep step = createAndInitStep( stepMetaInterface, stepDataInterface ); assertFalse( step.init( stepMetaInterface, stepDataInterface ) ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void restoreDefaults() { if ( poolParameterTree != null ) { for ( int i = 0; i < poolParameterTree.getRootChildren().getItemCount(); i++ ) { XulTreeItem item = poolParameterTree.getRootChildren().getItem( i ); String parameterName = item.getRow().getCell( 1 ).getLabel(); String defaultValue = DatabaseConnectionPoolParameter .findParameter( parameterName, BaseDatabaseMeta.poolingParameters ).getDefaultValue(); if ( ( defaultValue == null ) || ( defaultValue.trim().length() <= 0 ) ) { continue; } item.getRow().addCellText( 2, defaultValue ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testRestoreDefaults() throws Exception { } |
### Question:
CalculatorData extends BaseStepData implements StepDataInterface { public ValueMetaInterface getValueMetaFor( int resultType, String name ) throws KettlePluginException { ValueMetaInterface meta = resultMetaMapping.get( resultType ); if ( meta == null ) { meta = ValueMetaFactory.createValueMeta( name, resultType ); resultMetaMapping.put( resultType, meta ); } return meta; } CalculatorData(); RowMetaInterface getOutputRowMeta(); void setOutputRowMeta( RowMetaInterface outputRowMeta ); RowMetaInterface getCalcRowMeta(); void setCalcRowMeta( RowMetaInterface calcRowMeta ); Calculator.FieldIndexes[] getFieldIndexes(); void setFieldIndexes( Calculator.FieldIndexes[] fieldIndexes ); int[] getTempIndexes(); void setTempIndexes( int[] tempIndexes ); ValueMetaInterface getValueMetaFor( int resultType, String name ); void clearValuesMetaMapping(); }### Answer:
@Test public void dataReturnsCachedValues() throws Exception { KettleEnvironment.init( false ); CalculatorData data = new CalculatorData(); ValueMetaInterface valueMeta = data.getValueMetaFor( ValueMetaInterface.TYPE_INTEGER, null ); ValueMetaInterface shouldBeTheSame = data.getValueMetaFor( ValueMetaInterface.TYPE_INTEGER, null ); assertTrue( "CalculatorData should cache loaded value meta instances", valueMeta == shouldBeTheSame ); } |
### Question:
CalculatorMeta extends BaseStepMeta implements StepMetaInterface { @Override public StepDataInterface getStepData() { return new CalculatorData(); } CalculatorMetaFunction[] getCalculation(); void setCalculation( CalculatorMetaFunction[] calcTypes ); void allocate( int nrCalcs ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); @Override String getXML(); @Override boolean equals( Object obj ); @Override int hashCode(); @Override Object clone(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); RowMetaInterface getAllFields( RowMetaInterface inputRowMeta ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); @Override StepDataInterface getStepData(); }### Answer:
@Test public void testGetStepData() { CalculatorMeta meta = new CalculatorMeta(); assertTrue( meta.getStepData() instanceof CalculatorData ); } |
### Question:
CalculatorMeta extends BaseStepMeta implements StepMetaInterface { @Override public void setDefault() { calculation = new CalculatorMetaFunction[0]; } CalculatorMetaFunction[] getCalculation(); void setCalculation( CalculatorMetaFunction[] calcTypes ); void allocate( int nrCalcs ); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); @Override String getXML(); @Override boolean equals( Object obj ); @Override int hashCode(); @Override Object clone(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); RowMetaInterface getAllFields( RowMetaInterface inputRowMeta ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); @Override StepDataInterface getStepData(); }### Answer:
@Test public void testSetDefault() { CalculatorMeta meta = new CalculatorMeta(); meta.setDefault(); assertNotNull( meta.getCalculation() ); assertEquals( 0, meta.getCalculation().length ); } |
### Question:
StepDefinition implements Cloneable { public Object clone() throws CloneNotSupportedException { StepDefinition retval; retval = (StepDefinition) super.clone(); if ( stepMeta != null ) { retval.stepMeta = (StepMeta) stepMeta.clone(); } return retval; } StepDefinition(); StepDefinition( String tag, String stepName, StepMeta stepMeta, String description ); Object clone(); public String tag; public String stepName; public StepMeta stepMeta; public String description; }### Answer:
@Test public void testClone() throws Exception { try { StepDefinition stepDefinition = new StepDefinition( "tag", "stepName", null, "" ); stepDefinition.clone(); } catch ( NullPointerException npe ) { fail( "Null value is not handled" ); } } |
### Question:
PrioritizeStreams extends BaseStep implements StepInterface { public boolean processRow( StepMetaInterface smi, StepDataInterface sdi ) throws KettleException { meta = (PrioritizeStreamsMeta) smi; data = (PrioritizeStreamsData) sdi; if ( first ) { if ( meta.getStepName() != null || meta.getStepName().length > 0 ) { data.stepnrs = meta.getStepName().length; data.rowSets = new RowSet[data.stepnrs]; for ( int i = 0; i < data.stepnrs; i++ ) { data.rowSets[i] = findInputRowSet( meta.getStepName()[i] ); if ( i > 0 ) { checkInputLayoutValid( data.rowSets[0].getRowMeta(), data.rowSets[i].getRowMeta() ); } } } else { throw new KettleException( BaseMessages.getString( PKG, "PrioritizeStreams.Error.NotInputSteps" ) ); } data.currentRowSet = data.rowSets[0]; } Object[] input = getOneRow(); while ( input == null && data.stepnr < data.stepnrs - 1 && !isStopped() ) { input = getOneRow(); } if ( input == null ) { setOutputDone(); return false; } if ( first ) { data.outputRowMeta = data.currentRowSet.getRowMeta(); first = false; } putRow( data.outputRowMeta, input ); return true; } PrioritizeStreams( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr,
TransMeta transMeta, Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testProcessRow() throws KettleException { PrioritizeStreamsMeta meta = new PrioritizeStreamsMeta(); meta.setStepName( new String[] { "high", "medium", "low" } ); PrioritizeStreamsData data = new PrioritizeStreamsData(); PrioritizeStreamsInner step = new PrioritizeStreamsInner( stepMockHelper ); try { step.processRow( meta, data ); } catch ( NullPointerException e ) { fail( "NullPointerException detecded, seems that RowMetaInterface was not set for RowSet you are attempting" + "to read from." ); } Assert.assertTrue( "First waiting for row set is 'high'", data.currentRowSet.getClass().equals( SingleRowRowSet.class ) ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void poolingRowChange( int idx ) { if ( idx != -1 ) { if ( idx >= BaseDatabaseMeta.poolingParameters.length ) { idx = BaseDatabaseMeta.poolingParameters.length - 1; } if ( idx < 0 ) { idx = 0; } poolingDescription.setValue( BaseDatabaseMeta.poolingParameters[idx].getDescription() ); XulTreeRow row = poolParameterTree.getRootChildren().getItem( idx ).getRow(); if ( row.getSelectedColumnIndex() == 2 ) { row.addCellText( 0, "true" ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testPoolingRowChange() throws Exception { } |
### Question:
Script extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (ScriptMeta) smi; data = (ScriptData) sdi; if ( super.init( smi, sdi ) ) { jsScripts = meta.getJSScripts(); for ( int j = 0; j < jsScripts.length; j++ ) { switch ( jsScripts[ j ].getScriptType() ) { case ScriptValuesScript.TRANSFORM_SCRIPT: strTransformScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.START_SCRIPT: strStartScript = jsScripts[ j ].getScript(); break; case ScriptValuesScript.END_SCRIPT: strEndScript = jsScripts[ j ].getScript(); break; default: break; } } return true; } return false; } Script( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); Object getValueFromJScript( Object result, int i ); RowMetaInterface getOutputRowMeta(); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final int SKIP_TRANSFORMATION; static final int ABORT_TRANSFORMATION; static final int ERROR_TRANSFORMATION; static final int CONTINUE_TRANSFORMATION; }### Answer:
@Test public void testOutputDoneIfInputEmpty() throws Exception { Script step = new Script( helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans ); step.init( helper.initStepMetaInterface, helper.initStepDataInterface ); RowSet rs = helper.getMockInputRowSet( new Object[ 0 ][ 0 ] ); List<RowSet> in = new ArrayList<RowSet>(); in.add( rs ); step.setInputRowSets( in ); TransTestingUtil.execute( step, helper.processRowsStepMetaInterface, helper.processRowsStepDataInterface, 0, true ); rs.getRow(); } |
### Question:
FilterRowsMeta extends BaseStepMeta implements StepMetaInterface { public Object clone() { FilterRowsMeta retval = (FilterRowsMeta) super.clone(); retval.setTrueStepname( getTrueStepname() ); retval.setFalseStepname( getFalseStepname() ); if ( condition != null ) { retval.condition = (Condition) condition.clone(); } else { retval.condition = null; } return retval; } FilterRowsMeta(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Condition getCondition(); void setCondition( Condition condition ); void allocate(); Object clone(); String getXML(); void setDefault(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void searchInfoAndTargetSteps( List<StepMeta> steps ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); StepDataInterface getStepData(); StepIOMetaInterface getStepIOMeta(); @Override void resetStepIoMeta(); void handleStreamSelection( StreamInterface stream ); @Override boolean excludeFromCopyDistributeVerification(); List<String> getOrphanFields( Condition condition, RowMetaInterface prev ); String getTrueStepname(); @Injection( name = "SEND_TRUE_STEP" ) void setTrueStepname( String trueStepname ); String getFalseStepname(); @Injection( name = "SEND_FALSE_STEP" ) void setFalseStepname( String falseStepname ); String getConditionXML(); @Injection( name = "CONDITION" ) void setConditionXML( String conditionXML ); }### Answer:
@Test public void testClone() { FilterRowsMeta filterRowsMeta = new FilterRowsMeta(); filterRowsMeta.setCondition( new Condition() ); filterRowsMeta.setTrueStepname( "true" ); filterRowsMeta.setFalseStepname( "false" ); FilterRowsMeta clone = (FilterRowsMeta) filterRowsMeta.clone(); assertNotNull( clone.getCondition() ); assertEquals( "true", clone.getTrueStepname() ); assertEquals( "false", clone.getFalseStepname() ); } |
### Question:
DatabaseConnectionDialog { public XulDomContainer getSwtInstance( Shell shell ) throws XulException { SwtXulLoader loader = new SwtXulLoader(); return getSwtInstance( loader, shell ); } DatabaseConnectionDialog(); void registerClass( String key, String className ); XulDomContainer getSwtInstance( Shell shell ); XulDomContainer getSwtInstance( SwtXulLoader loader, Shell shell ); static final String DIALOG_DEFINITION_FILE; }### Answer:
@Test public void testGetSwtInstance() throws Exception { } |
### Question:
TableOutputMeta extends BaseStepMeta implements StepMetaInterface, ProvidesModelerMeta { public boolean supportsErrorHandling() { if ( databaseMeta != null ) { return databaseMeta.getDatabaseInterface().supportsErrorHandling(); } else { return true; } } TableOutputMeta(); String getGeneratedKeyField(); void setGeneratedKeyField( String generatedKeyField ); boolean isReturningGeneratedKeys(); void setReturningGeneratedKeys( boolean returningGeneratedKeys ); boolean isTableNameInTable(); void setTableNameInTable( boolean tableNameInTable ); String getTableNameField(); void setTableNameField( String tableNameField ); boolean isTableNameInField(); void setTableNameInField( boolean tableNameInField ); boolean isPartitioningDaily(); void setPartitioningDaily( boolean partitioningDaily ); boolean isPartitioningMonthly(); void setPartitioningMonthly( boolean partitioningMontly ); boolean isPartitioningEnabled(); void setPartitioningEnabled( boolean partitioningEnabled ); String getPartitioningField(); void setPartitioningField( String partitioningField ); void allocate( int nrRows ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); DatabaseMeta getDatabaseMeta(); void setDatabaseMeta( DatabaseMeta database ); String getCommitSize(); void setCommitSize( int commitSizeInt ); void setCommitSize( String commitSize ); String getTableName(); void setTableName( String tableName ); @Deprecated String getTablename(); @Deprecated void setTablename( String tablename ); boolean truncateTable(); void setTruncateTable( boolean truncateTable ); void setIgnoreErrors( boolean ignoreErrors ); boolean ignoreErrors(); void setSpecifyFields( boolean specifyFields ); boolean specifyFields(); void setUseBatchUpdate( boolean useBatchUpdate ); boolean useBatchUpdate(); void setDefault(); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void getFields( RowMetaInterface row, String origin, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); void analyseImpact( List<DatabaseImpact> impact, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, Repository repository,
IMetaStore metaStore ); SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
Repository repository, IMetaStore metaStore ); SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String tk,
boolean use_autoinc, String pk ); RowMetaInterface getRequiredFields( VariableSpace space ); DatabaseMeta[] getUsedDatabaseConnections(); String[] getFieldStream(); void setFieldStream( String[] fieldStream ); @Override RowMeta getRowMeta( StepDataInterface stepData ); @Override List<String> getDatabaseFields(); @Override List<String> getStreamFields(); String[] getFieldDatabase(); void setFieldDatabase( String[] fieldDatabase ); String getSchemaName(); void setSchemaName( String schemaName ); boolean supportsErrorHandling(); @Override String getMissingDatabaseConnectionInformationMessage(); @Override TableOutputMetaInjection getStepMetaInjectionInterface(); List<StepInjectionMetaEntry> extractStepMetadataEntries(); }### Answer:
@Test public void testSupportsErrorHandling() throws Exception { TableOutputMeta tableOutputMeta = new TableOutputMeta(); DatabaseMeta dbMeta = mock( DatabaseMeta.class ); tableOutputMeta.setDatabaseMeta( dbMeta ); DatabaseInterface databaseInterface = mock( DatabaseInterface.class ); when( dbMeta.getDatabaseInterface() ).thenReturn( databaseInterface ); when( databaseInterface.supportsErrorHandling() ).thenReturn( true, false ); assertTrue( tableOutputMeta.supportsErrorHandling() ); assertFalse( tableOutputMeta.supportsErrorHandling() ); tableOutputMeta.setDatabaseMeta( null ); assertTrue( tableOutputMeta.supportsErrorHandling() ); } |
### Question:
TableOutput extends BaseStep implements StepInterface { void truncateTable() throws KettleDatabaseException { if ( !meta.isPartitioningEnabled() && !meta.isTableNameInField() ) { if ( meta.truncateTable() && ( ( getCopy() == 0 && getUniqueStepNrAcrossSlaves() == 0 ) || !Utils.isEmpty( getPartitionID() ) ) ) { data.db.truncateTable( environmentSubstitute( meta.getSchemaName() ), environmentSubstitute( meta .getTableName() ) ); } } } TableOutput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean isRowLevel(); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testTruncateTable_off() throws Exception { tableOutputSpy.truncateTable(); verify( db, never() ).truncateTable( anyString(), anyString() ); }
@Test public void testTruncateTable_on() throws Exception { when( tableOutputMeta.truncateTable() ).thenReturn( true ); when( tableOutputSpy.getCopy() ).thenReturn( 0 ); when( tableOutputSpy.getUniqueStepNrAcrossSlaves() ).thenReturn( 0 ); tableOutputSpy.truncateTable(); verify( db ).truncateTable( anyString(), anyString() ); }
@Test public void testTruncateTable_on_PartitionId() throws Exception { when( tableOutputMeta.truncateTable() ).thenReturn( true ); when( tableOutputSpy.getCopy() ).thenReturn( 1 ); when( tableOutputSpy.getUniqueStepNrAcrossSlaves() ).thenReturn( 0 ); when( tableOutputSpy.getPartitionID() ).thenReturn( "partition id" ); tableOutputSpy.truncateTable(); verify( db ).truncateTable( anyString(), anyString() ); } |
### Question:
SplitFieldToRows extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SplitFieldToRowsMeta) smi; data = (SplitFieldToRowsData) sdi; if ( super.init( smi, sdi ) ) { data.rownr = 1L; try { String delimiter = Const.nullToEmpty( meta.getDelimiter() ); if ( meta.isDelimiterRegex() ) { data.delimiterPattern = Pattern.compile( environmentSubstitute( delimiter ) ); } else { data.delimiterPattern = Pattern.compile( Pattern.quote( environmentSubstitute( delimiter ) ) ); } } catch ( PatternSyntaxException pse ) { log.logError( pse.getMessage() ); throw pse; } return true; } return false; } SplitFieldToRows( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr,
TransMeta transMeta, Trans trans ); synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void interpretsNullDelimiterAsEmpty() throws Exception { SplitFieldToRows step = StepMockUtil.getStep( SplitFieldToRows.class, SplitFieldToRowsMeta.class, "handlesNullDelimiter" ); SplitFieldToRowsMeta meta = new SplitFieldToRowsMeta(); meta.setDelimiter( null ); meta.setDelimiterRegex( false ); SplitFieldToRowsData data = new SplitFieldToRowsData(); step.init( meta, data ); assertEquals( "\\Q\\E", data.delimiterPattern.pattern() ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void disablePortIfInstancePopulated() { String serverInstance = serverInstanceBox.getValue(); if ( serverInstance != null && serverInstance.length() > 0 ) { portNumberBox.setDisabled( true ); } else { portNumberBox.setDisabled( false ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testDisablePortIfInstancePopulated() throws Exception { dataHandler.getControls(); dataHandler.disablePortIfInstancePopulated(); when( serverInstanceBox.getValue() ).thenReturn( null ); dataHandler.disablePortIfInstancePopulated(); assertFalse( dataHandler.portNumberBox.isDisabled() ); } |
### Question:
MonetDbVersion implements Comparable<MonetDbVersion> { @Override public int compareTo( MonetDbVersion mDbVersion ) { int result = majorVersion.compareTo( mDbVersion.majorVersion ); if ( result != 0 ) { return result; } result = minorVersion.compareTo( mDbVersion.minorVersion ); if ( result != 0 ) { return result; } result = patchVersion.compareTo( mDbVersion.patchVersion ); if ( result != 0 ) { return result; } return result; } MonetDbVersion(); MonetDbVersion( int majorVersion, int minorVersion, int patchVersion ); MonetDbVersion( String productVersion ); Integer getMinorVersion(); Integer getMajorVersion(); Integer getPatchVersion(); @Override int compareTo( MonetDbVersion mDbVersion ); @Override String toString(); static final MonetDbVersion JAN_2014_SP2_DB_VERSION; }### Answer:
@Test public void testCompareVersions_DiffInPatch() throws Exception { String dbVersionBigger = "785.2.3"; String dbVersion = "785.2.2"; assertEquals( 1, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); }
@Test public void testCompareVersions_DiffInMinor() throws Exception { String dbVersionBigger = "785.5.3"; String dbVersion = "785.2.2"; assertEquals( 1, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); }
@Test public void testCompareVersions_DiffInMajor() throws Exception { String dbVersionBigger = "786.5.3"; String dbVersion = "785.2.2"; assertEquals( 1, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); }
@Test public void testCompareVersions_DiffInMajor_LongVersion() throws Exception { String dbVersionBigger = "788.5.3.8.9.7.5"; String dbVersion = "785.2.2"; assertEquals( 1, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); }
@Test public void testCompareVersions_TheSame() throws Exception { String dbVersionBigger = "11.11.7"; String dbVersion = "11.11.7"; assertEquals( 0, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); }
@Test public void testCompareVersions_NoPatch() throws Exception { String dbVersionBigger = "11.18"; String dbVersion = "11.17.17"; assertEquals( 1, new MonetDbVersion( dbVersionBigger ).compareTo( new MonetDbVersion( dbVersion ) ) ); } |
### Question:
BlockUntilStepsFinishMeta extends BaseStepMeta implements StepMetaInterface { public Object clone() { BlockUntilStepsFinishMeta retval = (BlockUntilStepsFinishMeta) super.clone(); int nrfields = stepName.length; retval.allocate( nrfields ); System.arraycopy( stepName, 0, retval.stepName, 0, nrfields ); System.arraycopy( stepCopyNr, 0, retval.stepCopyNr, 0, nrfields ); return retval; } BlockUntilStepsFinishMeta(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void allocate( int nrfields ); String[] getStepName(); String[] getStepCopyNr(); void setStepName( String[] stepName ); void setStepCopyNr( String[] stepCopyNr ); void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void setDefault(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); StepDataInterface getStepData(); TransformationType[] getSupportedTransformationTypes(); }### Answer:
@Test public void cloneTest() throws Exception { BlockUntilStepsFinishMeta meta = new BlockUntilStepsFinishMeta(); meta.allocate( 2 ); meta.setStepName( new String[] { "step1", "step2" } ); meta.setStepCopyNr( new String[] { "copy1", "copy2" } ); BlockUntilStepsFinishMeta aClone = (BlockUntilStepsFinishMeta) meta.clone(); assertFalse( aClone == meta ); assertTrue( Arrays.equals( meta.getStepName(), aClone.getStepName() ) ); assertTrue( Arrays.equals( meta.getStepCopyNr(), aClone.getStepCopyNr() ) ); assertEquals( meta.getXML(), aClone.getXML() ); } |
### Question:
MultiMergeJoinMeta extends BaseStepMeta implements StepMetaInterface { @Override public String getXML() { StringBuilder retval = new StringBuilder(); String[] inputStepsNames = inputSteps != null ? inputSteps : ArrayUtils.EMPTY_STRING_ARRAY; retval.append( " " ).append( XMLHandler.addTagValue( "join_type", getJoinType() ) ); for ( int i = 0; i < inputStepsNames.length; i++ ) { retval.append( " " ).append( XMLHandler.addTagValue( "step" + i, inputStepsNames[ i ] ) ); } retval.append( " " ).append( XMLHandler.addTagValue( "number_input", inputStepsNames.length ) ); retval.append( " " ).append( XMLHandler.openTag( "keys" ) ).append( Const.CR ); for ( int i = 0; i < keyFields.length; i++ ) { retval.append( " " ).append( XMLHandler.addTagValue( "key", keyFields[i] ) ); } retval.append( " " ).append( XMLHandler.closeTag( "keys" ) ).append( Const.CR ); return retval.toString(); } MultiMergeJoinMeta(); String getJoinType(); void setJoinType( String joinType ); String[] getKeyFields(); void setKeyFields( String[] keyFields ); @Override boolean excludeFromRowLayoutVerification(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocateKeys( int nrKeys ); @Override Object clone(); @Override String getXML(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void searchInfoAndTargetSteps( List<StepMeta> steps ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); @Override StepDataInterface getStepData(); @Override void resetStepIoMeta(); void setInputSteps( String[] inputSteps ); String[] getInputSteps(); void allocateInputSteps( int count ); static final String[] join_types; static final boolean[] optionals; }### Answer:
@Test public void testGetXml() { String[] inputSteps = new String[] { "Step1", "Step2" }; multiMergeMeta.setInputSteps( inputSteps ); multiMergeMeta.setKeyFields( new String[] {"Key1", "Key2"} ); String xml = multiMergeMeta.getXML(); Assert.assertTrue( xml.contains( "step0" ) ); Assert.assertTrue( xml.contains( "step1" ) ); } |
### Question:
MultiMergeJoinMeta extends BaseStepMeta implements StepMetaInterface { @Override public Object clone() { MultiMergeJoinMeta retval = (MultiMergeJoinMeta) super.clone(); int nrKeys = keyFields == null ? 0 : keyFields.length; int nrSteps = inputSteps == null ? 0 : inputSteps.length; retval.allocateKeys( nrKeys ); retval.allocateInputSteps( nrSteps ); System.arraycopy( keyFields, 0, retval.keyFields, 0, nrKeys ); System.arraycopy( inputSteps, 0, retval.inputSteps, 0, nrSteps ); return retval; } MultiMergeJoinMeta(); String getJoinType(); void setJoinType( String joinType ); String[] getKeyFields(); void setKeyFields( String[] keyFields ); @Override boolean excludeFromRowLayoutVerification(); @Override void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocateKeys( int nrKeys ); @Override Object clone(); @Override String getXML(); @Override void setDefault(); @Override void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void searchInfoAndTargetSteps( List<StepMeta> steps ); @Override void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); @Override void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); @Override void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); @Override StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); @Override StepDataInterface getStepData(); @Override void resetStepIoMeta(); void setInputSteps( String[] inputSteps ); String[] getInputSteps(); void allocateInputSteps( int count ); static final String[] join_types; static final boolean[] optionals; }### Answer:
@Test public void cloneTest() throws Exception { MultiMergeJoinMeta meta = new MultiMergeJoinMeta(); meta.allocateKeys( 2 ); meta.allocateInputSteps( 3 ); meta.setKeyFields( new String[] { "key1", "key2" } ); meta.setInputSteps( new String[] { "step1", "step2", "step3" } ); meta.setJoinType( "INNER" ); MultiMergeJoinMeta aClone = (MultiMergeJoinMeta) meta.clone(); Assert.assertFalse( aClone == meta ); Assert.assertTrue( Arrays.equals( meta.getKeyFields(), aClone.getKeyFields() ) ); Assert.assertTrue( Arrays.equals( meta.getInputSteps(), aClone.getInputSteps() ) ); Assert.assertEquals( meta.getJoinType(), aClone.getJoinType() ); } |
### Question:
ConcatFields extends TextFileOutput implements StepInterface { Object[] prepareOutputRow( Object[] r ) { Object[] outputRowData = null; if ( !meta.isRemoveSelectedFields() ) { outputRowData = RowDataUtil.resizeArray( r, data.outputRowMeta.size() ); } else { outputRowData = new Object[data.outputRowMeta.size() + RowDataUtil.OVER_ALLOCATE_SIZE]; if ( r != null ) { for ( int i = 0; i < data.remainingFieldsInputOutputMapping.length; i++ ) { outputRowData[i] = r[data.remainingFieldsInputOutputMapping[i]]; } } } return outputRowData; } ConcatFields( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); @Override synchronized boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); @Override boolean init( StepMetaInterface smi, StepDataInterface sdi ); @Override void dispose( StepMetaInterface smi, StepDataInterface sdi ); public ConcatFieldsMeta meta; public ConcatFieldsData data; }### Answer:
@Test public void testPrepareOutputRow() throws Exception { ConcatFieldsHandler concatFields = new ConcatFieldsHandler( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); Object[] row = new Object[] { "one", "two" }; String[] fieldNames = new String[] { "one", "two" }; concatFields.setRow( row ); RowMetaInterface inputRowMeta = mock( RowMetaInterface.class ); when( inputRowMeta.clone() ).thenReturn( inputRowMeta ); when( inputRowMeta.size() ).thenReturn( 2 ); when( inputRowMeta.getFieldNames() ).thenReturn( fieldNames ); when( stepMockHelper.processRowsStepMetaInterface.getOutputFields() ).thenReturn( textFileFields ); when( stepMockHelper.processRowsStepMetaInterface.isFastDump() ).thenReturn( Boolean.TRUE ); when( stepMockHelper.processRowsStepMetaInterface.isFileAppended() ).thenReturn( Boolean.FALSE ); when( stepMockHelper.processRowsStepMetaInterface.isFileNameInField() ).thenReturn( Boolean.FALSE ); when( stepMockHelper.processRowsStepMetaInterface.isHeaderEnabled() ).thenReturn( Boolean.TRUE ); when( stepMockHelper.processRowsStepMetaInterface.isRemoveSelectedFields() ).thenReturn( Boolean.TRUE ); concatFields.setInputRowMeta( inputRowMeta ); try { concatFields.processRow( stepMockHelper.processRowsStepMetaInterface, stepMockHelper.processRowsStepDataInterface ); concatFields.prepareOutputRow( row ); } catch ( NullPointerException npe ) { fail( "NullPointerException issue PDI-8870 still reproduced " ); } } |
### Question:
DataHandler extends AbstractXulEventHandler { protected void showMessage( String message, boolean scroll ) { try { XulMessageBox box = (XulMessageBox) document.createElement( "messagebox" ); box.setMessage( message ); box.setModalParent( ( (XulRoot) document.getElementById( "general-datasource-window" ) ).getRootObject() ); if ( scroll ) { box.setScrollable( true ); box.setWidth( 500 ); box.setHeight( 400 ); } box.open(); } catch ( XulException e ) { System.out.println( "Error creating messagebox " + e.getMessage() ); } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testShowMessage() throws Exception { dataHandler.showMessage( "MyMessage", false ); dataHandler.showMessage( "MyMessage", true ); when( document.createElement( "messagebox" ) ).thenThrow( new XulException() ); dataHandler.showMessage( "MyMessage", false ); } |
### Question:
ExcelWriterStep extends BaseStep implements StepInterface { protected void protectSheet( Sheet sheet, String password ) { if ( sheet instanceof HSSFSheet ) { sheet.protectSheet( password ); } } ExcelWriterStep( StepMeta s, StepDataInterface stepDataInterface, int c, TransMeta t, Trans dis ); @Override boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); void writeNextLine( Object[] r ); String buildFilename( int splitNr ); static void copyFile( FileObject in, FileObject out ); void prepareNextOutputFile(); @Override boolean init( StepMetaInterface smi, StepDataInterface sdi ); @Override void dispose( StepMetaInterface smi, StepDataInterface sdi ); static final String STREAMER_FORCE_RECALC_PROP_NAME; }### Answer:
@Test public void testProtectSheet() throws Exception { step.protectSheet( wb.getSheet( SHEET_NAME ), "aa" ); assertTrue( wb.getSheet( SHEET_NAME ).getProtect() ); } |
### Question:
LdapProtocolFactory { public LdapProtocol createLdapProtocol( VariableSpace variableSpace, LdapMeta meta, Collection<String> binaryAttributes ) throws KettleException { String connectionType = variableSpace.environmentSubstitute( meta.getProtocol() ); synchronized ( protocols ) { for ( Class<? extends LdapProtocol> protocol : protocols ) { if ( getName( protocol ).equals( connectionType ) ) { try { return protocol.getConstructor( LogChannelInterface.class, VariableSpace.class, LdapMeta.class, Collection.class ).newInstance( log, variableSpace, meta, binaryAttributes ); } catch ( Exception e ) { throw new KettleException( e ); } } } } return null; } LdapProtocolFactory( LogChannelInterface log ); static final List<String> getConnectionTypes( LogChannelInterface log ); LdapProtocol createLdapProtocol( VariableSpace variableSpace, LdapMeta meta,
Collection<String> binaryAttributes ); }### Answer:
@Test public void createLdapProtocol() throws Exception { String ldapVariable = "${ldap_protocol_variable}"; String ldap = "LDAP"; String host = "localhost"; LdapProtocolFactory ldapProtocolFactory = new LdapProtocolFactory( Mockito.mock( LogChannelInterface.class ) ); VariableSpace variableSpace = Mockito.mock( VariableSpace.class ); LdapMeta meta = Mockito.mock( LdapMeta.class ); Mockito.doReturn( ldapVariable ).when( meta ).getProtocol(); Mockito.doReturn( ldap ).when( variableSpace ).environmentSubstitute( ldapVariable ); Mockito.doReturn( host ).when( meta ).getHost(); Mockito.doReturn( host ).when( variableSpace ).environmentSubstitute( host ); ldapProtocolFactory.createLdapProtocol( variableSpace, meta, Collections.emptyList() ); Mockito.verify( variableSpace, Mockito.times( 1 ) ).environmentSubstitute( ldapVariable ); } |
### Question:
LDAPInput extends BaseStep implements StepInterface { public boolean init( StepMetaInterface smi, StepDataInterface sdi ) { meta = (LDAPInputMeta) smi; data = (LDAPInputData) sdi; if ( super.init( smi, sdi ) ) { data.rownr = 1L; data.multi_valuedFieldSeparator = environmentSubstitute( meta.getMultiValuedSeparator() ); data.nrfields = meta.getInputFields().length; data.staticFilter = environmentSubstitute( meta.getFilterString() ); data.staticSearchBase = environmentSubstitute( meta.getSearchBase() ); data.dynamic = ( meta.isDynamicSearch() || meta.isDynamicFilter() ); try { connectServerLdap(); return true; } catch ( Exception e ) { logError( BaseMessages.getString( PKG, "LDAPInput.ErrorInit", e.toString() ) ); stopAll(); setErrors( 1 ); } } return false; } LDAPInput( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testRowProcessing() throws Exception { LDAPInput ldapInput = new LDAPInput( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); LDAPInputData data = new LDAPInputData(); LDAPInputMeta meta = mockMeta(); LDAPInputField[] fields = new LDAPInputField[] { new LDAPInputField( "dn" ), new LDAPInputField( "cn" ), new LDAPInputField( "role" ) }; int sortedField = 1; fields[sortedField].setSortedKey( true ); when( meta.getInputFields() ).thenReturn( fields ); when( meta.getProtocol() ).thenReturn( LdapMockProtocol.getName() ); when( meta.getHost() ).thenReturn( "host.mock" ); when( meta.getDerefAliases() ).thenReturn( "never" ); when( meta.getReferrals() ).thenReturn( "ignore" ); LdapMockProtocol.setup(); try { assertTrue( "Input Initialization Failed", ldapInput.init( meta, data ) ); assertEquals( "Field not marked as sorted", 1, data.connection.getSortingAttributes().size() ); assertEquals( "Field not marked as sorted", data.attrReturned[sortedField], data.connection.getSortingAttributes().get( 0 ) ); assertNotNull( data.attrReturned[sortedField] ); } finally { LdapMockProtocol.cleanup(); } } |
### Question:
CsvInputData extends BaseStepData implements StepDataInterface { byte[] removeEscapedEnclosures( byte[] field, int nrEnclosuresFound ) { byte[] result = new byte[field.length - nrEnclosuresFound]; int resultIndex = 0; for ( int i = 0; i < field.length; i++ ) { result[resultIndex++] = field[i]; if ( field[i] == enclosure[0] && i + 1 < field.length && field[i + 1] == enclosure[0] ) { i++; } } return result; } CsvInputData(); public FileChannel fc; public ByteBuffer bb; public RowMetaInterface convertRowMeta; public RowMetaInterface outputRowMeta; public byte[] delimiter; public byte[] enclosure; public int preferredBufferSize; public String[] filenames; public int filenr; public int startFilenr; public byte[] binaryFilename; public FileInputStream fis; public boolean isAddingRowNumber; public long rowNumber; public boolean stopReading; public int stepNumber; public int totalNumberOfSteps; public List<Long> fileSizes; public long totalFileSize; public long blockToRead; public long startPosition; public long endPosition; public long bytesToSkipInFirstFile; public long totalBytesRead; public boolean parallel; public int filenameFieldIndex; public int rownumFieldIndex; public EncodingType encodingType; public PatternMatcherInterface delimiterMatcher; public PatternMatcherInterface enclosureMatcher; public CrLfMatcherInterface crLfMatcher; public FieldsMapping fieldsMapping; }### Answer:
@Test public void testRemoveEscapedEnclosuresWithOneEscapedInMiddle() { CsvInputData csvInputData = new CsvInputData(); csvInputData.enclosure = "\"".getBytes(); String result = new String( csvInputData.removeEscapedEnclosures( "abcd \"\" defg".getBytes(), 1 ) ); assertEquals( "abcd \" defg", result ); }
@Test public void testRemoveEscapedEnclosuresWithTwoEscapedInMiddle() { CsvInputData csvInputData = new CsvInputData(); csvInputData.enclosure = "\"".getBytes(); String result = new String( csvInputData.removeEscapedEnclosures( "abcd \"\"\"\" defg".getBytes(), 2 ) ); assertEquals( "abcd \"\" defg", result ); }
@Test public void testRemoveEscapedEnclosuresWithOneByItself() { CsvInputData csvInputData = new CsvInputData(); csvInputData.enclosure = "\"".getBytes(); String result = new String( csvInputData.removeEscapedEnclosures( "\"\"".getBytes(), 1 ) ); assertEquals( "\"", result ); }
@Test public void testRemoveEscapedEnclosuresWithTwoByThemselves() { CsvInputData csvInputData = new CsvInputData(); csvInputData.enclosure = "\"".getBytes(); String result = new String( csvInputData.removeEscapedEnclosures( "\"\"\"\"".getBytes(), 2 ) ); assertEquals( "\"\"", result ); }
@Test public void testRemoveEscapedEnclosuresWithCharacterInTheMiddleOfThem() { CsvInputData csvInputData = new CsvInputData(); csvInputData.enclosure = "\"".getBytes(); String result = new String( csvInputData.removeEscapedEnclosures( "345\"\"1\"\"abc".getBytes(), 2 ) ); assertEquals( "345\"1\"abc", result ); } |
### Question:
NamedFieldsMapping implements FieldsMapping { @Override public int fieldMetaIndex( int index ) { if ( index >= size() || index < 0 ) { return FIELD_DOES_NOT_EXIST; } return actualToMetaFieldMapping[index]; } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer:
@Test public void fieldMetaIndex() { assertEquals( 3, fieldsMapping.fieldMetaIndex( 0 ) ); }
@Test public void fieldMetaIndexWithUnexistingField() { assertEquals( FieldsMapping.FIELD_DOES_NOT_EXIST, fieldsMapping.fieldMetaIndex( 4 ) ); } |
### Question:
DataHandler extends AbstractXulEventHandler { public void handleUseSecurityCheckbox() { if ( useIntegratedSecurityCheck != null ) { if ( useIntegratedSecurityCheck.isChecked() ) { userNameBox.setDisabled( true ); passwordBox.setDisabled( true ); } else { userNameBox.setDisabled( false ); passwordBox.setDisabled( false ); } } } DataHandler(); void loadConnectionData(); void loadAccessData(); void editOptions( int index ); void clearOptionsData(); void getOptionHelp(); void setDeckChildIndex(); void onPoolingCheck(); void onClusterCheck(); Object getData(); void setData( Object data ); void pushCache(); void popCache(); void onCancel(); void onOK(); void testDatabaseConnection(); void restoreDefaults(); void poolingRowChange( int idx ); void disablePortIfInstancePopulated(); void handleUseSecurityCheckbox(); static final SortedMap<String, DatabaseInterface> connectionMap; static final Map<String, String> connectionNametoID; }### Answer:
@Test public void testHandleUseSecurityCheckbox() throws Exception { dataHandler.handleUseSecurityCheckbox(); XulCheckbox useIntegratedSecurityCheck = mock( XulCheckbox.class ); when( useIntegratedSecurityCheck.isChecked() ).thenReturn( false ); when( document.getElementById( "use-integrated-security-check" ) ).thenReturn( useIntegratedSecurityCheck ); dataHandler.getControls(); dataHandler.handleUseSecurityCheckbox(); when( useIntegratedSecurityCheck.isChecked() ).thenReturn( true ); dataHandler.handleUseSecurityCheckbox(); } |
### Question:
NamedFieldsMapping implements FieldsMapping { @Override public int size() { return actualToMetaFieldMapping.length; } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer:
@Test public void size() { assertEquals( 2, fieldsMapping.size() ); } |
### Question:
NamedFieldsMapping implements FieldsMapping { public static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ) { LinkedHashMap<String, List<Integer>> metaNameToIndex = new LinkedHashMap<>(); List<Integer> unmatchedMetaFields = new ArrayList<>(); int[] actualToMetaFieldMapping = new int[actualFieldNames.length]; for ( int i = 0; i < metaFieldNames.length; i++ ) { List<Integer> coll = metaNameToIndex.getOrDefault( metaFieldNames[i], new ArrayList<>() ); coll.add( i ); metaNameToIndex.put( metaFieldNames[i], coll ); } for ( int i = 0; i < actualFieldNames.length; i++ ) { List<Integer> columnIndexes = metaNameToIndex.get( actualFieldNames[i] ); if ( columnIndexes == null || columnIndexes.isEmpty() ) { unmatchedMetaFields.add( i ); actualToMetaFieldMapping[i] = FIELD_DOES_NOT_EXIST; continue; } actualToMetaFieldMapping[i] = columnIndexes.remove( 0 ); } Iterator<Integer> remainingMetaIndexes = metaNameToIndex.values().stream() .flatMap( List::stream ) .sorted() .iterator(); for ( int idx : unmatchedMetaFields ) { if ( !remainingMetaIndexes.hasNext() ) { break; } actualToMetaFieldMapping[ idx ] = remainingMetaIndexes.next(); } return new NamedFieldsMapping( actualToMetaFieldMapping ); } NamedFieldsMapping( int[] actualToMetaFieldMapping ); @Override int fieldMetaIndex( int index ); @Override int size(); static NamedFieldsMapping mapping( String[] actualFieldNames, String[] metaFieldNames ); }### Answer:
@Test public void mapping() { NamedFieldsMapping mapping = NamedFieldsMapping.mapping( new String[] { "FIRST", "SECOND", "THIRD" }, new String[] { "SECOND", "THIRD" } ); assertEquals( 0, mapping.fieldMetaIndex( 1 ) ); } |
### Question:
UnnamedFieldsMapping implements FieldsMapping { @Override public int fieldMetaIndex( int index ) { return ( index >= fieldsCount || index < 0 ) ? FieldsMapping.FIELD_DOES_NOT_EXIST : index; } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer:
@Test public void fieldMetaIndex() { assertEquals( 1, fieldsMapping.fieldMetaIndex( 1 ) ); }
@Test public void fieldMetaIndexWithUnexistingField() { assertEquals( FieldsMapping.FIELD_DOES_NOT_EXIST, fieldsMapping.fieldMetaIndex( 2 ) ); } |
### Question:
UnnamedFieldsMapping implements FieldsMapping { @Override public int size() { return fieldsCount; } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer:
@Test public void size() { assertEquals( 2, fieldsMapping.size() ); } |
### Question:
UnnamedFieldsMapping implements FieldsMapping { public static UnnamedFieldsMapping mapping( int fieldsCount ) { return new UnnamedFieldsMapping( fieldsCount ); } UnnamedFieldsMapping( int fieldsCount ); @Override int fieldMetaIndex( int index ); @Override int size(); static UnnamedFieldsMapping mapping( int fieldsCount ); }### Answer:
@Test public void mapping() { UnnamedFieldsMapping mapping = UnnamedFieldsMapping.mapping( 2 ); assertEquals( 1, mapping.fieldMetaIndex( 1 ) ); } |
### Question:
CreditCardVerifier { public static boolean isNumber( String n ) { try { Double.valueOf( n ).doubleValue(); return true; } catch ( NumberFormatException e ) { return false; } } static String getCardName( int id ); static String getNotValidCardNames( int id ); static ReturnIndicator CheckCC( String CardNumber ); static boolean luhnValidate( String numberString ); static int getCardID( String number ); static boolean isNumber( String n ); static final int INVALID; static final int VISA; static final int MASTERCARD; static final int AMERICAN_EXPRESS; static final int EN_ROUTE; static final int DINERS_CLUB; static final int DISCOVER; static final int JCB1; static final int JCB2; static final int BANKCARD; static final int MAESTRO; static final int SOLO; static final int SWITCH; static final int AIRPLUS; static final int LASER; static final int VOYAGER; }### Answer:
@Test public void testIsNumber() { assertFalse( CreditCardVerifier.isNumber( "" ) ); assertFalse( CreditCardVerifier.isNumber( "a" ) ); assertTrue( CreditCardVerifier.isNumber( "1" ) ); assertTrue( CreditCardVerifier.isNumber( "1.01" ) ); } |
### Question:
CreditCardValidatorMeta extends BaseStepMeta implements StepMetaInterface { public boolean supportsErrorHandling() { return true; } CreditCardValidatorMeta(); String getDynamicField(); void setDynamicField( String fieldname ); String getResultFieldName(); void setOnlyDigits( boolean onlydigits ); boolean isOnlyDigits(); void setResultFieldName( String resultfieldname ); void setCardType( String cardtype ); String getCardType(); void setNotValidMsg( String notvalidmsg ); String getNotValidMsg(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); }### Answer:
@Test public void testSupportsErrorHandling() { assertTrue( new CreditCardValidatorMeta().supportsErrorHandling() ); } |
### Question:
CreditCardValidatorMeta extends BaseStepMeta implements StepMetaInterface { public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException { String realresultfieldname = space.environmentSubstitute( resultfieldname ); if ( !Utils.isEmpty( realresultfieldname ) ) { ValueMetaInterface v = new ValueMetaBoolean( realresultfieldname ); v.setOrigin( name ); inputRowMeta.addValueMeta( v ); } String realcardtype = space.environmentSubstitute( cardtype ); if ( !Utils.isEmpty( realcardtype ) ) { ValueMetaInterface v = new ValueMetaString( realcardtype ); v.setOrigin( name ); inputRowMeta.addValueMeta( v ); } String realnotvalidmsg = space.environmentSubstitute( notvalidmsg ); if ( !Utils.isEmpty( notvalidmsg ) ) { ValueMetaInterface v = new ValueMetaString( realnotvalidmsg ); v.setOrigin( name ); inputRowMeta.addValueMeta( v ); } } CreditCardValidatorMeta(); String getDynamicField(); void setDynamicField( String fieldname ); String getResultFieldName(); void setOnlyDigits( boolean onlydigits ); boolean isOnlyDigits(); void setResultFieldName( String resultfieldname ); void setCardType( String cardtype ); String getCardType(); void setNotValidMsg( String notvalidmsg ); String getNotValidMsg(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); void setDefault(); void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); String getXML(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr,
TransMeta transMeta, Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); }### Answer:
@Test public void testGetFields() throws KettleStepException { CreditCardValidatorMeta meta = new CreditCardValidatorMeta(); meta.setDefault(); meta.setResultFieldName( "The Result Field" ); meta.setCardType( "The Card Type Field" ); meta.setNotValidMsg( "Is Card Valid" ); RowMeta rowMeta = new RowMeta(); meta.getFields( rowMeta, "this step", null, null, new Variables(), null, null ); assertEquals( 3, rowMeta.size() ); assertEquals( "The Result Field", rowMeta.getValueMeta( 0 ).getName() ); assertEquals( ValueMetaInterface.TYPE_BOOLEAN, rowMeta.getValueMeta( 0 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 0 ).getOrigin() ); assertEquals( "The Card Type Field", rowMeta.getValueMeta( 1 ).getName() ); assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 1 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 1 ).getOrigin() ); assertEquals( "Is Card Valid", rowMeta.getValueMeta( 2 ).getName() ); assertEquals( ValueMetaInterface.TYPE_STRING, rowMeta.getValueMeta( 2 ).getType() ); assertEquals( "this step", rowMeta.getValueMeta( 2 ).getOrigin() ); } |
### Question:
TransExecutorParameters implements Cloneable { @Override public Object clone() { try { TransExecutorParameters retval = (TransExecutorParameters) super.clone(); int nrVariables = variable.length; retval.allocate( nrVariables ); System.arraycopy( variable, 0, retval.variable, 0, nrVariables ); System.arraycopy( field, 0, retval.field, 0, nrVariables ); System.arraycopy( input, 0, retval.input, 0, nrVariables ); return retval; } catch ( CloneNotSupportedException e ) { throw new RuntimeException( e ); } } TransExecutorParameters(); TransExecutorParameters( Node paramNode ); TransExecutorParameters( Repository rep, ObjectId id_step ); void allocate( int nrVariables ); @Override Object clone(); String getXML(); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); String[] getField(); void setField( String[] field ); String[] getVariable(); void setVariable( String[] variable ); boolean isInheritingAllVariables(); void setInheritingAllVariables( boolean inheritingAllVariables ); String[] getInput(); void setInput( String[] input ); static final String XML_TAG; }### Answer:
@Test public void testClone() throws Exception { TransExecutorParameters meta = new TransExecutorParameters(); meta.setField( new String[] { "field1", "field2" } ); meta.setVariable( new String[] { "var1", "var2" } ); meta.setInput( new String[] { "input1", "input2" } ); TransExecutorParameters cloned = (TransExecutorParameters) meta.clone(); assertFalse( cloned.getField() == meta.getField() ); assertTrue( Arrays.equals( cloned.getField(), meta.getField() ) ); assertFalse( cloned.getVariable() == meta.getVariable() ); assertTrue( Arrays.equals( cloned.getVariable(), meta.getVariable() ) ); assertFalse( cloned.getInput() == meta.getInput() ); assertTrue( Arrays.equals( cloned.getInput(), meta.getInput() ) ); } |
### Question:
FragmentHandler extends AbstractXulEventHandler { protected void loadDatabaseOptionsFragment( String fragmentUri ) throws XulException { XulComponent groupElement = document.getElementById( "database-options-box" ); XulComponent parentElement = groupElement.getParent(); XulDomContainer fragmentContainer; try { fragmentContainer = this.xulDomContainer.loadFragment( fragmentUri, Messages.getBundle() ); XulComponent newGroup = fragmentContainer.getDocumentRoot().getFirstChild(); parentElement.replaceChild( groupElement, newGroup ); } catch ( XulException e ) { e.printStackTrace(); throw e; } } FragmentHandler(); void refreshOptions(); Object getData(); void setData( Object arg0 ); }### Answer:
@Test public void testLoadDatabaseOptionsFragment() throws Exception { XulComponent component = mock( XulComponent.class ); XulComponent parent = mock( XulComponent.class ); when( component.getParent() ).thenReturn( parent ); when( document.getElementById( "database-options-box" ) ).thenReturn( component ); XulDomContainer fragmentContainer = mock( XulDomContainer.class ); Document mockDoc = mock( Document.class ); XulComponent firstChild = mock( XulComponent.class ); when( mockDoc.getFirstChild() ).thenReturn( firstChild ); when( fragmentContainer.getDocumentRoot() ).thenReturn( mockDoc ); when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenReturn( fragmentContainer ); fragmentHandler.loadDatabaseOptionsFragment( null ); }
@Test( expected = XulException.class ) public void testLoadDatabaseOptionsFragmentWithException() throws Exception { XulComponent component = mock( XulComponent.class ); XulComponent parent = mock( XulComponent.class ); when( component.getParent() ).thenReturn( parent ); when( document.getElementById( "database-options-box" ) ).thenReturn( component ); when( xulDomContainer.loadFragment( anyString(), any( Object.class ) ) ).thenThrow( new XulException() ); fragmentHandler.loadDatabaseOptionsFragment( null ); } |
### Question:
LoadFileInputMeta extends BaseStepMeta implements StepMetaInterface { public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException { readData( stepnode ); } LoadFileInputMeta(); String getShortFileNameField(); void setShortFileNameField( String field ); String getPathField(); void setPathField( String field ); String isHiddenField(); void setIsHiddenField( String field ); String getLastModificationDateField(); void setLastModificationDateField( String field ); String getUriField(); void setUriField( String field ); String getRootUriField(); void setRootUriField( String field ); String getExtensionField(); void setExtensionField( String field ); String[] getFileRequired(); void setFileRequired( String[] fileRequired ); @Deprecated String[] getExludeFileMask(); String[] getExcludeFileMask(); void setExcludeFileMask( String[] excludeFileMask ); @Deprecated boolean addResultFile(); boolean getAddResultFile(); boolean isIgnoreEmptyFile(); void setIgnoreEmptyFile( boolean IsIgnoreEmptyFile ); boolean isIgnoreMissingPath(); void setIgnoreMissingPath( boolean IsIgnoreMissingPath ); void setAddResultFile( boolean addresultfile ); LoadFileInputField[] getInputFields(); void setInputFields( LoadFileInputField[] inputFields ); String getDynamicFilenameField(); void setDynamicFilenameField( String DynamicFilenameField ); boolean getFileInFields(); @Deprecated boolean getIsInFields(); @Deprecated void setIsInFields( boolean IsInFields ); void setFileInFields( boolean IsInFields ); String[] getFileMask(); void setFileMask( String[] fileMask ); String[] getFileName(); String[] getIncludeSubFolders(); void setIncludeSubFolders( String[] includeSubFoldersin ); String getRequiredFilesCode( String tt ); String getRequiredFilesDesc( String tt ); void setFileName( String[] fileName ); String getFilenameField(); void setFilenameField( String filenameField ); @Deprecated boolean includeFilename(); boolean getIncludeFilename(); void setIncludeFilename( boolean includeFilename ); @Deprecated boolean includeRowNumber(); boolean getIncludeRowNumber(); void setIncludeRowNumber( boolean includeRowNumber ); long getRowLimit(); void setRowLimit( long rowLimit ); String getRowNumberField(); void setRowNumberField( String rowNumberField ); String getEncoding(); void setEncoding( String encoding ); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); Object clone(); String getXML(); void allocate( int nrfiles, int nrfields ); void setDefault(); void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); FileInputList getFiles( VariableSpace space ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository,
IMetaStore metaStore ); String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta transMeta,
Trans trans ); StepDataInterface getStepData(); boolean supportsErrorHandling(); @Override boolean equals( Object o ); @Override int hashCode(); static final String[] RequiredFilesDesc; static final String[] RequiredFilesCode; }### Answer:
@Test public void testLoadXML() throws Exception { LoadFileInputMeta origMeta = createMeta(); LoadFileInputMeta testMeta = new LoadFileInputMeta(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse( new InputSource( new StringReader( "<step>" + xmlOrig + "</step>" ) ) ); IMetaStore metaStore = null; testMeta.loadXML( doc.getFirstChild(), null, metaStore ); assertEquals( origMeta, testMeta ); } |
### Question:
SyslogMessage extends BaseStep implements StepInterface { public void dispose( StepMetaInterface smi, StepDataInterface sdi ) { meta = (SyslogMessageMeta) smi; data = (SyslogMessageData) sdi; if ( data.syslog != null ) { data.syslog.shutdown(); } super.dispose( smi, sdi ); } SyslogMessage( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta,
Trans trans ); boolean processRow( StepMetaInterface smi, StepDataInterface sdi ); boolean init( StepMetaInterface smi, StepDataInterface sdi ); void dispose( StepMetaInterface smi, StepDataInterface sdi ); }### Answer:
@Test public void testDispose() throws Exception { SyslogMessageData data = new SyslogMessageData(); SyslogIF syslog = mock( SyslogIF.class ); SyslogConfigIF syslogConfigIF = mock( SyslogConfigIF.class, RETURNS_MOCKS ); when( syslog.getConfig() ).thenReturn( syslogConfigIF ); final Boolean[] initialized = new Boolean[] { Boolean.FALSE }; doAnswer( new Answer<Object>() { public Object answer( InvocationOnMock invocation ) { initialized[0] = true; return initialized; } } ).when( syslog ).initialize( anyString(), (SyslogConfigIF) anyObject() ); doAnswer( new Answer<Object>() { public Object answer( InvocationOnMock invocation ) { if ( !initialized[0] ) { throw new NullPointerException( "this.socket is null" ); } else { initialized[0] = false; } return initialized; } } ).when( syslog ).shutdown(); SyslogMessageMeta meta = new SyslogMessageMeta(); SyslogMessage syslogMessage = new SyslogMessage( stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans ); SyslogMessage sysLogMessageSpy = spy( syslogMessage ); when( sysLogMessageSpy.getSyslog() ).thenReturn( syslog ); meta.setServerName( "1" ); meta.setMessageFieldName( "1" ); sysLogMessageSpy.init( meta, data ); sysLogMessageSpy.dispose( meta, data ); } |
### Question:
MergeJoinMeta extends BaseStepMeta implements StepMetaInterface { public Object clone() { MergeJoinMeta retval = (MergeJoinMeta) super.clone(); int nrKeys1 = keyFields1.length; int nrKeys2 = keyFields2.length; retval.allocate( nrKeys1, nrKeys2 ); System.arraycopy( keyFields1, 0, retval.keyFields1, 0, nrKeys1 ); System.arraycopy( keyFields2, 0, retval.keyFields2, 0, nrKeys2 ); StepIOMetaInterface stepIOMeta = new StepIOMeta( true, true, false, false, false, false ); List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams(); for ( StreamInterface infoStream : infoStreams ) { stepIOMeta.addStream( new Stream( infoStream ) ); } retval.ioMeta = stepIOMeta; return retval; } MergeJoinMeta(); String getJoinType(); void setJoinType( String joinType ); String[] getKeyFields1(); void setKeyFields1( String[] keyFields1 ); String[] getKeyFields2(); void setKeyFields2( String[] keyFields2 ); boolean excludeFromRowLayoutVerification(); void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ); void allocate( int nrKeys1, int nrKeys2 ); Object clone(); String getXML(); void setDefault(); void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ); @Override void searchInfoAndTargetSteps( List<StepMeta> steps ); void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ); void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ); void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ); StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ); StepDataInterface getStepData(); StepIOMetaInterface getStepIOMeta(); void resetStepIoMeta(); TransformationType[] getSupportedTransformationTypes(); static final String[] join_types; static final boolean[] one_optionals; static final boolean[] two_optionals; }### Answer:
@Test public void cloneTest() throws Exception { MergeJoinMeta meta = new MergeJoinMeta(); meta.allocate( 2, 3 ); meta.setKeyFields1( new String[] { "kf1-1", "kf1-2" } ); meta.setKeyFields2( new String[] { "kf2-1", "kf2-2", "kf2-3" } ); meta.setJoinType( "INNER" ); MergeJoinMeta aClone = (MergeJoinMeta) meta.clone(); assertFalse( aClone == meta ); assertTrue( Arrays.equals( meta.getKeyFields1(), aClone.getKeyFields1() ) ); assertTrue( Arrays.equals( meta.getKeyFields2(), aClone.getKeyFields2() ) ); assertEquals( meta.getJoinType(), aClone.getJoinType() ); assertNotNull( aClone.getStepIOMeta() ); assertFalse( meta.getStepIOMeta() == aClone.getStepIOMeta() ); List<StreamInterface> infoStreams = meta.getStepIOMeta().getInfoStreams(); List<StreamInterface> cloneInfoStreams = aClone.getStepIOMeta().getInfoStreams(); assertFalse( infoStreams == cloneInfoStreams ); int streamSize = infoStreams.size(); assertTrue( streamSize == cloneInfoStreams.size() ); for ( int i = 0; i < streamSize; i++ ) { assertFalse( infoStreams.get( i ) == cloneInfoStreams.get( i ) ); } } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.