Project

General

Profile

1 28340 alessia.ba
package eu.dnetlib.openaire.exporter;
2
3 29219 alessia.ba
import java.io.IOException;
4
import java.io.StringWriter;
5
6 40152 alessia.ba
import eu.dnetlib.miscutils.functional.xml.ApplyXslt;
7 29219 alessia.ba
import org.apache.commons.io.IOUtils;
8 28340 alessia.ba
import org.junit.Before;
9
import org.junit.Test;
10
import org.springframework.core.io.ClassPathResource;
11
import org.springframework.core.io.Resource;
12
13
public class EPrintsTest {
14
15 29219 alessia.ba
	private Resource wtProject = new ClassPathResource("eu/dnetlib/openaire/exporter/WT-project.xml");
16 33664 alessia.ba
	private Resource fctProject = new ClassPathResource("eu/dnetlib/openaire/exporter/FCT-project.xml");
17
	private Resource fp7Project = new ClassPathResource("eu/dnetlib/openaire/exporter/FP7-project.xml");
18 40152 alessia.ba
	private Resource sfiProject = new ClassPathResource("eu/dnetlib/openaire/exporter/SFI-project.xml");
19 40912 alessia.ba
	private Resource msesProject = new ClassPathResource("eu/dnetlib/openaire/exporter/MSES-project.xml");
20 29219 alessia.ba
21 28340 alessia.ba
	private Resource ePrintsXslt;
22
23
	@Before
24
	public void setUp() throws Exception {
25
		ePrintsXslt = new ClassPathResource("xslt/projects_eprints.xslt", getClass());
26
	}
27
28
	@Test
29 29219 alessia.ba
	public void testWTePrints() throws IOException {
30 40152 alessia.ba
		doTest(wtProject);
31 29219 alessia.ba
	}
32
33 33664 alessia.ba
	@Test
34
	public void testFCTePrints() throws IOException {
35 40152 alessia.ba
		doTest(fctProject);
36 33664 alessia.ba
	}
37
38
	@Test
39
	public void testFP7ePrints() throws IOException {
40 40152 alessia.ba
		doTest(fp7Project);
41 33664 alessia.ba
	}
42
43 40152 alessia.ba
	@Test
44
	public void testSFIePrints() throws IOException {
45
		doTest(sfiProject);
46
	}
47
48 40912 alessia.ba
	@Test
49
	public void testMSESePrints() throws IOException {
50
		doTest(msesProject);
51
	}
52
53 29219 alessia.ba
	private void assertTab(final String str) {
54 33664 alessia.ba
		System.out.println(str);
55 29219 alessia.ba
		String[] splitOnTab = str.split("\t");
56
		org.junit.Assert.assertTrue(splitOnTab.length > 1);
57 28340 alessia.ba
		System.out.println(splitOnTab[0]);
58
		System.out.println("According to the Java split function, now there is a tab, followed by:");
59
		System.out.println(splitOnTab[1]);
60
	}
61 40152 alessia.ba
62
	private void doTest(Resource resource) throws IOException {
63
		ApplyXslt applyXslt = new ApplyXslt(ePrintsXslt);
64
		StringWriter w = new StringWriter();
65
		IOUtils.copy(resource.getInputStream(), w);
66
		String res = applyXslt.evaluate(w.toString());
67
		assertTab(res);
68
	}
69 28340 alessia.ba
}