Search in sources :

Example 51 with Trans

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

the class LoadFileInputTest method setup.

@Before
public void setup() throws FileSystemException {
    fs = VFS.getManager();
    filesPath = '/' + this.getClass().getPackage().getName().replace('.', '/') + "/files/";
    transName = "LoadFileInput";
    transMeta = new TransMeta();
    transMeta.setName(transName);
    trans = new Trans(transMeta);
    stepMetaInterface = spy(new LoadFileInputMeta());
    stepInputFiles = new FileInputList();
    Mockito.doReturn(stepInputFiles).when(stepMetaInterface).getFiles(any(VariableSpace.class));
    String stepId = PluginRegistry.getInstance().getPluginId(StepPluginType.class, stepMetaInterface);
    stepMeta = new StepMeta(stepId, "Load File Input", stepMetaInterface);
    transMeta.addStep(stepMeta);
    stepDataInterface = new LoadFileInputData();
    stepCopyNr = 0;
    stepLoadFileInput = new LoadFileInput(stepMeta, stepDataInterface, stepCopyNr, transMeta, trans);
    assertSame(stepMetaInterface, stepMeta.getStepMetaInterface());
    runtimeSMI = stepMetaInterface;
    runtimeSDI = runtimeSMI.getStepData();
    inputField = new LoadFileInputField();
    ((LoadFileInputMeta) runtimeSMI).setInputFields(new LoadFileInputField[] { inputField });
    stepLoadFileInput.init(runtimeSMI, runtimeSDI);
}
Also used : VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Trans(org.pentaho.di.trans.Trans) StepMeta(org.pentaho.di.trans.step.StepMeta) FileInputList(org.pentaho.di.core.fileinput.FileInputList) Before(org.junit.Before)

Example 52 with Trans

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

the class TransMetaConverterTest method testDisabledHops.

@Test
public void testDisabledHops() {
    TransMeta trans = new TransMeta();
    StepMeta start = new StepMeta("Start", stepMetaInterface);
    trans.addStep(start);
    StepMeta withEnabledHop = new StepMeta("WithEnabledHop", stepMetaInterface);
    trans.addStep(withEnabledHop);
    StepMeta withDisabledHop = new StepMeta("WithDisabledHop", stepMetaInterface);
    trans.addStep(withDisabledHop);
    StepMeta shouldStay = new StepMeta("ShouldStay", stepMetaInterface);
    trans.addStep(shouldStay);
    StepMeta shouldNotStay = new StepMeta("ShouldNotStay", stepMetaInterface);
    trans.addStep(shouldNotStay);
    StepMeta withEnabledAndDisabledHops = new StepMeta("WithEnabledAndDisabledHops", stepMetaInterface);
    trans.addStep(withEnabledAndDisabledHops);
    StepMeta afterEnabledDisabled = new StepMeta("AfterEnabledDisabled", stepMetaInterface);
    trans.addStep(afterEnabledDisabled);
    trans.addTransHop(new TransHopMeta(start, withEnabledHop));
    trans.addTransHop(new TransHopMeta(start, withDisabledHop, false));
    trans.addTransHop(new TransHopMeta(withEnabledHop, shouldStay));
    trans.addTransHop(new TransHopMeta(withDisabledHop, shouldStay));
    trans.addTransHop(new TransHopMeta(withDisabledHop, shouldNotStay));
    trans.addTransHop(new TransHopMeta(start, withEnabledAndDisabledHops));
    trans.addTransHop(new TransHopMeta(withEnabledHop, withEnabledAndDisabledHops, false));
    trans.addTransHop(new TransHopMeta(withEnabledAndDisabledHops, afterEnabledDisabled));
    Transformation transformation = TransMetaConverter.convert(trans);
    List<String> steps = transformation.getOperations().stream().map(op -> op.getId()).collect(Collectors.toList());
    assertThat("Only 5 ops should exist", steps.size(), is(5));
    assertThat(steps, hasItems("Start", "WithEnabledHop", "ShouldStay", "WithEnabledAndDisabledHops", "AfterEnabledDisabled"));
    List<String> hops = transformation.getHops().stream().map(hop -> hop.getId()).collect(Collectors.toList());
    assertThat("Only 4 hops should exist", hops.size(), is(4));
    assertThat(hops, hasItems("Start -> WithEnabledHop", "WithEnabledHop -> ShouldStay", "Start -> WithEnabledAndDisabledHops", "WithEnabledAndDisabledHops -> AfterEnabledDisabled"));
}
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)

Example 53 with Trans

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

the class DeleteMetaTest method setUp.

@Before
public void setUp() {
    TransMeta transMeta = new TransMeta();
    transMeta.setName("delete1");
    Map<String, String> vars = new HashMap<String, String>();
    vars.put("max.sz", "10");
    transMeta.injectVariables(vars);
    dmi = new DeleteMeta();
    dd = new DeleteData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String deletePid = plugReg.getPluginId(StepPluginType.class, dmi);
    stepMeta = new StepMeta(deletePid, "delete", dmi);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(stepMeta);
    del = new Delete(stepMeta, dd, 1, transMeta, trans);
    del.copyVariablesFrom(transMeta);
}
Also used : HashMap(java.util.HashMap) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) Before(org.junit.Before)

Example 54 with Trans

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

the class GetRepositoryNamesTest method init.

private void init(Repository repository, String directoryName, boolean includeSubFolders, String nameMask, String exludeNameMask, ObjectTypeSelection typeSelection, int itemCount) throws KettleException {
    VariableSpace vars = new Variables();
    vars.setVariable("DirName", "/subdir1");
    vars.setVariable("IncludeMask", ".*");
    vars.setVariable("ExcludeMask", "");
    GetRepositoryNamesMeta meta = new GetRepositoryNamesMeta();
    meta.setDirectory(new String[] { directoryName });
    meta.setNameMask(new String[] { nameMask });
    meta.setExcludeNameMask(new String[] { exludeNameMask });
    meta.setIncludeSubFolders(new boolean[] { includeSubFolders });
    meta.setObjectTypeSelection(typeSelection);
    StepMeta stepMeta = new StepMeta("GetRepoNamesStep", meta);
    TransMeta transMeta = new TransMeta(vars);
    transMeta.setRepository(repository);
    transMeta.addStep(stepMeta);
    GetRepositoryNamesData data = (GetRepositoryNamesData) meta.getStepData();
    GetRepositoryNames step = new GetRepositoryNames(stepMeta, data, 0, transMeta, new Trans(transMeta));
    step.init(meta, data);
    assertNotNull(data.list);
    assertEquals(itemCount, data.list.size());
}
Also used : Variables(org.pentaho.di.core.variables.Variables) VariableSpace(org.pentaho.di.core.variables.VariableSpace) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

Example 55 with Trans

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

the class TransExecutorUnitTest method setUp.

@Before
public void setUp() throws Exception {
    executor = StepMockUtil.getStep(TransExecutor.class, TransExecutorMeta.class, "TransExecutorUnitTest");
    executor = spy(executor);
    TransMeta internalTransMeta = mock(TransMeta.class);
    doReturn(internalTransMeta).when(executor).loadExecutorTransMeta();
    internalTrans = spy(new Trans());
    internalTrans.setLog(mock(LogChannelInterface.class));
    doNothing().when(internalTrans).prepareExecution(any(String[].class));
    doNothing().when(internalTrans).startThreads();
    doNothing().when(internalTrans).waitUntilFinished();
    doNothing().when(executor).discardLogLines(any(TransExecutorData.class));
    doReturn(internalTrans).when(executor).createInternalTrans();
    internalResult = new Result();
    doReturn(internalResult).when(internalTrans).getResult();
    meta = new TransExecutorMeta();
    data = new TransExecutorData();
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Result(org.pentaho.di.core.Result) Before(org.junit.Before)

Aggregations

Trans (org.pentaho.di.trans.Trans)307 TransMeta (org.pentaho.di.trans.TransMeta)210 StepMeta (org.pentaho.di.trans.step.StepMeta)118 Test (org.junit.Test)95 StepInterface (org.pentaho.di.trans.step.StepInterface)92 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)84 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)81 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)73 RowStepCollector (org.pentaho.di.trans.RowStepCollector)71 KettleException (org.pentaho.di.core.exception.KettleException)65 RowProducer (org.pentaho.di.trans.RowProducer)58 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)54 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)48 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)47 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)47 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)47 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)42 PrintWriter (java.io.PrintWriter)34 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)29