Search in sources :

Example 1 with StepMockHelper

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();
}
Also used : JSONObject(org.json.simple.JSONObject) StepMockHelper(org.pentaho.di.trans.steps.mock.StepMockHelper) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Writer(java.io.Writer)

Example 2 with StepMockHelper

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;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) StepMockHelper(org.pentaho.di.trans.steps.mock.StepMockHelper) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Aggregations

LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)2 StepMockHelper (org.pentaho.di.trans.steps.mock.StepMockHelper)2 Writer (java.io.Writer)1 JSONObject (org.json.simple.JSONObject)1 RowSet (org.pentaho.di.core.RowSet)1 RowMeta (org.pentaho.di.core.row.RowMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1