Source Code Cross Referenced for SystemPropertiesTest.java in  » Science » Cougaar12_4 » org » cougaar » bootstrap » 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 » Science » Cougaar12_4 » org.cougaar.bootstrap 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * <copyright> 
003:         *  Copyright 1999-2005 Cougaar Software, Inc.
004:         *  under sponsorship of the Defense Advanced Research Projects 
005:         *  Agency (DARPA). 
006:         *  
007:         *  You can redistribute this software and/or modify it under the
008:         *  terms of the Cougaar Open Source License as published on the
009:         *  Cougaar Open Source Website (www.cougaar.org).  
010:         *  
011:         *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
012:         *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
013:         *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
014:         *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
015:         *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
016:         *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
017:         *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
018:         *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
019:         *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
020:         *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
021:         *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
022:         *  
023:         * </copyright> 
024:         */
025:        package org.cougaar.bootstrap;
026:
027:        import java.util.Properties;
028:
029:        import junit.framework.TestCase;
030:
031:        /**
032:         * @author srosset
033:         */
034:        public class SystemPropertiesTest extends TestCase {
035:
036:            /*
037:             * A set of properties Before Expansion.
038:             */
039:            private static final String BE_A = "c:\\cougaar";
040:            private static final String BE_A_SUBA = "bob";
041:            private static final String BE_B = "${a} ${a.${c}}/bar";
042:            private static final String BE_C = "subA";
043:            private static final String BE_D = "\\$\\{a\\} ${a.${c}}/bar";
044:            private static final String BE_E = "\\\\$\\{a\\} ${a.${c}}/bar";
045:            private static final String BE_V = "${b}";
046:            private static final String BE_W = "${a.${abc}}";
047:            private static final String BE_X = "${y}";
048:            private static final String BE_Y = "${z}";
049:            private static final String BE_Z = "${x}";
050:
051:            /*
052:             * A set of properties After Expansion.
053:             */
054:            private static final String AE_B = BE_A + " " + BE_A_SUBA + "/bar";
055:            private static final String AE_D = "${a} " + BE_A_SUBA + "/bar";
056:            private static final String AE_E = "\\${a} " + BE_A_SUBA + "/bar";
057:
058:            public void testPropertyExpansion() {
059:                System.setProperties(new Properties());
060:
061:                System.setProperty("a", BE_A);
062:                System.setProperty("a.subA", BE_A_SUBA);
063:                System.setProperty("b", BE_B);
064:                System.setProperty("c", BE_C);
065:                System.setProperty("d", BE_D);
066:                System.setProperty("e", BE_E);
067:                // Test forward references
068:                System.setProperty("V", BE_V);
069:
070:                // Expand properties
071:                try {
072:                    SystemProperties.expandProperties();
073:                } catch (Exception e) {
074:                    fail("Unexpected property after expansion: " + e);
075:                }
076:
077:                checkProperty("a", BE_A);
078:                checkProperty("b", AE_B);
079:                checkProperty("c", BE_C);
080:                checkProperty("d", AE_D);
081:                checkProperty("e", AE_E);
082:                checkProperty("V", AE_B);
083:            }
084:
085:            /**
086:             * Test unresolved references
087:             */
088:            public void testUnresolvedReferences() {
089:                System.setProperties(new Properties());
090:
091:                System.setProperty("x", BE_X);
092:                System.setProperty("y", BE_Y);
093:
094:                // Expand properties
095:                try {
096:                    // This should throw an exception
097:                    SystemProperties.expandProperties();
098:                    fail("Did not detect unresolved references");
099:                } catch (IllegalArgumentException e) {
100:                    // Nothing to do. This is what we expect in the test.
101:                } catch (Exception e) {
102:                    fail("Unexpected exception: " + e);
103:                }
104:
105:                System.setProperty("W", BE_W);
106:                // Expand properties
107:                try {
108:                    // This should throw an exception
109:                    SystemProperties.expandProperties();
110:                    fail("Did not detect unresolved references");
111:                } catch (IllegalArgumentException e) {
112:                    // Nothing to do. This is what we expect in the test.
113:                } catch (Exception e) {
114:                    fail("Unexpected exception: " + e);
115:                }
116:            }
117:
118:            /**
119:             * Test circular references
120:             */
121:            public void testCircularExpansion() {
122:                System.setProperties(new Properties());
123:                System.setProperty("x", BE_X);
124:                System.setProperty("y", BE_Y);
125:                System.setProperty("z", BE_Z);
126:
127:                // Expand properties
128:                try {
129:                    // This should throw an exception
130:                    SystemProperties.expandProperties();
131:                    fail("Did not detect circular reference");
132:                } catch (IllegalArgumentException e) {
133:                    // Nothing to do. This is what we expect in the test.
134:                } catch (Exception e) {
135:                    fail("Unexpected exception: " + e);
136:                }
137:            }
138:
139:            /**
140:             * Check the value of a System property after expansion.
141:             * @param propertyName The name of a System property.
142:             * @param expectedValue The expected value of the named property.
143:             */
144:            private void checkProperty(String propertyName, String expectedValue) {
145:                String value = System.getProperty(propertyName);
146:                if (expectedValue == null) {
147:                    assertNull(value);
148:                } else {
149:                    assertEquals("Property " + propertyName + ": Expected "
150:                            + expectedValue + " but was " + value,
151:                            expectedValue, value);
152:                }
153:            }
154:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.