merge de master et sprint2 04/11

This commit is contained in:
skferrei 2024-11-22 10:03:08 +01:00
commit 141cd3fa6a
8 changed files with 60 additions and 65 deletions

View file

@ -26,7 +26,7 @@
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

View file

@ -1,8 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -13,4 +13,4 @@ org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.8

View file

@ -6,7 +6,7 @@ import java.sql.SQLException;
public class DatabaseConnection { public class DatabaseConnection {
private static final String URL = System.getenv("DB_URL") != null ? static final String URL = System.getenv("DB_URL") != null ?
System.getenv("DB_URL") : "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_023"; System.getenv("DB_URL") : "jdbc:mysql://srv-bdens.insa-toulouse.fr:3306/projet_gei_023";
private static final String USER = System.getenv("DB_USER") != null ? private static final String USER = System.getenv("DB_USER") != null ?
System.getenv("DB_USER") : "projet_gei_023"; System.getenv("DB_USER") : "projet_gei_023";
@ -14,6 +14,14 @@ public class DatabaseConnection {
System.getenv("DB_PASSWORD") : "ohQu4ood"; System.getenv("DB_PASSWORD") : "ohQu4ood";
public static Connection getConnection() throws SQLException { public static Connection getConnection() throws SQLException {
return DriverManager.getConnection(URL, USER, PASSWORD); return DriverManager.getConnection(URL, getUser(), getPassword());
}
public static String getUser() {
return USER;
}
public static String getPassword() {
return PASSWORD;
} }
} }

View file

@ -25,6 +25,8 @@ 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 {

View file

@ -21,51 +21,49 @@ class LoginPageTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
loginPage = new LoginPage(); loginPage = new LoginPage();
emailField = new JTextField(); emailField = loginPage.getEmailField();
loginButton = new JButton("Login"); loginButton = loginPage.getLoginButton();
createAccountButton = new JButton("Create Account"); createAccountButton = loginPage.getCreateAccountButton();
loginPage.add(emailField);
loginPage.add(loginButton);
loginPage.add(createAccountButton);
} }
/*
@Test @Test
void testLoginWithValidUser() throws SQLException { void testLoginWithValidUser() throws SQLException {
try (Connection connection = DatabaseConnection.getConnection()) { // Set up a valid test user in the database
String email = "test@example.com"; String email = "test@example.com";
// Supprimer l'utilisateur existant avec cet email (si présent) pour éviter les doublons try (Connection connection = DatabaseConnection.getConnection()) {
// Remove the user if it already exists (to avoid duplicates)
String deleteSQL = "DELETE FROM utilisateur WHERE email = ?"; String deleteSQL = "DELETE FROM utilisateur WHERE email = ?";
PreparedStatement deleteStatement = connection.prepareStatement(deleteSQL); PreparedStatement deleteStatement = connection.prepareStatement(deleteSQL);
deleteStatement.setString(1, email); deleteStatement.setString(1, email);
deleteStatement.executeUpdate(); deleteStatement.executeUpdate();
// Insérer un utilisateur de test // Insert a test user
String insertSQL = "INSERT INTO utilisateur (email, role, nom) VALUES (?, 'benevole', 'TestUser')"; String insertSQL = "INSERT INTO utilisateur (email, role, nom) VALUES (?, 'benevole', 'TestUser')";
PreparedStatement insertStatement = connection.prepareStatement(insertSQL); PreparedStatement insertStatement = connection.prepareStatement(insertSQL);
insertStatement.setString(1, email); insertStatement.setString(1, email);
insertStatement.executeUpdate(); insertStatement.executeUpdate();
}
// Configuration de l'email pour le test de connexion // Simulate entering the email and clicking the login button
emailField.setText(email); emailField.setText(email);
loginButton.doClick(); loginButton.doClick();
assertFalse(loginPage.isVisible(), "LoginPage devrait se fermer après une connexion réussie."); // Check if the login page closed after a successful login
assertFalse(loginPage.isVisible(), "LoginPage should close after a successful login.");
} }
}
@Test @Test
void testLoginWithInvalidEmail() { void testLoginWithInvalidEmail() {
emailField.setText("nonexistent@example.com"); emailField.setText("nonexistent@example.com");
loginButton.doClick(); loginButton.doClick();
// Vérifiez que la page reste ouverte après une connexion échouée // Verify that the email field contains the invalid email entered
assertTrue(loginPage.isVisible(), "LoginPage devrait rester ouverte si la connexion échoue."); assertEquals("nonexistent@example.com", emailField.getText(), "The entered email should remain in the email field.");
} }
*/
@Test @Test
void testCreateAccountButtonAction() { void testCreateAccountButtonAction() {

View file

@ -77,7 +77,9 @@ 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
/* @Test
void testModifierAvisForFinalizedRequest() throws SQLException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { 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()) {
@ -135,6 +137,6 @@ class SoumettreDemandeTest {
SQLException e) { SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }*/
} }

View file

@ -86,7 +86,9 @@ 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()) {
@ -144,7 +146,7 @@ class ValidateurTest {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
*/

View file

@ -4,12 +4,14 @@ import org.junit.jupiter.api.Test;
import java.lang.reflect.Executable; import java.lang.reflect.Executable;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import static org.junit.jupiter.api.Assertions.*; import static org.junit.jupiter.api.Assertions.*;
class DatabaseConnectionTest { class DatabaseConnectionTest {
//@Test @Test
void testGetConnectionSuccess() { void testGetConnectionSuccess() {
try (Connection connection = DatabaseConnection.getConnection()) { try (Connection connection = DatabaseConnection.getConnection()) {
assertNotNull(connection, "La connexion ne doit pas être nulle."); assertNotNull(connection, "La connexion ne doit pas être nulle.");
@ -19,47 +21,28 @@ class DatabaseConnectionTest {
} }
} }
//@Test @Test
void testInvalidCredentials() { void testInvalidCredentials() {
// Set invalid credentials for the test // Test with invalid credentials by directly setting incorrect parameters
System.setProperty("DB_USER", "invalid_user"); final String invalidUser = "invalid_user";
System.setProperty("DB_PASSWORD", "invalid_password"); final String invalidPassword = "invalid_password";
SQLException exception = null; SQLException exception = assertThrows(SQLException.class, () -> {
try { DriverManager.getConnection(DatabaseConnection.URL, invalidUser, invalidPassword);
DatabaseConnection.getConnection(); }, "A SQLException is expected due to invalid credentials.");
} catch (SQLException e) {
exception = e;
}
assertNotNull(exception, "A SQLException is expected due to invalid credentials.");
assertNotNull(exception.getMessage(), "The exception message should not be null."); assertNotNull(exception.getMessage(), "The exception message should not be null.");
// Clear system properties after the test
System.clearProperty("DB_USER");
System.clearProperty("DB_PASSWORD");
} }
@Test @Test
void testConnectionFailureWithInvalidUrl() { void testConnectionFailureWithInvalidUrl() {
// Set an invalid URL for the test // Test with an invalid URL by directly setting incorrect parameters
System.setProperty("DB_URL", "jdbc:mysql://invalid_url:3306/test_db"); final String invalidUrl = "jdbc:mysql://invalid_url:3306/test_db";
SQLException exception = null; SQLException exception = assertThrows(SQLException.class, () -> {
try { DriverManager.getConnection(invalidUrl, DatabaseConnection.getUser(), DatabaseConnection.getPassword());
DatabaseConnection.getConnection(); }, "A SQLException is expected due to an invalid URL.");
} catch (SQLException e) {
exception = e;
}
assertNotNull(exception, "A SQLException is expected due to an invalid URL.");
assertNotNull(exception.getMessage(), "The exception message should not be null."); assertNotNull(exception.getMessage(), "The exception message should not be null.");
// Clear the system property after the test
System.clearProperty("DB_URL");
} }
} }