merge de master et sprint2 04/11
This commit is contained in:
commit
141cd3fa6a
8 changed files with 60 additions and 65 deletions
|
@ -26,7 +26,7 @@
|
|||
<attribute name="optional" value="true"/>
|
||||
</attributes>
|
||||
</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>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
eclipse.preferences.version=1
|
||||
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.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.localVariable=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.processAnnotations=disabled
|
||||
org.eclipse.jdt.core.compiler.release=disabled
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
|
|
|
@ -6,7 +6,7 @@ import java.sql.SQLException;
|
|||
|
||||
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";
|
||||
private static final String USER = System.getenv("DB_USER") != null ?
|
||||
System.getenv("DB_USER") : "projet_gei_023";
|
||||
|
@ -14,6 +14,14 @@ public class DatabaseConnection {
|
|||
System.getenv("DB_PASSWORD") : "ohQu4ood";
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ class CreateAccountPageTest {
|
|||
private JComboBox<String> roleComboBox;
|
||||
private JButton createAccountButton;
|
||||
private JButton retourLoginButton;
|
||||
|
||||
//TODO
|
||||
|
||||
/*
|
||||
@BeforeEach
|
||||
|
|
|
@ -21,51 +21,49 @@ class LoginPageTest {
|
|||
@BeforeEach
|
||||
void setUp() {
|
||||
loginPage = new LoginPage();
|
||||
emailField = new JTextField();
|
||||
loginButton = new JButton("Login");
|
||||
createAccountButton = new JButton("Create Account");
|
||||
|
||||
loginPage.add(emailField);
|
||||
loginPage.add(loginButton);
|
||||
loginPage.add(createAccountButton);
|
||||
emailField = loginPage.getEmailField();
|
||||
loginButton = loginPage.getLoginButton();
|
||||
createAccountButton = loginPage.getCreateAccountButton();
|
||||
}
|
||||
|
||||
/*
|
||||
@Test
|
||||
void testLoginWithValidUser() throws SQLException {
|
||||
// Set up a valid test user in the database
|
||||
String email = "test@example.com";
|
||||
|
||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||
String email = "test@example.com";
|
||||
|
||||
// Supprimer l'utilisateur existant avec cet email (si présent) pour éviter les doublons
|
||||
// Remove the user if it already exists (to avoid duplicates)
|
||||
String deleteSQL = "DELETE FROM utilisateur WHERE email = ?";
|
||||
PreparedStatement deleteStatement = connection.prepareStatement(deleteSQL);
|
||||
deleteStatement.setString(1, email);
|
||||
deleteStatement.executeUpdate();
|
||||
|
||||
// Insérer un utilisateur de test
|
||||
// Insert a test user
|
||||
String insertSQL = "INSERT INTO utilisateur (email, role, nom) VALUES (?, 'benevole', 'TestUser')";
|
||||
PreparedStatement insertStatement = connection.prepareStatement(insertSQL);
|
||||
insertStatement.setString(1, email);
|
||||
insertStatement.executeUpdate();
|
||||
|
||||
// Configuration de l'email pour le test de connexion
|
||||
emailField.setText(email);
|
||||
loginButton.doClick();
|
||||
|
||||
assertFalse(loginPage.isVisible(), "LoginPage devrait se fermer après une connexion réussie.");
|
||||
}
|
||||
}
|
||||
|
||||
// Simulate entering the email and clicking the login button
|
||||
emailField.setText(email);
|
||||
loginButton.doClick();
|
||||
|
||||
// Check if the login page closed after a successful login
|
||||
assertFalse(loginPage.isVisible(), "LoginPage should close after a successful login.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLoginWithInvalidEmail() {
|
||||
emailField.setText("nonexistent@example.com");
|
||||
loginButton.doClick();
|
||||
|
||||
// Vérifiez que la page reste ouverte après une connexion échouée
|
||||
assertTrue(loginPage.isVisible(), "LoginPage devrait rester ouverte si la connexion échoue.");
|
||||
// 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.");
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
void testCreateAccountButtonAction() {
|
||||
|
|
|
@ -77,7 +77,9 @@ class SoumettreDemandeTest {
|
|||
assertEquals(0, tableModel.getRowCount(), "No request should be submitted if the description is empty.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
//TODO
|
||||
/* @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
|
||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||
|
@ -135,6 +137,6 @@ class SoumettreDemandeTest {
|
|||
SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
|
@ -85,8 +85,10 @@ class ValidateurTest {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
|
||||
//TODO
|
||||
/* @Test
|
||||
void testRejeterDemande() {
|
||||
//on crée une demande avec le statut 'soumise' pour tester la méthode rejeterDemande()
|
||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||
|
@ -144,7 +146,7 @@ class ValidateurTest {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,12 +4,14 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import java.lang.reflect.Executable;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class DatabaseConnectionTest {
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
void testGetConnectionSuccess() {
|
||||
try (Connection connection = DatabaseConnection.getConnection()) {
|
||||
assertNotNull(connection, "La connexion ne doit pas être nulle.");
|
||||
|
@ -19,47 +21,28 @@ class DatabaseConnectionTest {
|
|||
}
|
||||
}
|
||||
|
||||
//@Test
|
||||
@Test
|
||||
void testInvalidCredentials() {
|
||||
// Set invalid credentials for the test
|
||||
System.setProperty("DB_USER", "invalid_user");
|
||||
System.setProperty("DB_PASSWORD", "invalid_password");
|
||||
// Test with invalid credentials by directly setting incorrect parameters
|
||||
final String invalidUser = "invalid_user";
|
||||
final String invalidPassword = "invalid_password";
|
||||
|
||||
SQLException exception = null;
|
||||
try {
|
||||
DatabaseConnection.getConnection();
|
||||
} catch (SQLException e) {
|
||||
exception = e;
|
||||
}
|
||||
SQLException exception = assertThrows(SQLException.class, () -> {
|
||||
DriverManager.getConnection(DatabaseConnection.URL, invalidUser, invalidPassword);
|
||||
}, "A SQLException is expected due to invalid credentials.");
|
||||
|
||||
assertNotNull(exception, "A SQLException is expected due to invalid credentials.");
|
||||
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
|
||||
void testConnectionFailureWithInvalidUrl() {
|
||||
// Set an invalid URL for the test
|
||||
System.setProperty("DB_URL", "jdbc:mysql://invalid_url:3306/test_db");
|
||||
// Test with an invalid URL by directly setting incorrect parameters
|
||||
final String invalidUrl = "jdbc:mysql://invalid_url:3306/test_db";
|
||||
|
||||
SQLException exception = null;
|
||||
try {
|
||||
DatabaseConnection.getConnection();
|
||||
} catch (SQLException e) {
|
||||
exception = e;
|
||||
}
|
||||
SQLException exception = assertThrows(SQLException.class, () -> {
|
||||
DriverManager.getConnection(invalidUrl, DatabaseConnection.getUser(), DatabaseConnection.getPassword());
|
||||
}, "A SQLException is expected due to an invalid URL.");
|
||||
|
||||
assertNotNull(exception, "A SQLException is expected due to an invalid URL.");
|
||||
assertNotNull(exception.getMessage(), "The exception message should not be null.");
|
||||
|
||||
// Clear the system property after the test
|
||||
System.clearProperty("DB_URL");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue