Search in sources :

Example 26 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class ExcelWriterStepTest method testInjection.

@Test
public void testInjection() {
    ExcelWriterStepMeta meta = new ExcelWriterStepMeta();
    try {
        List<StepInjectionMetaEntry> entries = stepMeta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
        for (StepInjectionMetaEntry entry : entries) {
            switch(entry.getValueType()) {
                case ValueMetaInterface.TYPE_STRING:
                    entry.setValue("new_".concat(entry.getKey()));
                    break;
                case ValueMetaInterface.TYPE_BOOLEAN:
                    entry.setValue(Boolean.TRUE);
                    break;
                default:
                    break;
            }
            if (!entry.getDetails().isEmpty()) {
                List<StepInjectionMetaEntry> childEntries = entry.getDetails().get(0).getDetails();
                for (StepInjectionMetaEntry childEntry : childEntries) {
                    switch(childEntry.getValueType()) {
                        case ValueMetaInterface.TYPE_STRING:
                            childEntry.setValue("new_".concat(childEntry.getKey()));
                            break;
                        case ValueMetaInterface.TYPE_BOOLEAN:
                            childEntry.setValue(Boolean.TRUE);
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        stepMeta.getStepMetaInjectionInterface().injectStepMetadataEntries(entries);
        assertEquals("Cell comment not properly injected... ", "new_CELLCOMMENT", stepMeta.getOutputFields()[0].getCommentField());
        assertEquals("Format not properly injected... ", "new_FORMAT", stepMeta.getOutputFields()[0].getFormat());
        assertEquals("Hyperlink not properly injected... ", "new_HYPERLINKFIELD", stepMeta.getOutputFields()[0].getHyperlinkField());
        assertEquals("Name not properly injected... ", "new_NAME", stepMeta.getOutputFields()[0].getName());
        assertEquals("Style cell not properly injected... ", "new_STYLECELL", stepMeta.getOutputFields()[0].getStyleCell());
        assertEquals("Title not properly injected... ", "new_FIELDTITLE", stepMeta.getOutputFields()[0].getTitle());
        assertEquals("Title style cell not properly injected... ", "new_TITLESTYLE", stepMeta.getOutputFields()[0].getTitleStyleCell());
        assertEquals("Type not properly injected... ", 0, stepMeta.getOutputFields()[0].getType());
        assertEquals("Comment author not properly injected... ", "new_COMMENTAUTHOR", stepMeta.getOutputFields()[0].getCommentAuthorField());
    } catch (KettleException e) {
        fail(e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Example 27 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class ExcelWriterStepTest method testTopLevelMetadataEntries.

@Test
public void testTopLevelMetadataEntries() {
    try {
        List<StepInjectionMetaEntry> entries = stepMeta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
        String masterKeys = "FIELDS";
        for (StepInjectionMetaEntry entry : entries) {
            String key = entry.getKey();
            assertTrue(masterKeys.contains(key));
            masterKeys = masterKeys.replace(key, "");
        }
        assertTrue(masterKeys.trim().length() == 0);
    } catch (KettleException e) {
        fail(e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Example 28 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class ExcelWriterStepTest method testChildLevelMetadataEntries.

@Test
public void testChildLevelMetadataEntries() {
    try {
        List<StepInjectionMetaEntry> entries = stepMeta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries();
        String childKeys = "NAME TYPE FORMAT STYLECELL FIELDTITLE TITLESTYLE " + "FORMULA HYPERLINKFIELD CELLCOMMENT COMMENTAUTHOR";
        StepInjectionMetaEntry mappingEntry = null;
        for (StepInjectionMetaEntry entry : entries) {
            String key = entry.getKey();
            if (key.equals("FIELDS")) {
                mappingEntry = entry;
                break;
            }
        }
        assertNotNull(mappingEntry);
        List<StepInjectionMetaEntry> fieldAttributes = mappingEntry.getDetails().get(0).getDetails();
        for (StepInjectionMetaEntry attribute : fieldAttributes) {
            String key = attribute.getKey();
            assertTrue(childKeys.contains(key));
            childKeys = childKeys.replace(key, "");
        }
        assertTrue(childKeys.trim().length() == 0);
    } catch (KettleException e) {
        fail(e.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Example 29 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TextFileInputMetaInjectionTest method extractingAll.

@Test
public void extractingAll() throws Exception {
    TextFileInputMetaInjection injection = new TextFileInputMetaInjection(new TextFileInputMeta());
    List<StepInjectionMetaEntry> metadata = injection.getStepInjectionMetadataEntries();
    List<StepInjectionMetaEntry> extracted = injection.extractStepMetadataEntries();
    assertEquals(metadata.size(), extracted.size());
    for (StepInjectionMetaEntry metaEntry : metadata) {
        assertNotNull(metaEntry.getKey(), StepInjectionUtil.findEntry(extracted, metaEntry.getKey()));
    }
}
Also used : StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry) Test(org.junit.Test)

Example 30 with StepInjectionMetaEntry

use of org.pentaho.di.trans.step.StepInjectionMetaEntry in project pentaho-kettle by pentaho.

the class TextFileInputMetaInjectionTest method assertInjected.

private static void assertInjected(List<StepInjectionMetaEntry> fields, List<StepInjectionMetaEntry> toBeInjected) {
    Map<String, StepInjectionMetaEntry> map = new HashMap<String, StepInjectionMetaEntry>(fields.size());
    for (StepInjectionMetaEntry field : fields) {
        map.put(field.getKey(), field);
    }
    for (StepInjectionMetaEntry entry : toBeInjected) {
        StepInjectionMetaEntry field = map.get(entry.getKey());
        assertNotNull(entry.getKey(), field);
        Object value = field.getValue();
        if (value == null) {
            assertNull(entry.getKey(), entry.getValue());
        } else {
            assertEquals(entry.getKey(), entry.getValue(), value);
        }
    }
}
Also used : HashMap(java.util.HashMap) StepInjectionMetaEntry(org.pentaho.di.trans.step.StepInjectionMetaEntry)

Aggregations

StepInjectionMetaEntry (org.pentaho.di.trans.step.StepInjectionMetaEntry)54 ArrayList (java.util.ArrayList)31 Test (org.junit.Test)17 KettleException (org.pentaho.di.core.exception.KettleException)10 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)6 KettleAttributeInterface (org.pentaho.di.core.KettleAttributeInterface)3 TextFileInputField (org.pentaho.di.trans.steps.textfileinput.TextFileInputField)2 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 FocusEvent (org.eclipse.swt.events.FocusEvent)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 ShellEvent (org.eclipse.swt.events.ShellEvent)1