1 20 package org.enhydra.barracuda.taskdefs; 21 22 import junit.framework.TestCase; 24 25 import org.apache.log4j.Logger; 27 28 import java.io.File ; 30 import java.io.IOException ; 31 32 import org.enhydra.xml.xmlc.taskdef.*; 33 34 import org.enhydra.barracuda.testbed.*; 35 36 40 public class TestFileNames extends DefaultTestCase { 41 42 46 51 public TestFileNames( String theName) { 52 super( theName ); 53 } 54 55 59 protected void setUp() throws Exception { 60 super.setUp(); 61 } 62 63 67 protected void tearDown() throws Exception { 68 super.tearDown(); 69 } 70 71 public void testBasicBuildFullBaseFileName() throws IOException { 75 XmlcUtils xmlcUtils = XmlcUtils.create(); 76 77 String baseFilename = "base"; 78 String newBaseFileName = xmlcUtils.buildFullBaseFileName( null, null, baseFilename ); 79 assertEquals("Name should be unchanged", baseFilename, newBaseFileName ); 80 81 baseFilename = "base.html"; 82 String expectedBaseFileName = "base"; 83 newBaseFileName = xmlcUtils.buildFullBaseFileName( null, null, baseFilename ); 84 assertEquals("Type should be stripped off", expectedBaseFileName, newBaseFileName ); 85 } 86 87 public void testPackageNameBuildFullBaseFileName() throws IOException { 88 XmlcUtils xmlcUtils = XmlcUtils.create(); 89 90 String baseFilename = "base"; 91 92 String packageName = "a"; 93 String expectedBaseFileName = "a/" + baseFilename; 94 String newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 95 assertEquals("Name 0 should be as expected", 96 expectedBaseFileName, 97 newBaseFileName ); 98 99 packageName = ""; 100 expectedBaseFileName = baseFilename; 101 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 102 assertEquals("Name should be unchanged", 103 expectedBaseFileName, 104 newBaseFileName ); 105 106 packageName = "a.b.c.d"; 107 expectedBaseFileName = "a/b/c/d/" + baseFilename; 108 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 109 assertEquals("Name 1 should be as expected", 110 expectedBaseFileName, 111 newBaseFileName ); 112 113 packageName = "p1.p2.p3.p4.p5."; 114 expectedBaseFileName = "p1/p2/p3/p4/p5/" + baseFilename; 115 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 116 assertEquals("Name 2 should be as expected", 117 expectedBaseFileName, 118 newBaseFileName ); 119 120 baseFilename = "/test1/test2/test3/base"; 121 packageName = ""; 122 expectedBaseFileName = baseFilename; 123 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 124 assertEquals("Name should be unchanged again", 125 expectedBaseFileName, 126 newBaseFileName ); 127 128 packageName = "a.b.c.d."; 129 expectedBaseFileName = "a/b/c/d" + baseFilename; 130 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, null, baseFilename ); 131 assertEquals("Name 3 should be as expected", 132 expectedBaseFileName, 133 newBaseFileName ); 134 } 135 136 public void testPackageDirBuildFullBaseFileName() throws IOException { 137 XmlcUtils xmlcUtils = XmlcUtils.create(); 138 139 String baseFilename = "base"; 140 String packageDir = "a"; 141 String expectedBaseFileName = "a/" + baseFilename; 142 String newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename ); 143 assertEquals("Name 0 should be as expected", 144 expectedBaseFileName, 145 newBaseFileName ); 146 147 baseFilename = "test.base"; 148 packageDir = ""; 149 expectedBaseFileName = "test"; 150 newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename ); 151 assertEquals("Name 1 should be as expected", 152 expectedBaseFileName, 153 newBaseFileName ); 154 155 baseFilename = "\\base"; 156 packageDir = "a/"; 157 expectedBaseFileName = "a/" + "base"; 158 newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename ); 159 assertEquals("Name 2 should be as expected", 160 expectedBaseFileName, 161 newBaseFileName ); 162 163 baseFilename = "/test1/test2/test3/base"; 164 packageDir = "a/b/c/d"; 165 expectedBaseFileName = "a/b/c/d/" + "base"; 166 newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename ); 167 assertEquals("Name 3 should be as expected", 168 expectedBaseFileName, 169 newBaseFileName ); 170 171 baseFilename = "test1\\test2/test3\\base/"; 172 packageDir = "\\a/b\\c/d\\"; 173 expectedBaseFileName = "/a/b/c/d/" + "base"; 174 newBaseFileName = xmlcUtils.buildFullBaseFileName( null, packageDir, baseFilename ); 175 assertEquals("Name 4 should be as expected", 176 expectedBaseFileName, 177 newBaseFileName ); 178 } 179 180 public void testBuildFullBaseFileName() throws IOException { 181 XmlcUtils xmlcUtils = XmlcUtils.create(); 182 183 String baseFilename = "base"; 184 String packageName = "packageName"; 185 String packageDir = "packageDir"; 186 String expectedBaseFileName = packageName + "/" + packageDir + "/" + baseFilename; 187 String newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename ); 188 assertEquals("Name 0 should be as expected", 189 expectedBaseFileName, 190 newBaseFileName ); 191 192 baseFilename = "/dir1/dir2/dir3/base.test.test"; 193 packageName = "name1.name2.name3...."; 194 packageDir = "/dirA/dirB/dirc/"; 195 expectedBaseFileName = "name1/name2/name3" + packageDir + "base"; 196 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename ); 197 assertEquals("Name 1 should be as expected", 198 expectedBaseFileName, 199 newBaseFileName ); 200 201 baseFilename = "/dir1/dir2/dir3/base.test.test"; 202 packageName = "name1.name2.name3...."; 203 packageDir = ""; 204 expectedBaseFileName = "name1/name2/name3/" + "dir1/dir2/dir3/base"; 205 newBaseFileName = xmlcUtils.buildFullBaseFileName( packageName, packageDir, baseFilename ); 206 assertEquals("Name 2 should be as expected", 207 expectedBaseFileName, 208 newBaseFileName ); 209 } 210 211 public void testBuildClassName() throws IOException { 212 XmlcUtils xmlcUtils = XmlcUtils.create(); 213 214 String filename = "p1/p2/p3/base"; 215 String typeModifier = "HTML"; 216 String expectedClassName = "p1.p2.p3.baseHTML"; 217 String newClassName = xmlcUtils.buildClassName( filename, typeModifier ); 218 assertEquals("Class 0 should be as expected", 219 expectedClassName, 220 newClassName ); 221 } 222 223 224 228 232 private static final Logger theirLogger = Logger.getLogger( TestFileNames.class.getName() ); 234 235 } 236 | Popular Tags |