1 4 package org.oddjob.arooa.handlers; 5 6 import java.io.File ; 7 8 import junit.framework.TestCase; 9 10 import org.apache.log4j.Logger; 11 import org.oddjob.arooa.ArooaConstants; 12 import org.oddjob.arooa.ArooaContext; 13 import org.oddjob.arooa.ArooaRuntime; 14 import org.oddjob.arooa.SimpleObjectFactory; 15 import org.oddjob.arooa.registry.ComponentRegistry; 16 import org.oddjob.persist.OddjobPersistException; 17 import org.oddjob.persist.SerializePersister; 18 import org.xml.sax.SAXParseException ; 19 import org.xml.sax.helpers.AttributesImpl ; 20 21 25 public class SerializedComponentHandlerTest extends TestCase { 26 27 File dir = new File ("test/persist"); 28 String id = "serialized-handler-test"; 29 Logger logger = Logger.getLogger("test"); 30 DummyComponent foo; 31 32 37 public void testGoodLoad() 38 throws OddjobPersistException, 39 SAXParseException { 40 DummyComponent test = new DummyComponent(); 42 test.setFoo("Hello World"); 43 SerializePersister persister = new SerializePersister(); 44 persister.setDir(dir); 45 persister.persist(id, test); 46 DefaultComponentHandler def = new DefaultComponentHandler(); 48 SerializedComponentHandler handler 49 = new SerializedComponentHandler(def, persister); 50 ArooaContext context = new ArooaContext(); 51 context.set(ArooaConstants.COMPONENT_FACTORY, new SimpleObjectFactory()); 52 context.set(ArooaConstants.COMPONENT_REGISTRY, new ComponentRegistry()); 53 context.set(ArooaConstants.CURRENTLY_CONFIGURING, new ArooaRuntime(this, "test")); 54 context.set(ArooaConstants.ELEMENT_NAME, "foo"); 55 context = new ArooaContext(context); 56 57 AttributesImpl atts = new AttributesImpl (); 58 atts.addAttribute("", "id", "id", "java.lang.String", id); 59 handler.onStartElement("", "foo", "foo", atts, context); 61 handler.onEndElement("", "foo", context); 63 64 assertTrue("Component not equal to that saved", test.getFoo().equals(foo.getFoo())); 65 } 66 67 public void addComponentFoo(DummyComponent foo) { 68 this.foo = foo; 69 } 70 } 71 | Popular Tags |