Search in sources :

Example 16 with RuntimeContainer

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

the class JDBCTypeMappingTestIT method testGetSchema.

@Test
public void testGetSchema() throws Exception {
    TJDBCInputDefinition definition = new TJDBCInputDefinition();
    TJDBCInputProperties properties = DBTestUtils.createCommonJDBCInputProperties(allSetting, definition);
    properties.main.schema.setValue(DBTestUtils.createTestSchema3(true, tablename));
    properties.tableSelection.tablename.setValue(tablename);
    properties.sql.setValue(DBTestUtils.getSQL(tablename));
    JDBCSource source = DBTestUtils.createCommonJDBCSource(properties);
    RuntimeContainer container = new DefaultComponentRuntimeContainerImpl() {

        @Override
        public String getCurrentComponentId() {
            return "tJDBCInput1";
        }
    };
    java.net.URL mappings_url = this.getClass().getResource("/mappings");
    mappings_url = DBTestUtils.correctURL(mappings_url);
    container.setComponentData(container.getCurrentComponentId(), ComponentConstants.MAPPING_URL_SUBFIX, mappings_url);
    Schema schema = source.getEndpointSchema(container, tablename);
    assertEquals(tablename, schema.getName().toUpperCase());
    List<Field> columns = schema.getFields();
    testMetadata(columns);
}
Also used : Field(org.apache.avro.Schema.Field) DefaultComponentRuntimeContainerImpl(org.talend.components.api.container.DefaultComponentRuntimeContainerImpl) Schema(org.apache.avro.Schema) TJDBCInputProperties(org.talend.components.jdbc.tjdbcinput.TJDBCInputProperties) JDBCSource(org.talend.components.jdbc.runtime.JDBCSource) TJDBCInputDefinition(org.talend.components.jdbc.tjdbcinput.TJDBCInputDefinition) RuntimeContainer(org.talend.components.api.container.RuntimeContainer) Test(org.junit.Test)

Example 17 with RuntimeContainer

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

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

the class MarkLogicWriterTest method prepareDocManagerText.

private DocumentManager prepareDocManagerText(MarkLogicOutputProperties.Action action, MarkLogicOutputProperties.DocType docType, Object docContent) throws IOException {
    MarkLogicSink sink = new MarkLogicSink();
    MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
    properties.init();
    properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
    properties.docType.setValue(docType);
    properties.action.setValue(action);
    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);
    writer = sink.createWriteOperation().createWriter(mockedContainer);
    GenericData.Record indexedRecord = new GenericData.Record(properties.datasetProperties.main.schema.getValue());
    indexedRecord.put(0, "docId");
    indexedRecord.put(1, docContent);
    writer.open("123");
    writer.docMgr = markLogicDocMngrMock;
    writer.write(indexedRecord);
    return markLogicDocMngrMock;
}
Also used : DatabaseClient(com.marklogic.client.DatabaseClient) MarkLogicOutputProperties(org.talend.components.marklogic.tmarklogicoutput.MarkLogicOutputProperties) DocumentManager(com.marklogic.client.document.DocumentManager) IndexedRecord(org.apache.avro.generic.IndexedRecord) GenericData(org.apache.avro.generic.GenericData) RuntimeContainer(org.talend.components.api.container.RuntimeContainer)

Example 19 with RuntimeContainer

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

the class MarkLogicWriterTest method testInitDocManagerXML.

@Test
public void testInitDocManagerXML() 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.XML);
    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).newXMLDocumentManager();
}
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 20 with RuntimeContainer

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

the class MarkLogicWriterTest method testInitDocManagerMixed.

@Test
public void testInitDocManagerMixed() throws IOException {
    MarkLogicSink sink = new MarkLogicSink();
    MarkLogicOutputProperties properties = new MarkLogicOutputProperties("outputProperties");
    properties.init();
    properties.connection.referencedComponent.componentInstanceId.setValue("Not null value");
    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).newDocumentManager();
}
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)

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