You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bsf-dev@jakarta.apache.org by se...@apache.org on 2009/03/25 19:47:25 UTC

svn commit: r758403 - in /jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf: SimpleBindingsTest.java SimpleScriptContextTest.java

Author: sebb
Date: Wed Mar 25 18:47:18 2009
New Revision: 758403

URL: http://svn.apache.org/viewvc?rev=758403&view=rev
Log:
Two more test suites

Added:
    jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java   (with props)
    jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java   (with props)

Added: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java?rev=758403&view=auto
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java (added)
+++ jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java Wed Mar 25 18:47:18 2009
@@ -0,0 +1,153 @@
+/*
+ * 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 java.util.HashMap;
+import java.util.Map;
+
+import javax.script.*;
+
+import junit.framework.TestCase;
+
+public class SimpleBindingsTest extends TestCase {
+
+    Bindings bindings;
+    
+    public void setUp(){
+        bindings = new SimpleBindings();
+    }
+    
+    public void testConstruct(){
+        assertNotNull(bindings);
+        try {
+            new SimpleBindings(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        new SimpleBindings(new HashMap());
+    }
+    
+    
+    
+    public void testBadParams(){
+        try {
+            bindings.containsKey(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            bindings.containsKey("");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            bindings.containsKey(Boolean.FALSE);
+            fail("Expected ClassCastException");
+        } catch (ClassCastException e) {
+        }
+
+        try {
+            bindings.get(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            bindings.get("");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            bindings.get(Boolean.FALSE);
+            fail("Expected ClassCastException");
+        } catch (ClassCastException e) {
+        }
+
+
+        try {
+            bindings.put(null, null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            bindings.put("", null);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+//        try {
+//            bindings.put(Boolean.FALSE, null);
+//            fail("Expected ClassCastException");
+//        } catch (ClassCastException e) {
+//        }
+
+        try {
+            bindings.remove(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            bindings.remove("");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            bindings.remove(Boolean.FALSE);
+            fail("Expected ClassCastException");
+        } catch (ClassCastException e) {
+        }
+
+        try {
+            bindings.putAll(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            Map map = new HashMap();
+            map.put("OK", null);
+            map.put("", null);
+            bindings.putAll(map);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            Map map = new HashMap();
+            map.put("OK", null);
+            map.put(Boolean.FALSE, null);
+            bindings.putAll(map);
+            bindings.remove(Boolean.FALSE);
+            fail("Expected ClassCastException");
+        } catch (ClassCastException e) {
+        }
+    }
+    
+    // Most of these are standard Map tests
+    public void testValid(){
+        assertFalse(bindings.containsKey("key"));
+        assertNull(bindings.get("key"));
+        bindings.put("key", Boolean.FALSE);        
+        assertNotNull(bindings.get("key"));
+        assertTrue(bindings.containsKey("key"));
+        assertFalse(bindings.containsKey("null"));
+        bindings.put("null", null);
+        assertTrue(bindings.containsKey("null"));
+        assertNull(bindings.get("null"));
+        assertNull(bindings.remove("null"));
+        assertNotNull(bindings.remove("key"));
+        assertNull(bindings.remove("key"));
+    }
+}

Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java
URL: http://svn.apache.org/viewvc/jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java?rev=758403&view=auto
==============================================================================
--- jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java (added)
+++ jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java Wed Mar 25 18:47:18 2009
@@ -0,0 +1,130 @@
+/*
+ * 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 java.util.List;
+
+import javax.script.*;
+
+import junit.framework.TestCase;
+
+public class SimpleScriptContextTest extends TestCase {
+
+    ScriptContext context;
+    
+    public void setUp(){
+        context = new SimpleScriptContext();
+    }
+    
+    public void testCtor(){
+        assertNotNull(context);
+    }
+    
+    public void testInvalidGetAttribute(){
+        try {
+            context.getAttribute(null);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            context.getAttribute("");
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            context.getAttribute(null, ScriptContext.ENGINE_SCOPE);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            context.getAttribute("", 0);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            context.getAttribute("OK", 0);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            context.getAttribute(null, ScriptContext.ENGINE_SCOPE);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            context.getAttribute("", ScriptContext.ENGINE_SCOPE);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+    }
+    
+    public void testInvalidRemoveAttribute(){
+        try {
+            context.removeAttribute(null, ScriptContext.ENGINE_SCOPE);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            context.removeAttribute("", 0);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            context.removeAttribute("OK", 0);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        try {
+            context.removeAttribute(null, ScriptContext.ENGINE_SCOPE);
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+        try {
+            context.removeAttribute("", ScriptContext.ENGINE_SCOPE);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }        
+    }
+    public void testBindings(){
+        try {
+            context.getBindings(0);
+            fail("Expected IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+        }
+        assertNotNull(context.getBindings(ScriptContext.ENGINE_SCOPE));
+        assertNull(context.getBindings(ScriptContext.GLOBAL_SCOPE)); // no global default
+        context.setBindings(null, ScriptContext.GLOBAL_SCOPE); // OK
+        try {
+            context.setBindings(null, ScriptContext.ENGINE_SCOPE); // Not OK
+            fail("Expected NullPointerException");
+        } catch (NullPointerException e) {
+        }
+    }
+    
+    public void testScopes(){
+        List l = (List) context.getScopes();
+        assertNotNull(l);
+        assertTrue(l.size() >=2);
+        try {
+            l.remove(0);
+            fail("Expected UnsupportedOperationException");
+        } catch (UnsupportedOperationException e) {
+        }
+    }
+}

Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/bsf/trunk/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



---------------------------------------------------------------------
To unsubscribe, e-mail: bsf-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bsf-dev-help@jakarta.apache.org