use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testUpdateProject.
/**
* Checks {@link JiraUpdateWriter#write(Object)} updates project on Jira server
*
* @throws IOException
*/
public void testUpdateProject() throws IOException {
IndexedRecord updateProjectRecord = new GenericData.Record(UPDATE_SCHEMA);
String updateProject = "{\"name\":\"Updated Integration Test Project\",\"assigneeType\":\"PROJECT_LEAD\"}";
updateProjectRecord.put(0, "ITP");
updateProjectRecord.put(1, updateProject);
JiraWriter updateProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.PROJECT, Action.UPDATE);
updateProjectWriter.open("updProj");
try {
updateProjectWriter.write(updateProjectRecord);
updateProjectWriter.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 JiraDeleteWriterTestIT method testWriteUnauthorized.
/**
* Checks {@link JiraDeleteWriter#write()} throws {@link IOException} which message contains
* "User is not authenticated. Record wasn't deleted"
* in case server responses with 401 Unauthorized status code
*
* @throws IOException
*/
@Test
public void testWriteUnauthorized() throws IOException {
String expectedError = "User is not authenticated. Record wasn't deleted";
IndexedRecord badJsonRecord = new GenericData.Record(DELETE_SCHEMA);
badJsonRecord.put(0, "TP");
thrown.expect(IOException.class);
thrown.expectMessage("Reason: user is not authenticated. Record wasn't deleted");
thrown.expectMessage("Record: TP");
thrown.expectMessage("Error: ");
JiraWriter deleteProjectWriter = JiraTestsHelper.createWriter(HOST_PORT, WRONG_USER, PASS, Resource.PROJECT, Action.DELETE);
deleteProjectWriter.open("del");
try {
deleteProjectWriter.write(badJsonRecord);
fail();
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
assertEquals(expectedError, rejectError);
} finally {
deleteProjectWriter.close();
}
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class FileDelimitedReaderTestIT method readAndCheck.
// Read the records from the file and check the records
private void readAndCheck(TFileInputDelimitedProperties inputProps, int count, boolean dieOnError) throws Throwable {
FileDelimitedSource source = new FileDelimitedSource();
source.initialize(null, inputProps);
source.validate(null);
BoundedReader<IndexedRecord> reader = source.createReader(null);
boolean hasRecord = reader.start();
while (hasRecord) {
try {
IndexedRecord currentRecord = reader.getCurrent();
assertNotNull(currentRecord.getSchema());
StringBuffer sb = new StringBuffer();
int columnSize = currentRecord.getSchema().getFields().size();
for (int i = 0; i < columnSize; i++) {
// This convert exception maybe throw exception
// DataRejectException or the real exception which based on "Die on error" check or not.
sb.append(currentRecord.get(i));
if (i != columnSize - 1) {
sb.append(" - ");
}
}
LOGGER.debug("Valid row " + " :" + sb.toString());
sb.delete(0, sb.length());
} catch (DataRejectException e) {
if (dieOnError) {
throw e;
} else {
LOGGER.debug("Invalid row " + " :" + e.getRejectInfo().get(TFileInputDelimitedProperties.FIELD_ERROR_MESSAGE));
}
}
hasRecord = reader.advance();
}
reader.close();
Map<String, Object> returnMap = reader.getReturnValues();
assertNotNull(returnMap);
// Check the nb line with except value
assertEquals(count, returnMap.get(ComponentDefinition.RETURN_TOTAL_RECORD_COUNT));
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class FileDelimitedTestBasic method printLogRecords.
// Return the records are not rejected
protected List<IndexedRecord> printLogRecords(List<IndexedRecord> records) {
List<IndexedRecord> successRecords = new ArrayList<>();
if (records != null) {
StringBuffer sb = new StringBuffer();
for (int index = 0; index < records.size(); index++) {
try {
IndexedRecord record = records.get(index);
assertNotNull(record.getSchema());
int columnSize = record.getSchema().getFields().size();
for (int i = 0; i < columnSize; i++) {
sb.append(record.get(i));
if (i != columnSize - 1) {
sb.append(" - ");
}
}
LOGGER.debug("Row " + (index + 1) + " :" + sb.toString());
successRecords.add(record);
} catch (DataRejectException dre) {
LOGGER.debug("Row " + (index + 1) + " :" + dre.getRejectInfo().get("errorMessage"));
}
sb.delete(0, sb.length());
}
} else {
LOGGER.debug("Records list is empty!");
}
return successRecords;
}
use of org.talend.components.api.exception.DataRejectException in project components by Talend.
the class JiraWritersTestIT method testInsertIssues.
/**
* Checks {@link JiraInsertWriter#write(Object)} inserts issues on Jira server
*
* @throws IOException
*/
public void testInsertIssues() throws IOException {
IndexedRecord insertIssueRecord1 = new GenericData.Record(INSERT_SCHEMA);
String insertIssue1 = "{\"fields\":{\"project\":{\"key\":\"ITP\"},\"summary\":\"Integration test issue 1\",\"issuetype\":{\"id\":\"10000\"}}}";
insertIssueRecord1.put(0, insertIssue1);
IndexedRecord insertIssueRecord2 = new GenericData.Record(INSERT_SCHEMA);
String insertIssue2 = "{\"fields\":{\"project\":{\"key\":\"ITP\"},\"summary\":\"Integration test issue 2\",\"issuetype\":{\"id\":\"10000\"}}}";
insertIssueRecord2.put(0, insertIssue2);
JiraWriter insertIssueWriter = JiraTestsHelper.createWriter(HOST_PORT, USER, PASS, Resource.ISSUE, Action.INSERT);
insertIssueWriter.open("insIss");
try {
insertIssueWriter.write(insertIssueRecord1);
insertIssueWriter.write(insertIssueRecord2);
insertIssueWriter.close();
} catch (DataRejectException e) {
String rejectError = e.getRejectInfo().get("error").toString();
LOG.error(rejectError);
collector.addError(new Throwable(rejectError));
}
}
Aggregations