AssignmentDaoImpl implements AssignmentDao { @Override @Transactional(readOnly = true) public Assignment getAssignment(String blockId, Date date) { Date from = getStartOfServiceDay(date); Date to = getEndOfServiceDay(date); Query query = getSession().createQuery("FROM Assignment assign WHERE assign.assignmentId.blockId=:blockId AND assign.assignmentId.assignmentDate between :from and :to"); query.setParameter("blockId", blockId); query.setParameter("from", from); query.setParameter("to", to); return (Assignment) query.uniqueResult(); }  @Autowired @Qualifier("assignmentSessionFactory") void setSessionFactory(SessionFactory sessionFactory); @Override @Transactional(readOnly = true) List<Assignment> getAll(Date date); @Override @Transactional(readOnly = true) Assignment getAssignment(String blockId, Date date); @Override @Transactional(rollbackFor = Throwable.class) void save(Assignment assignment); @Override @Transactional(rollbackFor = Throwable.class) void saveAll(List<Assignment> assignmentList); @Override @Transactional(rollbackFor = Throwable.class) void delete(Assignment assignment); @Override @Transactional(rollbackFor = Throwable.class) void deleteAll();  }
@Test public void getAssignmentTest() { Date currentServiceDate = currentServiceDate(); Date previousServiceDate = previousServiceDate(); Assignment assignment = new Assignment("blockId", "vehicleId", currentServiceDate); Assignment retrievedAssignment = _dao.getAssignment("blockId", currentServiceDate); assertNull(retrievedAssignment); _dao.save(assignment); retrievedAssignment = _dao.getAssignment("blockId", currentServiceDate); assertEquals("blockId", retrievedAssignment.getBlockId()); assertEquals("vehicleId", retrievedAssignment.getVehicleId()); retrievedAssignment = _dao.getAssignment("blockId", previousServiceDate); assertNull("blockId", retrievedAssignment); }