KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > test > tools > ant > TestSyncMLWBXMLTask


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.test.tools.ant;
19
20 import java.io.*;
21 import java.util.ArrayList JavaDoc;
22
23 import org.apache.tools.ant.Project;
24 import org.apache.tools.ant.BuildException;
25 import org.apache.tools.ant.types.PatternSet;
26 import org.apache.tools.ant.taskdefs.*;
27
28 import sync4j.framework.tools.IOTools;
29 import sync4j.test.TestFailedException;
30 import sync4j.test.tools.PostWBXMLSyncML;
31
32
33 /**
34  * This is an Ant task that executes the protocol level tests.
35  * <p>
36  * @see sync4j.test.tools.PostSyncML
37  * <p
38  * It can be used in the following manner:
39  *
40  * <pre>
41  * &lt;task name="test-syncml" ...&gt;
42  * &lt;testsyncml url="{initial URL}" test="{test name}"&gt;
43  * &lt;patternset&gt;
44           &lt;exclude name="/SyncML/SyncHdr/SessionID/self::node()[1]"/&gt;
45           &lt;exclude name="/SyncML/SyncHdr/RespURI/self::node()[1]"/&gt;
46         &lt;/patternset&gt;
47  * &lt;/testsyncml&gt;
48  * &lt;/task&gt;
49  * </pre>
50  *
51  * @version $Id: TestSyncMLWBXMLTask.java,v 1.10 2005/07/07 09:43:58 luigiafassina Exp $
52  */

53 public class TestSyncMLWBXMLTask extends TestSyncMLBaseTask {
54
55     // -------------------------------------------------------------- Properties
56

57     // ----------------------------------------------------- Task Implementation
58

59     public void execute() throws BuildException {
60         //
61
// make sure we don't have an illegal set of options
62
//
63
validateAttributes();
64
65         //
66
// Deal with the specified XPath to exclude from the comparison of
67
// the XML messages. They are specified through one or more inner
68
// <patternset> elements.
69
//
70
ArrayList JavaDoc allExcludeXPaths = new ArrayList JavaDoc();
71
72         PatternSet ps = null;
73         String JavaDoc[] xpaths = null;
74         for (int i = 0; i < xpathPatterns.size(); i++) {
75             ps = (PatternSet) xpathPatterns.get(i);
76             xpaths = ps.getExcludePatterns(getProject());
77             for (int j = 0; j < xpaths.length; ++j) {
78                 allExcludeXPaths.add(xpaths[j]);
79             }
80         } // next i
81

82         log("Initial URL: " + url );
83         log("Test: " + test );
84         log("Ignored XPaths: " + allExcludeXPaths);
85
86         xpaths = (String JavaDoc[])allExcludeXPaths.toArray(new String JavaDoc[0]);
87
88         Ant antTask = loadAntTask(test);
89         //
90
// Execute the tests now
91
//
92
FilenameFilter filter = IOTools.getFileTypeFilter("wbxml");
93
94         String JavaDoc[] msgFiles = new File(basedir, test).list(filter);
95         if (antTask != null) {
96             System.out.println("execute antTask != null");
97             System.out.println("test: " + test);
98
99             msgFiles = removeBuildFile(msgFiles);
100         }
101
102         msgFiles = ordersAndFilterFiles(new File(basedir, test).list(filter));
103
104         try {
105             new PostWBXMLSyncML(
106                 url ,
107                 new File(basedir, test),
108                 msgFiles ,
109                 xpaths ,
110                 antTask
111             ).syncAndTest();
112
113             log("Test " + test + " passed!");
114         } catch (IOException e) {
115             log(e.getMessage(), Project.MSG_ERR);
116             throw new BuildException("Error executing PostSyncMLTask", e);
117         } catch (TestFailedException e) {
118             log("Test " + test + " failed: " + e.getMessage(), Project.MSG_INFO);
119         }
120     }
121
122 }
123
Popular Tags