use of org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator in project pentaho-kettle by pentaho.
the class CombinationLookupMetaTest method setUpLoadSave.
@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
List<String> attributes = Arrays.asList("schemaName", "tableName", "databaseMeta", "replaceFields", "keyField", "keyLookup", "useHash", "hashField", "technicalKeyField", "sequenceFrom", "commitSize", "preloadCache", "cacheSize", "useAutoinc", "techKeyCreation", "lastUpdateField");
Map<String, String> getterMap = new HashMap<String, String>() {
{
put("replaceFields", "replaceFields");
put("useHash", "useHash");
}
};
Map<String, String> setterMap = new HashMap<String, String>() {
{
put("tableName", "setTablename");
}
};
FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);
Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put("keyField", stringArrayLoadSaveValidator);
attrValidatorMap.put("keyLookup", stringArrayLoadSaveValidator);
attrValidatorMap.put("databaseMeta", new DatabaseMetaLoadSaveValidator());
Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
loadSaveTester = new LoadSaveTester(testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(), getterMap, setterMap, attrValidatorMap, typeValidatorMap, this);
}
use of org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator in project pentaho-kettle by pentaho.
the class LoadSaveBase method createValidatorMapAndInvokeSetters.
@SuppressWarnings({ "unchecked" })
protected Map<String, FieldLoadSaveValidator<?>> createValidatorMapAndInvokeSetters(List<String> attributes, T metaToSave) {
Map<String, FieldLoadSaveValidator<?>> validatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
databases.clear();
for (String attribute : attributes) {
Getter<?> getter = manipulator.getGetter(attribute);
@SuppressWarnings("rawtypes") Setter setter = manipulator.getSetter(attribute);
FieldLoadSaveValidator<?> validator = fieldLoadSaveValidatorFactory.createValidator(getter);
try {
Object testValue = validator.getTestObject();
// no-inspection unchecked
setter.set(metaToSave, testValue);
if (testValue instanceof DatabaseMeta) {
addDatabase((DatabaseMeta) testValue);
} else if (testValue instanceof DatabaseMeta[]) {
addDatabase((DatabaseMeta[]) testValue);
}
} catch (Exception e) {
throw new RuntimeException("Unable to invoke setter for " + attribute, e);
}
validatorMap.put(attribute, validator);
}
return validatorMap;
}
use of org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator in project pentaho-kettle by pentaho.
the class LoadSaveTester method testXmlRoundTrip.
public void testXmlRoundTrip() throws KettleException {
T metaToSave = createMeta();
Map<String, FieldLoadSaveValidator<?>> validatorMap = createValidatorMapAndInvokeSetters(xmlAttributes, metaToSave);
T metaLoaded = createMeta();
String xml = "<step>" + metaToSave.getXML() + "</step>";
InputStream is = new ByteArrayInputStream(xml.getBytes());
metaLoaded.loadXML(XMLHandler.getSubNode(XMLHandler.loadXMLFile(is, null, false, false), "step"));
validateLoadedMeta(xmlAttributes, validatorMap, metaToSave, metaLoaded);
}
use of org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator in project pentaho-kettle by pentaho.
the class MappingInputMetaCloningTest method setUp.
@Before
public void setUp() throws Exception {
KettleEnvironment.init();
PluginRegistry.init(false);
List<String> attributes = Arrays.asList("selectingAndSortingUnspecifiedFields", "fieldName", "fieldType", "fieldLength", "fieldPrecision");
Map<String, String> getterMap = new HashMap<String, String>() {
{
put("selectingAndSortingUnspecifiedFields", "isSelectingAndSortingUnspecifiedFields");
put("fieldName", "getFieldName");
put("fieldType", "getFieldType");
put("fieldLength", "getFieldLength");
put("fieldPrecision", "getFieldPrecision");
}
};
Map<String, String> setterMap = new HashMap<String, String>() {
{
put("selectingAndSortingUnspecifiedFields", "setSelectingAndSortingUnspecifiedFields");
put("fieldName", "setFieldName");
put("fieldType", "setFieldType");
put("fieldLength", "setFieldLength");
put("fieldPrecision", "setFieldPrecision");
}
};
FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);
Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put("fieldName", stringArrayLoadSaveValidator);
Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
typeValidatorMap.put(int[].class.getCanonicalName(), new PrimitiveIntArrayLoadSaveValidator(new NonZeroIntLoadSaveValidator(6), 5));
loadSaveTester = new LoadSaveTester<MappingInputMeta>(MappingInputMeta.class, attributes, getterMap, setterMap, attrValidatorMap, typeValidatorMap);
}
use of org.pentaho.di.trans.steps.loadsave.validator.FieldLoadSaveValidator in project pentaho-kettle by pentaho.
the class MergeRowsMetaTest method setUpLoadSave.
@Before
public void setUpLoadSave() throws Exception {
KettleEnvironment.init();
PluginRegistry.init(false);
List<String> attributes = Arrays.asList("flagField", "keyFields", "valueFields");
FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator = new ArrayLoadSaveValidator<String>(new StringLoadSaveValidator(), 5);
Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
attrValidatorMap.put("keyFields", stringArrayLoadSaveValidator);
attrValidatorMap.put("valueFields", stringArrayLoadSaveValidator);
Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
loadSaveTester = new LoadSaveTester(testMetaClass, attributes, new ArrayList<String>(), new ArrayList<String>(), new HashMap<String, String>(), new HashMap<String, String>(), attrValidatorMap, typeValidatorMap, this);
}
Aggregations