use of org.talend.components.salesforce.schema.SalesforceSchemaHelper in project components by Talend.
the class TSalesforceInputPropertiesTest method testValidateGuessSchema.
@Test
public void testValidateGuessSchema() throws Exception {
properties.init();
String query = "\"SELECT Id, Name, BillingCity FROM Account\"";
String invalidQuery = "qwerty";
Schema schema = SchemaBuilder.record("Result").fields().name("Id").type().stringType().noDefault().name("Name").type().stringType().noDefault().name("BillingCity").type().stringType().noDefault().endRecord();
Schema emptySchema = AvroUtils.createEmptySchema();
properties.module.moduleName.setValue("Account");
properties.module.main.schema.setValue(emptySchema);
properties.query.setValue(query);
try (MockRuntimeSourceOrSinkTestFixture testFixture = new MockRuntimeSourceOrSinkTestFixture(equalTo(properties), createDefaultTestDataset())) {
testFixture.setUp();
// Valid
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessSchema(eq(query))).thenReturn(schema);
ValidationResult vr1 = properties.validateGuessSchema();
assertEquals(ValidationResult.Result.OK, vr1.getStatus());
assertEquals(schema, properties.module.main.schema.getValue());
// Not valid / Error
properties.query.setValue(invalidQuery);
properties.module.main.schema.setValue(schema);
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessSchema(eq(invalidQuery))).thenThrow(TalendRuntimeException.createUnexpectedException("ERROR"));
ValidationResult vr2 = properties.validateGuessSchema();
assertEquals(ValidationResult.Result.ERROR, vr2.getStatus());
assertEquals(schema, properties.module.main.schema.getValue());
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessSchema(eq(invalidQuery))).thenThrow(new RuntimeException("ERROR"));
vr2 = properties.validateGuessSchema();
assertEquals(ValidationResult.Result.ERROR, vr2.getStatus());
assertEquals(schema, properties.module.main.schema.getValue());
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessSchema(eq(invalidQuery))).thenThrow(new IOException("I/O ERROR"));
vr2 = properties.validateGuessSchema();
assertEquals(ValidationResult.Result.ERROR, vr2.getStatus());
assertEquals(schema, properties.module.main.schema.getValue());
}
}
use of org.talend.components.salesforce.schema.SalesforceSchemaHelper in project components by Talend.
the class TSalesforceInputProperties method validateGuessQuery.
public ValidationResult validateGuessQuery() {
ValidationResultMutable validationResult = new ValidationResultMutable();
try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS)) {
SalesforceRuntimeSourceOrSink salesforceSourceOrSink = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
salesforceSourceOrSink.initialize(null, this);
Schema schema = module.main.schema.getValue();
String moduleName = module.moduleName.getValue();
if (!schema.getFields().isEmpty()) {
String soqlQuery = ((SalesforceSchemaHelper<Schema>) salesforceSourceOrSink).guessQuery(schema, moduleName);
query.setValue(soqlQuery);
validationResult.setStatus(ValidationResult.Result.OK);
} else {
String errorMessage = getI18nMessage("errorMessage.validateGuessQueryError");
validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
query.setValue("");
}
} catch (TalendRuntimeException tre) {
validationResult.setStatus(ValidationResult.Result.ERROR);
validationResult.setMessage(getI18nMessage("errorMessage.validateGuessQuerySoqlError", tre.getMessage()));
}
return validationResult;
}
use of org.talend.components.salesforce.schema.SalesforceSchemaHelper in project components by Talend.
the class TSalesforceInputProperties method validateGuessSchema.
public ValidationResult validateGuessSchema() {
ValidationResultMutable validationResult = new ValidationResultMutable();
try (SandboxedInstance sandboxedInstance = getSandboxedInstance(SOURCE_OR_SINK_CLASS)) {
SalesforceRuntimeSourceOrSink salesforceSourceOrSink = (SalesforceRuntimeSourceOrSink) sandboxedInstance.getInstance();
salesforceSourceOrSink.initialize(null, this);
Schema schema = ((SalesforceSchemaHelper<Schema>) salesforceSourceOrSink).guessSchema(query.getValue());
module.main.schema.setValue(schema);
validationResult.setStatus(ValidationResult.Result.OK);
} catch (TalendRuntimeException tre) {
String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaSoqlError", tre.getMessage());
validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
} catch (RuntimeException e1) {
String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaRuntimeError", e1.getMessage());
validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
} catch (IOException e2) {
String errorMessage = getI18nMessage("errorMessage.validateGuessSchemaConnectionError", e2.getMessage());
validationResult.setStatus(ValidationResult.Result.ERROR).setMessage(errorMessage);
}
return validationResult;
}
use of org.talend.components.salesforce.schema.SalesforceSchemaHelper in project components by Talend.
the class TSalesforceInputPropertiesTest method testValidateGuessQuery.
@Test
public void testValidateGuessQuery() throws Exception {
properties.init();
String query = "\"SELECT Id, Name, BillingCity FROM Account\"";
Schema schema = SchemaBuilder.record("Result").fields().name("Id").type().stringType().noDefault().name("Name").type().stringType().noDefault().name("BillingCity").type().stringType().noDefault().endRecord();
Schema emptySchema = AvroUtils.createEmptySchema();
properties.module.moduleName.setValue("Account");
properties.module.main.schema.setValue(schema);
try (MockRuntimeSourceOrSinkTestFixture testFixture = new MockRuntimeSourceOrSinkTestFixture(equalTo(properties), createDefaultTestDataset())) {
testFixture.setUp();
// Valid
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessQuery(eq(schema), eq("Account"))).thenReturn(query);
ValidationResult vr1 = properties.validateGuessQuery();
assertEquals(ValidationResult.Result.OK, vr1.getStatus());
assertEquals(query, properties.query.getValue());
// Not valid
properties.module.main.schema.setValue(emptySchema);
ValidationResult vr2 = properties.validateGuessQuery();
assertEquals(ValidationResult.Result.ERROR, vr2.getStatus());
assertEquals("", properties.query.getValue());
// Error
when(((SalesforceSchemaHelper) testFixture.runtimeSourceOrSink).guessQuery(eq(schema), eq("Account"))).thenThrow(TalendRuntimeException.createUnexpectedException("ERROR"));
properties.module.main.schema.setValue(schema);
properties.query.setValue(query);
ValidationResult vr3 = properties.validateGuessQuery();
assertEquals(ValidationResult.Result.ERROR, vr3.getStatus());
assertEquals(query, properties.query.getValue());
}
}
Aggregations