view src/org/RhinoTests/ScriptContextTest.java @ 368:7d807b490b62 draft default tip

Seven new tests added into ScriptContextTest.
author ptisnovs
date Tue, 27 May 2014 08:54:25 +0200
parents ac41c65e3bb9
children
line wrap: on
line source

/*
  Rhino test framework

   Copyright (C) 2011, 2012, 2013, 2014  Red Hat

This file is part of IcedTea.

IcedTea is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

IcedTea is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with IcedTea; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version.
*/

package org.RhinoTests;

import java.util.HashMap;

import javax.script.Bindings;
import javax.script.SimpleBindings;
import javax.script.ScriptContext;
import javax.script.SimpleScriptContext;



/**
 * Basic ScriptContext test suite. Following tests checks the interface
 * javax.script.ScriptContext.
 *
 * @author Pavel Tisnovsky
 */
public class ScriptContextTest extends BaseRhinoTest {

    /**
     * Many methods accepts ScriptContext.GLOBAL_SCOPE or ScriptContext.ENGINE_SCOPE
     * as one integer parameters. Let's see how those methods works with different value.
     */
    private final static Integer INVALID_SCOPE = 42;

    @Override
    protected void setUp(String[] args) {
        // this block could be empty
        return;
    }

    @Override
    protected void tearDown() {
        // this block could be empty
        return;
    }

    /**
     * Test for toString() method.
     */
    protected void testToString() {
        // tested object
        Object object = new SimpleScriptContext();

        // call the toString() method
        String string = object.toString();

        assertTrue(string != null, "toString() method returned null!");
        assertTrue(string.startsWith("javax.script.SimpleScriptContext"), "bad toString() return value " + string);
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute1() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "value", ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute2() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "", ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute3() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", null, ScriptContext.ENGINE_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute4() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "value", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"value\", ScriptContext.ENGINE_SCOPE.) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute5() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute6() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", null, ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute7() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "value", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"value\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute8() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "", ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"\", ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute9() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, null, ScriptContext.ENGINE_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, null, ScriptContext.ENGINE_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute10() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "value", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute11() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute12() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", null, ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute13() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "value", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute14() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute15() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", null, ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute16() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "value", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute17() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute18() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, null, ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute19() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", "value", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute20() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", "", ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute21() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", null, ScriptContext.GLOBAL_SCOPE);
        }
        catch (Exception e) {
            e.printStackTrace();
            throw new AssertionError(e.getMessage());
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute22() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", "value", ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"value\", ScriptContext.GLOBAL_SCOPE.) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute23() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", "", ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", \"\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute24() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", null, ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(\"\", null, ScriptContext.GLOBAL_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute25() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, "value", ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"value\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute26() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, "", ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, \"\", ScriptContext.GLOBAL_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute27() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, null, ScriptContext.GLOBAL_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute(null, null, ScriptContext.GLOBAL_SCOPE) does not throw any exception");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute28() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute29() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute30() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("name", null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute31() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute32() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute33() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute("", null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute34() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute35() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute36() {
        // tested object
        ScriptContext object = new SimpleScriptContext();
        try {
            object.setAttribute(null, null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute37() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute38() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute39() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("name", null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute40() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute41() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute42() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute("", null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute43() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, "value", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute44() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, "", INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Test for method SimpleScriptContext.setAttribute().
     */
    protected void testSetAttribute45() {
        // tested object
        ScriptContext object = new SimpleScriptContext();

        // setup global scope
        Bindings bindings = new SimpleBindings(new HashMap<String, Object>());
        object.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);

        try {
            object.setAttribute(null, null, INVALID_SCOPE);
            throw new AssertionError("ScriptContext.setAttribute() does not throw any exception for invalid scope");
        }
        catch (Exception e) {
            // expected exception
        }
    }

    /**
     * Entry point to this test case.
     *
     * @param args parameters passed from command line
     */
    public static void main(String[] args) {
        new ScriptContextTest().doTests(args);
    }

}