Search in sources :

Example 11 with ComponentDerivationRecord

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());
        }
    }
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 12 with ComponentDerivationRecord

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());
}
Also used : IOperation(org.pentaho.metaverse.api.model.IOperation) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operations(org.pentaho.metaverse.api.model.Operations) Test(org.junit.Test)

Example 13 with ComponentDerivationRecord

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));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Test(org.junit.Test)

Example 14 with ComponentDerivationRecord

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());
}
Also used : ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with ComponentDerivationRecord

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));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) ComponentDerivationRecord(org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord) Operation(org.pentaho.metaverse.api.model.Operation) Test(org.junit.Test)

Aggregations

ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)43 Test (org.junit.Test)23 HashSet (java.util.HashSet)21 StepField (org.pentaho.metaverse.api.StepField)11 Operation (org.pentaho.metaverse.api.model.Operation)11 Matchers.anyString (org.mockito.Matchers.anyString)5 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)5 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)5 IOperation (org.pentaho.metaverse.api.model.IOperation)3 Operations (org.pentaho.metaverse.api.model.Operations)3 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)2 IAnalysisContext (org.pentaho.metaverse.api.IAnalysisContext)2 IFieldLineageMetadataProvider (org.pentaho.metaverse.api.analyzer.kettle.step.IFieldLineageMetadataProvider)2 StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)2 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 Condition (org.pentaho.di.core.Condition)1 CalculatorMetaFunction (org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction)1 NumberRangeRule (org.pentaho.di.trans.steps.numberrange.NumberRangeRule)1