use of com.marklogic.client.document.GenericDocumentManager in project components by Talend.
the class MarkLogicDatasetRuntimeTest method testWorkflow.
@SuppressWarnings("unchecked")
@Test
public void testWorkflow() {
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
MarkLogicConnectionProperties connection = new MarkLogicConnectionProperties("datastore");
connection.referencedComponent.componentInstanceId.setValue("reference");
DatabaseClient connectionClient = Mockito.mock(DatabaseClient.class);
GenericDocumentManager docManager = Mockito.mock(GenericDocumentManager.class);
Mockito.when(connectionClient.newDocumentManager()).thenReturn(docManager);
QueryManager queryManager = Mockito.mock(QueryManager.class);
Mockito.when(connectionClient.newQueryManager()).thenReturn(queryManager);
StringQueryDefinition stringQueryDefinition = Mockito.mock(StringQueryDefinition.class);
Mockito.when(queryManager.newStringDefinition()).thenReturn(stringQueryDefinition);
SearchHandle searchHandle = Mockito.mock(SearchHandle.class);
Mockito.when(queryManager.search(Mockito.eq(stringQueryDefinition), Mockito.any(SearchHandle.class))).thenReturn(searchHandle);
MatchDocumentSummary[] results = new MatchDocumentSummary[2];
MatchDocumentSummary firstRecord = Mockito.mock(MatchDocumentSummary.class);
MatchDocumentSummary secondRecord = Mockito.mock(MatchDocumentSummary.class);
results[0] = firstRecord;
results[1] = secondRecord;
Mockito.when(container.getComponentData("reference", MarkLogicConnection.CONNECTION)).thenReturn(connectionClient);
MarkLogicDatasetProperties properties = new MarkLogicDatasetProperties("dataset");
connection.init();
properties.setDatastoreProperties(connection);
properties.init();
datasetRuntime.initialize(container, properties);
Assert.assertEquals(2, datasetRuntime.getSchema().getFields().size());
Assert.assertEquals("docId", datasetRuntime.getSchema().getFields().get(0).name());
Assert.assertEquals("docContent", datasetRuntime.getSchema().getFields().get(1).name());
Mockito.when(searchHandle.getMatchResults()).thenReturn(results);
Mockito.when(searchHandle.getTotalResults()).thenReturn(2l);
Mockito.when(docManager.readAs(Mockito.anyString(), Mockito.any(Class.class))).thenReturn(new Object());
Consumer<IndexedRecord> consumer = Mockito.mock(Consumer.class);
datasetRuntime.getSample(2, consumer);
Mockito.verify(consumer, Mockito.times(2)).accept(Mockito.any(IndexedRecord.class));
}
Aggregations