コード例 #1
0
  public static Event createEvent() {
    Event event = new Event();

    event.setDateCreated(new Date());
    event.setDescription(randomString("description", 2000));
    event.setCategory(randomString("category", 50));

    return event;
  }
コード例 #2
0
 @Override
 public void onCoordinateEvent(Event event, String message) {
   System.err.println("Got unit test even " + event.toString() + " " + message);
   events.add(event);
   latch1.countDown();
   latch2.countDown();
 }
コード例 #3
0
  @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();
      }
    }
  }
コード例 #4
0
  public static void modifyRecord(Event event) {

    event.setDateCreated(new Date());
    event.setDescription(randomString("description", 2000));
    event.setCategory(randomString("category", 50));
  }
コード例 #5
0
  public static void compareRecords(Event event, Event readRecord) {

    assertNotSame(event.getDateCreated(), readRecord.getDateCreated());
    assertEquals(event.getDescription(), readRecord.getDescription());
    assertEquals(event.getCategory(), readRecord.getCategory());
  }