@Test @PrepareForTest( { EnvUtil.class } ) public void testLoadXML() throws KettleValueException, KettlePluginException, ParseException { PowerMockito.mockStatic( EnvUtil.class ); Mockito.when( EnvUtil.getSystemProperty( Const.KETTLE_DEFAULT_DATE_FORMAT ) ).thenReturn( "yyyy-MM-dd HH:mm:ss.SSS" ); ValueMetaAndData valueMetaAndData = new ValueMetaAndData( Mockito.mock( ValueMetaInterface.class ), new Object() ); PluginRegistry pluginRegistry = Mockito.mock( PluginRegistry.class ); List<PluginInterface> pluginTypeList = new ArrayList<>(); PluginInterface plugin = Mockito.mock( PluginInterface.class ); Mockito.when( plugin.getName() ).thenReturn( "3" ); String[] ids = { "3" }; Mockito.when( plugin.getIds() ).thenReturn( ids ); pluginTypeList.add( plugin ); Mockito.when( pluginRegistry.getPlugins( ValueMetaPluginType.class ) ).thenReturn( pluginTypeList ); ValueMetaFactory.pluginRegistry = pluginRegistry; NodeList nodeList = Mockito.mock( NodeList.class ); Mockito.when( nodeList.getLength() ).thenReturn( 2 ); Node node = Mockito.mock( Node.class ); Mockito.when( node.getChildNodes() ).thenReturn( nodeList ); Node childNodeText = Mockito.mock( Node.class ); Mockito.when( childNodeText.getNodeName() ).thenReturn( "text" ); Mockito.when( nodeList.item( 0 ) ).thenReturn( childNodeText ); Node nodeValue = Mockito.mock( Node.class ); Mockito.when( childNodeText.getFirstChild() ).thenReturn( nodeValue ); String testData = "2010/01/01 00:00:00.000"; Mockito.when( nodeValue.getNodeValue() ).thenReturn( testData ); Node childNodeType = Mockito.mock( Node.class ); Mockito.when( childNodeType.getNodeName() ).thenReturn( "type" ); Mockito.when( nodeList.item( 1 ) ).thenReturn( childNodeType ); Node nodeTypeValue = Mockito.mock( Node.class ); Mockito.when( childNodeType.getFirstChild() ).thenReturn( nodeTypeValue ); Mockito.when( nodeTypeValue.getNodeValue() ).thenReturn( "3" ); valueMetaAndData.loadXML( node ); Assert.assertEquals( valueMetaAndData.getValueData(), new SimpleDateFormat( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ).parse( testData ) ); }
public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; }
ValueMetaAndData { public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; } }
ValueMetaAndData { public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; } ValueMetaAndData();  ValueMetaAndData( ValueMetaInterface valueMeta, Object valueData );  ValueMetaAndData( String valueName, Object valueData );  ValueMetaAndData( Node valnode ); }
ValueMetaAndData { public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; } ValueMetaAndData();  ValueMetaAndData( ValueMetaInterface valueMeta, Object valueData );  ValueMetaAndData( String valueName, Object valueData );  ValueMetaAndData( Node valnode ); @Override Object clone(); @Override String toString(); String getXML(); boolean loadXML( Node valnode ); String toStringMeta(); Object getValueData(); void setValueData( Object valueData ); ValueMetaInterface getValueMeta(); void setValueMeta( ValueMetaInterface valueMeta ); }
ValueMetaAndData { public boolean loadXML( Node valnode ) { valueMeta = null; try { String valname = XMLHandler.getTagValue( valnode, "name" ); int valtype = ValueMetaBase.getType( XMLHandler.getTagValue( valnode, "type" ) ); String text = XMLHandler.getTagValue( valnode, "text" ); boolean isnull = "Y".equalsIgnoreCase( XMLHandler.getTagValue( valnode, "isnull" ) ); int len = Const.toInt( XMLHandler.getTagValue( valnode, "length" ), -1 ); int prec = Const.toInt( XMLHandler.getTagValue( valnode, "precision" ), -1 ); String mask = XMLHandler.getTagValue( valnode, "mask" ); valueMeta = new ValueMeta( valname, valtype ); valueData = text; valueMeta.setLength( len ); valueMeta.setPrecision( prec ); if ( mask != null ) { valueMeta.setConversionMask( mask ); } if ( valtype != ValueMetaInterface.TYPE_STRING ) { ValueMetaInterface originMeta = new ValueMetaString( valname ); if ( valueMeta.isNumeric() ) { originMeta.setDecimalSymbol( "." ); originMeta.setGroupingSymbol( null ); originMeta.setCurrencySymbol( null ); } if ( valtype == ValueMetaInterface.TYPE_DATE ) { originMeta.setConversionMask( ValueMetaBase.COMPATIBLE_DATE_FORMAT_PATTERN ); } valueData = Const.trim( text ); valueData = valueMeta.convertData( originMeta, valueData ); } if ( isnull ) { valueData = null; } } catch ( Exception e ) { valueData = null; return false; } return true; } ValueMetaAndData();  ValueMetaAndData( ValueMetaInterface valueMeta, Object valueData );  ValueMetaAndData( String valueName, Object valueData );  ValueMetaAndData( Node valnode ); @Override Object clone(); @Override String toString(); String getXML(); boolean loadXML( Node valnode ); String toStringMeta(); Object getValueData(); void setValueData( Object valueData ); ValueMetaInterface getValueMeta(); void setValueMeta( ValueMetaInterface valueMeta ); static final String XML_TAG; static final String VALUE_REPOSITORY_NUMBER_CONVERSION_MASK; static final String VALUE_REPOSITORY_INTEGER_CONVERSION_MASK; static final String VALUE_REPOSITORY_DATE_CONVERSION_MASK; static final String VALUE_REPOSITORY_DECIMAL_SYMBOL; static final String VALUE_REPOSITORY_GROUPING_SYMBOL; }