Example usage for org.springframework.beans DirectFieldAccessor getPropertyValue

List of usage examples for org.springframework.beans DirectFieldAccessor getPropertyValue

Introduction

In this page you can find the example usage for org.springframework.beans DirectFieldAccessor getPropertyValue.

Prototype

@Override
    @Nullable
    public Object getPropertyValue(String propertyName) throws BeansException 

Source Link

Usage

From source file:com.manning.siia.kitchen.CookTest.java

@Test
public void shouldCookAllProducts() {
    Grocery grocery = mock(Grocery.class);
    Meat meat = mock(Meat.class);
    List<Message<Product>> products = Arrays.asList(wrapInMessage(grocery), wrapInMessage(meat));

    Meal meal = cook.prepareMeal(products);
    DirectFieldAccessor accessor = new DirectFieldAccessor(meal);
    assertThat((List<Product>) accessor.getPropertyValue("products"), hasItems(grocery, meat));
}

From source file:org.esupportail.sympa.test.IntroTest.java

public void testIntro() throws Exception {
    UserSympaList item = new UserSympaList();
    item.setEditor(true);//  w w  w .  j a  va  2s . c  o  m
    item.setOwner(false);
    item.setSubscriber(true);

    List<SympaListCriterion> crit = new ArrayList<SympaListCriterion>();
    crit.add(new SympaListCriterion(SympaListFields.editor, new Boolean(true)));
    crit.add(new SympaListCriterion(SympaListFields.owner, new Boolean(true)));
    crit.add(new SympaListCriterion(SympaListFields.subscriber, new Boolean(true)));

    DirectFieldAccessor accessor = new DirectFieldAccessor(item);
    System.out.println(accessor.getPropertyValue("editor").equals(new Boolean(false)));
    System.out.println(matchCriterion(item, crit));
}

From source file:de.tudarmstadt.ukp.clarin.webanno.support.EntityModel.java

private void analyze(T aObject) {
    if (aObject != null) {
        entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject);

        String idProperty = null;
        Metamodel metamodel = getEntityManager().getMetamodel();
        EntityType entity = metamodel.entity(entityClass);
        Set<SingularAttribute> singularAttributes = entity.getSingularAttributes();
        for (SingularAttribute singularAttribute : singularAttributes) {
            if (singularAttribute.isId()) {
                idProperty = singularAttribute.getName();
                break;
            }/* w  w w . ja v a  2s  . c om*/
        }
        if (idProperty == null) {
            throw new RuntimeException("id field not found");
        }

        DirectFieldAccessor accessor = new DirectFieldAccessor(aObject);
        id = (Number) accessor.getPropertyValue(idProperty);
    } else {
        entityClass = null;
        id = null;
    }
}

From source file:org.opencredo.cloud.storage.si.adapter.config.OutboundChannelAdapterParserTest.java

@Test
public void testOutboundAdapterLoadWithMinimumSettings() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "OutboundChannelAdapterParserTest-context.xml", this.getClass());

    Object bean = context.getBean("outbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());

    DirectFieldAccessor beanDirect = new DirectFieldAccessor(bean);
    Object value = beanDirect.getPropertyValue("handler");
    assertNotNull("'handler' not found", value);
    System.out.println(value.getClass());

    WritingMessageHandler a = (WritingMessageHandler) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(a);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
    assertNotNull("'blobNameBuilder' queue not found", adapterDirect.getPropertyValue("blobNameBuilder"));
    assertTrue(adapterDirect.getPropertyValue("blobNameBuilder") instanceof DefaultBlobNameBuilder);
}

From source file:org.opencredo.cloud.storage.si.adapter.config.OutboundChannelAdapterParserTest.java

@Test
public void testOutboundAdapterLoadWithFullSettings() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "OutboundChannelAdapterParserTest-full-context.xml", this.getClass());

    Object bean = context.getBean("outbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());

    DirectFieldAccessor beanDirect = new DirectFieldAccessor(bean);
    Object value = beanDirect.getPropertyValue("handler");
    assertNotNull("'handler' not found", value);
    System.out.println(value.getClass());

    WritingMessageHandler a = (WritingMessageHandler) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(a);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
    assertNotNull("'blobNameBuilder' queue not found", adapterDirect.getPropertyValue("blobNameBuilder"));
    assertTrue(adapterDirect.getPropertyValue("blobNameBuilder") instanceof MockBlobNameBuilder);
}

From source file:org.opencredo.cloud.storage.si.adapter.config.InboundChannelAdapterParserTest.java

@Test
public void testInboundAdapterLoadWithMinimumSettings() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "InboundChannelAdapterParserTest-context.xml", this.getClass());

    Object bean = context.getBean("inbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());
    DirectFieldAccessor d = new DirectFieldAccessor(bean);
    Object value = d.getPropertyValue("source");
    assertNotNull("Source not found", value);
    System.out.println(value.getClass());

    ReadingMessageSource rms = (ReadingMessageSource) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(rms);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertNotNull("'filter' queue not found", adapterDirect.getPropertyValue("filter"));
    assertTrue(adapterDirect.getPropertyValue("filter") instanceof AcceptOnceBlobNameFilter);
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
}

From source file:org.opencredo.cloud.storage.si.adapter.config.InboundChannelAdapterParserTest.java

@Test
public void testInboundAdapterLoadWithFilter() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "InboundChannelAdapterParserTest-withFilter-context.xml", this.getClass());

    Object bean = context.getBean("inbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());
    DirectFieldAccessor d = new DirectFieldAccessor(bean);
    Object value = d.getPropertyValue("source");
    assertNotNull("Source not found", value);
    System.out.println(value.getClass());

    ReadingMessageSource rms = (ReadingMessageSource) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(rms);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertNotNull("'filter' queue not found", adapterDirect.getPropertyValue("filter"));
    assertTrue(adapterDirect.getPropertyValue("filter") instanceof PatternMatchingBlobNameFilter);
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
}

From source file:org.opencredo.cloud.storage.si.adapter.config.InboundChannelAdapterParserTest.java

@Test
public void testInboundAdapterLoadWithComparator() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "InboundChannelAdapterParserTest-withComparator-context.xml", this.getClass());

    Object bean = context.getBean("inbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());
    DirectFieldAccessor d = new DirectFieldAccessor(bean);
    Object value = d.getPropertyValue("source");
    assertNotNull("Source not found", value);
    System.out.println(value.getClass());

    ReadingMessageSource rms = (ReadingMessageSource) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(rms);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertNotNull("'filter' queue not found", adapterDirect.getPropertyValue("filter"));
    assertTrue(adapterDirect.getPropertyValue("filter") instanceof AcceptOnceBlobNameFilter);
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
}

From source file:org.opencredo.cloud.storage.si.adapter.config.InboundChannelAdapterParserTest.java

@Test
public void testInboundAdapterLoadFull() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
            "InboundChannelAdapterParserTest-full-context.xml", this.getClass());

    Object bean = context.getBean("inbound-adapter");
    assertNotNull("Adapter not found", bean);
    System.out.println(bean.getClass());
    DirectFieldAccessor d = new DirectFieldAccessor(bean);
    Object value = d.getPropertyValue("source");
    assertNotNull("Source not found", value);
    System.out.println(value.getClass());

    ReadingMessageSource rms = (ReadingMessageSource) value;
    DirectFieldAccessor adapterDirect = new DirectFieldAccessor(rms);
    assertNotNull("'template' not found", adapterDirect.getPropertyValue("template"));
    assertNotNull("'filter' queue not found", adapterDirect.getPropertyValue("filter"));
    assertTrue(adapterDirect.getPropertyValue("filter") instanceof PatternMatchingBlobNameFilter);
    assertEquals(TestPropertiesAccessor.getDefaultContainerName(),
            adapterDirect.getPropertyValue("containerName"));
}

From source file:multibinder.TwoKafkaBindersApplicationTest.java

@Test
public void contextLoads() {
    Binder<MessageChannel, ?, ?> binder1 = binderFactory.getBinder("kafka1");
    KafkaMessageChannelBinder kafka1 = (KafkaMessageChannelBinder) binder1;
    DirectFieldAccessor directFieldAccessor1 = new DirectFieldAccessor(kafka1);
    KafkaBinderConfigurationProperties configuration1 = (KafkaBinderConfigurationProperties) directFieldAccessor1
            .getPropertyValue("configurationProperties");
    Assert.assertThat(configuration1.getBrokers(), arrayWithSize(1));
    Assert.assertThat(configuration1.getBrokers()[0], equalTo(kafkaTestSupport1.getBrokersAsString()));

    Binder<MessageChannel, ?, ?> binder2 = binderFactory.getBinder("kafka2");
    KafkaMessageChannelBinder kafka2 = (KafkaMessageChannelBinder) binder2;
    DirectFieldAccessor directFieldAccessor2 = new DirectFieldAccessor(kafka2);
    KafkaBinderConfigurationProperties configuration2 = (KafkaBinderConfigurationProperties) directFieldAccessor2
            .getPropertyValue("configurationProperties");
    Assert.assertThat(configuration2.getBrokers(), arrayWithSize(1));
    Assert.assertThat(configuration2.getBrokers()[0], equalTo(kafkaTestSupport2.getBrokersAsString()));
}