@Test
  public void insert() throws Exception, ConstraintViolationException {

    Person p = new Person("etester", "Tester", "Ehrenfried", "1234567");

    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      personDAO.insert(p);
      dbContext.commit();

      assertNotEquals(0, p.getPersonId());

    } catch (Exception e) {

      e.printStackTrace();
      fail("Exception " + e.getMessage());

    } finally {

      if (p.getPersonId() != 0) {
        try (DbContext dbContext = contextProvider.getDbContext()) {

          PersonDAO personDAO = dbContext.getPersonDAO();

          personDAO.remove(p.getPersonId());

          dbContext.commit();
        }
      }
    }
  }
  @Test(expected = EntityNotFoundException.class)
  public void insertRemovCycle() throws Exception {

    Person p = new Person("etester", "Tester", "Ehrenfried", "12345678");

    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      personDAO.insert(p);
      dbContext.commit();

      assertNotEquals(0, p.getPersonId());
    }

    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      Person x = personDAO.getById(p.getPersonId());

      personDAO.remove(x);

      dbContext.commit();
    }

    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      Person x = personDAO.getById(p.getPersonId());
      assertEquals(x, new Person());
    }
  }
  @Test(expected = ParameterException.class)
  public void removeOnNull() throws Exception {
    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      personDAO.remove(null);
    }
  }
예제 #4
0
  @After
  public void teardown() throws Exception {

    try (DbContext context = contextProvider.getDbContext()) {

      CommunityDAO communityDAO = context.getCommunityDAO();

      for (Community c : toDelete) {
        communityDAO.remove(c.getCommunityId());
      }

      PersonDAO personDao = context.getPersonDAO();

      personDao.remove(plainPerson.getPersonId());
      personDao.remove(adminPerson.getPersonId());
      personDao.remove(inActivePerson.getPersonId());

      context.commit();
    }
  }
  @Test(expected = ParameterException.class)
  public void removeOnIdZero() throws Exception {
    try (DbContext dbContext = contextProvider.getDbContext()) {

      PersonDAO personDAO = dbContext.getPersonDAO();

      Person p = new Person();
      p.setPersonId(0);

      personDAO.remove(p);
    }
  }