Clover icon

Coverage Report

  1. Project Clover database Thu Nov 7 2024 17:01:39 GMT
  2. Package jalview.io

File JSONFileTest.java

 

Code metrics

26
231
19
1
635
499
57
0.25
12.16
19
3

Classes

Class Line # Actions
JSONFileTest 58 231 57
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import static org.testng.AssertJUnit.assertNotNull;
24   
25    import jalview.api.AlignExportSettingsI;
26    import jalview.datamodel.AlignExportSettingsAdapter;
27    import jalview.datamodel.Alignment;
28    import jalview.datamodel.AlignmentAnnotation;
29    import jalview.datamodel.AlignmentI;
30    import jalview.datamodel.Annotation;
31    import jalview.datamodel.HiddenColumns;
32    import jalview.datamodel.Sequence;
33    import jalview.datamodel.SequenceFeature;
34    import jalview.datamodel.SequenceGroup;
35    import jalview.datamodel.SequenceI;
36    import jalview.datamodel.features.SequenceFeatures;
37    import jalview.gui.AlignFrame;
38    import jalview.gui.JvOptionPane;
39    import jalview.json.binding.biojson.v1.ColourSchemeMapper;
40    import jalview.schemes.ColourSchemeI;
41    import jalview.schemes.ResidueColourScheme;
42   
43    import java.io.IOException;
44    import java.util.ArrayList;
45    import java.util.HashMap;
46    import java.util.Iterator;
47    import java.util.List;
48    import java.util.Map;
49   
50    import org.testng.Assert;
51    import org.testng.AssertJUnit;
52    import org.testng.annotations.AfterTest;
53    import org.testng.annotations.BeforeClass;
54    import org.testng.annotations.BeforeMethod;
55    import org.testng.annotations.BeforeTest;
56    import org.testng.annotations.Test;
57   
 
58    public class JSONFileTest
59    {
60   
 
61  0 toggle @BeforeClass(alwaysRun = true)
62    public void setUpJvOptionPane()
63    {
64  0 JvOptionPane.setInteractiveMode(false);
65  0 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
66    }
67   
68    private int TEST_SEQ_HEIGHT = 0;
69   
70    private int TEST_GRP_HEIGHT = 0;
71   
72    private int TEST_ANOT_HEIGHT = 0;
73   
74    private int TEST_CS_HEIGHT = 0;
75   
76    private String TEST_JSON_FILE = "examples/example.json";
77   
78    private Alignment alignment;
79   
80    private HashMap<String, SequenceI> expectedSeqs = new HashMap<>();
81   
82    private HashMap<String, AlignmentAnnotation> expectedAnnots = new HashMap<>();
83   
84    private HashMap<String, SequenceGroup> expectedGrps = new HashMap<>();
85   
86    private HiddenColumns expectedColSel = new HiddenColumns();
87   
88    private SequenceI[] expectedHiddenSeqs = new SequenceI[1];
89   
90    private AlignmentI testAlignment;
91   
92    private int passedCount;
93   
94    private JSONFile testJsonFile;
95   
96    private JSONFile jf;
97   
98    private AlignExportSettingsI exportSettings;
99   
 
100  0 toggle @BeforeTest(alwaysRun = true)
101    public void setup() throws Exception
102    {
103    /*
104    * construct expected values
105    * nb this have to match the data in examples/example.json
106    */
107    // create and add sequences
108  0 Sequence[] seqs = new Sequence[5];
109  0 seqs[0] = new Sequence("FER_CAPAN",
110    "SVSATMISTSFMPRKPAVTSL-KPIPNVGE--ALF", 3, 34);
111  0 seqs[1] = new Sequence("FER1_SOLLC",
112    "SISGTMISTSFLPRKPAVTSL-KAISNVGE--ALF", 3, 34);
113  0 seqs[2] = new Sequence("Q93XJ9_SOLTU",
114    "SISGTMISTSFLPRKPVVTSL-KAISNVGE--ALF", 3, 34);
115  0 seqs[3] = new Sequence("FER1_PEA",
116    "ALYGTAVSTSFLRTQPMPMSV-TTTKAFSN--GFL", 6, 37);
117  0 seqs[4] = new Sequence("Q7XA98_TRIPR",
118    "ALYGTAVSTSFMRRQPVPMSV-ATTTTTKAFPSGF", 6, 39);
119   
120  0 SequenceI hiddenSeq = new Sequence("FER_TOCH",
121    "FILGTMISKSFLFRKPAVTSL-KAISNVGE--ALF", 3, 34);
122  0 expectedHiddenSeqs[0] = hiddenSeq;
123   
124    // create and add sequence features
125  0 SequenceFeature seqFeature2 = new SequenceFeature("feature_x",
126    "theDesc", 6, 15, "Jalview");
127  0 SequenceFeature seqFeature3 = new SequenceFeature("feature_x",
128    "theDesc", 9, 18, "Jalview");
129  0 SequenceFeature seqFeature4 = new SequenceFeature("feature_x",
130    "theDesc", 9, 18, "Jalview");
131    // non-positional feature:
132  0 SequenceFeature seqFeature5 = new SequenceFeature("Domain",
133    "My description", 0, 0, "Pfam");
134  0 seqs[2].addSequenceFeature(seqFeature2);
135  0 seqs[3].addSequenceFeature(seqFeature3);
136  0 seqs[4].addSequenceFeature(seqFeature4);
137  0 seqs[2].addSequenceFeature(seqFeature5);
138   
139  0 for (Sequence seq : seqs)
140    {
141  0 seq.createDatasetSequence();
142  0 expectedSeqs.put(seq.getName(), seq);
143    }
144   
145    // create and add a sequence group
146  0 List<SequenceI> grpSeqs = new ArrayList<>();
147  0 grpSeqs.add(seqs[1]);
148  0 grpSeqs.add(seqs[2]);
149  0 grpSeqs.add(seqs[3]);
150  0 grpSeqs.add(seqs[4]);
151  0 SequenceGroup seqGrp = new SequenceGroup(grpSeqs, "JGroup:1883305585",
152    null, true, true, false, 21, 29);
153  0 ColourSchemeI scheme = ColourSchemeMapper
154    .getJalviewColourScheme("zappo", seqGrp);
155  0 seqGrp.cs.setColourScheme(scheme);
156  0 seqGrp.setShowNonconserved(false);
157  0 seqGrp.setDescription(null);
158   
159  0 expectedGrps.put(seqGrp.getName(), seqGrp);
160   
161    // create and add annotation
162  0 Annotation[] annot = new Annotation[35];
163  0 annot[0] = new Annotation("", "", '\u0000', 0);
164  0 annot[1] = new Annotation("", "", '\u0000', 0);
165  0 annot[2] = new Annotation("α", "", 'H', 0);
166  0 annot[3] = new Annotation("α", "", 'H', 0);
167  0 annot[4] = new Annotation("α", "", 'H', 0);
168  0 annot[5] = new Annotation("", "", '\u0000', 0);
169  0 annot[6] = new Annotation("", "", '\u0000', 0);
170  0 annot[7] = new Annotation("", "", '\u0000', 0);
171  0 annot[8] = new Annotation("β", "", 'E', 0);
172  0 annot[9] = new Annotation("β", "", 'E', 0);
173  0 annot[10] = new Annotation("β", "", 'E', 0);
174  0 annot[11] = new Annotation("β", "", 'E', 0);
175  0 annot[12] = new Annotation("β", "", 'E', 0);
176  0 annot[13] = new Annotation("β", "", 'E', 0);
177  0 annot[14] = new Annotation("β", "", 'E', 0);
178  0 annot[15] = new Annotation("β", "", 'E', 0);
179  0 annot[16] = new Annotation("", "", '\u0000', 0);
180  0 annot[17] = new Annotation("", "", '\u0000', 0);
181  0 annot[18] = new Annotation("", "", '\u0000', 0);
182  0 annot[19] = new Annotation("", "", '\u0000', 0);
183  0 annot[20] = new Annotation("", "", '\u0000', 0);
184  0 annot[21] = new Annotation("", "", '\u0000', 0);
185  0 annot[22] = new Annotation("", "", '\u0000', 0);
186  0 annot[23] = new Annotation("", "", '\u0000', 0);
187  0 annot[24] = new Annotation("", "", '\u0000', 0);
188  0 annot[25] = new Annotation("", "", '\u0000', 0);
189  0 annot[26] = new Annotation("α", "", 'H', 0);
190  0 annot[27] = new Annotation("α", "", 'H', 0);
191  0 annot[28] = new Annotation("α", "", 'H', 0);
192  0 annot[29] = new Annotation("α", "", 'H', 0);
193  0 annot[30] = new Annotation("α", "", 'H', 0);
194  0 annot[31] = new Annotation("", "", '\u0000', 0);
195  0 annot[32] = new Annotation("", "", '\u0000', 0);
196  0 annot[33] = new Annotation("", "", '\u0000', 0);
197  0 annot[34] = new Annotation("", "", '\u0000', 0);
198   
199  0 AlignmentAnnotation alignAnnot = new AlignmentAnnotation(
200    "Secondary Structure", "New description", annot);
201  0 expectedAnnots.put(alignAnnot.label, alignAnnot);
202   
203  0 expectedColSel.hideColumns(32, 33);
204  0 expectedColSel.hideColumns(34, 34);
205   
206  0 TEST_SEQ_HEIGHT = expectedSeqs.size();
207  0 TEST_GRP_HEIGHT = expectedGrps.size();
208  0 TEST_ANOT_HEIGHT = expectedAnnots.size();
209  0 TEST_CS_HEIGHT = expectedColSel.getNumberOfRegions();
210   
211  0 exportSettings = new AlignExportSettingsAdapter(true);
212   
213  0 AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
214  0 try
215    {
216  0 alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE,
217    DataSourceType.FILE, FileFormat.Json);
218  0 jf = (JSONFile) formatAdapter.getAlignFile();
219   
220  0 AlignFrame af = new AlignFrame(alignment, jf.getHiddenSequences(),
221    jf.getHiddenColumns(), AlignFrame.DEFAULT_WIDTH,
222    AlignFrame.DEFAULT_HEIGHT);
223  0 af.getViewport().setShowSequenceFeatures(jf.isShowSeqFeatures());
224  0 String colourSchemeName = jf.getGlobalColourScheme();
225  0 ColourSchemeI cs = ColourSchemeMapper
226    .getJalviewColourScheme(colourSchemeName, alignment);
227  0 af.changeColour(cs);
228  0 af.getViewport().setFeaturesDisplayed(jf.getDisplayedFeatures());
229   
230  0 formatAdapter = new AppletFormatAdapter(af.alignPanel,
231    exportSettings);
232  0 String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
233    af.alignPanel.getAlignment(), false);
234   
235  0 formatAdapter = new AppletFormatAdapter();
236  0 testAlignment = formatAdapter.readFile(jsonOutput,
237    DataSourceType.PASTE, FileFormat.Json);
238  0 testJsonFile = (JSONFile) formatAdapter.getAlignFile();
239  0 System.out.println(jsonOutput);
240    } catch (IOException e)
241    {
242  0 e.printStackTrace();
243    }
244   
245    }
246   
 
247  0 toggle @BeforeMethod(alwaysRun = true)
248    public void methodSetup()
249    {
250  0 passedCount = 0;
251    }
252   
 
253  0 toggle @AfterTest(alwaysRun = true)
254    public void tearDown() throws Exception
255    {
256  0 testJsonFile = null;
257  0 alignment = null;
258  0 expectedSeqs = null;
259  0 expectedAnnots = null;
260  0 expectedGrps = null;
261  0 testAlignment = null;
262  0 jf = null;
263    }
264   
 
265  0 toggle @Test(groups = { "Functional" })
266    public void roundTripTest()
267    {
268  0 assertNotNull("JSON roundtrip test failed!", testJsonFile);
269    }
270   
 
271  0 toggle @Test(groups = { "Functional" })
272    public void testSeqParsed()
273    {
274  0 assertNotNull("Couldn't read supplied alignment data.", testAlignment);
275  0 Assert.assertNotNull(testAlignment.getSequences());
276  0 for (SequenceI seq : testAlignment.getSequences())
277    {
278  0 SequenceI expectedSeq = expectedSeqs.get(seq.getName());
279  0 AssertJUnit.assertTrue(
280    "Failed Sequence Test for >>> " + seq.getName(),
281    isSeqMatched(expectedSeq, seq));
282  0 passedCount++;
283    }
284  0 AssertJUnit.assertEquals("Some Sequences did not pass the test",
285    TEST_SEQ_HEIGHT, passedCount);
286    }
287   
 
288  0 toggle @Test(groups = { "Functional" })
289    public void hiddenColsTest()
290    {
291  0 HiddenColumns cs = testJsonFile.getHiddenColumns();
292  0 Assert.assertNotNull(cs);
293   
294  0 Iterator<int[]> it = cs.iterator();
295  0 Iterator<int[]> colselit = expectedColSel.iterator();
296  0 Assert.assertTrue(it.hasNext());
297  0 Assert.assertEquals(cs.getNumberOfRegions(), TEST_CS_HEIGHT);
298  0 Assert.assertEquals(it.next(), colselit.next(),
299    "Mismatched hidden columns!");
300    }
301   
 
302  0 toggle @Test(groups = { "Functional" })
303    public void hiddenSeqsTest()
304    {
305  0 Assert.assertNotNull(testJsonFile.getHiddenSequences(),
306    "Hidden sequence Expected but found Null");
307  0 Assert.assertEquals(jf.getHiddenSequences().length, 1,
308    "Hidden sequence");
309    }
310   
 
311  0 toggle @Test(groups = { "Functional" })
312    public void colorSchemeTest()
313    {
314  0 Assert.assertNotNull(testJsonFile.getGlobalColourScheme(),
315    "Colourscheme is null, parsing failed!");
316  0 Assert.assertEquals(testJsonFile.getGlobalColourScheme(), "Zappo",
317    "Zappo colour scheme expected!");
318    }
319   
320    /**
321    * Test for bug JAL-2489, NPE when exporting BioJSON with global colour
322    * scheme, and a group colour scheme, set as 'None'
323    */
 
324  0 toggle @Test(groups = { "Functional" })
325    public void testBioJSONRoundTripWithColourSchemeNone()
326    {
327  0 AppletFormatAdapter formatAdapter = new AppletFormatAdapter();
328   
329  0 Alignment _alignment;
330  0 try
331    {
332    // load example BioJSON file
333  0 _alignment = (Alignment) formatAdapter.readFile(TEST_JSON_FILE,
334    DataSourceType.FILE, FileFormat.Json);
335  0 JSONFile bioJsonFile = (JSONFile) formatAdapter.getAlignFile();
336  0 AlignFrame alignFrame = new AlignFrame(_alignment,
337    bioJsonFile.getHiddenSequences(),
338    bioJsonFile.getHiddenColumns(), AlignFrame.DEFAULT_WIDTH,
339    AlignFrame.DEFAULT_HEIGHT);
340   
341    /*
342    * Create a group on the alignment;
343    * Change global and group colour scheme to 'None' and perform round trip
344    */
345  0 SequenceGroup sg = new SequenceGroup();
346  0 sg.addSequence(_alignment.getSequenceAt(0), false);
347  0 sg.setColourScheme(null);
348  0 ColourSchemeI cs = ColourSchemeMapper
349    .getJalviewColourScheme(ResidueColourScheme.NONE, _alignment);
350  0 alignFrame.changeColour(cs);
351  0 alignFrame.getViewport()
352    .setFeaturesDisplayed(bioJsonFile.getDisplayedFeatures());
353  0 formatAdapter = new AppletFormatAdapter(alignFrame.alignPanel,
354    exportSettings);
355    // export BioJSON string
356  0 String jsonOutput = formatAdapter.formatSequences(FileFormat.Json,
357    alignFrame.alignPanel.getAlignment(), false);
358    // read back Alignment from BioJSON string
359  0 formatAdapter = new AppletFormatAdapter();
360  0 formatAdapter.readFile(jsonOutput, DataSourceType.PASTE,
361    FileFormat.Json);
362    // assert 'None' colour scheme is retained after round trip
363  0 JSONFile _bioJsonFile = (JSONFile) formatAdapter.getAlignFile();
364  0 Assert.assertEquals(_bioJsonFile.getGlobalColourScheme(),
365    ResidueColourScheme.NONE);
366    } catch (IOException e)
367    {
368  0 e.printStackTrace();
369    }
370    }
371   
 
372  0 toggle @Test(groups = { "Functional" })
373    public void isShowSeqFeaturesSet()
374    {
375  0 Assert.assertTrue(testJsonFile.isShowSeqFeatures(),
376    "Sequence feature isDisplayed setting expected to be true");
377    }
378   
 
379  0 toggle @Test(groups = { "Functional" })
380    public void testGrpParsed()
381    {
382  0 Assert.assertNotNull(testAlignment.getGroups());
383  0 for (SequenceGroup seqGrp : testAlignment.getGroups())
384    {
385  0 SequenceGroup expectedGrp = expectedGrps.get(seqGrp.getName());
386  0 AssertJUnit.assertTrue(
387    "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
388    isGroupMatched(expectedGrp, seqGrp));
389  0 passedCount++;
390    }
391  0 AssertJUnit.assertEquals("Some SequenceGroups did not pass the test",
392    TEST_GRP_HEIGHT, passedCount);
393    }
394   
 
395  0 toggle @Test(groups = { "Functional" })
396    public void testAnnotationParsed()
397    {
398  0 Assert.assertNotNull(testAlignment.getAlignmentAnnotation());
399  0 for (AlignmentAnnotation annot : testAlignment.getAlignmentAnnotation())
400    {
401  0 AlignmentAnnotation expectedAnnot = expectedAnnots.get(annot.label);
402  0 AssertJUnit.assertTrue(
403    "Failed AlignmentAnnotation Test for >>> " + annot.label,
404    isAnnotationMatched(expectedAnnot, annot));
405  0 passedCount++;
406    }
407  0 AssertJUnit.assertEquals("Some Sequences did not pass the test",
408    TEST_ANOT_HEIGHT, passedCount);
409    }
410   
 
411  0 toggle public boolean isAnnotationMatched(AlignmentAnnotation eAnnot,
412    AlignmentAnnotation annot)
413    {
414  0 if (!eAnnot.label.equals(annot.label)
415    || !eAnnot.description.equals(annot.description)
416    || eAnnot.annotations.length != annot.annotations.length)
417    {
418  0 return false;
419    }
420   
421  0 for (int x = 0; x < annot.annotations.length; x++)
422    {
423  0 Annotation y = annot.annotations[x];
424  0 Annotation z = annot.annotations[x];
425   
426  0 if (!y.displayCharacter.equals(z.displayCharacter)
427    || y.value != z.value
428    || y.secondaryStructure != z.secondaryStructure)
429    {
430  0 return false;
431    }
432    }
433  0 return true;
434    }
435   
 
436  0 toggle boolean isSeqMatched(SequenceI expectedSeq, SequenceI actualSeq)
437    {
438  0 System.out.println("Testing >>> " + actualSeq.getName());
439   
440  0 if (expectedSeq.getName().equals(actualSeq.getName())
441    && expectedSeq.getSequenceAsString()
442    .equals(actualSeq.getSequenceAsString())
443    && expectedSeq.getStart() == actualSeq.getStart()
444    && expectedSeq.getEnd() == actualSeq.getEnd()
445    && featuresMatched(expectedSeq, actualSeq))
446    {
447  0 return true;
448    }
449  0 return false;
450    }
451   
 
452  0 toggle public boolean isGroupMatched(SequenceGroup expectedGrp,
453    SequenceGroup actualGrp)
454    {
455   
456  0 System.out.println("Testing >>> " + actualGrp.getName());
457  0 System.out.println(expectedGrp.getName() + " | " + actualGrp.getName());
458  0 System.out.println(expectedGrp.getColourText() + " | "
459    + actualGrp.getColourText());
460  0 System.out.println(expectedGrp.getDisplayBoxes() + " | "
461    + actualGrp.getDisplayBoxes());
462  0 System.out.println(expectedGrp.getIgnoreGapsConsensus() + " | "
463    + actualGrp.getIgnoreGapsConsensus());
464  0 System.out.println(expectedGrp.getSequences().size() + " | "
465    + actualGrp.getSequences().size());
466  0 System.out.println(
467    expectedGrp.getStartRes() + " | " + actualGrp.getStartRes());
468  0 System.out.println(
469    expectedGrp.getEndRes() + " | " + actualGrp.getEndRes());
470  0 System.out.println(expectedGrp.cs.getColourScheme() + " | "
471    + actualGrp.cs.getColourScheme());
472   
473  0 boolean colourSchemeMatches = (expectedGrp.cs.getColourScheme() == null
474    && actualGrp.cs.getColourScheme() == null)
475    || expectedGrp.cs.getColourScheme().getClass()
476    .equals(actualGrp.cs.getColourScheme().getClass());
477  0 if (expectedGrp.getName().equals(actualGrp.getName())
478    && expectedGrp.getColourText() == actualGrp.getColourText()
479    && expectedGrp.getDisplayBoxes() == actualGrp.getDisplayBoxes()
480    && expectedGrp.getIgnoreGapsConsensus() == actualGrp
481    .getIgnoreGapsConsensus()
482    && colourSchemeMatches
483    && expectedGrp.getSequences().size() == actualGrp.getSequences()
484    .size()
485    && expectedGrp.getStartRes() == actualGrp.getStartRes()
486    && expectedGrp.getEndRes() == actualGrp.getEndRes())
487    {
488  0 return true;
489    }
490  0 return false;
491    }
492   
 
493  0 toggle private boolean featuresMatched(SequenceI seq1, SequenceI seq2)
494    {
495  0 try
496    {
497  0 if (seq1 == null && seq2 == null)
498    {
499  0 return true;
500    }
501   
502  0 List<SequenceFeature> inFeature = seq1.getFeatures().getAllFeatures();
503  0 List<SequenceFeature> outFeature = seq2.getFeatures()
504    .getAllFeatures();
505   
506  0 if (inFeature.size() != outFeature.size())
507    {
508  0 System.err.println("Feature count in: " + inFeature.size()
509    + ", out: " + outFeature.size());
510  0 return false;
511    }
512   
513  0 SequenceFeatures.sortFeatures(inFeature, true);
514  0 SequenceFeatures.sortFeatures(outFeature, true);
515  0 int i = 0;
516  0 for (SequenceFeature in : inFeature)
517    {
518  0 SequenceFeature out = outFeature.get(i);
519    /*
520    System.out.println(out.getType() + " | " + in.getType());
521    System.out.println(out.getBegin() + " | " + in.getBegin());
522    System.out.println(out.getEnd() + " | " + in.getEnd());
523    */
524  0 if (!in.equals(out))
525    {
526  0 System.err.println(
527    "Mismatch of " + in.toString() + " " + out.toString());
528  0 return false;
529    }
530    /*
531    if (in.getBegin() == out.getBegin() && in.getEnd() == out.getEnd()
532    && in.getScore() == out.getScore()
533    && in.getFeatureGroup().equals(out.getFeatureGroup())
534    && in.getType().equals(out.getType())
535    && mapsMatch(in.otherDetails, out.otherDetails))
536    {
537    }
538    else
539    {
540    System.err.println("Feature[" + i + "] mismatch, in: "
541    + in.toString() + ", out: "
542    + outFeature.get(i).toString());
543    return false;
544    }
545    */
546  0 i++;
547    }
548    } catch (Exception e)
549    {
550  0 e.printStackTrace();
551    }
552    // System.out.println(">>>>>>>>>>>>>> features matched : " + matched);
553  0 return true;
554    }
555   
 
556  0 toggle boolean mapsMatch(Map<String, Object> m1, Map<String, Object> m2)
557    {
558  0 if (m1 == null || m2 == null)
559    {
560  0 if (m1 != null || m2 != null)
561    {
562  0 System.err.println(
563    "only one SequenceFeature.otherDetails is not null");
564  0 return false;
565    }
566    else
567    {
568  0 return true;
569    }
570    }
571  0 if (m1.size() != m2.size())
572    {
573  0 System.err.println("otherDetails map different sizes");
574  0 return false;
575    }
576  0 for (String key : m1.keySet())
577    {
578  0 if (!m2.containsKey(key))
579    {
580  0 System.err.println(key + " in only one otherDetails");
581  0 return false;
582    }
583  0 if (m1.get(key) == null && m2.get(key) != null
584    || m1.get(key) != null && m2.get(key) == null
585    || !m1.get(key).equals(m2.get(key)))
586    {
587  0 System.err.println(key + " values in otherDetails don't match");
588  0 return false;
589    }
590    }
591  0 return true;
592    }
593   
594    /**
595    * Test group roundtrip with null (None) group colour scheme
596    *
597    * @throws IOException
598    */
 
599  0 toggle @Test(groups = { "Functional" })
600    public void testGrpParsed_colourNone() throws IOException
601    {
602  0 AlignmentI copy = new Alignment(testAlignment);
603  0 SequenceGroup sg = testAlignment.getGroups().get(0);
604  0 SequenceGroup copySg = new SequenceGroup(new ArrayList<SequenceI>(),
605    sg.getName(), null, sg.getDisplayBoxes(), sg.getDisplayText(),
606    sg.getColourText(), sg.getStartRes(), sg.getEndRes());
607  0 for (SequenceI seq : sg.getSequences())
608    {
609  0 int seqIndex = testAlignment.findIndex(seq);
610  0 copySg.addSequence(copy.getSequenceAt(seqIndex), false);
611    }
612  0 copy.addGroup(copySg);
613   
614  0 AlignFrame af = new AlignFrame(copy, copy.getWidth(), copy.getHeight());
615  0 AppletFormatAdapter formatAdapter = new AppletFormatAdapter(
616    af.alignPanel);
617  0 String jsonOutput = formatAdapter.formatSequences(FileFormat.Json, copy,
618    false);
619  0 formatAdapter = new AppletFormatAdapter();
620  0 AlignmentI newAlignment = formatAdapter.readFile(jsonOutput,
621    DataSourceType.PASTE, FileFormat.Json);
622   
623  0 Assert.assertNotNull(newAlignment.getGroups());
624  0 for (SequenceGroup seqGrp : newAlignment.getGroups())
625    {
626  0 SequenceGroup expectedGrp = copySg;
627  0 AssertJUnit.assertTrue(
628    "Failed SequenceGroup Test for >>> " + seqGrp.getName(),
629    isGroupMatched(expectedGrp, seqGrp));
630  0 passedCount++;
631    }
632  0 AssertJUnit.assertEquals("Some SequenceGroups did not pass the test",
633    TEST_GRP_HEIGHT, passedCount);
634    }
635    }