1 16 17 22 package test.wsdl.groups; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 import java.lang.reflect.Method ; 27 import java.util.Arrays ; 28 import java.util.HashSet ; 29 import java.util.Set ; 30 31 32 public class GroupsTestCase extends junit.framework.TestCase { 33 public GroupsTestCase(String name) { 34 super(name); 35 } 36 37 40 protected Set shouldExist() { 41 HashSet set = new HashSet (); 42 set.add("GroupsTestCase.java"); 43 set.add("SomeType.java"); 44 return set; 45 } 46 47 50 protected Set shouldNotExist() { 51 HashSet set = new HashSet (); 52 set.add("SomeGroup.java"); 53 return set; 54 } 55 56 59 protected String rootDir() { 60 return "build" + File.separator + "work" + File.separator + 61 "test" + File.separator + "wsdl" + File.separator + 62 "groups"; 63 } 64 65 protected String getPrefix(String parent) { 66 if (parent == null || parent.length() == 0) { 67 return ""; 68 } 69 else { 70 return parent + File.separator; 71 } 72 } 73 74 81 protected String [] getPaths(File root, String parent) { 82 File files[] = root.listFiles(); 83 if (files == null) 84 fail("Unable to get a list of files from " + root.getPath()); 85 86 Set filePaths = new HashSet (); 87 for(int i=0; i<files.length; i++) { 88 if (files[i].isDirectory()) { 89 String children[] = getPaths(files[i], 90 getPrefix(parent) + files[i].getName()); 91 filePaths.addAll(Arrays.asList(children)); 92 } 93 else { 94 filePaths.add(getPrefix(parent) + files[i].getName()); 95 } 96 } 97 String paths[] = new String [filePaths.size()]; 98 return (String []) filePaths.toArray(paths); 99 } 100 101 102 public void testGroups() throws IOException , ClassNotFoundException , SecurityException , NoSuchMethodException { 103 104 106 String rootDir = rootDir(); 107 Set shouldExist = shouldExist(); 108 Set shouldNotExist = shouldNotExist(); 109 110 File outputDir = new File (rootDir); 112 113 String [] files = getPaths(outputDir, null); 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 (shouldNotExist.contains(files[i])) { 120 fail("The following file should not exist in " + rootDir + 121 ", but does: " + files[i]); 122 } 123 } 124 125 if (shouldExist.size() > 0) { 126 fail("The following files should exist in " + rootDir + 127 ", but do not: " + shouldExist); 128 } 129 130 132 Class ourClass = Class.forName("test.wsdl.groups.SomeType"); 133 ourClass.getDeclaredMethod("getA", null); 134 ourClass.getDeclaredMethod("getB", null); 135 ourClass.getDeclaredMethod("getZ", null); 136 137 return; 138 } 139 } 140 141 | Popular Tags |