use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class TableOutputStepAnalyzerTest method testGetChangeRecords.
@Test
public void testGetChangeRecords() throws Exception {
String[] tableFields = new String[] { "field1", "field2" };
when(meta.getFieldDatabase()).thenReturn(tableFields);
String[] streamFields = new String[] { "f1", "field2", "field3" };
when(meta.getFieldStream()).thenReturn(streamFields);
StepNodes inputs = new StepNodes();
inputs.addNode("prevStep", "f1", node);
inputs.addNode("prevStep", "field2", node);
inputs.addNode("prevStep", "field3", node);
inputs.addNode(ExternalResourceStepAnalyzer.RESOURCE, "field1", node);
inputs.addNode(ExternalResourceStepAnalyzer.RESOURCE, "field2", node);
doReturn(inputs).when(analyzer).getInputs();
Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
assertNotNull(changeRecords);
assertEquals(tableFields.length, changeRecords.size());
for (ComponentDerivationRecord changeRecord : changeRecords) {
if ("f1".equals(changeRecord.getOriginalEntityName())) {
assertEquals("field1", changeRecord.getChangedEntityName());
} else if ("field2".equals(changeRecord.getOriginalEntityName())) {
assertEquals("field2", changeRecord.getChangedEntityName());
} else {
fail("We encountered a change record that shouldn't be here - " + changeRecord.toString());
}
}
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class ValueMapperStepAnalyzerTest method testGetChangeRecords.
@Test
public void testGetChangeRecords() throws Exception {
Set<ComponentDerivationRecord> changeRecords = analyzer.getChangeRecords(meta);
assertEquals(1, changeRecords.size());
ComponentDerivationRecord changeRecord = changeRecords.iterator().next();
assertEquals(meta.getFieldToUse(), changeRecord.getOriginalEntityName());
assertEquals((meta.getTargetField() == null ? meta.getFieldToUse() : meta.getTargetField()), changeRecord.getChangedEntityName());
Operations operations = changeRecord.getOperations();
// Only data operations
assertEquals(1, operations.size());
List<IOperation> dataOperations = operations.get(ChangeType.DATA);
assertEquals(2, dataOperations.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testMapChange_noOperation.
@Test
public void testMapChange_noOperation() throws Exception {
doReturn(outputs).when(analyzer).getOutputs();
doReturn(inputs).when(analyzer).getInputs();
StepField original = new StepField("previousStep", "address");
StepField changed = new StepField("nextStep", "address");
ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
ComponentDerivationRecord spyCdr = spy(cdr);
analyzer.mapChange(spyCdr);
// should only be called to see if there are any operations
verify(spyCdr).getOperations();
verify(analyzer).linkChangeNodes(any(IMetaverseNode.class), any(IMetaverseNode.class));
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testGetChanges_ExceptionGettingChangeRecords.
@Test
public void testGetChanges_ExceptionGettingChangeRecords() throws Exception {
ComponentDerivationRecord passthrough1 = mock(ComponentDerivationRecord.class);
ComponentDerivationRecord passthrough2 = mock(ComponentDerivationRecord.class);
Set<ComponentDerivationRecord> passthroughs = new HashSet<>();
passthroughs.add(passthrough1);
passthroughs.add(passthrough2);
doThrow(MetaverseAnalyzerException.class).when(analyzer).getChangeRecords(baseStepMeta);
doReturn(passthroughs).when(analyzer).getPassthroughChanges();
Set<ComponentDerivationRecord> changes = analyzer.getChanges();
assertTrue(CollectionUtils.isNotEmpty(changes));
assertEquals(2, changes.size());
}
use of org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord in project pentaho-metaverse by pentaho.
the class StepAnalyzerTest method testMapChange.
@Test
public void testMapChange() throws Exception {
doReturn(outputs).when(analyzer).getOutputs();
doReturn(inputs).when(analyzer).getInputs();
Operation operation = new Operation("testOperation", "testOperation");
StepField original = new StepField("previousStep", "address");
StepField changed = new StepField("nextStep", "address");
ComponentDerivationRecord cdr = new ComponentDerivationRecord(original, changed);
cdr.addOperation(operation);
ComponentDerivationRecord spyCdr = spy(cdr);
analyzer.mapChange(spyCdr);
// get operations to verify it is not null, then agains to toString it
verify(spyCdr, times(1)).getOperations();
verify(analyzer).linkChangeNodes(any(IMetaverseNode.class), any(IMetaverseNode.class));
}
Aggregations