Checkpoint: Added ExchangeServiceTest
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
		@@ -19,6 +19,11 @@ public class MatchData {
 | 
			
		||||
	return assignmentOne;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public int hashCode() {
 | 
			
		||||
	return this.assignmentOne.hashCode() + this.assignmentTwo.hashCode();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean equals(Object o) {
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,10 @@
 | 
			
		||||
package com.plannaplan.services;
 | 
			
		||||
 | 
			
		||||
import java.util.HashSet;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
 | 
			
		||||
import com.plannaplan.entities.Assignment;
 | 
			
		||||
import com.plannaplan.entities.Exchange;
 | 
			
		||||
@@ -62,9 +65,14 @@ public class ExchangeService {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
//    public void getMatches(){
 | 
			
		||||
//	final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
 | 
			
		||||
//		return (MatchData) m;
 | 
			
		||||
//	    });
 | 
			
		||||
//    }
 | 
			
		||||
   public Set<MatchData> getMatches(){
 | 
			
		||||
       final List<MatchData> matches = this.repo.getMatches().stream().map(m -> {
 | 
			
		||||
	       final Exchange exchangeOne = (Exchange) m[0];
 | 
			
		||||
	       final Exchange exchangeTwo = (Exchange) m[1];
 | 
			
		||||
	       return new MatchData(exchangeOne.getOwnedAssignment(), exchangeTwo.getOwnedAssignment());
 | 
			
		||||
	   }).collect(Collectors.toList());
 | 
			
		||||
 | 
			
		||||
       final Set<MatchData> filterMatches = new HashSet<>(matches);
 | 
			
		||||
       return filterMatches;
 | 
			
		||||
   }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,9 +2,7 @@ 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;
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,66 @@
 | 
			
		||||
package com.plannaplan.services;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
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.models.MatchData;
 | 
			
		||||
import com.plannaplan.repositories.CommisionRepository;
 | 
			
		||||
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 ExchangeServiceTest {
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private AssignmentService assignmentService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private GroupService groupService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private UserService userService;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private CommisionRepository commisionRepository;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ExchangeService exchangeService;
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
 | 
			
		||||
    public void shouldReturnUniqMatches() {
 | 
			
		||||
	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.exchangeService.save(new Exchange(assignmentUser1, group2));
 | 
			
		||||
	this.exchangeService.save(new Exchange(assignmentUser2, group1));
 | 
			
		||||
 | 
			
		||||
	final Set<MatchData> uniqList = this.exchangeService.getMatches();
 | 
			
		||||
	assertTrue(uniqList.size() == 1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -30,11 +30,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
import org.springframework.web.bind.annotation.RestController;
 | 
			
		||||
 | 
			
		||||
import io.swagger.annotations.Api;
 | 
			
		||||
import io.swagger.annotations.ApiModelProperty;
 | 
			
		||||
import io.swagger.annotations.ApiOperation;
 | 
			
		||||
import io.swagger.annotations.ApiParam;
 | 
			
		||||
import io.swagger.annotations.Example;
 | 
			
		||||
import io.swagger.annotations.ExampleProperty;
 | 
			
		||||
 | 
			
		||||
@RestController
 | 
			
		||||
@CrossOrigin
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user