1
|
package eu.dnetlib.x3m;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import eu.dnetlib.msro.workflows.nodes.transform.ApplyX3Mapping;
|
6
|
import org.apache.commons.io.IOUtils;
|
7
|
import org.junit.Test;
|
8
|
import org.springframework.core.io.ClassPathResource;
|
9
|
|
10
|
/**
|
11
|
* Created by alessia on 13/03/17.
|
12
|
*/
|
13
|
public class ApplyX3MappingTest {
|
14
|
|
15
|
final String recordPath = "/eu/dnetlib/x3m/new-10304741.xml";
|
16
|
final String mappingPath = "/eu/dnetlib/x3m/mappings.x3ml";
|
17
|
final String policyPath = "/eu/dnetlib/x3m/maria-policy.xml";
|
18
|
|
19
|
final String forthInputPath ="/eu/dnetlib/x3m/input.xml";
|
20
|
final String forthMappingPath = "/eu/dnetlib/x3m/mappingsWithoutGenerator.x3ml";
|
21
|
|
22
|
final String[] allInputFiles =
|
23
|
new String[] { recordPath, "/eu/dnetlib/x3m/new-10304737.xml", "/eu/dnetlib/x3m/new-10304738.xml", "/eu/dnetlib/x3m/new-10304739.xml",
|
24
|
"/eu/dnetlib/x3m/new-10304740.xml", "/eu/dnetlib/x3m/new-10304741.xml", "/eu/dnetlib/x3m/new-10304742.xml" };
|
25
|
|
26
|
@Test
|
27
|
public void testForth() throws Exception{
|
28
|
String m = getString(forthMappingPath);
|
29
|
String r = getString(forthInputPath);
|
30
|
|
31
|
ApplyX3Mapping x3m = new ApplyX3Mapping(m, null, true);
|
32
|
String res = x3m.apply(r);
|
33
|
System.out.println(res);
|
34
|
}
|
35
|
|
36
|
@Test
|
37
|
public void test() throws IOException {
|
38
|
String m = getString(mappingPath);
|
39
|
String g = getString(policyPath);
|
40
|
String r = getString(recordPath);
|
41
|
ApplyX3Mapping x3m = new ApplyX3Mapping(m, g, true);
|
42
|
String res = x3m.apply(r);
|
43
|
System.out.println(res);
|
44
|
|
45
|
}
|
46
|
|
47
|
@Test
|
48
|
public void testAll() throws IOException {
|
49
|
String m = getString(mappingPath);
|
50
|
String g = getString(policyPath);
|
51
|
|
52
|
ApplyX3Mapping x3m = new ApplyX3Mapping(m, g, true);
|
53
|
for(String path : allInputFiles){
|
54
|
String res = x3m.apply(getString(path));
|
55
|
System.out.println(res);
|
56
|
}
|
57
|
}
|
58
|
|
59
|
private String getString(final String classpath) {
|
60
|
try {
|
61
|
final ClassPathResource resource = new ClassPathResource(classpath);
|
62
|
return IOUtils.toString(resource.getInputStream(), "UTF-8");
|
63
|
}catch(IOException e){
|
64
|
return null;
|
65
|
}
|
66
|
}
|
67
|
}
|