Merge branch 'master' of https://git.etud.insa-toulouse.fr/el-ouali/PDLA_24
This commit is contained in:
commit
8212c64582
17 changed files with 97 additions and 132 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1 +1,3 @@
|
||||||
/target/
|
/target/
|
||||||
|
/.idea/
|
||||||
|
/.settings/
|
||||||
|
|
3
.idea/.gitignore
vendored
3
.idea/.gitignore
vendored
|
@ -1,3 +0,0 @@
|
||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
|
@ -1,13 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="CompilerConfiguration">
|
|
||||||
<annotationProcessing>
|
|
||||||
<profile name="Maven default annotation processors profile" enabled="true">
|
|
||||||
<sourceOutputDir name="target/generated-sources/annotations" />
|
|
||||||
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
|
||||||
<outputRelativeToContentRoot value="true" />
|
|
||||||
<module name="AidePersonnesApp" />
|
|
||||||
</profile>
|
|
||||||
</annotationProcessing>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,20 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RemoteRepositoriesConfiguration">
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Central Repository" />
|
|
||||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="central" />
|
|
||||||
<option name="name" value="Maven Central repository" />
|
|
||||||
<option name="url" value="https://repo1.maven.org/maven2" />
|
|
||||||
</remote-repository>
|
|
||||||
<remote-repository>
|
|
||||||
<option name="id" value="jboss.community" />
|
|
||||||
<option name="name" value="JBoss Community repository" />
|
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
|
||||||
</remote-repository>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,12 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
|
||||||
<component name="MavenProjectsManager">
|
|
||||||
<option name="originalFiles">
|
|
||||||
<list>
|
|
||||||
<option value="$PROJECT_DIR$/pom.xml" />
|
|
||||||
</list>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="openjdk-23" project-jdk-type="JavaSDK" />
|
|
||||||
</project>
|
|
|
@ -1,7 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="" vcs="Git" />
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
|
@ -1,2 +0,0 @@
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.apt.aptEnabled=false
|
|
|
@ -1,16 +0,0 @@
|
||||||
eclipse.preferences.version=1
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
|
||||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
|
||||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
|
|
||||||
org.eclipse.jdt.core.compiler.processAnnotations=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.release=disabled
|
|
||||||
org.eclipse.jdt.core.compiler.source=1.8
|
|
|
@ -1,4 +0,0 @@
|
||||||
activeProfiles=
|
|
||||||
eclipse.preferences.version=1
|
|
||||||
resolveWorkspaceProjects=true
|
|
||||||
version=1
|
|
|
@ -75,6 +75,14 @@ public class BenevoleDemandesFinaliseesPage extends JFrame {
|
||||||
loadDemandesFinalisees();
|
loadDemandesFinalisees();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Méthodes de type get()
|
||||||
|
public JTable getTable() {return this.table;}
|
||||||
|
public DefaultTableModel getTableModel() {return this.tableModel;}
|
||||||
|
public JButton getVoirAvisButton() {return this.voirAvisButton;}
|
||||||
|
public JButton getModifierAvisButton() {return this.modifierAvisButton;}
|
||||||
|
public JButton getRetourBenevoleButton() {return this.retourBenevoleButton;}
|
||||||
|
public int getID() {return this.utilisateurId;}
|
||||||
|
|
||||||
private void afficherAvis() {
|
private void afficherAvis() {
|
||||||
int selectedRow = table.getSelectedRow();
|
int selectedRow = table.getSelectedRow();
|
||||||
if (selectedRow == -1) {
|
if (selectedRow == -1) {
|
||||||
|
|
|
@ -52,7 +52,4 @@ class BenevoleDemandesEncoursPageTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,46 +4,96 @@ import database.DatabaseConnection;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
class BenevoleDemandesFinaliseesPageTest {
|
class BenevoleDemandesFinaliseesPageTest {
|
||||||
private BenevoleDemandesFinaliseesPage page;
|
private BenevoleDemandesFinaliseesPage benevoleDemandesFinaliseesPage;
|
||||||
private int utilisateurId = 1; // ID fictif de l'utilisateur
|
private JTable table;
|
||||||
private int demandeId = 1; // ID fictif de la demande
|
private DefaultTableModel tableModel;
|
||||||
|
private int user_besoinID = 1;
|
||||||
|
private int benevoleID = 2; // ID fictif de l'utilisateur
|
||||||
|
private int demandeID; // ID fictif de la demande
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws SQLException {
|
void setUp() throws SQLException {
|
||||||
// Préparer la base de données avec des données fictives pour les tests
|
// Initialiser la benevoleDemandesFinaliseesPage pour les tests
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
benevoleDemandesFinaliseesPage = new BenevoleDemandesFinaliseesPage(benevoleID);
|
||||||
// Insérer un utilisateur fictif
|
|
||||||
String insertUtilisateurSQL = "INSERT IGNORE INTO utilisateur (id) VALUES (?)";
|
|
||||||
try (PreparedStatement utilisateurStatement = connection.prepareStatement(insertUtilisateurSQL)) {
|
|
||||||
utilisateurStatement.setInt(1, utilisateurId);
|
|
||||||
utilisateurStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insérer une demande liée à cet utilisateur
|
|
||||||
String insertDemandeSQL = "INSERT IGNORE INTO demandes_aide (id, description, statut, benevole_id) VALUES (?, ?, ?, ?)";
|
|
||||||
try (PreparedStatement demandeStatement = connection.prepareStatement(insertDemandeSQL)) {
|
|
||||||
demandeStatement.setInt(1, demandeId);
|
|
||||||
demandeStatement.setString(2, "Test demande description");
|
|
||||||
demandeStatement.setString(3, "finalisée");
|
|
||||||
demandeStatement.setInt(4, utilisateurId);
|
|
||||||
demandeStatement.executeUpdate();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialiser la page pour les tests
|
|
||||||
page = new BenevoleDemandesFinaliseesPage(utilisateurId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testPageCreation() {
|
void testPageCreation() {
|
||||||
// Vérifie que l'instance de la page est créée correctement
|
// on vérifie que l'instance de la benevoleDemandesFinaliseesPage est créée correctement
|
||||||
assertNotNull(page);
|
assertNotNull(benevoleDemandesFinaliseesPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testModifierAvisForFinalizedRequest() {
|
||||||
|
//on crée une demande avec le statut 'finalisée' pour tester la méthode modifierAvis(), et avec un avis original
|
||||||
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
|
String insertSQL = "INSERT INTO demandes_aide (statut, utilisateur_id, benevole_id, description, avis_benevole) VALUES (?, ?, ?, ?, ?)";
|
||||||
|
PreparedStatement insertStatement = connection.prepareStatement(insertSQL, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
|
insertStatement.setString(1, "finalisée");
|
||||||
|
insertStatement.setInt(2, user_besoinID);
|
||||||
|
insertStatement.setInt(3, benevoleID); // Aucun bénévole affecté initialement
|
||||||
|
insertStatement.setString(4, "Demande de test pour JUnit / Test modif avis_benevole");
|
||||||
|
insertStatement.setString(5, "Avis_benevole à modifier");
|
||||||
|
insertStatement.executeUpdate();
|
||||||
|
|
||||||
|
// Récupération de l'ID généré pour pouvoir le supprimer après
|
||||||
|
ResultSet generatedKeys = insertStatement.getGeneratedKeys();
|
||||||
|
if (generatedKeys.next()) {
|
||||||
|
demandeID = generatedKeys.getInt(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// on met à jour la table avec la nouvelle demande rajoutée
|
||||||
|
// on utilise une méthode détournée pour accéder à la méthode private 'loadAnciennesDemandes()'
|
||||||
|
Method loadDemandesFinaliseesMethod = BenevoleDemandesFinaliseesPage.class.getDeclaredMethod("loadDemandesFinalisees");
|
||||||
|
loadDemandesFinaliseesMethod.setAccessible(true); // permet d'appeler la méthode même si elle est private
|
||||||
|
loadDemandesFinaliseesMethod.invoke(benevoleDemandesFinaliseesPage); // on l'appele
|
||||||
|
|
||||||
|
//test de modifierAvis(); on sélectionne la dernière ligne de la table car elle correspond à la demande test
|
||||||
|
int lastRow = benevoleDemandesFinaliseesPage.getTable().getRowCount()-1;
|
||||||
|
benevoleDemandesFinaliseesPage.getTable().setRowSelectionInterval(lastRow, lastRow);
|
||||||
|
|
||||||
|
// idem que pour loadAnciennesDemandes() comme modifierAvis() est aussi en private
|
||||||
|
Method modifierAvisMethod = BenevoleDemandesFinaliseesPage.class.getDeclaredMethod("modifierAvis");
|
||||||
|
modifierAvisMethod.setAccessible(true); // permet d'appeler la méthode même si elle est private
|
||||||
|
modifierAvisMethod.invoke(benevoleDemandesFinaliseesPage); // on l'appele
|
||||||
|
|
||||||
|
// on attend un moment pour que la base de données se mette à jour
|
||||||
|
Thread.sleep(1000);
|
||||||
|
|
||||||
|
String sql = "SELECT avis_benevole FROM demandes_aide WHERE id = ?";
|
||||||
|
PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
|
statement.setInt(1, demandeID);
|
||||||
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
|
String currentAvis = "";
|
||||||
|
if (resultSet.next()) {
|
||||||
|
currentAvis = resultSet.getString("avis_benevole");
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNotEquals("Avis_benevole à modifier", currentAvis, "L'avis n'a pas été modifié.");
|
||||||
|
|
||||||
|
// Suppression de la demande de test après le test de prendreDemande()
|
||||||
|
String deleteSQL = "DELETE FROM demandes_aide WHERE id = ?";
|
||||||
|
PreparedStatement deleteStatement = connection.prepareStatement(deleteSQL);
|
||||||
|
deleteStatement.setInt(1, demandeID);
|
||||||
|
deleteStatement.executeUpdate();
|
||||||
|
} catch (InterruptedException | InvocationTargetException | NoSuchMethodException | IllegalAccessException |
|
||||||
|
SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -25,9 +25,6 @@ class CreateAccountPageTest {
|
||||||
private JButton createAccountButton;
|
private JButton createAccountButton;
|
||||||
private JButton retourLoginButton;
|
private JButton retourLoginButton;
|
||||||
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
/*
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||||
createAccountPage = new CreateAccountPage();
|
createAccountPage = new CreateAccountPage();
|
||||||
|
@ -124,5 +121,5 @@ class CreateAccountPageTest {
|
||||||
// Check that the current frame is disposed
|
// Check that the current frame is disposed
|
||||||
assertFalse(createAccountPage.isVisible(), "La page de création de compte devrait être fermée après avoir cliqué sur 'Retour à la connexion'.");
|
assertFalse(createAccountPage.isVisible(), "La page de création de compte devrait être fermée après avoir cliqué sur 'Retour à la connexion'.");
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,11 +60,8 @@ class LoginPageTest {
|
||||||
|
|
||||||
// Verify that the email field contains the invalid email entered
|
// Verify that the email field contains the invalid email entered
|
||||||
assertEquals("nonexistent@example.com", emailField.getText(), "The entered email should remain in the email field.");
|
assertEquals("nonexistent@example.com", emailField.getText(), "The entered email should remain in the email field.");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCreateAccountButtonAction() {
|
void testCreateAccountButtonAction() {
|
||||||
createAccountButton.doClick();
|
createAccountButton.doClick();
|
||||||
|
|
|
@ -21,12 +21,12 @@ class SoumettreDemandeTest {
|
||||||
private SoumettreDemande soumettreDemande;
|
private SoumettreDemande soumettreDemande;
|
||||||
private JTextField descriptionField;
|
private JTextField descriptionField;
|
||||||
private DefaultTableModel tableModel;
|
private DefaultTableModel tableModel;
|
||||||
private int utilisateurId = 1; // utilisateur arbitraire qui va créer les demandes de test
|
private int utilisateurID = 1; // utilisateur arbitraire qui va créer les demandes de test
|
||||||
private int demandeID;
|
private int demandeID;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
void setUp() throws NoSuchFieldException, IllegalAccessException {
|
||||||
soumettreDemande = new SoumettreDemande(utilisateurId);
|
soumettreDemande = new SoumettreDemande(utilisateurID);
|
||||||
|
|
||||||
// Access private fields using reflection
|
// Access private fields using reflection
|
||||||
descriptionField = (JTextField) getField("descriptionField");
|
descriptionField = (JTextField) getField("descriptionField");
|
||||||
|
@ -52,7 +52,7 @@ class SoumettreDemandeTest {
|
||||||
String sql = "SELECT description FROM demandes_aide WHERE description = ? AND utilisateur_id = ?";
|
String sql = "SELECT description FROM demandes_aide WHERE description = ? AND utilisateur_id = ?";
|
||||||
PreparedStatement statement = connection.prepareStatement(sql);
|
PreparedStatement statement = connection.prepareStatement(sql);
|
||||||
statement.setString(1, "Test request description");
|
statement.setString(1, "Test request description");
|
||||||
statement.setInt(2, utilisateurId);
|
statement.setInt(2, utilisateurID);
|
||||||
ResultSet resultSet = statement.executeQuery();
|
ResultSet resultSet = statement.executeQuery();
|
||||||
|
|
||||||
assertTrue(resultSet.next(), "The request should be added to the database.");
|
assertTrue(resultSet.next(), "The request should be added to the database.");
|
||||||
|
@ -77,16 +77,14 @@ class SoumettreDemandeTest {
|
||||||
assertEquals(0, tableModel.getRowCount(), "No request should be submitted if the description is empty.");
|
assertEquals(0, tableModel.getRowCount(), "No request should be submitted if the description is empty.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
//TODO
|
void testModifierAvisForFinalizedRequest() {
|
||||||
/* @Test
|
|
||||||
void testModifierAvisForFinalizedRequest() throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
|
||||||
//on crée une demande avec le statut 'finalisée' pour tester la méthode modifierAvis(), et avec un avis original
|
//on crée une demande avec le statut 'finalisée' pour tester la méthode modifierAvis(), et avec un avis original
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
String insertSQL = "INSERT INTO demandes_aide (statut, utilisateur_id, benevole_id, description, avis_besoin) VALUES (?, ?, ?, ?, ?)";
|
String insertSQL = "INSERT INTO demandes_aide (statut, utilisateur_id, benevole_id, description, avis_besoin) VALUES (?, ?, ?, ?, ?)";
|
||||||
PreparedStatement insertStatement = connection.prepareStatement(insertSQL, PreparedStatement.RETURN_GENERATED_KEYS);
|
PreparedStatement insertStatement = connection.prepareStatement(insertSQL, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||||
insertStatement.setString(1, "finalisée");
|
insertStatement.setString(1, "finalisée");
|
||||||
insertStatement.setInt(2, utilisateurId);
|
insertStatement.setInt(2, utilisateurID);
|
||||||
insertStatement.setNull(3, java.sql.Types.INTEGER); // Aucun bénévole affecté initialement
|
insertStatement.setNull(3, java.sql.Types.INTEGER); // Aucun bénévole affecté initialement
|
||||||
insertStatement.setString(4, "Demande de test pour JUnit / Test modif avis_besoin");
|
insertStatement.setString(4, "Demande de test pour JUnit / Test modif avis_besoin");
|
||||||
insertStatement.setString(5, "Avis_besoin à modifier");
|
insertStatement.setString(5, "Avis_besoin à modifier");
|
||||||
|
@ -137,6 +135,6 @@ class SoumettreDemandeTest {
|
||||||
SQLException e) {
|
SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,6 @@ import database.DatabaseConnection;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.swing.*;
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -86,9 +83,7 @@ class ValidateurTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
//TODO
|
|
||||||
/* @Test
|
|
||||||
void testRejeterDemande() {
|
void testRejeterDemande() {
|
||||||
//on crée une demande avec le statut 'soumise' pour tester la méthode rejeterDemande()
|
//on crée une demande avec le statut 'soumise' pour tester la méthode rejeterDemande()
|
||||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||||
|
@ -146,8 +141,5 @@ class ValidateurTest {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package database;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.lang.reflect.Executable;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
Loading…
Reference in a new issue