-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
99 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
|
||
public class ControllerTest { | ||
|
||
static SingletonBDD bdd = SingletonBDD.getInstance(); | ||
|
||
// Utilisez ces variables pour stocker les données de test | ||
private static final String testUserEmail = "[email protected]"; | ||
private static final String testUserPassword = "testPassword"; | ||
|
@@ -23,127 +25,140 @@ public class ControllerTest { | |
@BeforeAll | ||
public static void setUp() throws SQLException { | ||
// Ajoutez un utilisateur de test à la base de données | ||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = testUserEmail; | ||
String password = testUserPassword; | ||
if (bdd.conn != null) { | ||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = testUserEmail; | ||
String password = testUserPassword; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
assertEquals("User successfully created", result); | ||
assertEquals("User successfully created", result); | ||
|
||
// Récupérez l'ID de l'utilisateur de test | ||
String[] loginResult = Controller.logIn(email, password); | ||
testUserId = Integer.parseInt(loginResult[2]); | ||
// Récupérez l'ID de l'utilisateur de test | ||
String[] loginResult = Controller.logIn(email, password); | ||
testUserId = Integer.parseInt(loginResult[2]); | ||
} | ||
} | ||
|
||
// Cette méthode s'exécute une fois après la fin de tous les tests | ||
@AfterAll | ||
public static void tearDown() { | ||
Controller.deleteUser(testUserId); | ||
if (bdd.conn != null) { | ||
Controller.deleteUser(testUserId); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateNewUser() throws SQLException { | ||
if (bdd.conn != null) { | ||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
|
||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
assertEquals("User successfully created", result); | ||
assertEquals("User successfully created", result); | ||
|
||
String[] loginResult = Controller.logIn(email, password); | ||
int testId= Integer.parseInt(loginResult[2]); | ||
String[] loginResult = Controller.logIn(email, password); | ||
int testId = Integer.parseInt(loginResult[2]); | ||
|
||
Controller.deleteUser(testId); | ||
Controller.deleteUser(testId); | ||
} | ||
} | ||
|
||
@Test | ||
public void testLogIn() throws SQLException { | ||
// Assuming there is a test user in the database with known credentials | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
if (bdd.conn != null) { | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
|
||
String[] result = Controller.logIn(email, password); | ||
String[] result = Controller.logIn(email, password); | ||
|
||
assertEquals("Login successful", result[0]); | ||
assertEquals("Needer", result[1]); | ||
assertEquals(testUserId, Integer.parseInt(result[2])); | ||
assertEquals("Login successful", result[0]); | ||
assertEquals("Needer", result[1]); | ||
assertEquals(testUserId, Integer.parseInt(result[2])); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateExistingUser() throws SQLException{ | ||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
if (bdd.conn != null) { | ||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
assertEquals("User already exists", result); | ||
assertEquals("User already exists", result); | ||
} | ||
} | ||
|
||
@Test | ||
public void testCreateNewMission() { | ||
// Use the test user's ID | ||
int idUser = testUserId; | ||
|
||
// Data for the test mission | ||
String title = "Test Mission"; | ||
String description = "Test Description"; | ||
String date = "2023-01-01 18:00:00"; | ||
|
||
// Perform the mission creation | ||
String result = Controller.createNewMission(title, description, date, idUser); | ||
|
||
// Ensure the mission is created successfully | ||
assertEquals("Mission successfully created", result); | ||
|
||
// Retrieve the ID of the created mission (this assumes you have a method to get mission data) | ||
ArrayList<Mission> missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
int testMissionId = missions.get(0).getIdMission(); | ||
Controller.deleteMission(testMissionId); | ||
{ | ||
// Use the test user's ID | ||
int idUser = testUserId; | ||
|
||
// Data for the test mission | ||
String title = "Test Mission"; | ||
String description = "Test Description"; | ||
String date = "2023-01-01 18:00:00"; | ||
|
||
// Perform the mission creation | ||
String result = Controller.createNewMission(title, description, date, idUser); | ||
|
||
// Ensure the mission is created successfully | ||
assertEquals("Mission successfully created", result); | ||
|
||
// Retrieve the ID of the created mission (this assumes you have a method to get mission data) | ||
ArrayList<Mission> missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
int testMissionId = missions.get(0).getIdMission(); | ||
Controller.deleteMission(testMissionId); | ||
} | ||
} | ||
|
||
@Test | ||
public void testAcceptOrRefuseMission(){ | ||
int idUser = testUserId; | ||
|
||
// Data for the test mission | ||
String title = "Test Mission"; | ||
String description = "Test Description"; | ||
String date = "2023-01-01 18:00:00"; | ||
|
||
// Perform the mission creation | ||
String result = Controller.createNewMission(title, description, date, idUser); | ||
|
||
// Ensure the mission is created successfully | ||
assertEquals("Mission successfully created", result); | ||
|
||
// Retrieve the ID of the created mission (this assumes you have a method to get mission data) | ||
ArrayList<Mission> missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
int testMissionId = missions.get(0).getIdMission(); | ||
|
||
//accept | ||
Controller.acceptMission(testMissionId); | ||
missions.clear(); | ||
missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
assertEquals(Status.Accepted, missions.get(0).getStatus()); | ||
|
||
//refuse | ||
Controller.refuseMission(testMissionId); | ||
missions.clear(); | ||
missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
assertEquals(Status.Refused, missions.get(0).getStatus()); | ||
|
||
Controller.deleteMission(testMissionId); | ||
if (bdd.conn != null) { | ||
int idUser = testUserId; | ||
|
||
// Data for the test mission | ||
String title = "Test Mission"; | ||
String description = "Test Description"; | ||
String date = "2023-01-01 18:00:00"; | ||
|
||
// Perform the mission creation | ||
String result = Controller.createNewMission(title, description, date, idUser); | ||
|
||
// Ensure the mission is created successfully | ||
assertEquals("Mission successfully created", result); | ||
|
||
// Retrieve the ID of the created mission (this assumes you have a method to get mission data) | ||
ArrayList<Mission> missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
int testMissionId = missions.get(0).getIdMission(); | ||
|
||
//accept | ||
Controller.acceptMission(testMissionId); | ||
missions.clear(); | ||
missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
assertEquals(Status.Accepted, missions.get(0).getStatus()); | ||
|
||
//refuse | ||
Controller.refuseMission(testMissionId); | ||
missions.clear(); | ||
missions = Controller.getMissionsOfNeeder(idUser); | ||
assertFalse(missions.isEmpty()); | ||
assertEquals(Status.Refused, missions.get(0).getStatus()); | ||
|
||
Controller.deleteMission(testMissionId); | ||
} | ||
} | ||
|
||
|
||
|