KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: DefaultsValueURIHandlerTest.java 186 2007-03-16 13:42:35Z 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 org.apache.tools.ant.Project;
32
33 import junit.framework.TestSuite;
34
35 import com.idaremedia.antx.Iteration;
36 import com.idaremedia.antx.ValueURIHandler;
37 import com.idaremedia.antx.valueuri.info.DefaultsValueURIHandler;
38
39 /**
40  * Testsuite for {@linkplain DefaultsValueURIHandler}.
41  *
42  * @since JWare/AntX 0.5
43  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
44  * @version 0.5
45  * @.safety single
46  * @.group impl,test
47  **/

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

55     public DefaultsValueURIHandlerTest(String JavaDoc methodname)
56     {
57         super("DefaultsValueURIHandler::",methodname);
58     }
59
60
61     /**
62      * Returns full test suite for DefaultsValueURIHandler.
63      **/

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

73     protected String JavaDoc xmlTestFile()
74     {
75         return "defaults.xml";
76     }
77
78     protected ValueURIHandler newOUT()
79     {
80         return new DefaultsValueURIHandler();
81     }
82     
83     protected void setUp() throws Exception JavaDoc
84     {
85         super.setUp();
86         assertNil(getProject().getProperty("defaults.licenses"),
87                  "'defaults.licenses' property");
88     }
89
90 // ---------------------------------------------------------------------------------------------------------
91
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
92
// ---------------------------------------------------------------------------------------------------------
93

94     /**
95      * Verify a blank uri fragment is evaluated as null.
96      * @since JWare/AntX 0.5
97      **/

98     public void testBaseline_AntX05()
99     {
100         checkBaseline();
101
102         String JavaDoc result = newOUT().valueFrom("","$default:",m_rqlink);
103         assertNil(result,"$default:");
104     }
105
106
107     /**
108      * Verify the capitalization of the key is unimportant.
109      * @since JWare/AntX 0.5
110      **/

111     public void testKeyIsCaseInsensitive_AntX05()
112     {
113         ValueURIHandler out = newOUT();
114         String JavaDoc result1 = out.valueFrom("CONFIGID","$default:CONFIGID",m_rqlink);
115         assertEqual(result1,Iteration.configId(),"$default:CONFIGID");
116         assertTrue(result1.startsWith("jware.antx"),"configid startswith jware.antx");
117         String JavaDoc result2 = out.valueFrom("configid","$default:configid",m_rqlink);
118         assertEqual(result2,result1,"$default:config");
119
120         result1 = out.valueFrom("haltiferror","$default:haltiferror",m_rqlink);
121         result2 = out.valueFrom("haltIfError","$default:haltIfError",m_rqlink);
122         assertEqual(result2,result1,"$default:haltIfError");
123         assertEqual(result1,String.valueOf(Iteration.defaultdefaults().isHaltIfError()));
124     }
125
126
127     /**
128      * Verify can include a fallback value if handler unable to
129      * determine default value from context.
130      * @since JWare/AntX 0.5
131      **/

132     public void testCanInlineDefaultsIfNotPredefined_AntX05()
133     {
134         final Project myproject = getProject();
135
136         ValueURIHandler out = newOUT();
137         String JavaDoc license = out.valueFrom("licenses?LGPL","$df:licenses?LGPL",m_rqlink);
138         assertEqual(license,"LGPL","$df:licenses?LGPL");
139
140         assertNil(myproject.getProperty("fallback"),"'fallback' property");
141         myproject.setProperty("fallback", "MIT");
142         license = out.valueFrom("licenses?@(fallback)/latest","$df:licenses?@(fallback)/latest",m_rqlink);
143         assertEqual(license,"MIT/latest","$df:licenses?@(fallback)/latest with $fallback=MIT");
144
145         myproject.setProperty("defaults.licenses","Apache2");
146         license = out.valueFrom("licenses?LGPL","$df:licenses?LGPL",m_rqlink);
147         assertEqual(license,"Apache2","$df:licenses?LGPL with defaults.license=Apache2");
148     }
149     
150     
151     
152     /**
153      * Verifies that the key of the URI fragment must be a resolved
154      * value. Property references are supported only as part of the
155      * inline default string.
156      * @since JWare/AntX 0.5
157      **/

158     public void testLiteralKeyRequired_AntX05()
159     {
160         final Project myproject = getProject();
161         myproject.setProperty("dotd","assertions");
162         
163         ValueURIHandler out = newOUT();
164         String JavaDoc result = out.valueFrom("@(dotd)","$df:@(dotd)",m_rqlink);
165         assertNil(result,"$df:@(dotd)");
166         
167         result = out.valueFrom("@(dotd)?@(dotd)","$df:@(dotd)?@(dotd)",m_rqlink);
168         assertEqual(result,"assertions","$df:@(dotd)?@(dotd)");
169     }
170
171
172
173     /**
174      * Verify some things from within an Ant-only environment.
175      * @since JWare/AntX 0.5
176      **/

177     public void testDefaultsHandlerInAntScript_AntX05()
178     {
179         runTarget("testInstallDefaultsHandler_AntX05");
180     }
181
182
183     /**
184      * Ensures the general "getDefault" API can extract inlined defaults.
185      * @since JWare/AntX 0.5
186      **/

187     public void testDefaultsValueApiCanExtractInlineDefaults_AntX05()
188     {
189         final Project myproject = getProject();
190         myproject.setProperty("defaults.licenses","MIT");
191         
192         ValueURIHandler out = newOUT();
193         String JavaDoc result = out.getDefaultValue("$df:licenses?GPL",m_rqlink);
194         assertEqual(result,"GPL","getDefault('$df:licenses?GPL')");
195
196         myproject.setProperty("fallback","CollabNet");
197         result = out.getDefaultValue("$df:licenses?@(fallback)",m_rqlink);
198         assertEqual(result,"CollabNet","getDefault('$df:licenses?@(fallback)') where $fallback=CollabNet");
199     }
200 }
201
202 /* end-of-DefaultsValueURIHandlerTest.java */
Popular Tags