fix : tests
This commit is contained in:
parent
6029457735
commit
7df2c768c8
MyINPulse-back/src
main/java/enseirb/myinpulse/service
test/java/enseirb/myinpulse
@ -112,9 +112,17 @@ public class EntrepreneurApiService {
|
||||
mail,
|
||||
sectionCellId,
|
||||
this.sectionCellService.getProjectId(sectionCellId));
|
||||
SectionCell removedSectionCell = new SectionCell(null, -1L, "", LocalDateTime.now(), null);
|
||||
removedSectionCell.setIdReference(editSectionCell.getIdReference());
|
||||
SectionCell removedSectionCell =
|
||||
new SectionCell(
|
||||
null,
|
||||
-1L,
|
||||
"",
|
||||
LocalDateTime.now(),
|
||||
this.projectService.getProjectById(
|
||||
editSectionCell.getProjectSectionCell().getIdProject()));
|
||||
sectionCellService.addNewSectionCell(removedSectionCell);
|
||||
this.sectionCellService.updateSectionCellReferenceId(
|
||||
removedSectionCell.getIdSectionCell(), editSectionCell.getIdReference());
|
||||
projectService.updateProjectListSectionCell(
|
||||
sectionCellService.getProjectId(sectionCellId), removedSectionCell);
|
||||
// sectionCellService.removeSectionCellById(sectionCellId);
|
||||
@ -132,19 +140,19 @@ public class EntrepreneurApiService {
|
||||
HttpStatus.BAD_REQUEST, "La cellule de section fournie n'est pas valide");
|
||||
}
|
||||
if (!utilsService.isAllowedToCheckProject(
|
||||
mail, this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()))) {
|
||||
mail, sectionCell.getProjectSectionCell().getIdProject())) {
|
||||
logger.warn(
|
||||
"User {} tried to add a section cell to the project {} but is not allowed to.",
|
||||
mail,
|
||||
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
|
||||
sectionCell.getProjectSectionCell().getIdProject());
|
||||
throw new ResponseStatusException(
|
||||
HttpStatus.UNAUTHORIZED, "You're not allowed to check this project");
|
||||
}
|
||||
logger.info(
|
||||
"User {} added a new section cell {} to the project with id {}",
|
||||
"User {} added a new section cell {} to the project {}",
|
||||
mail,
|
||||
sectionCell.getIdSectionCell(),
|
||||
this.sectionCellService.getProjectId(sectionCell.getIdSectionCell()));
|
||||
sectionCell.getProjectSectionCell().getIdProject());
|
||||
SectionCell newSectionCell =
|
||||
sectionCellService.addNewSectionCell(
|
||||
sectionCell); // if here, logger fails cause id is null (not added yet)
|
||||
@ -173,11 +181,18 @@ public class EntrepreneurApiService {
|
||||
project.setEntrepreneurProposed((Entrepreneur) this.userService.getUserByEmail(mail));
|
||||
projectService.addNewProject(project);
|
||||
project.getProjectAdministrator().updateListProject(project);
|
||||
project.getEntrepreneurProposed().setProjectProposed(project);
|
||||
this.entrepreneurService.updateEntrepreneurProjectProposed(
|
||||
this.userService.getUserByEmail(mail).getIdUser(), project);
|
||||
project.getListEntrepreneurParticipation()
|
||||
.forEach(entrepreneur -> entrepreneur.setProjectParticipation(project));
|
||||
.forEach(
|
||||
entrepreneur ->
|
||||
this.entrepreneurService.updateEntrepreneurProjectParticipation(
|
||||
entrepreneur.getIdUser(), project));
|
||||
project.getListSectionCell()
|
||||
.forEach(sectionCell -> sectionCell.setProjectSectionCell(project));
|
||||
.forEach(
|
||||
sectionCell ->
|
||||
this.sectionCellService.updateSectionCellProject(
|
||||
sectionCell.getIdSectionCell(), project));
|
||||
}
|
||||
|
||||
public void createAccount(Entrepreneur e) {
|
||||
|
@ -146,8 +146,10 @@ public class EntrepreneurApiServiceTest {
|
||||
null, 2L, "contenu temporaire", LocalDateTime.now(), project));
|
||||
assertEquals(
|
||||
2, IterableToList(sectionCellService.getSectionCellsByProject(project, 2L)).size());
|
||||
entrepreneurApiService.removeSectionCell(
|
||||
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr");
|
||||
assertDoesNotThrow(
|
||||
() ->
|
||||
entrepreneurApiService.removeSectionCell(
|
||||
tmpCell.getIdSectionCell(), "entrepreneur@mail.fr"));
|
||||
assertEquals(
|
||||
tmpCell.getIdReference(),
|
||||
IterableToList(sectionCellService.getSectionCellsByProject(project, -1L))
|
||||
@ -181,14 +183,8 @@ public class EntrepreneurApiServiceTest {
|
||||
|
||||
@Test
|
||||
void addSectionCellInvalidAccess() {
|
||||
System.out.println(
|
||||
"content : "
|
||||
+ IterableToList(sectionCellService.getSectionCellsByProject(project, 2L))
|
||||
.getLast()
|
||||
.getContentSectionCell());
|
||||
SectionCell added =
|
||||
sectionCellService.addNewSectionCell(
|
||||
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project));
|
||||
new SectionCell(null, 2L, "contenu ajouté", LocalDateTime.now(), project);
|
||||
assertThrows(
|
||||
ResponseStatusException.class,
|
||||
() -> entrepreneurApiService.addSectionCell(added, "fauxentrepreneur@mail.fr"));
|
||||
@ -208,4 +204,7 @@ public class EntrepreneurApiServiceTest {
|
||||
ResponseStatusException.class,
|
||||
() -> entrepreneurApiService.addSectionCell(added, "entrepreneur@mail.fr"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void requestValidProject() {}
|
||||
}
|
||||
|
@ -3,28 +3,22 @@ package enseirb.myinpulse;
|
||||
import static enseirb.myinpulse.model.ProjectDecisionValue.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.endsWith;
|
||||
|
||||
import enseirb.myinpulse.model.Administrator;
|
||||
import enseirb.myinpulse.model.Appointment;
|
||||
import enseirb.myinpulse.model.Entrepreneur;
|
||||
import enseirb.myinpulse.model.Project;
|
||||
import enseirb.myinpulse.model.Appointment;
|
||||
|
||||
import enseirb.myinpulse.service.SharedApiService;
|
||||
import enseirb.myinpulse.service.database.AdministratorService;
|
||||
import enseirb.myinpulse.service.database.EntrepreneurService;
|
||||
import enseirb.myinpulse.service.database.ProjectService;
|
||||
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.checkerframework.checker.units.qual.kmPERh;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
@ -34,7 +28,7 @@ import java.util.List;
|
||||
@SpringBootTest
|
||||
@Transactional
|
||||
public class SharedApiServiceTest {
|
||||
|
||||
|
||||
@Autowired private SharedApiService sharedApiService;
|
||||
|
||||
@Autowired private ProjectService projectService;
|
||||
@ -45,58 +39,52 @@ public class SharedApiServiceTest {
|
||||
private static Entrepreneur functional_entrepreneur;
|
||||
private static Project functional_project;
|
||||
|
||||
static private Entrepreneur empty_entrepreneur;
|
||||
static private Administrator empty_administrator;
|
||||
static private Project empty_Project;
|
||||
|
||||
private static Entrepreneur empty_entrepreneur;
|
||||
private static Administrator empty_administrator;
|
||||
private static Project empty_Project;
|
||||
|
||||
private static Administrator getTestAdmin(String name) {
|
||||
return new Administrator(
|
||||
name,
|
||||
name,
|
||||
name+"@example.com",
|
||||
"seconday@example.com",
|
||||
"0123456789");
|
||||
name, name, name + "@example.com", "seconday@example.com", "0123456789");
|
||||
}
|
||||
|
||||
private static Entrepreneur getTestEntrpreneur(String name) {
|
||||
return new Entrepreneur(
|
||||
name,
|
||||
name,
|
||||
name+"@example.com",
|
||||
"seconday@example.com",
|
||||
"0123456789",
|
||||
"School",
|
||||
"Course",
|
||||
false);
|
||||
name,
|
||||
name,
|
||||
name + "@example.com",
|
||||
"seconday@example.com",
|
||||
"0123456789",
|
||||
"School",
|
||||
"Course",
|
||||
false);
|
||||
}
|
||||
|
||||
private static Project getTestProject(String name, Administrator admin) {
|
||||
return new Project(name, null, LocalDate.now(), ACTIVE, admin);
|
||||
}
|
||||
|
||||
static
|
||||
|
||||
@BeforeAll
|
||||
private void setup(
|
||||
static @BeforeAll private void setup(
|
||||
@Autowired AdministratorService administratorService,
|
||||
@Autowired ProjectService projectService,
|
||||
@Autowired EntrepreneurService entrepreneurService) {
|
||||
|
||||
empty_entrepreneur = entrepreneurService.addEntrepreneur(null);
|
||||
empty_administrator = administratorService.addAdministrator(null);
|
||||
empty_Project = projectService.addNewProject(new Project());
|
||||
|
||||
functional_administrator = administratorService.addAdministrator(getTestAdmin("functional_administrator"));
|
||||
functional_entrepreneur = entrepreneurService.addEntrepreneur(getTestEntrpreneur("functional_entrepreneur"));
|
||||
functional_project = projectService.addNewProject(getTestProject("functional_project", functional_administrator));
|
||||
functional_project.updateListEntrepreneurParticipation(functional_entrepreneur);
|
||||
|
||||
empty_entrepreneur = entrepreneurService.addEntrepreneur(null);
|
||||
empty_administrator = administratorService.addAdministrator(null);
|
||||
empty_Project = projectService.addNewProject(new Project());
|
||||
|
||||
functional_administrator =
|
||||
administratorService.addAdministrator(getTestAdmin("functional_administrator"));
|
||||
functional_entrepreneur =
|
||||
entrepreneurService.addEntrepreneur(getTestEntrpreneur("functional_entrepreneur"));
|
||||
functional_project =
|
||||
projectService.addNewProject(
|
||||
getTestProject("functional_project", functional_administrator));
|
||||
functional_project.updateListEntrepreneurParticipation(functional_entrepreneur);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
private void cleanup() {
|
||||
|
||||
}
|
||||
private void cleanup() {}
|
||||
|
||||
private <T> List<T> IterableToList(Iterable<T> iterable) {
|
||||
List<T> l = new ArrayList<>();
|
||||
@ -106,7 +94,7 @@ public class SharedApiServiceTest {
|
||||
|
||||
private <T> boolean matchesIgnoringId(T expected, T actual) {
|
||||
/*
|
||||
Implementing custom comparison logic depending on the actual type of T,
|
||||
Implementing custom comparison logic depending on the actual type of T,
|
||||
Can't think of a better way than changing the model and overriding equals
|
||||
*/
|
||||
if (expected instanceof Appointment && actual instanceof Appointment) {
|
||||
@ -117,87 +105,87 @@ public class SharedApiServiceTest {
|
||||
&& e.getAppointmentDuration().equals(a.getAppointmentDuration())
|
||||
&& e.getAppointmentDuration().equals(a.getAppointmentPlace());
|
||||
}
|
||||
|
||||
|
||||
throw new IllegalArgumentException("Unsupported type for comparison");
|
||||
}
|
||||
|
||||
|
||||
private <T, K> void TestIfInIterable(Iterable<T> iterable, K expected) {
|
||||
List<T> l = IterableToList(iterable);
|
||||
Boolean exists = l.stream()
|
||||
.anyMatch(e -> matchesIgnoringId(expected, e));
|
||||
Boolean exists = l.stream().anyMatch(e -> matchesIgnoringId(expected, e));
|
||||
assertTrue(exists, "");
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests if an appointement made by the user himself and the users associated with appointment,
|
||||
* the appoitement date, time, etc are correct.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testCreateAppointmentRequest_Users() {
|
||||
/*
|
||||
/*
|
||||
* Creating the setup for the test
|
||||
*/
|
||||
*/
|
||||
LocalDate date = LocalDate.parse("02-05-2025");
|
||||
LocalTime duration = LocalTime.parse("00:15:30");
|
||||
LocalTime time = LocalTime.parse("10:20:00");
|
||||
String appointmentPlace = "salleInpulse";
|
||||
String appointmentSubject = "Titanic";
|
||||
Appointment appointment = new Appointment( new Long(0), date, time, duration, appointmentPlace, appointmentSubject);
|
||||
sharedApiService.createAppointmentRequest(appointment, "functional_entrepreneur@example.com");
|
||||
Appointment appointment =
|
||||
new Appointment(
|
||||
new Long(0), date, time, duration, appointmentPlace, appointmentSubject);
|
||||
sharedApiService.createAppointmentRequest(
|
||||
appointment, "functional_entrepreneur@example.com");
|
||||
/*
|
||||
* fetching the values and testing them
|
||||
*/
|
||||
Iterable<Appointment> appointments = sharedApiService.getAppointmentsByProjectId(functional_project.getIdProject(), "functional_entrepreneur@example.com");
|
||||
Iterable<Appointment> appointments =
|
||||
sharedApiService.getAppointmentsByProjectId(
|
||||
functional_project.getIdProject(), "functional_entrepreneur@example.com");
|
||||
List<Appointment> appointment_list = IterableToList(appointments);
|
||||
|
||||
|
||||
assertEquals(date, date);
|
||||
assertEquals(time, time);
|
||||
assertEquals(appointmentPlace, appointmentPlace);
|
||||
assertEquals(appointmentSubject, appointmentSubject);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests the edge cases:
|
||||
* - an appointement made by a user but has no participants.
|
||||
* - the inputed dates for appointments are not older than current date.
|
||||
* - date or time format is wrong.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testCreateAppointmentRequest_EdgeCases() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests if an admin and entrepreneur with no prior appointments
|
||||
/*
|
||||
* Tests if an admin and entrepreneur with no prior appointments
|
||||
* have no appointments.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetAppointement_EmptyUser() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests if an admin and entrepreneur indepedant of eachother with no prior appointments,
|
||||
/*
|
||||
* Tests if an admin and entrepreneur indepedant of eachother with no prior appointments,
|
||||
* each have exactly one appointment an appointment after .
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetAppointement_NonEmptyUser() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests if an admin and entrepreneur both bound by the same project
|
||||
* have the same appointment.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetAppointement_UsersHaveSameAppointement() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Tests if in empty project has no sectionCells
|
||||
*/
|
||||
@ -207,7 +195,7 @@ public class SharedApiServiceTest {
|
||||
}
|
||||
|
||||
/*
|
||||
* Tests if in a project with no prior sectionCells that is given exactly
|
||||
* Tests if in a project with no prior sectionCells that is given exactly
|
||||
* one sectionCell has:
|
||||
* - exactly one section cell.
|
||||
* - the cell given back has the correct information.
|
||||
@ -217,31 +205,31 @@ public class SharedApiServiceTest {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests the edge cases:
|
||||
* - sectionId is in {1, ... , 8}.
|
||||
* - modificationDate is not newer than the current date.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetSectionCells_EdgeCases() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests if:
|
||||
* - handls a non existing projectId correctly.
|
||||
* - returns the correct admin associated with project by id
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetAdminByProjectId() {
|
||||
assertEquals(0, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* Tests if:
|
||||
* - handls non existing projectId correctly.
|
||||
* - returns the correct entrepreneurs associated with the project.
|
||||
*/
|
||||
*/
|
||||
@Test
|
||||
void testGetEntrepreneursByProjectId() {
|
||||
assertEquals(0, 0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user