1 |
47423
|
michele.ar
|
package eu.dnetlib.msro.openaireplus.api.objects;
|
2 |
|
|
|
3 |
52789
|
alessia.ba
|
import com.google.gson.Gson;
|
4 |
|
|
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService;
|
5 |
|
|
import eu.dnetlib.openaire.directindex.api.DirecIndexApiException;
|
6 |
|
|
import eu.dnetlib.openaire.directindex.objects.PidEntry;
|
7 |
|
|
import eu.dnetlib.openaire.directindex.objects.ResultEntry;
|
8 |
50646
|
alessia.ba
|
import org.apache.commons.lang3.StringEscapeUtils;
|
9 |
47423
|
michele.ar
|
import org.apache.velocity.app.VelocityEngine;
|
10 |
|
|
import org.dom4j.Document;
|
11 |
|
|
import org.dom4j.io.OutputFormat;
|
12 |
|
|
import org.dom4j.io.SAXReader;
|
13 |
|
|
import org.dom4j.io.XMLWriter;
|
14 |
|
|
import org.junit.Before;
|
15 |
|
|
import org.junit.Test;
|
16 |
|
|
import org.junit.runner.RunWith;
|
17 |
|
|
import org.mockito.Mock;
|
18 |
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
19 |
|
|
|
20 |
55761
|
claudio.at
|
import java.io.InputStreamReader;
|
21 |
|
|
import java.io.StringReader;
|
22 |
|
|
import java.util.ArrayList;
|
23 |
|
|
import java.util.Arrays;
|
24 |
|
|
import java.util.Properties;
|
25 |
|
|
|
26 |
52789
|
alessia.ba
|
import static org.mockito.Matchers.anyString;
|
27 |
|
|
import static org.mockito.Mockito.when;
|
28 |
47423
|
michele.ar
|
|
29 |
|
|
/**
|
30 |
|
|
* Created by michele on 14/12/15.
|
31 |
|
|
*/
|
32 |
|
|
@RunWith(MockitoJUnitRunner.class)
|
33 |
|
|
public class ResultEntryTest {
|
34 |
|
|
|
35 |
|
|
private VelocityEngine ve;
|
36 |
|
|
|
37 |
56346
|
miriam.bag
|
private final String community_api = "https://dev-openaire.d4science.org/openaire/community/";
|
38 |
56335
|
miriam.bag
|
|
39 |
47423
|
michele.ar
|
@Mock
|
40 |
|
|
private ISLookUpService lookUpService;
|
41 |
|
|
|
42 |
|
|
@Before
|
43 |
|
|
public void setUp() throws Exception {
|
44 |
|
|
|
45 |
|
|
final Properties props = new Properties();
|
46 |
|
|
props.setProperty("resource.loader", "class");
|
47 |
|
|
props.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
|
48 |
|
|
props.setProperty("runtime.log.logsystem.class", "org.apache.velocity.runtime.log.Log4JLogChute");
|
49 |
|
|
ve = new VelocityEngine();
|
50 |
|
|
ve.init(props);
|
51 |
|
|
|
52 |
51236
|
michele.ar
|
when(lookUpService.quickSearchProfile(anyString())).thenAnswer(invocation -> {
|
53 |
|
|
final String query = invocation.getArguments()[0].toString();
|
54 |
|
|
if (query.contains("dnet:result_typologies")) {
|
55 |
53686
|
alessia.ba
|
return Arrays.asList("publication @@@ publication", "dataset @@@ dataset", "software @@@ software", "other @@@ other");
|
56 |
51236
|
michele.ar
|
} else if (query.contains("dnet:access_modes")) {
|
57 |
|
|
return Arrays.asList("OPEN @@@ Open Access");
|
58 |
|
|
} else if (query.contains("dnet:publication_resource")) {
|
59 |
|
|
return Arrays.asList("0001 @@@ Journal Article");
|
60 |
|
|
} else if (query.contains("dnet:pid_types")) {
|
61 |
|
|
return Arrays.asList("oai @@@ Open Archive Initiative", "doi @@@ Digital object identifier");
|
62 |
|
|
} else if (query.contains("dnet:languages")) {
|
63 |
|
|
return Arrays.asList("ita @@@ Italian");
|
64 |
|
|
} else if (query.contains("ContextDSResourceType")) {
|
65 |
|
|
return Arrays.asList(
|
66 |
|
|
"egi::classification::natsc::math::stats @@@ Statistics and Probability",
|
67 |
|
|
"egi::classification::natsc::math::pure @@@ Pure Mathematics",
|
68 |
|
|
"egi::classification::natsc::math @@@ Mathematics",
|
69 |
|
|
"egi::classification::natsc @@@ Natural Sciences",
|
70 |
|
|
"egi::classification @@@ EGI classification scheme",
|
71 |
|
|
"egi @@@ EGI");
|
72 |
|
|
} else {
|
73 |
|
|
return new ArrayList<String>();
|
74 |
47423
|
michele.ar
|
}
|
75 |
|
|
});
|
76 |
|
|
|
77 |
51236
|
michele.ar
|
when(lookUpService.getResourceProfileByQuery(anyString())).thenAnswer(invocation -> "REPO NAME @@@ repo________");
|
78 |
47423
|
michele.ar
|
}
|
79 |
|
|
|
80 |
|
|
@Test
|
81 |
|
|
public void testAsIndexRecord() throws Exception {
|
82 |
|
|
final ResultEntry pub = new ResultEntry();
|
83 |
|
|
pub.setOriginalId("ORIG_ID_1234");
|
84 |
|
|
pub.setTitle("TEST TITLE <test>");
|
85 |
|
|
pub.getAuthors().add("Michele Artini");
|
86 |
|
|
pub.getAuthors().add("Claudio Atzori");
|
87 |
|
|
pub.getAuthors().add("Alessia Bardi");
|
88 |
|
|
pub.setPublisher("Test publisher");
|
89 |
|
|
pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
|
90 |
|
|
pub.setLanguage("ita");
|
91 |
|
|
pub.setLicenseCode("OPEN");
|
92 |
|
|
pub.setResourceType("0001");
|
93 |
|
|
pub.setUrl("http://test.it/a=1&b=2");
|
94 |
|
|
pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
|
95 |
|
|
pub.getPids().add(new PidEntry("oai", "oai:1234"));
|
96 |
|
|
pub.setCollectedFromId("test________::zenodo");
|
97 |
|
|
pub.setHostedById("test________::UNKNOWN");
|
98 |
|
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
|
99 |
59954
|
alessia.ba
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/RCUK//244%2F909/EU/Making Capabilities Work/WorkAble");
|
100 |
47423
|
michele.ar
|
pub.getContexts().add("egi::classification::natsc::math::pure");
|
101 |
|
|
pub.getContexts().add("egi::classification::natsc::math::stats");
|
102 |
56335
|
miriam.bag
|
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
|
103 |
47423
|
michele.ar
|
|
104 |
51236
|
michele.ar
|
final Document doc = new SAXReader().read(new StringReader(xml));
|
105 |
47423
|
michele.ar
|
|
106 |
|
|
final OutputFormat format = OutputFormat.createPrettyPrint();
|
107 |
|
|
|
108 |
|
|
final XMLWriter writer = new XMLWriter(System.out, format);
|
109 |
|
|
|
110 |
|
|
writer.write(doc);
|
111 |
|
|
|
112 |
|
|
/* writer.close(); */
|
113 |
|
|
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
@Test
|
117 |
52789
|
alessia.ba
|
public void testAsIndexRecordAccessRight() throws Exception {
|
118 |
|
|
final ResultEntry pub = new ResultEntry();
|
119 |
|
|
pub.setOriginalId("ORIG_ID_1234");
|
120 |
|
|
pub.setTitle("TEST TITLE <test>");
|
121 |
|
|
pub.getAuthors().add("Michele Artini");
|
122 |
|
|
pub.getAuthors().add("Claudio Atzori");
|
123 |
|
|
pub.getAuthors().add("Alessia Bardi");
|
124 |
|
|
pub.setPublisher("Test publisher");
|
125 |
|
|
pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
|
126 |
|
|
pub.setLanguage("ita");
|
127 |
|
|
pub.setLicenseCode("CLOSED");
|
128 |
|
|
pub.setAccessRightCode("OPEN");
|
129 |
|
|
pub.setResourceType("0001");
|
130 |
|
|
pub.setUrl("http://test.it/a=1&b=2");
|
131 |
|
|
pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
|
132 |
|
|
pub.getPids().add(new PidEntry("oai", "oai:1234"));
|
133 |
|
|
pub.setCollectedFromId("test________::zenodo");
|
134 |
|
|
pub.setHostedById("test________::UNKNOWN");
|
135 |
|
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
|
136 |
|
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
|
137 |
|
|
pub.getContexts().add("egi::classification::natsc::math::pure");
|
138 |
|
|
pub.getContexts().add("egi::classification::natsc::math::stats");
|
139 |
56335
|
miriam.bag
|
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
|
140 |
52789
|
alessia.ba
|
|
141 |
|
|
final Document doc = new SAXReader().read(new StringReader(xml));
|
142 |
|
|
|
143 |
|
|
final OutputFormat format = OutputFormat.createPrettyPrint();
|
144 |
|
|
|
145 |
|
|
final XMLWriter writer = new XMLWriter(System.out, format);
|
146 |
|
|
|
147 |
|
|
writer.write(doc);
|
148 |
|
|
|
149 |
|
|
/* writer.close(); */
|
150 |
|
|
|
151 |
|
|
}
|
152 |
|
|
|
153 |
54784
|
alessia.ba
|
@Test
|
154 |
|
|
public void testAsORP() throws Exception {
|
155 |
|
|
final ResultEntry pub = new ResultEntry();
|
156 |
|
|
pub.setOriginalId("ORIG_ID_1234");
|
157 |
|
|
pub.setTitle("TEST TITLE <test>");
|
158 |
|
|
pub.getAuthors().add("Michele Artini");
|
159 |
|
|
pub.getAuthors().add("Claudio Atzori");
|
160 |
|
|
pub.getAuthors().add("Alessia Bardi");
|
161 |
|
|
pub.setPublisher("Test publisher");
|
162 |
|
|
pub.setDescription("DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION & DESCRIPTION ");
|
163 |
|
|
pub.setLanguage("ita");
|
164 |
|
|
pub.setLicenseCode("CLOSED");
|
165 |
|
|
pub.setAccessRightCode("OPEN");
|
166 |
|
|
pub.setResourceType("0020");
|
167 |
|
|
pub.setType("other");
|
168 |
|
|
pub.setUrl("http://test.it/a=1&b=2");
|
169 |
|
|
pub.getPids().add(new PidEntry("doi", "10.000/xyz-123"));
|
170 |
|
|
pub.getPids().add(new PidEntry("oai", "oai:1234"));
|
171 |
|
|
pub.setCollectedFromId("test________::zenodo");
|
172 |
|
|
pub.setHostedById("test________::UNKNOWN");
|
173 |
|
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/283595/EU//OpenAIREplus");
|
174 |
|
|
pub.getLinksToProjects().add("info:eu-repo/grantAgreement/EC/FP7/244909/EU/Making Capabilities Work/WorkAble");
|
175 |
|
|
pub.getContexts().add("egi::classification::natsc::math::pure");
|
176 |
|
|
pub.getContexts().add("egi::classification::natsc::math::stats");
|
177 |
56335
|
miriam.bag
|
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
|
178 |
52789
|
alessia.ba
|
|
179 |
54784
|
alessia.ba
|
final Document doc = new SAXReader().read(new StringReader(xml));
|
180 |
|
|
|
181 |
|
|
final OutputFormat format = OutputFormat.createPrettyPrint();
|
182 |
|
|
|
183 |
|
|
final XMLWriter writer = new XMLWriter(System.out, format);
|
184 |
|
|
|
185 |
|
|
writer.write(doc);
|
186 |
|
|
|
187 |
|
|
/* writer.close(); */
|
188 |
|
|
|
189 |
|
|
}
|
190 |
|
|
|
191 |
52789
|
alessia.ba
|
@Test
|
192 |
47423
|
michele.ar
|
public void testAsIndexRecord_json() throws Exception {
|
193 |
50646
|
alessia.ba
|
testAsIndexRecord_json("test_record.json");
|
194 |
47423
|
michele.ar
|
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
@Test
|
198 |
|
|
public void testAsIndexRecord_json_with_greek_chars() throws Exception {
|
199 |
|
|
|
200 |
50646
|
alessia.ba
|
testAsIndexRecord_json("test_record_with_greek_chars.json");
|
201 |
47423
|
michele.ar
|
|
202 |
|
|
}
|
203 |
|
|
|
204 |
48540
|
alessia.ba
|
@Test
|
205 |
|
|
public void testAsIndexRecord_openaireId() throws Exception {
|
206 |
|
|
|
207 |
50646
|
alessia.ba
|
testAsIndexRecord_json("test_record_openaireId.json");
|
208 |
48540
|
alessia.ba
|
|
209 |
50646
|
alessia.ba
|
}
|
210 |
48540
|
alessia.ba
|
|
211 |
51236
|
michele.ar
|
@Test(expected = DirecIndexApiException.class)
|
212 |
50646
|
alessia.ba
|
public void testAsIndexRecord_wrongOpenaireId() throws Exception {
|
213 |
48540
|
alessia.ba
|
|
214 |
50646
|
alessia.ba
|
testAsIndexRecord_json("test_record_wrong_openaireId.json");
|
215 |
48540
|
alessia.ba
|
|
216 |
50646
|
alessia.ba
|
}
|
217 |
48540
|
alessia.ba
|
|
218 |
50646
|
alessia.ba
|
@Test
|
219 |
|
|
public void testAsIndexRecord_json_zenodo() throws Exception {
|
220 |
48540
|
alessia.ba
|
|
221 |
50646
|
alessia.ba
|
testAsIndexRecord_json("test_zenodo.json");
|
222 |
48540
|
alessia.ba
|
|
223 |
|
|
}
|
224 |
|
|
|
225 |
53567
|
alessia.ba
|
@Test
|
226 |
|
|
public void testAsIndexRecord_json_zenodoWithAmpersand() throws Exception {
|
227 |
|
|
|
228 |
|
|
testAsIndexRecord_json("test_zenodoAmpersandEverywhere.json");
|
229 |
|
|
|
230 |
|
|
}
|
231 |
|
|
|
232 |
53686
|
alessia.ba
|
@Test
|
233 |
|
|
public void testAsIndexRecord_json_software() throws Exception {
|
234 |
|
|
|
235 |
|
|
testAsIndexRecord_json("test_record_software.json");
|
236 |
|
|
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
@Test
|
240 |
|
|
public void testAsIndexRecord_json_orp() throws Exception {
|
241 |
|
|
|
242 |
|
|
testAsIndexRecord_json("test_record_orp.json");
|
243 |
|
|
|
244 |
|
|
}
|
245 |
|
|
|
246 |
50646
|
alessia.ba
|
private void testAsIndexRecord_json(final String filename) throws Exception {
|
247 |
48541
|
alessia.ba
|
final ResultEntry pub =
|
248 |
51236
|
michele.ar
|
new Gson().fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
|
249 |
55047
|
miriam.bag
|
|
250 |
55761
|
claudio.at
|
|
251 |
56335
|
miriam.bag
|
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd",community_api);
|
252 |
55047
|
miriam.bag
|
//System.out.println(xml);
|
253 |
48541
|
alessia.ba
|
|
254 |
51236
|
michele.ar
|
final Document doc = new SAXReader().read(new StringReader(xml));
|
255 |
48541
|
alessia.ba
|
|
256 |
|
|
final OutputFormat format = OutputFormat.createPrettyPrint();
|
257 |
|
|
|
258 |
|
|
final XMLWriter writer = new XMLWriter(System.out, format);
|
259 |
|
|
|
260 |
|
|
writer.write(doc);
|
261 |
|
|
|
262 |
|
|
/* writer.close(); */
|
263 |
50646
|
alessia.ba
|
}
|
264 |
48541
|
alessia.ba
|
|
265 |
50646
|
alessia.ba
|
@Test
|
266 |
55761
|
claudio.at
|
public void testAsIndexRecord_json_zenodocommunities()throws Exception{
|
267 |
|
|
testAsIndexRecord_json("test_zenodo_community.json");
|
268 |
54615
|
miriam.bag
|
}
|
269 |
|
|
|
270 |
|
|
@Test
|
271 |
56346
|
miriam.bag
|
public void testAsIndexRecordFromSandbox_json_zenodocommunities()throws Exception{
|
272 |
|
|
testAsIndexRecord_json("test_zenodo_community2.json");
|
273 |
|
|
}
|
274 |
|
|
|
275 |
|
|
@Test
|
276 |
51236
|
michele.ar
|
public void testEscapeUnicode() {
|
277 |
|
|
final String unicodeTxt =
|
278 |
|
|
"i.e. closed curves of the form $t\ud835\udfc4 [0,2\u03c0] \u21a6 (\\cos t)u + (\\sin t)v$ for suitable orthogonal vectors $u$";
|
279 |
50646
|
alessia.ba
|
System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt));
|
280 |
48541
|
alessia.ba
|
}
|
281 |
|
|
|
282 |
47423
|
michele.ar
|
}
|