Ejemplo n.º 1
0
  @Test
  public void testUpdate() {
    Collection<Cours> cours = null;
    boolean isupdated = false;
    try {
      conn.beginTransaction();

      cours = daoCours.findAll();
      for (Cours c : cours) {
        if (c.getEnseignant().getId() == 2) {
          c.setNom("AnotherCour");
          daoCours.update(c);
          isupdated = true;
          break;
        }
      }

      conn.commitTransaction();
    } catch (DaoException e) {
      try {
        conn.rollbackTransaction();
      } catch (DaoException ex) {
        ex.printStackTrace();
      }
    }
    assertTrue(isupdated);
  }
Ejemplo n.º 2
0
  @Test
  public void testDelete() {
    Collection<Cours> cours = null;
    boolean isdeleted = false;
    try {
      conn.beginTransaction();

      cours = daoCours.findAll();
      for (Cours c : cours) {
        if (c.getNom().compareTo("AnotherCour") == 0) {
          daoCours.delete(c);
          isdeleted = true;
          break;
        }
      }

      conn.commitTransaction();
    } catch (DaoException e) {
      try {
        conn.rollbackTransaction();
      } catch (DaoException ex) {
        ex.printStackTrace();
      }
    }
    assertTrue(isdeleted);
  }
Ejemplo n.º 3
0
  @Test
  public void testCreate() {
    Collection<Cours> cours = null;
    Enseignant en = null;
    try {
      conn.beginTransaction();

      en = daoEnseignant.findById(2);
      Cours cour = new Cours("NewCour", en);

      daoCours.create(cour);

      // find all cours. there should be three cours now
      cours = daoCours.findAll();

      conn.commitTransaction();
    } catch (DaoException e) {
      try {
        conn.rollbackTransaction();
      } catch (DaoException ex) {
        ex.printStackTrace();
      }
    }
    assertTrue(cours.size() == 3);
  }
Ejemplo n.º 4
0
  @Test
  public void testFindAll() {
    Collection<Cours> c = null;
    try {
      conn.beginTransaction();

      c = daoCours.findAll();

      conn.commitTransaction();
    } catch (DaoException e) {
      try {
        conn.rollbackTransaction();
      } catch (DaoException ex) {
        ex.printStackTrace();
      }
    }
    assertTrue(c.size() == 2);
  }