KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > optional > TraXLiaisonTest


1 package org.apache.tools.ant.taskdefs.optional;
2
3 import org.apache.tools.ant.taskdefs.XSLTLiaison;
4 import org.apache.tools.ant.taskdefs.XSLTLogger;
5 import org.apache.tools.ant.BuildException;
6
7 import java.io.File JavaDoc;
8
9 import junit.framework.AssertionFailedError;
10
11 /*
12  * Copyright 2001-2002,2004 The Apache Software Foundation
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License");
15  * you may not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  * http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS,
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  *
26  */

27
28 /**
29  * TraX XSLTLiaison testcase
30  */

31 public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
32     implements XSLTLogger {
33
34     public TraXLiaisonTest(String JavaDoc name){
35         super(name);
36     }
37
38     public void tearDown() {
39         File JavaDoc f = new File JavaDoc("xalan2-redirect-out.tmp");
40         if (f.exists()) {
41             f.delete();
42         }
43     }
44
45     public XSLTLiaison createLiaison() throws Exception JavaDoc {
46         TraXLiaison l = new TraXLiaison();
47         l.setLogger(this);
48         return l;
49     }
50
51     public void testXalan2Redirect() throws Exception JavaDoc {
52         File JavaDoc xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
53         liaison.setStylesheet(xsl);
54         File JavaDoc out = new File JavaDoc("xalan2-redirect-out-dummy.tmp");
55         File JavaDoc in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
56         try {
57             liaison.addParam("xalan-version", "2");
58             liaison.transform(in, out);
59         } finally {
60             out.delete();
61         }
62     }
63
64     public void testMultipleTransform() throws Exception JavaDoc {
65         File JavaDoc xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
66         liaison.setStylesheet(xsl);
67         liaison.addParam("param", "value");
68         File JavaDoc in = getFile("/taskdefs/optional/xsltliaison-in.xml");
69         // test for 10 consecutives transform
70
for (int i = 0; i < 50; i++){
71             File JavaDoc out = new File JavaDoc("xsltliaison" + i + ".tmp");
72             try {
73                 liaison.transform(in, out);
74             } catch (Exception JavaDoc e){
75                 throw new BuildException("failed in transform " + i, e);
76             } finally {
77                 out.delete();
78             }
79         }
80     }
81
82     public void testSystemId(){
83         File JavaDoc file = null;
84         if ( File.separatorChar == '\\' ){
85             file = new File JavaDoc("d:\\jdk");
86         } else {
87             file = new File JavaDoc("/user/local/bin");
88         }
89         String JavaDoc systemid = ((TraXLiaison)liaison).getSystemId(file);
90         assertTrue("SystemIDs should start by file:///", systemid.startsWith("file:///"));
91         assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
92     }
93
94     public void log(String JavaDoc message) {
95         throw new AssertionFailedError("Liaison sent message: "+message);
96     }
97
98 }
99
Popular Tags