Search in sources :

Example 21 with MarkLogicInputProperties

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

the class MarkLogicRowProcessorTest method testOpen.

@Test
public void testOpen() 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);
    rowProcessor.open("123");
    assertNotNull(rowProcessor.docContentReader);
}
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 22 with MarkLogicInputProperties

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

the class MarkLogicRowProcessorTest method testWriteCorrectRecord.

@Test
public void testWriteCorrectRecord() throws IOException {
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
    inputProperties.init();
    inputProperties.docIdColumn.setValue(inputProperties.datasetProperties.main.schema.getValue().getFields().get(0).name());
    MarkLogicInputSink inputSink = new MarkLogicInputSink();
    MarkLogicInputWriteOperation inputWriteOperation = new MarkLogicInputWriteOperation(inputSink, inputProperties);
    MarkLogicRowProcessor rowProcessor = inputWriteOperation.createWriter(null);
    DocContentReader mockedDocContentReader = mock(DocContentReader.class);
    rowProcessor.docContentReader = mockedDocContentReader;
    GenericData.Record correctRecord = new GenericData.Record(inputProperties.datasetProperties.main.schema.getValue());
    correctRecord.put(0, "docId");
    rowProcessor.write(correctRecord);
    verify(mockedDocContentReader).readDocument("docId");
    assertTrue(((ArrayList<IndexedRecord>) rowProcessor.getSuccessfulWrites()).size() > 0);
}
Also used : DocContentReader(org.talend.components.marklogic.runtime.input.strategies.DocContentReader) ArrayList(java.util.ArrayList) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericData(org.apache.avro.generic.GenericData) MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) Test(org.junit.Test)

Example 23 with MarkLogicInputProperties

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

the class MarkLogicRowProcessorTest method testCloseResult.

@Test
public void testCloseResult() throws IOException {
    MarkLogicInputSink sink = new MarkLogicInputSink();
    // set reference connection to avoid closing
    MarkLogicInputProperties inputProperties = new MarkLogicInputProperties("inputProps");
    inputProperties.init();
    inputProperties.connection.referencedComponent.componentInstanceId.setValue(MarkLogicConnectionDefinition.COMPONENT_NAME + "_1");
    MarkLogicInputWriteOperation writeOperation = new MarkLogicInputWriteOperation(sink, inputProperties);
    MarkLogicRowProcessor rowProcessor = writeOperation.createWriter(null);
    long longNBLine = Long.MAX_VALUE;
    rowProcessor.totalCounter = longNBLine;
    Result longResult = rowProcessor.close();
    assertTrue(longResult instanceof ResultWithLongNB);
    assertEquals(longNBLine, ((ResultWithLongNB) longResult).totalCountLong);
}
Also used : MarkLogicInputProperties(org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties) Result(org.talend.components.api.component.runtime.Result) 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