Permalink
Browse files

Fix unit test so it doesn't depend on JSON order.

The test was failing because the strings didn't match exactly but they were still correct, it just happened that the order of the elements was different.
  • Loading branch information...
1 parent e04cbcf commit 213dab47e8b81f8560ec1c6fab5399b39d034d57 @buckett buckett committed Apr 15, 2013
Showing with 22 additions and 16 deletions.
  1. +22 −16 src/test/java/uk/ac/ox/oucs/sirlouie/PrimoServiceTest.java
@@ -8,6 +8,7 @@
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.json.JSONArray;
import org.json.JSONObject;
import org.xml.sax.SAXException;
@@ -618,23 +619,28 @@ public void testOLISToJSON() {
}
}
*/
- public void testORAoJSON() {
- try {
- String id = "ORAdebe641a-17ca-4196-ab2c-fe7565ced721";
- ResponseBean responseBean = new ResponseBean(id);
- Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, ORA_XML);
- responseBean.addSearObjects(beans);
-
- JSONObject json = responseBean.toJSON("2009-06-09T15:39:52.831+02:00");
- Assert.assertEquals(ORA_JSON.length(), json.toString().length());
-
- } catch (Exception e) {
- System.out.println("Exception caught ["+e.getLocalizedMessage()+"]");
- e.printStackTrace();
- Assert.fail("Exception caught ["+e.getLocalizedMessage()+"]");
- }
+ public void testORAoJSON() throws Exception {
+ String id = "ORAdebe641a-17ca-4196-ab2c-fe7565ced721";
+ ResponseBean responseBean = new ResponseBean(id);
+ Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, ORA_XML);
+ responseBean.addSearObjects(beans);
+
+ JSONObject json = responseBean.toJSON("2009-06-09T15:39:52.831+02:00");
+ // Check the basics
+ assertEquals("0.5", json.getString("version"));
+ assertNotNull(json.get("institution"));
+ assertEquals("http://www.ox.ac.uk", json.getJSONObject("institution").getString("href"));
+ // Check the document
+ JSONArray document = json.getJSONArray("document");
+ assertNotNull(document);
+ JSONObject first = document.getJSONObject(0);
+ assertNotNull(first);
+ assertEquals("ORAdebe641a-17ca-4196-ab2c-fe7565ced721", first.getString("id"));
+ assertNotNull(first.get("item"));
+ assertEquals("http://ora.ouls.ox.ac.uk/objects/uuid:debe641a-17ca-4196-ab2c-fe7565ced721"
+ ,first.getJSONArray("item").getJSONObject(0).getString("href"));
}
-
+
public void testNewXmlResponse() throws SAXException, IOException {
// Test that the library name lookups are working.
Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, NEW_OLIS_XML);

0 comments on commit 213dab4

Please sign in to comment.