Search in sources :

Example 6 with BeanInjector

use of org.pentaho.di.core.injection.bean.BeanInjector in project pentaho-kettle by pentaho.

the class MetaAnnotationInjectionTest method testInjectionForArrayPropertyWithoutDefaultConstructor_class_parameter.

@Test
public void testInjectionForArrayPropertyWithoutDefaultConstructor_class_parameter() throws KettleException {
    BeanInjector beanInjector = buildBeanInjectorFor(MetadataBean.class);
    MetadataBean targetBean = new MetadataBean();
    beanInjector.setProperty(targetBean, COMPLEX_NAME, createRowMetaAndData(), FIELD_ONE);
    assertNotNull(targetBean.getComplexField());
    assertTrue(targetBean.getComplexField().length == 1);
    assertEquals(TEST_NAME, targetBean.getComplexField()[0].getFieldName());
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) Test(org.junit.Test)

Example 7 with BeanInjector

use of org.pentaho.di.core.injection.bean.BeanInjector in project pentaho-kettle by pentaho.

the class MetaAnnotationInjectionTest method testInjectionSets.

@Test
public void testInjectionSets() throws Exception {
    MetaBeanLevel1 obj = new MetaBeanLevel1();
    RowMeta meta = new RowMeta();
    meta.addValueMeta(new ValueMetaString("f1"));
    meta.addValueMeta(new ValueMetaString("f2"));
    meta.addValueMeta(new ValueMetaString("fstrint"));
    meta.addValueMeta(new ValueMetaString("fstrlong"));
    // TODO STLOCALE
    meta.addValueMeta(new ValueMetaString("fstrboolean"));
    List<RowMetaAndData> rows = new ArrayList<>();
    rows.add(new RowMetaAndData(meta, "<sep>", "/tmp/file.txt", "123", "1234567891213", "y"));
    rows.add(new RowMetaAndData(meta, "<sep>", "/tmp/file2.txt", "123", "1234567891213", "y"));
    BeanInjector inj = buildBeanInjectorFor(MetaBeanLevel1.class);
    inj.setProperty(obj, "SEPARATOR", rows, "f1");
    inj.setProperty(obj, "FILENAME", rows, "f2");
    inj.setProperty(obj, "FILENAME_ARRAY", rows, "f2");
    inj.setProperty(obj, "FBOOLEAN", rows, "fstrboolean");
    inj.setProperty(obj, "FINT", rows, "fstrint");
    inj.setProperty(obj, "FLONG", rows, "fstrlong");
    inj.setProperty(obj, "FIRST", rows, "fstrint");
    assertEquals("<sep>", obj.getSub().getSeparator());
    assertEquals("/tmp/file.txt", obj.getSub().getFiles()[0].getName());
    assertTrue(obj.fboolean);
    assertEquals(123, obj.fint);
    assertEquals(1234567891213L, obj.flong);
    assertEquals("123", obj.getSub().first());
    assertArrayEquals(new String[] { "/tmp/file.txt", "/tmp/file2.txt" }, obj.getSub().getFilenames());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with BeanInjector

use of org.pentaho.di.core.injection.bean.BeanInjector in project pentaho-kettle by pentaho.

the class MetaAnnotationInjectionTest method testInjectionForArrayPropertyWithoutDefaultConstructor_interface_parameter.

@Test
public void testInjectionForArrayPropertyWithoutDefaultConstructor_interface_parameter() throws KettleException {
    BeanInjector beanInjector = buildBeanInjectorFor(MetadataBeanImplementsInterface.class);
    MetadataBeanImplementsInterface targetBean = new MetadataBeanImplementsInterface();
    beanInjector.setProperty(targetBean, COMPLEX_NAME, createRowMetaAndData(), FIELD_ONE);
    assertNotNull(targetBean.getComplexField());
    assertTrue(targetBean.getComplexField().length == 1);
    assertEquals(TEST_NAME, targetBean.getComplexField()[0].getFieldName());
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) Test(org.junit.Test)

Example 9 with BeanInjector

use of org.pentaho.di.core.injection.bean.BeanInjector in project pentaho-kettle by pentaho.

the class MetaAnnotationInjectionTest method testInjectionConstant.

@Test
public void testInjectionConstant() throws Exception {
    MetaBeanLevel1 obj = new MetaBeanLevel1();
    BeanInjector inj = buildBeanInjectorFor(MetaBeanLevel1.class);
    inj.setProperty(obj, "SEPARATOR", null, "<sep>");
    inj.setProperty(obj, "FINT", null, "123");
    inj.setProperty(obj, "FLONG", null, "1234567891213");
    inj.setProperty(obj, "FBOOLEAN", null, "true");
    inj.setProperty(obj, "FILENAME", null, "f1");
    inj.setProperty(obj, "FILENAME_ARRAY", null, "f2");
    assertEquals("<sep>", obj.getSub().getSeparator());
    assertTrue(obj.fboolean);
    assertEquals(123, obj.fint);
    assertEquals(1234567891213L, obj.flong);
    assertNull(obj.getSub().getFiles());
    assertNull(obj.getSub().getFilenames());
    obj.getSub().files = new MetaBeanLevel3[] { new MetaBeanLevel3(), new MetaBeanLevel3() };
    obj.getSub().filenames = new String[] { "", "", "" };
    inj.setProperty(obj, "FILENAME", null, "f1");
    inj.setProperty(obj, "FILENAME_ARRAY", null, "f2");
    assertEquals(2, obj.getSub().getFiles().length);
    assertEquals("f1", obj.getSub().getFiles()[0].getName());
    assertEquals("f1", obj.getSub().getFiles()[1].getName());
    assertArrayEquals(new String[] { "f2", "f2", "f2" }, obj.getSub().getFilenames());
}
Also used : BeanInjector(org.pentaho.di.core.injection.bean.BeanInjector) Test(org.junit.Test)

Aggregations

BeanInjector (org.pentaho.di.core.injection.bean.BeanInjector)9 BeanInjectionInfo (org.pentaho.di.core.injection.bean.BeanInjectionInfo)5 Test (org.junit.Test)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)2 ArrayList (java.util.ArrayList)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1