AsyncMsgRecordDao { public void checkExpiration() { LOG.debug("AsyncMsgRecordDao.checkExpiration() - Begin"); long value; String units; value = getValueFromPropFile(); units = getUnitsFromPropFile(); Date expirationValue = calculateExpirationValue(value, units); List<AsyncMsgRecord> asyncMsgRecs = queryForExpired(expirationValue); for (AsyncMsgRecord rec : asyncMsgRecs) { rec.setDuration(Long.valueOf(0)); rec.setStatus(QUEUE_STATUS_EXPIRED); save(rec); } LOG.debug("AsyncMsgRecordDao.checkExpiration() - End"); } AsyncMsgRecordDao();  AsyncMsgRecordDao(PropertyAccessor accessor); List<AsyncMsgRecord> queryByMessageIdAndDirection(String messageId, String direction); List<AsyncMsgRecord> queryByMessageIdAndServiceName(String messageId, String serviceName); List<AsyncMsgRecord> queryByTime(Date timestamp); List<AsyncMsgRecord> queryForExpired(Date timestamp); List<AsyncMsgRecord> queryForDeferredQueueProcessing(); List<AsyncMsgRecord> queryForDeferredQueueSelected(); List<AsyncMsgRecord> queryByCriteria(QueryDeferredQueueRequestType queryCriteria); boolean insertRecords(List<AsyncMsgRecord> asyncMsgRecs); void save(AsyncMsgRecord asyncMsgRecord); void save(List<AsyncMsgRecord> asyncMsgRecs); void delete(AsyncMsgRecord asyncMsgRecord); void checkExpiration(); static final String QUEUE_DIRECTION_INBOUND; static final String QUEUE_DIRECTION_OUTBOUND; static final String QUEUE_RESPONSE_TYPE_AUTO; static final String QUEUE_RESPONSE_TYPE_EXTERNAL; static final String QUEUE_STATUS_EXPIRED; static final String QUEUE_STATUS_REQPROCESS; static final String QUEUE_STATUS_REQRCVD; static final String QUEUE_STATUS_REQRCVDACK; static final String QUEUE_STATUS_REQRCVDERR; static final String QUEUE_STATUS_REQSENT; static final String QUEUE_STATUS_REQSENTACK; static final String QUEUE_STATUS_REQSENTERR; static final String QUEUE_STATUS_RSPSELECT; static final String QUEUE_STATUS_RSPPROCESS; static final String QUEUE_STATUS_RSPRCVD; static final String QUEUE_STATUS_RSPRCVDACK; static final String QUEUE_STATUS_RSPRCVDERR; static final String QUEUE_STATUS_RSPSENT; static final String QUEUE_STATUS_RSPSENTACK; static final String QUEUE_STATUS_RSPSENTERR; }
@Test public void testCheckExpiration() throws PropertyAccessException { System.out.println("checkExpiration"); AsyncMsgRecord asyncMsgRecord1 = new AsyncMsgRecord(); asyncMsgRecord1.setCommunityId("1.1"); asyncMsgRecord1.setDuration(Long.valueOf(0)); asyncMsgRecord1.setStatus(AsyncMsgRecordDao.QUEUE_STATUS_EXPIRED); AsyncMsgRecord asyncMsgRecord2 = new AsyncMsgRecord(); asyncMsgRecord2.setCommunityId("2.2"); asyncMsgRecord2.setDuration(Long.valueOf(0)); asyncMsgRecord2.setStatus(AsyncMsgRecordDao.QUEUE_STATUS_EXPIRED); final List<AsyncMsgRecord> asyncMsgRecords = new ArrayList<>(); asyncMsgRecords.add(asyncMsgRecord1); asyncMsgRecords.add(asyncMsgRecord2); when(accessor.getProperty(Mockito.anyString(), Mockito.anyString())).thenReturn("days"); when(accessor.getPropertyLong(Mockito.anyString(), Mockito.anyString())).thenReturn((long) 30); asyncMsgRecordDao = new AsyncMsgRecordDao(accessor) { @Override protected Session getSession() { return session; } @Override public List<AsyncMsgRecord> queryForExpired(Date timestamp) { return asyncMsgRecords; } @Override public void save(List<AsyncMsgRecord> asyncMsgRecs) { } }; asyncMsgRecordDao.checkExpiration(); for (int i = 0; i < asyncMsgRecords.size(); i++) { verify(session).saveOrUpdate(asyncMsgRecords.get(i)); } }