Search in sources :

Example 46 with Trans

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

the class ScriptValueAddFunctions_SetVariableScopeTest method createTrans.

private Trans createTrans(Job parent) {
    Trans trans = createTrans();
    trans.setParentJob(parent);
    trans.setParentVariableSpace(parent);
    return trans;
}
Also used : Trans(org.pentaho.di.trans.Trans)

Example 47 with Trans

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

the class MissingTransStepTest method testInit.

@Test
public void testInit() {
    StepMetaInterface stepMetaInterface = new AbstractStepMeta() {

        @Override
        public void setDefault() {
        }

        @Override
        public StepInterface getStep(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans) {
            return null;
        }
    };
    StepMeta stepMeta = new StepMeta();
    stepMeta.setName("TestMetaStep");
    StepDataInterface stepDataInterface = mock(StepDataInterface.class);
    Trans trans = new Trans();
    LogChannel log = mock(LogChannel.class);
    doAnswer(new Answer<Void>() {

        public Void answer(InvocationOnMock invocation) {
            return null;
        }
    }).when(log).logError(anyString());
    trans.setLog(log);
    TransMeta transMeta = new TransMeta();
    transMeta.addStep(stepMeta);
    MissingTransStep step = createAndInitStep(stepMetaInterface, stepDataInterface);
    assertFalse(step.init(stepMetaInterface, stepDataInterface));
}
Also used : AbstractStepMeta(org.pentaho.di.core.util.AbstractStepMeta) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) TransMeta(org.pentaho.di.trans.TransMeta) LogChannel(org.pentaho.di.core.logging.LogChannel) StepMeta(org.pentaho.di.trans.step.StepMeta) AbstractStepMeta(org.pentaho.di.core.util.AbstractStepMeta) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 48 with Trans

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

the class MySQLBulkLoaderTest method testEscapeCharacters.

@Test
public void testEscapeCharacters() throws KettleException, IOException {
    PluginRegistry.addPluginType(ValueMetaPluginType.getInstance());
    PluginRegistry.init(false);
    MySQLBulkLoader loader;
    MySQLBulkLoaderData ld = new MySQLBulkLoaderData();
    MySQLBulkLoaderMeta lm = new MySQLBulkLoaderMeta();
    TransMeta transMeta = new TransMeta();
    transMeta.setName("loader");
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String loaderPid = plugReg.getPluginId(StepPluginType.class, lm);
    StepMeta stepMeta = new StepMeta(loaderPid, "loader", lm);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(stepMeta);
    trans.setRunning(true);
    loader = Mockito.spy(new MySQLBulkLoader(stepMeta, ld, 1, transMeta, trans));
    RowMeta rm = new RowMeta();
    ValueMetaString vm = new ValueMetaString("I don't want NPE!");
    rm.addValueMeta(vm);
    RowMeta spyRowMeta = Mockito.spy(new RowMeta());
    Mockito.when(spyRowMeta.getValueMeta(Mockito.anyInt())).thenReturn(vm);
    loader.setInputRowMeta(spyRowMeta);
    MySQLBulkLoaderMeta smi = new MySQLBulkLoaderMeta();
    smi.setFieldStream(new String[] { "Test" });
    smi.setFieldFormatType(new int[] { MySQLBulkLoaderMeta.FIELD_FORMAT_TYPE_STRING_ESCAPE });
    smi.setEscapeChar("\\");
    smi.setEnclosure("\"");
    smi.setDatabaseMeta(Mockito.mock(DatabaseMeta.class));
    MySQLBulkLoaderData sdi = new MySQLBulkLoaderData();
    sdi.keynrs = new int[1];
    sdi.keynrs[0] = 0;
    sdi.fifoStream = Mockito.mock(OutputStream.class);
    loader.init(smi, sdi);
    loader.first = false;
    Mockito.when(loader.getRow()).thenReturn(new String[] { "test\"Escape\\" });
    loader.processRow(smi, sdi);
    Mockito.verify(sdi.fifoStream, Mockito.times(1)).write("test\\\"Escape\\\\".getBytes());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Example 49 with Trans

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

the class PGBulkLoaderMetaTest method setUp.

@Before
public void setUp() {
    TransMeta transMeta = new TransMeta();
    transMeta.setName("loader");
    lm = new PGBulkLoaderMeta();
    ld = new PGBulkLoaderData();
    PluginRegistry plugReg = PluginRegistry.getInstance();
    String loaderPid = plugReg.getPluginId(StepPluginType.class, lm);
    stepMeta = new StepMeta(loaderPid, "loader", lm);
    Trans trans = new Trans(transMeta);
    transMeta.addStep(stepMeta);
    loader = new PGBulkLoader(stepMeta, ld, 1, transMeta, trans);
}
Also used : 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 50 with Trans

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

the class PropertyOutputIT method testExecute.

@Test
public void testExecute() throws KettleException, IOException {
    TransMeta meta = new TransMeta(getClass().getResource("propertyOutput.ktr").getPath());
    Trans trans = new Trans(meta);
    trans.execute(new String[] {});
    trans.waitUntilFinished();
    // check that trans is finished
    assertTrue(trans.isFinished());
    PropertyOutputData dataStep = (PropertyOutputData) trans.getSteps().get(1).data;
    RandomAccessFile fos = null;
    try {
        File file = new File(URI.create(dataStep.filename.replace("\\", "/")).getPath());
        if (file.exists()) {
            fos = new RandomAccessFile(file, "rw");
        }
    } catch (FileNotFoundException | SecurityException e) {
        fail("the file with properties should be unallocated");
    } finally {
        if (fos != null) {
            fos.close();
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) TransMeta(org.pentaho.di.trans.TransMeta) FileNotFoundException(java.io.FileNotFoundException) Trans(org.pentaho.di.trans.Trans) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Test(org.junit.Test)

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