incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1165132 - in /incubator/lcf/trunk: ./ framework/ framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/
Date Sun, 04 Sep 2011 23:09:46 GMT
Author: kwright
Date: Sun Sep  4 23:09:45 2011
New Revision: 1165132

URL: http://svn.apache.org/viewvc?rev=1165132&view=rev
Log:
CONNECTORS-247.  Add tests for scripting language.

Added:
    incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
  (with props)
Modified:
    incubator/lcf/trunk/CHANGES.txt
    incubator/lcf/trunk/framework/build.xml
    incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/ExpressionTest.java

Modified: incubator/lcf/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/CHANGES.txt?rev=1165132&r1=1165131&r2=1165132&view=diff
==============================================================================
--- incubator/lcf/trunk/CHANGES.txt (original)
+++ incubator/lcf/trunk/CHANGES.txt Sun Sep  4 23:09:45 2011
@@ -3,6 +3,9 @@ $Id$
 
 ======================= 0.3-dev =========================
 
+CONNECTORS-247: Add unit tests for script engine.
+(Karl Wright)
+
 CONNECTORS-246, CONNECTORS-248: Problems with MVCC model of Hsqldb
 causing query inconsistencies, claimed to be fixed in HSQLDB 2.2.5.
 (Karl Wright)

Modified: incubator/lcf/trunk/framework/build.xml
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/build.xml?rev=1165132&r1=1165131&r2=1165132&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/build.xml (original)
+++ incubator/lcf/trunk/framework/build.xml Sun Sep  4 23:09:45 2011
@@ -563,7 +563,7 @@
             <formatter type="brief" usefile="false"/>
 
             <test name="org.apache.manifoldcf.scriptengine.tests.ExpressionTest" todir="test-output"/>
-            <!-- MHL -->
+            <test name="org.apache.manifoldcf.scriptengine.tests.CommandTest" todir="test-output"/>
             
         </junit>
     </target>

Added: incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java?rev=1165132&view=auto
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
(added)
+++ incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
Sun Sep  4 23:09:45 2011
@@ -0,0 +1,125 @@
+/* $Id$ */
+
+/**
+* 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.manifoldcf.scriptengine.tests;
+
+import org.apache.manifoldcf.scriptengine.*;
+import org.junit.*;
+import static org.junit.Assert.*;
+
+public class CommandTest extends ScriptEngineBase
+{
+  @Test
+  public void setCommand()
+    throws Exception
+  {
+    VariableReference vr;
+    assertEquals(false,executeStatements("set x = 1;"));
+    vr = evaluateExpression("x");
+    assertNotNull(vr);
+    assertEquals(1,vr.resolve().getIntValue());
+  }
+
+  @Test
+  public void ifCommand()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    assertEquals(false,executeStatements("if 1==1 then set y = 1; else set y = 2; ;"));
+    vr = evaluateExpression("y");
+    assertNotNull(vr);
+    assertEquals(1,vr.resolve().getIntValue());
+
+    assertEquals(false,executeStatements("if 1==0 then set y = 1; else set y = 2; ;"));
+    vr = evaluateExpression("y");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+
+  }
+
+  @Test
+  public void whileCommand()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    assertEquals(false,executeStatements("set counter = 10; while counter > 0 do set counter
= counter - 1; ;"));
+
+    vr = evaluateExpression("counter");
+    assertNotNull(vr);
+    assertEquals(0,vr.resolve().getIntValue());
+
+    assertEquals(false,executeStatements("set flag = null; while ! isnull foo do set flag
= 1; ;"));
+
+    vr = evaluateExpression("flag");
+    assertNotNull(vr);
+    assertNull(vr.resolve());
+  }
+
+  @Test
+  public void breakCommand()
+    throws Exception
+  {
+    VariableReference vr;
+
+    assertEquals(true,executeStatements("set x = null; break; set x = 1;"));
+    
+    vr = evaluateExpression("x");
+    assertNotNull(vr);
+    assertNull(vr.resolve());
+  }
+
+  @Test
+  public void waitCommand()
+    throws Exception
+  {
+    long now = System.currentTimeMillis();
+    assertEquals(false,executeStatements("wait 1000;"));
+    assertEquals(true,(now + 1000L) <= System.currentTimeMillis());
+  }
+
+  @Test
+  public void errorCommand()
+    throws Exception
+  {
+    boolean sawException = false;
+    try
+    {
+      executeStatements("error '123456';");
+    }
+    catch (ScriptException e)
+    {
+      if (e.getMessage().indexOf("123456") != -1)
+        sawException = true;
+      else
+        throw e;
+    }
+    assertEquals(true,sawException);
+  }
+
+  @Test
+  public void printCommand()
+    throws Exception
+  {
+    assertEquals(false,executeStatements("print 'hello';"));
+  }
+  
+  // MHL for GET, PUT, DELETE and POST commands, which need a jetty instance to work against.
+  
+}
\ No newline at end of file

Propchange: incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/CommandTest.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/ExpressionTest.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/ExpressionTest.java?rev=1165132&r1=1165131&r2=1165132&view=diff
==============================================================================
--- incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/ExpressionTest.java
(original)
+++ incubator/lcf/trunk/framework/script-engine/src/test/java/org/apache/manifoldcf/scriptengine/tests/ExpressionTest.java
Sun Sep  4 23:09:45 2011
@@ -34,110 +34,539 @@ public class ExpressionTest extends Scri
     // Binary +
     vr = evaluateExpression("1+2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),3);
+    assertEquals(3,vr.resolve().getIntValue());
     
     // Binary -
     vr = evaluateExpression("1-2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),-1);
+    assertEquals(-1,vr.resolve().getIntValue());
 
     // Binary *
     vr = evaluateExpression("2*3");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),6);
+    assertEquals(6,vr.resolve().getIntValue());
 
     // Binary /
     vr = evaluateExpression("3/2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),1);
+    assertEquals(1,vr.resolve().getIntValue());
 
     // Unary -
     vr = evaluateExpression("-2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),-2);
+    assertEquals(-2,vr.resolve().getIntValue());
 
     // Binary &
     vr = evaluateExpression("1&5");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),1);
+    assertEquals(1,vr.resolve().getIntValue());
 
     // Binary |
     vr = evaluateExpression("1|2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),3);
+    assertEquals(3,vr.resolve().getIntValue());
 
     // Unary !
     vr = evaluateExpression("!2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),2^2);
+    assertEquals(2^2,vr.resolve().getIntValue());
 
     // >
     vr = evaluateExpression("1>1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("2>1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // >=
     vr = evaluateExpression("0>=1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("1>=1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // <
     vr = evaluateExpression("2<2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("1<2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // <=
     vr = evaluateExpression("2<=1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("1<=1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // ==
     vr = evaluateExpression("1==2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("1==1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // !=
     vr = evaluateExpression("1!=1");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),false);
+    assertEquals(false,vr.resolve().getBooleanValue());
     vr = evaluateExpression("1!=2");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getBooleanValue(),true);
+    assertEquals(true,vr.resolve().getBooleanValue());
 
     // Attributes
     vr = evaluateExpression("2 .__int__");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getIntValue(),2);
+    assertEquals(2,vr.resolve().getIntValue());
     vr = evaluateExpression("2 .__string__");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getStringValue(),"2");
+    assertEquals("2",vr.resolve().getStringValue());
     vr = evaluateExpression("2 .__float__");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getDoubleValue(),2.0,0.0);
+    assertEquals(2.0,vr.resolve().getDoubleValue(),0.0);
     vr = evaluateExpression("2 .__script__");
     assertNotNull(vr);
-    assertEquals(vr.resolve().getStringValue(),"2");
+    assertEquals("2",vr.resolve().getStringValue());
 
     // Various values
-    assertEquals(new VariableInt(2).getIntValue(),2);
-    assertEquals(new VariableInt(2).getStringValue(),"2");
-    assertEquals(new VariableInt(2).getDoubleValue(),2.0,0.0);
+    assertEquals(2,new VariableInt(2).getIntValue());
+    assertEquals("2",new VariableInt(2).getStringValue());
+    assertEquals(2.0,new VariableInt(2).getDoubleValue(),0.0);
 
   }
 
+  @Test
+  public void basicFloatOperations()
+    throws Exception
+  {
+    VariableReference vr;
+
+    // Binary +
+    vr = evaluateExpression("1.0+2.0");
+    assertNotNull(vr);
+    assertEquals(3.0,vr.resolve().getDoubleValue(),0.0);
+    
+    // Binary -
+    vr = evaluateExpression("1.0-2.0");
+    assertNotNull(vr);
+    assertEquals(-1.0,vr.resolve().getDoubleValue(),0.0);
+
+    // Binary *
+    vr = evaluateExpression("2.0*3.0");
+    assertNotNull(vr);
+    assertEquals(6.0,vr.resolve().getDoubleValue(),0.0);
+
+    // Binary /
+    vr = evaluateExpression("3.0/2.0");
+    assertNotNull(vr);
+    assertEquals(1.5,vr.resolve().getDoubleValue(),0.0);
+
+    // Unary -
+    vr = evaluateExpression("-2.0");
+    assertNotNull(vr);
+    assertEquals(-2.0,vr.resolve().getDoubleValue(),0.0);
+
+    // >
+    vr = evaluateExpression("1.0>1.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("2.0>1.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // >=
+    vr = evaluateExpression("0.0>=1.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("1.0>=1.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // <
+    vr = evaluateExpression("2.0<2.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("1.0<2.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // <=
+    vr = evaluateExpression("2.0<=1.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("1.0<=1.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // ==
+    vr = evaluateExpression("1.0==2.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("1.0==1.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // !=
+    vr = evaluateExpression("1.0!=1.0");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("1.0!=2.0");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Attributes
+    vr = evaluateExpression("2.0 .__int__");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+    vr = evaluateExpression("2.0 .__string__");
+    assertNotNull(vr);
+    assertEquals("2.0",vr.resolve().getStringValue());
+    vr = evaluateExpression("2.0 .__float__");
+    assertNotNull(vr);
+    assertEquals(2.0,vr.resolve().getDoubleValue(),0.0);
+    vr = evaluateExpression("2.0 .__script__");
+    assertNotNull(vr);
+    assertEquals("2.0",vr.resolve().getStringValue());
+
+    // Various values
+    assertEquals(2,new VariableFloat(2.0).getIntValue());
+    assertEquals("2.0",new VariableFloat(2.0).getStringValue());
+    assertEquals(2.0,new VariableFloat(2.0).getDoubleValue(),0.0);
+
+  }
+
+  @Test
+  public void basicBooleanOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Binary &
+    vr = evaluateExpression("true&false");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+
+    // Binary |
+    vr = evaluateExpression("true|false");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Binary &&
+    vr = evaluateExpression("true&&false");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+
+    // Binary ||
+    vr = evaluateExpression("true||false");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Unary !
+    vr = evaluateExpression("!true");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+
+    // ==
+    vr = evaluateExpression("true==false");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("true==true");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // !=
+    vr = evaluateExpression("true!=true");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("true!=false");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Attributes
+    vr = evaluateExpression("true .__script__");
+    assertNotNull(vr);
+    assertEquals("true",vr.resolve().getStringValue());
+
+  }
+
+  @Test
+  public void basicStringOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Binary +
+    vr = evaluateExpression("'1'+'2'");
+    assertNotNull(vr);
+    assertEquals("12",vr.resolve().getStringValue());
+    
+    // ==
+    vr = evaluateExpression("'1'=='2'");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("'1'=='1'");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // !=
+    vr = evaluateExpression("'1'!='1'");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("'1'!='2'");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Attributes
+    vr = evaluateExpression("'2'.__int__");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+    vr = evaluateExpression("'2'.__string__");
+    assertNotNull(vr);
+    assertEquals("2",vr.resolve().getStringValue());
+    vr = evaluateExpression("'2'.__float__");
+    assertNotNull(vr);
+    assertEquals(2.0,vr.resolve().getDoubleValue(),0.0);
+    vr = evaluateExpression("'2'.__script__");
+    assertNotNull(vr);
+    assertEquals("\"2\"",vr.resolve().getStringValue());
+
+    // Various values
+    assertEquals(2,new VariableString("2").getIntValue());
+    assertEquals("2",new VariableString("2").getStringValue());
+    assertEquals(2.0,new VariableString("2").getDoubleValue(),0.0);
+
+  }
+
+  @Test
+  public void basicURLOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Binary +
+    vr = evaluateExpression("(new url 'http://localhost:8345/mcf-api-service/json') + 'jobs'
+ '123'");
+    assertNotNull(vr);
+    assertEquals("http://localhost:8345/mcf-api-service/json/jobs/123",vr.resolve().getStringValue());
+    
+    // ==
+    vr = evaluateExpression("(new url 'hello')==(new url 'there')");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("(new url 'hello')==(new url 'hello')");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // !=
+    vr = evaluateExpression("(new url 'hello')!=(new url 'hello')");
+    assertNotNull(vr);
+    assertEquals(false,vr.resolve().getBooleanValue());
+    vr = evaluateExpression("(new url 'hello')!=(new url 'there')");
+    assertNotNull(vr);
+    assertEquals(true,vr.resolve().getBooleanValue());
+
+    // Attributes
+    vr = evaluateExpression("((new url 'abc') + 'def ghi').__string__");
+    assertNotNull(vr);
+    assertEquals("abc/def%20ghi",vr.resolve().getStringValue());
+    vr = evaluateExpression("(new url 'abc').__script__");
+    assertNotNull(vr);
+    assertEquals("\"abc\"",vr.resolve().getStringValue());
+
+    // Various values
+    assertEquals("abc",new VariableURL("abc").getStringValue());
+
+    // Connectionname objecfs
+    vr = evaluateExpression("((new url 'hello') + (new connectionname 'there/guys.')).__string__");
+    assertNotNull(vr);
+    assertEquals("hello/there.%2Bguys..",vr.resolve().getStringValue());
+
+  }
+
+  @Test
+  public void basicArrayOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // initializer and subscript
+    assertEquals(false,executeStatements("set x = [1,'2',3];")); 
+
+    vr = evaluateExpression("x[2]");
+    assertNotNull(vr);
+    assertEquals(3,vr.resolve().getIntValue());
+
+    // Attributes
+    vr = evaluateExpression("x.__script__");
+    assertNotNull(vr);
+    assertEquals("[ 1, \"2\", 3 ]",vr.resolve().getStringValue());
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(3,vr.resolve().getIntValue());
+
+    // Do inserts
+    assertEquals(false,executeStatements("insert 'tail' into x;"));
+    vr = evaluateExpression("x[3]");
+    assertNotNull(vr);
+    assertEquals("tail",vr.resolve().getStringValue());
+    assertEquals(false,executeStatements("insert 'head' into x at 0;"));
+    vr = evaluateExpression("x[1]");
+    assertNotNull(vr);
+    assertEquals(1,vr.resolve().getIntValue());
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(5,vr.resolve().getIntValue());
+    
+    // Do deletes
+    assertEquals(false,executeStatements("remove 1 from x;"));
+    vr = evaluateExpression("x[1]");
+    assertNotNull(vr);
+    assertEquals("2",vr.resolve().getStringValue());
+    vr = evaluateExpression("x[0]");
+    assertNotNull(vr);
+    assertEquals("head",vr.resolve().getStringValue());
+
+  }
+
+  @Test
+  public void basicDictOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Set up
+    assertEquals(false,executeStatements("set x = new dictionary; set x['a'] = 1; set x['b']
= 2;"));
+    vr = evaluateExpression("x['a']");
+    assertNotNull(vr);
+    assertEquals(1,vr.resolve().getIntValue());
+
+    // Attributes
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+
+  }
+
+  @Test
+  public void basicConfigurationnodeOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Set up
+    assertEquals(false,executeStatements("set x = << 'type' : 'value' : 'attr1' = 'av1',
'attr2' = 'av2' : << 'child1' : 'cv1' : : >>, << 'child2' : 'cv2' : : >>
>>;")); 
+
+    // Subscripts
+    vr = evaluateExpression("x[0].__type__");
+    assertNotNull(vr);
+    assertEquals("child1",vr.resolve().getStringValue());
+    vr = evaluateExpression("x[0].__value__");
+    assertNotNull(vr);
+    assertEquals("cv1",vr.resolve().getStringValue());
+
+    // Size
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+    
+    // Dict
+    vr = evaluateExpression("x.__dict__['child1'].__value__");
+    assertNotNull(vr);
+    assertEquals("cv1",vr.resolve().getStringValue());
+
+    // User attributes
+    vr = evaluateExpression("x.attr1");
+    assertNotNull(vr);
+    assertEquals("av1",vr.resolve().getStringValue());
+    vr = evaluateExpression("x.attr2");
+    assertNotNull(vr);
+    assertEquals("av2",vr.resolve().getStringValue());
+
+    // Do inserts
+    assertEquals(false,executeStatements("insert << 'child3' : 'cv3' : : >> into
x;"));
+    vr = evaluateExpression("x[2].__type__");
+    assertNotNull(vr);
+    assertEquals("child3",vr.resolve().getStringValue());
+    assertEquals(false,executeStatements("insert << 'childn1' : 'cvn1' : : >>
into x at 0;"));
+    vr = evaluateExpression("x[1].__type__");
+    assertNotNull(vr);
+    assertEquals("child1",vr.resolve().getStringValue());
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(4,vr.resolve().getIntValue());
+    
+    // Do deletes
+    assertEquals(false,executeStatements("remove 1 from x;"));
+    vr = evaluateExpression("x[1].__type__");
+    assertNotNull(vr);
+    assertEquals("child2",vr.resolve().getStringValue());
+    vr = evaluateExpression("x[0].__type__");
+    assertNotNull(vr);
+    assertEquals("childn1",vr.resolve().getStringValue());
+
+    // Script value
+    vr = evaluateExpression("x.__script__");
+    assertNotNull(vr);
+    assertEquals("<< \"type\" : \"value\" : \"attr1\"=\"av1\", \"attr2\"=\"av2\" :
<< \"childn1\" : \"cvn1\" :  :  >>, << \"child2\" : \"cv2\" :  :  >>,
<< \"child3\" : \"cv3\" :  :  >> >>",vr.resolve().getStringValue());
+  }
+
+  @Test
+  public void basicConfigurationOperations()
+    throws Exception
+  {
+    VariableReference vr;
+    
+    // Set up
+    assertEquals(false,executeStatements("set x = {<< 'child1' : 'cv1' : : >>,
<< 'child2' : 'cv2' : : >>};")); 
+
+    // Subscripts
+    vr = evaluateExpression("x[0].__type__");
+    assertNotNull(vr);
+    assertEquals("child1",vr.resolve().getStringValue());
+    vr = evaluateExpression("x[0].__value__");
+    assertNotNull(vr);
+    assertEquals("cv1",vr.resolve().getStringValue());
+
+    // Size
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(2,vr.resolve().getIntValue());
+    
+    // Dict
+    vr = evaluateExpression("x.__dict__['child1'].__value__");
+    assertNotNull(vr);
+    assertEquals("cv1",vr.resolve().getStringValue());
+
+    // Do inserts
+    assertEquals(false,executeStatements("insert << 'child3' : 'cv3' : : >> into
x;"));
+    vr = evaluateExpression("x[2].__type__");
+    assertNotNull(vr);
+    assertEquals("child3",vr.resolve().getStringValue());
+    assertEquals(false,executeStatements("insert << 'childn1' : 'cvn1' : : >>
into x at 0;"));
+    vr = evaluateExpression("x[1].__type__");
+    assertNotNull(vr);
+    assertEquals("child1",vr.resolve().getStringValue());
+    vr = evaluateExpression("x.__size__");
+    assertNotNull(vr);
+    assertEquals(4,vr.resolve().getIntValue());
+    
+    // Do deletes
+    assertEquals(false,executeStatements("remove 1 from x;"));
+    vr = evaluateExpression("x[1].__type__");
+    assertNotNull(vr);
+    assertEquals("child2",vr.resolve().getStringValue());
+    vr = evaluateExpression("x[0].__type__");
+    assertNotNull(vr);
+    assertEquals("childn1",vr.resolve().getStringValue());
+
+    // Script value
+    vr = evaluateExpression("x.__script__");
+    assertNotNull(vr);
+    assertEquals("{ << \"childn1\" : \"cvn1\" :  :  >>, << \"child2\" :
\"cv2\" :  :  >>, << \"child3\" : \"cv3\" :  :  >> }",vr.resolve().getStringValue());
+  }
+
 }



Mime
View raw message