public class NurseRosteringScoreRulesTest extends LoggingTest {
@Test
public void switchEmployeeAndUndo() {
LocalSearchSolverScope localSearchSolverScope = new LocalSearchSolverScope();
localSearchSolverScope.setRuleBase(buildRuleBase());
localSearchSolverScope.setWorkingScoreCalculator(new DefaultHardAndSoftConstraintScoreCalculator());
NurseRoster nurseRoster = (NurseRoster) new NurseRosteringDaoImpl().readSolution(getClass().getResourceAsStream(
"/org/drools/planner/examples/nurserostering/data/testNurseRosteringScoreRules.xml"));
localSearchSolverScope.setWorkingSolution(nurseRoster);
WorkingMemory workingMemory = localSearchSolverScope.getWorkingMemory();
Score firstScore = localSearchSolverScope.calculateScoreFromWorkingMemory();
// do AssignmentSwitchMove
Employee leftEmployee = findEmployeeById(nurseRoster, 0L);
Assignment leftAssignment = findAssignmentById(nurseRoster, 200204001L);
assertEquals(leftEmployee, leftAssignment.getEmployee());
Employee rightEmployee = findEmployeeById(nurseRoster, 12L);
Assignment rightAssignment = findAssignmentById(nurseRoster, 200204002L);
assertEquals(rightEmployee, rightAssignment.getEmployee());
NurseRosteringMoveHelper.moveEmployee(workingMemory, leftAssignment, rightEmployee);
NurseRosteringMoveHelper.moveEmployee(workingMemory, rightAssignment, leftEmployee);
localSearchSolverScope.calculateScoreFromWorkingMemory();
// undo AssignmentSwitchMove;
NurseRosteringMoveHelper.moveEmployee(workingMemory, rightAssignment, rightEmployee);
NurseRosteringMoveHelper.moveEmployee(workingMemory, leftAssignment, leftEmployee);
Score secondScore = localSearchSolverScope.calculateScoreFromWorkingMemory();
assertEquals(firstScore, secondScore);
}