@Test public void getCreneauxByIdAtelier() throws SQLException, IOException, ClassNotFoundException { 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", "", "", "", ""); Map<Integer, Creneau> creneaux = new HashMap<Integer, Creneau>(); // Test : récupération d'un objet null creneaux = BddCreneau.getCreneauxByIdAtelier(1); assertEquals(creneaux.size(), 0); // Insertion int idAtelier = 1; String jour = "2015-12-23"; String heure = "21:00"; int capacite = 20; BddCreneau.ajoutCreneau(idAtelier, jour, heure, capacite); // Test : récupération de creneaux creneaux = BddCreneau.getCreneauxByIdAtelier(idAtelier); assertEquals(creneaux.size(), 1); }
@Test public void testEditCreneau() 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); // Edition BddCreneau.editCreneau(1, jour, heure, newCapacite); // Vérification String sql = "SELECT * FROM Creneau WHERE idAtelier='" + idAtelier + "'"; Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(sql); int count = 0; int capaciteRecup = 0; while (rs.next()) { capaciteRecup = rs.getInt("capacite"); count++; } assertEquals(count, 1); assertEquals(capaciteRecup, newCapacite); // Fermeture rs.close(); statement.close(); connection.close(); }
@Test public void testGetAtelierByIdCreneau() throws SQLException, IOException, ClassNotFoundException { 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", "", "", "", ""); 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); BddCreneau.ajoutCreneau(1, jour, heure, capacite); BddCreneau.ajoutCreneau(2, jour, heure, capacite); Atelier atelier = BddCreneau.getAtelierByIdCreneau(1); assertEquals(atelier.getIdAtelier(), 1); atelier = BddCreneau.getAtelierByIdCreneau(3); assertEquals(atelier.getIdAtelier(), 2); }