KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

59     public PasswordValueURIHandlerTest(String JavaDoc methodname)
60     {
61         super("PasswordValueURIHandler::",methodname);
62     }
63
64
65     /**
66      * Returns full test suite for PasswordValueURIHandler.
67      **/

68     public static TestSuite suite()
69     {
70         return new TestSuite(PasswordValueURIHandlerTest.class);
71     }
72
73 // ---------------------------------------------------------------------------------------------------------
74
// --------------------------------------- [ Misc Factory Methods ] ----------------------------------------
75
// ---------------------------------------------------------------------------------------------------------
76

77     private static final String JavaDoc PASSWORDSMAP = "build.passwords";
78     private static final String JavaDoc DEFAULTPASSWORD = "defaults.password";
79
80
81     protected String JavaDoc xmlTestFile()
82     {
83         return "password.xml";
84     }
85
86     protected ValueURIHandler newOUT()
87     {
88         return new PasswordValueURIHandler();
89     }
90
91     protected void setUp() throws Exception JavaDoc
92     {
93         super.setUp();
94
95         Project myproject = getProject();
96         assertNil(myproject.getProperty(PASSWORDSMAP),"'build.passwords' property");
97         assertNil(myproject.getProperty(DEFAULTPASSWORD),"'defaults.password' property");
98         assertNil(myproject.getReference(PASSWORDSMAP),"'build.passwords' reference");
99
100         Iteration.initValueURIHandler("default",DefaultsValueURIHandler.class);
101         Iteration.initValueURIHandler("df",DefaultsValueURIHandler.class);
102     }
103
104 // ---------------------------------------------------------------------------------------------------------
105
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
106
// ---------------------------------------------------------------------------------------------------------
107

108     /**
109      * Verify a blank uri fragment is evaluated as null.
110      * @since JWare/AntX 0.5
111      **/

112     public void testBaseline_AntX05()
113     {
114         checkBaseline();
115
116         String JavaDoc result = newOUT().valueFrom("","$password:",m_rqlink);
117         assertNil(result,"$password:");
118     }
119
120
121     /**
122      * Verify the capitalization of the key is unimportant.
123      * @since JWare/AntX 0.5
124      **/

125     public void testFallbackOnDefaultsPassword_AntX05()
126     {
127         Project myproject = getProject();
128
129         ValueURIHandler out = newOUT();
130         String JavaDoc userid = SIDs.next("user");
131         String JavaDoc result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
132         assertNil(result,"$password:"+userid);
133
134         myproject.setProperty(DEFAULTPASSWORD,"superseekrit");
135         result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
136         assertEqual(result,"superseekrit","$password:"+userid+"(defaults)");
137         
138         Properties JavaDoc passwords = new Properties JavaDoc();
139         passwords.setProperty("user0","password0");
140         myproject.addReference(PASSWORDSMAP,passwords);
141
142         result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
143         assertEqual(result,"superseekrit","$password:"+userid+"(passwords+defaults)");
144     }
145
146
147
148     /**
149      * Verify that if both a default password and a build.passwords
150      * property set are defined, the build.passwords win (if a match
151      * found).
152      * @since JWare/AntX 0.5
153      **/

154     public void testBuildPasswordsBlocksDefaultsPassword_AntX05()
155     {
156         String JavaDoc userid = SIDs.next("user");
157         String JavaDoc password= SIDs.next("pw");
158         
159         Project myproject = getProject();
160         myproject.setProperty(DEFAULTPASSWORD,"superseekrit");
161
162         Properties JavaDoc passwords = new Properties JavaDoc();
163         passwords.setProperty("user0","password0");
164         passwords.setProperty("user1","password1");
165         passwords.setProperty(userid,password);
166         myproject.addReference(PASSWORDSMAP,passwords);
167
168         ValueURIHandler out = newOUT();
169         String JavaDoc result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
170         assertEqual(result,password,"$password:"+userid);
171
172         passwords.setProperty(userid,password+"-delta");
173         result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
174         assertEqual(result,password+"-delta","$password:"+userid);
175     }
176
177
178     /**
179      * Verify that an unrecognized data type stored under the
180      * 'build.passwords' refid, is ignored.
181      * @since JWare/AntX 0.5
182      **/

183     public void testIllegalBuildPasswordsTypesIgnored_AntX05()
184     {
185         Project myproject = getProject();
186         myproject.addReference(PASSWORDSMAP, new Thingy());
187
188         String JavaDoc userid = SIDs.next("user");
189         ValueURIHandler out = newOUT();
190         String JavaDoc result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
191         assertNil(result,"$password:"+userid+"(badtype passwords)");
192
193         myproject.setProperty(DEFAULTPASSWORD,"lightweight");
194         result = out.valueFrom(userid,"$password:"+userid,m_rqlink);
195         assertEqual(result,"lightweight","$password:"+userid+"(badtype passwords+defaults)");
196     }
197
198
199     /**
200      * Verify handler resolve property references in fragment
201      * before looking up name.
202      * @since JWare/AntX 0.5
203      **/

204     public void testPropertyRefsInterpreted_AntX05()
205     {
206         runTarget("testPropertyRefsInterpreted_AntX05");
207     }
208
209
210     /**
211      * Verifies that a cleartext password file in:
212      * $user&#46;home/&#46;ant/build&#46;passwords used as a
213      * fallback measure.
214      **/

215     public void testUserHomePasswordFileUsed_AntX05()
216     {
217         runTarget("testUserHomePasswordFileUsed_AntX05");
218     }
219
220
221     /**
222      * Verifies that a password file pointed to by the standard
223      * AntX passwordfile defaults setting is used.
224      * @since JWare/AntX 0.5
225      */

226     public void testDefaultsPasswordFileOptionUsed_AntX05()
227     {
228         runTarget("testDefaultsPasswordFileOptionUsed_AntX05");
229     }
230
231
232     /**
233      * Verifies the order in which handler searches for
234      * password files.
235      * @since JWare/AntX 0.5
236      */

237     public void testSearchOrdering_AntX05()
238     {
239         runTarget("testSearchOrdering_AntX05");
240     }
241
242
243     /**
244      * Ensure we install a reference to a "thing" no one else
245      * could know about.
246      */

247     private static class Thingy {
248         private Thingy() {}
249     }
250 }
251
252 /* end-of-DefaultsValueURIHandlerTest.java */
Popular Tags