bb8784a3dd557c4dd1c919a1a477562c9c8e1620
[jalview.git] / test / jalview / io / BioJsHTMLOutputTest.java
1 package jalview.io;
2
3 import jalview.datamodel.Alignment;
4 import jalview.datamodel.Sequence;
5
6 import java.io.IOException;
7 import java.util.Iterator;
8
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;
14
15 import com.json.JSONException;
16
17 public class BioJsHTMLOutputTest
18 {
19
20
21   // @Test
22   public void getJalviewAlignmentAsJsonString()
23   {
24     BioJsHTMLOutput bioJsHtmlOuput = new BioJsHTMLOutput(null, null);
25     bioJsHtmlOuput.setGlobalColorScheme("Zappo");
26
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);
33     seqs[0] = seq;
34
35     Alignment al = new Alignment(seqs);
36     try
37     {
38
39       JSONParser jsonParser = new JSONParser();
40       String actualJsonString = bioJsHtmlOuput
41               .getJalviewAlignmentAsJsonString(al);
42
43       JSONObject actualJsonObj = (JSONObject) jsonParser.parse(actualJsonString);
44
45       // System.out.println("Output : " + actualJsonString);
46       Assert.assertTrue(actualJsonObj.get("globalColorScheme") != null); 
47       Assert.assertTrue((actualJsonObj.get("globalColorScheme").toString()).equals("zappo")); 
48       
49       Assert.assertTrue(actualJsonObj.get("webStartUrl") != null);
50       Assert.assertTrue((actualJsonObj.get("webStartUrl").toString())
51               .equals("http://www.jalview.org/services/launchApp"));
52
53       JSONArray actualSeqJsonObj = (JSONArray) actualJsonObj.get("seqs");
54       Assert.assertTrue(actualSeqJsonObj != null);
55       Assert.assertTrue(actualSeqJsonObj.size() == 1);
56
57       @SuppressWarnings("unchecked")
58       Iterator<JSONObject> jsonIter = actualSeqJsonObj.iterator();
59       JSONObject jsonSeq = jsonIter.next();
60       Assert.assertTrue(jsonSeq != null);
61
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"));
67
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"));
72
73       Assert.assertTrue("'id' cannot be null!", jsonSeq.get("id") != null);
74       Assert.assertTrue("Expected id mismatched!",
75               (jsonSeq.get("id").toString()).equals("1"));
76
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"));
81
82       Assert.assertTrue("'end' cannot be null!", jsonSeq.get("end") != null);
83       Assert.assertTrue("Expected end mismatched!",
84               (jsonSeq.get("end").toString()).equals("26"));
85
86       Assert.assertTrue("'features' cannot be null!",
87               jsonSeq.get("features") != null);
88       Assert.assertTrue("Expected features mismatched!",
89               jsonSeq.get("features").toString().equals("[]"));
90
91     } catch (IOException e)
92     {
93       e.printStackTrace();
94     } catch (JSONException e)
95     {
96       e.printStackTrace();
97     } catch (ParseException e)
98     {
99       e.printStackTrace();
100     }
101   }
102   
103 }