From 7c9ed2475bfb426d786ba6e80d1965ebb74d518e Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Thu, 26 Mar 2015 12:25:12 +0000 Subject: [PATCH] Modified BioJsHTMLOutputTest to test specific json object values rather than comparing the raw json string values which are not usually ordered --- test/jalview/io/BioJsHTMLOutputTest.java | 62 ++++++++++++++++++++++++++---- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/test/jalview/io/BioJsHTMLOutputTest.java b/test/jalview/io/BioJsHTMLOutputTest.java index 4b817ab..694419f 100644 --- a/test/jalview/io/BioJsHTMLOutputTest.java +++ b/test/jalview/io/BioJsHTMLOutputTest.java @@ -4,7 +4,13 @@ import jalview.datamodel.Alignment; import jalview.datamodel.Sequence; import java.io.IOException; +import java.util.Iterator; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import org.junit.Assert; import org.junit.Test; import com.json.JSONException; @@ -30,21 +36,61 @@ public class BioJsHTMLOutputTest Alignment al = new Alignment(seqs); try { - String generatedJson = bioJsHtmlOuput + + JSONParser jsonParser = new JSONParser(); + String actualJsonString = bioJsHtmlOuput .getJalviewAlignmentAsJsonString(al); - org.junit.Assert - .assertEquals( - generatedJson.toLowerCase(), - "{\"globalColorScheme\":\"zappo\",\"seqs\":[{\"id\":\"1\",\"start\":1,\"name\":\"name/1-26\",\"features\":[],\"seq\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"end\":26}]}" - .toLowerCase()); - System.out.println("Output : " + generatedJson); + + JSONObject actualJsonObj = (JSONObject) jsonParser.parse(actualJsonString); + + System.out.println("Output : " + actualJsonString); + Assert.assertTrue(actualJsonObj.get("globalColorScheme") != null); + Assert.assertTrue((actualJsonObj.get("globalColorScheme").toString()).equals("zappo")); + + Assert.assertTrue(actualJsonObj.get("webStartUrl") != null); + Assert.assertTrue((actualJsonObj.get("webStartUrl").toString()) + .equals("http://www.jalview.org/services/launchApp")); + + JSONArray actualSeqJsonObj = (JSONArray) actualJsonObj.get("seqs"); + Assert.assertTrue(actualSeqJsonObj != null); + Assert.assertTrue(actualSeqJsonObj.size() == 1); + + @SuppressWarnings("unchecked") + Iterator jsonIter = actualSeqJsonObj.iterator(); + JSONObject jsonSeq = jsonIter.next(); + Assert.assertTrue(jsonSeq != null); + + Assert.assertTrue(jsonSeq.get("name") != null); + Assert.assertTrue((jsonSeq.get("name").toString()) + .equals("name/1-26")); + + Assert.assertTrue(jsonSeq.get("seq") != null); + Assert.assertTrue((jsonSeq.get("seq").toString()) + .equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ")); + + Assert.assertTrue(jsonSeq.get("id") != null); + Assert.assertTrue((jsonSeq.get("id").toString()).equals("1")); + + Assert.assertTrue(jsonSeq.get("start") != null); + Assert.assertTrue((jsonSeq.get("start").toString()).equals("1")); + + Assert.assertTrue(jsonSeq.get("end") != null); + Assert.assertTrue((jsonSeq.get("end").toString()).equals("26")); + + Assert.assertTrue(jsonSeq.get("features") != null); + Assert.assertTrue(jsonSeq.get("features").toString().equals("[]")); + + } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); + } catch (ParseException e) + { + e.printStackTrace(); } } - + } -- 1.7.10.2