*/
@Test
public void testSettingProperties()
throws SAXException, IOException
{
Digester digester = newLoader( new AbstractRulesModule()
{
@Override
protected void configure()
{
forPattern( "employee" ).createObject().ofType( Employee.class )
.then()
.callMethod( "setLastName" ).withParamTypes( "java.lang.String" );
forPattern( "employee/lastName" ).callParam().ofIndex( 0 );
}
}).newDigester();
// Parse our test input
// an exception will be thrown if the method can't be found
Employee employee = digester.parse( getInputStream( "Test5.xml" ) );
assertEquals( "Failed to call Employee.setLastName", "Last Name", employee.getLastName() );
digester = newLoader( new AbstractRulesModule()
{
@Override
protected void configure()
{
forPattern( "employee" ).createObject().ofType( Employee.class )
.then()
.callMethod( "setAge" ).withParamTypes( int.class );
forPattern( "employee/age" ).callParam();
}
}).newDigester();
// Parse our test input
// an exception will be thrown if the method can't be found
employee = digester.parse( getInputStream( "Test5.xml" ) );
assertEquals( "Failed to call Employee.setAge", 21, employee.getAge() );
digester = newLoader( new AbstractRulesModule()
{
@Override
protected void configure()
{
forPattern( "employee" ).createObject().ofType( Employee.class )
.then()
.callMethod( "setActive" ).withParamTypes( boolean.class );
forPattern( "employee/active" ).callParam();
}
}).newDigester();
// Parse our test input
// an exception will be thrown if the method can't be found
employee = digester.parse( getInputStream( "Test5.xml" ) );
assertEquals( "Failed to call Employee.setActive", true, employee.isActive() );
digester = newLoader( new AbstractRulesModule()
{
@Override
protected void configure()
{