1 package tests.jfun.yan.xml; 2 3 import java.io.ByteArrayInputStream ; 4 import java.io.ByteArrayOutputStream ; 5 import java.io.ObjectInputStream ; 6 import java.io.ObjectOutputStream ; 7 import java.util.HashMap ; 8 import java.util.Set ; 9 10 import jfun.yan.Container; 11 import jfun.yan.PropertyBinder; 12 import jfun.yan.lifecycle.DefaultLifecycleManager; 13 import jfun.yan.xml.NutsProcessor; 14 import junit.framework.TestCase; 15 16 public abstract class BaseConfigurationTest extends TestCase { 17 18 protected void setUp() throws Exception { 19 super.setUp(); 20 final HashMap custom_naming_service = new HashMap (); 21 custom_naming_service.put("tests/jfun/models/BankAccount/balance", new Integer (1000)); 22 custom_naming_service.put("tests/jfun/models/BankAccount/id", "auto lookup"); 23 final PropertyBinder lookup = new NamingServiceWiring(custom_naming_service); 24 final PropertyBinder autolookup = new MapNamingServiceWiring("namingservice"); 25 26 processor = new NutsProcessor(); 27 processor.registerAutoWiring("lookup", lookup); 28 processor.registerAutoWiring("autolookup", autolookup); 29 processor.registerService("echo_msg", "there ya go:"); 30 yan = processor.getContainer(); 31 manager = processor.getLifecycleManager(); 32 } 33 34 protected void tearDown() throws Exception { 35 super.tearDown(); 37 } 38 protected DefaultLifecycleManager manager; 39 protected Container yan; 40 protected NutsProcessor processor; 41 42 protected void runTest(String filename) 43 throws Throwable { 44 processor.processFile(filename); 45 final Set keys = yan.keys(); 46 final HashMap result = new HashMap (keys.size()); 47 processor.preInstantiate(result); 49 manager.init(); 51 manager.start(); 52 manager.stop(); 53 manager.dispose(); 54 System.out.println(result); 55 } 56 protected Container trans(Container yan) 57 throws java.io.IOException , ClassNotFoundException { 58 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 59 ObjectOutputStream oos = new ObjectOutputStream (baos); 60 61 oos.writeObject(yan); 62 ObjectInputStream ois = new ObjectInputStream (new ByteArrayInputStream (baos.toByteArray())); 63 64 return (Container) ois.readObject(); 65 } 66 67 } 68 | Popular Tags |