Package org.jtester.fit.fixture

Source Code of org.jtester.fit.fixture.SpringFixture

package org.jtester.fit.fixture;

import org.jtester.annotations.SpringApplicationContext;
import org.jtester.core.IJTester;
import org.jtester.core.context.DbFitContext;
import org.jtester.core.context.DbFitContext.RunIn;
import org.jtester.fit.JTesterFixture;
import org.jtester.fit.spring.FixtureBeanInjector;
import org.jtester.fit.spring.RemoteInvokerRegister;
import org.jtester.fit.spring.FixtureSpringApplicationContext;
import org.jtester.utility.AnnotationUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class SpringFixture extends JTesterFixture implements IJTester {
  private ClassPathXmlApplicationContext ctx;

  /**
   * 注入spring bean
   */
  public SpringFixture() {
    DbFitContext.setRunIn(RunIn.FitNesse);

    SpringApplicationContext anotations = AnnotationUtils.getClassLevelAnnotation(SpringApplicationContext.class,
        this.getClass());
    if (anotations == null) {
      return;
    }
    try {
      String[] locations = anotations.value();
      boolean ignoreNoSuchBean = anotations.ignoreNoSuchBean();
      ctx = new FixtureSpringApplicationContext(locations, this.getClass(), ignoreNoSuchBean);
      FixtureBeanInjector.injectBeans(ctx, this);
      RemoteInvokerRegister.injectSpringBeanRemote(ctx, this);
    } catch (Throwable e) {
      e.printStackTrace();
      throw new RuntimeException("spring inject error", e);
    }
  }
}
TOP

Related Classes of org.jtester.fit.fixture.SpringFixture

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.