From: Ben Soares Date: Thu, 9 Mar 2023 23:56:15 +0000 (+0000) Subject: JAL-629 start of tests X-Git-Tag: Release_2_11_3_0~14^2~174 X-Git-Url: http://source.jalview.org/gitweb/?p=jalview.git;a=commitdiff_plain;h=5afaa80bd2cddc6651867f86a04affffa0896f89 JAL-629 start of tests --- diff --git a/src/jalview/bin/Cache.java b/src/jalview/bin/Cache.java index 698cbb8..da6b1ea 100755 --- a/src/jalview/bin/Cache.java +++ b/src/jalview/bin/Cache.java @@ -244,6 +244,9 @@ public class Cache */ public static final String JALVIEWLOGLEVEL = "logs.Jalview.level"; + // for tests + public static final String BOOTSTRAP_TEST = "BOOTSTRAP_TEST"; + /** * Sifts settings */ @@ -1622,7 +1625,7 @@ public class Cache } private static final Collection bootstrapProperties = new ArrayList<>( - Arrays.asList(JALVIEWLOGLEVEL)); + Arrays.asList(JALVIEWLOGLEVEL, BOOTSTRAP_TEST)); public static Properties bootstrapProperties(String filename) { diff --git a/test/jalview/bin/ArgParserTest.java b/test/jalview/bin/ArgParserTest.java new file mode 100644 index 0000000..7b70a4b --- /dev/null +++ b/test/jalview/bin/ArgParserTest.java @@ -0,0 +1,97 @@ +package jalview.bin; + +import java.io.File; +import java.io.IOException; +import java.util.List; +import java.util.Properties; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import jalview.bin.ArgParser.Arg; +import jalview.bin.ArgParser.BootstrapArgs; +import jalview.util.FileUtils; + +public class ArgParserTest +{ + + @Test(groups = "Functional", dataProvider = "argLines") + public void parseArgsAndSubValsTest(String commandLineArgs) + { + String[] args = commandLineArgs.split("\\s*"); + ArgParser argparser = new ArgParser(args); + } + + @Test(groups = "Functional", dataProvider = "argLines") + public void bootstrapArgsTest(String commandLineArgs, Arg a, String other) + { + String[] args = commandLineArgs.split("\\s+"); + BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); + + Assert.assertTrue(b.contains(a)); + if (a == Arg.PROPS) + { + Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + Assert.assertTrue(other.equals(bP.get(Cache.BOOTSTRAP_TEST))); + } + else if (a == Arg.ARGFILE) + { + List files = FileUtils.getFilesFromGlob(b.get(a)); + boolean found = false; + for (File f : files) + { + File fo = new File(other); + try + { + if (fo.getCanonicalPath().equals(f.getCanonicalPath())) + { + found = true; + break; + } + } catch (IOException e) + { + } + } + Assert.assertTrue(found); + } + + } + + @Test(groups = "Functional", dataProvider = "argFiles") + public void argFilesTest(String commandLineArgs, Arg a) + { + String[] args = commandLineArgs.split("\\s+"); + BootstrapArgs b = BootstrapArgs.getBootstrapArgs(args); + + Assert.assertTrue(b.contains(a)); + if (a == Arg.PROPS) + { + Properties bP = Cache.bootstrapProperties(b.get(Arg.PROPS)); + Assert.assertTrue("true".equals(bP.get(Cache.BOOTSTRAP_TEST))); + } + + } + + @DataProvider(name = "argLines") + public Object[][] argLines() + { + return new Object[][] { + { "--debug --open=test/jalview/bin/argparser/test1.fa", Arg.DEBUG, + null }, + { "--open=test/jalview/bin/argparser/test1.fa --headless", + Arg.HEADLESS, null }, + { "--open=test/jalview/bin/argparser/test1.fa --props=test/jalview/bin/argparser/testProps.jvprops", + Arg.PROPS, "true" }, + { "--argfile=test/jalview/bin/argparser/argfile*.txt", Arg.ARGFILE, + "test/jalview/bin/argparser/argfile1.txt" } }; + } + + @DataProvider(name = "argFiles") + public Object[][] argFiles() + { + return new Object[][] { + { "--argfile=test/jalview/bin/argparser/argfile0.txt", Arg.OPEN, + "test/jalview/bin/argfiles/test1.fa" } }; + } +} diff --git a/test/jalview/bin/CommandsTest.java b/test/jalview/bin/CommandsTest.java new file mode 100644 index 0000000..e4fea7b --- /dev/null +++ b/test/jalview/bin/CommandsTest.java @@ -0,0 +1,103 @@ +package jalview.bin; + +import java.io.File; +import java.io.IOException; +import java.lang.management.ManagementFactory; + +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import io.github.classgraph.ClassGraph; + +public class CommandsTest +{ + + private static final int SETUP_TIMEOUT = 30000; + + private static class Worker extends Thread + { + private final Process process; + + private Integer exit; + + private Worker(Process process) + { + this.process = process; + } + + @Override + public void run() + { + try + { + exit = process.waitFor(); + } catch (InterruptedException ignore) + { + return; + } + } + } + + private static ClassGraph scanner = null; + + private static String classpath = null; + + private static String modules = null; + + private static String java_exe = null; + + public synchronized static String getClassPath() + { + java_exe = System.getProperty("java.home") + File.separator + "bin" + + File.separator + "java"; + classpath = ManagementFactory.getRuntimeMXBean().getClassPath(); + return classpath; + } + + private Worker getJalviewDesktopRunner(boolean withAwt, String cmd, + int timeout) + { + // Note: JAL-3065 - don't include quotes for lib/* because the arguments are + // not expanded by the shell + String classpath = getClassPath(); + String _cmd = java_exe + " " + + (withAwt ? "-Djava.awt.headless=true" : "") + " -classpath " + + classpath + " jalview.bin.Jalview "; + Process ls2_proc = null; + Worker worker = null; + try + { + ls2_proc = Runtime.getRuntime().exec(_cmd + cmd); + } catch (Throwable e1) + { + e1.printStackTrace(); + } + if (ls2_proc != null) + { + worker = new Worker(ls2_proc); + worker.start(); + try + { + worker.join(timeout); + } catch (InterruptedException e) + { + System.err.println("Thread interrupted"); + } + } + return worker; + } + + @BeforeTest(alwaysRun = true) + public void initialize() + { + new CommandsTest(); + } + + @Test(groups = "Functional") + public void setUpForHeadlessCommandsTest() throws IOException + { + String cmds = "--open=./examples/uniref50.fa"; + Worker worker = getJalviewDesktopRunner(true, cmds, SETUP_TIMEOUT); + } + +} diff --git a/test/jalview/bin/argparser/argfile0.txt b/test/jalview/bin/argparser/argfile0.txt new file mode 100644 index 0000000..8ef7264 --- /dev/null +++ b/test/jalview/bin/argparser/argfile0.txt @@ -0,0 +1,2 @@ +--open=test/jalview/bin/argparser/test1.fa +--open=test/jalview/bin/argparser/test2.fa diff --git a/test/jalview/bin/argparser/argfile1.txt b/test/jalview/bin/argparser/argfile1.txt new file mode 100644 index 0000000..f1b406f --- /dev/null +++ b/test/jalview/bin/argparser/argfile1.txt @@ -0,0 +1,4 @@ +--open[all]=test/jalview/bin/argparser/test1.fa +--open[all]=test/jalview/bin/argparser/test2.fa +--open[1]=test/jalview/bin/argparser/test1.fa +--open[2]=test/jalview/bin/argparser/test1.fa diff --git a/test/jalview/bin/argparser/argfile2.txt b/test/jalview/bin/argparser/argfile2.txt new file mode 100644 index 0000000..63e8433 --- /dev/null +++ b/test/jalview/bin/argparser/argfile2.txt @@ -0,0 +1 @@ +--open=test/jalview/bin/argparser/test1.fa diff --git a/test/jalview/bin/argparser/test1.fa b/test/jalview/bin/argparser/test1.fa new file mode 100644 index 0000000..5174ae1 --- /dev/null +++ b/test/jalview/bin/argparser/test1.fa @@ -0,0 +1,6 @@ +>TEST1A +AAAARG +>TEST1B +HELLO +>TEST1C +OUTTHERE diff --git a/test/jalview/bin/argparser/test2.fa b/test/jalview/bin/argparser/test2.fa new file mode 100644 index 0000000..90d48e1 --- /dev/null +++ b/test/jalview/bin/argparser/test2.fa @@ -0,0 +1,6 @@ +>TEST2A +AAAARG +>TEST2B +HELLO +>TEST2C +OUTTHERE diff --git a/test/jalview/bin/argparser/testProps.jvprops b/test/jalview/bin/argparser/testProps.jvprops new file mode 100644 index 0000000..7e142b2 --- /dev/null +++ b/test/jalview/bin/argparser/testProps.jvprops @@ -0,0 +1,86 @@ +#---JalviewX Properties File--- +#Fri Apr 25 09:54:25 BST 2014 +SCREEN_Y=768 +SCREEN_X=936 +SHOW_WSDISCOVERY_ERRORS=true +LATEST_VERSION=2.8.0b1 +SHOW_CONSERVATION=true +JALVIEW_RSS_WINDOW_SCREEN_WIDTH=550 +JAVA_CONSOLE_SCREEN_WIDTH=450 +LAST_DIRECTORY=/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples +ID_ITALICS=true +SORT_ALIGNMENT=No sort +SHOW_IDENTITY=true +WSMENU_BYHOST=false +SEQUENCE_LINKS=EMBL-EBI Search|http\://www.ebi.ac.uk/ebisearch/search.ebi?db\=allebi&query\=$SEQUENCE_ID$ +SHOW_FULLSCREEN=false +RECENT_URL=http\://www.jalview.org/examples/exampleFile_2_7.jar +FONT_NAME=SansSerif +BLC_JVSUFFIX=true +VERSION_CHECK=false +YEAR=2011 +SHOW_DBREFS_TOOLTIP=true +MSF_JVSUFFIX=true +SCREENGEOMETRY_HEIGHT=1600 +JAVA_CONSOLE_SCREEN_Y=475 +JAVA_CONSOLE_SCREEN_X=830 +PFAM_JVSUFFIX=true +PIR_JVSUFFIX=true +STARTUP_FILE=http\://www.jalview.org/examples/exampleFile_2_3.jar +JAVA_CONSOLE_SCREEN_HEIGHT=162 +PIR_MODELLER=false +GAP_SYMBOL=- +SHOW_QUALITY=true +SHOW_GROUP_CONSERVATION=false +SHOW_JWS2_SERVICES=true +SHOW_NPFEATS_TOOLTIP=true +FONT_STYLE=plain +ANTI_ALIAS=false +SORT_BY_TREE=false +RSBS_SERVICES=|Multi-Harmony|Analysis|Sequence Harmony and Multi-Relief (Brandt et al. 2010)|hseparable,gapCharacter\='-',returns\='ANNOTATION'|?tool\=jalview|http\://zeus.few.vu.nl/programs/shmrwww/index.php?tool\=jalview&groups\=$PARTITION\:min\='2',minsize\='2',sep\=' '$&ali_file\=$ALIGNMENT\:format\='FASTA',writeasfile$ +AUTHORFNAMES=Jim Procter, Andrew Waterhouse, Jan Engelhardt, Lauren Lui, Michele Clamp, James Cuff, Steve Searle, David Martin & Geoff Barton +JALVIEW_RSS_WINDOW_SCREEN_HEIGHT=328 +SHOW_GROUP_CONSENSUS=false +SHOW_CONSENSUS_HISTOGRAM=true +SHOW_OVERVIEW=false +AUTHORS=J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle +FIGURE_AUTOIDWIDTH=false +SCREEN_WIDTH=900 +ANNOTATIONCOLOUR_MIN=ffc800 +SHOW_STARTUP_FILE=false +RECENT_FILE=examples/uniref50.fa\t/Volumes/Data/Users/jimp/Documents/testing/Jalview/examples/RF00031_folded.stk\t/Volumes/Data/Users/jimp/bs_ig_mult.out +DEFAULT_FILE_FORMAT=FASTA +SHOW_JAVA_CONSOLE=false +VERSION=2.8b1 +FIGURE_USERIDWIDTH= +WSMENU_BYTYPE=false +DEFAULT_COLOUR=None +NOQUESTIONNAIRES=true +JALVIEW_NEWS_RSS_LASTMODIFIED=Apr 23, 2014 2\:53\:26 PM +BUILD_DATE=01 November 2013 +PILEUP_JVSUFFIX=true +SHOW_CONSENSUS_LOGO=false +SCREENGEOMETRY_WIDTH=2560 +SHOW_ANNOTATIONS=true +JALVIEW_RSS_WINDOW_SCREEN_Y=0 +USAGESTATS=false +JALVIEW_RSS_WINDOW_SCREEN_X=0 +SHOW_UNCONSERVED=false +SHOW_JVSUFFIX=true +DAS_LOCAL_SOURCE= +SCREEN_HEIGHT=650 +ANNOTATIONCOLOUR_MAX=ff0000 +AUTO_CALC_CONSENSUS=true +FASTA_JVSUFFIX=true +DAS_ACTIVE_SOURCE=uniprot\t +JWS2HOSTURLS=http\://www.compbio.dundee.ac.uk/jabaws +PAD_GAPS=false +CLUSTAL_JVSUFFIX=true +SHOW_ENFIN_SERVICES=true +FONT_SIZE=10 +RIGHT_ALIGN_IDS=false +USE_PROXY=false +WRAP_ALIGNMENT=false +#DAS_REGISTRY_URL=http\://www.dasregistry.org/das/ # retired 01/05/2015 +DAS_REGISTRY_URL=http\://www.ebi.ac.uk/das-srv/registry/das/ +BOOTSTRAP_TEST=true