1
|
package eu.dnetlib.msro.workflows.nodes;
|
2
|
|
3
|
import static org.junit.Assert.assertTrue;
|
4
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
5
|
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
6
|
|
7
|
import java.util.HashMap;
|
8
|
import java.util.Map;
|
9
|
|
10
|
import org.apache.commons.io.IOUtils;
|
11
|
import org.dom4j.DocumentException;
|
12
|
import org.dom4j.DocumentHelper;
|
13
|
import org.junit.Before;
|
14
|
import org.junit.Ignore;
|
15
|
import org.junit.Test;
|
16
|
import org.springframework.core.io.FileSystemResource;
|
17
|
import org.springframework.core.io.Resource;
|
18
|
|
19
|
public class PatchCinecaIdsJobNodeTest {
|
20
|
|
21
|
private PatchCinecaIdsJobNode node = new PatchCinecaIdsJobNode();
|
22
|
|
23
|
private Map<String, String> idMap;
|
24
|
|
25
|
@Before
|
26
|
public void setUp() throws Exception {
|
27
|
idMap = new HashMap<>();
|
28
|
idMap.put("20.500.14243/404244", "425561");
|
29
|
idMap.put("20.500.14243/340721", "377451");
|
30
|
idMap.put("20.500.14243/340722", "377452");
|
31
|
idMap.put("20.500.14243/340723", "377453");
|
32
|
}
|
33
|
|
34
|
@Test
|
35
|
@Ignore
|
36
|
public void testLoadMap() throws Exception {
|
37
|
final Resource r = new FileSystemResource("/Users/michele/Develop/scripts/openportal_cineca/people-iris-ids.json");
|
38
|
final Map<String, String> map = node.loadMap(r);
|
39
|
System.out.println("MAP SIZE: " + map.size());
|
40
|
assertTrue(map.size() > 10000);
|
41
|
}
|
42
|
|
43
|
@Test
|
44
|
public void testPatchId_1() throws Exception {
|
45
|
final String[] arr = patchId("record-01.xml");
|
46
|
assertEquals("oai:it.cnr:prodotti:294753", arr[0]);
|
47
|
assertEquals("oai:it.cnr:prodotti:294753", arr[1]);
|
48
|
assertEquals(arr[0], arr[1]);
|
49
|
}
|
50
|
|
51
|
@Test
|
52
|
public void testPatchId_2() throws Exception {
|
53
|
final String[] arr = patchId("record-02.xml");
|
54
|
assertEquals("oai:iris.cnr.it:20.500.14243/404244", arr[0]);
|
55
|
assertEquals("oai:it.cnr:prodotti:425561", arr[1]);
|
56
|
assertNotEquals(arr[0], arr[1]);
|
57
|
}
|
58
|
|
59
|
@Test
|
60
|
public void testPatchId_3() throws Exception {
|
61
|
final String[] arr = patchId("record-03.xml");
|
62
|
assertEquals("oai:iris.cnr.it:20.500.14243/43516", arr[0]);
|
63
|
assertEquals("oai:iris.cnr.it:20.500.14243/43516", arr[1]);
|
64
|
assertEquals(arr[0], arr[1]);
|
65
|
}
|
66
|
|
67
|
private String[] patchId(final String file) throws Exception {
|
68
|
final String xmlIn = IOUtils.toString(getClass().getResourceAsStream(file));
|
69
|
final String xmlOut = node.patchId(xmlIn, idMap);
|
70
|
return new String[] { extractId(xmlIn), extractId(xmlOut) };
|
71
|
}
|
72
|
|
73
|
private String extractId(final String xml) throws DocumentException {
|
74
|
return DocumentHelper.parseText(xml).valueOf("//*[local-name()='header']/*[local-name()='identifier']");
|
75
|
}
|
76
|
|
77
|
}
|