7 |
7 |
import eu.dnetlib.actionmanager.actions.AtomicAction;
|
8 |
8 |
import eu.dnetlib.actionmanager.common.Agent;
|
9 |
9 |
import eu.dnetlib.data.mapreduce.hbase.dataimport.DOIBoostToActions;
|
10 |
|
import eu.dnetlib.data.mapreduce.util.XmlRecordFactory;
|
11 |
10 |
import eu.dnetlib.data.transform.Column;
|
12 |
11 |
import eu.dnetlib.data.transform.Row;
|
13 |
|
import eu.dnetlib.data.transform.XsltRowTransformerFactoryTest;
|
14 |
12 |
import org.apache.commons.lang3.StringUtils;
|
15 |
|
import org.dom4j.Document;
|
16 |
|
import org.dom4j.io.DocumentResult;
|
17 |
|
import org.dom4j.io.DocumentSource;
|
18 |
|
import org.dom4j.io.SAXReader;
|
19 |
13 |
import org.junit.Before;
|
20 |
14 |
import org.junit.Test;
|
21 |
15 |
|
22 |
16 |
import javax.xml.transform.Transformer;
|
23 |
|
import javax.xml.transform.TransformerFactory;
|
24 |
|
import java.io.*;
|
|
17 |
import java.io.BufferedReader;
|
|
18 |
import java.io.IOException;
|
|
19 |
import java.io.InputStream;
|
|
20 |
import java.io.InputStreamReader;
|
25 |
21 |
import java.util.List;
|
26 |
|
import java.util.Map;
|
27 |
22 |
|
28 |
|
public class DOIBoostToActionsTest extends XsltRowTransformerFactoryTest {
|
|
23 |
public class DOIBoostToActionsTest {
|
29 |
24 |
private String setName;
|
30 |
25 |
private Agent agent;
|
31 |
26 |
|
32 |
|
private final static String xslt =
|
33 |
|
"<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">\n"
|
34 |
|
+ " <xsl:template match=\"@*|node()\">\n"
|
35 |
|
+ " <xsl:copy>\n"
|
36 |
|
+ " <xsl:apply-templates select=\"@*|node()\"/>\n"
|
37 |
|
+ " </xsl:copy>\n"
|
38 |
|
+ " </xsl:template>\n"
|
39 |
|
+ "</xsl:stylesheet>";
|
40 |
27 |
|
41 |
|
private Transformer transformer;
|
42 |
28 |
|
43 |
29 |
@Before
|
44 |
30 |
public void setup() {
|
... | ... | |
65 |
51 |
}
|
66 |
52 |
|
67 |
53 |
|
|
54 |
|
|
55 |
|
68 |
56 |
private void doTestSingleDOIBoostActionToXML(final String filePath) throws Exception {
|
69 |
57 |
final List<Row> rows = Lists.newArrayList();
|
70 |
58 |
final InputStream is = this.getClass().getResourceAsStream(filePath);
|
... | ... | |
89 |
77 |
|
90 |
78 |
}
|
91 |
79 |
|
92 |
|
Map<String, XmlRecordFactory> stringXmlRecordFactoryMap = mapAll(buildTable(rows));
|
93 |
|
transformer = TransformerFactory.newInstance().newTransformer(new DocumentSource((new SAXReader()).read(new StringReader(xslt))));
|
94 |
80 |
|
95 |
|
final SAXReader saxReader = new SAXReader();
|
96 |
|
stringXmlRecordFactoryMap.values().forEach(it -> {
|
97 |
|
try {
|
98 |
|
final DocumentResult result = new DocumentResult();
|
99 |
|
final Document document = saxReader.read(new StringReader(it.build()));
|
100 |
|
transformer.transform(new DocumentSource(document), result);
|
101 |
|
System.out.println(result.getDocument().asXML());
|
102 |
|
}
|
103 |
|
catch (Exception e) {
|
104 |
|
e.printStackTrace();
|
105 |
|
}
|
106 |
81 |
|
107 |
|
});
|
108 |
|
|
109 |
82 |
}
|
110 |
83 |
|
111 |
84 |
private void doTestSingleDOIBoostAction(final String filePath) throws IOException {
|
fixed test