Exemplo n.º 1
0
  @Test
  public void testFindTroopByNameWithWrongParameters() {

    try {
      Troop t1 = troopDao.findTroopByName("Rats"); // this name is not used
      Troop t2 = troopDao.findTroopByName(null); // null parameter
      Assert.fail();
    } catch (IllegalArgumentException ex) {
      // OK
    }
  }
Exemplo n.º 2
0
  @Test
  public void testFindTroopByName() {
    Troop troopE = new Troop();
    troopE.setName("E");
    troopE.setMoney(BigDecimal.ZERO);
    troopE.setMission("mise E");
    troopDao.createTroop(troopE);
    Troop t1 = troopDao.findTroopById(troopE.getId());

    Assert.assertEquals(t1.getName(), "E");
    Assert.assertEquals(t1.getMission(), "mise E");
  }
Exemplo n.º 3
0
  @Test
  public void testUpdateGoldForTroop() {
    EntityManager entityManager = emf.createEntityManager();
    entityManager.getTransaction().begin();
    Troop troopC = new Troop();
    troopC.setName("Testers");
    troopC.setMoney(new BigDecimal("30"));
    entityManager.persist(troopC);
    entityManager.getTransaction().commit();
    entityManager.close();

    troopDao.updateGoldForTroop(troopC.getId(), new BigDecimal("5"));

    Troop t1 = troopDao.findTroopById(troopC.getId());
    Assert.assertEquals(t1.getMoney().compareTo(new BigDecimal("5")), 0);
  }
Exemplo n.º 4
0
  @Test
  public void testDeleteTroop() {
    EntityManager entityManager = emf.createEntityManager();
    entityManager.getTransaction().begin();
    Troop troopC = new Troop();
    troopC.setName("Testers");
    troopC.setMoney(new BigDecimal("30"));
    troopC.setMission("mise C");
    entityManager.persist(troopC);
    entityManager.getTransaction().commit();
    entityManager.close();

    Troop t1 = troopDao.findTroopById(troopC.getId());
    troopDao.deleteTroop(t1);

    Troop t2 = troopDao.findTroopById(troopC.getId());
    Assert.assertEquals(t2, null);
  }
Exemplo n.º 5
0
  @Test
  public void testFindAllTroops() {
    List<Troop> list = troopDao.findAllTroops();

    for (Iterator<Troop> i = list.iterator(); i.hasNext(); ) {
      Troop t = i.next();
      troopDao.deleteTroop(t);
    }

    troopDao.createTroop(troopA);
    troopDao.createTroop(troopB);

    list = troopDao.findAllTroops();

    Assert.assertEquals(list.size(), 2);

    Assert.assertTrue(list.contains(troopA));
    Assert.assertTrue(list.contains(troopB));
  }
Exemplo n.º 6
0
  @Test
  public void testDeleteTroopWithWrongParameters() {

    Troop troopC = new Troop();
    Troop troopD = null;

    try {
      troopDao.deleteTroop(troopC); // detached entity
      troopDao.deleteTroop(troopD); // null argument
      Assert.fail();
    } catch (IllegalArgumentException ex) {
      // OK
    }
  }
Exemplo n.º 7
0
  // Tests for wrong parameters
  @Test
  public void testCreateTroopWithWrongParameters() {

    Troop troopC = new Troop();
    Troop troopD = null;

    try {
      troopDao.createTroop(troopC); // no name assigned
      troopDao.createTroop(troopD); // null argument
      Assert.fail();
    } catch (IllegalArgumentException ex) {
      // OK
    }
  }