1
|
package eu.dnetlib.openaire.exporter;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
|
5
|
import org.antlr.stringtemplate.StringTemplate;
|
6
|
import org.apache.commons.io.IOUtils;
|
7
|
import org.junit.Before;
|
8
|
import org.junit.Test;
|
9
|
import org.springframework.core.io.ClassPathResource;
|
10
|
import org.springframework.core.io.Resource;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
|
14
|
public class ProjectsControllerTest {
|
15
|
|
16
|
private String queryTemplate = "/eu/dnetlib/openaire/exporter/sql/projects_fundings.sql.st";
|
17
|
|
18
|
private Resource expectedQueryTemplate = new ClassPathResource("/eu/dnetlib/openaire/exporter/sql/expected_projects_fundings.sql.st");
|
19
|
|
20
|
private ProjectsController controller;
|
21
|
private ProjectQueryParams params;
|
22
|
|
23
|
@Before
|
24
|
public void setup() {
|
25
|
controller = new ProjectsController();
|
26
|
Resource template = new ClassPathResource(queryTemplate);
|
27
|
|
28
|
controller.setProjectsFundingQueryTemplate(template);
|
29
|
params = new ProjectQueryParams();
|
30
|
}
|
31
|
|
32
|
@Test
|
33
|
public void testObtainFP7Query() throws IllegalArgumentException, IOException {
|
34
|
params.setFundingProgramme("FP7");
|
35
|
params.setFundingPath(null);
|
36
|
String res = controller.obtainQuery(params);
|
37
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
38
|
st.setAttribute("fundingprefix", "ec__________::EC::FP7");
|
39
|
System.out.println(res);
|
40
|
System.out.println(st);
|
41
|
assertEquals(st.toString(), res);
|
42
|
}
|
43
|
|
44
|
@Test
|
45
|
public void testObtainFP7QuerySP1() throws IllegalArgumentException, IOException {
|
46
|
params.setFundingProgramme("FP7");
|
47
|
params.setFundingPath("SP1");
|
48
|
String res = controller.obtainQuery(params);
|
49
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
50
|
st.setAttribute("fundingprefix", "ec__________::EC::FP7::SP1");
|
51
|
System.out.println(res);
|
52
|
assertEquals(st.toString(), res);
|
53
|
}
|
54
|
|
55
|
@Test
|
56
|
public void testObtainFP7QueryHealth() throws IllegalArgumentException, IOException {
|
57
|
params.setFundingProgramme("FP7");
|
58
|
params.setFundingPath("SP1::HEALTH");
|
59
|
String res = controller.obtainQuery(params);
|
60
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
61
|
st.setAttribute("fundingprefix", "ec__________::EC::FP7::SP1::HEALTH");
|
62
|
System.out.println(res);
|
63
|
assertEquals(st.toString(), res);
|
64
|
}
|
65
|
|
66
|
@Test
|
67
|
public void testObtainFP7QueryHealth2() throws IllegalArgumentException, IOException {
|
68
|
params.setFundingProgramme("FP7");
|
69
|
params.setFundingPath("%::HEALTH");
|
70
|
String res = controller.obtainQuery(params);
|
71
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
72
|
st.setAttribute("fundingprefix", "ec__________::EC::FP7::%::HEALTH");
|
73
|
System.out.println(res);
|
74
|
assertEquals(st.toString(), res);
|
75
|
}
|
76
|
|
77
|
@Test
|
78
|
public void testObtainWellcomeTrustQuery() throws IllegalArgumentException, IOException {
|
79
|
params.setFundingProgramme("WT");
|
80
|
params.setFundingPath(null);
|
81
|
String res = controller.obtainQuery(params);
|
82
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
83
|
st.setAttribute("fundingprefix", "wt__________::WT");
|
84
|
System.out.println(res);
|
85
|
assertEquals(st.toString(), res);
|
86
|
}
|
87
|
|
88
|
@Test
|
89
|
public void testObtainFCTQuery() throws IllegalArgumentException, IOException {
|
90
|
params.setFundingProgramme("FCT");
|
91
|
params.setFundingPath(null);
|
92
|
String res = controller.obtainQuery(params);
|
93
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
94
|
st.setAttribute("fundingprefix", "fct_________::FCT");
|
95
|
System.out.println(res);
|
96
|
assertEquals(st.toString(), res);
|
97
|
}
|
98
|
|
99
|
@Test
|
100
|
public void testQueryWithDateParams() throws IllegalArgumentException, IOException {
|
101
|
params.setFundingProgramme("WT");
|
102
|
params.setFundingPath(null);
|
103
|
params.setStartFrom("2015-05-04");
|
104
|
String res = controller.obtainQuery(params);
|
105
|
System.out.println(res);
|
106
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
107
|
st.setAttribute("fundingprefix", "wt__________::WT");
|
108
|
String q = st.toString() + " AND startdate >= '2015-05-04'";
|
109
|
assertEquals(q, res);
|
110
|
}
|
111
|
|
112
|
@Test
|
113
|
public void testObtainSNSFQuery() throws IllegalArgumentException, IOException {
|
114
|
params.setFundingProgramme("SNSF");
|
115
|
params.setFundingPath(null);
|
116
|
String res = controller.obtainQuery(params);
|
117
|
final StringTemplate st = new StringTemplate(IOUtils.toString(expectedQueryTemplate.getInputStream(), ProjectsController.UTF8));
|
118
|
st.setAttribute("fundingprefix", "snsf________::SNSF");
|
119
|
System.out.println(res);
|
120
|
assertEquals(st.toString(), res);
|
121
|
}
|
122
|
|
123
|
}
|