Revision 50646
Added by Alessia Bardi about 6 years ago
ResultEntryTest.java | ||
---|---|---|
9 | 9 |
import com.google.gson.Gson; |
10 | 10 |
import eu.dnetlib.enabling.is.lookup.rmi.ISLookUpService; |
11 | 11 |
import eu.dnetlib.msro.rmi.MSROException; |
12 |
import org.apache.commons.lang3.StringEscapeUtils; |
|
12 | 13 |
import org.apache.velocity.app.VelocityEngine; |
13 | 14 |
import org.dom4j.Document; |
14 | 15 |
import org.dom4j.io.OutputFormat; |
... | ... | |
122 | 123 |
|
123 | 124 |
@Test |
124 | 125 |
public void testAsIndexRecord_json() throws Exception { |
125 |
final ResultEntry pub = (new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record.json")), ResultEntry.class);
|
|
126 |
testAsIndexRecord_json("test_record.json");
|
|
126 | 127 |
|
127 |
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd"); |
|
128 |
|
|
129 |
final Document doc = (new SAXReader()).read(new StringReader(xml)); |
|
130 |
|
|
131 |
final OutputFormat format = OutputFormat.createPrettyPrint(); |
|
132 |
|
|
133 |
final XMLWriter writer = new XMLWriter(System.out, format); |
|
134 |
|
|
135 |
writer.write(doc); |
|
136 |
|
|
137 |
/* writer.close(); */ |
|
138 |
|
|
139 | 128 |
} |
140 | 129 |
|
141 | 130 |
@Test |
142 | 131 |
public void testAsIndexRecord_json_with_greek_chars() throws Exception { |
143 | 132 |
|
144 |
final ResultEntry pub = |
|
145 |
(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_with_greek_chars.json")), ResultEntry.class); |
|
133 |
testAsIndexRecord_json("test_record_with_greek_chars.json"); |
|
146 | 134 |
|
147 |
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd"); |
|
148 |
|
|
149 |
final Document doc = (new SAXReader()).read(new StringReader(xml)); |
|
150 |
|
|
151 |
final OutputFormat format = OutputFormat.createPrettyPrint(); |
|
152 |
|
|
153 |
final XMLWriter writer = new XMLWriter(System.out, format); |
|
154 |
|
|
155 |
writer.write(doc); |
|
156 |
|
|
157 |
/* writer.close(); */ |
|
158 |
|
|
159 | 135 |
} |
160 | 136 |
|
161 | 137 |
@Test |
162 | 138 |
public void testAsIndexRecord_openaireId() throws Exception { |
163 | 139 |
|
164 |
final ResultEntry pub = |
|
165 |
(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_openaireId.json")), ResultEntry.class); |
|
140 |
testAsIndexRecord_json("test_record_openaireId.json"); |
|
166 | 141 |
|
167 |
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd");
|
|
142 |
}
|
|
168 | 143 |
|
169 |
final Document doc = (new SAXReader()).read(new StringReader(xml)); |
|
144 |
@Test(expected = MSROException.class) |
|
145 |
public void testAsIndexRecord_wrongOpenaireId() throws Exception { |
|
170 | 146 |
|
171 |
final OutputFormat format = OutputFormat.createPrettyPrint();
|
|
147 |
testAsIndexRecord_json("test_record_wrong_openaireId.json");
|
|
172 | 148 |
|
173 |
final XMLWriter writer = new XMLWriter(System.out, format);
|
|
149 |
}
|
|
174 | 150 |
|
175 |
writer.write(doc); |
|
151 |
@Test |
|
152 |
public void testAsIndexRecord_json_zenodo() throws Exception { |
|
176 | 153 |
|
177 |
/* writer.close(); */
|
|
154 |
testAsIndexRecord_json("test_zenodo.json");
|
|
178 | 155 |
|
179 | 156 |
} |
180 | 157 |
|
181 |
@Test(expected = MSROException.class) |
|
182 |
public void testAsIndexRecord_wrongOpenaireId() throws Exception { |
|
183 |
|
|
158 |
private void testAsIndexRecord_json(final String filename) throws Exception { |
|
184 | 159 |
final ResultEntry pub = |
185 |
(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream("test_record_wrong_openaireId.json")), ResultEntry.class);
|
|
160 |
(new Gson()).fromJson(new InputStreamReader(getClass().getResourceAsStream(filename)), ResultEntry.class);
|
|
186 | 161 |
|
187 | 162 |
final String xml = pub.asOafRecord(ve, lookUpService, "http://oaf/oaf.xsd"); |
163 |
System.out.println(xml); |
|
188 | 164 |
|
189 | 165 |
final Document doc = (new SAXReader()).read(new StringReader(xml)); |
190 | 166 |
|
... | ... | |
195 | 171 |
writer.write(doc); |
196 | 172 |
|
197 | 173 |
/* writer.close(); */ |
174 |
} |
|
198 | 175 |
|
176 |
@Test |
|
177 |
public void testEscapeUnicode(){ |
|
178 |
String unicodeTxt = "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$"; |
|
179 |
System.out.println(StringEscapeUtils.escapeXml11(unicodeTxt)); |
|
199 | 180 |
} |
200 | 181 |
|
201 | 182 |
|
Also available in: Unified diff
Use misc-utils escaper: the one in velocity is too old and does not cover all XML entities!