1 |
26600
|
sandro.lab
|
package eu.dnetlib.miscutils.functional.xml;
|
2 |
|
|
|
3 |
|
|
import java.io.IOException;
|
4 |
|
|
import javax.xml.transform.TransformerFactory;
|
5 |
|
|
|
6 |
|
|
import org.apache.commons.io.IOUtils;
|
7 |
|
|
import org.junit.Test;
|
8 |
|
|
import org.junit.runner.RunWith;
|
9 |
|
|
import org.mockito.runners.MockitoJUnit44Runner;
|
10 |
|
|
import org.springframework.core.io.ClassPathResource;
|
11 |
|
|
|
12 |
55926
|
alessia.ba
|
import static org.junit.Assert.assertEquals;
|
13 |
|
|
|
14 |
26600
|
sandro.lab
|
@RunWith(MockitoJUnit44Runner.class)
|
15 |
|
|
public class ApplyXsltTest {
|
16 |
|
|
|
17 |
|
|
TransformerFactory tf = TransformerFactory.newInstance();
|
18 |
|
|
|
19 |
|
|
private static final Class<?> transformerClass = net.sf.saxon.TransformerFactoryImpl.class;
|
20 |
|
|
|
21 |
|
|
@Test
|
22 |
|
|
public void testTransformerFactoryType() {
|
23 |
|
|
assertEquals(tf.getClass(), transformerClass);
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
@Test
|
27 |
|
|
public void applyXslt() throws IOException {
|
28 |
|
|
String record = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleRecord.xml")).getInputStream());
|
29 |
|
|
String layout = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleIndexLayout.xml")).getInputStream());
|
30 |
|
|
String indexXsltOfXslt = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/layoutToRecordStylesheet.xsl")).getInputStream());
|
31 |
|
|
ApplyXslt applyXslt = new ApplyXslt(IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/recordStylesheet.xsl")).getInputStream()));
|
32 |
|
|
ApplyXslt xslt1 = new ApplyXslt(indexXsltOfXslt);
|
33 |
|
|
String indexXslt = xslt1.evaluate(layout);
|
34 |
|
|
ApplyXslt xslt2 = new ApplyXslt(indexXslt);
|
35 |
|
|
String response = xslt2.evaluate(record);
|
36 |
|
|
System.out.println(response);
|
37 |
|
|
|
38 |
|
|
}
|
39 |
|
|
|
40 |
55926
|
alessia.ba
|
@Test(expected = NullPointerException.class)
|
41 |
|
|
public void applyXsltNullInput() throws IOException {
|
42 |
|
|
String record = null;
|
43 |
|
|
String layout = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleIndexLayout.xml")).getInputStream());
|
44 |
|
|
String indexXsltOfXslt = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/layoutToRecordStylesheet.xsl")).getInputStream());
|
45 |
|
|
ApplyXslt applyXslt = new ApplyXslt(IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/recordStylesheet.xsl")).getInputStream()));
|
46 |
|
|
ApplyXslt xslt1 = new ApplyXslt(indexXsltOfXslt);
|
47 |
|
|
String indexXslt = xslt1.evaluate(layout);
|
48 |
|
|
ApplyXslt xslt2 = new ApplyXslt(indexXslt);
|
49 |
|
|
String response = xslt2.evaluate(record);
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
@Test(expected = NullPointerException.class)
|
53 |
|
|
public void applyXsltEmptyInput() throws IOException {
|
54 |
|
|
String record = "";
|
55 |
|
|
String layout = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/sampleIndexLayout.xml")).getInputStream());
|
56 |
|
|
String indexXsltOfXslt = IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/layoutToRecordStylesheet.xsl")).getInputStream());
|
57 |
|
|
ApplyXslt applyXslt = new ApplyXslt(IOUtils.toString((new ClassPathResource("/eu/dnetlib/miscutils/functional/xml/recordStylesheet.xsl")).getInputStream()));
|
58 |
|
|
ApplyXslt xslt1 = new ApplyXslt(indexXsltOfXslt);
|
59 |
|
|
String indexXslt = xslt1.evaluate(layout);
|
60 |
|
|
ApplyXslt xslt2 = new ApplyXslt(indexXslt);
|
61 |
|
|
String response = xslt2.evaluate(record);
|
62 |
|
|
System.out.println(response);
|
63 |
|
|
|
64 |
|
|
}
|
65 |
|
|
|
66 |
26600
|
sandro.lab
|
}
|