use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-kettle by pentaho.
the class JsonInputAnalyzerPluginLifecycleListener method onStart.
@Override
public void onStart(final LifeEventHandler lifeEventHandler) throws LifecycleException {
// instantiate a new analyzer
final JsonInputAnalyzer analyzer = new JsonInputAnalyzer();
// construct the external resource consumer for the files that it reads from
final IStepExternalResourceConsumer consumer = new JsonInputExternalResourceConsumer();
analyzer.setExternalResourceConsumer(consumer);
// register the analyzer with PentahoSystem
PentahoSystem.registerObject(analyzer);
// register the consumer with PentahoSystem
PentahoSystem.registerObject(consumer);
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.
the class StepExternalConsumerRowListenerTest method testStepExternalConsumerRowListener.
@Test
public void testStepExternalConsumerRowListener() throws Exception {
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
BaseStep mockStep = mock(BaseStep.class, withSettings().extraInterfaces(StepInterface.class));
StepMeta mockStepMeta = mock(StepMeta.class);
BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
StepMetaInterface stepMetaInterface = (StepMetaInterface) bsm;
when(mockStep.getStepMeta()).thenReturn(mockStepMeta);
when(mockStepMeta.getStepMetaInterface()).thenReturn(stepMetaInterface);
Trans mockTrans = mock(Trans.class);
when(mockStep.getTrans()).thenReturn(mockTrans);
IExecutionProfile executionProfile = mock(IExecutionProfile.class);
IExecutionData executionData = mock(IExecutionData.class);
when(executionProfile.getExecutionData()).thenReturn(executionData);
LineageHolder holder = new LineageHolder();
holder.setExecutionProfile(executionProfile);
TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
StepExternalConsumerRowListener listener = new StepExternalConsumerRowListener(consumer, mockStep);
RowMetaInterface rmi = mock(RowMetaInterface.class);
Object[] row = new Object[0];
listener.rowReadEvent(rmi, row);
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.
the class StepExternalResourceConsumerListenerTest method testCallStepExtensionPoint.
@Test
public void testCallStepExtensionPoint() throws Exception {
StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
stepExtensionPoint.setStepExternalResourceConsumerProvider(MetaverseTestUtils.getStepExternalResourceConsumerProvider());
StepMetaDataCombi stepCombi = mock(StepMetaDataCombi.class);
BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
stepCombi.meta = (StepMetaInterface) bsm;
stepCombi.step = mock(StepInterface.class);
stepCombi.stepMeta = mock(StepMeta.class);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
Map<Class<? extends BaseStepMeta>, Set<IStepExternalResourceConsumer>> stepConsumerMap = new StepExternalResourceConsumerProvider().getStepConsumerMap();
Set<IStepExternalResourceConsumer> consumers = new HashSet<IStepExternalResourceConsumer>();
stepConsumerMap.put(bsm.getClass(), consumers);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
consumers.add(consumer);
Trans mockTrans = mock(Trans.class);
when(stepCombi.step.getTrans()).thenReturn(mockTrans);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
stepExtensionPoint.callExtensionPoint(null, stepCombi);
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializerTest method testWriteExternalResources.
@Test
public void testWriteExternalResources() throws Exception {
StepExternalResourceConsumerProvider mockConsumerMap = mock(StepExternalResourceConsumerProvider.class);
List<IStepExternalResourceConsumer> consumers = new ArrayList<IStepExternalResourceConsumer>();
Set<IExternalResourceInfo> externalResources = new HashSet<IExternalResourceInfo>();
IExternalResourceInfo info = mock(IExternalResourceInfo.class);
externalResources.add(info);
IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
when(consumer.getResourcesFromMeta(anyObject())).thenReturn(externalResources);
consumers.add(consumer);
Class<? extends BaseStepMeta> stepMetaClass = BaseStepMeta.class;
when(mockConsumerMap.getExternalResourceConsumers(any(Collection.class))).thenReturn(consumers);
serializer.setStepExternalResourceConsumerProvider(mockConsumerMap);
serializer.writeExternalResources(spyMeta, json, provider);
verify(mockConsumerMap).getExternalResourceConsumers(any(Collection.class));
verify(json).writeArrayFieldStart(AbstractStepMetaJsonSerializer.JSON_PROPERTY_EXTERNAL_RESOURCES);
verify(consumer).getResourcesFromMeta(anyObject());
verify(json, times(externalResources.size())).writeObject(any(IExternalResourceInfo.class));
verify(json).writeEndArray();
}
use of org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer in project pentaho-metaverse by pentaho.
the class AbstractStepMetaJsonSerializer method writeExternalResources.
protected void writeExternalResources(T meta, JsonGenerator json, SerializerProvider serializerProvider) throws IOException, JsonGenerationException {
Set<Class<?>> metaClassSet = new HashSet<Class<?>>(1);
metaClassSet.add(meta.getClass());
IStepExternalResourceConsumerProvider stepExternalResourceConsumerProvider = getStepExternalResourceConsumerProvider();
List<IStepExternalResourceConsumer> resourceConsumers = null;
if (stepExternalResourceConsumerProvider != null) {
resourceConsumers = stepExternalResourceConsumerProvider.getExternalResourceConsumers(metaClassSet);
}
json.writeArrayFieldStart(JSON_PROPERTY_EXTERNAL_RESOURCES);
if (resourceConsumers != null) {
for (IStepExternalResourceConsumer resourceConsumer : resourceConsumers) {
Collection<IExternalResourceInfo> infos = resourceConsumer.getResourcesFromMeta(meta);
for (IExternalResourceInfo info : infos) {
json.writeObject(info);
}
}
}
json.writeEndArray();
}
Aggregations