Example usage for junit.framework TestSuite TestSuite

List of usage examples for junit.framework TestSuite TestSuite

Introduction

In this page you can find the example usage for junit.framework TestSuite TestSuite.

Prototype

TestSuite

Source Link

Usage

From source file:com.networknt.light.rule.role.RoleRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(RoleRuleTest.class);
    return suite;
}

From source file:com.runwaysdk.browser.JavascriptTestRunner.java

public static Test suite() throws Exception {
    // Read project.version
    Properties prop1 = new Properties();
    ClassLoader loader1 = Thread.currentThread().getContextClassLoader();
    InputStream stream1 = loader1.getResourceAsStream("avail-maven.properties");
    prop1.load(stream1);/*from  w  w w  . ja  va2 s. c om*/
    String projVer = prop1.getProperty("mvn.project.version");

    TestSuite suite = new TestSuite();

    int browserLoopIterationNumber = 0;

    System.out.println("Preparing to run cross-browser javascript unit tests.");
    long totalTime = System.currentTimeMillis();

    for (String browser : supportedBrowsers) {
        try {
            String browserDisplayName = String.valueOf(browser.charAt(1)).toUpperCase() + browser.substring(2);
            System.out.println("Opening " + browserDisplayName);

            TestSuite browserSuite = new TestSuite(browserDisplayName);

            selenium = new DefaultSelenium("localhost", 4444, browser,
                    "http://localhost:8080/runwaysdk-browser-test-" + projVer + "/");
            selenium.start();
            isSeleniumStarted = true;
            selenium.open("MasterTestLauncher.jsp");

            //          selenium.waitForCondition("selenium.browserbot.getCurrentWindow().document.getElementById('all');", "6000");

            selenium.setTimeout("1000");

            System.out.println("Running tests...");
            long time = System.currentTimeMillis();

            selenium.click("all");
            selenium.waitForCondition(
                    "!selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.isRunning()",
                    Integer.toString(MAXIMUM_TOTAL_TEST_DURATION * 1000));

            time = System.currentTimeMillis() - time; // elapsed time in milis
            if (time < 1000) {
                System.out.println("Tests completed in " + time + " miliseconds.");
            } else if (time < 60000) {
                time = time / 1000;
                System.out.println("Tests completed in " + time + " seconds.");
            } else if (time < 3600000) {
                time = time / (1000 * 60);
                System.out.println("Tests completed in " + time + " minutes.");
            } else {
                time = time / (1000 * 60 * 60);
                System.out.println("Tests completed in " + time + " hours.");
            }

            //System.out.println(selenium.getEval("\n\n" + "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.XML);") + "\n\n");

            // tests are done running, get the results and display them through junit

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();

            String resultsJunitXML = selenium.getEval(
                    "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.JUnitXML);");
            String resultsYUITestXML = selenium.getEval(
                    "selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Runner.getResults(selenium.browserbot.getCurrentWindow().com.runwaysdk.test.TestFramework.getY().Test.Format.XML);");

            // Write the test output to xml
            Properties prop = new Properties();
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            InputStream stream = loader.getResourceAsStream("default/common/terraframe.properties");
            prop.load(stream);
            String basedir = prop.getProperty("local.root");

            System.out.println("Writing javascript test results to '" + basedir
                    + "/target/surefire-reports/TEST-com.runwaysdk.browser.JavascriptTestRunner-"
                    + browserDisplayName + ".xml.");
            File dir = new File(basedir + "/target/surefire-reports");
            dir.mkdirs();
            final OutputStream os = new FileOutputStream(dir.getAbsolutePath()
                    + "/TEST-com.runwaysdk.browser.JavascriptTestRunner-" + browserDisplayName + ".xml", false);
            final PrintStream printStream = new PrintStream(os);
            printStream.print(resultsJunitXML);
            printStream.close();

            InputSource in = new InputSource();
            in.setCharacterStream(new StringReader(resultsYUITestXML));
            Element doc = db.parse(in).getDocumentElement();

            NodeList suiteList = doc.getElementsByTagName("testsuite");

            if (suiteList == null || suiteList.getLength() == 0) {
                //suiteList = (NodeList)doc;
                throw new Exception("Unable to find any suites!");
            }

            String uniqueWhitespace = "";
            for (int j = 0; j < browserLoopIterationNumber; j++) {
                uniqueWhitespace = uniqueWhitespace + " ";
            }

            for (int i = 0; i < suiteList.getLength(); i++) //looping through test suites
            {
                Node n = suiteList.item(i);
                TestSuite s = new TestSuite();
                NamedNodeMap nAttrMap = n.getAttributes();

                s.setName(nAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace);

                NodeList testCaseList = ((Element) n).getElementsByTagName("testcase");
                for (int j = 0; j < testCaseList.getLength(); j++) // looping through test cases
                {
                    Node x = testCaseList.item(j);
                    NamedNodeMap xAttrMap = x.getAttributes();

                    TestSuite testCaseSuite = new TestSuite();
                    testCaseSuite.setName(xAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace);

                    NodeList testList = ((Element) x).getElementsByTagName("test");
                    for (int k = 0; k < testList.getLength(); k++) // looping through tests
                    {
                        Node testNode = testList.item(k);
                        NamedNodeMap testAttrMap = testNode.getAttributes();

                        Test t = new GeneratedTest(
                                testAttrMap.getNamedItem("name").getNodeValue() + uniqueWhitespace);

                        if (testAttrMap.getNamedItem("result").getNodeValue().equals("fail")) {
                            ((GeneratedTest) t).testFailMessage = testAttrMap.getNamedItem("message")
                                    .getNodeValue();
                        }

                        testCaseSuite.addTest(t);
                    }

                    s.addTest(testCaseSuite);
                }

                browserSuite.addTest(s);
            }

            //suite.addTest(browserSuite);
            browserLoopIterationNumber++;
        } // end try
        catch (Exception e) {
            throw (e);
        } finally {
            if (isSeleniumStarted) {
                selenium.stop();
                isSeleniumStarted = false;
            }
        }
    } // end for loop on browsers

    totalTime = System.currentTimeMillis() - totalTime; // elapsed time in milis
    if (totalTime < 1000) {
        System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " miliseconds.");
    } else if (totalTime < 60000) {
        totalTime = totalTime / 1000;
        System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " seconds.");
    } else if (totalTime < 3600000) {
        totalTime = totalTime / (1000 * 60);
        System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " minutes.");
    } else {
        totalTime = totalTime / (1000 * 60 * 60);
        System.out.println("Cross-browser javascript unit tests completed in " + totalTime + " hours.");
    }

    return suite;
}

From source file:edu.ucsb.nceas.metacattest.SubTreeTest.java

/**
 * Create a suite of tests to be run together
 */// w  w w .j a v a 2 s  .co  m
public static Test suite() {
    //Get DBConnection pool, this is only for junit test.
    //Because DBConnection is singleton class. So there is only one DBConnection
    //pool in the program
    try {
        DBConnectionPool pool = DBConnectionPool.getInstance();
    } //try
    catch (Exception e) {
        log.debug("Error in ReplicationServerList() to get" + " DBConnection pool" + e.getMessage());
    } //catch

    TestSuite suite = new TestSuite();

    try {

        //create a new subtree
        SubTree subTree = new SubTree("eml.349", "distribution1", 118214, 118223);

        //Doing test test cases
        suite.addTest(new SubTreeTest("initialize"));
        System.out.println("before adding testGetSubTreeNodeStack() into suite");
        suite.addTest(new SubTreeTest("testGetSubTreeNodeStack", subTree));
        System.out.println("here!!");

    } //try
    catch (Exception e) {
        log.debug("Error in SubTreeTest.suite: " + e.getMessage());
    } //catch
    return suite;
}

From source file:edu.lternet.pasta.dml.parser.document.DocumentDataPackageParserTest.java

/**
 * Create a suite of tests to be run together.
 *//* w ww  .j  av  a2 s .c  o m*/
public static Test suite() {
    TestSuite testSuite = new TestSuite();

    testSuite.addTest(new DocumentDataPackageParserTest("initialize"));
    testSuite.addTest(new DocumentDataPackageParserTest("testLoadAndMerge"));

    return testSuite;
}

From source file:com.networknt.light.rule.forum.ForumRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ForumRuleTest.class);
    return suite;
}

From source file:edu.ucsb.nceas.metacattest.ReplicationServerListTest.java

/**
 * Create a suite of tests to be run together
 *//*from   w  w w. ja  v  a2  s .  c  o m*/
public static Test suite() {
    //Get DBConnection pool, this is only for junit test.
    //Because DBConnection is singleton class. So there is only one DBConnection
    //pool in the program
    try {
        DBConnectionPool pool = DBConnectionPool.getInstance();
    } //try
    catch (Exception e) {
        log.debug("Error in ReplicationServerList() to get" + " DBConnection pool" + e.getMessage());
    } //catch

    TestSuite suite = new TestSuite();
    suite.addTest(new ReplicationServerListTest("initialize"));

    try {

        //Add two server into xml_replication table
        URL dev = new URL(metacatReplicationURL + "?action=servercontrol&server=dev"
                + "&subaction=add&replicate=1&datareplicate=1&hub=1");
        URL epsilon = new URL(metacatReplicationURL + "?action=servercontrol"
                + "&server=epsilon&subaction=add&replicate=0&datareplicate=1&hub=0");
        InputStream input = dev.openStream();
        input.close();
        input = epsilon.openStream();
        input.close();

        //create a new server list
        ReplicationServerList list = new ReplicationServerList();

        //Doing test test cases
        suite.addTest(new ReplicationServerListTest("testSize", list));

        suite.addTest(new ReplicationServerListTest("testServerAt0", list));
        suite.addTest(new ReplicationServerListTest("testServerAt1", list));

        suite.addTest(new ReplicationServerListTest("testNonEmptyServerList", list));

        suite.addTest(new ReplicationServerListTest("testServerIsNotInList", list));
        suite.addTest(new ReplicationServerListTest("testServerIsInList", list));

        suite.addTest(new ReplicationServerListTest("testGetLastCheckedDate", list));

        suite.addTest(new ReplicationServerListTest("testGetReplicationValueFalse", list));

        suite.addTest(new ReplicationServerListTest("testGetReplicationValueTrue", list));
        suite.addTest(new ReplicationServerListTest("testGetDataReplicationValueFalse", list));

        suite.addTest(new ReplicationServerListTest("testGetHubValueTrue", list));
        suite.addTest(new ReplicationServerListTest("testGetHubValueFalse", list));

        //Delete this two server
        URL deleteDev = new URL(
                metacatReplicationURL + "?action=servercontrol" + "&server=dev&subaction=delete");
        URL deleteEpsilon = new URL(
                metacatReplicationURL + "?action=servercontrol" + "&server=epsilon&subaction=delete");
        input = deleteDev.openStream();
        input.close();
        input = deleteEpsilon.openStream();
        input.close();
    } //try
    catch (Exception e) {
        log.debug("Error in ReplicationServerListTest.suite: " + e.getMessage());
    } //catch

    return suite;
}

From source file:com.germinus.easyconf.systemtests.ReloadTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(ReloadTest.class);
    return suite;
}

From source file:com.networknt.light.rule.menu.MenuRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(MenuRuleTest.class);
    return suite;
}

From source file:com.networknt.light.rule.comment.CommentRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(CommentRuleTest.class);
    return suite;
}

From source file:com.networknt.light.rule.post.PostRuleTest.java

public static Test suite() {
    TestSuite suite = new TestSuite();
    suite.addTestSuite(PostRuleTest.class);
    return suite;
}