1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.hostedby;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.nio.charset.StandardCharsets;
|
5
|
import java.util.HashMap;
|
6
|
|
7
|
import com.google.common.collect.Maps;
|
8
|
import junit.framework.Assert;
|
9
|
import org.apache.commons.io.IOUtils;
|
10
|
import org.dom4j.Document;
|
11
|
import org.dom4j.DocumentException;
|
12
|
import org.dom4j.io.SAXReader;
|
13
|
import org.junit.Test;
|
14
|
import org.springframework.core.io.ClassPathResource;
|
15
|
import org.springframework.core.io.Resource;
|
16
|
|
17
|
public class PatchHostedByTest {
|
18
|
private PatchHostedBy p = new PatchHostedBy(new HashMap<>(),"", new HostedByCounters());
|
19
|
private Resource xmlInput = new ClassPathResource("/eu/dnetlib/msro/openaireplus/workflows/nodes/hostedby/input.xml");
|
20
|
private Resource xmlInput2 = new ClassPathResource("/eu/dnetlib/msro/openaireplus/workflows/nodes/hostedby/input2.xml");
|
21
|
private Resource xmlInput3 = new ClassPathResource("/eu/dnetlib/msro/openaireplus/workflows/nodes/hostedby/input3.xml");
|
22
|
private Resource xmlInputFails = new ClassPathResource("/eu/dnetlib/msro/openaireplus/workflows/nodes/hostedby/inputFails.xml");
|
23
|
|
24
|
|
25
|
private final SAXReader reader = new SAXReader();
|
26
|
|
27
|
private final String xpath = "substring-after(//*[local-name()='supplementTo']/*[local-name()='source']/@id,'.')";
|
28
|
|
29
|
@Test
|
30
|
public void testEvaluate() throws DocumentException, IOException {
|
31
|
final Document doc = reader.read(xmlInput.getInputStream());
|
32
|
for (Object o : doc.selectNodes(this.xpath)) {
|
33
|
Assert.assertEquals("journal10808", o);
|
34
|
}
|
35
|
}
|
36
|
|
37
|
|
38
|
@Test
|
39
|
public void testEvaluate3() throws Exception{
|
40
|
HashMap<String, HostedByEntry> map = Maps.newHashMap();
|
41
|
map.put("TIB.TEM", new HostedByEntry("123", "test repo"));
|
42
|
PatchHostedBy phb = new PatchHostedBy(map,"//*[local-name() = 'setSpec']", new HostedByCounters());
|
43
|
String res = phb.evaluate(IOUtils.toString(xmlInput3.getInputStream(), StandardCharsets.UTF_8));
|
44
|
Assert.assertTrue(res.contains("123"));
|
45
|
|
46
|
}
|
47
|
|
48
|
@Test
|
49
|
public void testInputFails() throws Exception{
|
50
|
HashMap<String, HostedByEntry> map = Maps.newHashMap();
|
51
|
map.put("0035-8711", new HostedByEntry("crossref::0035-8711", "Monthly Notices of the Royal Astronomical Society - RIGHT"));
|
52
|
PatchHostedBy phb = new PatchHostedBy(map,"//*[local-name()='journal']/@issn", new HostedByCounters());
|
53
|
String res = phb.evaluate(IOUtils.toString(xmlInputFails.getInputStream(), StandardCharsets.UTF_8));
|
54
|
}
|
55
|
|
56
|
}
|