properly quit so JUnit marks tests as successful
[jalview.git] / test / jalview / io / Jalview2xmlTests.java
1 package jalview.io;
2
3 import static org.junit.Assert.*;
4 import jalview.datamodel.AlignmentAnnotation;
5 import jalview.datamodel.SequenceI;
6 import jalview.gui.AlignFrame;
7
8 import java.io.File;
9
10 import org.junit.AfterClass;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13
14 public class Jalview2xmlTests
15 {
16
17   /**
18    * @throws java.lang.Exception
19    */
20   @BeforeClass
21   public static void setUpBeforeClass() throws Exception
22   {
23     jalview.bin.Jalview.main(new String[] {"-props","test/src/jalview/io/testProps.jvprops"});
24   }
25
26   /**
27    * @throws java.lang.Exception
28    */
29   @AfterClass
30   public static void tearDownAfterClass() throws Exception
31   {
32     jalview.gui.Desktop.instance.closeAll_actionPerformed(null);
33     
34   }
35   public int countDsAnn(jalview.viewmodel.AlignmentViewport avp)
36   {
37     int numdsann=0;
38     for (SequenceI sq: avp.getAlignment().getDataset().getSequences()) {
39       if (sq.getAnnotation() != null)
40       {
41         for (AlignmentAnnotation dssa : sq.getAnnotation())
42         {
43           if (dssa.isValidStruc())
44           {
45             numdsann++;
46           }
47         }
48       }
49     }
50     return numdsann;
51   }
52   @Test
53   public void testRNAStructureRecovery() throws Exception
54   {
55     String inFile = "examples/RF00031_folded.stk";
56     String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
57     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
58     assertTrue("Didn't read input file "+inFile, af!=null);
59     int olddsann=countDsAnn(af.getViewport());
60     assertTrue("Didn't find any dataset annotations",olddsann>0);
61     af.rnahelicesColour_actionPerformed(null);
62     assertTrue("Couldn't apply RNA helices colourscheme",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
63     assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
64     af.closeMenuItem_actionPerformed(true);
65     af=null;
66     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
67     assertTrue("Failed to import new project", af!=null);
68     int newdsann=countDsAnn(af.getViewport());
69     assertTrue("Differing numbers of dataset sequence annotation\nOriginally "+olddsann+" and now "+newdsann,olddsann==newdsann);
70     System.out.println("Read in same number of annotations as originally present ("+olddsann+")");
71     assertTrue("RNA helices colourscheme was not applied on import.",af.getViewport().getGlobalColourScheme() instanceof jalview.schemes.RNAHelicesColour);
72   }
73   @Test
74   public void testTCoffeeScores() throws Exception
75   {
76     String inFile = "examples/uniref50.fa",inAnnot="examples/uniref50.score_ascii";
77     String tfile = File.createTempFile("JalviewTest", ".jvp").getAbsolutePath();
78     AlignFrame af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(inFile, FormatAdapter.FILE);
79     assertTrue("Didn't read input file "+inFile, af!=null);
80     af.loadJalviewDataFile(inAnnot, FormatAdapter.FILE, null,null);
81     assertTrue(
82             "Didn't set T-coffee colourscheme",
83             af.getViewport().getGlobalColourScheme().getClass()
84                     .equals(jalview.schemes.TCoffeeColourScheme.class));
85     assertTrue(
86             "Recognise T-Coffee score from string",
87             jalview.schemes.ColourSchemeProperty.getColour(af.getViewport()
88                     .getAlignment(),
89                     jalview.schemes.ColourSchemeProperty.getColourName(af
90                             .getViewport().getGlobalColourScheme())) != null);
91
92     assertTrue("Failed to store as a project.",af.saveAlignment(tfile, "Jalview"));
93     af.closeMenuItem_actionPerformed(true);
94     af=null;
95     af = new jalview.io.FileLoader().LoadFileWaitTillLoaded(tfile, FormatAdapter.FILE);
96     assertTrue("Failed to import new project", af!=null);
97     assertTrue("Didn't set T-coffee colourscheme for imported project.",af.getViewport().getGlobalColourScheme().getClass().equals(jalview.schemes.TCoffeeColourScheme.class));
98     System.out.println("T-Coffee score shading successfully recovered from project.");
99   }
100 }