package com.plannaplan.services; import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.List; import com.plannaplan.entities.Assignment; import com.plannaplan.entities.Commision; import com.plannaplan.entities.Groups; import com.plannaplan.entities.User; 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.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest @ContextConfiguration public class GroupServiceTest { @Autowired private GroupService groupService; @Autowired private AssignmentService assignmentService; @Autowired private CommisionService commisionService; @Autowired private UserService userService; @Test public void createAndDeleteGroup() { int startAmmount = this.groupService.getGroupsAmmount(); Groups group = new Groups(); group.setRoom("A1"); groupService.save(group); assertTrue(this.groupService.getGroupsAmmount() > startAmmount); groupService.delete(group); assertTrue(this.groupService.getGroupsAmmount() == startAmmount); } @Test public void shouldGetGroupsAssignmentsAmmounts() throws InterruptedException { final Groups testGroup = groupService.save(new Groups(43, "A-41", null, 645, WeekDay.MONDAY, null)); final Groups testGroup2 = groupService.save(new Groups(433, "A-41", null, 235, WeekDay.TUESDAY, null)); final Groups testGroup3 = groupService.save(new Groups(23, "A-41", null, 340, WeekDay.MONDAY, null)); final User user = this.userService.save( new User("Dare", "Oc", "shouldReturnGroupAssignmentTimesList@grouprepository.test", UserRoles.STUDENT)); final Commision commision = this.commisionService.save(new Commision(user)); this.assignmentService.save(new Assignment(testGroup, commision)); this.assignmentService.save(new Assignment(testGroup2, commision)); this.assignmentService.save(new Assignment(testGroup3, commision)); Thread.sleep(1000); HashMap response = this.groupService.getTakenPlaces(List.of(testGroup, testGroup2, testGroup3)); assertTrue(response.size() == 3); assertTrue(response.get(testGroup.getId()) == 1); assertTrue(response.get(testGroup2.getId()) == 1); assertTrue(response.get(testGroup3.getId()) == 1); } }