Search in sources :

Example 11 with MarkLogicInputProperties

use of org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties in project components by Talend.

the class MarkLogicRowProcessorTest method testCloseReferencedConnectionNotReleased.

@Test
public void testCloseReferencedConnectionNotReleased() throws IOException {
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    MarkLogicInputSink mockedSink = mock(MarkLogicInputSink.class);
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
    inputProperties.init();
    inputProperties.connection.referencedComponent.componentInstanceId.setValue(MarkLogicConnectionDefinition.COMPONENT_NAME + "_1");
    MarkLogicInputWriteOperation writeOperation = new MarkLogicInputWriteOperation(mockedSink, inputProperties);
    MarkLogicRowProcessor rowProcessor = writeOperation.createWriter(null);
    when(mockedSink.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
    rowProcessor.open("1");
    verify(mockedClient).newDocumentManager();
    rowProcessor.close();
    verifyNoMoreInteractions(mockedClient);
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 12 with MarkLogicInputProperties

use of org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties in project components by Talend.

the class MarkLogicRowProcessorTest method testClose.

@Test
public void testClose() throws IOException {
    DatabaseClient mockedClient = mock(DatabaseClient.class);
    MarkLogicInputSink mockedSink = mock(MarkLogicInputSink.class);
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
    inputProperties.init();
    MarkLogicInputWriteOperation writeOperation = new MarkLogicInputWriteOperation(mockedSink, inputProperties);
    MarkLogicRowProcessor rowProcessor = writeOperation.createWriter(null);
    when(mockedSink.connect(any(RuntimeContainer.class))).thenReturn(mockedClient);
    String uId = "123";
    rowProcessor.open(uId);
    Result result = rowProcessor.close();
    assertNotNull(result);
    assertEquals(uId, result.getuId());
    verify(mockedClient).release();
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Result(org.talend.components.api.component.runtime.Result) Test(org.junit.Test)

Example 13 with MarkLogicInputProperties

use of org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties in project components by Talend.

the class MarkLogicSourceOrSinkTest method testDocContentDocumentTypeSupported.

@Test
public void testDocContentDocumentTypeSupported() {
    MarkLogicInputProperties testInputProperties = new MarkLogicInputProperties("inputProperties");
    testInputProperties.init();
    Schema bytesSchema = prepareSchema(AvroUtils._short(), "id_Document");
    testInputProperties.datasetProperties.main.schema.setValue(bytesSchema);
    sourceOrSink.checkDocContentTypeSupported(testInputProperties.datasetProperties.main);
}
Also used : Schema(org.apache.avro.Schema) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 14 with MarkLogicInputProperties

use of org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties in project components by Talend.

the class MarkLogicSourceOrSinkTest method testDocContentBytesTypeSupported.

@Test
public void testDocContentBytesTypeSupported() {
    MarkLogicInputProperties testInputProperties = new MarkLogicInputProperties("inputProperties");
    testInputProperties.init();
    Schema bytesSchema = prepareSchema(AvroUtils._bytes(), null);
    testInputProperties.inputSchema.schema.setValue(bytesSchema);
    sourceOrSink.checkDocContentTypeSupported(testInputProperties.datasetProperties.main);
}
Also used : Schema(org.apache.avro.Schema) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 15 with MarkLogicInputProperties

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

Aggregations

Test (org.junit.Test)23 MarkLogicInputProperties (org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 DatabaseClient (com.marklogic.client.DatabaseClient)8 Schema (org.apache.avro.Schema)8 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)8 ValidationResult (org.talend.daikon.properties.ValidationResult)4 GenericData (org.apache.avro.generic.GenericData)2 IndexedRecord (org.apache.avro.generic.IndexedRecord)2 Result (org.talend.components.api.component.runtime.Result)2 MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)2 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)1 ForbiddenUserException (com.marklogic.client.ForbiddenUserException)1 SearchHandle (com.marklogic.client.io.SearchHandle)1 QueryManager (com.marklogic.client.query.QueryManager)1 StringQueryDefinition (com.marklogic.client.query.StringQueryDefinition)1 ArrayList (java.util.ArrayList)1 DocContentReader (org.talend.components.marklogic.runtime.input.strategies.DocContentReader)1