From 489361286985f3f28253142b9ed3e75afbf1f914 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Tue, 25 Jun 2024 09:55:45 +0100 Subject: [PATCH] JAL-3631 Tests for version comparisons and Jar version comparisons and Jar version checking --- test/jalview/util/LaunchUtilsTest.java | 203 ++++++++++++++++++++ .../fake-getdown-launcher-1.8.3-1.4.3.jar | Bin 0 -> 562 bytes .../fake-getdown-launcher-1.8.3-1.4.4.jar | Bin 0 -> 562 bytes .../fake-getdown-launcher-1.8.3-1.5.0.jar | Bin 0 -> 561 bytes .../fake-getdown-launcher-1.8.4-1.5.0.jar | Bin 0 -> 562 bytes 5 files changed, 203 insertions(+) create mode 100644 test/jalview/util/LaunchUtilsTest.java create mode 100644 test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.3.jar create mode 100644 test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.4.jar create mode 100644 test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.5.0.jar create mode 100644 test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.4-1.5.0.jar diff --git a/test/jalview/util/LaunchUtilsTest.java b/test/jalview/util/LaunchUtilsTest.java new file mode 100644 index 0000000..6545d40 --- /dev/null +++ b/test/jalview/util/LaunchUtilsTest.java @@ -0,0 +1,203 @@ +package jalview.util; + +import java.io.File; + +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +public class LaunchUtilsTest +{ + @Test(groups = "Functional", dataProvider = "versionComparisons") + public void testVersionComparisons(String v0, String v1, int parity) + { + int comparison = LaunchUtils.compareVersions(v0, v1); + if (parity == 0) + { + Assert.assertEquals(comparison, parity, + "These should be parsed as the same."); + } + else if (parity < 0) + { + Assert.assertTrue(comparison < 0, "These should be v0 < v1"); + } + else if (parity > 0) + { + Assert.assertTrue(comparison > 0, "These should be v0 > v1"); + } + } + + @DataProvider(name = "versionComparisons") + public Object[][] versionComparisons() + { + /* + String v0, // a version number + String v1, // a version number + int comparison, // -1 if v0 < v1, 0 if v0 == v1, +1 if v0 > v1 + */ + return new Object[][] { + // + /* + */ + { "2", "2", 0 }, + { "1.2.3.4", "1.2.3.4", 0 }, + { "1.1.1.1", "1.1.1.1", 0 }, + { "1.2.3", "1.2", 1 }, + { "1.2.3", "1.2.3.4", -1 }, + { "1.2.hello.4", "1.2.world.4", -1 }, + { "2.0a", "2.0b", -1 }, + { "1", "2", -1 }, + { "2", "1", 1 }, + /* + */ + // + }; + } + + @Test(groups = "Functional", dataProvider = "getdownVersionComparisons") + public void testGetdownVersionComparisons(String v0, String v1, + int parity) + { + int comparison = LaunchUtils.compareGetdownLauncherJarVersions(v0, v1); + if (parity == 0) + { + Assert.assertEquals(comparison, parity, + "These should be parsed as the same."); + } + else if (parity < 0) + { + Assert.assertTrue(comparison < 0, "These should be v0 < v1"); + } + else if (parity > 0) + { + Assert.assertTrue(comparison > 0, "These should be v0 > v1"); + } + } + + @DataProvider(name = "getdownVersionComparisons") + public Object[][] getdownVersionComparisons() + { + /* + String v0, // a getdown style version number + String v1, // a getdown style version number + int comparison, // -1 if v0 < v1, 0 if v0 == v1, +1 if v0 > v1 + */ + return new Object[][] { + // + /* + */ + { "2", "2", 0 }, + { "1.2.3.4", "1.2.3.4", 0 }, + { "1.1.1.1", "1.1.1.1", 0 }, + { "1.2.3", "1.2", 1 }, + { "1.2.3", "1.2.3.4", -1 }, + { "1.2.hello.4", "1.2.world.4", -1 }, + { "2.0a", "2.0b", -1 }, + { "1", "2", -1 }, + { "2", "1", 1 }, + { "1.8.3-1.4.0_JVL", "1.8.3-1.4.0_JVL", 0 }, + { "1.2.3-4.5.6-7.8.9_NOJVL", "1.2.3-4.5.6-7.8.9_JVL", 0 }, + { "1.2.3-4.6.0-7.8.9", "1.2.3-4.5.6-9.0.0", 1 }, + { "1.2.3-4.5.6-7.8.9", "1.2.3-4.5.6-9.0.0", -1 }, + { "1.3.0-4.5.6-7.8.9", "1.2.3-4.5.6-9.0.0", 1 }, + /* + */ + // + }; + } + + @Test(groups = "Functional", dataProvider = "jarVersions") + public void testJarVersions(File f0, String version) + { + String implementationVersion = LaunchUtils + .getJarImplementationVersion(f0); + Assert.assertEquals(implementationVersion, version, + "These should be the same."); + } + + @DataProvider(name = "jarVersions") + public Object[][] jarVersions() + { + File f0 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.3.jar"); + File f1 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.4.jar"); + File f2 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.5.0.jar"); + File f3 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.4-1.5.0.jar"); + /* + File f0, // a jar file + String version, // the Implementation-Version found in the jar's META-INF/MANIFEST.MF + */ + return new Object[][] { + // + /* + */ + { f0, "1.8.3-1.4.3_JVL" }, + { f1, "1.8.3-1.4.4_JVL" }, + { f2, "1.8.3-1.5.0_JVL" }, + { f3, "1.8.4-1.5.0_JVL" }, + /* + */ + // + }; + } + + @Test(groups = "Functional", dataProvider = "jarVersionComparisons") + public void testJarVersionComparisons(File f0, File f1, int parity) + { + int comparison = LaunchUtils.compareGetdownLauncherJarVersions(f0, f1); + if (parity == 0) + { + Assert.assertEquals(comparison, parity, + "These should be parsed as the same."); + } + else if (parity < 0) + { + Assert.assertTrue(comparison < 0, "These should be f0 < f1"); + } + else if (parity > 0) + { + Assert.assertTrue(comparison > 0, "These should be f0 > f1"); + } + } + + @DataProvider(name = "jarVersionComparisons") + public Object[][] jarVersionComparisons() + { + File f0 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.3.jar"); + File f1 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.4.jar"); + File f2 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.5.0.jar"); + File f3 = new File( + "test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.4-1.5.0.jar"); + /* + File f0, // a jar file (with getdown style Implementation-Version in the META-INF/MANIFEST.MF) + File f1, // a jar file (with getdown style Implementation-Version in the META-INF/MANIFEST.MF) + int comparison, // -1 if f0 < f1, 0 if f0 == f1, +1 if f0 > f1 + */ + return new Object[][] { + // + /* + */ + { f0, f0, 0 }, + { f1, f1, 0 }, + { f2, f2, 0 }, + { f3, f3, 0 }, + { f1, f0, 1 }, + { f2, f1, 1 }, + { f3, f2, 1 }, + { f3, f0, 1 }, + { f0, f1, -1 }, + { f1, f2, -1 }, + { f2, f3, -1 }, + { f0, f3, -1 }, + /* + */ + // + }; + } +} diff --git a/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.3.jar b/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.3.jar new file mode 100644 index 0000000000000000000000000000000000000000..057b95a6eca60ea238aee64d797c12f49e742bb7 GIT binary patch literal 562 zcmWIWW@Zs#;Nak3$n?4y!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g<+J~{VaMSbYi>+YJ7vdPjZ)83Y@+3lrr;tkKt-U-Vm^KY24 z;oo(QpUj{T?mB2SU4fB-K?oSk0p5&EA`GYz1Pgso1fc?Wh=ZaFT`RJ&py)vWTObpz Y6)Ca;yjj^ms+fSV7D&$rI*Ne-00N7%m;e9( literal 0 HcmV?d00001 diff --git a/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.4.jar b/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.4.4.jar new file mode 100644 index 0000000000000000000000000000000000000000..a15f4a0bde3043e5498c9dd897ccc9793ff4b78a GIT binary patch literal 562 zcmWIWW@Zs#;Nak3sPVcP!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g|d8LKY3)GF!k;SDikvbe+u)=JUOU)hl>D%?yrk^stoIh-}(clcvy8U3N%D z^N67K&R`?v* z5&yHN{9y)#u$;ipn+l8!3_`$Q4)A7V5@A4%AXw;wA_x`0LmU)c=vtAD1w{`6*aDew Ytw@m-;LXYgQpE&>wLp44&`}Hw0N6#iIRF3v literal 0 HcmV?d00001 diff --git a/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.5.0.jar b/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.3-1.5.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..3cb6aba361e27e34136c9a9ebd050665b9489e32 GIT binary patch literal 561 zcmWIWW@Zs#;Nak3Xz{uk!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g{#>8*;?NBWDKiM?x<e>Dfj+c1c7a;XSd-;Zz2}O1RK@Hn#QWaXN%MQ)a zJR+&RGk6nI@`d}wweI&{Tu@fKz2wQ;(g|h9FRgv=w}05em#egFUf literal 0 HcmV?d00001 diff --git a/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.4-1.5.0.jar b/test/jalview/util/fake-getdown-launchers/fake-getdown-launcher-1.8.4-1.5.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..bc0ac0251b1ed74ca498661fda02f40c0395fc9c GIT binary patch literal 562 zcmWIWW@Zs#;Nak3==Qo9!GHuf8CV#6T|*poJ^kGD|D9rBU}gyLX6FE@V1g25*Q%G*+VTW6^Kk(HYAhIesMwfD(A znY?Bhj|+BRx;STjBQD|VTAspoY{CBLzZ&;lT)%MPu;Vw_W~N%pzFsH9X=Lr3=6>SxN%jb@ zi2vDB{xE|=Sikm~wE`mpgAg#71H2iTL>N#b2p0OF2toz$5C=sUx>jUkLD7Q%wm>Fa YD^g?yc(byBR51ZzEs&lMbQA*v0HIE|yZ`_I literal 0 HcmV?d00001 -- 1.7.10.2