Checkpoint: Added test to ExchangeRepo

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2021-01-11 16:20:59 +01:00
parent b18f9cd50e
commit 5e459ac429
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -0,0 +1,69 @@
package com.plannaplan.repositories;
import static org.junit.Assert.assertTrue;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.plannaplan.entities.Assignment;
import com.plannaplan.entities.Commision;
import com.plannaplan.entities.Exchange;
import com.plannaplan.entities.Groups;
import com.plannaplan.entities.User;
import com.plannaplan.services.AssignmentService;
import com.plannaplan.services.GroupService;
import com.plannaplan.services.UserService;
import com.plannaplan.types.UserRoles;
import com.plannaplan.types.WeekDay;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.MethodMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest
@ContextConfiguration
public class ExchangeRepositoryTest{
@Autowired
private ExchangeRepository exchangeRepository;
@Autowired
private AssignmentService assignmentService;
@Autowired
private GroupService groupService;
@Autowired
private UserService userService;
@Autowired
private CommisionRepository commisionRepository;
@Test
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
public void shouldReturnMatches() {
final User user1 = this.userService.save(new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT , 451));
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 User user2 = this.userService.save(new User(null, null, "shouldReturnMatches@ExchangeRepository.test", "123454", UserRoles.STUDENT , 451));
final Groups group2 = this.groupService.save(new Groups(123, "A2-3", null, 430, WeekDay.MONDAY, null));
final Commision commision2 = this.commisionRepository.save(new Commision(user2));
final Assignment assignmentUser1 = this.assignmentService.save(new Assignment(group1, commision1));
final Assignment assignmentUser2 = this.assignmentService.save(new Assignment(group2, commision2));
this.assignmentService.callAcceptAlgorythm();
this.exchangeRepository.save(new Exchange(assignmentUser1, group2));
this.exchangeRepository.save(new Exchange(assignmentUser2, group1));
final List<Object[]> exchangeRepoMatches = this.exchangeRepository.getMatches();
assertTrue(exchangeRepoMatches.size() == 2);
}
}