public static Event createEvent() { Event event = new Event(); event.setDateCreated(new Date()); event.setDescription(randomString("description", 2000)); event.setCategory(randomString("category", 50)); return event; }
@Test public void test() throws Exception { SqlSession session = SessionFactory.getSession(); EventDao eventDao = session.getMapper(EventDao.class); try { Event event = TestEventDao.createEvent(); String where = "KEY='" + event.getKey() + "' "; Map<String, Object> map = new HashMap<String, Object>(); map.put("where", where); int count = eventDao.create(event); assertEquals(1, count); assertNotNull(event.getKey()); Event readRecord = eventDao.read(map); assertNotNull(readRecord.getKey()); compareRecords(event, readRecord); modifyRecord(event); count = eventDao.update(event); assertEquals(1, count); readRecord = eventDao.read(map); assertNotNull(readRecord.getKey()); compareRecords(event, readRecord); count = eventDao.delete(map); assertEquals(1, count); readRecord = eventDao.read(map); assertNull(readRecord); } finally { if (session != null) { session.rollback(); session.close(); } } }
public static void modifyRecord(Event event) { event.setDateCreated(new Date()); event.setDescription(randomString("description", 2000)); event.setCategory(randomString("category", 50)); }
public static void compareRecords(Event event, Event readRecord) { assertNotSame(event.getDateCreated(), readRecord.getDateCreated()); assertEquals(event.getDescription(), readRecord.getDescription()); assertEquals(event.getCategory(), readRecord.getCategory()); }