Skip to main content
summaryrefslogtreecommitdiffstats
blob: 4cfb3addc05233338cf2d5e10bcbca957550e6ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package org.eclipse.wst.xml.resolver.tools.tests.internal;

import java.io.File;

import junit.framework.TestCase;

import org.apache.xml.resolver.tools.CatalogResolver;
import org.eclipse.wst.xml.catalog.tests.internal.TestPlugin;


/**
 * Test from http://issues.apache.org/bugzilla/show_bug.cgi?id=16336
 * 
 * To run this test need to add resolver.jar to the classpath.
 * Run as JUnit Plugin test:
 * - put resolver.jar on the boot class path
 * - add VM argument:
 * 
 * -Xbootclasspath/p:<install location>\jre\lib\ext\resolver.jar
 *
 *
 */
public class XSLTWithCatalogResolverTest extends TestCase {

	CatalogResolver catalogResolver = null;
	TraXLiaison xsltLiason = null;
	static String SEP = File.separator;

	public XSLTWithCatalogResolverTest(String name) {
		super(name);
	}

	public static void main(String[] args) {
		junit.textui.TestRunner.run(XSLTWithCatalogResolverTest.class);
	}

	protected void setUp() throws Exception {
		super.setUp();	
		catalogResolver = new CatalogResolver();
		xsltLiason = new TraXLiaison();
		xsltLiason.setEntityResolver(catalogResolver);
		xsltLiason.setURIResolver(catalogResolver);

	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testXSLTwithCatalogResolver() throws Exception {
		
		String testDirName = "data/testXSLTwithCatalogResolver";
		testDirName = TestPlugin.resolvePluginLocation(testDirName);
		
		String catalogFileName = testDirName + SEP + "catalog.xml";	
		String xslFileName = testDirName + SEP + "xmlcatalog.xsl";
		String xmlFileName = testDirName + SEP + "xmlcatalog2.xml";
		String resultFileName = xmlFileName + "-out";
		String idealResultFileName = xmlFileName + "-result";

		//setup catalog 

		File catalogFile = new File(catalogFileName);
		
		assertTrue("Catalog file " + catalogFileName + " should exist for the test", catalogFile.exists());
	
		catalogResolver.getCatalog().parseCatalog(catalogFileName);
		
		File xslFile = new File(xslFileName);
		
		assertTrue("XSL file " + xslFileName + " should exist for the test", xslFile.exists());		
			
		File inFile = new File(xmlFileName);
		
		assertTrue("XML file " + xslFileName + " should exist for the test", xslFile.exists());		
		
		File outFile = FileUtil.createFileAndParentDirectories(resultFileName);

		xsltLiason.setStylesheet(xslFile);
		xsltLiason.addParam("outprop", "testvalue");
	
		xsltLiason.transform(inFile, outFile);
		
		boolean diffFound =
					FileUtil.textualCompare(
						outFile,
						new File(idealResultFileName),
						new File(resultFileName + "-diff"));
			
	   assertTrue("Output file should match the expected results", !diffFound);

		

	}


}

Back to the top