public Object [ ] getArgValues ( ApplicationContext applicationContext ) { List < Object > argValues = new ArrayList <> ( ) ; try { if ( args != null ) { for ( MethodArg methodArg : args . getArgs ( ) ) { Class argType = Class . forName ( methodArg . getType ( ) ) ; Object value = null ; if ( methodArg . getValueObject ( ) != null ) { value = methodArg . getValueObject ( ) ; } else if ( methodArg . getValue ( ) != null ) { value = methodArg . getValue ( ) ; } else if ( StringUtils . hasText ( methodArg . getRef ( ) ) && applicationContext != null ) { value = applicationContext . getBean ( methodArg . getRef ( ) ) ; } if ( value == null ) { argValues . add ( null ) ; } else if ( argType . isInstance ( value ) || argType . isAssignableFrom ( value . getClass ( ) ) ) { argValues . add ( argType . cast ( value ) ) ; } else if ( Map . class . equals ( argType ) ) { String mapString = value . toString ( ) ; Properties props = new Properties ( ) ; try { props . load ( new StringReader ( mapString . substring ( 1 , mapString . length ( ) - 1 ) . replace ( ", " , "\n" ) ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to reconstruct method argument of type map" , e ) ; } Map < String , String > map = new LinkedHashMap <> ( ) ; for ( Map . Entry < Object , Object > entry : props . entrySet ( ) ) { map . put ( entry . getKey ( ) . toString ( ) , entry . getValue ( ) . toString ( ) ) ; } argValues . add ( map ) ; } else { try { argValues . add ( new SimpleTypeConverter ( ) . convertIfNecessary ( value , argType ) ) ; } catch ( ConversionNotSupportedException e ) { if ( String . class . equals ( argType ) ) { argValues . add ( value . toString ( ) ) ; } throw e ; } } } } } catch ( ClassNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to construct method arg objects" , e ) ; } return argValues . toArray ( new Object [ argValues . size ( ) ] ) ; }
Gets method args as objects . Automatically converts simple types and ready referenced beans .