Checkpoint: Added mew test
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
1e1160736d
commit
f9a27abb32
@ -46,6 +46,10 @@ public class ExchangeService {
|
|||||||
return this.repo.findById(id);
|
return this.repo.findById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Exchange> getAllExchanges() {
|
||||||
|
return this.repo.findAll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param id Id of user
|
* @param id Id of user
|
||||||
* @return List of exchanges that belong to user
|
* @return List of exchanges that belong to user
|
||||||
|
@ -2,7 +2,9 @@ package com.plannaplan.services;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.plannaplan.entities.Assignment;
|
import com.plannaplan.entities.Assignment;
|
||||||
import com.plannaplan.entities.Commision;
|
import com.plannaplan.entities.Commision;
|
||||||
@ -14,6 +16,7 @@ import com.plannaplan.repositories.CommisionRepository;
|
|||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
import com.plannaplan.types.WeekDay;
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -66,20 +69,29 @@ public class ExchangeServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
|
@Ignore
|
||||||
public void shouldPerformExchange() {
|
public void shouldPerformExchange() {
|
||||||
final User user1 = this.userService.save(new User(null, null, "1shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT , 451));
|
User user1 = this.userService.save(
|
||||||
|
new User(null, null, "1shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT, 451));
|
||||||
|
final Long user1Id = user1.getId();
|
||||||
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||||
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||||
|
|
||||||
final User user2 = this.userService.save(new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123455", UserRoles.STUDENT , 452));
|
User user2 = this.userService.save(
|
||||||
|
new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123455", UserRoles.STUDENT, 452));
|
||||||
|
final Long user2Id = user2.getId();
|
||||||
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||||
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||||
|
|
||||||
final User user3 = this.userService.save(new User(null, null, "3shouldReturnMatches@ExchangeRepository.test", "123456", UserRoles.STUDENT , 453));
|
User user3 = this.userService.save(
|
||||||
|
new User(null, null, "3shouldReturnMatches@ExchangeRepository.test", "123456", UserRoles.STUDENT, 453));
|
||||||
|
final Long user3Id = user3.getId();
|
||||||
final Groups group3 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.WEDNESDAY, null));
|
final Groups group3 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.WEDNESDAY, null));
|
||||||
final Commision commision3 = this.commisionRepository.save(new Commision(user3));
|
final Commision commision3 = this.commisionRepository.save(new Commision(user3));
|
||||||
|
|
||||||
final User user4 = this.userService.save(new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123457", UserRoles.STUDENT , 455));
|
User user4 = this.userService.save(
|
||||||
|
new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123457", UserRoles.STUDENT, 455));
|
||||||
|
final Long user4Id = user4.getId();
|
||||||
final Groups group4 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.FRIDAY, null));
|
final Groups group4 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.FRIDAY, null));
|
||||||
final Commision commision4 = this.commisionRepository.save(new Commision(user4));
|
final Commision commision4 = this.commisionRepository.save(new Commision(user4));
|
||||||
|
|
||||||
@ -93,9 +105,67 @@ public class ExchangeServiceTest {
|
|||||||
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
||||||
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
||||||
this.exchangeService.save(new Exchange(assignmentUser3, group1));
|
this.exchangeService.save(new Exchange(assignmentUser3, group1));
|
||||||
|
|
||||||
this.exchangeService.save(new Exchange(assignmentUser4, group3));
|
this.exchangeService.save(new Exchange(assignmentUser4, group3));
|
||||||
|
|
||||||
this.exchangeService.performExchange();
|
this.exchangeService.performExchange();
|
||||||
assertTrue(false);
|
|
||||||
|
user1 = this.userService.getById(user1Id).get();
|
||||||
|
user2 = this.userService.getById(user2Id).get();
|
||||||
|
user3 = this.userService.getById(user3Id).get();
|
||||||
|
user4 = this.userService.getById(user4Id).get();
|
||||||
|
|
||||||
|
final List<Long> listGroupsOfUser1 = user1.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final List<Long> listGroupsOfUser2 = user2.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final List<Long> listGroupsOfUser3 = user3.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final List<Long> listGroupsOfUser4 = user4.getStudentRegisteredGrups().stream().map(Groups::getId)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
||||||
|
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
||||||
|
assertTrue(listGroupsOfUser3.contains(group2.getId()));
|
||||||
|
assertTrue(listGroupsOfUser4.contains(group4.getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
|
public void shouldRemoveOutDatedExchnages() {
|
||||||
|
User user1 = this.userService.save(new User(null, null, "1shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT , 451));
|
||||||
|
final Long user1Id = user1.getId();
|
||||||
|
final Groups group1 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
|
||||||
|
final Commision commision1 = this.commisionRepository.save(new Commision(user1));
|
||||||
|
|
||||||
|
User user2 = this.userService.save(new User(null, null, "2shouldReturnMatches@ExchangeRepository.test", "123455", UserRoles.STUDENT, 452));
|
||||||
|
final Long user2Id = user2.getId();
|
||||||
|
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||||
|
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
|
||||||
|
|
||||||
|
final Groups group3 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||||
|
final Groups group4 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.THURSDAY, null));
|
||||||
|
|
||||||
|
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
|
||||||
|
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
|
||||||
|
|
||||||
|
this.assignmentService.callAcceptAlgorythm();
|
||||||
|
|
||||||
|
this.exchangeService.save(new Exchange(assignmentUser1, group2));
|
||||||
|
this.exchangeService.save(new Exchange(assignmentUser2, group1));
|
||||||
|
this.exchangeService.save(new Exchange(assignmentUser1, group3));
|
||||||
|
this.exchangeService.save(new Exchange(assignmentUser1, group4));
|
||||||
|
|
||||||
|
this.exchangeService.performExchange();
|
||||||
|
|
||||||
|
user1 = this.userService.getById(user1Id).get();
|
||||||
|
user2 = this.userService.getById(user2Id).get();
|
||||||
|
|
||||||
|
final List<Long> listGroupsOfUser1 = user1.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
|
||||||
|
final List<Long> listGroupsOfUser2 = user2.getStudentRegisteredGrups().stream().map(Groups::getId).collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
||||||
|
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
||||||
|
assertTrue(this.exchangeService.getAllExchanges().size() == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user