KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > regis > bean > NodeInvocationHandlerTest


1 package org.sapia.regis.bean;
2
3 import java.net.Socket JavaDoc;
4
5 import org.sapia.regis.SessionUtil;
6 import org.sapia.regis.impl.NodeImpl;
7 import org.sapia.regis.local.LocalRegistry;
8
9 import junit.framework.TestCase;
10
11 public class NodeInvocationHandlerTest extends TestCase {
12   
13   public NodeInvocationHandlerTest(String JavaDoc name){
14     super(name);
15   }
16
17   public void testGetValues(){
18     LocalRegistry reg = new LocalRegistry();
19     NodeImpl node = new NodeImpl(null, "");
20     node.setProperty("booleanValue", "true");
21     node.setProperty("intValue", "10");
22     node.setProperty("longValue", "100");
23     node.setProperty("floatValue", "20.2");
24     node.setProperty("doubleValue", "200.2");
25     
26     NodeInvocationHandler handler = new NodeInvocationHandler(reg, node, Config.class);
27     
28     Config conf = (Config)BeanFactory.newBeanInstanceFor(node, Config.class, handler);
29     
30     super.assertEquals(true, conf.getBooleanValue());
31     super.assertEquals(10, conf.getIntValue());
32     super.assertEquals(100, conf.getLongValue());
33     super.assertTrue(20.2f == conf.getFloatValue());
34     super.assertTrue(200.2d == conf.getDoubleValue());
35   }
36   
37   public void testWithSessionUtil(){
38     LocalRegistry reg = new LocalRegistry();
39     NodeImpl node = new NodeImpl(null, "");
40     node.setProperty("booleanValue", "true");
41     node.setProperty("intValue", "10");
42     node.setProperty("longValue", "100");
43     node.setProperty("floatValue", "20.2");
44     node.setProperty("doubleValue", "200.2");
45     
46     NodeInvocationHandler handler = new NodeInvocationHandler(reg, node, Config.class);
47     
48     Config conf = (Config)BeanFactory.newBeanInstanceFor(node, Config.class, handler);
49     
50     SessionUtil.createSessionFor(conf);
51     
52     super.assertEquals(true, conf.getBooleanValue());
53     super.assertEquals(10, conf.getIntValue());
54     super.assertEquals(100, conf.getLongValue());
55     super.assertTrue(20.2f == conf.getFloatValue());
56     super.assertTrue(200.2d == conf.getDoubleValue());
57     
58     SessionUtil.close();
59     
60   }
61   
62   public void testInvalidConfig(){
63     LocalRegistry reg = new LocalRegistry();
64     NodeImpl node = new NodeImpl(null, "");
65     node.setProperty("socket", "1099");
66
67     try{
68       new NodeInvocationHandler(reg, node, InvalidConfig.class);
69       fail("Socket property should not be processed");
70     }catch(InvalidReturnTypeException e){
71       //ok
72
}
73   }
74   
75   public void testMissingProperty(){
76     LocalRegistry reg = new LocalRegistry();
77     NodeImpl node = new NodeImpl(null, "");
78     
79     NodeInvocationHandler handler = new NodeInvocationHandler(reg, node, Config.class);
80     Config conf = (Config)BeanFactory.newBeanInstanceFor(node, Config.class, handler);
81     try{
82       conf.getBooleanValue();
83       fail("property should not be returned");
84     }catch(IllegalStateException JavaDoc e){
85       //ok
86
}
87   }
88   
89   public static interface Config{
90     
91     public boolean getBooleanValue();
92     
93     public int getIntValue();
94     
95     public long getLongValue();
96
97     public float getFloatValue();
98     
99     public double getDoubleValue();
100     
101   }
102   
103   public static interface InvalidConfig{
104
105     public Socket JavaDoc getSocket();
106     
107   }
108 }
109
Popular Tags