blob: 28b260ceac8c49d191fa9f3685cd79c7adaf3993 [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.bsf;
import junit.framework.Test;
import junit.framework.TestResult;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import org.apache.bsf.engines.JaclTest;
import org.apache.bsf.engines.JavascriptTest;
import org.apache.bsf.engines.JythonTest;
import org.apache.bsf.engines.NetrexxTest;
import org.apache.bsf.util.EngineUtilsTest;
import org.apache.bsf.util.IOUtilsTest;
import org.apache.bsf.util.StringUtilsTest;
/**
* Primary test class and testing front end for BSF.
* @author Victor J. Orlikowski <vjo@us.ibm.com>
*/
public class BSFTest extends BSFEngineTestTmpl {
public static String[] testNames;
public BSFTest(String name) {
super(name);
}
public static void main(String args[]) {
TestRunner runner = new TestRunner();
TestSuite suite = (TestSuite) suite();
TestResult results;
for (int i = 0; i < suite.testCount(); i++) {
System.out.print(testNames[i]);
results = runner.doRun(suite.testAt(i), false);
System.out.println("Results: " + results.runCount() +
" tests run, " + results.failureCount() +
" failures, " + results.errorCount() +
" errors.");
System.out.print("\n----------------------------------------\n");
}
}
public static Test suite() {
/*
* Please add testcases here as needed.
*/
TestSuite suite = new TestSuite();
testNames = new String [8];
suite.addTestSuite(BSFTest.class);
testNames[0] = "BSFManager Base Tests";
suite.addTestSuite(JaclTest.class);
testNames[1] = "Jacl Engine Tests";
suite.addTestSuite(JavascriptTest.class);
testNames[2] = "Rhino Engine Tests";
suite.addTestSuite(JythonTest.class);
testNames[3] = "Jython Engine Tests";
suite.addTestSuite(NetrexxTest.class);
testNames[4] = "NetRexx Engine Tests";
suite.addTestSuite(StringUtilsTest.class);
testNames[5] = "StringUtils Test";
suite.addTestSuite(IOUtilsTest.class);
testNames[6] = "IOUtils Test";
suite.addTestSuite(EngineUtilsTest.class);
testNames[7] = "EngineUtils Test";
return suite;
}
public void setUp() {
super.setUp();
BSFManager.registerScriptingEngine("fakeEngine",
FakeEngine.class.getName(),
new String[] { "fakeEng", "fE" });
}
public void testRegisterEngine() {
assertTrue(bsfManager.isLanguageRegistered("fakeEngine"));
}
public void testGetLangFromFileName() {
try {
assertEquals("fakeEngine",
BSFManager.getLangFromFilename("Test.fE"));
}
catch (Exception e) {
fail(failMessage("getLangFromFilename() test failed", e));
}
}
public void testExec() {
try {
bsfManager.exec("fakeEngine", "Test.fE", 0, 0, "Fake syntax");
}
catch (Exception e) {
fail(failMessage("exec() test failed", e));
}
assertEquals("PASSED", getTmpOutStr());
}
public void testEval() {
Boolean retval = Boolean.FALSE;
try {
retval = (Boolean) bsfManager.eval("fakeEngine",
"Test.fE", 0, 0,
"Fake Syntax");
}
catch (Exception e) {
fail(failMessage("eval() test failed", e));
}
assertTrue(retval.booleanValue());
}
public void testIexec() {
try {
bsfManager.iexec("fakeEngine", "Test.fE", 0, 0, "Fake syntax");
}
catch (Exception e) {
fail(failMessage("iexec() test failed", e));
}
assertEquals("PASSED", getTmpOutStr());
}
public void testDeclareBean() {
try {
bsfManager.declareBean("foo", new Integer(1), Integer.class);
}
catch (Exception e) {
fail(failMessage("declareBean() test failed", e));
}
assertEquals(new Integer(1), (Integer) bsfManager.lookupBean("foo"));
}
public void testUndeclareBean() {
try {
bsfManager.declareBean("foo", new Integer(1), Integer.class);
bsfManager.undeclareBean("foo");
}
catch (Exception e) {
fail(failMessage("undeclareBean() test failed", e));
}
assertNull(bsfManager.lookupBean("foo"));
}
public void testTerminate() throws Exception {
try {
bsfManager.loadScriptingEngine("fakeEngine");
bsfManager.terminate();
}
catch (Exception e) {
fail(failMessage("terminate() test failed", e));
}
assertEquals("PASSED", getTmpOutStr());
}
}