Source Code Cross Referenced for StandardConfigContextTest.java in  » Net » Terracotta » com » tc » config » schema » context » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Terracotta » com.tc.config.schema.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice.  All rights reserved.
003:         */
004:        package com.tc.config.schema.context;
005:
006:        import com.tc.config.schema.MockIllegalConfigurationChangeHandler;
007:        import com.tc.config.schema.MockSchemaType;
008:        import com.tc.config.schema.MockXmlObject;
009:        import com.tc.config.schema.defaults.MockDefaultValueProvider;
010:        import com.tc.config.schema.dynamic.BooleanConfigItem;
011:        import com.tc.config.schema.dynamic.ConfigItem;
012:        import com.tc.config.schema.dynamic.FileConfigItem;
013:        import com.tc.config.schema.dynamic.IntConfigItem;
014:        import com.tc.config.schema.dynamic.MockConfigItem;
015:        import com.tc.config.schema.dynamic.MockListeningConfigItem;
016:        import com.tc.config.schema.dynamic.StringArrayConfigItem;
017:        import com.tc.config.schema.dynamic.StringConfigItem;
018:        import com.tc.config.schema.dynamic.XPathBasedConfigItem;
019:        import com.tc.config.schema.repository.MockBeanRepository;
020:        import com.tc.test.TCTestCase;
021:
022:        /**
023:         * Unit test for {@link StandardConfigContext}.
024:         */
025:        public class StandardConfigContextTest extends TCTestCase {
026:
027:            private MockSchemaType schemaType;
028:            private MockBeanRepository beanRepository;
029:            private MockDefaultValueProvider defaultValueProvider;
030:            private MockIllegalConfigurationChangeHandler illegalConfigurationChangeHandler;
031:
032:            private ConfigContext context;
033:
034:            public void setUp() throws Exception {
035:                this .schemaType = new MockSchemaType();
036:                this .beanRepository = new MockBeanRepository();
037:                this .beanRepository
038:                        .setReturnedRootBeanSchemaType(this .schemaType);
039:                this .defaultValueProvider = new MockDefaultValueProvider();
040:                this .illegalConfigurationChangeHandler = new MockIllegalConfigurationChangeHandler();
041:
042:                this .context = new StandardConfigContext(this .beanRepository,
043:                        this .defaultValueProvider,
044:                        this .illegalConfigurationChangeHandler, null);
045:            }
046:
047:            public void testEnsureRepositoryProvides() throws Exception {
048:                this .beanRepository.setExceptionOnEnsureBeanIsOfClass(null);
049:
050:                this .context.ensureRepositoryProvides(Number.class);
051:                assertEquals(1, this .beanRepository
052:                        .getNumEnsureBeanIsOfClasses());
053:                assertEquals(Number.class, this .beanRepository.getLastClass());
054:                this .beanRepository.reset();
055:
056:                RuntimeException exception = new RuntimeException("foo");
057:                this .beanRepository
058:                        .setExceptionOnEnsureBeanIsOfClass(exception);
059:
060:                try {
061:                    this .context.ensureRepositoryProvides(Object.class);
062:                    fail("Didn't get expected exception");
063:                } catch (RuntimeException re) {
064:                    assertSame(exception, re);
065:                    assertEquals(1, this .beanRepository
066:                            .getNumEnsureBeanIsOfClasses());
067:                    assertEquals(Object.class, this .beanRepository
068:                            .getLastClass());
069:                }
070:            }
071:
072:            public void testConstruction() throws Exception {
073:                try {
074:                    new StandardConfigContext(null, this .defaultValueProvider,
075:                            this .illegalConfigurationChangeHandler, null);
076:                    fail("Didn't get NPE on no bean repository");
077:                } catch (NullPointerException npe) {
078:                    // ok
079:                }
080:
081:                try {
082:                    new StandardConfigContext(this .beanRepository, null,
083:                            this .illegalConfigurationChangeHandler, null);
084:                    fail("Didn't get NPE on no default value provider");
085:                } catch (NullPointerException npe) {
086:                    // ok
087:                }
088:
089:                try {
090:                    new StandardConfigContext(this .beanRepository,
091:                            this .defaultValueProvider, null, null);
092:                    fail("Didn't get NPE on no illegal configuration change handler");
093:                } catch (NullPointerException npe) {
094:                    // ok
095:                }
096:            }
097:
098:            public void testHasDefaultFor() throws Exception {
099:                this .defaultValueProvider
100:                        .setReturnedPossibleForXPathToHaveDefault(false);
101:                this .defaultValueProvider.setReturnedHasDefault(false);
102:
103:                assertFalse(this .context.hasDefaultFor("foobar/baz"));
104:                assertEquals(1, this .defaultValueProvider
105:                        .getNumPossibleForXPathToHaveDefaults());
106:                assertEquals("foobar/baz", this .defaultValueProvider
107:                        .getLastPossibleForXPathToHaveDefaultsXPath());
108:                assertEquals(0, this .defaultValueProvider.getNumHasDefaults());
109:
110:                this .defaultValueProvider.reset();
111:                this .defaultValueProvider
112:                        .setReturnedPossibleForXPathToHaveDefault(true);
113:                this .defaultValueProvider.setReturnedHasDefault(false);
114:
115:                assertFalse(this .context.hasDefaultFor("foobar/baz"));
116:                assertEquals(1, this .defaultValueProvider
117:                        .getNumPossibleForXPathToHaveDefaults());
118:                assertEquals("foobar/baz", this .defaultValueProvider
119:                        .getLastPossibleForXPathToHaveDefaultsXPath());
120:                assertEquals(1, this .defaultValueProvider.getNumHasDefaults());
121:                assertSame(this .schemaType, this .defaultValueProvider
122:                        .getLastHasDefaultsSchemaType());
123:                assertEquals("foobar/baz", this .defaultValueProvider
124:                        .getLastHasDefaultsXPath());
125:
126:                this .defaultValueProvider.reset();
127:                this .defaultValueProvider
128:                        .setReturnedPossibleForXPathToHaveDefault(false);
129:                this .defaultValueProvider.setReturnedHasDefault(true);
130:
131:                assertFalse(this .context.hasDefaultFor("foobar/baz"));
132:                assertEquals(1, this .defaultValueProvider
133:                        .getNumPossibleForXPathToHaveDefaults());
134:                assertEquals("foobar/baz", this .defaultValueProvider
135:                        .getLastPossibleForXPathToHaveDefaultsXPath());
136:                assertEquals(0, this .defaultValueProvider.getNumHasDefaults());
137:
138:                this .defaultValueProvider.reset();
139:                this .defaultValueProvider
140:                        .setReturnedPossibleForXPathToHaveDefault(true);
141:                this .defaultValueProvider.setReturnedHasDefault(true);
142:
143:                assertTrue(this .context.hasDefaultFor("foobar/baz"));
144:                assertEquals(1, this .defaultValueProvider
145:                        .getNumPossibleForXPathToHaveDefaults());
146:                assertEquals("foobar/baz", this .defaultValueProvider
147:                        .getLastPossibleForXPathToHaveDefaultsXPath());
148:                assertEquals(1, this .defaultValueProvider.getNumHasDefaults());
149:                assertSame(this .schemaType, this .defaultValueProvider
150:                        .getLastHasDefaultsSchemaType());
151:                assertEquals("foobar/baz", this .defaultValueProvider
152:                        .getLastHasDefaultsXPath());
153:            }
154:
155:            public void testDefaultFor() throws Exception {
156:                MockXmlObject object = new MockXmlObject();
157:                this .defaultValueProvider.setReturnedDefaultFor(object);
158:
159:                assertSame(object, this .context.defaultFor("foobar/baz"));
160:                assertEquals(1, this .defaultValueProvider.getNumDefaultFors());
161:                assertSame(this .schemaType, this .defaultValueProvider
162:                        .getLastBaseType());
163:                assertEquals("foobar/baz", this .defaultValueProvider
164:                        .getLastXPath());
165:            }
166:
167:            public void testIsOptional() throws Exception {
168:                this .defaultValueProvider.setReturnedIsOptional(false);
169:
170:                assertFalse(this .context.isOptional("foobar/baz"));
171:                assertEquals(1, this .defaultValueProvider.getNumIsOptionals());
172:                assertSame(this .schemaType, this .defaultValueProvider
173:                        .getLastBaseType());
174:                assertEquals("foobar/baz", this .defaultValueProvider
175:                        .getLastXPath());
176:            }
177:
178:            public void testBean() throws Exception {
179:                MockXmlObject object = new MockXmlObject();
180:                this .beanRepository.setReturnedBean(object);
181:
182:                assertSame(object, this .context.bean());
183:                assertEquals(1, this .beanRepository.getNumBeans());
184:            }
185:
186:            public void testItemCreated() throws Exception {
187:                MockConfigItem item = new MockConfigItem();
188:
189:                this .context.itemCreated(item);
190:                assertEquals(0, this .beanRepository.getNumAddListeners());
191:
192:                MockListeningConfigItem listeningItem = new MockListeningConfigItem();
193:
194:                this .context.itemCreated(listeningItem);
195:                assertEquals(1, this .beanRepository.getNumAddListeners());
196:                assertSame(listeningItem, this .beanRepository.getLastListener());
197:            }
198:
199:            public void testItems() throws Exception {
200:                checkItem(this .context.intItem("foobar/baz"), "foobar/baz",
201:                        IntConfigItem.class, null);
202:                checkItem(this .context.stringItem("foobar/baz"), "foobar/baz",
203:                        StringConfigItem.class, null);
204:                checkItem(this .context.stringArrayItem("foobar/baz"),
205:                        "foobar/baz", StringArrayConfigItem.class, null);
206:                checkItem(this .context.fileItem("foobar/baz"), "foobar/baz",
207:                        FileConfigItem.class, null);
208:                checkItem(this .context.booleanItem("foobar/baz"), "foobar/baz",
209:                        BooleanConfigItem.class, null);
210:                checkItem(this .context.booleanItem("foobar/baz", true),
211:                        "foobar/baz", BooleanConfigItem.class, Boolean.TRUE);
212:                checkItem(this .context.booleanItem("foobar/baz", false),
213:                        "foobar/baz", BooleanConfigItem.class, Boolean.FALSE);
214:            }
215:
216:            private void checkItem(ConfigItem item, String xpath,
217:                    Class expectedClass, Object expectedDefaultValue) {
218:                assertTrue(expectedClass.isInstance(item));
219:                assertEquals(xpath, ((XPathBasedConfigItem) item).xpath());
220:                assertSame(this .context, ((XPathBasedConfigItem) item)
221:                        .context());
222:                assertEquals(expectedDefaultValue,
223:                        ((XPathBasedConfigItem) item).defaultValue());
224:            }
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.