Search in sources :

Example 11 with StepNodes

use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.

the class MergeJoinStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    when(mergeJoinMeta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
    analyzer = spy(new MergeJoinStepAnalyzer());
    analyzer.setParentStepMeta(parentStepMeta);
    analyzer.setParentTransMeta(parentTransMeta);
    analyzer.setMetaverseBuilder(builder);
    inputs = new StepNodes();
    inputs.addNode("leftStep", "Country", mockFieldNode);
    inputs.addNode("leftStep", "State", mockFieldNode);
    inputs.addNode("rightStep", "CTR", mockFieldNode);
    inputs.addNode("rightStep", "ST", mockFieldNode);
    when(analyzer.getInputs()).thenReturn(inputs);
    fields1 = inputs.getFieldNames("leftStep").toArray(new String[] {});
    fields2 = inputs.getFieldNames("rightStep").toArray(new String[] {});
    // add some more fields that won't be part of the join keys
    inputs.addNode("leftStep", "value", mockFieldNode);
    inputs.addNode("rightStep", "value", mockFieldNode);
    when(parentTransMeta.getPrevStepNames(analyzer.getStepName())).thenReturn(inputs.getStepNames().toArray(new String[] {}));
    when(mergeJoinMeta.getKeyFields1()).thenReturn(fields1);
    when(mergeJoinMeta.getKeyFields2()).thenReturn(fields2);
    outputs = new StepNodes();
    outputs.addNode("out", "Country", mockFieldNode);
    outputs.addNode("out", "State", mockFieldNode);
    outputs.addNode("out", "CTR", mockFieldNode);
    outputs.addNode("out", "ST", mockFieldNode);
    outputs.addNode("out", "value", mockFieldNode);
    outputs.addNode("out", "value_1", mockFieldNode);
    when(analyzer.getOutputs()).thenReturn(outputs);
}
Also used : StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 12 with StepNodes

use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.

the class SelectValuesStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    analyzer = spy(new SelectValuesStepAnalyzer());
    analyzer.setParentTransMeta(parentTransMeta);
    analyzer.setBaseStepMeta(selectValuesMeta);
    doNothing().when(analyzer).validateState(null, selectValuesMeta);
    prevFields = new HashMap<>();
    prevFields.put("previousStep", rmi);
    doReturn(prevFields).when(analyzer).getInputFields(selectValuesMeta);
    doReturn("select values").when(analyzer).getStepName();
    when(parentTransMeta.getPrevStepNames(analyzer.getStepName())).thenReturn(new String[] { "previousStep" });
    inputs = new StepNodes();
    inputs.addNode("previousStep", "first", node);
    inputs.addNode("previousStep", "last", node);
    inputs.addNode("previousStep", "age", node);
    inputs.addNode("previousStep", "birthday", node);
    doReturn(inputs).when(analyzer).getInputs();
    testChange1 = new SelectMetadataChange(selectValuesMeta);
    testChange1.setName("first");
    testChange1.setCurrencySymbol("~");
    testChange1.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    testChange1.setDateFormatLocale("en_UK");
    testChange1.setGroupingSymbol("...");
    testChange2 = new SelectMetadataChange(selectValuesMeta);
    testChange2.setName("last");
    testChange2.setRename("last name");
    testChange2.setDateFormatLenient(true);
    testChange2.setConversionMask("##.#");
    testChange2.setDateFormatTimeZone("YYYY-MM-DD");
    testChange2.setDecimalSymbol(",");
}
Also used : SelectMetadataChange(org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 13 with StepNodes

use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.

the class StringsReplaceStepAnalyzerTest method setUp.

@Before
public void setUp() throws Exception {
    when(stringsReplaceMeta.getFieldInStream()).thenReturn(new String[] { "firstName", "middleName", "lastName" });
    when(stringsReplaceMeta.getFieldOutStream()).thenReturn(new String[] { "", "MN", "lastName" });
    when(stringsReplaceMeta.getFieldReplaceByString()).thenReturn(new String[] { "Tom", "Dick", "Harry" });
    when(stringsReplaceMeta.getReplaceString()).thenReturn(new String[] { "Bill", "Steve", "Jeff" });
    analyzer = spy(new StringsReplaceStepAnalyzer());
    stepFields = new HashSet<>();
    stepFields.add(new StepField("prev", "firstName"));
    stepFields.add(new StepField("prev", "middleName"));
    stepFields.add(new StepField("prev", "lastName"));
    StepNodes stepNodes = mock(StepNodes.class);
    when(stepNodes.findNodes(anyString())).thenAnswer(new Answer<List<IMetaverseNode>>() {

        @Override
        public List<IMetaverseNode> answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            List<IMetaverseNode> foundNodes = new ArrayList<>();
            String fieldName = (String) args[0];
            if (fieldName.equals("firstName") || fieldName.equals("middleName") || fieldName.equals("lastName")) {
                foundNodes.add(mock(IMetaverseNode.class));
            }
            return foundNodes;
        }
    });
    when(analyzer.getInputs()).thenReturn(stepNodes);
    doReturn(stepFields).when(analyzer).createStepFields(anyString(), any(StepNodes.class));
    // Call customAnalyze() for coverage, it does nothing
    analyzer.customAnalyze(stringsReplaceMeta, mock(IMetaverseNode.class));
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Before(org.junit.Before)

Example 14 with StepNodes

use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzerTest method testConnectToSubTransOutputFields.

@Test
public void testConnectToSubTransOutputFields() throws Exception {
    when(meta.getOutputRowsSourceStep()).thenReturn("outputRowsStepName");
    when(meta.getExecutorsOutputStep()).thenReturn(null);
    String[] outputFields = new String[] { "first", "last" };
    when(meta.getOutputRowsField()).thenReturn(outputFields);
    IMetaverseNode outNode = mock(IMetaverseNode.class);
    StepNodes outputs = new StepNodes();
    outputs.addNode("outputRowsStepName", "first", outNode);
    outputs.addNode("outputRowsStepName", "last", outNode);
    doReturn(outputs).when(spyAnalyzer).getOutputs();
    // we'll test this in it's own test
    doNothing().when(spyAnalyzer).linkResultFieldToSubTrans(any(IMetaverseNode.class), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
    IMetaverseNode childTransNode = mock(IMetaverseNode.class);
    spyAnalyzer.connectToSubTransOutputFields(meta, childTransMeta, childTransNode, descriptor);
    verify(spyAnalyzer, times(outputFields.length)).linkResultFieldToSubTrans(any(IMetaverseNode.class), any(TransMeta.class), any(IMetaverseNode.class), any(IComponentDescriptor.class));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Matchers.anyString(org.mockito.Matchers.anyString) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Example 15 with StepNodes

use of org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzerTest method testGetUsedFields.

@Test
public void testGetUsedFields() throws Exception {
    IMetaverseNode outNode = mock(IMetaverseNode.class);
    StepNodes inputs = new StepNodes();
    inputs.addNode("previousStep", "one", outNode);
    inputs.addNode("previousStep", "two", outNode);
    doReturn(inputs).when(spyAnalyzer).getInputs();
    Set<StepField> usedFields = spyAnalyzer.getUsedFields(meta);
    assertEquals(inputs.getFieldNames(), usedFields);
}
Also used : IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) StepField(org.pentaho.metaverse.api.StepField) StepNodes(org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes) Test(org.junit.Test)

Aggregations

StepNodes (org.pentaho.metaverse.api.analyzer.kettle.step.StepNodes)17 Test (org.junit.Test)10 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)7 Before (org.junit.Before)6 StepField (org.pentaho.metaverse.api.StepField)5 Matchers.anyString (org.mockito.Matchers.anyString)4 TransMeta (org.pentaho.di.trans.TransMeta)4 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)4 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)2 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)2 ComponentDerivationRecord (org.pentaho.metaverse.api.analyzer.kettle.ComponentDerivationRecord)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)1 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 SelectMetadataChange (org.pentaho.di.trans.steps.selectvalues.SelectMetadataChange)1