| 1 |
/* |
| 2 |
* Copyright 2002-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 |
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 |
/** |
| 30 |
* base class for Axis FileGen test cases. |
| 31 |
*/ |
| 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 |
/** This method returns a array of String file paths, located within the |
| 52 |
* supplied root directory. The string values are created relative to the |
| 53 |
* specified parent so that the names get returned in the form of |
| 54 |
* "file.java", "dir/file.java", "dir/dir/file.java", etc. This feature |
| 55 |
* asslows the various file specs to include files in sub-directories as |
| 56 |
* well as the root directory. |
| 57 |
*/ |
| 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 |
// open up the output directory and check what files exist. |
| 85 |
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 |
} |