JAL-3253 jalview.bin.Instance handles all singleton instances -
[jalview.git] / test / jalview / io / Jalview2xmlBase.java
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 jalview.bin.Cache;
24 import jalview.bin.Instance;
25 import jalview.bin.Jalview;
26 import jalview.datamodel.AlignmentAnnotation;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.Desktop;
29 import jalview.gui.JvOptionPane;
30
31 import java.util.Date;
32
33 import org.testng.annotations.AfterClass;
34 import org.testng.annotations.BeforeClass;
35 import org.testng.annotations.BeforeTest;
36
37 public class Jalview2xmlBase
38 {
39
40   @BeforeClass(alwaysRun = true)
41   public void setUpJvOptionPane()
42   {
43     JvOptionPane.setInteractiveMode(false);
44     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
45   }
46
47   /**
48    * @throws java.lang.Exception
49    */
50   @BeforeClass(alwaysRun = true)
51   public static void setUpBeforeClass() throws Exception
52   {
53     /*
54      * use read-only test properties file
55      */
56     Cache.loadProperties("test/jalview/io/testProps.jvprops");
57
58     /*
59      * set news feed last read to a future time to ensure no
60      * 'unread' news item is displayed
61      */
62     Date oneHourFromNow = new Date(System.currentTimeMillis() + 3600 * 1000);
63     Cache.setDateProperty("JALVIEW_NEWS_RSS_LASTMODIFIED", oneHourFromNow);
64
65     Jalview.main(new String[] {});
66   }
67
68   /**
69    * @throws java.lang.Exception
70    */
71   @AfterClass(alwaysRun = true)
72   public static void tearDownAfterClass() throws Exception
73   {
74     jalview.bin.Instance.getDesktop().closeAll_actionPerformed(null);
75   }
76
77   @BeforeTest(alwaysRun = true)
78   public static void clearDesktop()
79   {
80     if (Instance.getDesktop() != null && Desktop.getFrames() != null
81             && Desktop.getFrames().length > 0)
82     {
83       Instance.getDesktop().closeAll_actionPerformed(null);
84     }
85   }
86
87   public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
88   {
89     int numdsann = 0;
90     for (SequenceI sq : avp.getAlignment().getDataset().getSequences())
91     {
92       if (sq.getAnnotation() != null)
93       {
94         for (AlignmentAnnotation dssa : sq.getAnnotation())
95         {
96           if (dssa.isValidStruc())
97           {
98             numdsann++;
99           }
100         }
101       }
102     }
103     return numdsann;
104   }
105
106 }