use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testInsertProject.
/**
* Checks {@link JiraInsertWriter#write(Object)} creates project on Jira server
*
* @throws IOException
*/
public void testInsertProject() throws IOException {
IndexedRecord insertProjectRecord = new GenericData.Record(INSERT_SCHEMA);
String insertProject = "{\"key\":\"ITP\",\"name\":\"Integration Test Project\",\"projectTemplateKey\":" + "\"com.atlassian.jira-core-project-templates:jira-core-project-management\",\"lead\":\"UserID\"}";
insertProject = insertProject.replace("UserID", USER);
insertProjectRecord.put(0, insertProject);
JiraWriter insertProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.PROJECT, Action.INSERT);
insertProjectWriter.open("insProj");
try {
insertProjectWriter.write(insertProjectRecord);
insertProjectWriter.close();
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
LOG.error(rejectError);
collector.addError(new Throwable(rejectError));
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testDeleteProject.
/**
* Checks {@link JiraDeleteWriter#write(Object)} deletes project from Jira server
*
* @throws IOException
*/
public void testDeleteProject() throws IOException {
IndexedRecord deleteProjectRecord = new GenericData.Record(DELETE_SCHEMA);
deleteProjectRecord.put(0, "ITP");
JiraWriter deleteProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.PROJECT, Action.DELETE);
deleteProjectWriter.open("delProj");
try {
deleteProjectWriter.write(deleteProjectRecord);
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
LOG.error(rejectError);
collector.addError(new Throwable(rejectError));
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpdate.
@Test
public void testUpdate() throws Throwable {
List<String> ids = util.createTestData();
String id = ids.get(0);
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
Map<String, String> datarow = new HashMap<String, String>();
datarow.put("Id", id);
datarow.put("FirstName", "Wei");
datarow.put("LastName", "Wang");
// update the field
datarow.put("Phone", "010-89492686");
testData.add(datarow);
datarow = new HashMap<String, String>();
// should reject
datarow.put("Id", "not_exist");
datarow.put("FirstName", "Who");
datarow.put("LastName", "Who");
datarow.put("Phone", "010-89492686");
testData.add(datarow);
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema4());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema4(), testData);
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema4(), util.getTestSchema4());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.UPDATE);
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String phone = (String) record.get(3);
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} catch (DataRejectException e) {
java.util.Map<String, Object> info = e.getRejectInfo();
Object data = info.get("talend_record");
String err = (String) info.get("error");
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String firstname = (String) record.get(1);
String lastname = (String) record.get(2);
String phone = (String) record.get(3);
Assert.assertNull(resultid);
Assert.assertEquals("Who", firstname);
Assert.assertEquals("Who", lastname);
Assert.assertEquals("010-89492686", phone);
Assert.assertTrue(err != null);
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class SalesforceBulkLoadTestIT method testUpsert.
@Test
public void testUpsert() throws Throwable {
List<String> ids = util.createTestData();
String id = ids.get(0);
final List<Map<String, String>> testData = new ArrayList<Map<String, String>>();
Map<String, String> datarow = new HashMap<String, String>();
// should update
datarow.put("Id", id);
datarow.put("FirstName", "Wei");
datarow.put("LastName", "Wang");
// update the field
datarow.put("Phone", "010-89492686");
testData.add(datarow);
datarow = new HashMap<String, String>();
// should insert
datarow.put("Id", null);
datarow.put("FirstName", "Who");
datarow.put("LastName", "Who");
datarow.put("Phone", "010-89492686");
testData.add(datarow);
String data_file = tempFolder.newFile("data.txt").getAbsolutePath();
// outputbulk part
TSalesforceOutputBulkDefinition definition = (TSalesforceOutputBulkDefinition) getComponentService().getComponentDefinition(TSalesforceOutputBulkDefinition.COMPONENT_NAME);
TSalesforceOutputBulkProperties modelProperties = util.simulateUserBasicAction(definition, data_file, util.getTestSchema4());
util.simulateRuntimeCaller(definition, modelProperties, util.getTestSchema4(), testData);
// bulkexec part
TSalesforceBulkExecDefinition defin = (TSalesforceBulkExecDefinition) getComponentService().getComponentDefinition(TSalesforceBulkExecDefinition.COMPONENT_NAME);
TSalesforceBulkExecProperties modelProps = (TSalesforceBulkExecProperties) defin.createRuntimeProperties();
Reader reader = util.initReader(defin, data_file, modelProps, util.getTestSchema4(), util.getTestSchema4());
modelProps.outputAction.setValue(TSalesforceBulkExecProperties.OutputAction.UPSERT);
modelProps.upsertKeyColumn.setValue("Id");
try {
IndexedRecordConverter<Object, ? extends IndexedRecord> factory = null;
int index = -1;
for (boolean available = reader.start(); available; available = reader.advance()) {
try {
Object data = reader.getCurrent();
factory = initCurrentData(factory, data);
IndexedRecord record = factory.convertToAvro(data);
String resultid = (String) record.get(0);
String phone = (String) record.get(3);
index++;
if (index == 0) {
Assert.assertEquals(id, resultid);
Assert.assertEquals("010-89492686", phone);
} else if (index == 1) {
Assert.assertTrue(resultid != null);
Assert.assertEquals("010-89492686", phone);
}
} catch (DataRejectException e) {
Assert.fail(e.getMessage());
}
}
} finally {
try {
reader.close();
} finally {
util.deleteTestData(ids);
}
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class SalesforceBulkExecReader method getCurrent.
@Override
public IndexedRecord getCurrent() {
BulkResult result = currentBatchResult.get(resultIndex);
IndexedRecord record = null;
try {
record = ((BulkResultAdapterFactory) getFactory()).convertToAvro(result);
} catch (IOException e) {
throw new ComponentException(e);
}
if ("true".equalsIgnoreCase((String) result.getValue("Success"))) {
return record;
} else {
Map<String, Object> resultMessage = new HashMap<String, Object>();
String error = (String) result.getValue("Error");
resultMessage.put("error", error);
resultMessage.put("talend_record", record);
throw new DataRejectException(resultMessage);
}
}
Aggregations