From 5e459ac4292795f47aeafd13d197748d08880b40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Wo=C5=BAniak?= Date: Mon, 11 Jan 2021 16:20:59 +0100 Subject: [PATCH] Checkpoint: Added test to ExchangeRepo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Marcin Woźniak --- .../repositories/ExchangeRepositoryTest.java | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 buisnesslogic/src/test/java/com/plannaplan/repositories/ExchangeRepositoryTest.java diff --git a/buisnesslogic/src/test/java/com/plannaplan/repositories/ExchangeRepositoryTest.java b/buisnesslogic/src/test/java/com/plannaplan/repositories/ExchangeRepositoryTest.java new file mode 100644 index 0000000..1690c5b --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/repositories/ExchangeRepositoryTest.java @@ -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 exchangeRepoMatches = this.exchangeRepository.getMatches(); + assertTrue(exchangeRepoMatches.size() == 2); + } +}