@Override public HistoryDto saveHistory(HistoryDto historyDto) { HistoryDto savedDto = null; if (isValidSqlObject(historyDto)) { LOG.debug("History dto object is valid. Saving history..."); String applicationId = historyDto.getApplicationId(); if (isValidSqlId(applicationId)) { Application application = applicationDao.getNextSeqNumber(applicationId); if (application != null) { int sequenceNumber = application.getSequenceNumber(); historyDto.setSequenceNumber(sequenceNumber); historyDto.setLastModifyTime(System.currentTimeMillis()); History savedHistory = historyDao.persist(new History(historyDto)); savedDto = savedHistory != null ? savedHistory.toDto() : null; } else { LOG.debug("Can't get sequence number for application id [{}] .", applicationId); } } else { LOG.debug("Incorrect application id, can't save history."); } } else { LOG.info("Invalid HistoryDto object. Can't save object."); } return savedDto; }
@Test public void testGetNextSeqNumberWithIncorrectAppId() { Application app = applicationDao.getNextSeqNumber("777"); Assert.assertNull(app); }
@Test public void testGetNextSeqNumber() { Tenant ten = generateTenant(); Application app = generateApplication(ten); int sequenceNumber = app.getSequenceNumber(); app = applicationDao.getNextSeqNumber(app.getId().toString()); Assert.assertNotEquals(sequenceNumber, app.getSequenceNumber()); }