package tests.jfun.yan.xml;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.Set;
import jfun.yan.Container;
import jfun.yan.PropertyBinder;
import jfun.yan.lifecycle.DefaultLifecycleManager;
import jfun.yan.xml.NutsProcessor;
import junit.framework.TestCase;
public abstract class BaseConfigurationTest extends TestCase {
protected void setUp() throws Exception {
super.setUp();
final HashMap custom_naming_service = new HashMap();
custom_naming_service.put("tests/jfun/models/BankAccount/balance", new Integer(1000));
custom_naming_service.put("tests/jfun/models/BankAccount/id", "auto lookup");
final PropertyBinder lookup = new NamingServiceWiring(custom_naming_service);
final PropertyBinder autolookup = new MapNamingServiceWiring("namingservice");
processor = new NutsProcessor();
processor.registerAutoWiring("lookup", lookup);
processor.registerAutoWiring("autolookup", autolookup);
processor.registerService("echo_msg", "there ya go:");
yan = processor.getContainer();
manager = processor.getLifecycleManager();
}
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
super.tearDown();
}
protected DefaultLifecycleManager manager;
protected Container yan;
protected NutsProcessor processor;
protected void runTest(String filename)
throws Throwable{
processor.processFile(filename);
final Set keys = yan.keys();
final HashMap result = new HashMap(keys.size());
//yan = trans(yan);
processor.preInstantiate(result);
//yan.getInstances(result);
manager.init();
manager.start();
manager.stop();
manager.dispose();
System.out.println(result);
}
protected Container trans(Container yan)
throws java.io.IOException, ClassNotFoundException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(yan);
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
return (Container) ois.readObject();
}
}