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