Search in sources :

Example 1 with TeamAssignmentPayload

use of de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload in project ArTEMiS by ls1intum.

the class TeamWebsocketServiceTest method testSendTeamAssignmentUpdateOnTeamCreate.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
void testSendTeamAssignmentUpdateOnTeamCreate() throws Exception {
    Team team = new Team().name("Team").shortName("team").exercise(modelingExercise).students(students);
    team = request.postWithResponseBody(teamResourceUrl(), team, Team.class, HttpStatus.CREATED);
    TeamAssignmentPayload expectedPayload = new TeamAssignmentPayload(modelingExercise, team);
    team.getStudents().forEach(user -> verify(messagingTemplate).convertAndSendToUser(user.getLogin(), assignmentTopic, expectedPayload));
}
Also used : TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 2 with TeamAssignmentPayload

use of de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload in project Artemis by ls1intum.

the class TeamWebsocketService method sendTeamAssignmentUpdate.

/**
 * Sends out team assignment information for an exercise to students of a created/updated/deleted team
 *
 * Cases:
 * 1. Team was created: sendTeamAssignmentUpdate(exercise, null, createdTeam);
 * 2. Team was updated: sendTeamAssignmentUpdate(exercise, existingTeam, updatedTeam);
 * 3. Team was deleted: sendTeamAssignmentUpdate(exercise, deletedTeam, null);
 *
 * @param exercise                    Exercise for which the team assignment has been made
 * @param existingTeam                Team before the update (null when a team was created)
 * @param updatedTeam                 Team after the update (null when a team was deleted)
 * @param participationsOfUpdatedTeam Student participations of the updated team
 */
public void sendTeamAssignmentUpdate(Exercise exercise, @Nullable Team existingTeam, @Nullable Team updatedTeam, List<StudentParticipation> participationsOfUpdatedTeam) {
    // Users in the existing team that are no longer in the updated team were unassigned => inform them
    if (existingTeam != null) {
        TeamAssignmentPayload payload = new TeamAssignmentPayload(exercise, null);
        Set<User> unassignedUsers = new HashSet<>(existingTeam.getStudents());
        unassignedUsers.removeAll(Optional.ofNullable(updatedTeam).map(Team::getStudents).orElse(Set.of()));
        unassignedUsers.forEach(user -> messagingTemplate.convertAndSendToUser(user.getLogin(), assignmentTopic, payload));
    }
    // Users in the updated team that were not yet part of the existing team were newly assigned => inform them
    if (updatedTeam != null) {
        TeamAssignmentPayload payload = new TeamAssignmentPayload(exercise, updatedTeam, participationsOfUpdatedTeam);
        Set<User> assignedUsers = new HashSet<>(updatedTeam.getStudents());
        assignedUsers.removeAll(Optional.ofNullable(existingTeam).map(Team::getStudents).orElse(Set.of()));
        assignedUsers.forEach(user -> messagingTemplate.convertAndSendToUser(user.getLogin(), assignmentTopic, payload));
    }
}
Also used : User(de.tum.in.www1.artemis.domain.User) TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) Team(de.tum.in.www1.artemis.domain.Team)

Example 3 with TeamAssignmentPayload

use of de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload in project ArTEMiS by ls1intum.

the class TeamWebsocketServiceTest method testSendTeamAssignmentUpdateOnAddStudentToTeam.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
void testSendTeamAssignmentUpdateOnAddStudentToTeam() throws Exception {
    Team team = new Team().name("Team").shortName("team").exercise(modelingExercise);
    team = request.postWithResponseBody(teamResourceUrl(), team, Team.class, HttpStatus.CREATED);
    Team updatedTeam = new Team(team).id(team.getId()).students(students);
    updatedTeam = request.putWithResponseBody(teamResourceUrl() + "/" + updatedTeam.getId(), updatedTeam, Team.class, HttpStatus.OK);
    TeamAssignmentPayload expectedPayload = new TeamAssignmentPayload(modelingExercise, updatedTeam);
    team.getStudents().forEach(user -> verify(messagingTemplate).convertAndSendToUser(user.getLogin(), assignmentTopic, expectedPayload));
}
Also used : TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 4 with TeamAssignmentPayload

use of de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload in project ArTEMiS by ls1intum.

the class TeamWebsocketServiceTest method testSendTeamAssignmentUpdateOnTeamImport.

@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void testSendTeamAssignmentUpdateOnTeamImport() throws Exception {
    // create teams in source exercise
    database.addTeamsForExercise(textExercise, 2, null);
    List<Team> destinationTeams = request.putWithResponseBodyList(importFromExerciseUrl(textExercise), null, Team.class, HttpStatus.OK);
    destinationTeams.forEach(team -> {
        TeamAssignmentPayload expectedPayload = new TeamAssignmentPayload(modelingExercise, team);
        team.getStudents().forEach(user -> verify(messagingTemplate).convertAndSendToUser(user.getLogin(), assignmentTopic, expectedPayload));
    });
}
Also used : TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Example 5 with TeamAssignmentPayload

use of de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload in project ArTEMiS by ls1intum.

the class TeamWebsocketServiceTest method testSendTeamAssignmentUpdateOnRemoveStudentFromTeam.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
void testSendTeamAssignmentUpdateOnRemoveStudentFromTeam() throws Exception {
    Team team = new Team().name("Team").shortName("team").exercise(modelingExercise).students(students);
    team = request.postWithResponseBody(teamResourceUrl(), team, Team.class, HttpStatus.CREATED);
    User studentToRemoveFromTeam = students.iterator().next();
    Team updatedTeam = new Team(team).id(team.getId()).removeStudents(studentToRemoveFromTeam);
    request.putWithResponseBody(teamResourceUrl() + "/" + updatedTeam.getId(), updatedTeam, Team.class, HttpStatus.OK);
    TeamAssignmentPayload expectedPayload = new TeamAssignmentPayload(modelingExercise, null);
    verify(messagingTemplate).convertAndSendToUser(studentToRemoveFromTeam.getLogin(), assignmentTopic, expectedPayload);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) AbstractSpringIntegrationBambooBitbucketJiraTest(de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)

Aggregations

TeamAssignmentPayload (de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload)12 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)10 Test (org.junit.jupiter.api.Test)10 WithMockUser (org.springframework.security.test.context.support.WithMockUser)10 Team (de.tum.in.www1.artemis.domain.Team)2 User (de.tum.in.www1.artemis.domain.User)2