All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.Collections;
import java.util.Comparator;
import java.util.HashMap;
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.QunitTestLocator;
import com.cj.qunit.mojo.QunitTestLocator.LocatedTest;;

class TestListingResource extends HttpObject {
    private final List paths;
    private final String basePath;
    
    public TestListingResource(String pathPattern, String basePath, List paths) {
        super(pathPattern);
        this.basePath = basePath;
        this.paths = paths;
    }
    
    @Override
    public Response get(Request req) {

        List allTestFiles = findFiles();
        Collections.sort(allTestFiles, new Comparator() {
            @Override
            public int compare(LocatedTest a, LocatedTest b) {
                return a.relativePath.compareTo(b.relativePath);
            }
        });
        
        StringBuffer html = new StringBuffer("" +
        		"Qunit Tests" +
        		"
Qunit Tests
"); Map> testsByParentDir = new TreeMap>(); for(LocatedTest test : allTestFiles){ final String parent = parentPath(test.relativePath); 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(" findFiles() { List allTestFiles = new ArrayList(); for(File path: paths){ allTestFiles.addAll(new QunitTestLocator().locateTests(path, basePath)); } return allTestFiles; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy