예제 #1
0
  @Test
  public void testUpdate() {

    try {

      NotaB notaBU = new NotaB();
      notaBU.setDescrizione("asd2");

      boolean test = notaBDAO.update(conn, notaBU, notaB1);
      db.rollbackConnection(conn);

      assertTrue(test);

    } catch (DAOException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 2

    try {

      notaBDAO.update(conn, new Allegato(), notaB1);
      fail();
    } catch (DAOException e) {

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 3

    try {

      notaBDAO.update(conn, null, notaB1);
      fail();

    } catch (DAOException e) {
      // return;
      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
  @Test
  public void testTransformStmt() {
    // PROVA UPDATE
    try {
      Allegato9 newAllegato9 = new Allegato9();
      newAllegato9.setAltro("campoi");

      String SET = sga9.transformStmt(newAllegato9, 1);
      String WHERE = sga9.transformStmt(allegato9, 2);

      String query = ALLEGATO9_UPDATE;

      query = query.replaceFirst(CHAR_AT, SET);
      query = query.replaceFirst(CHAR_AT, WHERE);

      Statement stmt = conn.createStatement();
      int count = stmt.executeUpdate(query);

      // PROVA FIND
      WHERE = sga9.transformStmt(newAllegato9, 2);

      query = ALLEGATO9_FIND_MAIN;
      query = query.replaceFirst(CHAR_AT, WHERE);

      ResultSet rs = stmt.executeQuery(query);
      rs.next();

      boolean test = rs.getString(17).equals(newAllegato9.getAltro());

      db.rollbackConnection(conn);
      assertTrue(test);
    } catch (Exception e) {
      fail(e.getMessage());
    }
  }
  @Test
  public void testGetPreparedStatement() {
    try {
      // testo il getPrearedStatement facendo una query di creazione
      // MANCA TESTO QUERY IN ALLEGATO5_CREATE
      stmt = conn.prepareStatement(ALLEGATO5_CREATE);
      Allegato5Assembler.getPreparedStatement(allegato5, stmt);
      stmt.executeUpdate();
      db.rollbackConnection(conn);

      stmt.close();
      db.closeConnection(conn);

    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      fail(e.getMessage());
    }
  }
예제 #4
0
  @Test
  public void testRemove() {
    try {

      boolean res = notaBDAO.remove(conn, notaB1.getIdNotaB());

      db.rollbackConnection(conn);

      assertTrue(res);

    } catch (DBAccessException e) {
      fail(e.getMessage());
    } catch (DAOException e) {

      fail(e.getMessage());
    } finally {

      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }
예제 #5
0
  @Test
  public void testCreate() {
    try {
      notaB2.setData(cd.getTime());
      notaBDAO.create(conn, notaB2);
      String query = NOTA_B_FIND_BYPK;

      Statement stmt2 = conn.createStatement();
      ResultSet rs =
          stmt2.executeQuery(
              "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'db_qualita' AND TABLE_NAME = 'nota_b'");
      rs.next();
      int id = rs.getInt(1);

      PreparedStatement stmt = conn.prepareStatement(query);
      stmt.setInt(1, id - 1);
      rs = stmt.executeQuery();

      rs.next();
      int a = rs.getInt(1);
      db.rollbackConnection(conn);
      assertTrue(rs.getInt(1) == (id - 1));

    } catch (DAOException e) {
      fail(e.getMessage());
    } catch (SQLException e) {
      fail(e.getMessage());
    } catch (DBAccessException e) {
      e.printStackTrace();
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 2 test null
    try {

      notaBDAO.create(null, notaB2);
      fail();
    } catch (DAOException e) {
      // return;

      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }

    // TEST 3 test class exception
    try {

      notaBDAO.create(conn, new Allegato());
      fail();

    } catch (DAOException e) {
      assertTrue(e.getMessageKey().equals(INV_OBJ_NOTA_B));
    } finally {
      try {
        db.closeConnection(conn);
      } catch (DBAccessException e) {
        e.printStackTrace();
      }
    }
  }