Search in sources :

Example 6 with DocumentManager

use of com.marklogic.client.document.DocumentManager in project components by Talend.

the class MarkLogicWriterTest method prepareDocManagerText.

private DocumentManager prepareDocManagerText(MarkLogicOutputProperties.Action action, MarkLogicOutputProperties.DocType docType, Object docContent) throws IOException {
    MarkLogicSink sink = new MarkLogicSink();
    MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
    properties.init();
    properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
    properties.docType.setValue(docType);
    properties.action.setValue(action);
    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);
    writer = sink.createWriteOperation().createWriter(mockedContainer);
    GenericData.Record indexedRecord = new GenericData.Record(properties.datasetProperties.main.schema.getValue());
    indexedRecord.put(0, "docId");
    indexedRecord.put(1, docContent);
    writer.open("123");
    writer.docMgr = markLogicDocMngrMock;
    writer.write(indexedRecord);
    return markLogicDocMngrMock;
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) DocumentManager(com.marklogic.client.document.DocumentManager) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericData(org.apache.avro.generic.GenericData) RuntimeContainer(org.talend.components.api.container.RuntimeContainer)

Example 7 with DocumentManager

use of com.marklogic.client.document.DocumentManager in project components by Talend.

the class MarkLogicWriterTest method testFailedUpsert.

@Test
public void testFailedUpsert() throws IOException {
    DocumentManager markLogicDocMngrMock = prepareDocManagerText(MarkLogicOutputProperties.Action.UPSERT, MarkLogicOutputProperties.DocType.BINARY, new Object());
    verifyZeroInteractions(markLogicDocMngrMock);
}
Also used : DocumentManager(com.marklogic.client.document.DocumentManager) Matchers.anyObject(org.mockito.Matchers.anyObject) Test(org.junit.Test)

Example 8 with DocumentManager

use of com.marklogic.client.document.DocumentManager in project components by Talend.

the class MarkLogicWriterTest method testMarkLogicPatchJSON.

@Test
public void testMarkLogicPatchJSON() throws IOException {
    DocumentManager markLogicDocMngrMock = prepareDocManagerText(MarkLogicOutputProperties.Action.PATCH, MarkLogicOutputProperties.DocType.JSON);
    verify(markLogicDocMngrMock).patch(anyString(), (DocumentPatchHandle) anyObject());
}
Also used : DocumentManager(com.marklogic.client.document.DocumentManager) Test(org.junit.Test)

Example 9 with DocumentManager

use of com.marklogic.client.document.DocumentManager in project components by Talend.

the class MarkLogicWriterTest method testMarkLogicFailPatch.

@Test
public void testMarkLogicFailPatch() throws IOException {
    DocumentManager markLogicDocMngrMock = prepareDocManagerText(MarkLogicOutputProperties.Action.PATCH, MarkLogicOutputProperties.DocType.BINARY);
    verifyZeroInteractions(markLogicDocMngrMock);
    assertFalse(((Collection<IndexedRecord>) writer.getRejectedWrites()).isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) DocumentManager(com.marklogic.client.document.DocumentManager) Test(org.junit.Test)

Example 10 with DocumentManager

use of com.marklogic.client.document.DocumentManager 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());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FileHandle(com.marklogic.client.io.FileHandle) DocumentManager(com.marklogic.client.document.DocumentManager) DocumentUriTemplate(com.marklogic.client.document.DocumentUriTemplate) AbstractWriteHandle(com.marklogic.client.io.marker.AbstractWriteHandle) GenericData(org.apache.avro.generic.GenericData) DocumentDescriptor(com.marklogic.client.document.DocumentDescriptor) DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) File(java.io.File) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

DocumentManager (com.marklogic.client.document.DocumentManager)11 Test (org.junit.Test)10 MarkLogicOutputProperties (org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 DatabaseClient (com.marklogic.client.DatabaseClient)2 GenericData (org.apache.avro.generic.GenericData)2 Matchers.anyObject (org.mockito.Matchers.anyObject)2 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)2 DocumentDescriptor (com.marklogic.client.document.DocumentDescriptor)1 DocumentUriTemplate (com.marklogic.client.document.DocumentUriTemplate)1 FileHandle (com.marklogic.client.io.FileHandle)1 AbstractWriteHandle (com.marklogic.client.io.marker.AbstractWriteHandle)1 File (java.io.File)1