Search in sources :

Example 51 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryImporterTest method testImportTrans_patchTransEntries_with_variable.

@Test
public void testImportTrans_patchTransEntries_with_variable() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("");
    StepMetaInterface stepMeta = createStepMeta("${USER_VARIABLE}");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importTransformation(entityNode, feedback);
    verify((HasRepositoryDirectories) stepMeta).setDirectories(new String[] { "${USER_VARIABLE}" });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 52 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryImporterTest method createStepMeta.

private static StepMetaInterface createStepMeta(String directory) {
    StepMetaInterface stepMetaInterface = mock(StepMetaInterface.class, withSettings().extraInterfaces(HasRepositoryDirectories.class));
    when(stepMetaInterface.isReferencedObjectEnabled()).thenReturn(new boolean[] { true });
    doAnswer(invocationOnMock -> new ObjectLocationSpecificationMethod[] { ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME }).when(((HasRepositoryDirectories) stepMetaInterface)).getSpecificationMethods();
    doAnswer(invocationOnMock -> new String[] { directory }).when((HasRepositoryDirectories) stepMetaInterface).getDirectories();
    return stepMetaInterface;
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface)

Example 53 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class RepositoryImporterTest method testImportJob_patchJobEntries_when_directory_path_ends_with_variable.

@Test
public void testImportJob_patchJobEntries_when_directory_path_ends_with_variable() throws KettleException {
    JobEntryInterface jobEntryInterface = createJobEntry("/myDir/${USER_VARIABLE}");
    StepMetaInterface stepMeta = createStepMeta("");
    RepositoryImporter importer = createRepositoryImporter(jobEntryInterface, stepMeta, true);
    importer.setBaseDirectory(baseDirectory);
    importer.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface).setDirectories(new String[] { "/myDir/${USER_VARIABLE}" });
    JobEntryInterface jobEntryInterface2 = createJobEntry("/myDir/${USER_VARIABLE}");
    RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter(jobEntryInterface2, stepMeta, false);
    importerWithCompatibilityImportPath.setBaseDirectory(baseDirectory);
    importerWithCompatibilityImportPath.importJob(entityNode, feedback);
    verify((HasRepositoryDirectories) jobEntryInterface2).setDirectories(new String[] { ROOT_PATH + "/myDir/${USER_VARIABLE}" });
}
Also used : JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Test(org.junit.Test)

Example 54 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class TransMetaTest method getThisStepFieldsPassesCloneRowMeta.

@Test
public void getThisStepFieldsPassesCloneRowMeta() throws Exception {
    final String overriddenValue = "overridden";
    StepMeta nextStep = mockStepMeta("nextStep");
    StepMetaInterface smi = mock(StepMetaInterface.class);
    StepIOMeta ioMeta = mock(StepIOMeta.class);
    when(smi.getStepIOMeta()).thenReturn(ioMeta);
    doAnswer(new Answer<Object>() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            RowMetaInterface rmi = (RowMetaInterface) invocation.getArguments()[0];
            rmi.clear();
            rmi.addValueMeta(new ValueMetaString(overriddenValue));
            return null;
        }
    }).when(smi).getFields(any(RowMetaInterface.class), anyString(), any(RowMetaInterface[].class), eq(nextStep), any(VariableSpace.class), any(Repository.class), any(IMetaStore.class));
    StepMeta thisStep = mockStepMeta("thisStep");
    when(thisStep.getStepMetaInterface()).thenReturn(smi);
    RowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("value"));
    RowMetaInterface thisStepsFields = transMeta.getThisStepFields(thisStep, nextStep, rowMeta);
    assertEquals(1, thisStepsFields.size());
    assertEquals(overriddenValue, thisStepsFields.getValueMeta(0).getName());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepIOMeta(org.pentaho.di.trans.step.StepIOMeta) RowMeta(org.pentaho.di.core.row.RowMeta) VariableSpace(org.pentaho.di.core.variables.VariableSpace) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Repository(org.pentaho.di.repository.Repository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Example 55 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class TransMetaConverterTest method testRemovingDisabledInputSteps.

@Test
public void testRemovingDisabledInputSteps() {
    TransMeta trans = new TransMeta();
    StepMeta inputToBeRemoved = new StepMeta("InputToBeRemoved", stepMetaInterface);
    trans.addStep(inputToBeRemoved);
    StepMeta inputToStay = new StepMeta("InputToStay", stepMetaInterface);
    trans.addStep(inputToStay);
    StepMeta inputReceiver1 = new StepMeta("InputReceiver1", stepMetaInterface);
    trans.addStep(inputReceiver1);
    StepMeta inputReceiver2 = new StepMeta("InputReceiver2", stepMetaInterface);
    trans.addStep(inputReceiver2);
    TransHopMeta hop1 = new TransHopMeta(inputToBeRemoved, inputReceiver1, false);
    TransHopMeta hop2 = new TransHopMeta(inputToStay, inputReceiver1);
    TransHopMeta hop3 = new TransHopMeta(inputToBeRemoved, inputReceiver2, false);
    trans.addTransHop(hop1);
    trans.addTransHop(hop2);
    trans.addTransHop(hop3);
    Transformation transformation = TransMetaConverter.convert(trans);
    List<String> steps = transformation.getOperations().stream().map(op -> op.getId()).collect(Collectors.toList());
    assertThat("Only 2 ops should exist", steps.size(), is(2));
    assertThat(steps, hasItems("InputToStay", "InputReceiver1"));
    List<String> hops = transformation.getHops().stream().map(hop -> hop.getId()).collect(Collectors.toList());
    assertThat("Only 1 hop should exist", hops.size(), is(1));
    assertThat(hops, hasItems("InputToStay -> InputReceiver1"));
}
Also used : Transformation(org.pentaho.di.engine.api.model.Transformation) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Trans(org.pentaho.di.trans.Trans) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) StepPluginType(org.pentaho.di.core.plugins.StepPluginType) Hop(org.pentaho.di.engine.api.model.Hop) CoreMatchers.startsWith(org.hamcrest.CoreMatchers.startsWith) KettleClientEnvironment(org.pentaho.di.core.KettleClientEnvironment) Operation(org.pentaho.di.engine.api.model.Operation) TransMeta(org.pentaho.di.trans.TransMeta) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) Document(org.w3c.dom.Document) Matchers.eq(org.mockito.Matchers.eq) Spy(org.mockito.Spy) KettleMissingPluginsException(org.pentaho.di.core.exception.KettleMissingPluginsException) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) CsvInputMeta(org.pentaho.di.trans.steps.csvinput.CsvInputMeta) ClassRule(org.junit.ClassRule) Mockito.doReturn(org.mockito.Mockito.doReturn) StepInterface(org.pentaho.di.trans.step.StepInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) AfterClass(org.junit.AfterClass) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) Variables(org.pentaho.di.core.variables.Variables) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Collectors(java.util.stream.Collectors) ResolvableResource(org.pentaho.di.workarounds.ResolvableResource) List(java.util.List) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Mockito.mock(org.mockito.Mockito.mock) RestorePDIEngineEnvironment(org.pentaho.di.junit.rules.RestorePDIEngineEnvironment) BeforeClass(org.junit.BeforeClass) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) KettleException(org.pentaho.di.core.exception.KettleException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) Answer(org.mockito.stubbing.Answer) CoreMatchers.everyItem(org.hamcrest.CoreMatchers.everyItem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) XMLHandler(org.pentaho.di.core.xml.XMLHandler) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Node(org.w3c.dom.Node) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Props(org.pentaho.di.core.Props) Repository(org.pentaho.di.repository.Repository) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) Assert.assertNotNull(org.junit.Assert.assertNotNull) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) KettleEnvironment(org.pentaho.di.core.KettleEnvironment) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) TransHopMeta(org.pentaho.di.trans.TransHopMeta) RepositoryDirectory(org.pentaho.di.repository.RepositoryDirectory) TableInputMeta(org.pentaho.di.trans.steps.tableinput.TableInputMeta) Assert.assertEquals(org.junit.Assert.assertEquals) Transformation(org.pentaho.di.engine.api.model.Transformation) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) Test(org.junit.Test)

Aggregations

StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)77 StepMeta (org.pentaho.di.trans.step.StepMeta)40 KettleException (org.pentaho.di.core.exception.KettleException)31 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 TransMeta (org.pentaho.di.trans.TransMeta)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 TableItem (org.eclipse.swt.widgets.TableItem)15 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)14 Trans (org.pentaho.di.trans.Trans)14 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)14 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Point (org.pentaho.di.core.gui.Point)12 TransHopMeta (org.pentaho.di.trans.TransHopMeta)11 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)11 NotePadMeta (org.pentaho.di.core.NotePadMeta)8 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)8