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