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;
}
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));
}
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());
}
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);
}
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();
}
}
}
Aggregations