Modified BioJsHTMLOutputTest to test specific json object values rather than comparin...
authortcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 26 Mar 2015 12:25:12 +0000 (12:25 +0000)
committertcofoegbu <tcnofoegbu@dundee.ac.uk>
Thu, 26 Mar 2015 12:25:12 +0000 (12:25 +0000)
test/jalview/io/BioJsHTMLOutputTest.java

index 4b817ab..694419f 100644 (file)
@@ -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<JSONObject> 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();
     }
   }
-
+  
 }