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