Search in sources :

Example 11 with MarkLogicOutputProperties

use of org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties in project components by Talend.

the class MarkLogicWriterTest method testInitDocManagerXML.

@Test
public void testInitDocManagerXML() 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.XML);
    sink.ioProperties = properties;
    RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
    writer = sink.createWriteOperation().createWriter(mockedContainer);
    writer.open("123");
    verify(mockedClient).newXMLDocumentManager();
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 12 with MarkLogicOutputProperties

use of org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties in project components by Talend.

the class MarkLogicWriterTest method testInitDocManagerMixed.

@Test
public void testInitDocManagerMixed() throws IOException {
    MarkLogicSink sink = new MarkLogicSink();
    MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
    properties.init();
    properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
    sink.ioProperties = properties;
    RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    Mockito.when(mockedContainer.getComponentData(anyString(), anyString())).thenReturn(mockedClient);
    writer = sink.createWriteOperation().createWriter(mockedContainer);
    writer.open("123");
    verify(mockedClient).newDocumentManager();
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 13 with MarkLogicOutputProperties

use of org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties 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)

Example 14 with MarkLogicOutputProperties

use of org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties in project components by Talend.

the class MarkLogicWriterTest method testWriteNull.

@Test
public void testWriteNull() throws IOException {
    DocumentManager markLogicDocMngrMock = mock(DocumentManager.class);
    MarkLogicSink someSink = new MarkLogicSink();
    someSink.ioProperties = new MarkLogicOutputProperties("outputProps");
    writer = someSink.createWriteOperation().createWriter(null);
    writer.docMgr = markLogicDocMngrMock;
    writer.write(null);
    verifyZeroInteractions(markLogicDocMngrMock);
}
Also used : MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) DocumentManager(com.marklogic.client.document.DocumentManager) Test(org.junit.Test)

Example 15 with MarkLogicOutputProperties

use of org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties in project components by Talend.

the class MarkLogicSourceTest method testValidateWrongProperties.

@Test
public void testValidateWrongProperties() {
    MarkLogicOutputProperties wrongProperties = new MarkLogicOutputProperties("notInputProps");
    wrongProperties.init();
    source.initialize(null, wrongProperties);
    ValidationResult result = source.validate(null);
    assertEquals(ValidationResult.Result.ERROR, result.getStatus());
}
Also used : MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test)

Aggregations

MarkLogicOutputProperties (org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties)16 Test (org.junit.Test)14 DatabaseClient (com.marklogic.client.DatabaseClient)7 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)7 DocumentManager (com.marklogic.client.document.DocumentManager)4 ValidationResult (org.talend.daikon.properties.ValidationResult)3 GenericData (org.apache.avro.generic.GenericData)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)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 Before (org.junit.Before)1 Matchers.anyObject (org.mockito.Matchers.anyObject)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1