Search in sources :

Example 21 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer in project components by Talend.

the class MarkLogicWriterTest method testUpsertWithAutoGenerateDocId.

@Test
public void testUpsertWithAutoGenerateDocId() 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);
    properties.action.setValue(MarkLogicOutputProperties.Action.UPSERT);
    properties.autoGenerateDocId.setValue(true);
    properties.docIdPrefix.setValue("somePrefix");
    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);
    DocumentUriTemplate uriTemplateMock = mock(DocumentUriTemplate.class);
    DocumentDescriptor descriptorMock = mock(DocumentDescriptor.class);
    when(markLogicDocMngrMock.newDocumentUriTemplate(anyString())).thenReturn(uriTemplateMock);
    when(markLogicDocMngrMock.create(any(DocumentUriTemplate.class), any(AbstractWriteHandle.class))).thenReturn(descriptorMock);
    when(descriptorMock.getUri()).thenReturn("somePrefix/docId");
    MarkLogicWriter writer = sink.createWriteOperation().createWriter(mockedContainer);
    GenericData.Record indexedRecord = new GenericData.Record(properties.datasetProperties.main.schema.getValue());
    indexedRecord.put(0, "docId");
    File docContent = new File("someFile");
    indexedRecord.put(1, docContent);
    writer.open("123");
    writer.docMgr = markLogicDocMngrMock;
    writer.write(indexedRecord);
    verify(markLogicDocMngrMock).write(eq("somePrefix/docId"), any(FileHandle.class));
    assertFalse(((Collection<IndexedRecord>) writer.getSuccessfulWrites()).isEmpty());
}
Also used : IndexedRecord(org.apache.avro.generic.IndexedRecord) FileHandle(com.marklogic.client.io.FileHandle) DocumentManager(com.marklogic.client.document.DocumentManager) DocumentUriTemplate(com.marklogic.client.document.DocumentUriTemplate) AbstractWriteHandle(com.marklogic.client.io.marker.AbstractWriteHandle) GenericData(org.apache.avro.generic.GenericData) DocumentDescriptor(com.marklogic.client.document.DocumentDescriptor) DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) IndexedRecord(org.apache.avro.generic.IndexedRecord) File(java.io.File) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 22 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer in project components by Talend.

the class MarkLogicInputWriteOperationTest method testInitialize.

@Test
public void testInitialize() {
    RuntimeContainer mockedContainer = mock(RuntimeContainer.class);
    MarkLogicInputWriteOperation inputWriteOperation = new MarkLogicInputWriteOperation(null, null);
    inputWriteOperation.initialize(mockedContainer);
    verifyZeroInteractions(mockedContainer);
}
Also used : RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 23 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer 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)

Example 24 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer in project components by Talend.

the class MarkLogicDatastoreRuntimeTest method testDoHealthChecks.

@Test
public void testDoHealthChecks() {
    DatabaseClient client = Mockito.mock(DatabaseClient.class);
    RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
    Mockito.when(container.getComponentData("reference", MarkLogicConnection.CONNECTION)).thenReturn(client);
    List<ValidationResult> healthChecks = (List<ValidationResult>) datastoreRuntime.doHealthChecks(container);
    Assert.assertEquals(1, healthChecks.size());
    Assert.assertEquals(ValidationResult.OK, healthChecks.get(0));
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) List(java.util.List) ValidationResult(org.talend.daikon.properties.ValidationResult) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 25 with RuntimeContainer

use of org.talend.components.api.container.RuntimeContainer in project components by Talend.

the class TMarkLogicCloseStandaloneTest method testCloseSuccess.

@Test
public void testCloseSuccess() {
    MarkLogicCloseProperties closeProperties = new MarkLogicCloseProperties("close");
    closeProperties.referencedComponent.componentInstanceId.setValue("referenced1");
    RuntimeContainer container = Mockito.mock(RuntimeContainer.class);
    closeStandalone.initialize(container, closeProperties);
    DatabaseClient client = Mockito.mock(DatabaseClient.class);
    Mockito.when(container.getComponentData(closeProperties.getReferencedComponentId(), MarkLogicConnection.CONNECTION)).thenReturn(client);
    closeStandalone.runAtDriver(container);
    Mockito.verify(container, Mockito.only()).getComponentData(closeProperties.getReferencedComponentId(), MarkLogicConnection.CONNECTION);
    Mockito.verify(client).release();
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicCloseProperties(org.talend.components.marklogic.tmarklogicclose.MarkLogicCloseProperties) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Aggregations

RuntimeContainer (org.talend.components.api.container.RuntimeContainer)36 Test (org.junit.Test)34 DatabaseClient (com.marklogic.client.DatabaseClient)14 Schema (org.apache.avro.Schema)10 IndexedRecord (org.apache.avro.generic.IndexedRecord)10 DefaultComponentRuntimeContainerImpl (org.talend.components.api.container.DefaultComponentRuntimeContainerImpl)9 MarkLogicOutputProperties (org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties)7 List (java.util.List)6 NetSuiteDatasetRuntime (org.talend.components.netsuite.NetSuiteDatasetRuntime)6 ValidationResult (org.talend.daikon.properties.ValidationResult)6 NetSuiteRuntimeImpl (org.talend.components.netsuite.v2016_2.NetSuiteRuntimeImpl)5 NetSuitePortType (com.netsuite.webservices.v2016_2.platform.NetSuitePortType)4 CustomFieldList (com.netsuite.webservices.v2016_2.platform.core.CustomFieldList)4 CustomRecordRef (com.netsuite.webservices.v2016_2.platform.core.CustomRecordRef)4 RecordRefList (com.netsuite.webservices.v2016_2.platform.core.RecordRefList)4 GetListRequest (com.netsuite.webservices.v2016_2.platform.messages.GetListRequest)4 ArrayList (java.util.ArrayList)4 Result (org.talend.components.api.component.runtime.Result)4 NetSuiteSink (org.talend.components.netsuite.NetSuiteSink)4 NetSuiteClientService (org.talend.components.netsuite.client.NetSuiteClientService)4