Search in sources :

Example 1 with DatabaseClient

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

the class MarkLogicSourceOrSinkTest method testValidateCannotConnect.

@Test
public void testValidateCannotConnect() {
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    when(mockedClient.openTransaction()).thenThrow(new ForbiddenUserException("User not allowed"));
    PowerMockito.mockStatic(DatabaseClientFactory.class);
    when(DatabaseClientFactory.newClient(anyString(), anyInt(), anyString(), (DatabaseClientFactory.SecurityContext) anyObject())).thenReturn(mockedClient);
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProperties");
    sourceOrSink.initialize(null, inputProperties);
    assertEquals(Result.ERROR, sourceOrSink.validate(null).getStatus());
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) DatabaseClientFactory(com.marklogic.client.DatabaseClientFactory) ForbiddenUserException(com.marklogic.client.ForbiddenUserException) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with DatabaseClient

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

the class MarkLogicWriterTest method testInitDocManagerBinary.

@Test
public void testInitDocManagerBinary() 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);
    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).newBinaryDocumentManager();
}
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 3 with DatabaseClient

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

the class MarkLogicWriterTest method testInitDocManagerText.

@Test
public void testInitDocManagerText() 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.PLAIN_TEXT);
    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).newTextDocumentManager();
}
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 4 with DatabaseClient

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

the class MarkLogicWriterTest method testInitDocManagerJSON.

@Test
public void testInitDocManagerJSON() 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.JSON);
    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).newJSONDocumentManager();
}
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 5 with DatabaseClient

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

the class MarkLogicCriteriaReaderTest method testStartWithoutDocContentField.

@Test
public void testStartWithoutDocContentField() throws IOException {
    StringQueryDefinition mockedStringQueryDefinition = mock(StringQueryDefinition.class);
    QueryManager mockedQueryManager = mock(QueryManager.class);
    when(mockedQueryManager.newStringDefinition()).thenReturn(mockedStringQueryDefinition);
    when(mockedQueryManager.newStringDefinition(anyString())).thenReturn(mockedStringQueryDefinition);
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    when(mockedClient.newDocumentManager()).thenReturn(null);
    when(mockedClient.newQueryManager()).thenReturn(mockedQueryManager);
    SearchHandle searchHandle = Mockito.mock(SearchHandle.class);
    Mockito.when(mockedQueryManager.search(Mockito.eq(mockedStringQueryDefinition), Mockito.any(SearchHandle.class))).thenReturn(searchHandle);
    MarkLogicSource mockedSource = mock(MarkLogicSource.class);
    when(mockedSource.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
    MarkLogicInputProperties properties = new MarkLogicInputProperties("inputProperties");
    properties.init();
    Schema.Field docIdField = new Schema.Field("docId", AvroUtils._string(), null, (Object) null, Schema.Field.Order.IGNORE);
    properties.datasetProperties.main.schema.setValue(Schema.createRecord("docIdOnlySchema", null, null, false, Collections.singletonList(docIdField)));
    MarkLogicCriteriaReader criteriaReader = new MarkLogicCriteriaReader(mockedSource, null, properties);
    System.out.println(criteriaReader.start());
}
Also used : StringQueryDefinition(com.marklogic.client.query.StringQueryDefinition) DatabaseClient(com.marklogic.client.DatabaseClient) SearchHandle(com.marklogic.client.io.SearchHandle) Schema(org.apache.avro.Schema) QueryManager(com.marklogic.client.query.QueryManager) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) 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