use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicWriterTest method testUpsertWithAutoGenerateDocId.
@Test
public void testUpsertWithAutoGenerateDocId() throws IOException {
MarkLogicSink sink = new MarkLogicSink();
MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
properties.init();
properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
properties.docType.setValue(MarkLogicOutputProperties.DocType.BINARY);
properties.action.setValue(MarkLogicOutputProperties.Action.UPSERT);
properties.autoGenerateDocId.setValue(true);
properties.docIdPrefix.setValue("somePrefix");
sink.ioProperties = properties;
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient mockedClient = mock(DatabaseClient.class);
Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
DocumentManager markLogicDocMngrMock = mock(DocumentManager.class);
DocumentUriTemplate uriTemplateMock = mock(DocumentUriTemplate.class);
DocumentDescriptor descriptorMock = mock(DocumentDescriptor.class);
when(markLogicDocMngrMock.newDocumentUriTemplate(anyString())).thenReturn(uriTemplateMock);
when(markLogicDocMngrMock.create(any(DocumentUriTemplate.class), any(AbstractWriteHandle.class))).thenReturn(descriptorMock);
when(descriptorMock.getUri()).thenReturn("somePrefix/docId");
MarkLogicWriter writer = sink.createWriteOperation().createWriter(mockedContainer);
GenericData.Record indexedRecord = new GenericData.Record(properties.datasetProperties.main.schema.getValue());
indexedRecord.put(0, "docId");
File docContent = new File("someFile");
indexedRecord.put(1, docContent);
writer.open("123");
writer.docMgr = markLogicDocMngrMock;
writer.write(indexedRecord);
verify(markLogicDocMngrMock).write(eq("somePrefix/docId"), any(FileHandle.class));
assertFalse(((Collection<IndexedRecord>) writer.getSuccessfulWrites()).isEmpty());
}
use of com.marklogic.client.DatabaseClient 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));
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicDatastoreRuntimeTest method testDoHealthChecks.
@Test
public void testDoHealthChecks() {
DatabaseClient client = Mockito.mock(DatabaseClient.class);
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
Mockito.when(container.getComponentData("reference", MarkLogicConnection.CONNECTION)).thenReturn(client);
List<ValidationResult> healthChecks = (List<ValidationResult>) datastoreRuntime.doHealthChecks(container);
Assert.assertEquals(1, healthChecks.size());
Assert.assertEquals(ValidationResult.OK, healthChecks.get(0));
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class TMarkLogicCloseStandaloneTest method testCloseSuccess.
@Test
public void testCloseSuccess() {
MarkLogicCloseProperties closeProperties = new MarkLogicCloseProperties("close");
closeProperties.referencedComponent.componentInstanceId.setValue("referenced1");
RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
closeStandalone.initialize(container, closeProperties);
DatabaseClient client = Mockito.mock(DatabaseClient.class);
Mockito.when(container.getComponentData(closeProperties.getReferencedComponentId(), MarkLogicConnection.CONNECTION)).thenReturn(client);
closeStandalone.runAtDriver(container);
Mockito.verify(container, Mockito.only()).getComponentData(closeProperties.getReferencedComponentId(), MarkLogicConnection.CONNECTION);
Mockito.verify(client).release();
}
use of com.marklogic.client.DatabaseClient in project components by Talend.
the class MarkLogicInputSinkTest method testValidate.
@Test
public void testValidate() {
MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
inputProperties.init();
inputProperties.connection.referencedComponent.componentInstanceId.setValue("some value");
RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
DatabaseClient client = mock(DatabaseClient.class);
when(mockedContainer.getComponentData(inputProperties.connection.getReferencedComponentId(), "connection")).thenReturn(client);
inputSink.initialize(mockedContainer, inputProperties);
ValidationResult result = inputSink.validate(mockedContainer);
assertEquals(ValidationResult.Result.OK, result.getStatus());
}
Aggregations