Search in sources :

Example 6 with MarkLogicConnectionProperties

use of org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties in project components by Talend.

the class MarkLogicDatasetPropertiesTest method setup.

@Before
public void setup() {
    properties = new MarkLogicDatasetProperties("dataset");
    datastore = new MarkLogicConnectionProperties("datastore");
    properties.setDatastoreProperties(datastore);
}
Also used : MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) Before(org.junit.Before)

Example 7 with MarkLogicConnectionProperties

use of org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties 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 8 with MarkLogicConnectionProperties

use of org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties in project components by Talend.

the class TMarkLogicConnectionStandaloneTest method setup.

@Before
public void setup() {
    connectionStandalone = new TMarkLogicConnectionStandalone();
    PowerMockito.mockStatic(DatabaseClientFactory.class);
    client = Mockito.mock(DatabaseClient.class);
    Mockito.when(DatabaseClientFactory.newClient(Mockito.anyString(), Mockito.anyInt(), Mockito.anyString(), Mockito.any(SecurityContext.class))).thenReturn(client);
    container = Mockito.mock(RuntimeContainer.class);
    connectionProperties = new MarkLogicConnectionProperties("connection");
    connectionProperties.authentication.setValue("BASIC");
    Mockito.when(container.getComponentData(Mockito.anyString(), Mockito.eq(MarkLogicConnection.CONNECTION))).thenReturn(client);
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) SecurityContext(com.marklogic.client.DatabaseClientFactory.SecurityContext) MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Before(org.junit.Before)

Example 9 with MarkLogicConnectionProperties

use of org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties in project components by Talend.

the class MarkLogicExternalBulkLoadRunnerTest method setUp.

@Before
public void setUp() {
    bulkLoadRuntime = new MarkLogicBulkLoad();
    connectionProperties = new MarkLogicConnectionProperties("connectionProperties");
    bulkLoadProperties = new MarkLogicBulkLoadProperties("bulkLoadProperties");
}
Also used : MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) MarkLogicBulkLoadProperties(org.talend.components.marklogic.tmarklogicbulkload.MarkLogicBulkLoadProperties) Before(org.junit.Before)

Example 10 with MarkLogicConnectionProperties

use of org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties in project components by Talend.

the class MarkLogicDatasetRuntimeTest method testWorkflow.

@SuppressWarnings("unchecked")
@Test
public void testWorkflow() {
    RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
    MarkLogicConnectionProperties connection = new MarkLogicConnectionProperties("datastore");
    connection.referencedComponent.componentInstanceId.setValue("reference");
    DatabaseClient connectionClient = Mockito.mock(DatabaseClient.class);
    GenericDocumentManager docManager = Mockito.mock(GenericDocumentManager.class);
    Mockito.when(connectionClient.newDocumentManager()).thenReturn(docManager);
    QueryManager queryManager = Mockito.mock(QueryManager.class);
    Mockito.when(connectionClient.newQueryManager()).thenReturn(queryManager);
    StringQueryDefinition stringQueryDefinition = Mockito.mock(StringQueryDefinition.class);
    Mockito.when(queryManager.newStringDefinition()).thenReturn(stringQueryDefinition);
    SearchHandle searchHandle = Mockito.mock(SearchHandle.class);
    Mockito.when(queryManager.search(Mockito.eq(stringQueryDefinition), Mockito.any(SearchHandle.class))).thenReturn(searchHandle);
    MatchDocumentSummary[] results = new MatchDocumentSummary[2];
    MatchDocumentSummary firstRecord = Mockito.mock(MatchDocumentSummary.class);
    MatchDocumentSummary secondRecord = Mockito.mock(MatchDocumentSummary.class);
    results[0] = firstRecord;
    results[1] = secondRecord;
    Mockito.when(container.getComponentData("reference", MarkLogicConnection.CONNECTION)).thenReturn(connectionClient);
    MarkLogicDatasetProperties properties = new MarkLogicDatasetProperties("dataset");
    connection.init();
    properties.setDatastoreProperties(connection);
    properties.init();
    datasetRuntime.initialize(container, properties);
    Assert.assertEquals(2, datasetRuntime.getSchema().getFields().size());
    Assert.assertEquals("docId", datasetRuntime.getSchema().getFields().get(0).name());
    Assert.assertEquals("docContent", datasetRuntime.getSchema().getFields().get(1).name());
    Mockito.when(searchHandle.getMatchResults()).thenReturn(results);
    Mockito.when(searchHandle.getTotalResults()).thenReturn(2l);
    Mockito.when(docManager.readAs(Mockito.anyString(), Mockito.any(Class.class))).thenReturn(new Object());
    Consumer<IndexedRecord> consumer = Mockito.mock(Consumer.class);
    datasetRuntime.getSample(2, consumer);
    Mockito.verify(consumer, Mockito.times(2)).accept(Mockito.any(IndexedRecord.class));
}
Also used : GenericDocumentManager(com.marklogic.client.document.GenericDocumentManager) IndexedRecord(org.apache.avro.generic.IndexedRecord) MatchDocumentSummary(com.marklogic.client.query.MatchDocumentSummary) StringQueryDefinition(com.marklogic.client.query.StringQueryDefinition) DatabaseClient(com.marklogic.client.DatabaseClient) SearchHandle(com.marklogic.client.io.SearchHandle) MarkLogicConnectionProperties(org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties) QueryManager(com.marklogic.client.query.QueryManager) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

MarkLogicConnectionProperties (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionProperties)17 Test (org.junit.Test)8 Before (org.junit.Before)7 DatabaseClient (com.marklogic.client.DatabaseClient)4 MarkLogicConnectionPropertiesTest (org.talend.components.marklogic.tmarklogicconnection.MarkLogicConnectionPropertiesTest)4 RuntimeContainer (org.talend.components.api.container.RuntimeContainer)3 MarkLogicBulkLoadProperties (org.talend.components.marklogic.tmarklogicbulkload.MarkLogicBulkLoadProperties)3 SecurityContext (com.marklogic.client.DatabaseClientFactory.SecurityContext)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 MarkLogicInputProperties (org.talend.components.marklogic.tmarklogicinput.MarkLogicInputProperties)2 DatabaseClientFactory (com.marklogic.client.DatabaseClientFactory)1 GenericDocumentManager (com.marklogic.client.document.GenericDocumentManager)1 SearchHandle (com.marklogic.client.io.SearchHandle)1 MatchDocumentSummary (com.marklogic.client.query.MatchDocumentSummary)1 QueryManager (com.marklogic.client.query.QueryManager)1 StringQueryDefinition (com.marklogic.client.query.StringQueryDefinition)1 IndexedRecord (org.apache.avro.generic.IndexedRecord)1 MarkLogicErrorCode (org.talend.components.marklogic.exceptions.MarkLogicErrorCode)1 MarkLogicException (org.talend.components.marklogic.exceptions.MarkLogicException)1 ValidationResult (org.talend.daikon.properties.ValidationResult)1