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;
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();
}
}
-
+
}