KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > idaremedia > antx > valueuri > tests > DefinedValueURIHandlerTest


1 /**
2  * $Id: DefinedValueURIHandlerTest.java 180 2007-03-15 12:56:38Z ssmc $
3  * Copyright 2005 iDare Media, Inc. All rights reserved.
4  *
5  * Originally written by iDare Media, Inc. for release into the public domain. This
6  * library, source form and binary form, is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License (LGPL) as published
8  * by the Free Software Foundation; either version 2.1 of the License, or (at your option)
9  * any later version.<p>
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU LGPL for more details.<p>
14  *
15  * You should have received a copy of the GNU Lesser General Public License along with this
16  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite
17  * 330, Boston, MA 02111-1307 USA. The GNU LGPL can be found online at
18  * http://www.fsf.org/copyleft/lesser.html<p>
19  *
20  * This product has been influenced by several projects within the open-source community.
21  * The JWare developers wish to acknowledge the open-source community's support. For more
22  * information regarding the open-source products used within JWare, please visit the
23  * JWare website.
24  *----------------------------------------------------------------------------------------*
25  * WEBSITE- http://www.jware.info EMAIL- inquiries@jware.info
26  *----------------------------------------------------------------------------------------*
27  **/

28
29 package com.idaremedia.antx.valueuri.tests;
30
31 import junit.framework.TestSuite;
32
33 import com.idaremedia.antx.ValueURIHandler;
34 import com.idaremedia.antx.helpers.Strings;
35 import com.idaremedia.antx.valueuri.condition.DefinedValueURIHandler;
36
37 /**
38  * Testsuite for {@linkplain DefinedValueURIHandler}.
39  *
40  * @since JWare/AntX 0.5
41  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
42  * @version 0.5
43  * @.safety single
44  * @.group impl,test
45  **/

46
47 public final class DefinedValueURIHandlerTest extends ValueURIHandlerTestSkeleton
48 {
49     /**
50      * Initializes a new test case for named method.
51      * @param methodname test case method's name (non-null)
52      **/

53     public DefinedValueURIHandlerTest(String JavaDoc methodname)
54     {
55         super("DefinedValueURIHandler::",methodname);
56     }
57
58
59     /**
60      * Returns full test suite for DefinedValueURIHandler.
61      **/

62     public static TestSuite suite()
63     {
64         return new TestSuite(DefinedValueURIHandlerTest.class);
65     }
66
67 // ---------------------------------------------------------------------------------------------------------
68
// --------------------------------------- [ Misc Factory Methods ] ----------------------------------------
69
// ---------------------------------------------------------------------------------------------------------
70

71     protected ValueURIHandler newOUT()
72     {
73         return new DefinedValueURIHandler();
74     }
75
76 // ---------------------------------------------------------------------------------------------------------
77
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
78
// ---------------------------------------------------------------------------------------------------------
79

80     private void assertIsTrue(String JavaDoc value, String JavaDoc what)
81     {
82         assertEqual(value,Strings.TRUE,"$defined:"+what);
83     }
84
85
86     private void assertIsFalse(String JavaDoc value, String JavaDoc what)
87     {
88         assertEqual(value,Strings.FALSE,"$defined:"+what);
89     }
90
91
92     /**
93      * Verify we can generate a project-unique reference always.
94      * @since JWare/AntX 0.5
95      **/

96     public void testBaseline_AntX05()
97     {
98         checkBaseline();
99
100         ValueURIHandler out = newOUT();
101         assertIsFalse(out.valueFrom("","$defined:",m_rqlink),"[:empty:]");
102     }
103
104
105
106     /**
107      * Verifies we evaluate 'true' for defined and resolvable
108      * properties.
109      * @since JWare/AntX 0.5
110      **/

111     public void testGoodProperty_AntX05()
112     {
113         getProject().setProperty("seekrit","ssshhh");
114         ValueURIHandler out = newOUT();
115         
116         String JavaDoc result = out.valueFrom("seekrit?property","$defined:seekrit?property",m_rqlink);
117         assertIsTrue(result,"seekrit?property");
118         result = out.valueFrom("${seekrit}","$defined:${seekrit}",m_rqlink);
119         assertIsTrue(result,"${seekrit}");
120         result = out.valueFrom("@(seekrit)","$defined:@(seekrit)",m_rqlink);
121         assertIsTrue(result,"${seekrit}");
122     }
123  
124  
125
126     /**
127      * Verifies we evaluate 'false' for defined but malformed
128      * properties.
129      * @since JWare/AntX 0.5
130      **/

131     public void testMalformedProperty_AntX05()
132     {
133         getProject().setProperty("malformed","a${non-existing}value");
134         ValueURIHandler out = newOUT();
135         
136         String JavaDoc result = out.valueFrom("malformed?property","$defined:malformed?property",m_rqlink);
137         assertIsFalse(result,"malformed?property");
138         result = out.valueFrom("${malformed}","$defined:${malformed}",m_rqlink);
139         assertIsFalse(result,"${malformed}");
140         result = out.valueFrom("@(malformed)","$defined:@(malformed)",m_rqlink);
141         assertIsFalse(result,"@(malformed)");
142     }
143
144
145
146     /**
147      * Verifies we evaluate 'false' for undefined properties.
148      * @since JWare/AntX 0.5
149      **/

150     public void testUndefinedProperty_AntX05()
151     {
152         ValueURIHandler out= newOUT();
153         
154         String JavaDoc result = out.valueFrom("nosuchproperty?property","$defined:nosuchproperty?property",m_rqlink);
155         assertIsFalse(result,"nosuchproperty?property");
156         result = out.valueFrom("@(nosuchproperty)","$defined:@(nosuchproperty)",m_rqlink);
157         assertIsFalse(result,"@(nosuchproperty)");
158     }
159     
160
161
162     /**
163      * Verifies we evaluate 'false' for all whitespace literals and
164      * property values.
165      * @since JWare/AntX 0.5
166      **/

167     public void testAllWhitespaceValues_AntX05()
168     {
169         getProject().setProperty("whitespace"," \t");
170         ValueURIHandler out = newOUT();
171         
172         String JavaDoc result = out.valueFrom("${whitespace}","$defined:${whitespace}",m_rqlink);
173         assertIsFalse(result,"${whitespace}");
174         result = out.valueFrom(" \t ","$defined: \t ",m_rqlink);
175         assertIsFalse(result,"[:space:]");
176     }
177     
178
179
180     /**
181      * Verifies we evaluate 'false' for all empty string literals and
182      * property values.
183      * @since JWare/AntX 0.5
184      **/

185     public void testEmptyValues_AntX05()
186     {
187         getProject().setProperty("empty","");
188         ValueURIHandler out = newOUT();
189         
190         String JavaDoc result = out.valueFrom("@(empty)","$defined:@(empty)",m_rqlink);
191         assertIsFalse(result,"@([:empty:])");
192         assertIsFalse(out.valueFrom("","$defined:",m_rqlink),"[:empty:]");
193     }
194 }
195
196 /* end-of-DefinedValueURIHandlerTest.java */
Popular Tags