backend-api #6
@@ -37,7 +37,6 @@ public class Entrepreneur extends User {
 | 
				
			|||||||
    public Entrepreneur() {}
 | 
					    public Entrepreneur() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Entrepreneur(
 | 
					    public Entrepreneur(
 | 
				
			||||||
            Long idUser,
 | 
					 | 
				
			||||||
            String userSurname,
 | 
					            String userSurname,
 | 
				
			||||||
            String username,
 | 
					            String username,
 | 
				
			||||||
            String primaryMail,
 | 
					            String primaryMail,
 | 
				
			||||||
@@ -46,7 +45,7 @@ public class Entrepreneur extends User {
 | 
				
			|||||||
            String school,
 | 
					            String school,
 | 
				
			||||||
            String course,
 | 
					            String course,
 | 
				
			||||||
            boolean sneeStatus) {
 | 
					            boolean sneeStatus) {
 | 
				
			||||||
        super(idUser, userSurname, username, primaryMail, secondaryMail, phoneNumber);
 | 
					        super(userSurname, username, primaryMail, secondaryMail, phoneNumber);
 | 
				
			||||||
        this.school = school;
 | 
					        this.school = school;
 | 
				
			||||||
        this.course = course;
 | 
					        this.course = course;
 | 
				
			||||||
        this.sneeStatus = sneeStatus;
 | 
					        this.sneeStatus = sneeStatus;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -28,6 +28,8 @@ public class User {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    public User() {}
 | 
					    public User() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TODO: this should be removed as we shouldn't be able to chose the ID. Leaving it for
 | 
				
			||||||
 | 
					    // compatibility purposes, as soon as it's not used anymore, delete it
 | 
				
			||||||
    public User(
 | 
					    public User(
 | 
				
			||||||
            Long idUser,
 | 
					            Long idUser,
 | 
				
			||||||
            String userSurname,
 | 
					            String userSurname,
 | 
				
			||||||
@@ -43,6 +45,19 @@ public class User {
 | 
				
			|||||||
        this.phoneNumber = phoneNumber;
 | 
					        this.phoneNumber = phoneNumber;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public User(
 | 
				
			||||||
 | 
					            String userSurname,
 | 
				
			||||||
 | 
					            String userName,
 | 
				
			||||||
 | 
					            String primaryMail,
 | 
				
			||||||
 | 
					            String secondaryMail,
 | 
				
			||||||
 | 
					            String phoneNumber) {
 | 
				
			||||||
 | 
					        this.userSurname = userSurname;
 | 
				
			||||||
 | 
					        this.userName = userName;
 | 
				
			||||||
 | 
					        this.primaryMail = primaryMail;
 | 
				
			||||||
 | 
					        this.secondaryMail = secondaryMail;
 | 
				
			||||||
 | 
					        this.phoneNumber = phoneNumber;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public Long getIdUser() {
 | 
					    public Long getIdUser() {
 | 
				
			||||||
        return idUser;
 | 
					        return idUser;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -91,7 +91,9 @@ public class AdminApiService {
 | 
				
			|||||||
            newProject.getProjectAdministrator().updateListProject(newProject);
 | 
					            newProject.getProjectAdministrator().updateListProject(newProject);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (newProject.getEntrepreneurProposed() != null) {
 | 
					        if (newProject.getEntrepreneurProposed() != null) {
 | 
				
			||||||
            newProject.getEntrepreneurProposed().setProjectProposed(newProject);
 | 
					            Entrepreneur proposed = newProject.getEntrepreneurProposed();
 | 
				
			||||||
 | 
					            proposed.setProjectProposed(newProject);
 | 
				
			||||||
 | 
					            proposed.setProjectParticipation(newProject);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        newProject
 | 
					        newProject
 | 
				
			||||||
                .getListEntrepreneurParticipation()
 | 
					                .getListEntrepreneurParticipation()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,10 +5,12 @@ import static enseirb.myinpulse.model.ProjectDecisionValue.*;
 | 
				
			|||||||
import static org.junit.jupiter.api.Assertions.*;
 | 
					import static org.junit.jupiter.api.Assertions.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import enseirb.myinpulse.model.Administrator;
 | 
					import enseirb.myinpulse.model.Administrator;
 | 
				
			||||||
 | 
					import enseirb.myinpulse.model.Entrepreneur;
 | 
				
			||||||
import enseirb.myinpulse.model.Project;
 | 
					import enseirb.myinpulse.model.Project;
 | 
				
			||||||
import enseirb.myinpulse.model.ProjectDecision;
 | 
					import enseirb.myinpulse.model.ProjectDecision;
 | 
				
			||||||
import enseirb.myinpulse.service.AdminApiService;
 | 
					import enseirb.myinpulse.service.AdminApiService;
 | 
				
			||||||
import enseirb.myinpulse.service.database.AdministratorService;
 | 
					import enseirb.myinpulse.service.database.AdministratorService;
 | 
				
			||||||
 | 
					import enseirb.myinpulse.service.database.EntrepreneurService;
 | 
				
			||||||
import enseirb.myinpulse.service.database.ProjectService;
 | 
					import enseirb.myinpulse.service.database.ProjectService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.BeforeAll;
 | 
					import org.junit.jupiter.api.BeforeAll;
 | 
				
			||||||
@@ -26,13 +28,16 @@ import java.util.List;
 | 
				
			|||||||
@Transactional
 | 
					@Transactional
 | 
				
			||||||
public class AdminApiServiceTest {
 | 
					public class AdminApiServiceTest {
 | 
				
			||||||
    private static long administratorid;
 | 
					    private static long administratorid;
 | 
				
			||||||
 | 
					    private static Administrator administrator;
 | 
				
			||||||
 | 
					    private static Entrepreneur entrepreneur;
 | 
				
			||||||
    @Autowired private AdminApiService adminApiService;
 | 
					    @Autowired private AdminApiService adminApiService;
 | 
				
			||||||
    @Autowired private ProjectService projectService;
 | 
					    @Autowired private ProjectService projectService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @BeforeAll
 | 
					    @BeforeAll
 | 
				
			||||||
    static void setup(
 | 
					    static void setup(
 | 
				
			||||||
            @Autowired AdministratorService administratorService,
 | 
					            @Autowired AdministratorService administratorService,
 | 
				
			||||||
            @Autowired ProjectService projectService) {
 | 
					            @Autowired ProjectService projectService,
 | 
				
			||||||
 | 
					            @Autowired EntrepreneurService entrepreneurService) {
 | 
				
			||||||
        administratorService.addAdministrator(
 | 
					        administratorService.addAdministrator(
 | 
				
			||||||
                new Administrator(
 | 
					                new Administrator(
 | 
				
			||||||
                        "admin",
 | 
					                        "admin",
 | 
				
			||||||
@@ -40,7 +45,7 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
                        "testAdminEmpty@example.com",
 | 
					                        "testAdminEmpty@example.com",
 | 
				
			||||||
                        "testAdmin@example.com",
 | 
					                        "testAdmin@example.com",
 | 
				
			||||||
                        ""));
 | 
					                        ""));
 | 
				
			||||||
        Administrator a =
 | 
					        administrator =
 | 
				
			||||||
                administratorService.addAdministrator(
 | 
					                administratorService.addAdministrator(
 | 
				
			||||||
                        new Administrator(
 | 
					                        new Administrator(
 | 
				
			||||||
                                "admin2",
 | 
					                                "admin2",
 | 
				
			||||||
@@ -48,7 +53,18 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
                                "testAdminFull@example.com",
 | 
					                                "testAdminFull@example.com",
 | 
				
			||||||
                                "testAdmin@example.com",
 | 
					                                "testAdmin@example.com",
 | 
				
			||||||
                                ""));
 | 
					                                ""));
 | 
				
			||||||
        administratorid = a.getIdUser();
 | 
					        administratorid = administrator.getIdUser();
 | 
				
			||||||
 | 
					        entrepreneur =
 | 
				
			||||||
 | 
					                new Entrepreneur(
 | 
				
			||||||
 | 
					                        "JeSuisUnEntrepreneurDeCompet",
 | 
				
			||||||
 | 
					                        "EtUé",
 | 
				
			||||||
 | 
					                        "Entrepreneur@inpulse.com",
 | 
				
			||||||
 | 
					                        "mail2",
 | 
				
			||||||
 | 
					                        "phone",
 | 
				
			||||||
 | 
					                        "Ensimag    nan jdeconne ENSEIRB (-matmeca mais on s'en fout)",
 | 
				
			||||||
 | 
					                        "info ofc",
 | 
				
			||||||
 | 
					                        false);
 | 
				
			||||||
 | 
					        entrepreneurService.addEntrepreneur(entrepreneur);
 | 
				
			||||||
        projectService.addNewProject(
 | 
					        projectService.addNewProject(
 | 
				
			||||||
                new Project(
 | 
					                new Project(
 | 
				
			||||||
                        "sampleProjectAdminApiService",
 | 
					                        "sampleProjectAdminApiService",
 | 
				
			||||||
@@ -161,6 +177,41 @@ public class AdminApiServiceTest {
 | 
				
			|||||||
        assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size());
 | 
					        assertEquals(1, IterableToList(this.adminApiService.getPendingProjects()).size());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectToAdmin() {
 | 
				
			||||||
 | 
					        assertEquals(0, administrator.getListProject().size());
 | 
				
			||||||
 | 
					        Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, administrator);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(1, administrator.getListProject().size());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectToUser() {
 | 
				
			||||||
 | 
					        assertNull(entrepreneur.getProjectParticipation());
 | 
				
			||||||
 | 
					        Project p1 =
 | 
				
			||||||
 | 
					                new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, entrepreneur);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(p1, entrepreneur.getProjectParticipation());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    void addProjectWithManyUsers() {
 | 
				
			||||||
 | 
					        Entrepreneur e1 = new Entrepreneur();
 | 
				
			||||||
 | 
					        Entrepreneur e2 = new Entrepreneur();
 | 
				
			||||||
 | 
					        Entrepreneur e3 = new Entrepreneur();
 | 
				
			||||||
 | 
					        assertNull(e1.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertNull(e2.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertNull(e3.getProjectParticipation());
 | 
				
			||||||
 | 
					        Project p1 = new Project("assProjectToAdmin", null, LocalDate.now(), ACTIVE, null, null);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e1);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e2);
 | 
				
			||||||
 | 
					        p1.updateListEntrepreneurParticipation(e3);
 | 
				
			||||||
 | 
					        this.adminApiService.addNewProject(p1);
 | 
				
			||||||
 | 
					        assertEquals(p1, e1.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertEquals(p1, e2.getProjectParticipation());
 | 
				
			||||||
 | 
					        assertEquals(p1, e3.getProjectParticipation());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    void addDuplicateProject() {
 | 
					    void addDuplicateProject() {
 | 
				
			||||||
        Project p1 =
 | 
					        Project p1 =
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user