KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > tests > jfun > yan > xml > BaseConfigurationTest


1 package tests.jfun.yan.xml;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.ByteArrayOutputStream JavaDoc;
5 import java.io.ObjectInputStream JavaDoc;
6 import java.io.ObjectOutputStream JavaDoc;
7 import java.util.HashMap JavaDoc;
8 import java.util.Set JavaDoc;
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 JavaDoc {
19     super.setUp();
20     final HashMap JavaDoc custom_naming_service = new HashMap JavaDoc();
21     custom_naming_service.put("tests/jfun/models/BankAccount/balance", new Integer JavaDoc(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 JavaDoc {
35     // TODO Auto-generated method stub
36
super.tearDown();
37   }
38   protected DefaultLifecycleManager manager;
39   protected Container yan;
40   protected NutsProcessor processor;
41
42   protected void runTest(String JavaDoc filename)
43   throws Throwable JavaDoc{
44     processor.processFile(filename);
45     final Set JavaDoc keys = yan.keys();
46     final HashMap JavaDoc result = new HashMap JavaDoc(keys.size());
47     //yan = trans(yan);
48
processor.preInstantiate(result);
49     //yan.getInstances(result);
50
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 JavaDoc, ClassNotFoundException JavaDoc{
58     ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
59     ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
60     
61     oos.writeObject(yan);
62     ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(baos.toByteArray()));
63     
64     return (Container) ois.readObject();
65   }
66
67 }
68
Popular Tags