You are viewing a plain text version of this content. The canonical link for it is here.
Posted to slide-dev@jakarta.apache.org by ju...@apache.org on 2002/09/02 14:43:39 UTC
cvs commit: jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor TProcessors.java
juergen 2002/09/02 05:43:39
Modified: testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor
TProcessors.java
Log:
setting xml href elements into variable are url encoded now. I18N urls were encode twice before.
Revision Changes Path
1.39 +376 -368 jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java
Index: TProcessors.java
===================================================================
RCS file: /home/cvs/jakarta-slide/testsuite/testsuite/junit/src/org/apache/slide/testsuite/testtools/tprocessor/TProcessors.java,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -r1.38 -r1.39
--- TProcessors.java 14 Aug 2002 07:43:24 -0000 1.38
+++ TProcessors.java 2 Sep 2002 12:43:39 -0000 1.39
@@ -87,62 +87,62 @@
* @version $Revision$
*/
public class TProcessors {
-
-
-
+
+
+
/** Table for startup parameter */
Hashtable startUp = null;
-
-
+
+
/** home */
String xdavhome;
-
+
/** port */
String port;
-
+
/** host */
String host;
-
+
/** user */
String defaultUser;
-
+
/** password */
String defaultPassword;
-
-
+
+
/** url encoding */
String defaultUrlEncoding;
-
-
+
+
/** Tracing required */
String tracingRequest;
-
-
+
+
/** hold all the variable defined **/
KnownVariablesHashtable knownVariables = new KnownVariablesHashtable();
-
-
+
+
/** holds all configuration **/
XConf xdavConfiguration = null;
-
+
/** specify where to write the xml results **/
private XMLOutput xmlresult = new XMLOutput(System.out);
-
+
/** count all executed test elements **/
private long testElementsExecuted = 0;
-
+
/** count all executed test elements **/
private long testElementsExecutedWithError = 0;
-
+
/** The absolute path name of the execute input file **/
private String globalAbsolutePath = null;
-
+
/**
* Constructor
*/
-
+
public TProcessors (){
-
+
xdavhome = System.getProperty("xdav.home");
host = System.getProperty("xdav.host");
port = System.getProperty("xdav.port");
@@ -150,7 +150,7 @@
defaultPassword = System.getProperty("xdav.password");
defaultUrlEncoding = System.getProperty("xdav.urlencoding");
tracingRequest = System.getProperty("xdav.tracingRequest", "none");
-
+
if (defaultUrlEncoding == null) {
defaultUrlEncoding = "UTF-8";
}
@@ -172,24 +172,24 @@
System.out.println("xdav.port is not set!");
throw new Error("xdav.port is not set!");
}
-
+
// Set some defaults
startUp = new Hashtable();
startUp.put("host", host);
startUp.put("port", new Integer(port));
-
-
+
+
try { xdavConfiguration = new XConf(new File(xdavhome +
File.separator + "testsuite"+
File.separator + "junit"+
File.separator + "tprocessor.xml")); }
catch (Exception e) { e.printStackTrace(); }
-
-
+
+
}
-
-
-
+
+
+
/**
* main method
*/
@@ -199,46 +199,46 @@
System.exit (-1);
}
}
-
-
-
-
-
+
+
+
+
+
/**
* main executer method to be called from outside
*/
public static boolean mainExecuter(String[] args, java.io.PrintStream xmlresult, int[] counters)
{
-
-
+
+
String stestName = "";
String url;
boolean result = true;
TArgs arg = new TArgs (args);
-
-
+
+
TProcessors tp = new TProcessors();
if(!tp.processStartUp( args )){
System.exit(-1);
}
-
+
if (arg.isOptionSet ("name")) {
stestName = arg.get ("name");
-
+
}
else {
return false;
}
-
-
+
+
// System.out.println("Can read this file: "+ testName.canRead()+ "***" +testName.length());
// System.out.println("Can get the name of this file: "+ testName.getName());
-
-
+
+
if (!tp.executeTestCase( new File (stestName), xmlresult )) {
result = false;
}
-
+
if (counters != null) {
counters[0] ++;
if (!result) counters[1] ++;
@@ -246,17 +246,17 @@
// System.out.println("$$$$$$$$$$$ processed cases err " + counters[1]);
// System.out.println("");
}
-
-
-
+
+
+
return result;
}
-
-
-
-
-
-
+
+
+
+
+
+
/**
* Process the initial args passed to the Class.<br>
* Currently this should consist of:<br>
@@ -269,23 +269,23 @@
* If all goes well, a session will be created and credentials set.
*/
private boolean processStartUp( String[] args ){
-
+
int argsIndex = 0;
boolean ready = false;
-
-
+
+
TArgs arg = new TArgs (args);
-
+
if (arg.isOptionSet ("help")) {
-
+
printStartUsage();
return false;
}
if (arg.isOptionSet("host")){
-
-
+
+
startUp.put("host", arg.get("host"));
-
+
ready = true;
}
if(arg.isOptionSet("port")){
@@ -300,17 +300,17 @@
return false;
}
startUp.put("port", new Integer(val) );
-
-
+
+
ready = true;
}
-
-
+
+
if (arg.isOptionSet( "name" ) ){
ready = true;
}
-
-
+
+
return ready;
}
/**
@@ -318,39 +318,39 @@
*/
private static void printStartUsage()
{
-
+
System.out.println("XDAV Tprocessor Startup args:");
System.out.println(" -name <The name of testcase, full path should be given>");
System.out.println(" -host <host to connect to>");
System.out.println(" -port <post to conect on>");
System.out.println(" -help");
-
-
+
+
}
// -------------------------------------------------------- Private Methods
-
+
/**
* Construct a document (tree) out of given XML file. Execute testStep given in the
* file
* @param WeddavClient client, File
*/
-
+
private boolean executeTestCase( File testfile, PrintStream xmlresultPar ){
boolean result= true;
long time = System.currentTimeMillis();
-
+
if (xmlresultPar != null){
this.xmlresult = new XMLOutput(xmlresultPar);
}
-
-
+
+
System.out.println("");
System.out.println(new Date() + " Starting test case: " + testfile.getAbsolutePath());
-
+
xmlresult.writeElementStart("testCase");
xmlresult.writeElement("fileName", testfile.getAbsolutePath());
xmlresult.flush();
-
+
try{
globalAbsolutePath = testfile.getAbsolutePath();
globalAbsolutePath = testfile.getParent();
@@ -363,37 +363,37 @@
} catch( Exception e ) {
e.printStackTrace();
}
-
-
+
+
xmlresult.writeElement("result", ((testElementsExecutedWithError!=0)?"ERROR":"Success"));
xmlresult.writeElement("time", ((System.currentTimeMillis() - time)));
xmlresult.writeElement("testElementCount", testElementsExecuted);
xmlresult.writeElement("testElementErrors", testElementsExecutedWithError);
xmlresult.writeElementEnd("testCase");
xmlresult.flush();
-
-
+
+
if (testElementsExecutedWithError!=0) System.out.println(new Date() + " FAILED test case: " + testfile.getAbsolutePath());
// System.out.println("Ending test case: " + testfile.getAbsolutePath());
// System.out.println("");
// try {System.in.read();} catch (Exception e) {}
-
-
-
+
+
+
return testElementsExecutedWithError==0;
-
+
}
-
-
+
+
private boolean exceuteStepOrRepeater(Iterator items) {
boolean result = true;
Vector threadsToExceute = new Vector(10);
Vector cleanUpThreads = new Vector(10);
-
+
try {
-
+
result = exceuteStepOrRepeater(items, threadsToExceute, cleanUpThreads);
-
+
// now execute all collected threads in parallel
for (int i = 0 ; i<threadsToExceute.size(); i++) {
((Thread)threadsToExceute.elementAt(i)).start();
@@ -401,7 +401,7 @@
for (int i = 0 ; i<threadsToExceute.size(); i++) {
((Thread)threadsToExceute.elementAt(i)).join();
}
-
+
// now do the clean up tasks
// now execute all collected threads in parallel
for (int i = 0 ; i<cleanUpThreads.size(); i++) {
@@ -414,13 +414,13 @@
catch (Exception e){
e.printStackTrace();
}
-
+
return result;
-
+
}
-
-
-
+
+
+
private boolean exceuteStepOrRepeater(Iterator items, Vector threadsToExceute, Vector cleanUpThreads) {
boolean result = true;
try {
@@ -458,17 +458,17 @@
System.out.println("#########################");
}
}
-
-
+
+
}
catch (Exception e){
e.printStackTrace();
}
-
+
return result;
}
-
-
+
+
private void assignVariables(List varDefinitions ){
if (varDefinitions != null) {
Iterator iter = varDefinitions.iterator();
@@ -479,18 +479,18 @@
}
}
}
-
-
-
-
-
+
+
+
+
+
/**
* Execute a given request for a testStep
* @param Element
*/
-
+
private boolean executeStep(Element elt ){
-
+
boolean result = false;
long time = System.currentTimeMillis();
HttpMethod method = null;
@@ -498,17 +498,17 @@
// initialise user and password
knownVariables.put("user", defaultUser);
knownVariables.put("password", defaultPassword);
-
+
assignVariables(elt.getChildren("assign"));
-
+
String user = replaceKnownVariable(elt.getChild("user"), defaultUser);
String password = replaceKnownVariable(elt.getChild("password"), defaultPassword);
// set user and password to the computed values
knownVariables.put("user", user);
knownVariables.put("password", password);
-
-
+
+
HttpClient client = new HttpClient();
WebdavState state = new WebdavState();
state.setAuthenticateToken("Basic realm=xxx"); // currently only basic is supported
@@ -524,32 +524,32 @@
else {
client.setDebug(0);
}
-
+
// System.out.println("############### user " + user);
// System.out.println("############### pwd " + password);
-
+
xmlresult.writeElementStart("exceuteStep");
-
+
try{
method = executeRequest((Element) elt.getChild("request"));
-
+
if (method == null){
System.out.println("#########################");
System.out.println("Method pointer is null = " + getElementString(elt.getChild("request")) );
System.out.println("#########################");
return false;
}
-
+
xmlresult.writeElement("method", method.getName());
xmlresult.writeElement("url", URLUtil.URLEncode(method.getPath(),"UTF-8"));
-
-
+
+
client.executeMethod(method);
client.endSession();
// System.out.println("Status Code "+ m.getStatusCode());
// System.out.println("Status Text "+ m.getStatusText());
-
-
+
+
// if (method instanceof PropFindMethod) {
// System.out.println("###################");
// System.out.println("###################");
@@ -559,45 +559,45 @@
// System.out.println("###################");
// System.out.println("###################");
// }
-
-
+
+
fillVariables(method, elt.getChild("response"));
-
+
result = (responseAssert(method, elt));
-
-
+
+
}catch(Exception e){
xmlresult.writeException( e );
e.printStackTrace();
}
-
+
if (!result) testElementsExecutedWithError ++;
testElementsExecuted ++;
-
-
+
+
xmlresult.writeElement("result", (!result?"ERROR":"Success"));
xmlresult.writeElement("time", ((System.currentTimeMillis() - time)));
xmlresult.writeElementEnd("exceuteStep");
xmlresult.flush();
-
-
+
+
return result;
}
-
+
/**
* Constructs from request the method associated to the given request
* @param Element
*/
-
+
private HttpMethod executeRequest(Element request) throws Exception {
HttpMethod method = null;
List list = request.getChildren();
Iterator items = list.iterator();
-
-
+
+
while(items.hasNext()){
Element item = (Element) items.next();
-
+
if(item.getName().equals("command")){
method = fillMethodName(item, method);
}
@@ -606,12 +606,12 @@
} else if(item.getName().equals("body")){
method = fillBody(item, method);
}
-
+
}
return(method);
}
-
-
+
+
/**
* This method is used to replace variables in a element
* @param element the element to replacement should be applied
@@ -620,8 +620,8 @@
private String replaceKnownVariable(Element element){
return replaceKnownVariable(element, null);
}
-
-
+
+
/**
* This method checks if a name points to a valid file
* @param fileName
@@ -631,9 +631,9 @@
// System.out.println("Checking " + name + " = " + new File(name).isFile());
return new File(name).isFile();
}
-
-
-
+
+
+
/**
* This method returns the name of a valid file
* @param name is the possibly unqualified file name
@@ -647,8 +647,8 @@
}
return result;
}
-
-
+
+
/**
* This method returns the name of a valid file
* @param name is the possibly unqualified file name
@@ -665,9 +665,9 @@
}
return result;
}
-
-
-
+
+
+
/**
* This method returns the name of a valid file
* @param name is the possibly unqualified file name
@@ -678,8 +678,8 @@
if (result == null || result.equals("")) result = "UTF-8";
return result;
}
-
-
+
+
/**
* This method is used to replace variables in a string
* @param element the element to replacement should be applied
@@ -690,34 +690,34 @@
String result = body.getText();
String fileName = getFileReferenceName(body);
if (fileName != null) {
-
+
try {
-
+
Reader input = new BufferedReader(
new InputStreamReader(
new FileInputStream(fileName), getFileEncoding(body)));
StringWriter output = new StringWriter();
char[] buffer = new char[1024];
int numberOfBytesRead;
-
+
while ((numberOfBytesRead=input.read(buffer)) > 0) {
output.write (buffer, 0, numberOfBytesRead);
}
-
+
result = output.toString();
input.close();
output.close();
-
+
}
catch (Exception e) {
e.printStackTrace();
}
-
-
+
+
}
return result;
}
-
+
/**
* This method is used to replace variables in a string
* @param element the element to replacement should be applied
@@ -728,8 +728,8 @@
if (element == null) return defaultValue;
return replaceKnownVariable(element, getBodyValue(element), defaultValue);
}
-
-
+
+
/**
* This method is used to replace variables in a string. If a variable value uses other variables
* those variables are subsituted too.
@@ -739,11 +739,11 @@
* @return String the value of the element, with all applied replacements, if element is null return defaultValue
*/
private String replaceKnownVariable(Element element, String line, String defaultValue){
-
+
if (element == null) return defaultValue;
-
+
if (element.getAttributeValue("varUsage") != null && !element.getAttributeValue("varUsage").equals("")){
-
+
if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
String varName = "varUsage"; // default
line = replace(line, "%"+varName+"%", computeVarValue(element, element.getAttributeValue("varUsage")));
@@ -768,11 +768,11 @@
* @return String the value of the element, with all applied replacements, if element is null return defaultValue
*/
private String doReplaceKnownVariable(Element element, String line, String defaultValue){
-
+
if (element == null) return defaultValue;
-
+
if (element.getAttributeValue("varUsage") != null && !element.getAttributeValue("varUsage").equals("")){
-
+
if (element.getAttributeValue("varUsage").indexOf(",") == (-1)) {
String varName = "varUsage"; // default
line = replace(line, "%"+varName+"%", knownVariables.get(element.getAttributeValue("varUsage")));
@@ -788,9 +788,9 @@
}
return line;
}
-
-
-
+
+
+
/**
* This method computes for a given variable name the value. If the value contains
* additional variable references, these are resolved to their values
@@ -805,10 +805,10 @@
}
return result;
}
-
-
-
-
+
+
+
+
/**
* This method is used to replace variables in a string
* @param line the string which will be modified
@@ -817,7 +817,7 @@
* @return value of line, with all applied replacements
*/
public static String replace(String line, String pattern, String value){
-
+
while (line.indexOf(pattern) != -1){
line = line.substring(0, line.indexOf(pattern)) +
value +
@@ -826,10 +826,10 @@
// System.out.println("#### Replaced " + pattern + " with " + value + " --> " + line);
return line;
}
-
-
-
-
+
+
+
+
/**
* This method is used to find out the name of the Resquest Method
* @param List
@@ -840,10 +840,10 @@
method = HttpMethodFactory(st.nextToken(), st.nextToken());
return method;
}
-
-
-
-
+
+
+
+
/**
* This method is used to set the Header in request Method
* @param List
@@ -853,7 +853,7 @@
method.setHeader(headerToSet.getName(), headerToSet.getValue());
return method;
}
-
+
private boolean binaryReadRequest(Element element) {
String fileReference = getFileReferenceName(element);
String fileEncoding = element.getAttributeValue("fileEncoding");
@@ -861,9 +861,9 @@
(fileEncoding == null || fileEncoding.equals("binary"));
return result;
}
-
-
-
+
+
+
/**
* This method is used to set the Header in request Method
* @param List
@@ -889,16 +889,16 @@
catch (UnsupportedEncodingException e) { throw new Exception(e.toString());}
}
return method;
-
+
}
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
/**
* This method is used to return body as String
* @param String
@@ -907,28 +907,28 @@
boolean firstPart = false;
boolean secondPart = false;
Iterator header = responseHeader(elt.getChild("response"));
-
-
+
+
List expectedResponseCodes = responseStatus(elt.getChild("response").getChildText("command"));
-
+
if (expectedResponseCodes != null && !expectedResponseCodes.contains(new Integer(m.getStatusCode()))) {
-
+
xmlresult.writeElementStart("responseError");
xmlresult.writeElement("receivedValue", WebdavStatus.getStatusText(m.getStatusCode()) +
" " + m.getStatusCode());
xmlresult.writeElement("expectedValue", getStatusText(expectedResponseCodes) +
" " + expectedResponseCodes);
xmlresult.writeElementEnd("responseError");
-
+
if (m instanceof XMLResponseMethodBase && m.getStatusCode()==207 ) {
System.out.println("#################");
System.out.println(getElementString(((XMLResponseMethodBase)m).getResponseDocument().getDocumentElement()));
System.out.println("#################");
}
-
+
return false;
}
-
+
// a received response code of 404 will not compare the headers
ResponseBodyAssert methodAssert = assertFactory(m, elt);
secondPart = (m.getStatusCode() == 404 && expectedResponseCodes != null &&
@@ -937,38 +937,38 @@
||
responseHeaderAssert(m, elt, header);
firstPart = (methodAssert!=null)?methodAssert.assertResponseBody():true;
-
-
+
+
return ( firstPart && secondPart);
}
-
-
-
-
+
+
+
+
/**
* This method is used to set the Header in request Method
* @param List
*/
private String getStatusText (List responseCodes){
-
+
String result = "";
-
+
Iterator iter = responseCodes.iterator();
while (iter.hasNext()) {
result = result + " " + WebdavStatus.getStatusText(((Integer)iter.next()).intValue());
}
-
+
return result;
-
+
}
-
-
+
+
/**
* This method is used to set the Header in request Method
* @param String
*/
private Header getResponseHeader (String headerString){
-
+
Header result = new Header();
String name;
String value;
@@ -981,15 +981,15 @@
value = headerString.substring(size+1);
}
value = value.trim();
-
+
result.setName(name);
result.setValue(value);
-
+
return result;
-
+
}
-
-
+
+
/**
* This method is used to set the Header in request Method
* @param Element
@@ -997,7 +997,7 @@
private Header getResponseHeader (Element headerElement){
return getResponseHeader(replaceKnownVariable(headerElement));
}
-
+
/**
* This method is used to return body as String
* @param String
@@ -1005,21 +1005,21 @@
private boolean responseHeaderAssert(HttpMethod m, Element elt, Iterator header){
boolean result = false;
try{
-
+
result = verifyHeader(xdavConfiguration.getPropertyList ("excludedHeaderProperties", m.getName()), m, header);
-
+
}catch(Exception e){
e.printStackTrace();
}
-
-
+
+
return result;
}
-
-
-
-
-
+
+
+
+
+
/**
* This method is used to check if all the given headers are returned by the WebDav method
* @param String
@@ -1027,14 +1027,14 @@
private boolean verifyHeader(List allowHeaders, HttpMethod m, Iterator header){
boolean result = true;
int i = 0;
-
-
+
+
while (header.hasNext()){
-
+
Header headToMatch = (Header) header.next();
boolean oneHeaderMatched = allowHeaders.contains(headToMatch.getName()) || // head to be compared
verifyOneHeader(headToMatch, m.getHeaders()); // compare it
-
+
if (!oneHeaderMatched){
if (result) {
xmlresult.writeElementStart("headerErrors");
@@ -1049,20 +1049,20 @@
xmlresult.writeElementEnd("nonMatchingHeader");
}
}
-
+
result = result && oneHeaderMatched;
-
+
}
if (!result) {
xmlresult.writeElementEnd("headerErrors");
}
return result;
}
-
-
-
-
-
+
+
+
+
+
private boolean verifyOneHeader(Header h, Enumeration enum){
boolean result = false;
while(enum.hasMoreElements()){
@@ -1077,8 +1077,8 @@
}
return result;
}
-
-
+
+
private Iterator responseHeader(Element response){
ArrayList result = new ArrayList();
Iterator iter = response.getChildren("header").iterator();
@@ -1088,11 +1088,11 @@
}
return result.iterator();
}
-
-
-
-
-
+
+
+
+
+
public static List responseStatus (String response){
List result = new ArrayList();
StringTokenizer st = new StringTokenizer(response);
@@ -1111,44 +1111,44 @@
}
return result;
}
-
-
-
+
+
+
//
-
-
+
+
/**
*
*/
public static String getElementString (org.w3c.dom.Element e) {
return getElementString(new org.jdom.input.DOMBuilder().build(e));
}
-
-
+
+
/**
*
*/
public static String getElementString (Element e) {
XMLOutputter out = new XMLOutputter(" ", true);
String result = null;
-
+
if (e == null) return "null";
-
+
try {
result = out.outputString (e);
}
catch (Exception ex) {}
-
+
return result;
}
-
+
/**
* Extract from expected response it body
*/
protected Element getElementFromString (String input){
-
+
if (input == null) return null;
-
+
Element result = null;
// System.out.println("######");
// System.out.println("######" + element);
@@ -1156,11 +1156,11 @@
// System.out.println("");
// System.out.println("");
// System.out.println("");
-
+
if (input.trim().equals("")) return null;
-
+
try {
-
+
result = (new SAXBuilder().build(new StringReader(input.trim()))).getRootElement();
}
catch (Exception e){
@@ -1169,12 +1169,12 @@
System.out.println("#####################");
e.printStackTrace();
}
-
+
return result;
}
-
-
-
+
+
+
/**
*
*/
@@ -1185,19 +1185,19 @@
fillSpecifiedVariable((XMLResponseMethodBase)m, responseElement.getChild("body"));
}
}
-
-
-
-
+
+
+
+
/**
*
*/
private void fillSpecifiedHeaderVariable (HttpMethod m, Element responseElement) {
-
+
if (responseElement == null) return; // no response, nothing to fill
-
+
try {
-
+
Iterator iter = responseElement.getChildren("header").iterator();
while (iter.hasNext()) {
Element headerElement = (Element)iter.next();
@@ -1211,49 +1211,49 @@
knownVariables.put(varName, varValue);
}
}
-
+
} catch(Exception e){
e.printStackTrace();
}
-
+
}
/**
*
*/
private void fillSpecifiedVariable (XMLResponseMethodBase m, Element body) {
-
+
if (body == null) return; // no body, nothing to fill
-
+
try {
-
+
String searchPattern = body.getAttributeValue("varPath");
String varName = body.getAttributeValue("varDefinition");
if ((searchPattern != null) && (varName != null) && m.getResponseDocument() != null){
-
+
String varValue = "";
Iterator iter = findElementList(getMethodElement(m), searchPattern).iterator();
while (iter.hasNext()) {
varValue = ((Element)iter.next()).getText();
}
-
+
knownVariables.put(varName, varValue); // store only the very last ocuurence
-
+
}
-
-
+
+
} catch(Exception e){
e.printStackTrace();
}
-
+
}
-
+
/**
*
*/
private void fillAutomatedVariables (XMLResponseMethodBase m) {
-
+
try {
-
+
List possible = xdavConfiguration.getPropertyList("automatedVariables", m.getName());
Iterator iter = possible.iterator();
while (iter.hasNext()){
@@ -1262,17 +1262,17 @@
fillAutomatedVariables(findElementList(getMethodElement(m), searchPattern));
}
}
-
-
+
+
} catch(Exception e){
e.printStackTrace();
}
-
+
}
-
-
-
-
+
+
+
+
private void fillAutomatedVariables (List valueList) {
Iterator iter = valueList.iterator();
while (iter.hasNext()){
@@ -1280,72 +1280,80 @@
String varName = "automaticVariable" + (knownVariables.size()-2);
String varValue = e.getText();
knownVariables.put(varName, varValue);
-
+
}
}
-
-
+
+
private Element getMethodElement(XMLResponseMethodBase m) {
return new org.jdom.input.DOMBuilder().build(m.getResponseDocument().getDocumentElement());
}
-
-
-
-
+
+
+
+
private List findElementList (Element rootElement, String key) {
-
+
List result = new ArrayList();
-
+
if (key == null || key.equals("")) return result;
+
if (rootElement.getName().equals(key)) {
- result.add(rootElement);
+ Element e = rootElement;
+ if (key.equals("href")) {
+ e = (Element)e.clone();
+ try {e.setText(URLUtil.URLDecode(e.getText(), defaultUrlEncoding));} catch (Exception dec) { }
+ }
+ result.add(e);
return result;
}
if (key.indexOf("/") == -1) return result;
-
+
String head = key.substring(0, key.indexOf("/"));
String tail = key.substring(key.indexOf("/")+1);
String child = null;
-
+
// System.out.println("@@@@@@@@@ xml " + rootElement.getName());
-
- if (!rootElement.getName().equals(head)) return result;
-
+
+ if (!rootElement.getName().equals(head)) {
+ return result;
+ }
+
if (tail.indexOf("/") == (-1)){
child = tail;
}
else{
child = tail.substring(0, tail.indexOf("/"));
}
-
+
// System.out.println("@@@@@@@@@ head " + head);
// System.out.println("@@@@@@@@@ child " + child);
// System.out.println("@@@@@@@@@ tail " + tail);
-
-
+
+
Iterator iter = rootElement.getChildren().iterator();
while (iter.hasNext()){
Element e = (Element)iter.next();
if (e.getName().equals(child))
result.addAll(findElementList(e, tail));
};
-
-
+
+
return result;
}
-
-
+
+
private Element expectedResponseAsDOM(Element expectedResponse) {
return getElementFromString(expectedResponseAsString(expectedResponse));
}
-
-
+
+
private InputStream expectedResponseAsStream(Element element) throws Exception {
-
+
Element expectedResponse = element.getChild("response").getChild("body");
if (expectedResponse == null) return null;
-
-
+
+
InputStream result = null;
if (binaryReadRequest(expectedResponse)) {
result = new FileInputStream(getFileReferenceName(expectedResponse));
@@ -1357,20 +1365,20 @@
}
return result;
}
-
-
-
+
+
+
private String expectedResponseAsString(Element expectedResponse) {
if (expectedResponse.getChild("response").getChild("body") != null) {
return replaceKnownVariable(expectedResponse.getChild("response").getChild("body"));
}
return null;
}
-
-
-
+
+
+
private ResponseBodyAssert assertFactory(HttpMethod m, Element expectedResponse) throws Exception {
-
+
ResponseBodyAssert result = null;
if(m instanceof PropFindMethod){
result = new PropfindAssert((XMLResponseMethodBase) m, expectedResponseAsDOM(expectedResponse), xdavConfiguration, xmlresult);
@@ -1413,9 +1421,9 @@
}
return result;
}
-
-
-
+
+
+
/**
* Factory method to return a method object based on the methodName.
* If the method name is not known, null is returned
@@ -1499,10 +1507,10 @@
throw new Exception("Method " + methodName + " does not exist");
return result;
}
-
-
-
-
+
+
+
+
/**
* Factory method to return a method object based on the methodName.
* If the method name is not known, null is returned
@@ -1515,11 +1523,11 @@
}
return result;
}
-
-
-
-
-
+
+
+
+
+
/**************************************************************/
/* Inner class to help the thread to execute the function */
/**************************************************************/
@@ -1539,11 +1547,11 @@
knownVariables.removeEnvironment();
}
}
-
-
-
-
-
+
+
+
+
+
/**************************************************************/
/* Inner class to contain all variable sorted by thread name */
/**************************************************************/
@@ -1551,7 +1559,7 @@
private Hashtable knownVarsByThread = new Hashtable();
public String get(String key) {
String result = "";
-
+
if (key.startsWith("globalVariable") ||
key.equals("host")||
key.equals("port")||
@@ -1607,9 +1615,9 @@
return getEnvironment(Thread.currentThread());
}
}
-
-
-
+
+
+
/**************************************************************/
/* Inner class to have a HashMap act as a stack too */
/**************************************************************/
@@ -1632,13 +1640,13 @@
return super.remove(stack.pop());
}
}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>