X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fgui%2FFeatureSettingsTest.java;h=12c4c6cc9fa287c7cf3f46ca754d366254d714b0;hb=eb3e681d6e82ccdd5d312d1981dfb306e7f479f0;hp=195ca87ad9e2264b3ed01ec8159b7cc9efce4fc6;hpb=3740241b6d0dfa109dc81847afe58f17497c39e8;p=jalview.git diff --git a/test/jalview/gui/FeatureSettingsTest.java b/test/jalview/gui/FeatureSettingsTest.java index 195ca87..12c4c6c 100644 --- a/test/jalview/gui/FeatureSettingsTest.java +++ b/test/jalview/gui/FeatureSettingsTest.java @@ -1,30 +1,75 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.gui; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; import static org.testng.Assert.assertTrue; +import java.awt.Color; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; + +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + import jalview.api.FeatureColourI; +import jalview.bin.Cache; +import jalview.bin.Jalview; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.datamodel.features.FeatureMatcher; import jalview.datamodel.features.FeatureMatcherSet; import jalview.datamodel.features.FeatureMatcherSetI; import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FileFormatI; import jalview.io.FileLoader; +import jalview.io.IdentifyFile; import jalview.schemes.FeatureColour; +import jalview.schemes.FeatureColourTest; import jalview.util.matcher.Condition; import jalview.viewmodel.seqfeatures.FeatureRendererModel; -import java.awt.Color; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; - -import org.testng.annotations.Test; - public class FeatureSettingsTest { + @BeforeClass(alwaysRun = true) + public static void setUpBeforeClass() throws Exception + { + /* + * use read-only test properties file + */ + Cache.loadProperties("test/jalview/io/testProps.jvprops"); + Jalview.main(new String[] { "--nonews" }); + } + + @AfterMethod(alwaysRun = true) + public void tearDown() + { + if (Desktop.instance != null) + Desktop.instance.closeAll_actionPerformed(null); + } + /** * Test a roundtrip of save and reload of feature colours and filters as XML * @@ -61,8 +106,8 @@ public class FeatureSettingsTest fr.setColour("type2", byLabel); // type3: by score above threshold - FeatureColourI byScore = new FeatureColour(Color.BLACK, Color.BLUE, 1, - 10); + FeatureColourI byScore = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byScore.setAboveThreshold(true); byScore.setThreshold(2f); fr.setColour("type3", byScore); @@ -74,8 +119,8 @@ public class FeatureSettingsTest fr.setColour("type4", byAF); // type5: by attribute CSQ:PolyPhen below threshold - FeatureColourI byPolyPhen = new FeatureColour(Color.BLACK, Color.BLUE, - 1, 10); + FeatureColourI byPolyPhen = new FeatureColour(null, Color.BLACK, + Color.BLUE, null, 1, 10); byPolyPhen.setBelowThreshold(true); byPolyPhen.setThreshold(3f); byPolyPhen.setAttributeName("CSQ", "PolyPhen"); @@ -155,11 +200,12 @@ public class FeatureSettingsTest assertTrue(fc.isBelowThreshold()); assertEquals(fc.getThreshold(), 3f); - assertEquals(fr.getFeatureFilter("type1").toStableString(), "Label Contains x"); + assertEquals(fr.getFeatureFilter("type1").toStableString(), + "Label Contains x"); assertEquals(fr.getFeatureFilter("type2").toStableString(), "(Score LE 2.4) AND (Score GT 1.1)"); assertEquals(fr.getFeatureFilter("type3").toStableString(), - "(AF Contains X) OR (CSQ:PolyPhen NE 0.0)"); + "(AF Contains X) OR (CSQ:PolyPhen NE 0)"); } /** @@ -189,4 +235,65 @@ public class FeatureSettingsTest }); seq.addSequenceFeature(sf); } + + /** + * @see FeatureColourTest#testGetDescription() + * @throws IOException + */ + @Test(groups = "Functional") + public void testGetColorTooltip() throws IOException + { + assertNull(FeatureSettings.getColorTooltip(null, false)); + + /* + * simple colour + */ + FeatureColourI fc = new FeatureColour(Color.black); + String simpleTooltip = "Click to edit, right-click for menu"; + assertEquals(FeatureSettings.getColorTooltip(fc, true), simpleTooltip); + assertNull(FeatureSettings.getColorTooltip(fc, false)); + + /* + * graduated colour tooltip includes description of colour + */ + fc.setColourByLabel(true); + assertEquals(FeatureSettings.getColorTooltip(fc, false), + "By Label"); + assertEquals(FeatureSettings.getColorTooltip(fc, true), + "By Label
" + simpleTooltip + "
"); + + /* + * graduated colour with threshold is html-encoded + */ + fc = new FeatureColour(null, Color.red, Color.blue, null, 2f, 10f); + fc.setBelowThreshold(true); + fc.setThreshold(4f); + assertEquals(FeatureSettings.getColorTooltip(fc, false), + "By Score (< 4.0)"); + assertEquals(FeatureSettings.getColorTooltip(fc, true), + "By Score (< 4.0)
" + simpleTooltip + + "
"); + + fc.setAboveThreshold(true); + assertEquals(FeatureSettings.getColorTooltip(fc, false), + "By Score (> 4.0)"); + assertEquals(FeatureSettings.getColorTooltip(fc, true), + "By Score (> 4.0)
" + simpleTooltip + + "
"); + } + + String fsfile = "", + fsfile2 = "\n"; + + @Test(groups = "Functional") + public void testIdentifyFeatureSettingsFile() throws Exception + { + FileFormatI type = new IdentifyFile().identify(fsfile, + DataSourceType.PASTE); + assertTrue(FileFormat.FeatureSettings == type, + "Feature settings file was identified as " + type); + type = new IdentifyFile().identify(fsfile2, DataSourceType.PASTE); + assertTrue(FileFormat.FeatureSettings == type, + "Feature settings file with newline was identified as " + type); + } }