JAL-4281 store/restore ID width and manual adjustment flag in Jalview projects
[jalview.git] / test / jalview / gui / DesktopTests.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.gui;
22
23 import static org.junit.Assert.assertNotEquals;
24 import static org.testng.Assert.assertEquals;
25 import static org.testng.Assert.assertFalse;
26 import static org.testng.Assert.assertNotSame;
27 import static org.testng.Assert.assertSame;
28 import static org.testng.Assert.assertTrue;
29
30 import java.awt.Color;
31 import java.util.Iterator;
32
33 import javax.swing.SwingUtilities;
34
35 import org.junit.Assert;
36 import org.testng.annotations.AfterMethod;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.BeforeMethod;
39 import org.testng.annotations.Test;
40
41 import jalview.api.FeatureColourI;
42 import jalview.bin.Cache;
43 import jalview.bin.Jalview;
44 import jalview.datamodel.Alignment;
45 import jalview.datamodel.AlignmentI;
46 import jalview.datamodel.HiddenColumns;
47 import jalview.datamodel.Sequence;
48 import jalview.datamodel.SequenceFeature;
49 import jalview.datamodel.SequenceGroup;
50 import jalview.datamodel.SequenceI;
51 import jalview.io.DataSourceType;
52 import jalview.io.FileLoader;
53 import jalview.project.Jalview2xmlTests;
54 import jalview.renderer.ResidueShaderI;
55 import jalview.schemes.BuriedColourScheme;
56 import jalview.schemes.FeatureColour;
57 import jalview.schemes.HelixColourScheme;
58 import jalview.schemes.JalviewColourScheme;
59 import jalview.schemes.StrandColourScheme;
60 import jalview.schemes.TurnColourScheme;
61 import jalview.util.MessageManager;
62
63 public class DesktopTests
64 {
65
66   @BeforeClass(alwaysRun = true)
67   public static void setUpBeforeClass() throws Exception
68   {
69     setUpJvOptionPane();
70     /*
71      * use read-only test properties file
72      */
73     Cache.loadProperties("test/jalview/io/testProps.jvprops");
74     Jalview.main(new String[] { "-nonews" });
75   }
76
77   @AfterMethod(alwaysRun = true)
78   public void tearDown()
79   {
80     Desktop.instance.closeAll_actionPerformed(null);
81   }
82
83   /**
84    * 
85    * configure (read-only) properties for test to ensure Consensus is computed
86    * for colour Above PID testing
87    */
88   public AlignFrame loadTestFile()
89   {
90     Cache.loadProperties("test/jalview/io/testProps.jvprops");
91     Cache.applicationProperties.setProperty("SHOW_IDENTITY",
92             Boolean.TRUE.toString());
93     AlignFrame af = new FileLoader().LoadFileWaitTillLoaded(
94             "examples/uniref50.fa", DataSourceType.FILE);
95
96     /*
97      * wait for Consensus thread to complete
98      */
99     do
100     {
101       try
102       {
103         Thread.sleep(50);
104       } catch (InterruptedException x)
105       {
106       }
107     } while (af.getViewport().getCalcManager().isWorking());
108     return af;
109   }
110
111   public static void setUpJvOptionPane()
112   {
113     JvOptionPane.setInteractiveMode(false);
114     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
115   }
116
117   @Test(groups = { "Functional" })
118   public void testInternalCopyPaste()
119   {
120     AlignFrame internalSource = loadTestFile();
121
122     try
123     {
124       SwingUtilities.invokeAndWait(new Runnable()
125       {
126         @Override
127         public void run()
128         {
129           internalSource.selectAllSequenceMenuItem_actionPerformed(null);
130           internalSource.copy_actionPerformed();
131           Desktop.instance.paste();
132         }
133       });
134     } catch (Exception x)
135     {
136       Assert.fail("Unexpected exception " + x);
137     }
138     AlignFrame[] alfs = Desktop.getAlignFrames();
139     Assert.assertEquals("Expect just 2 alignment frames", 2, alfs.length);
140     // internal paste should yield a new alignment window with shared dataset
141     AlignmentI dataset = internalSource.getViewport().getAlignment()
142             .getDataset();
143     Assert.assertNotNull(dataset);
144
145     for (AlignFrame alf : alfs)
146     {
147       Assert.assertTrue(
148               "Internal paste should yield alignment with same dataset.",
149               dataset == alf.getViewport().getAlignment().getDataset());
150     }
151
152   }
153 }