public void testInjectionEntries() throws Exception { JaninoMeta meta = populateJaninoMeta(); List<StepInjectionMetaEntry> entries = meta.getStepMetaInjectionInterface().getStepInjectionMetadataEntries(); assertEquals(1, entries.size()); StepInjectionMetaEntry fieldsEntry = StepInjectionUtil.findEntry(entries, JaninoMetaInjection.Entry.EXPRESSION_FIELDS); assertNotNull(fieldsEntry); StepInjectionMetaEntry fieldEntry = StepInjectionUtil.findEntry( fieldsEntry.getDetails(), JaninoMetaInjection.Entry.EXPRESSION_FIELD); assertNotNull(fieldEntry); assertNotNull( StepInjectionUtil.findEntry( fieldEntry.getDetails(), JaninoMetaInjection.Entry.NEW_FIELDNAME)); assertNotNull( StepInjectionUtil.findEntry( fieldEntry.getDetails(), JaninoMetaInjection.Entry.JAVA_EXPRESSION)); assertNotNull( StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.VALUE_TYPE)); assertNotNull( StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.LENGTH)); assertNotNull( StepInjectionUtil.findEntry(fieldEntry.getDetails(), JaninoMetaInjection.Entry.PRECISION)); assertNotNull( StepInjectionUtil.findEntry( fieldEntry.getDetails(), JaninoMetaInjection.Entry.REPLACE_VALUE)); }
@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())); } }
private static List<StepInjectionMetaEntry> createInjectionValues( TextFileInputMetaInjection.Entry[] entries) { Map<TextFileInputMetaInjection.Entry, Generator<?>> generators = createGeneratorsMapping(); List<StepInjectionMetaEntry> result = new ArrayList<StepInjectionMetaEntry>(entries.length); for (TextFileInputMetaInjection.Entry entry : entries) { StepInjectionMetaEntry injectionEntry = StepInjectionUtil.getEntry(entry); if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) { injectionEntry.setValue(generators.get(entry).generateValue()); } result.add(injectionEntry); } return result; }
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); } } }
public void injectStepMetadataEntries(List<StepInjectionMetaEntry> metadata) { for (StepInjectionMetaEntry entry : metadata) { KettleAttributeInterface attr = findAttribute(entry.getKey()); // Set top level attributes... // if (entry.getValueType() != ValueMetaInterface.TYPE_NONE) { if (entry.getKey().equals("SCHEMA")) { schemaName = (String) entry.getValue(); } else if (entry.getKey().equals("TABLE")) { tableName = (String) entry.getValue(); } else if (entry.getKey().equals("LOADACTION")) { loadAction = (String) entry.getValue(); } else if (entry.getKey().equals("PSQLPATH")) { setPsqlpath((String) entry.getValue()); } else if (entry.getKey().equals("DBNAMEOVERRIDE")) { dbNameOverride = (String) entry.getValue(); } else if (entry.getKey().equals("ENCLOSURE")) { enclosure = (String) entry.getValue(); } else if (entry.getKey().equals("DELIMITER")) { delimiter = (String) entry.getValue(); } else if (entry.getKey().equals("STOPONERROR")) { stopOnError = (Boolean) entry.getValue(); } else { throw new RuntimeException( "Unhandled metadata injection of attribute: " + attr.toString() + " - " + attr.getDescription()); } } else { // The data sets... // if (attr.getKey().equals("MAPPINGS")) { List<StepInjectionMetaEntry> selectMappings = entry.getDetails(); fieldTable = new String[selectMappings.size()]; fieldStream = new String[selectMappings.size()]; dateMask = new String[selectMappings.size()]; for (int row = 0; row < selectMappings.size(); row++) { StepInjectionMetaEntry selectField = selectMappings.get(row); List<StepInjectionMetaEntry> fieldAttributes = selectField.getDetails(); // CHECKSTYLE:Indentation:OFF for (int i = 0; i < fieldAttributes.size(); i++) { StepInjectionMetaEntry fieldAttribute = fieldAttributes.get(i); KettleAttributeInterface fieldAttr = findAttribute(fieldAttribute.getKey()); String attributeValue = (String) fieldAttribute.getValue(); if (fieldAttr.getKey().equals("STREAMNAME")) { getFieldStream()[row] = attributeValue; } else if (fieldAttr.getKey().equals("FIELDNAME")) { getFieldTable()[row] = attributeValue; } else if (fieldAttr.getKey().equals("DATEMASK")) { getDateMask()[row] = attributeValue; } else { throw new RuntimeException( "Unhandled metadata injection of attribute: " + fieldAttr.toString() + " - " + fieldAttr.getDescription()); } } } } if (!Const.isEmpty(getFieldStream())) { for (int i = 0; i < getFieldStream().length; i++) { logDetailed( "row " + Integer.toString(i) + ": stream=" + getFieldStream()[i] + " : table=" + getFieldTable()[i]); } } } } }