zoukankan      html  css  js  c++  java
  • junit spring


    import org.apache.commons.lang3.StringUtils;
    import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;

    import com.opensymphony.xwork2.interceptor.annotations.After;
    import com.opensymphony.xwork2.interceptor.annotations.Before;

    public class UnitTestBean {
        private ClassPathXmlApplicationContext context;
        
        private String springXmlpath;
        
        public UnitTestBean(String springXmlpath){
            this.springXmlpath = springXmlpath;
        }
        
        @Before
        public void before(){
            System.out.println("springXmlpath = : "+springXmlpath);
            if(StringUtils.isEmpty(springXmlpath)){
                springXmlpath="classpath*:spring-*.xml";
            }
                context=new ClassPathXmlApplicationContext(springXmlpath.split("[,\s]+"));
                System.out.println("context new :  "+springXmlpath.split("[,\s]+"));
                context.start();
        }
        
        @After
        public void after() {
            context.destroy();
        }
        
        @SuppressWarnings("unchecked")
        protected <T extends Object>T getBean(String beanId){
            return(T)context.getBean(beanId);
        }
        
        protected <T extends Object>T getBean(Class<T> clazz){
            return context.getBean(clazz);
        }
        
        
    }

    import org.junit.runner.RunWith;
    import org.junit.runners.BlockJUnit4ClassRunner;


    @RunWith(BlockJUnit4ClassRunner.class)
    public class TestOneInterface extends UnitTestBean {

        public TestOneInterface() {
            super("classpath*:spring-ioc.xml");
        }
        
        @Test
        public void testSay() {
            OneInterface oneInterface = super.getBean("oneInterface");
            oneInterface.say("This is a test.");
        }

    }

  • 相关阅读:
    AlwaysOn 执行备份任务
    SQL Server 2016 + AlwaysOn 无域集群
    IIS负载均衡
    利用mapWithState实现按照首字母统计的有状态的wordCount
    DStream转为DF的两种方式(突破map时元组22的限制)
    java.lang.reflect.InvocationTargetException at shade.com.datastax.spark.connector.google.common.base.Throwables.propagate(Throwables.java160)
    java学习路线
    Java线程间通信
    多线程对象及变量的并发访问
    Java多线程基础
  • 原文地址:https://www.cnblogs.com/aiwoqu/p/4424822.html
Copyright © 2011-2022 走看看