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

play.modules.testrunner.TestRunnerPlugin Maven / Gradle / Ivy

There is a newer version: 1.5.0
Show newest version
package play.modules.testrunner;

import java.io.File;

import play.Play;
import play.PlayPlugin;
import play.mvc.Router;
import play.vfs.VirtualFile;

public class TestRunnerPlugin extends PlayPlugin {

    @Override
    public void onLoad() {
        VirtualFile appRoot = VirtualFile.open(Play.applicationPath);
        Play.javaPath.add(appRoot.child("test"));
        for (VirtualFile module : Play.modules.values()) {
            File modulePath = module.getRealFile();
            if (!modulePath.getAbsolutePath().startsWith(Play.frameworkPath.getAbsolutePath()) && !Play.javaPath.contains(module.child("test"))) {
                Play.javaPath.add(module.child("test"));
            }
        }
    }

    @Override
    public void onRoutesLoaded() {
        Router.addRoute("GET", "/@tests", "TestRunner.index");
        Router.addRoute("GET", "/@tests.list", "TestRunner.list");
        Router.addRoute("GET", "/@tests/{<.*>test}", "TestRunner.run");
        Router.addRoute("POST", "/@tests/{<.*>test}", "TestRunner.saveResult");
        Router.addRoute("GET", "/@tests/emails", "TestRunner.mockEmail");
        Router.addRoute("GET", "/@tests/cache", "TestRunner.cacheEntry");
    }

    @Override
    public void onApplicationReady() {
        String protocol = "http";
        String port = "9000";
        if(Play.configuration.getProperty("https.port") != null) {
            port = Play.configuration.getProperty("https.port");
            protocol = "https";
        } else if(Play.configuration.getProperty("http.port") != null) {
          port = Play.configuration.getProperty("http.port");
        }
        System.out.println("~");
        System.out.println("~ Go to "+protocol+"://localhost:" + port + "/@tests to run the tests");
        System.out.println("~");
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy