Search in sources :

Example 36 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class SandboxedRowGeneratorRuntimeTest method testBasic.

@Test
public void testBasic() throws Exception {
    final RowGeneratorProperties props = createComponentProperties();
    props.schemaFlow.schema.setValue(SampleSchemas.recordSimple());
    props.nbRows.setValue(95L);
    props.nbPartitions.setValue(10);
    RuntimeInfo ri = def.getRuntimeInfo(ExecutionEngine.BEAM, props, ConnectorTopology.OUTGOING);
    try (SandboxedInstance si = RuntimeUtil.createRuntimeClass(ri, getClass().getClassLoader())) {
        RuntimableRuntime<RowGeneratorProperties> runtime = (RuntimableRuntime<RowGeneratorProperties>) si.getInstance();
        runtime.initialize(null, props);
    }
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimableRuntime(org.talend.components.api.component.runtime.RuntimableRuntime) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) RowGeneratorProperties(org.talend.components.localio.rowgenerator.RowGeneratorProperties) Test(org.junit.Test)

Example 37 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class MarketoCustomObjectsSchemasProperties method beforeFormPresentCustomObjects.

public void beforeFormPresentCustomObjects() throws IOException {
    List<NamedThing> customObjectsNames;
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(RUNTIME_SOURCEORSINK_CLASS, USE_CURRENT_JVM_PROPS)) {
        MarketoSourceOrSinkRuntime sos = (MarketoSourceOrSinkRuntime) sandboxedInstance.getInstance();
        sos.initialize(null, this);
        customObjectsNames = sos.getSchemaNames(null);
    }
    selectedCustomObjectsNames.setPossibleValues(customObjectsNames);
    getForm(FORM_CUSTOMOBJECTS).setAllowBack(true);
    getForm(FORM_CUSTOMOBJECTS).setAllowFinish(true);
}
Also used : MarketoComponentDefinition.getSandboxedInstance(org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) MarketoSourceOrSinkRuntime(org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime) NamedThing(org.talend.daikon.NamedThing)

Example 38 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class GoogleDriveConnectionProperties method validateTestConnection.

public ValidationResult validateTestConnection() throws Exception {
    try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS, true)) {
        GoogleDriveProvideRuntime sos = (GoogleDriveProvideRuntime) sandboxedInstance.getInstance();
        sos.initialize(null, this);
        try {
            ValidationResultMutable vr = new ValidationResultMutable(sos.validateConnection(this));
            if (Result.OK.equals(vr.getStatus())) {
                getForm(FORM_WIZARD).setAllowFinish(true);
            } else {
                getForm(FORM_WIZARD).setAllowFinish(false);
            }
            return vr;
        } catch (Exception e) {
            LOG.error("[validateTestConnection] {}.", e.getMessage());
            return new ValidationResultMutable(Result.ERROR, e.getMessage());
        }
    }
}
Also used : GoogleDriveComponentDefinition.getSandboxedInstance(org.talend.components.google.drive.GoogleDriveComponentDefinition.getSandboxedInstance) SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) GoogleDriveProvideRuntime(org.talend.components.google.drive.GoogleDriveProvideRuntime) ValidationResultMutable(org.talend.daikon.properties.ValidationResultMutable)

Example 39 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class JDBCTableSelectionModule method beforeTablename.

public ValidationResult beforeTablename() throws IOException {
    JdbcRuntimeInfo jdbcRuntimeInfo = new JdbcRuntimeInfo(connection, "org.talend.components.jdbc.runtime.JDBCSource");
    try (SandboxedInstance sandboxI = RuntimeUtil.createRuntimeClass(jdbcRuntimeInfo, connection.getClass().getClassLoader())) {
        SourceOrSink ss = (SourceOrSink) sandboxI.getInstance();
        ss.initialize(null, (ComponentProperties) connection);
        List<NamedThing> tablenames = ss.getSchemaNames(null);
        tablename.setPossibleNamedThingValues(tablenames);
    } catch (ComponentException ex) {
        return ex.getValidationResult();
    }
    return ValidationResult.OK;
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) SourceOrSink(org.talend.components.api.component.runtime.SourceOrSink) JdbcRuntimeInfo(org.talend.components.jdbc.JdbcRuntimeInfo) ComponentException(org.talend.components.api.exception.ComponentException) NamedThing(org.talend.daikon.NamedThing)

Example 40 with SandboxedInstance

use of org.talend.daikon.sandbox.SandboxedInstance in project components by Talend.

the class MarkLogicConnectionPropertiesTest method testValidateConnection.

@Test
public void testValidateConnection() {
    testConnectionProperties.init();
    SandboxedInstance sandbox = Mockito.mock(SandboxedInstance.class);
    PowerMockito.mockStatic(SandboxInstanceFactory.class);
    PowerMockito.when(SandboxInstanceFactory.createSandboxedInstance(Mockito.any(RuntimeInfo.class), Mockito.any(ClassLoader.class), Mockito.eq(false))).thenReturn(sandbox);
    DatastoreRuntime<MarkLogicConnectionProperties> datastore = Mockito.mock(DatastoreRuntime.class);
    Mockito.when(sandbox.getInstance()).thenReturn(datastore);
    Mockito.when(datastore.doHealthChecks(null)).thenReturn(Collections.singletonList(new ValidationResult(Result.ERROR)));
    ValidationResult vr = testConnectionProperties.validateTestConnection();
    assertEquals(Result.ERROR, vr.getStatus());
    assertFalse(testConnectionProperties.getForm(MarkLogicConnectionProperties.WIZARD).isAllowFinish());
    Mockito.when(datastore.doHealthChecks(null)).thenReturn(Collections.singletonList(new ValidationResult(Result.OK)));
    vr = testConnectionProperties.validateTestConnection();
    assertEquals(Result.OK, vr.getStatus());
    Assert.assertTrue(testConnectionProperties.getForm(MarkLogicConnectionProperties.WIZARD).isAllowFinish());
}
Also used : SandboxedInstance(org.talend.daikon.sandbox.SandboxedInstance) RuntimeInfo(org.talend.daikon.runtime.RuntimeInfo) ValidationResult(org.talend.daikon.properties.ValidationResult) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SandboxedInstance (org.talend.daikon.sandbox.SandboxedInstance)66 Test (org.junit.Test)30 ValidationResult (org.talend.daikon.properties.ValidationResult)30 RuntimeInfo (org.talend.daikon.runtime.RuntimeInfo)28 Schema (org.apache.avro.Schema)20 IndexedRecord (org.apache.avro.generic.IndexedRecord)18 ArrayList (java.util.ArrayList)12 ComponentException (org.talend.components.api.exception.ComponentException)12 TJDBCRowDefinition (org.talend.components.jdbc.tjdbcrow.TJDBCRowDefinition)10 TJDBCRowProperties (org.talend.components.jdbc.tjdbcrow.TJDBCRowProperties)10 NamedThing (org.talend.daikon.NamedThing)9 DatasetRuntime (org.talend.components.common.dataset.runtime.DatasetRuntime)8 SalesforceDefinition.getSandboxedInstance (org.talend.components.salesforce.SalesforceDefinition.getSandboxedInstance)8 SalesforceRuntimeSourceOrSink (org.talend.components.salesforce.common.SalesforceRuntimeSourceOrSink)8 ValidationResultMutable (org.talend.daikon.properties.ValidationResultMutable)8 TalendRuntimeException (org.talend.daikon.exception.TalendRuntimeException)7 IOException (java.io.IOException)6 MarketoComponentDefinition.getSandboxedInstance (org.talend.components.marketo.MarketoComponentDefinition.getSandboxedInstance)6 MarketoSourceOrSinkRuntime (org.talend.components.marketo.runtime.MarketoSourceOrSinkRuntime)6 WriteOperation (org.talend.components.api.component.runtime.WriteOperation)5