Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Fix unit test so it doesn't depend on JSON order.
Browse files Browse the repository at this point in the history
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
buckett committed Apr 15, 2013
1 parent e04cbcf commit 213dab4
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/test/java/uk/ac/ox/oucs/sirlouie/PrimoServiceTest.java
Expand Up @@ -8,6 +8,7 @@
import junit.framework.Assert; import junit.framework.Assert;
import junit.framework.TestCase; import junit.framework.TestCase;


import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;


Expand Down Expand Up @@ -618,23 +619,28 @@ public void testOLISToJSON() {
} }
} }
*/ */
public void testORAoJSON() { public void testORAoJSON() throws Exception {
try { String id = "ORAdebe641a-17ca-4196-ab2c-fe7565ced721";
String id = "ORAdebe641a-17ca-4196-ab2c-fe7565ced721"; ResponseBean responseBean = new ResponseBean(id);
ResponseBean responseBean = new ResponseBean(id); Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, ORA_XML);
Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, ORA_XML); responseBean.addSearObjects(beans);
responseBean.addSearObjects(beans);

JSONObject json = responseBean.toJSON("2009-06-09T15:39:52.831+02:00");
JSONObject json = responseBean.toJSON("2009-06-09T15:39:52.831+02:00"); // Check the basics
Assert.assertEquals(ORA_JSON.length(), json.toString().length()); assertEquals("0.5", json.getString("version"));

assertNotNull(json.get("institution"));
} catch (Exception e) { assertEquals("http://www.ox.ac.uk", json.getJSONObject("institution").getString("href"));
System.out.println("Exception caught ["+e.getLocalizedMessage()+"]"); // Check the document
e.printStackTrace(); JSONArray document = json.getJSONArray("document");
Assert.fail("Exception caught ["+e.getLocalizedMessage()+"]"); 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 { public void testNewXmlResponse() throws SAXException, IOException {
// Test that the library name lookups are working. // Test that the library name lookups are working.
Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, NEW_OLIS_XML); Collection<SearObject> beans = PrimoService.filterResponse(nameSpaceURI, NEW_OLIS_XML);
Expand Down

0 comments on commit 213dab4

Please sign in to comment.