Package org.jtester.annotations

Examples of org.jtester.annotations.SpringBeanByName


  public void injectBy(JTesterBeanFactory beanFactory, Object testedObject, Class<? extends Annotation> annotation) {
    Class testedClazz = testedObject.getClass();
    Set<Field> fields = getFieldsAnnotatedWith(testedClazz, SpringBeanByName.class);
    for (Field field : fields) {
      try {
        SpringBeanByName byName = field.getAnnotation(SpringBeanByName.class);
        String beanName = byName.value();
        if (StringHelper.isBlankOrNull(byName.value())) {
          beanName = field.getName();
        }
        Object bean = beanFactory.getBean(beanName);
        FieldHelper.setFieldValue(testedObject, field, bean);
      } catch (Throwable e) {
View Full Code Here


    return fields;
  }

  @Override
  protected void initSpringBean(final Field field, final BeanMeta beanMeta) {
    SpringBeanByName byName = field.getAnnotation(SpringBeanByName.class);

    beanMeta.beanName = field.getName();
    if (StringHelper.isBlankOrNull(byName.value()) == false) {
      beanMeta.beanName = byName.value();
    }
    beanMeta.initMethod = byName.init();
    beanMeta.beanClaz = byName.claz();
    beanMeta.properties = byName.properties();
  }
View Full Code Here

  public static void injectSpringBeanByName(final ApplicationContext ctx, final Class testedClazz,
      final Object testedObject) {
    Set<Field> springBeanByNamefields = getFieldsAnnotatedWith(testedClazz, SpringBeanByName.class);
    for (Field field : springBeanByNamefields) {
      try {
        SpringBeanByName byName = field.getAnnotation(SpringBeanByName.class);
        String beanName = field.getName();
        if (StringHelper.isBlankOrNull(byName.value()) == false) {
          beanName = byName.value();
        }
        FieldHelper.setFieldValue(testedObject, field, ctx.getBean(beanName));
      } catch (Throwable e) {
        throw new JTesterException(
            "Unable to assign the Spring bean value to field annotated with @SpringBeanByName", e);
View Full Code Here

TOP

Related Classes of org.jtester.annotations.SpringBeanByName

Copyright © 2018 www.massapicom. 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.