Merge branch 'develop' of https://source.jalview.org/git/jalview.git into develop
[jalview.git] / test / jalview / ext / jmol / JmolViewerTest.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.ext.jmol;
22
23 import static org.testng.AssertJUnit.assertTrue;
24
25 import jalview.api.structures.JalviewStructureDisplayI;
26 import jalview.bin.Cache;
27 import jalview.datamodel.SequenceI;
28 import jalview.gui.AlignFrame;
29 import jalview.gui.JvOptionPane;
30 import jalview.gui.Preferences;
31 import jalview.gui.StructureViewer;
32 import jalview.gui.StructureViewer.ViewerType;
33 import jalview.io.DataSourceType;
34
35 import org.testng.annotations.AfterClass;
36 import org.testng.annotations.BeforeClass;
37 import org.testng.annotations.Test;
38
39 @Test(singleThreaded = true)
40 public class JmolViewerTest
41 {
42
43   @BeforeClass(alwaysRun = true)
44   public void setUpJvOptionPane()
45   {
46     JvOptionPane.setInteractiveMode(false);
47     JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
48   }
49
50   /**
51    * @throws java.lang.Exception
52    */
53   @BeforeClass(alwaysRun = true)
54   public static void setUpBeforeClass() throws Exception
55   {
56     jalview.bin.Jalview.main(new String[] {
57         "-noquestionnaire -nonews -props",
58         "test/jalview/ext/rbvi/chimera/testProps.jvprops" });
59   }
60
61   /**
62    * @throws java.lang.Exception
63    */
64   @AfterClass(alwaysRun = true)
65   public static void tearDownAfterClass() throws Exception
66   {
67     jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
68   }
69
70   @Test(groups = { "Functional" })
71   public void testSingleSeqViewJMol()
72   {
73     Cache.setProperty(Preferences.STRUCTURE_DISPLAY, ViewerType.JMOL.name());
74     String inFile = "examples/1gaq.txt";
75     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(
76             inFile, DataSourceType.FILE);
77     assertTrue("Didn't read input file " + inFile, af != null);
78     for (SequenceI sq : af.getViewport().getAlignment().getSequences())
79     {
80       SequenceI dsq = sq.getDatasetSequence();
81       while (dsq.getDatasetSequence() != null)
82       {
83         dsq = dsq.getDatasetSequence();
84       }
85       if (dsq.getAllPDBEntries() != null
86               && dsq.getAllPDBEntries().size() > 0)
87       {
88         for (int q = 0; q < dsq.getAllPDBEntries().size(); q++)
89         {
90           final StructureViewer structureViewer = new StructureViewer(af
91                   .getViewport().getStructureSelectionManager());
92           structureViewer.setViewerType(ViewerType.JMOL);
93           JalviewStructureDisplayI jmolViewer = structureViewer
94                   .viewStructures(dsq.getAllPDBEntries().elementAt(q),
95                           new SequenceI[] { sq }, af.getCurrentView()
96                                   .getAlignPanel());
97           /*
98            * Wait for viewer load thread to complete
99            */
100           try
101           {
102             while (!jmolViewer.getBinding().isFinishedInit())
103             {
104               Thread.sleep(500);
105             }
106           } catch (InterruptedException e)
107           {
108           }
109
110           jmolViewer.closeViewer(true);
111           // todo: break here means only once through this loop?
112           break;
113         }
114         break;
115       }
116     }
117   }
118 }