@After
 public void dispose() throws SQLException, IOException, ClassNotFoundException {
   Connection connection = BddConnecteur.getConnection();
   Statement statement = connection.createStatement();
   statement.execute("DROP TABLE Creneau");
   statement.execute("DROP TABLE Atelier");
   statement.execute("DROP TABLE Labo");
   statement.execute("DROP TABLE Utilisateur");
   statement.close();
   connection.close();
   BddConnecteur.dispose();
 }
  @Test
  public void testAjoutCreneau() throws SQLException, IOException, ClassNotFoundException {
    Connection connection = BddConnecteur.getConnection();

    BddUtilisateur.ajout("*****@*****.**", "labri");
    BddLabo.ajout(1, "Labri");
    BddAtelier.ajoutAtelier(
        1,
        "A la poursuite d'ennemis invisibles",
        "Sciences de la vie ",
        "Campus Carreire (Hôpital Pellegrin)",
        "Labo MFP",
        "",
        "",
        "",
        "");

    // Insertion
    int idAtelier = 1;
    String jour = "2015-12-23";
    String heure = "13:00";
    int capacite = 20;
    BddCreneau.ajoutCreneau(1, jour, heure, capacite);

    // Vérification
    String sql = "SELECT * FROM Creneau WHERE idAtelier='" + idAtelier + "'";
    Statement statement = connection.createStatement();
    ResultSet rs = statement.executeQuery(sql);

    int count = 0;
    Date jourRecup;
    Time heureRecup;
    int capaciteRecup = 0;

    while (rs.next()) {
      jourRecup = rs.getDate("jour");
      heureRecup = rs.getTime("heure");
      capaciteRecup = rs.getInt("capacite");
      count++;
    }

    assertEquals(count, 1);
    // assertEquals(jourRecup, jour);
    // assertEquals(heureRecup, heure);
    assertEquals(capaciteRecup, capacite);

    // Fermeture
    rs.close();
    statement.close();
    connection.close();
  }
  @Test
  public void testSupprCreneauxByIdAtelier()
      throws SQLException, IOException, ClassNotFoundException {
    Connection connection = BddConnecteur.getConnection();

    BddUtilisateur.ajout("*****@*****.**", "labri");
    BddLabo.ajout(1, "Labri");
    BddAtelier.ajoutAtelier(
        1,
        "A la poursuite d'ennemis invisibles",
        "Sciences de la vie ",
        "Campus Carreire (Hôpital Pellegrin)",
        "Labo MFP",
        "",
        "",
        "",
        "");

    // Insertion
    int idAtelier = 1;
    String jour = "2015-12-23";
    String heure = "13:00";
    int oldCapacite = 20;
    int newCapacite = 40;
    BddCreneau.ajoutCreneau(1, jour, heure, oldCapacite);

    // Suppression
    BddCreneau.supprCreneauxByIdAtelier(1);

    // Vérification
    String sql = "SELECT * FROM Creneau WHERE idAtelier='" + idAtelier + "'";
    Statement statement = connection.createStatement();
    ResultSet rs = statement.executeQuery(sql);

    int count = 0;

    while (rs.next()) {
      count++;
    }

    assertEquals(count, 0);

    // Fermeture
    rs.close();
    statement.close();
    connection.close();
  }
  @Test
  public void createEncrypted() throws SQLException, IOException {
    File tmp = File.createTempFile("sqlitetest", ".db");
    tmp.deleteOnExit();
    String url = "jdbc:sqlite:" + tmp.getAbsolutePath();

    Properties props = new Properties();
    final String password = "******"dog";
    props.put("key", password);
    Connection conn = DriverManager.getConnection(url, props);
    conn.setAutoCommit(false);

    Statement st = conn.createStatement();
    st.executeUpdate("create table ants (col int)");
    st.executeUpdate("insert into ants values( 300 )");
    st.executeUpdate("insert into ants values( 400 )");
    st.close();
    conn.commit();
    conn.close();

    // Try reading without key.
    props.remove("key");
    conn = DriverManager.getConnection(url, props);

    try {
      st = conn.createStatement();
      ResultSet rs = st.executeQuery("select count(*) from ants");
      fail("Database not encrypted.");
    } catch (SQLException ignore) {
    }

    conn.close();
    props.put("key", password);
    conn = DriverManager.getConnection(url, props);

    st = conn.createStatement();
    ResultSet rs = st.executeQuery("select count(*) from ants");
    assertTrue(rs.next());
    assertEquals(2, rs.getInt(1));
    conn.close();
  }
Exemple #5
0
 @After
 public void close() throws SQLException {
   stat.close();
   conn.close();
 }