ItEr29S06CUAsignacionGrupoRecursosAPlanificacionItEr28S06: Adding method to retrieve the resources associated to a GenericResourceAllocation

This commit is contained in:
Óscar González Fernández 2009-10-08 23:05:59 +02:00
parent 0540589ec5
commit cd0f22cfe0
2 changed files with 29 additions and 0 deletions

View file

@ -249,4 +249,12 @@ public class GenericResourceAllocation extends
assignemnts);
}
public List<Resource> getAssociatedResources() {
Set<Resource> resources = new HashSet<Resource>();
for (DayAssignment dayAssignment : getAssignments()) {
resources.add(dayAssignment.getResource());
}
return new ArrayList<Resource>(resources);
}
}

View file

@ -34,6 +34,7 @@ import static org.navalplanner.business.test.planner.entities.DayAssignmentMatch
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
@ -338,4 +339,24 @@ public class GenericResourceAllocationTest {
* workableHoursDay));
}
@Test
public void theRelatedResourcesCanBeRetrieved() {
givenTaskWithStartAndEnd(toInterval(new LocalDate(2006, 10, 5), Period
.days(4)));
givenGenericResourceAllocationForTask(task);
givenWorkersWithoutLoadAndWithoutCalendar();
List<Resource> resourcesGiven = Arrays.<Resource> asList(worker1,
worker2);
genericResourceAllocation.forResources(resourcesGiven)
.allocate(ResourcesPerDay.amount(1));
assertThat(asSet(genericResourceAllocation.getAssociatedResources()),
equalTo(asSet(genericResourceAllocation
.getAssociatedResources())));
}
private Set<Resource> asSet(Collection<Resource> associatedResources) {
return new HashSet<Resource>(associatedResources);
}
}