KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > dynamic > StringXPathBasedConfigItemTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.dynamic;
5
6 import com.tc.config.schema.MockXmlObject;
7
8 public class StringXPathBasedConfigItemTest extends XPathBasedConfigItemTestBase {
9
10   private class SubBean extends MockXmlObject {
11     public String JavaDoc getStringValue() {
12       return currentValue;
13     }
14   }
15
16   private class DefaultBean extends MockXmlObject {
17     private final String JavaDoc value;
18
19     public DefaultBean(String JavaDoc value) {
20       this.value = value;
21     }
22
23     public String JavaDoc getStringValue() {
24       return value;
25     }
26   }
27
28   private String JavaDoc currentValue;
29
30   protected MockXmlObject createSubBean() throws Exception JavaDoc {
31     return new SubBean();
32   }
33
34   public void setUp() throws Exception JavaDoc {
35     super.setUp();
36
37     this.currentValue = "hi there";
38   }
39
40   public void testNoDefault() throws Exception JavaDoc {
41     StringXPathBasedConfigItem item = new StringXPathBasedConfigItem(context, xpath);
42
43     assertEquals("hi there", item.getString());
44     assertEquals("hi there", item.getObject());
45
46     currentValue = null;
47     item = new StringXPathBasedConfigItem(context, xpath);
48
49     assertNull(item.getString());
50     assertNull(item.getObject());
51   }
52
53   public void testDefault() throws Exception JavaDoc {
54     context.setReturnedHasDefaultFor(true);
55     context.setReturnedDefaultFor(new DefaultBean("the default"));
56     StringXPathBasedConfigItem item = new StringXPathBasedConfigItem(context, xpath);
57
58     assertEquals("hi there", item.getString());
59     assertEquals("hi there", item.getObject());
60
61     currentValue = null;
62     item = new StringXPathBasedConfigItem(context, xpath);
63
64     assertEquals("the default", item.getString());
65     assertEquals("the default", item.getObject());
66   }
67
68 }
69
Popular Tags