TestdataChainedEntity a3 = new TestdataChainedEntity("a3", a2);
TestdataChainedAnchor b0 = new TestdataChainedAnchor("b0");
TestdataChainedEntity b1 = new TestdataChainedEntity("b1", b0);
TestdataChainedSolution solution = new TestdataChainedSolution("solution");
solution.setChainedAnchorList(Arrays.asList(a0, b0));
solution.setChainedEntityList(Arrays.asList(a1, a2, a3, b1));
SolutionDescriptor solutionDescriptor = TestdataChainedSolution.buildSolutionDescriptor();
EntityDescriptor entityDescriptor = solutionDescriptor.findEntityDescriptorOrFail(
TestdataChainedEntity.class);
GenuineVariableDescriptor variableDescriptor = entityDescriptor.getGenuineVariableDescriptor("chainedObject");
AbstractScoreDirectorFactory scoreDirectorFactory = mock(AbstractScoreDirectorFactory.class);
when(scoreDirectorFactory.getSolutionDescriptor()).thenReturn(solutionDescriptor);
AbstractScoreDirector scoreDirector = new AbstractScoreDirector<AbstractScoreDirectorFactory>(
scoreDirectorFactory, false) {
public boolean isConstraintMatchEnabled() {
return false;
}
public Collection<ConstraintMatchTotal> getConstraintMatchTotals() {
throw new IllegalStateException();
}
public Score calculateScore() {
return SimpleScore.valueOf(-100);
}
};
FieldAccessingSolutionCloner<TestdataChainedSolution> cloner
= new FieldAccessingSolutionCloner<TestdataChainedSolution>(solutionDescriptor);
TestdataChainedSolution clonedStartingSolution = cloner.cloneSolution(solution);
scoreDirector.setWorkingSolution(solution);
assertEquals(a1, scoreDirector.getTrailingEntity(variableDescriptor, a0));
assertEquals(a2, scoreDirector.getTrailingEntity(variableDescriptor, a1));
assertEquals(a3, scoreDirector.getTrailingEntity(variableDescriptor, a2));
assertEquals(b1, scoreDirector.getTrailingEntity(variableDescriptor, b0));
scoreDirector.beforeVariableChanged(a3, "chainedObject");
a3.setChainedObject(b1);
scoreDirector.afterVariableChanged(a3, "chainedObject");
assertEquals(a1, scoreDirector.getTrailingEntity(variableDescriptor, a0));
assertEquals(a2, scoreDirector.getTrailingEntity(variableDescriptor, a1));
assertEquals(b1, scoreDirector.getTrailingEntity(variableDescriptor, b0));
assertEquals(a3, scoreDirector.getTrailingEntity(variableDescriptor, b1));
scoreDirector.setWorkingSolution(clonedStartingSolution);
TestdataChainedEntity a1Clone = clonedStartingSolution.getChainedEntityList().get(0);
assertCode("a1", a1Clone);
TestdataChainedEntity a2Clone = clonedStartingSolution.getChainedEntityList().get(1);
assertCode("a2", a2Clone);
assertEquals("a1", ((TestdataObject) scoreDirector.getTrailingEntity(variableDescriptor, a0)).getCode());
assertEquals("a2", ((TestdataObject) scoreDirector.getTrailingEntity(variableDescriptor, a1Clone)).getCode());
assertEquals("a3", ((TestdataObject) scoreDirector.getTrailingEntity(variableDescriptor, a2Clone)).getCode());
assertEquals("b1", ((TestdataObject) scoreDirector.getTrailingEntity(variableDescriptor, b0)).getCode());