fitnesse.testrunner.run.PagePositionsBasedWikiPagePartitioner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fitnesse Show documentation
Show all versions of fitnesse Show documentation
The fully integrated standalone wiki, and acceptance testing framework.
package fitnesse.testrunner.run;
import fitnesse.wiki.WikiPage;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Partitions pages based on provided PagePositions.
*/
public class PagePositionsBasedWikiPagePartitioner extends PositionMapBasedWikiPagePartitioner {
private Comparator pageComparator;
public PagePositionsBasedWikiPagePartitioner(PagePositions pagePositions) {
if (pagePositions != null) {
setPagePositions(pagePositions);
}
}
public void setPagePositions(PagePositions pagePositions) {
Map partitionMap = loadPartitionFile(pagePositions);
setPartitionMap(partitionMap);
setPageComparator(createComparator(pagePositions));
}
@Override
public List> split(List source, int partitionCount) {
List pages = source;
if (pageComparator != null) {
// by ordering the input according to the positions within each partition BEFORE partitioning the
// resulting partitions will have the ordering prescribed by the page positions
pages = new ArrayList<>(source);
pages.sort(pageComparator);
}
return super.split(pages, partitionCount);
}
protected Comparator createComparator(PagePositions pagePositions) {
Comparator comp = pagePositions.createByPositionInGroupComparator();
return Comparator.comparing(this::getFullPath, comp);
}
protected Map loadPartitionFile(PagePositions pagePositions) {
int part = pagePositions.getGroupIndex(PageListPartitionerImpl.PARTITION_HEADER);
if (part < 0) {
throw new IllegalArgumentException("No " + PageListPartitionerImpl.PARTITION_HEADER + " column found");
}
return extractPartitionMap(pagePositions, part);
}
protected Map extractPartitionMap(PagePositions pagePositions, int partGroupIndex) {
Map indices = new HashMap<>();
for (String page : pagePositions.getPages()) {
List positions = pagePositions.getPositions(page);
for (PagePosition position : positions) {
Integer partValue = position.getGroupIntValue(partGroupIndex);
indices.put(page, partValue);
}
}
return indices;
}
public Comparator getPageComparator() {
return pageComparator;
}
public void setPageComparator(Comparator pageComparator) {
this.pageComparator = pageComparator;
}
}