KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: NewRefIdValueURIHandlerTest.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.ExportedProperties;
34 import com.idaremedia.antx.FixtureExaminer;
35 import com.idaremedia.antx.ValueURIHandler;
36 import com.idaremedia.antx.helpers.SIDs;
37 import com.idaremedia.antx.valueuri.NewRefIdValueURIHandler;
38
39 /**
40  * Testsuite for {@linkplain NewRefIdValueURIHandler}.
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 NewRefIdValueURIHandlerTest 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 NewRefIdValueURIHandlerTest(String JavaDoc methodname)
56     {
57         super("NewRefIdValueURIHandler::",methodname);
58     }
59
60
61     /**
62      * Returns full test suite for NewRefIdValueURIHandler.
63      **/

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

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

82     /**
83      * Common new refid verification checks.
84      * @param refid the newly generated reference (before anything else done!)
85      * @param XpectedPrefix expected prefix of new refid (non-null)
86      **/

87     private void verifyNewRefId(String JavaDoc refid, String JavaDoc XpectedPrefix)
88     {
89         assertNotNil(refid,"a refid generated");
90         assertFalse(getProject().getReferences().containsKey(refid));
91         assertTrue(refid.startsWith(XpectedPrefix),"Prefixed with '"+XpectedPrefix+"'");
92     }
93
94
95     /**
96      * Common new pending refid verification checks.
97      * @param refid the newly generated reference (before anything else done!)
98      * @param XpectedPrefix expected prefix of new refid (non-null)
99      **/

100     private void verifyNewPendingRefId(String JavaDoc refid, String JavaDoc XpectedPrefix)
101     {
102         assertNotNil(refid,"a refid generated");
103         assertIdent(getProject().getReferences().get(refid),FixtureExaminer.PENDING_REFERENCE);
104         assertTrue(refid.startsWith(XpectedPrefix),"Prefixed with '"+XpectedPrefix+"'");
105     }
106
107
108     /**
109      * Verify we can generate a project-unique reference always.
110      * @since JWare/AntX 0.5
111      **/

112     public void testBaseline_AntX05()
113     {
114         checkBaseline();
115
116         ValueURIHandler out = newOUT();
117         String JavaDoc refid = out.valueFrom("","$newrefid:",m_rqlink);
118         verifyNewRefId(refid,"refid");
119
120         String JavaDoc varname = SIDs.next("var");
121         refid = out.valueFrom("?"+varname,"$newrefid:?"+varname,m_rqlink);
122         verifyNewPendingRefId(refid,"refid");
123     }
124
125
126     /**
127      * Verifies we can generate references prefixed with custom
128      * strings.
129      * @since JWare/AntX 0.5
130      **/

131     public void testAllowCustomPrefixed_AntX05()
132     {
133         ValueURIHandler out = newOUT();
134         String JavaDoc refid = out.valueFrom("test","$newrefid:test",m_rqlink);
135         verifyNewRefId(refid,"test");
136         refid = out.valueFrom("test2?","$newrefid:test2?",m_rqlink);
137         verifyNewRefId(refid,"test2");
138     }
139
140
141     /**
142      * Verify we can embed property references into refid value
143      * URIs.
144      * @since JWare/AntX 0.5
145      **/

146     public void testEmbeddedPropertyRefs_AntX05()
147     {
148         getProject().setProperty("seekrit","ssshhh");
149         ValueURIHandler out = newOUT();
150         String JavaDoc refid0 = out.valueFrom("@(seekrit)","$newrefid:@(seekrit)",m_rqlink);
151         verifyNewRefId(refid0,"ssshhh");
152         String JavaDoc refid1 = out.valueFrom("@(seekrit)?ignore","$newrefid:@(seekrit)?ignore",m_rqlink);
153         verifyNewPendingRefId(refid1,"ssshhh");
154         assertNotEqual(refid1,refid0,"Second generated reference");
155     }
156
157
158     /**
159      * Verify we can automatically fillin a variable with
160      * value of new refid.
161      * @since JWare/AntX 0.5
162      **/

163     public void testCanSetVariableToNewRefId_AntX05()
164     {
165         String JavaDoc varname = SIDs.next("var");
166         ValueURIHandler out = newOUT();
167         String JavaDoc refid = out.valueFrom("abc?"+varname,"$newrefid:abc?"+varname,m_rqlink);
168         verifyNewPendingRefId(refid,"abc");
169         assertTrue(ExportedProperties.has(varname),"var("+varname+") created");
170
171         varname = SIDs.next("var");
172         assertFalse(ExportedProperties.has(varname));
173         refid = out.valueFrom("?"+varname,"$newrefid:?"+varname,m_rqlink);
174         verifyNewPendingRefId(refid,"refid");
175         assertTrue(ExportedProperties.has(varname),"var("+varname+") created");
176     }
177 }
178
179 /* end-of-NewRefIdValueURIHandlerTest.java */
Popular Tags