1 16 17 22 package test.wsdl.filegen; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.util.Arrays ; 27 import java.util.HashSet ; 28 import java.util.Set ; 29 import java.util.Vector ; 30 31 32 public class FileGenTestCase extends junit.framework.TestCase { 33 public FileGenTestCase(String name) { 34 super(name); 35 } 36 37 40 protected Set shouldExist() { 41 HashSet set = new HashSet (); 42 set.add("AllOptionTestCase.java"); 43 set.add("FileGenTestCase.java"); 44 set.add("OpFault.java"); 45 set.add("PortTypeSoap.java"); 46 set.add("ReferenceService.java"); 47 set.add("ReferenceServiceLocator.java"); 48 set.add("ReferenceSoapBindingStub.java"); 49 return set; 50 } 51 52 55 protected Set mayExist() { 56 HashSet set = new HashSet (); 57 return set; 58 } 59 60 63 protected String rootDir() { 64 return "build" + File.separator + "work" + File.separator + 65 "test" + File.separator + "wsdl" + File.separator + 66 "filegen"; 67 } 68 69 protected String getPrefix(String parent) { 70 if (parent == null || parent.length() == 0) { 71 return ""; 72 } 73 else { 74 return parent + File.separator; 75 } 76 } 77 78 85 protected String [] getPaths(File root, String parent) { 86 File files[] = root.listFiles(); 87 Set filePaths = new HashSet (); 88 for(int i=0; i<files.length; i++) { 89 if (files[i].isDirectory()) { 90 String children[] = getPaths(files[i], 91 getPrefix(parent) + files[i].getName()); 92 filePaths.addAll(Arrays.asList(children)); 93 } 94 else { 95 filePaths.add(getPrefix(parent) + files[i].getName()); 96 } 97 } 98 String paths[] = new String [filePaths.size()]; 99 return (String []) filePaths.toArray(paths); 100 } 101 102 103 public void testFileGen() throws IOException { 104 String rootDir = rootDir(); 105 Set shouldExist = shouldExist(); 106 Set mayExist = mayExist(); 107 108 File outputDir = new File (rootDir); 110 111 String [] files = getPaths(outputDir, null); 112 113 Vector shouldNotExist = new Vector (); 114 115 for (int i = 0; i < files.length; ++i) { 116 if (shouldExist.contains(files[i])) { 117 shouldExist.remove(files[i]); 118 } 119 else if (mayExist.contains(files[i])) { 120 mayExist.remove(files[i]); 121 } 122 else { 123 shouldNotExist.add(files[i]); 124 } 125 } 126 127 if (shouldExist.size() > 0) { 128 fail("The following files should exist in " + rootDir + 129 ", but do not: " + shouldExist); 130 } 131 132 if (shouldNotExist.size() > 0) { 133 fail("The following files should NOT exist in " + rootDir + 134 ", but do: " + shouldNotExist); 135 } 136 } 137 } 138 139 | Popular Tags |