public void testFactoryCreateRule()
throws Exception
{
// test passing object create
Digester digester = new Digester();
ObjectCreationFactoryTestImpl factory = new ObjectCreationFactoryTestImpl();
digester.addFactoryCreate( "root", factory, ignoreCreateExceptions );
String xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
digester.parse( new StringReader( xml ) );
assertEquals( "Object create not called(1)[" + ignoreCreateExceptions + "]", factory.called, true );
assertEquals( "Attribute not passed (1)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
"good" );
assertEquals( "Attribute not passed (2)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
"bad" );
assertEquals( "Attribute not passed (3)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
"ugly" );
digester = new Digester();
digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl",
ignoreCreateExceptions );
digester.addSetNext( "root", "add" );
xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
List<ObjectCreationFactoryTestImpl> list = new ArrayList<ObjectCreationFactoryTestImpl>();
digester.push( list );
digester.parse( new StringReader( xml ) );
assertEquals( "List should contain only the factory object", list.size(), 1 );
factory = list.get( 0 );
assertEquals( "Object create not called(2)[" + ignoreCreateExceptions + "]", factory.called, true );
assertEquals( "Attribute not passed (4)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
"good" );
assertEquals( "Attribute not passed (5)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
"bad" );
assertEquals( "Attribute not passed (6)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
"ugly" );
digester = new Digester();
digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
ignoreCreateExceptions );
digester.addSetNext( "root", "add" );
xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
list = new ArrayList<ObjectCreationFactoryTestImpl>();
digester.push( list );
digester.parse( new StringReader( xml ) );
assertEquals( "List should contain only the factory object", list.size(), 1 );
factory = list.get( 0 );
assertEquals( "Object create not called(3)[" + ignoreCreateExceptions + "]", factory.called, true );
assertEquals( "Attribute not passed (7)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
"good" );
assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
"bad" );
assertEquals( "Attribute not passed (8)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
"ugly" );
digester = new Digester();
digester.addFactoryCreate( "root", "org.apache.commons.digester3.ObjectCreationFactoryTestImpl", "override",
ignoreCreateExceptions );
digester.addSetNext( "root", "add" );
xml =
new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
+ " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
list = new ArrayList<ObjectCreationFactoryTestImpl>();
digester.push( list );
digester.parse( new StringReader( xml ) );
assertEquals( "List should contain only the factory object", list.size(), 1 );
factory = list.get( 0 );
assertEquals( "Attribute Override Failed (1)", factory.getClass().getName(),
"org.apache.commons.digester3.OtherTestObjectCreationFactory" );
assertEquals( "Object create not called(4)[" + ignoreCreateExceptions + "]", factory.called, true );
assertEquals( "Attribute not passed (10)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
"good" );
assertEquals( "Attribute not passed (11)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
"bad" );
assertEquals( "Attribute not passed (12)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
"ugly" );
digester = new Digester();
digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
digester.addSetNext( "root", "add" );
xml = new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly'><element/></root>" );
list = new ArrayList<ObjectCreationFactoryTestImpl>();
digester.push( list );
digester.parse( new StringReader( xml ) );
assertEquals( "List should contain only the factory object", list.size(), 1 );
factory = list.get( 0 );
assertEquals( "Object create not called(5)[" + ignoreCreateExceptions + "]", factory.called, true );
assertEquals( "Attribute not passed (13)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "one" ),
"good" );
assertEquals( "Attribute not passed (14)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "two" ),
"bad" );
assertEquals( "Attribute not passed (15)[" + ignoreCreateExceptions + "]", factory.attributes.getValue( "three" ),
"ugly" );
digester = new Digester();
digester.addFactoryCreate( "root", ObjectCreationFactoryTestImpl.class, "override", ignoreCreateExceptions );
digester.addSetNext( "root", "add" );
xml =
new String( "<?xml version='1.0' ?><root one='good' two='bad' three='ugly' "
+ " override='org.apache.commons.digester3.OtherTestObjectCreationFactory' >" + "<element/></root>" );
list = new ArrayList<ObjectCreationFactoryTestImpl>();
digester.push( list );
digester.parse( new StringReader( xml ) );
assertEquals( "List should contain only the factory object", list.size(), 1 );
factory = list.get( 0 );
assertEquals( "Attribute Override Failed (2)", factory.getClass().getName(),
"org.apache.commons.digester3.OtherTestObjectCreationFactory" );