Project

General

Profile

1
package eu.dnetlib.data.search.transform;
2

    
3
import org.apache.log4j.BasicConfigurator;
4
import org.junit.Before;
5
import org.junit.Test;
6

    
7
import java.io.IOException;
8

    
9
public class XsltTransformerTest {
10
	@Before
11
	public void setup() throws IOException {
12
		BasicConfigurator.configure();
13
	}
14
	@Test
15
	public void TestTransformer() throws Exception{
16
		String xslt = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:output method=\"xml\" indent=\"yes\" encoding=\"UTF-8\"/><xsl:template match=\"/\"><xsl:apply-templates/></xsl:template>";
17
		xslt += "<xsl:template match=\"@*|node()\"><xsl:copy><xsl:apply-templates select=\"@*|node()\"/></xsl:copy></xsl:template></xsl:stylesheet>";
18
		
19
		String input = "<record type=\"result\"><field name=\"resultId\" value=\"WOS:000285231000019\" label=\"resultId\" indexId=\"\"/>";
20
		input += "<field name=\"title\" label=\"Title\" indexId=\"\" value=\"BLOCKADE OF CENTRAL NICOTINE ACETYLCHOLINE RECEPTOR \"/>";
21
		input += "<field name=\"description\" label=\"Description\" indexId=\"\" value=\"Here we sought ...\"/>";
22
		input += "</record>";
23
		
24
		String cur = "";
25
		String prev = "";
26
		
27
		XsltTransformer TR = new XsltTransformer(xslt); 
28

    
29
		long start = System.nanoTime();
30
		
31
		prev = TR.transform(input);
32
		for(int i =2; i<10000;i++) {
33
			cur = TR.transform(input);
34
			if(!cur.equals(prev)) {
35
				System.out.println("Error in "+i+" time");
36
				System.out.println(prev);
37
				System.out.println(cur);
38
				break;
39
			}
40
			prev = cur;				
41
		}
42
		long end = System.nanoTime();
43
		System.out.println(end-start);
44
	}
45
}
(5-5/5)