Two more test suites
git-svn-id: https://svn.apache.org/repos/asf/jakarta/bsf/trunk@758403 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java b/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java
new file mode 100644
index 0000000..4e76dd2
--- /dev/null
+++ b/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleBindingsTest.java
@@ -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"));
+ }
+}
diff --git a/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java b/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java
new file mode 100644
index 0000000..2015eb6
--- /dev/null
+++ b/bsf3/bsf-api/src/test/java/org/apache/bsf/SimpleScriptContextTest.java
@@ -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) {
+ }
+ }
+}