use of org.pentaho.di.trans.steps.mock.StepMockHelper in project pentaho-kettle by pentaho.
the class JsonOutputTest method testWriteToFile.
@SuppressWarnings("unchecked")
public void testWriteToFile() throws Exception {
StepMockHelper<JsonOutputMeta, JsonOutputData> mockHelper = new StepMockHelper<JsonOutputMeta, JsonOutputData>("jsonOutput", JsonOutputMeta.class, JsonOutputData.class);
when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
when(mockHelper.trans.isRunning()).thenReturn(true);
when(mockHelper.stepMeta.getStepMetaInterface()).thenReturn(new JsonOutputMeta());
JsonOutputData stepData = new JsonOutputData();
stepData.writeToFile = true;
JSONObject jsonObject = new JSONObject();
jsonObject.put("key", "value");
stepData.ja.add(jsonObject);
stepData.writer = mock(Writer.class);
JsonOutput step = new JsonOutput(mockHelper.stepMeta, stepData, 0, mockHelper.transMeta, mockHelper.trans);
step = spy(step);
doReturn(null).when(step).getRow();
doReturn(true).when(step).openNewFile();
doReturn(true).when(step).closeFile();
doNothing().when(stepData.writer).write(anyString());
step.processRow(mockHelper.processRowsStepMetaInterface, stepData);
verify(step).openNewFile();
verify(step).closeFile();
}
use of org.pentaho.di.trans.steps.mock.StepMockHelper in project pentaho-kettle by pentaho.
the class DatabaseLookupUTest method createMockHelper.
private StepMockHelper<DatabaseLookupMeta, DatabaseLookupData> createMockHelper() {
StepMockHelper<DatabaseLookupMeta, DatabaseLookupData> mockHelper = new StepMockHelper<DatabaseLookupMeta, DatabaseLookupData>("test DatabaseLookup", DatabaseLookupMeta.class, DatabaseLookupData.class);
when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenReturn(mockHelper.logChannelInterface);
when(mockHelper.trans.isRunning()).thenReturn(true);
RowMeta inputRowMeta = new RowMeta();
RowSet rowSet = mock(RowSet.class);
when(rowSet.getRowWait(anyLong(), any(TimeUnit.class))).thenReturn(new Object[0]).thenReturn(null);
when(rowSet.getRowMeta()).thenReturn(inputRowMeta);
when(mockHelper.trans.findRowSet(anyString(), anyInt(), anyString(), anyInt())).thenReturn(rowSet);
when(mockHelper.transMeta.findNextSteps(Matchers.any(StepMeta.class))).thenReturn(Collections.singletonList(mock(StepMeta.class)));
when(mockHelper.transMeta.findPreviousSteps(any(StepMeta.class), anyBoolean())).thenReturn(Collections.singletonList(mock(StepMeta.class)));
return mockHelper;
}
Aggregations