Search in sources :

Example 11 with DatabaseClient

use of com.marklogic.client.DatabaseClient in project components by Talend.

the class TMarkLogicCloseStandalone method runAtDriver.

@Override
public void runAtDriver(RuntimeContainer container) {
    if (container != null) {
        DatabaseClient containerClient = (DatabaseClient) container.getComponentData(properties.getReferencedComponentId(), MarkLogicConnection.CONNECTION);
        if (containerClient != null) {
            containerClient.release();
            LOGGER.info("Connection released");
        }
    }
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient)

Example 12 with DatabaseClient

use of com.marklogic.client.DatabaseClient in project components by Talend.

the class MarkLogicSourceOrSinkTest method testValidateWithReferenceConnection.

@Test
public void testValidateWithReferenceConnection() {
    RuntimeContainer container = mock(RuntimeContainer.class);
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    when(container.getComponentData(anyString(), eq(MarkLogicConnection.CONNECTION))).thenReturn(mockedClient);
    MarkLogicConnectionProperties connectionProperties = new MarkLogicConnectionProperties("connection");
    connectionProperties.init();
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProperties");
    inputProperties.connection.referencedComponent.setReference(connectionProperties);
    inputProperties.connection.referencedComponent.componentInstanceId.setValue(MarkLogicConnectionDefinition.COMPONENT_NAME + "_1");
    inputProperties.init();
    sourceOrSink.initialize(container, inputProperties);
    ValidationResult vr = sourceOrSink.validate(container);
    assertEquals(ValidationResult.Result.OK, vr.getStatus());
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) ValidationResult(org.talend.daikon.properties.ValidationResult) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 13 with DatabaseClient

use of com.marklogic.client.DatabaseClient 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 14 with DatabaseClient

use of com.marklogic.client.DatabaseClient 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 15 with DatabaseClient

use of com.marklogic.client.DatabaseClient 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)

Aggregations

DatabaseClient (com.marklogic.client.DatabaseClient)21 Test (org.junit.Test)18 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)18 MarkLogicInputProperties (org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties)8 MarkLogicOutputProperties (org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties)7 ValidationResult (org.talend.daikon.properties.ValidationResult)4 IndexedRecord (org.apache.avro.generic.IndexedRecord)3 MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)3 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)2 DocumentManager (com.marklogic.client.document.DocumentManager)2 SearchHandle (com.marklogic.client.io.SearchHandle)2 QueryManager (com.marklogic.client.query.QueryManager)2 StringQueryDefinition (com.marklogic.client.query.StringQueryDefinition)2 GenericData (org.apache.avro.generic.GenericData)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 SecurityContext (com.marklogic.client.DatabaseClientFactory.SecurityContext)1 ForbiddenUserException (com.marklogic.client.ForbiddenUserException)1 DocumentDescriptor (com.marklogic.client.document.DocumentDescriptor)1 DocumentUriTemplate (com.marklogic.client.document.DocumentUriTemplate)1 GenericDocumentManager (com.marklogic.client.document.GenericDocumentManager)1