com.cj.qunit.mojo.http.TestListingResource Maven / Gradle / Ivy
package com.cj.qunit.mojo.http;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.httpobjects.HttpObject;
import org.httpobjects.Request;
import org.httpobjects.Response;
import com.cj.qunit.mojo.LocatedTest;
import com.cj.qunit.mojo.Scanner;
class TestListingResource extends HttpObject {
private final List paths;
private final String basePath;
private final String webPathToRequireDotJsConfig;
private final Scanner scanner;
public TestListingResource(String pathPattern, String basePath, String webPathToRequireDotJsConfig, List paths, Scanner scanner) {
super(pathPattern);
this.basePath = basePath;
this.paths = paths;
this.webPathToRequireDotJsConfig = webPathToRequireDotJsConfig;
this.scanner = scanner;
}
@Override
public Response get(Request req) {
List allTestFiles = scanner.findTests();
StringBuffer html = new StringBuffer("" +
"Qunit Tests " +
"Qunit Tests");
Map> testsByParentDir = new TreeMap>();
for(LocatedTest test : allTestFiles){
final String parent = test.groupName();
List tests = testsByParentDir.get(parent);
if(tests==null){
tests = new ArrayList();
testsByParentDir.put(parent, tests);
}
tests.add(test);
}
for(Map.Entry> entry : testsByParentDir.entrySet()){
html.append("" + entry.getKey() + "");
for(LocatedTest test : entry.getValue()){
html.append("");
}
}
html.append("