1
|
package eu.dnetlib.wds.transformation;
|
2
|
|
3
|
import eu.dnetlib.enabling.locators.UniqueServiceLocator;
|
4
|
import eu.dnetlib.rmi.enabling.ISLookUpService;
|
5
|
import eu.dnetlib.wds.utils.WDSUtils;
|
6
|
import org.apache.commons.io.IOUtils;
|
7
|
import org.junit.Before;
|
8
|
import org.junit.Test;
|
9
|
import org.junit.runner.RunWith;
|
10
|
import org.mockito.Mock;
|
11
|
import org.mockito.Mockito;
|
12
|
import org.mockito.runners.MockitoJUnitRunner;
|
13
|
|
14
|
import javax.xml.transform.OutputKeys;
|
15
|
import javax.xml.transform.Transformer;
|
16
|
import javax.xml.transform.TransformerFactory;
|
17
|
import javax.xml.transform.stream.StreamResult;
|
18
|
import javax.xml.transform.stream.StreamSource;
|
19
|
import java.io.InputStream;
|
20
|
import java.io.StringWriter;
|
21
|
import java.util.Arrays;
|
22
|
|
23
|
import static org.mockito.Mockito.*;
|
24
|
|
25
|
@RunWith(MockitoJUnitRunner.class)
|
26
|
public class WDSTransformTest {
|
27
|
|
28
|
@Mock
|
29
|
UniqueServiceLocator serviceLocator;
|
30
|
|
31
|
|
32
|
@Mock
|
33
|
ISLookUpService isLookUpService;
|
34
|
|
35
|
|
36
|
@Mock
|
37
|
WDSUtils wdsUtils;
|
38
|
|
39
|
|
40
|
@Before
|
41
|
public void setup() throws Exception {
|
42
|
|
43
|
serviceLocator = mock(UniqueServiceLocator.class);
|
44
|
isLookUpService = mock(ISLookUpService.class);
|
45
|
wdsUtils = mock(WDSUtils.class);
|
46
|
when(serviceLocator.getService(ISLookUpService.class)).thenReturn(isLookUpService);
|
47
|
|
48
|
|
49
|
WDSUtils.setInstance(wdsUtils);
|
50
|
|
51
|
when(wdsUtils.getServiceLocator()).thenReturn(serviceLocator);
|
52
|
|
53
|
|
54
|
when(isLookUpService.quickSearchProfile(WDSUtils.HOSTED_BY_MAP_QUERY)).thenReturn(
|
55
|
Arrays.asList(
|
56
|
"14e0bfe8-a224-4516-ba74-056d5469e0e8<-->BIFWMS<-->Center for Biodiversity and Conservation, American Museum of Natural History",
|
57
|
"8cc5c356-bd45-47f1-85c7-a77cb968aa60<-->JIC<-->John Innes Centre",
|
58
|
"d5ea90ca-5faf-4c45-a8c1-84274ef672ff<-->DU/GPR<-->Great Plains Region, Ducks Unlimited, Inc.",
|
59
|
"c417024e-1d24-446b-88c7-6456fc44082c<-->WFC/FB<-->FishBase, WorldFish Center",
|
60
|
"50acc4de-aa45-4979-800a-948eefc291d6<-->CVAG<-->Coachella Valley Association of Governments",
|
61
|
"92dc7d21-d324-42da-9d82-3ec0f9b744f1<-->MDIWQC<-->Mount Desert Island Water Quality Coalition",
|
62
|
"43ce00b0-642e-4c1b-a3ca-e1424e392805<-->BDS<-->British Dragonfly Society",
|
63
|
"c7898f3c-6525-496f-a1f9-7794e6cabf7d<-->NSGIC<-->National States Geographic Information Council",
|
64
|
"bbdfc1d8-f44a-4898-8bc5-251c57b262d9<-->EFI<-->European Forest Institute",
|
65
|
"00a50ef2-5ed3-476d-bbfa-2b6558657672<-->SWRI<-->Southwest Research Institute")
|
66
|
);
|
67
|
}
|
68
|
|
69
|
|
70
|
@Test
|
71
|
public void testCMRTransform() throws Exception {
|
72
|
final InputStream xsltAsStream = getClass().getResourceAsStream("/eu/dnetlib/wds/transform/cmr_transformation.xslt");
|
73
|
|
74
|
|
75
|
final TransformerFactory factory = TransformerFactory.newInstance();
|
76
|
factory.newTransformer();
|
77
|
final StreamSource xsltSource = new StreamSource(xsltAsStream);
|
78
|
final InputStream recordStream = this.getClass().getResourceAsStream("/eu/dnetlib/wds/transform/cmr.xml");
|
79
|
final Transformer transformer = factory.newTransformer(xsltSource);
|
80
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
81
|
final StringWriter output = new StringWriter();
|
82
|
transformer.transform(new StreamSource(recordStream), new StreamResult(output));
|
83
|
System.out.println(output.toString());
|
84
|
}
|
85
|
|
86
|
@Test
|
87
|
public void testDCTransform() throws Exception{
|
88
|
final InputStream xsltAsStream = getClass().getResourceAsStream("/eu/dnetlib/wds/transform/dc2dbmf.xslt");
|
89
|
final TransformerFactory factory = TransformerFactory.newInstance();
|
90
|
factory.newTransformer();
|
91
|
final StreamSource xsltSource = new StreamSource(xsltAsStream);
|
92
|
final InputStream recordStream = this.getClass().getResourceAsStream("/eu/dnetlib/wds/transform/dc.xml");
|
93
|
final Transformer transformer = factory.newTransformer(xsltSource);
|
94
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
95
|
final StringWriter output = new StringWriter();
|
96
|
transformer.transform(new StreamSource(recordStream), new StreamResult(output));
|
97
|
System.out.println(output.toString());
|
98
|
}
|
99
|
|
100
|
@Test
|
101
|
public void testDIFTransform() throws Exception{
|
102
|
final InputStream xsltAsStream = getClass().getResourceAsStream("/eu/dnetlib/wds/transform/dif2dbmf.xslt");
|
103
|
final TransformerFactory factory = TransformerFactory.newInstance();
|
104
|
factory.newTransformer();
|
105
|
final StreamSource xsltSource = new StreamSource(xsltAsStream);
|
106
|
final InputStream recordStream = this.getClass().getResourceAsStream("/eu/dnetlib/wds/transform/dif.xml");
|
107
|
final Transformer transformer = factory.newTransformer(xsltSource);
|
108
|
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
109
|
final StringWriter output = new StringWriter();
|
110
|
transformer.transform(new StreamSource(recordStream), new StreamResult(output));
|
111
|
System.out.println(output.toString());
|
112
|
}
|
113
|
|
114
|
|
115
|
}
|