package tests.jfun.yan.spring;
import java.io.IOException;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import jfun.yan.Components;
import jfun.yan.Container;
import jfun.yan.containers.ManualContainer;
import jfun.yan.factory.Factory;
import jfun.yan.spring.Container2ApplicationContext;
import jfun.yan.spring.SpringAdapter;
import jfun.yan.spring.SpringContext;
import jfun.yan.xml.NutsProcessor;
import jfun.yan.xml.nuts.spring.SpringNuts;
import junit.framework.TestCase;
public class SpringIntegrationTestCase extends TestCase {
/*
public void test1()
throws Exception{
final Container yan = new ManualContainer();
final BeanFactory factory = new Container2ApplicationContext("test1", yan);
final ProxyFactoryBean pfb = new ProxyFactoryBean();
final InterceptorA interceptor = new InterceptorA();
yan.registerComponent("interceptorA", Components.value(interceptor));
final Hello hello = new Hello();
hello.setMsg("hello");
pfb.setSingleton(true);
pfb.setTarget(hello);
pfb.setInterceptorNames(new String[]{"interceptorA"});
SpringAdapter.injectBean(pfb, new AbstractSpringContext(){
public String getTagName(){return "myController";}
public ApplicationContext getApplicationContext(){
return factory;
}
}, null, null, null);
final Object r = pfb.getObject();
if(r instanceof Greeter){
((Greeter)r).greet();
}
else{
fail("Greeter expected, "+r.getClass().getName()+" encountered");
}
}*/
public void test2()
throws IOException{
final NutsProcessor interpreter = new NutsProcessor();
SpringNuts.setSpringAware("test2", interpreter);
interpreter.processFile("test/yan/test_spring.xml");
final Container yan = interpreter.getContainer();
final Greeter greeter = (Greeter)yan
.getInstance("myController");
greeter.greet();
final Factory factory = (Factory)yan.getInstance("myfactory");
factory.create();
final Factory factory2 = (Factory)yan.getInstance("myfactory2");
factory2.create();
final FactoryBean fb = SpringAdapter.getFactoryBean(yan, "myController");
assertNotNull(fb);
}
}