001: package org.apache.tools.ant.taskdefs.optional;
002:
003: import org.apache.tools.ant.taskdefs.XSLTLiaison;
004: import org.apache.tools.ant.taskdefs.XSLTLogger;
005: import org.apache.tools.ant.BuildException;
006: import org.apache.tools.ant.util.JAXPUtils;
007:
008: import java.io.File;
009:
010: import junit.framework.AssertionFailedError;
011:
012: /*
013: * Licensed to the Apache Software Foundation (ASF) under one or more
014: * contributor license agreements. See the NOTICE file distributed with
015: * this work for additional information regarding copyright ownership.
016: * The ASF licenses this file to You under the Apache License, Version 2.0
017: * (the "License"); you may not use this file except in compliance with
018: * the License. You may obtain a copy of the License at
019: *
020: * http://www.apache.org/licenses/LICENSE-2.0
021: *
022: * Unless required by applicable law or agreed to in writing, software
023: * distributed under the License is distributed on an "AS IS" BASIS,
024: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
025: * See the License for the specific language governing permissions and
026: * limitations under the License.
027: *
028: */
029:
030: /**
031: * TraX XSLTLiaison testcase
032: */
033: public class TraXLiaisonTest extends AbstractXSLTLiaisonTest implements
034: XSLTLogger {
035:
036: public TraXLiaisonTest(String name) {
037: super (name);
038: }
039:
040: public void tearDown() {
041: File f = new File("xalan2-redirect-out.tmp");
042: if (f.exists()) {
043: f.delete();
044: }
045: }
046:
047: public XSLTLiaison createLiaison() throws Exception {
048: TraXLiaison l = new TraXLiaison();
049: l.setLogger(this );
050: return l;
051: }
052:
053: public void testXalan2Redirect() throws Exception {
054: File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
055: liaison.setStylesheet(xsl);
056: File out = new File("xalan2-redirect-out-dummy.tmp");
057: File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
058: try {
059: liaison.addParam("xalan-version", "2");
060: liaison.transform(in, out);
061: } finally {
062: out.delete();
063: }
064: }
065:
066: public void testMultipleTransform() throws Exception {
067: File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
068: liaison.setStylesheet(xsl);
069: liaison.addParam("param", "value");
070: File in = getFile("/taskdefs/optional/xsltliaison-in.xml");
071: // test for 10 consecutives transform
072: for (int i = 0; i < 50; i++) {
073: File out = new File("xsltliaison" + i + ".tmp");
074: try {
075: liaison.transform(in, out);
076: } catch (Exception e) {
077: throw new BuildException("failed in transform " + i, e);
078: } finally {
079: out.delete();
080: }
081: }
082: }
083:
084: public void testSystemId() {
085: File file = null;
086: if (File.separatorChar == '\\') {
087: file = new File("d:\\jdk");
088: } else {
089: file = new File("/user/local/bin");
090: }
091: String systemid = JAXPUtils.getSystemId(file);
092: assertTrue("SystemIDs should start by file:/", systemid
093: .startsWith("file:/"));
094: assertTrue("SystemIDs should not start with file:////",
095: !systemid.startsWith("file:////"));
096: }
097:
098: public void log(String message) {
099: throw new AssertionFailedError("Liaison sent message: "
100: + message);
101: }
102:
103: }
|