use of org.pentaho.di.imp.rules.TransformationHasANoteImportRule in project pentaho-kettle by pentaho.
the class TransformationHasANoteImportRuleIT method testRule.
public void testRule() throws Exception {
// Create a transformation to test.
//
TransMeta transMeta = new TransMeta();
NotePadMeta note = new NotePadMeta("A note documenting the transformation", 50, 50, 200, 50);
transMeta.addNote(note);
// Load the plugin to test from the registry.
//
PluginRegistry registry = PluginRegistry.getInstance();
PluginInterface plugin = registry.findPluginWithId(ImportRulePluginType.class, "TransformationHasANote");
assertNotNull("The 'transformation has a note' rule could not be found in the plugin registry!", plugin);
TransformationHasANoteImportRule rule = (TransformationHasANoteImportRule) registry.loadClass(plugin);
assertNotNull("The 'transformation has a note' class could not be loaded by the plugin registry!", plugin);
rule.setEnabled(true);
List<ImportValidationFeedback> feedback = rule.verifyRule(transMeta);
assertTrue("We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty());
assertTrue("An approval ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.APPROVAL);
transMeta.removeNote(0);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty());
assertTrue("An error ruling was expected", feedback.get(0).getResultType() == ImportValidationResultType.ERROR);
rule.setEnabled(false);
feedback = rule.verifyRule(transMeta);
assertTrue("We didn't expect any feedback from the 'transformation has a note' rule while disabled", feedback.isEmpty());
}
use of org.pentaho.di.imp.rules.TransformationHasANoteImportRule in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testExportWithRules.
@Test
public void testExportWithRules() throws Exception {
String fileName = "testExportWithRuled.xml";
// $NON-NLS-1$
final String exportFileName = new File(fileName).getAbsolutePath();
RepositoryDirectoryInterface rootDir = initRepo();
String transWithoutNoteName = "2" + EXP_DBMETA_NAME;
TransMeta transWithoutNote = createTransMeta(transWithoutNoteName);
String transUniqueName = EXP_TRANS_NAME.concat(transWithoutNoteName);
RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
repository.save(transWithoutNote, VERSION_COMMENT_V1, null);
// So this transformation is cleaned up afterward
deleteStack.push(transWithoutNote);
assertNotNull(transWithoutNote.getObjectId());
assertTrue(hasVersionWithComment(transWithoutNote, VERSION_COMMENT_V1));
assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
// Second transformation (contained note)
String transWithNoteName = "1" + EXP_DBMETA_NAME;
TransMeta transWithNote = createTransMeta(transWithNoteName);
transUniqueName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
TransMeta transWithRules = createTransMeta(EXP_DBMETA_NAME);
NotePadMeta note = new NotePadMeta("Note Message", 1, 1, 100, 5);
transWithRules.addNote(note);
repository.save(transWithRules, VERSION_COMMENT_V1, null);
// So this transformation is cleaned up afterward
deleteStack.push(transWithRules);
assertNotNull(transWithRules.getObjectId());
assertTrue(hasVersionWithComment(transWithRules, VERSION_COMMENT_V1));
assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
// create rules for export to .xml file
List<ImportRuleInterface> rules = new AbstractList<ImportRuleInterface>() {
@Override
public ImportRuleInterface get(int index) {
TransformationHasANoteImportRule rule = new TransformationHasANoteImportRule();
rule.setEnabled(true);
return rule;
}
@Override
public int size() {
return 1;
}
};
ImportRules importRules = new ImportRules();
importRules.setRules(rules);
// create exporter
IRepositoryExporter exporter = repository.getExporter();
exporter.setImportRulesToValidate(importRules);
// export itself
try {
// $NON-NLS-1$
exporter.exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
FileObject exportFile = KettleVFS.getFileObject(exportFileName);
assertNotNull(exportFile);
MockRepositoryExportParser parser = new MockRepositoryExportParser();
SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
if (parser.getFatalError() != null) {
throw parser.getFatalError();
}
// assumed transformation with note will be here and only it
assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName(RepositoryObjectType.TRANSFORMATION.getTypeDescription()).size());
} finally {
KettleVFS.getFileObject(exportFileName).delete();
}
}
Aggregations