Source Code Cross Referenced for XStreamBuilderTest.java in  » XML » xstream-1.3 » com » thoughtworks » acceptance » 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 » XML » xstream 1.3 » com.thoughtworks.acceptance 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2007 XStream Committers.
003:         * All rights reserved.
004:         *
005:         * The software in this package is published under the terms of the BSD
006:         * style license a copy of which has been included with this distribution in
007:         * the LICENSE.txt file.
008:         * 
009:         * Created on 14. May 2007 by Guilherme Silveira
010:         */
011:        package com.thoughtworks.acceptance;
012:
013:        import java.util.ArrayList;
014:        import java.util.Collection;
015:        import java.util.HashSet;
016:        import java.util.List;
017:
018:        import com.thoughtworks.xstream.builder.XStreamBuilder;
019:        import com.thoughtworks.xstream.builder.processor.TypeConfigProcessor;
020:        import com.thoughtworks.xstream.converters.Converter;
021:        import com.thoughtworks.xstream.converters.MarshallingContext;
022:        import com.thoughtworks.xstream.converters.UnmarshallingContext;
023:        import com.thoughtworks.xstream.io.HierarchicalStreamReader;
024:        import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
025:
026:        /**
027:         * @author Guilherme Silveira
028:         */
029:        public class XStreamBuilderTest extends AbstractBuilderAcceptanceTest {
030:
031:            public void testSupportsBuildStyleWithAlias() {
032:                XStreamBuilder builder = new XStreamBuilder() {
033:                    {
034:                        handle(Office.class).with(alias("office"));
035:                    }
036:                };
037:
038:                Office office = new Office("Rua Vergueiro");
039:                String expected = "<office>\n  <address>Rua Vergueiro</address>\n</office>";
040:                assertBothWays(builder.buildXStream(), office, expected);
041:            }
042:
043:            public static class Office {
044:                private String address;
045:
046:                public Office(String address) {
047:                    this .address = address;
048:                }
049:            }
050:
051:            public void testHandleCorrectlyFieldAliases() {
052:
053:                XStreamBuilder builder = new XStreamBuilder() {
054:                    {
055:                        handle(Office.class)
056:                                .with(
057:                                        new TypeConfigProcessor[] {
058:                                                alias("office"),
059:                                                field("address").with(
060:                                                        as("logradouro")) });
061:                    }
062:                };
063:
064:                Office office = new Office("Rua Vergueiro");
065:                String expected = "<office>\n  <logradouro>Rua Vergueiro</logradouro>\n</office>";
066:                assertBothWays(builder.buildXStream(), office, expected);
067:
068:            }
069:
070:            public void testHandleCorrectlyFieldOmmission() {
071:
072:                XStreamBuilder builder = new XStreamBuilder() {
073:                    {
074:                        handle(Office.class).with(
075:                                new TypeConfigProcessor[] { alias("office"),
076:                                        ignores("address")
077:                                // TODO "decision: could be" field("address").with(ignored())
078:                                });
079:                    }
080:                };
081:
082:                Office office = new Office("Rua Vergueiro");
083:                String expected = "<office/>";
084:                assertBothWays(builder.buildXStream(), office, expected);
085:
086:            }
087:
088:            public static class CollectionContainer {
089:                Collection collection;
090:            }
091:
092:            public void testHandleCorrectlyDefaultImplementations() {
093:
094:                XStreamBuilder builder = new XStreamBuilder() {
095:                    {
096:                        handle(Collection.class).with(
097:                                implementedBy(HashSet.class));
098:                        handle(CollectionContainer.class).with(alias("cc"));
099:                    }
100:                };
101:
102:                CollectionContainer root = new CollectionContainer();
103:                root.collection = new HashSet();
104:                String expected = "<cc>\n  <collection/>\n</cc>";
105:
106:                assertBothWays(builder.buildXStream(), root, expected);
107:
108:            }
109:
110:            public static class DoNothingConverter implements  Converter {
111:                private final Class support;
112:
113:                public DoNothingConverter(Class aClass) {
114:                    this .support = aClass;
115:                }
116:
117:                public void marshal(Object source,
118:                        HierarchicalStreamWriter writer,
119:                        MarshallingContext context) {
120:                    writer.startNode("wow");
121:                    writer.endNode();
122:                }
123:
124:                public Object unmarshal(HierarchicalStreamReader reader,
125:                        UnmarshallingContext context) {
126:                    try {
127:                        return support.newInstance();
128:                    } catch (InstantiationException e) {
129:                        throw new RuntimeException(e);
130:                    } catch (IllegalAccessException e) {
131:                        throw new RuntimeException(e);
132:                    }
133:                }
134:
135:                public boolean canConvert(Class type) {
136:                    return support.equals(type);
137:                }
138:            }
139:
140:            public void testHandleCorrectlyConverterRegistrations() {
141:
142:                XStreamBuilder builder = new XStreamBuilder() {
143:                    {
144:                        handle(CollectionContainer.class).with(alias("cc"));
145:                        register(converter(new DoNothingConverter(
146:                                CollectionContainer.class)));
147:                    }
148:                };
149:
150:                CollectionContainer root = new CollectionContainer();
151:                root.collection = new HashSet();
152:                String expected = "<cc>\n  <wow/>\n</cc>";
153:
154:                assertBothWays(builder.buildXStream(), root, expected);
155:
156:            }
157:
158:            static class Home {
159:            }
160:
161:            public void testHandleCorrectlyAbsoluteReferences() {
162:
163:                XStreamBuilder builder = new XStreamBuilder() {
164:                    {
165:                        with(absoluteReferences());
166:                        handle(Home.class).with(alias("home"));
167:                    }
168:                };
169:
170:                List root = new ArrayList();
171:                root.add(new Home());
172:                root.add(root.get(0));
173:                String expected = "<list>\n  <home/>\n  <home reference=\"/list/home\"/>\n</list>";
174:
175:                assertBothWays(builder.buildXStream(), root, expected);
176:
177:            }
178:
179:            public void testHandleCorrectlyIdReferences() {
180:
181:                XStreamBuilder builder = new XStreamBuilder() {
182:                    {
183:                        with(idReferences());
184:                        handle(Home.class).with(alias("home"));
185:                    }
186:                };
187:
188:                List root = new ArrayList();
189:                root.add(new Home());
190:                root.add(root.get(0));
191:                String expected = "<list id=\"1\">\n  <home id=\"2\"/>\n  <home reference=\"2\"/>\n</list>";
192:
193:                assertBothWays(builder.buildXStream(), root, expected);
194:
195:            }
196:
197:            public void testHandleCorrectlyNoReferences() {
198:
199:                XStreamBuilder builder = new XStreamBuilder() {
200:                    {
201:                        with(noReferences());
202:                        handle(Home.class).with(alias("home"));
203:                    }
204:                };
205:
206:                List root = new ArrayList();
207:                root.add(new Home());
208:                root.add(root.get(0));
209:                String expected = "<list>\n  <home/>\n  <home/>\n</list>";
210:
211:                assertBothWays(builder.buildXStream(), root, expected);
212:
213:            }
214:
215:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.