-
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
2 changed files
with
170 additions
and
0 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
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 |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package controller; | ||
|
||
import model.Mission; | ||
import model.Status; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.sql.SQLException; | ||
import java.util.ArrayList; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
public class ControllerTest { | ||
|
||
// Utilisez ces variables pour stocker les données de test | ||
private static final String testUserEmail = "[email protected]"; | ||
private static final String testUserPassword = "testPassword"; | ||
private static int testUserId; | ||
|
||
// Cette méthode s'exécute une fois avant le début des tests | ||
@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; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
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]); | ||
} | ||
|
||
// Cette méthode s'exécute une fois après la fin de tous les tests | ||
@AfterAll | ||
public static void tearDown() { | ||
Controller.deleteUser(testUserId); | ||
} | ||
|
||
@Test | ||
public void testCreateNewUser() throws SQLException { | ||
|
||
String firstName = "Test"; | ||
String lastName = "User"; | ||
String email = "[email protected]"; | ||
String password = "testPassword"; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
assertEquals("User successfully created", result); | ||
|
||
String[] loginResult = Controller.logIn(email, password); | ||
int testId= Integer.parseInt(loginResult[2]); | ||
|
||
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"; | ||
|
||
String[] result = Controller.logIn(email, password); | ||
|
||
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"; | ||
|
||
String result = Controller.createNewUser(firstName, lastName, email, password, true, false, false); | ||
|
||
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); | ||
} | ||
|
||
@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); | ||
} | ||
|
||
|
||
} |