package tests.jfun.yan.xml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import tests.jfun.yan.xml.nuts.Listener;
import jfun.yan.Container;
import jfun.yan.lifecycle.DefaultLifecycleManager;
import jfun.yan.xml.NutsProcessor;
import junit.framework.TestCase;
public class DeclarativenessPluginTestCase extends TestCase {
private DefaultLifecycleManager manager;
private Container yan;
private NutsProcessor interpreter;
protected void setUp() throws Exception {
super.setUp();
interpreter = new NutsProcessor();
interpreter.registerService("echo_msg", "there ya go:");
yan = interpreter.getContainer();
manager = interpreter.getLifecycleManager();
}
protected void tearDown() throws Exception {
// TODO Auto-generated method stub
super.tearDown();
}
public void test1()
throws IOException{
final ArrayList cache = new ArrayList();
final Listener l = new Listener(){
public void onInstance(Object obj){
cache.add(obj);
}
};
final NutsProcessor meta = interpreter.createMetaInterpreter();
meta.getContainer().registerValue(l);
meta.processResource("tests/jfun/yan/xml/nuts/listeners.xml");
interpreter.loadNutsFromContainer(meta.getContainer());
interpreter.processFile("test/yan/test_pluggable_declarativeness.xml");
final List instances = yan.getInstances();
assertEquals(1, cache.size());
assertSame(cache.get(0), instances.get(0));
assertSame(cache.get(0), instances.get(2));
}
}