KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

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

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

75     protected String JavaDoc xmlTestFile()
76     {
77         return "listfriendly.xml";
78     }
79
80     protected ValueURIHandler newOUT()
81     {
82         return new ListFriendlyValueURIHandler();
83     }
84     
85     protected void setUp() throws Exception JavaDoc
86     {
87         super.setUp();
88         StringList sl = new StringList();
89         sl.setId("abBCd");
90         sl.addConfiguredString(new InnerString("a"));
91         sl.addConfiguredString(new InnerString("bB"));
92         sl.addConfiguredString(new InnerString("C"));
93         sl.addConfiguredString(new InnerString("d"));
94         getProject().addReference(sl.getId(),sl);
95         getProject().addReference("1,2,3","ERROR");
96     }
97
98 // ---------------------------------------------------------------------------------------------------------
99
// ------------------------------------------- [ The Test Cases ] ------------------------------------------
100
// ---------------------------------------------------------------------------------------------------------
101

102     /**
103      * Verify a blank uri fragment is evaluated as expected.
104      * @since JWare/AntX 0.5
105      **/

106     public void testBaseline_AntX05()
107     {
108         checkBaseline();
109         
110         assertNotNil(getProject().getReference("abBCd"),"abBCd reference");
111         ValueURIHandler out = newOUT();
112         String JavaDoc result = out.valueFrom("a,b,c","$list:a,b,c",m_rqlink);
113         assertEqual(result,"a,b,c","$list:a,b,c");
114         result = out.valueFrom("abBCd","$list:abBCd",m_rqlink);
115         assertEqual(result,"a,bB,C,d","$list:abBCd");
116     }
117
118
119     /**
120      * Verify a blank or all whitespace uri fragment is evaluated as expected.
121      * @since JWare/AntX 0.5
122      **/

123     public void testBlank_AntX05()
124     {
125         ValueURIHandler out = newOUT();
126         String JavaDoc result;
127         result = out.valueFrom("","$list:",m_rqlink);
128         assertEqual(result,"","$list:");
129         result = out.valueFrom("?size","$list:?size",m_rqlink);
130         assertEqual(result,"0","$list:?size");
131         result = out.valueFrom(" ?size","$list: ?size",m_rqlink);
132         assertEqual(result,"0","$list: ?size");
133         result = out.valueFrom("[]","$list:[]",m_rqlink);
134         assertEqual(result,"","$list:[]");
135         assertEqual("",out.valueFrom("?values","$list:?values",m_rqlink),"$list:?values");
136         assertEqual("[]",out.valueFrom("?dump","$list:?dump",m_rqlink),"$list:?dump");
137         result = out.valueFrom("?1","$list:?1",m_rqlink);
138         assertNil(result,"$list:?1");
139         result = out.valueFrom("?ickyblorf","$list:?ickyblorf",m_rqlink);
140         assertNil(result,"$list:?ickyblorf");
141     }
142     
143     
144     /**
145      * Verify defining a custom delimiter for existing lists.
146      * @since JWare/AntX 0.5
147      **/

148     public void testCustomDelim_AntX05()
149     {
150         ValueURIHandler out = newOUT();
151         String JavaDoc result;
152         result = out.valueFrom("abBCd?values,,;","$list:abBCd?values,,;",m_rqlink);
153         assertEqual(result,"a;bB;C;d","$list:abBCd?values,,;");
154         result = out.valueFrom("x,y,z?values,,-","$list:x,y,z?values,,-",m_rqlink);
155         assertEqual(result,"x-y-z","$list:x,y,z?values,,-");
156         result = out.valueFrom("x,y,z?values,, ","$list:x,y,z?values,, ",m_rqlink);
157         assertEqual(result,"x y z","$list:x,y,z?values,, ");
158         result = out.valueFrom("[1,2,3]?,,|","$list:[1,2,3]?,,|",m_rqlink);
159         assertEqual(result,"1|2|3","$list:[1,2,3]?,,|");
160     }
161
162
163     /**
164      * Verify we can force handler to use query as an inlined string
165      * even if a reference of same name exists.
166      * @since JWare/AntX 0.5
167      **/

168     public void testSquareBracketsOverrideRefId_AntX05()
169     {
170         ValueURIHandler out = newOUT();
171         String JavaDoc result;
172         result = out.valueFrom("1,2,3","$list:1,2,3",m_rqlink);
173         assertNil(result,"$list:1,2,3");
174         result = out.valueFrom("[1,2,3]","$list:[1,2,3]",m_rqlink);
175         assertEqual(result,"1,2,3","$list:[1,2,3]");
176     }
177
178
179
180     /**
181      * Ensure the handler really is "List" friendly towards List classes
182      * that are not AntX-based.
183      * @since JWare/AntX 0.5
184      **/

185     public void testWorksForPlainListTypesToo_AntX05()
186     {
187         List JavaDoc l = AntXFixture.newList();
188         l.add("larry");
189         l.add("curly");
190         l.add("moe");
191         getProject().addReference("3stooges",l);
192
193         ValueURIHandler out = newOUT();
194         String JavaDoc result;
195         result = out.valueFrom("3stooges","$list:3stooges",m_rqlink);
196         assertEqual(result,"larry,curly,moe","$list:3stooges");
197         result = out.valueFrom("3stooges?values,,!","$list:3stooges?values,,!",m_rqlink);
198         assertEqual(result,"larry!curly!moe","$list:3stooges?values,,!");
199         result = out.valueFrom("3stooges?2","$list:3stooges?2",m_rqlink);
200         assertEqual(result,"moe","$list:3stooges?2");
201         result = out.valueFrom("3stooges?3","$list:3stooges?3",m_rqlink);
202         assertNil(result,"$list:3stooges?3");
203     }
204
205
206
207     /**
208      * Verify some things from within an Ant-only environment.
209      * @since JWare/AntX 0.5
210      **/

211     public void testListFriendlyHandlerScript_AntX05()
212     {
213         runTarget("testListFriendlyHandlerScript_AntX05");
214     }
215 }
216
217 /* end-of-ListFriendlyValueURIHandlerTest.java */
Popular Tags