| 1 |
/* |
| 2 |
* Copyright 2001-2004 The Apache Software Foundation. |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
/** |
| 18 |
* This tests the file generation of only the items that are referenced in WSDL |
| 19 |
* |
| 20 |
* @author Steve Green ([email protected]) |
| 21 |
*/ |
| 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 |
/** |
| 38 |
* List of files which should be generated. |
| 39 |
*/ |
| 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 |
/** |
| 48 |
* List of files which may or may not be generated. |
| 49 |
*/ |
| 50 |
protected Set shouldNotExist() { |
| 51 |
HashSet set = new HashSet(); |
| 52 |
set.add("SomeGroup.java"); |
| 53 |
return set; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* The directory containing the files that should exist. |
| 58 |
*/ |
| 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 |
/** This method returns a array of String file paths, located within the |
| 75 |
* supplied root directory. The string values are created relative to the |
| 76 |
* specified parent so that the names get returned in the form of |
| 77 |
* "file.java", "dir/file.java", "dir/dir/file.java", etc. This feature |
| 78 |
* asslows the various file specs to include files in sub-directories as |
| 79 |
* well as the root directory. |
| 80 |
*/ |
| 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 |
// Test for the proper files |
| 105 |
|
| 106 |
String rootDir = rootDir(); |
| 107 |
Set shouldExist = shouldExist(); |
| 108 |
Set shouldNotExist = shouldNotExist(); |
| 109 |
|
| 110 |
// open up the output directory and check what files exist. |
| 111 |
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 |
// Test for the proper members |
| 131 |
|
| 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 |
|