@Test public void shouldThrowIncorrectDataLengthError() throws Exception { handler = new AbstractModelPersistenceHandler() { @Override protected BaseModel getExisting(BaseModel record) { return null; } @Override protected void save(BaseModel record) { throw new DataIntegrityViolationException("some error"); } }; handler.messageService = messageService; when(messageService.message("error.incorrect.length")).thenReturn("invalid data length"); when(messageService.message("upload.record.error", "invalid data length", "1")).thenReturn("final error message"); expectedEx.expect(DataException.class); expectedEx.expectMessage("final error message"); handler.execute(new TestImportable(), 2, new AuditFields(null)); }
@Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } } }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  @Override void execute(Importable importable, int rowNumber, AuditFields auditFields); @Override void postProcess(AuditFields auditFields); }
AbstractModelPersistenceHandler implements RecordHandler<Importable> { @Override public void execute(Importable importable, int rowNumber, AuditFields auditFields) { BaseModel currentRecord = (BaseModel) importable; BaseModel existing = getExisting(currentRecord); try { throwExceptionIfProcessedInCurrentUpload(auditFields, existing); currentRecord.setModifiedBy(auditFields.getUser()); currentRecord.setModifiedDate(auditFields.getCurrentTimestamp()); if (existing != null) { currentRecord.setId(existing.getId()); } else { currentRecord.setCreatedBy(auditFields.getUser()); } save(currentRecord); } catch (DataIntegrityViolationException dataIntegrityViolationException) { throwException("upload.record.error", "error.incorrect.length", rowNumber); } catch (DataException exception) { throwException("upload.record.error", exception.getOpenLmisMessage().getCode(), rowNumber); } }  @Override void execute(Importable importable, int rowNumber, AuditFields auditFields); @Override void postProcess(AuditFields auditFields);  }