Source Code Cross Referenced for TestRifeConfig.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » config » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.config 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestRifeConfig.java 3643 2007-01-12 15:29:45Z gbevin $
007:         */
008:        package com.uwyn.rife.config;
009:
010:        import com.uwyn.rife.config.exceptions.DateFormatInitializationException;
011:        import com.uwyn.rife.ioc.HierarchicalProperties;
012:        import com.uwyn.rife.rep.Participant;
013:        import com.uwyn.rife.rep.Rep;
014:        import com.uwyn.rife.rep.Repository;
015:        import com.uwyn.rife.rep.SingleObjectParticipant;
016:        import java.lang.reflect.Constructor;
017:        import java.lang.reflect.InvocationTargetException;
018:        import java.text.DateFormat;
019:        import java.util.Collection;
020:        import java.util.GregorianCalendar;
021:        import java.util.HashMap;
022:        import java.util.Map;
023:        import junit.framework.TestCase;
024:
025:        public class TestRifeConfig extends TestCase {
026:            private Repository mDefaultRep = null;
027:
028:            public TestRifeConfig(String name) {
029:                super (name);
030:            }
031:
032:            public void setUp() {
033:                mDefaultRep = Rep.getDefaultRepository();
034:            }
035:
036:            public void tearDown() {
037:                Rep.setDefaultRepository(mDefaultRep);
038:            }
039:
040:            public void testShortDateFormat() throws Exception {
041:                switchLocale(USLocaleConfig.class);
042:
043:                DateFormat sf = RifeConfig.Tools.getDefaultShortDateFormat();
044:                String formatted = sf.format(new GregorianCalendar(2004, 7, 31,
045:                        15, 53).getTime());
046:
047:                assertEquals(formatted, "8/31/04");
048:
049:                switchLocale(BelgiumNLLocaleConfig.class);
050:
051:                sf = RifeConfig.Tools.getDefaultShortDateFormat();
052:                formatted = sf
053:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
054:                                .getTime());
055:
056:                assertEquals(formatted, "31/08/04");
057:
058:                switchLocale(GeneralESLocaleConfig.class);
059:
060:                sf = RifeConfig.Tools.getDefaultShortDateFormat();
061:                formatted = sf
062:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
063:                                .getTime());
064:
065:                assertEquals(formatted, "31/08/04");
066:
067:                switchLocale(FormattedDateFormatConfig.class);
068:
069:                sf = RifeConfig.Tools.getDefaultShortDateFormat();
070:                formatted = sf
071:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
072:                                .getTime());
073:
074:                assertEquals(formatted, "Tue, Aug 31, 2004");
075:
076:                try {
077:                    switchLocale(BadlyFormattedDateFormatConfig.class);
078:
079:                    sf = RifeConfig.Tools.getDefaultShortDateFormat();
080:                    formatted = sf.format(new GregorianCalendar(2004, 7, 31,
081:                            15, 53).getTime());
082:                    assertFalse(true);
083:                } catch (DateFormatInitializationException e) {
084:                    assertTrue(true);
085:                }
086:            }
087:
088:            public void testLongDateFormat() throws IllegalAccessException,
089:                    InstantiationException, NoSuchMethodException,
090:                    InvocationTargetException {
091:                switchLocale(USLocaleConfig.class);
092:
093:                DateFormat sf = RifeConfig.Tools.getDefaultLongDateFormat();
094:                String formatted = sf.format(new GregorianCalendar(2004, 7, 31,
095:                        15, 53).getTime());
096:
097:                assertEquals(formatted, "Aug 31, 2004 3:53 PM");
098:
099:                switchLocale(BelgiumNLLocaleConfig.class);
100:
101:                sf = RifeConfig.Tools.getDefaultLongDateFormat();
102:                formatted = sf
103:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
104:                                .getTime());
105:
106:                assertEquals(formatted, "31-aug-2004 15:53");
107:
108:                switchLocale(GeneralESLocaleConfig.class);
109:
110:                sf = RifeConfig.Tools.getDefaultLongDateFormat();
111:                formatted = sf
112:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
113:                                .getTime());
114:
115:                assertEquals(formatted, "31-ago-2004 15:53");
116:
117:                switchLocale(FormattedDateFormatConfig.class);
118:
119:                sf = RifeConfig.Tools.getDefaultLongDateFormat();
120:                formatted = sf
121:                        .format(new GregorianCalendar(2004, 7, 31, 15, 53)
122:                                .getTime());
123:
124:                assertEquals(formatted, "Tue, 31 Aug 2004 15:53:00");
125:
126:                try {
127:                    switchLocale(BadlyFormattedDateFormatConfig.class);
128:
129:                    sf = RifeConfig.Tools.getDefaultLongDateFormat();
130:                    formatted = sf.format(new GregorianCalendar(2004, 7, 31,
131:                            15, 53).getTime());
132:                    assertFalse(true);
133:                } catch (DateFormatInitializationException e) {
134:                    assertTrue(true);
135:                }
136:            }
137:
138:            private void switchLocale(Class klazz)
139:                    throws IllegalAccessException, InstantiationException,
140:                    NoSuchMethodException, InvocationTargetException {
141:                MockRepository rep = new MockRepository();
142:                rep.addParticipant("ParticipantConfig", klazz);
143:                Rep.setDefaultRepository(rep);
144:            }
145:
146:            public class USLocaleConfig extends SingleObjectParticipant {
147:                public Object getObject() {
148:                    Config config = new Config();
149:                    config.setParameter(
150:                            RifeConfig.Tools.PARAM_L10N_DEFAULT_COUNTRY, "US");
151:                    config.setParameter(
152:                            RifeConfig.Tools.PARAM_L10N_DEFAULT_LANGUAGE, "EN");
153:
154:                    return config;
155:                }
156:            }
157:
158:            public class BelgiumNLLocaleConfig extends SingleObjectParticipant {
159:                public Object getObject() {
160:                    Config config = new Config();
161:                    config.setParameter(
162:                            RifeConfig.Tools.PARAM_L10N_DEFAULT_COUNTRY, "BE");
163:                    config.setParameter(
164:                            RifeConfig.Tools.PARAM_L10N_DEFAULT_LANGUAGE, "NL");
165:
166:                    return config;
167:                }
168:            }
169:
170:            public class GeneralESLocaleConfig extends SingleObjectParticipant {
171:                public Object getObject() {
172:                    Config config = new Config();
173:                    config.setParameter(
174:                            RifeConfig.Tools.PARAM_L10N_DEFAULT_LANGUAGE, "ES");
175:
176:                    return config;
177:                }
178:            }
179:
180:            public class FormattedDateFormatConfig extends
181:                    SingleObjectParticipant {
182:                public Object getObject() {
183:                    Config config = new Config();
184:                    config
185:                            .setParameter(
186:                                    RifeConfig.Tools.PARAM_L10N_DEFAULT_SHORT_DATEFORMAT,
187:                                    "EEE, MMM d, yyyy");
188:                    config
189:                            .setParameter(
190:                                    RifeConfig.Tools.PARAM_L10N_DEFAULT_LONG_DATEFORMAT,
191:                                    "EEE, d MMM yyyy HH:mm:ss");
192:
193:                    return config;
194:                }
195:            }
196:
197:            public class BadlyFormattedDateFormatConfig extends
198:                    SingleObjectParticipant {
199:                public Object getObject() {
200:                    Config config = new Config();
201:                    config
202:                            .setParameter(
203:                                    RifeConfig.Tools.PARAM_L10N_DEFAULT_SHORT_DATEFORMAT,
204:                                    "wwww 999 uuuu");
205:                    config
206:                            .setParameter(
207:                                    RifeConfig.Tools.PARAM_L10N_DEFAULT_LONG_DATEFORMAT,
208:                                    "vvvv, 82.2 cccc");
209:
210:                    return config;
211:                }
212:            }
213:
214:            public class MockRepository implements  Repository {
215:                private Map mParticipants = new HashMap();
216:
217:                public MockRepository() {
218:                }
219:
220:                public void addParticipant(String name, Class klazz)
221:                        throws IllegalAccessException, InstantiationException,
222:                        NoSuchMethodException, InvocationTargetException {
223:                    Constructor localeConstructor = klazz
224:                            .getDeclaredConstructor(new Class[] { TestRifeConfig.class });
225:                    TestRifeConfig t = new TestRifeConfig(
226:                            "Workaround for inner class instanciation");
227:
228:                    mParticipants.put(name, localeConstructor
229:                            .newInstance(new Object[] { t }));
230:                }
231:
232:                public boolean hasParticipant(String name) {
233:                    return mParticipants.containsKey(name);
234:                }
235:
236:                public Participant getParticipant(String name) {
237:                    return (Participant) mParticipants.get(name);
238:                }
239:
240:                public Collection<? extends Participant> getParticipants(
241:                        String name) {
242:                    return mParticipants.values();
243:                }
244:
245:                public boolean isFinished() {
246:                    return true;
247:                }
248:
249:                public void cleanup() {
250:                }
251:
252:                public HierarchicalProperties getProperties() {
253:                    HierarchicalProperties properties = new HierarchicalProperties();
254:                    for (Map.Entry property : System.getProperties().entrySet()) {
255:                        properties.put((String) property.getKey(), property
256:                                .getValue());
257:                    }
258:                    return properties;
259:                }
260:
261:                public Object getContext() {
262:                    return null;
263:                }
264:            }
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.