Source Code Cross Referenced for ContextTest.java in  » Mail-Clients » columba-1.4 » org » columba » core » 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 » Mail Clients » columba 1.4 » org.columba.core.context 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.columba.core.context;
002:
003:        import junit.framework.TestCase;
004:
005:        import org.columba.core.context.base.ContextFactory;
006:        import org.columba.core.context.base.api.IAttributeType;
007:        import org.columba.core.context.base.api.IStructureType;
008:        import org.columba.core.context.base.api.IStructureValue;
009:        import org.columba.core.context.base.api.MULTIPLICITY;
010:        import org.columba.core.context.base.api.IAttributeType.BASETYPE;
011:        import org.columba.core.main.MainInterface;
012:
013:        public class ContextTest extends TestCase {
014:
015:            public ContextTest() {
016:                super ();
017:            }
018:
019:            /**
020:             * 
021:             * attribute test <code>
022:             *  <userlist name="STRING" description="STRING"> 
023:             *  </userlist>
024:             * </code>
025:             */
026:            public void test() throws Exception {
027:                ContextFactory factory = new ContextFactory();
028:
029:                // top-level structure
030:                IStructureType type = factory.createStructure("userlist", "ns");
031:                type.setCardinality(MULTIPLICITY.ONE_TO_ONE);
032:
033:                // mandatory String-based attribute
034:                IAttributeType attr = type.addAttribute("name", "ns");
035:
036:                // optional String-based attribute
037:                IAttributeType attr2 = type.addAttribute("description", "ns");
038:
039:                IAttributeType result1 = type.getAttribute("name", "ns");
040:                assertEquals(attr, result1);
041:            }
042:
043:            public void testWithValue() throws Exception {
044:                ContextFactory factory = new ContextFactory();
045:
046:                // top-level structure
047:                IStructureType type = factory.createStructure("userlist", "ns");
048:                type.setCardinality(MULTIPLICITY.ONE_TO_ONE);
049:
050:                // mandatory String-based attribute
051:                IAttributeType attr = type.addAttribute("name", "ns");
052:                // optional String-based attribute
053:                IAttributeType attr2 = type.addAttribute("description", "ns");
054:
055:                IAttributeType result1 = type.getAttribute("name", "ns");
056:                assertEquals(attr, result1);
057:
058:                IStructureValue value = factory.createValue("userlist", "ns",
059:                        type);
060:                value.setString("name", "ns", "Name");
061:                value.setString("description", "ns", "Description");
062:
063:                // should throw exception as attribute type "name2" is not defined in
064:                // type structure
065:                try {
066:                    value.setString("name2", "ns", "Description");
067:                    fail();
068:                } catch (RuntimeException e) {
069:                }
070:
071:                try {
072:                    value.addChild("test", "ns");
073:                    fail();
074:                } catch (RuntimeException e) {
075:                }
076:
077:            }
078:
079:            /**
080:             * 
081:             * structure test
082:             * 
083:             * <pre>
084:             *   &lt;userlist name=&quot;STRING&quot; description=&quot;STRING&quot;&gt;
085:             *    &lt;user firstname=&quot;STRING&quot; lastname=&quot;STRING&quot;&gt;
086:             *    &lt;/user&gt;
087:             *    &lt;user firstname=&quot;STRING&quot; lastname=&quot;STRING&quot;&gt;
088:             *    &lt;/user&gt;
089:             *   &lt;/userlist&gt;
090:             * </pre>
091:             */
092:            public void test2() throws Exception {
093:                ContextFactory factory = new ContextFactory();
094:
095:                // top-level structure
096:                IStructureType userList = factory.createStructure("userlist",
097:                        "ns");
098:                userList.setCardinality(MULTIPLICITY.ONE_TO_ONE);
099:
100:                // mandatory String-based attribute
101:                IAttributeType attr = userList.addAttribute("name", "ns");
102:
103:                // optional String-based attribute
104:                IAttributeType attr2 = userList.addAttribute("description",
105:                        "ns");
106:                attr2.setBaseType(BASETYPE.STRING);
107:
108:                // user struct
109:                IStructureType user = userList.addChild("user", "ns");
110:                user.setCardinality(MULTIPLICITY.ZERO_TO_MANY);
111:
112:                IAttributeType attr1_1 = user.addAttribute("firstname", "ns");
113:                IAttributeType attr1_2 = user.addAttribute("lastname", "ns");
114:            }
115:
116:            public void test2WithValue() throws Exception {
117:                ContextFactory factory = new ContextFactory();
118:
119:                // top-level structure
120:                IStructureType userList = factory.createStructure("userlist",
121:                        "ns");
122:                userList.setCardinality(MULTIPLICITY.ONE_TO_ONE);
123:
124:                // mandatory String-based attribute
125:                IAttributeType attr = userList.addAttribute("name", "ns");
126:
127:                // optional String-based attribute
128:                IAttributeType attr2 = userList.addAttribute("description",
129:                        "ns");
130:                attr2.setBaseType(BASETYPE.STRING);
131:
132:                // user struct
133:                IStructureType user = userList.addChild("user", "ns");
134:                user.setCardinality(MULTIPLICITY.ZERO_TO_MANY);
135:
136:                IAttributeType attr1_1 = user.addAttribute("firstname", "ns");
137:                IAttributeType attr1_2 = user.addAttribute("lastname", "ns");
138:
139:                // create test userlist data
140:                IStructureValue value = factory.createValue("userlist", "ns",
141:                        userList);
142:                value.setString("name", "ns", "Name");
143:                value.setString("description", "ns", "Description");
144:
145:                IStructureValue value1 = value.addChild("user", "ns");
146:                value1.setString("firstname", "ns", "FirstName");
147:                value1.setString("lastname", "ns", "LastName");
148:
149:                IStructureValue value2 = value.addChild("user", "ns");
150:                value2.setString("firstname", "ns", "FirstName");
151:                value2.setString("lastname", "ns", "LastName");
152:            }
153:
154:            public void test3() throws Exception {
155:                ContextFactory factory = new ContextFactory();
156:
157:                IStructureType type = factory.createStructure("context",
158:                        "org.columba.core");
159:
160:                // MULTIPLICITY.ONE is default
161:                IStructureType core = type.addChild("core", "org.columba.core");
162:
163:                // identity definition
164:                IStructureType identity = core.addChild("identity",
165:                        "org.columba.core");
166:                // MULTIPLICITY.ZERO_TO_ONE is default
167:                IAttributeType emailAddress = identity.addAttribute(
168:                        "emailAddress", "org.columba.core");
169:                identity.addAttribute("displayName", "org.columba.core");
170:                identity.addAttribute("firstName", "org.columba.core");
171:                identity.addAttribute("lastName", "org.columba.core");
172:                identity.addAttribute("website", "org.columba.core");
173:
174:                // date time timezone definition
175:                IStructureType dateTime = core.addChild("dateTime",
176:                        "org.columba.core");
177:                IAttributeType date = dateTime.addAttribute("date",
178:                        "org.columba.core");
179:                IAttributeType timeZone = dateTime.addAttribute("timeZone",
180:                        "org.columba.core");
181:                date.setBaseType(BASETYPE.DATE);
182:
183:                // date range (start time, end time) definition
184:                IStructureType dateRange = core.addChild("dateRange",
185:                        "org.columba.core");
186:                IAttributeType startStart = dateRange.addAttribute("startDate",
187:                        "org.columba.core");
188:                startStart.setBaseType(BASETYPE.DATE);
189:                IAttributeType endDate = dateRange.addAttribute("endDate",
190:                        "org.columba.core");
191:                endDate.setBaseType(BASETYPE.DATE);
192:
193:                // document definition
194:                IStructureType document = core.addChild("document",
195:                        "org.columba.core");
196:                document.addAttribute("author", "org.columba.core");
197:                document.addAttribute("title", "org.columba.core");
198:                document.addAttribute("summary", "org.columba.core");
199:                document.addAttribute("body", "org.columba.core");
200:
201:                // locale definition
202:                IStructureType locale = core.addChild("locale",
203:                        "org.columba.core");
204:                locale.addAttribute("language", "org.columba.core");
205:                locale.addAttribute("country", "org.columba.core");
206:                locale.addAttribute("variant", "org.columba.core");
207:
208:                // list of attachments
209:                IStructureType attachmentList = core.addChild("attachmentList",
210:                        "org.columba.core");
211:                IStructureType attachment = attachmentList.addChild(
212:                        "attachment", "org.columba.core");
213:                attachment.setCardinality(MULTIPLICITY.ZERO_TO_MANY);
214:                // single attachment
215:                attachment.addAttribute("name", "org.columba.core");
216:                IAttributeType contentType = attachment.addAttribute("content",
217:                        "org.columba.core");
218:                contentType.setBaseType(BASETYPE.BINARY);
219:
220:                // message
221:                IStructureType message = core.addChild("message",
222:                        "org.columba.core");
223:                message.addAttribute("subject", "org.columba.core");
224:                // single sender - re-use identity type
225:                IStructureType sender = message.addChild("sender",
226:                        "org.columba.core");
227:                sender.addChild(identity);
228:                sender.setCardinality(MULTIPLICITY.ONE_TO_ONE);
229:                // re-use identity type for recipient list
230:                IStructureType recipients = message.addChild("recipients",
231:                        "org.columba.core");
232:                recipients.setCardinality(MULTIPLICITY.ZERO_TO_MANY);
233:                recipients.addChild(identity);
234:                // message body
235:                message.addAttribute("bodyText", "org.columba.core");
236:                message.addAttribute("selectedBodytext", "org.columba.core");
237:                // message contains list of attachments
238:                message.addChild(attachmentList);
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.