1 package org.sapia.regis.forms; 2 3 import java.util.HashMap ; 4 import java.util.Map ; 5 6 import org.sapia.regis.impl.NodeImpl; 7 import org.sapia.regis.type.BuiltinTypes; 8 9 import junit.framework.TestCase; 10 11 public class FormTest extends TestCase { 12 13 Form f; 14 15 public FormTest(String arg0) { 16 super(arg0); 17 } 18 19 protected void setUp() throws Exception { 20 f = new Form("form"); 21 } 22 23 public void testCreateField(){ 24 f.createField(BuiltinTypes.INT_TYPE, "test"); 25 try{ 26 f.createField(BuiltinTypes.INT_TYPE, "test"); 27 fail("Field already exists"); 28 }catch(IllegalArgumentException e){} 29 } 30 31 public void testGetContainsField(){ 32 f.createField(BuiltinTypes.INT_TYPE, "test"); 33 super.assertTrue(f.getField("test") != null); 34 super.assertTrue(f.containsField("test")); 35 36 } 37 38 public void testGetFields(){ 39 Field f1 = f.createField(BuiltinTypes.INT_TYPE, "field1"); 40 Field f2 = f.createField(BuiltinTypes.INT_TYPE, "field2"); 41 assertEquals(f.getFields().get(0), f1); 42 assertEquals(f.getFields().get(1), f2); 43 } 44 45 public void testAssign(){ 46 NodeImpl node = new NodeImpl(); 47 f.createField(BuiltinTypes.INT_TYPE, "intField"); 48 f.createField(BuiltinTypes.BOOLEAN_TYPE, "booleanField"); 49 Map values = new HashMap (); 50 values.put("intField", "100"); 51 values.put("booleanField", "true"); 52 f.assign(node, values); 53 assertEquals(new Integer (node.getProperty("intField").asInt()), new Integer (100)); 54 assertEquals(new Boolean (node.getProperty("booleanField").asBoolean()), new Boolean (true)); 55 } 56 57 } 58 | Popular Tags |