KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: DefaultsPropertyNameURIHandlerTest.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.AntX;
34 import com.idaremedia.antx.Defaults;
35 import com.idaremedia.antx.Iteration;
36 import com.idaremedia.antx.ValueURIHandler;
37 import com.idaremedia.antx.helpers.SIDs;
38 import com.idaremedia.antx.valueuri.info.DefaultsPropertyNameURIHandler;
39
40 /**
41  * Testsuite for {@linkplain XDefCheckValueURIHandler}.
42  *
43  * @since JWare/AntX 0.5
44  * @author ssmc, &copy;2005 <a HREF="http://www.jware.info">iDare&nbsp;Media,&nbsp;Inc.</a>
45  * @version 0.5
46  * @.safety single
47  * @.group impl,test
48  **/

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

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

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

74     protected ValueURIHandler newOUT()
75     {
76         return new DefaultsPropertyNameURIHandler();
77     }
78
79 // ---------------------------------------------------------------------------------------------------------
80
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
81
// ---------------------------------------------------------------------------------------------------------
82

83
84     /**
85      * Verify a blank uri fragment evaluates <i>null</i>.
86      * @since JWare/AntX 0.5
87      **/

88     public void testBaseline_AntX05()
89     {
90         checkBaseline();
91         
92         ValueURIHandler out = newOUT();
93         String JavaDoc result = out.valueFrom("","$defaultsproperty:",m_rqlink);
94         assertNil(result,"$defaultsproperty:");
95     }
96
97
98
99     /**
100      * Verify an unrecognized defaults attribute evaluates <i>null</i>.
101      * @since JWare/AntX 0.5
102      **/

103     public void testUnknownDefaultsAttributeIsNull_AntX05()
104     {
105         ValueURIHandler out = newOUT();
106         String JavaDoc propertyname = SIDs.next("defaults.");
107         String JavaDoc result = out.valueFrom(propertyname,"$defaultsproperty:"+propertyname,m_rqlink);
108         assertNil(result,"$defaultsproperty:[no-such-default]");
109     }
110
111
112
113     /**
114      * Verify handler returns correct results for some known
115      * default property names.
116      * @since JWare/AntX 0.5
117      **/

118     public void testFixedDefaultPropertyNames_AntX05()
119     {
120         ValueURIHandler out = newOUT();
121         String JavaDoc result = out.valueFrom("noiselevel","$defaultsproperty:noiselevel",m_rqlink);
122         assertEqual(result,AntX.DEFAULT_NOISELEVEL_PROP,"$defaultproperty:noiselevel");
123     }
124
125
126
127     /**
128      * Verifies that the handler can deal with non-standard Iteration
129      * subclasses and returns iteration-specific property names when
130      * should.
131      * @since JWare/AntX 0.5
132      **/

133     public void testConfigIdDependentPropertyNames_AntX05()
134     {
135         Defaults defaults = Iteration.defaultdefaults();
136         ValueURIHandler out = newOUT();
137         String JavaDoc result = out.valueFrom("assertions","$defaultsproperty:assertions",m_rqlink);
138         assertEqual(result,defaults.isAssertionsDisabledName(),"$defaultsproperty:assertions");
139         result = out.valueFrom("haltiferror.myzone","$defaultsproperty:haltiferror.myzone",m_rqlink);
140         assertEqual(result,defaults.isHaltIfErrorName("myzone"),
141                     "$defaultsproperty:haltiferror.myzone");
142
143         assertNotEqual(Iteration.configId(),"throadwobblermangrove","Real Iteration ConfigId");
144         Iteration.set(new MyIteration());
145         try {
146             assertEqual(Iteration.configId(),"throatwobblermangrove","Test Iteration ConfigId");
147             Defaults mydefaults = Iteration.defaultdefaults();
148             assertNotIdent(mydefaults,defaults,"Iteration.Defaults");
149             result = out.valueFrom("passwordfile","$defaultsproperty:passwordfile",m_rqlink);
150             assertEqual(result,mydefaults.passwordFileLocationName(),"$defaultsproperty:passwordfile");
151             assertTrue(result.startsWith("throatwobblermangrove"));
152         } finally {
153             Iteration.reset();
154         }
155     }
156
157
158     private static class MyIteration extends Iteration
159     {
160         private MyIteration() {
161         }
162         protected String JavaDoc getConfigId() {
163             return "throatwobblermangrove";
164         }
165     }
166 }
167
168 /* end-of-DefaultsPropertyNameURIHandlerTest.java */
Popular Tags