Source Code Cross Referenced for OptionsTest.java in  » Net » Terracotta » com » tc » object » logging » 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.object.logging 
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.object.logging;
005:
006:        import com.tc.exception.ImplementMe;
007:        import com.tc.logging.LogLevel;
008:        import com.tc.logging.TCLogger;
009:
010:        import java.util.HashMap;
011:        import java.util.Map;
012:
013:        import junit.framework.TestCase;
014:
015:        public class OptionsTest extends TestCase {
016:            Map defaults = new HashMap();
017:            Logger logger = new Logger();
018:            String[] keys = new String[] { "key1", "key2", "key3" };
019:            String input;
020:            Options opts;
021:
022:            protected void setUp() throws Exception {
023:                super .setUp();
024:
025:                defaults.put("key1", Boolean.TRUE);
026:                defaults.put("key2", Boolean.TRUE);
027:                defaults.put("key3", Boolean.FALSE);
028:            }
029:
030:            public void testExceptions() {
031:                try {
032:                    new Options("", new String[] { "key1", "ALL" }, logger,
033:                            defaults);
034:                    fail();
035:                } catch (IllegalArgumentException e) {
036:                    // expected
037:                }
038:
039:                try {
040:                    new Options("", new String[] { "NONE" }, logger, defaults);
041:                    fail();
042:                } catch (IllegalArgumentException e) {
043:                    // expected
044:                }
045:
046:                defaults.clear();
047:                defaults.put("key1", "not an instance of java.lang.Boolean");
048:
049:                try {
050:                    new Options("", keys, logger, defaults);
051:                    fail();
052:                } catch (IllegalArgumentException e) {
053:                    // expected
054:                }
055:            }
056:
057:            public void test() {
058:                input = "key1";
059:                opts = new Options(input, keys, logger, null);
060:                assertTrue(opts.getOption("key1"));
061:                assertFalse(opts.getOption("key2"));
062:                assertFalse(opts.getOption("key3"));
063:                assertEquals(0, logger.warnCount);
064:
065:                String[] empty = new String[] { null, "", " ", " \t", "\t ",
066:                        "\t", " ", "        \t ", " ,\t" };
067:                for (int i = 0; i < empty.length; i++) {
068:                    input = empty[i];
069:                    opts = new Options(input, keys, logger, null);
070:                    assertFalse(opts.getOption("key1"));
071:                    assertFalse(opts.getOption("key2"));
072:                    assertFalse(opts.getOption("key3"));
073:                    assertEquals(0, logger.warnCount);
074:                }
075:
076:                input = "this-aint-a-valid-option, key2";
077:                opts = new Options(input, keys, logger, null);
078:                assertEquals(1, logger.warnCount);
079:                assertFalse(opts.getOption("key1"));
080:                assertTrue(opts.getOption("key2"));
081:                assertFalse(opts.getOption("key3"));
082:
083:                String[] all = new String[] { "ALL", "toString, ALL",
084:                        "ALL, not-a-valid-option" };
085:                for (int i = 0; i < all.length; i++) {
086:                    input = all[i];
087:                    opts = new Options(input, keys, logger, null);
088:                    assertTrue(opts.getOption("key1"));
089:                    assertTrue(opts.getOption("key2"));
090:                    assertTrue(opts.getOption("key3"));
091:                }
092:            }
093:
094:            public void testNone() {
095:                input = "NONE, key2";
096:                opts = new Options(input, keys, logger, defaults);
097:                assertEquals(0, logger.warnCount);
098:                assertFalse(opts.getOption("key1"));
099:                assertTrue(opts.getOption("key2"));
100:                assertFalse(opts.getOption("key3"));
101:
102:                input = "key1, key2,key3, NONE";
103:                opts = new Options(input, keys, logger, defaults);
104:                assertEquals(0, logger.warnCount);
105:                assertFalse(opts.getOption("key1"));
106:                assertFalse(opts.getOption("key2"));
107:                assertFalse(opts.getOption("key3"));
108:            }
109:
110:            public void testNegation() {
111:                input = "key1, -key2";
112:                opts = new Options(input, keys, logger, defaults);
113:                assertEquals(0, logger.warnCount);
114:                assertTrue(opts.getOption("key1"));
115:                assertFalse(opts.getOption("key2")); // default is true, but we negated it in the the input
116:                assertFalse(opts.getOption("key3"));
117:            }
118:
119:            public void testAllPlusNegation() {
120:                input = "ALL, -key2";
121:                opts = new Options(input, keys, logger, defaults);
122:                assertEquals(0, logger.warnCount);
123:                assertTrue(opts.getOption("key1"));
124:                assertFalse(opts.getOption("key2"));
125:                assertTrue(opts.getOption("key3"));
126:            }
127:
128:            public void testDefaults() {
129:                opts = new Options(null, keys, logger, defaults);
130:                assertEquals(0, logger.warnCount);
131:                assertTrue(opts.getOption("key1"));
132:                assertTrue(opts.getOption("key2"));
133:                assertFalse(opts.getOption("key3"));
134:            }
135:
136:            private static class Logger implements  TCLogger {
137:
138:                int warnCount;
139:
140:                public void debug(Object message) {
141:                    throw new ImplementMe();
142:                }
143:
144:                public void debug(Object message, Throwable t) {
145:                    throw new ImplementMe();
146:                }
147:
148:                public void error(Object message) {
149:                    throw new ImplementMe();
150:                }
151:
152:                public void error(Object message, Throwable t) {
153:                    throw new ImplementMe();
154:                }
155:
156:                public void fatal(Object message) {
157:                    throw new ImplementMe();
158:                }
159:
160:                public void fatal(Object message, Throwable t) {
161:                    throw new ImplementMe();
162:                }
163:
164:                public void info(Object message) {
165:                    throw new ImplementMe();
166:                }
167:
168:                public void info(Object message, Throwable t) {
169:                    throw new ImplementMe();
170:                }
171:
172:                public void warn(Object message) {
173:                    this .warnCount++;
174:                }
175:
176:                public void warn(Object message, Throwable t) {
177:                    throw new ImplementMe();
178:                }
179:
180:                public void log(LogLevel level, Object message) {
181:                    throw new ImplementMe();
182:                }
183:
184:                public void log(LogLevel level, Object message, Throwable t) {
185:                    throw new ImplementMe();
186:                }
187:
188:                public boolean isDebugEnabled() {
189:                    return false;
190:                }
191:
192:                public boolean isInfoEnabled() {
193:                    return false;
194:                }
195:
196:                public void setLevel(LogLevel level) {
197:                    throw new ImplementMe();
198:                }
199:
200:                public LogLevel getLevel() {
201:                    throw new ImplementMe();
202:                }
203:
204:                public String getName() {
205:                    throw new ImplementMe();
206:                }
207:            }
208:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.