KickJava   Java API By Example, From Geeks To Geeks.

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


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.PostSyncML;
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  * @author Stefano Fornari
52  * @version $Id: TestSyncMLTask.java,v 1.13 2005/07/05 16:59:50 luigiafassina Exp $
53  */

54 public class TestSyncMLTask extends TestSyncMLBaseTask {
55
56     // -------------------------------------------------------------- Properties
57

58
59     // ----------------------------------------------------- Task Implementation
60

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

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