3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.Sequence;
6 import java.io.IOException;
7 import java.util.Iterator;
9 import org.json.simple.JSONArray;
10 import org.json.simple.JSONObject;
11 import org.json.simple.parser.JSONParser;
12 import org.json.simple.parser.ParseException;
13 import org.junit.Assert;
15 import com.json.JSONException;
17 public class BioJsHTMLOutputTest
22 public void getJalviewAlignmentAsJsonString()
24 BioJsHTMLOutput bioJsHtmlOuput = new BioJsHTMLOutput(null, null);
25 bioJsHtmlOuput.setGlobalColorScheme("Zappo");
27 Sequence[] seqs = new Sequence[1];
28 Sequence seq = new Sequence("name", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 1, 26);
29 // SequenceFeature seqFeature = new SequenceFeature("type", "desc",
30 // "status", 1, 5, "jalview");
31 // seq.addSequenceFeature(seqFeature);
32 seq.setDatasetSequence(seq);
35 Alignment al = new Alignment(seqs);
39 JSONParser jsonParser = new JSONParser();
40 String actualJsonString = bioJsHtmlOuput
41 .getJalviewAlignmentAsJsonString(al);
43 JSONObject actualJsonObj = (JSONObject) jsonParser.parse(actualJsonString);
45 // System.out.println("Output : " + actualJsonString);
46 Assert.assertTrue(actualJsonObj.get("globalColorScheme") != null);
47 Assert.assertTrue((actualJsonObj.get("globalColorScheme").toString()).equals("zappo"));
49 Assert.assertTrue(actualJsonObj.get("webStartUrl") != null);
50 Assert.assertTrue((actualJsonObj.get("webStartUrl").toString())
51 .equals("http://www.jalview.org/services/launchApp"));
53 JSONArray actualSeqJsonObj = (JSONArray) actualJsonObj.get("seqs");
54 Assert.assertTrue(actualSeqJsonObj != null);
55 Assert.assertTrue(actualSeqJsonObj.size() == 1);
57 @SuppressWarnings("unchecked")
58 Iterator<JSONObject> jsonIter = actualSeqJsonObj.iterator();
59 JSONObject jsonSeq = jsonIter.next();
60 Assert.assertTrue(jsonSeq != null);
62 Assert.assertTrue("'name' cannot be null!",
63 jsonSeq.get("name") != null);
64 Assert.assertTrue("Expected name mismatched!",
65 (jsonSeq.get("name").toString())
66 .equals("name/1-26"));
68 Assert.assertTrue("'seq' cannot be null!", jsonSeq.get("seq") != null);
69 Assert.assertTrue("Expected sequence mismatched!", (jsonSeq
70 .get("seq").toString())
71 .equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
73 Assert.assertTrue("'id' cannot be null!", jsonSeq.get("id") != null);
74 Assert.assertTrue("Expected id mismatched!",
75 (jsonSeq.get("id").toString()).equals("1"));
77 Assert.assertTrue("'start' cannot be null!",
78 jsonSeq.get("start") != null);
79 Assert.assertTrue("Expected start mismatched!",
80 (jsonSeq.get("start").toString()).equals("1"));
82 Assert.assertTrue("'end' cannot be null!", jsonSeq.get("end") != null);
83 Assert.assertTrue("Expected end mismatched!",
84 (jsonSeq.get("end").toString()).equals("26"));
86 Assert.assertTrue("'features' cannot be null!",
87 jsonSeq.get("features") != null);
88 Assert.assertTrue("Expected features mismatched!",
89 jsonSeq.get("features").toString().equals("[]"));
91 } catch (IOException e)
94 } catch (JSONException e)
97 } catch (ParseException e)