KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > taskdefs > TestLocalizeFileNames


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: TestLocalizeFileNames.java,v 1.8 2004/02/01 05:16:33 christianc Exp $
19  */

20 package org.enhydra.barracuda.taskdefs;
21
22 // import junit specifics
23
import junit.framework.TestCase;
24
25 // import logging specifics
26
import org.apache.log4j.Logger;
27
28 // import java specifics
29
import java.io.File JavaDoc;
30 import java.io.IOException JavaDoc;
31
32 import org.enhydra.xml.xmlc.taskdef.*;
33
34 import org.enhydra.barracuda.testbed.*;
35
36 /**
37  * Unit tests for buildClassName() method of LocalizeXmlcUtilsImpl
38  */

39 public class TestLocalizeFileNames extends DefaultTestCase {
40
41   //===========================================================================
42
// CONSTRUCTORS
43
//===========================================================================
44

45     /**
46      * Default constructor
47      *
48      * @param theName The name of the test
49      */

50     public TestLocalizeFileNames( String JavaDoc theName) {
51         super( theName );
52     }
53
54     /**
55      * Sets up the fixture, for example, open a network connection.
56      * This method is called before a test is executed.
57      */

58     protected void setUp() throws Exception JavaDoc {
59         super.setUp();
60         // save default xmlc utils class
61
this.myOriginalDefautlUtilsClass =
62           System.getProperty( XmlcUtils.DEFAULT_UTILS_CLASS_KEY, "" );
63         System.setProperty(XmlcUtils.DEFAULT_UTILS_CLASS_KEY,
64                        LocalizeXmlcUtilsImpl.class.getName());
65     }
66
67     /**
68      * Tears down the fixture, for example, close a network connection.
69      * This method is called after a test is executed.
70      */

71     protected void tearDown() throws Exception JavaDoc {
72         super.tearDown();
73
74         // restore default xmlc utils class
75
System.setProperty(XmlcUtils.DEFAULT_UTILS_CLASS_KEY,
76                        this.myOriginalDefautlUtilsClass);
77     }
78
79     //===========================================================================
80
// TEST METHODS
81
//===========================================================================
82
public void testBuildClassName() throws IOException JavaDoc {
83         XmlcUtils xmlcUtils = XmlcUtils.create();
84         assertEquals( "Should have localize implementation",
85                       LocalizeXmlcUtilsImpl.class,
86                       xmlcUtils.getClass() );
87
88         String JavaDoc filename = "config";
89         String JavaDoc typeModifier = "HTML";
90         String JavaDoc expectedClassName = "configHTML";
91         String JavaDoc newClassName = xmlcUtils.buildClassName( filename, typeModifier );
92         assertEquals("Class 0 should be as expected",
93                      expectedClassName,
94                      newClassName );
95
96         filename = "config_aa";
97         expectedClassName = "configHTML_aa";
98         newClassName = xmlcUtils.buildClassName( filename, typeModifier );
99         assertEquals("Class 1 should be as expected",
100                      expectedClassName,
101                      newClassName );
102
103         filename = "config_test";
104         expectedClassName = "config_testHTML";
105         newClassName = xmlcUtils.buildClassName( filename, typeModifier );
106         assertEquals("Class 2 should be as expected",
107                      expectedClassName,
108                      newClassName );
109
110         filename = "config_eng";
111         expectedClassName = "config_engHTML";
112         newClassName = xmlcUtils.buildClassName( filename, typeModifier );
113         assertEquals("Class 3 should be as expected",
114                      expectedClassName,
115                      newClassName );
116
117         filename = "config_aaab";
118         expectedClassName = "config_aaabHTML";
119         newClassName = xmlcUtils.buildClassName( filename, typeModifier );
120         assertEquals("Class 4 should be as expected",
121                      expectedClassName,
122                      newClassName );
123
124         filename = "name1/name2/name1/name2/config_zu";
125         expectedClassName = "name1.name2.name1.name2.configHTML_zu";
126         newClassName = xmlcUtils.buildClassName( filename, typeModifier );
127         assertEquals("Class 5 should be as expected",
128                      expectedClassName,
129                      newClassName );
130     }
131
132
133     //===========================================================================
134
// DATA MEMBERS
135
//===========================================================================
136
private String JavaDoc myOriginalDefautlUtilsClass;
137
138     //===========================================================================
139
// STATIC DATA MEMBERS
140
//===========================================================================
141
// setup the loggger for this class
142
private static final Logger theirLogger = Logger.getLogger( TestLocalizeFileNames.class.getName() );
143
144 }
145
Popular Tags