1 16 17 18 package test; 19 20 import org.custommonkey.xmlunit.XMLTestCase; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import java.util.Set ; 25 import java.util.HashSet ; 26 import java.util.Arrays ; 27 import java.util.Vector ; 28 29 32 public abstract class AxisFileGenTestBase extends AxisTestBase { 33 34 public AxisFileGenTestBase(String s) { 35 super(s); 36 } 37 38 protected String getPrefix(String parent) { 39 if (parent == null || parent.length() == 0) { 40 return ""; 41 } 42 else { 43 return parent + File.separator; 44 } 45 } 46 47 abstract protected Set mayExist(); 48 abstract protected String rootDir(); 49 abstract protected Set shouldExist(); 50 51 58 protected String [] getPaths(File root, String parent) { 59 File files[] = root.listFiles(); 60 if (files == null) 61 fail("Unable to get a list of files from " + root.getPath()); 62 63 Set filePaths = new HashSet (); 64 for(int i=0; i<files.length; i++) { 65 if (files[i].isDirectory()) { 66 String children[] = getPaths(files[i], 67 getPrefix(parent) + files[i].getName()); 68 filePaths.addAll(Arrays.asList(children)); 69 } 70 else { 71 filePaths.add(getPrefix(parent) + files[i].getName()); 72 } 73 } 74 String paths[] = new String [filePaths.size()]; 75 return (String []) filePaths.toArray(paths); 76 } 77 78 79 public void testFileGen() throws IOException { 80 String rootDir = rootDir(); 81 Set shouldExist = shouldExist(); 82 Set mayExist = mayExist(); 83 84 File outputDir = new File (rootDir); 86 87 String [] files = getPaths(outputDir, null); 88 89 Vector shouldNotExist = new Vector (); 90 91 for (int i = 0; i < files.length; ++i) { 92 if (shouldExist.contains(files[i])) { 93 shouldExist.remove(files[i]); 94 } 95 else if (mayExist.contains(files[i])) { 96 mayExist.remove(files[i]); 97 } 98 else { 99 shouldNotExist.add(files[i]); 100 } 101 } 102 103 if (shouldExist.size() > 0) { 104 fail("The following files should exist in " + rootDir + 105 ", but do not: " + shouldExist); 106 } 107 108 if (shouldNotExist.size() > 0) { 109 fail("The following files should NOT exist in " + rootDir + 110 ", but do: " + shouldNotExist); 111 } 112 } 113 } 114 | Popular Tags |