KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $Id: BasenameValueURIHandlerTest.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.io.File JavaDoc;
32
33 import org.apache.tools.ant.taskdefs.condition.Os;
34
35 import junit.framework.TestSuite;
36
37 import com.idaremedia.antx.ValueURIHandler;
38 import com.idaremedia.antx.valueuri.BasenameValueURIHandler;
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 BasenameValueURIHandlerTest 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 BasenameValueURIHandlerTest(String JavaDoc methodname)
57     {
58         super("BasenameValueURIHandler::",methodname);
59         isWindoze = Os.isFamily("windows");
60     }
61
62
63     /**
64      * Returns full test suite for BasenameValueURIHandler.
65      **/

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

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

84     /**
85      * Verify an empty path fragment is evaluated as project's basedir.
86      * @since JWare/AntX 0.5
87      **/

88     public void testBaseline_AntX05()
89     {
90         checkBaseline();
91
92         File JavaDoc basedir = getProject().getBaseDir();
93         assertNotNil(basedir,"project basedir");
94         
95         ValueURIHandler out = newOUT();
96         String JavaDoc blankresult = out.valueFrom("","$basename:",m_rqlink);
97         String JavaDoc basepath = basedir.getPath();
98         String JavaDoc baseresult = out.valueFrom(basepath,"$basename:"+basepath,m_rqlink);
99         assertEqual(blankresult,baseresult,"$basename:");
100         blankresult = out.valueFrom("?.foo","$basename:?.foo",m_rqlink);
101         assertEqual(blankresult,baseresult,"$basename:?.foo");
102     }
103
104
105     /**
106      * Verify the basename of "/" is an empty string.
107      * @since JWare/AntX 0.5
108      **/

109     public void testRootPathIsBlankBasename_AntX05()
110     {
111         ValueURIHandler out = newOUT();
112         String JavaDoc slash = isWindoze ? "\\" : "/";
113         String JavaDoc result = out.valueFrom(slash,"$basename:"+slash,m_rqlink);
114         assertEqual(result,"","$basename:"+slash);
115     }
116
117
118     /**
119      * Verify basename of /-terminated path works as expected.
120      * @since JWare/AntX 0.5
121      **/

122     public void testSlashTerminatedPath_AntX05()
123     {
124         ValueURIHandler out = newOUT();
125         String JavaDoc result= out.valueFrom("/fu/bar/","$basename:/fu/bar/",m_rqlink);
126         assertEqual(result,"bar","$basename:/fu/bar/");
127         if (isWindoze) {
128             result = out.valueFrom("\\fu\\bar\\","$basename:\\fu\\bar\\",m_rqlink);
129             assertEqual(result,"bar","$basename:\\fu\\bar\\");
130         }
131     }
132
133
134     /**
135      * Verify can strip the extension of a file name.
136      * @since JWare/AntX 0.5
137      */

138     public void testCanStripSuffix_AntX05()
139     {
140         ValueURIHandler out = newOUT();
141         String JavaDoc result = out.valueFrom("/xml/file.xml?xml","$basename:/xml/file.xml?xml",m_rqlink);
142         assertEqual(result,"file","$basename:/xml/file.xml?xml");
143         result = out.valueFrom("/xml/file.xml?.xml","$basename:/xml/file.xml?.xml",m_rqlink);
144         assertEqual(result,"file","$basename:/xml/file.xml?.xml");
145         result = out.valueFrom("/xml/file.xml?.XML","$basename:/xml/file.xml?.XML",m_rqlink);
146         assertEqual(result,"file.xml","$basename:/xml/file.xml?.XML");
147         result = out.valueFrom("/a/dir/fubar-libs?-libs","$basename:/a/dir/fubar-libs?-libs",m_rqlink);
148         assertEqual(result,"fubar","$basename:/a/dir/fubar-libs?-libs");
149     }
150
151
152     /**
153      * Verify that handler dereferences properties as expected.
154      * @since JWare/AntX 0.5
155      **/

156     public void testEmbeddedPropertyRefsHandled_AntX05()
157     {
158         ValueURIHandler out = newOUT();
159         String JavaDoc result = out.valueFrom("@(basedir)","$basename:@(basedir)",m_rqlink);
160         String JavaDoc basepath = getProject().getBaseDir().getPath();
161         String JavaDoc baseresult = out.valueFrom(basepath,"$basename:"+basepath,m_rqlink);
162         assertEqual(result,baseresult,"$basename:@(basedir)");
163         
164         getProject().setProperty("ext","-lib");
165         result = out.valueFrom("/fu/bar-lib/?@(ext)","$basename:/fu/bar-lib/?@(ext)",m_rqlink);
166         assertEqual(result,"bar","$basename:/fu/bar-lib/?@(ext)");
167     }
168
169
170     private final boolean isWindoze;
171 }
172
173 /* end-of-BasenameValueURIHandlerTest.java */
Popular Tags