From eec89bb7eeb11cd0d8fb3791ca80eefe4f9ab38a Mon Sep 17 00:00:00 2001 From: "derek.sharpe" Date: Thu, 11 Apr 2024 14:29:24 +0000 Subject: [PATCH] Cleaned up patch version comparison to simplify code complexity --- .../weblogic/imagetool/aru/AruPatch.java | 38 +----- .../weblogic/imagetool/aru/Version.java | 91 -------------- .../imagetool/cachestore/OPatchFile.java | 9 +- .../weblogic/imagetool/util/HttpUtil.java | 16 +-- .../oracle/weblogic/imagetool/util/Utils.java | 88 +++++++------ .../weblogic/imagetool/aru/VersionTest.java | 82 ------------ .../imagetool/cachestore/PatchFileTest.java | 3 +- .../installer/MiddlewareInstallTest.java | 90 ++++++++++++++ .../weblogic/imagetool/util/UtilsTest.java | 117 +++++++++++++++++- .../dummyInstallers/dummyResponse.txt | 1 + .../dummyInstallers/test-installer.zip | Bin 0 -> 506 bytes .../test/resources/patches/patch-2818673x.xml | 48 ++++++- 12 files changed, 321 insertions(+), 262 deletions(-) delete mode 100644 imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/Version.java delete mode 100644 imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/VersionTest.java create mode 100644 imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/MiddlewareInstallTest.java create mode 100644 imagetool/src/test/resources/dummyInstallers/dummyResponse.txt create mode 100644 imagetool/src/test/resources/dummyInstallers/test-installer.zip diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java index 298baf1b7..a03eae7cd 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/AruPatch.java @@ -1,11 +1,10 @@ -// Copyright (c) 2020, 2022, Oracle and/or its affiliates. +// Copyright (c) 2020, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.aru; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.xml.xpath.XPathExpressionException; @@ -22,11 +21,11 @@ * Metadata for a patch, as defined by ARU. * Simple bean for holding metadata obtained from ARU for a given patch ID and version. */ -public class AruPatch implements Comparable { +public class AruPatch { private static final LoggingFacade logger = LoggingFactory.getLogger(AruPatch.class); private String patchId; - private Version version; + private String version; private String description; private String product; private String release; @@ -51,15 +50,11 @@ public AruPatch patchId(String value) { * @return The string value of the version found in ARU. */ public String version() { - if (version != null) { - return version.toString(); - } else { - return null; - } + return version; } public AruPatch version(String value) { - version = new Version(value); + version = value; return this; } @@ -294,27 +289,4 @@ private static AruPatch selectPatchOffline(List patches, String provid public String toString() { return patchId + " - " + description; } - - @Override - public int compareTo(AruPatch obj) { - return version.compareTo(obj.version); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - AruPatch aruPatch = (AruPatch) o; - return Objects.equals(patchId, aruPatch.patchId) && Objects.equals(version, aruPatch.version) - && Objects.equals(release, aruPatch.release); - } - - @Override - public int hashCode() { - return Objects.hash(patchId, version, release); - } } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/Version.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/Version.java deleted file mode 100644 index dfec386af..000000000 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/aru/Version.java +++ /dev/null @@ -1,91 +0,0 @@ -// Copyright (c) 2023, Oracle and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - -package com.oracle.weblogic.imagetool.aru; - -import java.util.Arrays; - -public class Version implements Comparable { - private final int[] sequence; - private final String stringValue; - - /** - * Representation of the ARU version number used for Oracle products. - * Version must be one or more integers separated by a period, ".". - * @param value String to be parsed as the ARU version. - */ - public Version(String value) { - stringValue = value; - - if (value != null && !value.isEmpty()) { - // split version into a sequence tokens using the period separator - sequence = Arrays.stream(value.split("\\.")) - .mapToInt(Integer::parseInt) - .toArray(); - } else { - sequence = new int[1]; - } - } - - /** - * Return the sequence of version tokens padded to the minimum length with 0's. - * The sequence will NOT be truncated. - * @param minLength minimum number of version tokens in the array. - * @return sequence of version tokens - */ - public int[] getSequence(int minLength) { - if (sequence.length < minLength) { - return Arrays.copyOf(sequence, minLength); - } - return sequence; - } - - /** - * Compare this version number against the provided version, returning -1, 0, or 1 if - * this version is less than, equal to, or greater than the provided version, respectively. - * @param provided the object to be compared. - * @return -1, 0, or 1 if this version is less than, equal to, or greater than the provided version - */ - @Override - public int compareTo(Version provided) { - int match = 0; - int sequenceLength = Math.max(sequence.length, provided.sequence.length); - int[] mySequence = getSequence(sequenceLength); - int[] providedSequence = provided.getSequence(sequenceLength); - - for (int i = 0; i < sequenceLength; i++) { - if (mySequence[i] > providedSequence[i]) { - match = 1; - } else if (mySequence[i] < providedSequence[i]) { - match = -1; - } - if (match != 0) { - break; - } - } - - return match; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Version version = (Version) o; - return this.compareTo(version) == 0; - } - - @Override - public int hashCode() { - return Arrays.hashCode(sequence); - } - - @Override - public String toString() { - return stringValue; - } -} diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java index 30e93483d..58c2425fc 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/cachestore/OPatchFile.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2022, Oracle and/or its affiliates. +// Copyright (c) 2020, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.cachestore; @@ -110,8 +110,11 @@ private static AruPatch getAruPatchOnline(String patchNumber, String providedVer throw new VersionNotFoundException(patchNumber, providedVersion, patches); } } else { - // Select the newest (highest numbered) patch - selectedPatch = patches.stream().max(Comparator.naturalOrder()).orElse(null); + // Compare the ARU OPatch patches using the patch version field, like 12.2.1.4.0 + Comparator patchVersionComparator = + Comparator.comparing(AruPatch::version, Utils::compareVersionsNullsFirst); + // Select the newest (highest version) OPatch install/patch + selectedPatch = patches.stream().max(patchVersionComparator).orElse(null); } return selectedPatch; } diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/HttpUtil.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/HttpUtil.java index f12f71eea..ff9a5ca26 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/HttpUtil.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/HttpUtil.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2022, Oracle and/or its affiliates. +// Copyright (c) 2019, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.util; @@ -182,18 +182,12 @@ private static HttpRequestRetryHandler retryHandler() { // Do not retry if over max retries return false; } - if (exception instanceof InterruptedIOException) { - // Timeout - return false; - } - if (exception instanceof UnknownHostException) { - // Unknown host - return false; - } - if (exception instanceof SSLException) { - // SSL handshake failed + if (exception instanceof InterruptedIOException // Timeout + || exception instanceof UnknownHostException // Unknown Host + || exception instanceof SSLException) { // SSL handshake failed return false; } + HttpClientContext clientContext = HttpClientContext.adapt(context); HttpRequest request = clientContext.getRequest(); // return true if it is okay to retry this request type diff --git a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java index dd9f1da38..2c2e88a30 100644 --- a/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java +++ b/imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2021, Oracle and/or its affiliates. +// Copyright (c) 2019, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.util; @@ -303,6 +303,27 @@ public static void deleteFilesRecursively(String pathDir) throws IOException { logger.exiting(); } + /** + * Compares two version strings. A null-friendly comparator that considers null to be less than non-null. + * Any qualifiers are treated as older than the same version without + * a qualifier. If both versions have qualifiers and are otherwise equal, they are compared using + * String.compareTo() to determine the result. + * + * @param thisVersion - first version + * @param otherVersion - second version + * @return returns 0 if the versions are equal, greater than zero if thisVersion is newer, + * and less than zero if thisVersion is older. + */ + public static int compareVersionsNullsFirst(String thisVersion, String otherVersion) { + if (isEmptyString(thisVersion)) { + return (isEmptyString(otherVersion)) ? 0 : -1; + } else if (isEmptyString(otherVersion)) { + return 1; + } else { + return compareVersions(thisVersion, otherVersion); + } + } + /** * Compares two version strings. Any qualifiers are treated as older than the same version without * a qualifier. If both versions have qualifiers and are otherwise equal, they are compared using @@ -314,8 +335,6 @@ public static void deleteFilesRecursively(String pathDir) throws IOException { * and less than zero if thisVersion is older. */ public static int compareVersions(String thisVersion, String otherVersion) { - int result = 0; - if (isEmptyString(thisVersion) || isEmptyString(otherVersion)) { throw new IllegalArgumentException("cannot compare null strings"); } @@ -330,24 +349,22 @@ public static int compareVersions(String thisVersion, String otherVersion) { int fieldsToCompare = Math.min(thisVersionElements.length, otherVersionElements.length); + int result = 0; int idx; for (idx = 0; idx < fieldsToCompare; idx++) { int thisVersionNumber = Integer.parseInt(thisVersionElements[idx]); int otherVersionNumber = Integer.parseInt(otherVersionElements[idx]); - if (thisVersionNumber > otherVersionNumber) { - result = 1; - break; - } else if (thisVersionNumber < otherVersionNumber) { - result = -1; - break; + result = Integer.compare(thisVersionNumber, otherVersionNumber); + if (result != 0) { + return result; } } // Version fields compared so far are equal so check to see if one version number // has more fields than the other. // - if (result == 0 && thisVersionElements.length != otherVersionElements.length) { + if (thisVersionElements.length != otherVersionElements.length) { if (thisVersionElements.length > otherVersionElements.length) { result = 1; } else { @@ -355,36 +372,37 @@ public static int compareVersions(String thisVersion, String otherVersion) { } } + if (result != 0) { + return result; + } + // Finally, look to see if one or both versions have a qualifier if they are otherwise the same. // - if (result == 0) { - int useCase = 0; - if (thisVersion.indexOf('-') != -1) { - useCase += 1; - } - if (otherVersion.indexOf('-') != -1) { - useCase += 2; - } - switch (useCase) { - case 0: - break; + int useCase = 0; + if (thisVersion.indexOf('-') != -1) { + useCase += 1; + } + if (otherVersion.indexOf('-') != -1) { + useCase += 2; + } + switch (useCase) { + case 1: + result = -1; + break; - case 1: - result = -1; - break; + case 2: + result = 1; + break; - case 2: - result = 1; - break; + case 3: + String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); + String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); + result = thisQualifier.compareTo(otherQualifier); + break; - case 3: - String thisQualifier = thisVersion.substring(thisVersion.indexOf('-')); - String otherQualifier = otherVersion.substring(otherVersion.indexOf('-')); - result = thisQualifier.compareTo(otherQualifier); - break; - default: - break; - } + case 0: + default: + break; } return result; } diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/VersionTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/VersionTest.java deleted file mode 100644 index f0c135c56..000000000 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/aru/VersionTest.java +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) 2023, Oracle and/or its affiliates. -// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. - -package com.oracle.weblogic.imagetool.aru; - -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -@Tag("unit") -class VersionTest { - @Test - void sameVersionNumber() { - Version a = new Version("1.2.3"); - Version b = new Version("1.2.3"); - assertEquals(0, b.compareTo(a)); - assertEquals(0, a.compareTo(b)); - } - - private void compareDifferingVersions(String firstVersion, String laterVersion) { - Version v1 = new Version(firstVersion); - Version v2 = new Version(laterVersion); - assertEquals(1, v2.compareTo(v1)); - assertEquals(-1, v1.compareTo(v2)); - } - - @Test - void differentVersionNumbers() { - compareDifferingVersions("1.2.3", "1.2.4"); - } - - @Test - void differentVersionLengths() { - compareDifferingVersions("1.2.3", "1.2.3.1"); - } - - @Test - void integerComparison() { - compareDifferingVersions("13.9.4.2.9", "13.9.4.2.10"); - } - - @Test - void nullVersion() { - compareDifferingVersions(null, "1.2.3"); - } - - @Test - void nonNumericVersion() { - assertThrows(NumberFormatException.class, () -> new Version("1.A.4")); - assertThrows(NumberFormatException.class, () -> new Version("1.2.3-SNAP")); - } - - @Test - void allowsNull() { - Version a = new Version(null); - Version b = new Version("1.2.3"); - assertEquals(1, b.compareTo(a)); - assertEquals(-1, a.compareTo(b)); - } - - @Test - void equalObjects() { - Version a = new Version("1.2.3"); - Version b = new Version("1.2.3"); - assertEquals(a, b); - assertEquals(b, a); - assertEquals(a, a); - assertNotEquals(a, null); - } - - @Test - void hashcodeTest() { - Version a = new Version("1.2.3"); - Version b = new Version("1.2.3"); - Version c = new Version("1.2.4"); - assertEquals(a.hashCode(), b.hashCode()); - assertNotEquals(a.hashCode(), c.hashCode()); - } -} diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java index 9bb60e4ad..41cdd0af1 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/cachestore/PatchFileTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2020, 2022, Oracle and/or its affiliates. +// Copyright (c) 2020, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.cachestore; @@ -404,6 +404,7 @@ void opatchNoRecommendedTest() throws Exception { String patchId = "2818673x"; OPatchFile patchFile = OPatchFile.getInstance(patchId, "x", "x", cacheStore); + assertEquals("13.9.4.2.5", patchFile.getVersion()); String filePath = patchFile.resolve(cacheStore); assertNotNull(filePath, "Patch resolve() failed to get file path from XML"); diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/MiddlewareInstallTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/MiddlewareInstallTest.java new file mode 100644 index 000000000..e357ebfeb --- /dev/null +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/installer/MiddlewareInstallTest.java @@ -0,0 +1,90 @@ +// Copyright (c) 2024, Oracle and/or its affiliates. +// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. + +package com.oracle.weblogic.imagetool.installer; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Collections; +import java.util.List; +import java.util.logging.Level; + +import com.oracle.weblogic.imagetool.ResourceUtils; +import com.oracle.weblogic.imagetool.cachestore.CacheStore; +import com.oracle.weblogic.imagetool.cachestore.CacheStoreTestImpl; +import com.oracle.weblogic.imagetool.logging.LoggingFacade; +import com.oracle.weblogic.imagetool.logging.LoggingFactory; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; +import static org.junit.jupiter.api.Assertions.assertTrue; + +@Tag("unit") +class MiddlewareInstallTest { + static Path cacheDir; + static CacheStore cacheStore; + private static final LoggingFacade commandLogger = LoggingFactory.getLogger(MiddlewareInstall.class); + private static Level oldLevel; + + @BeforeAll + static void setup(@TempDir Path cacheDir) throws IOException { + oldLevel = commandLogger.getLevel(); + commandLogger.setLevel(Level.WARNING); + + MiddlewareInstallTest.cacheDir = cacheDir; + cacheStore = new CacheStoreTestImpl(cacheDir); + cacheStore.addToCache("wls_12.2.1.4.0", + ResourceUtils.resourcePath("/dummyInstallers/test-installer.zip").toString()); + } + + @AfterAll + static void tearDown() { + commandLogger.setLevel(oldLevel); + } + + @Test + void copyInstaller(@TempDir Path buildContextDir) throws IOException { + // Test a simple WLS install type, and copy the files to the build context folder + MiddlewareInstall install = new MiddlewareInstall(FmwInstallerType.WLS, "12.2.1.4.0", null, null); + install.copyFiles(cacheStore, buildContextDir.toString()); + // 2 files should be copied from cache to build context folder + assertTrue(Files.isRegularFile(buildContextDir.resolve("test-installer.zip"))); + assertTrue(Files.isRegularFile(buildContextDir.resolve("wls.rsp")), "Response file not found"); + // JAR name from inside the zip should be correctly identified + List installers = install.getInstallers(); + assertEquals(1, installers.size()); + + MiddlewareInstallPackage pkg = installers.get(0); + assertTrue(pkg.isZip); + assertEquals("the-installer.jar", pkg.jarName); + assertEquals("wls.rsp", pkg.responseFile.name()); + assertInstanceOf(DefaultResponseFile.class, pkg.responseFile); + } + + @Test + void customResponseFile(@TempDir Path buildContextDir) throws IOException { + List customResponse = + Collections.singletonList(ResourceUtils.resourcePath("/dummyInstallers/dummyResponse.txt")); + // Test a simple WLS install type, and copy the files to the build context folder + MiddlewareInstall install = new MiddlewareInstall(FmwInstallerType.WLS, "12.2.1.4.0", customResponse, null); + install.copyFiles(cacheStore, buildContextDir.toString()); + // 2 files should be copied from cache to build context folder + assertTrue(Files.isRegularFile(buildContextDir.resolve("test-installer.zip"))); + assertTrue(Files.isRegularFile(buildContextDir.resolve("dummyResponse.txt")), "Response file not found"); + // JAR name from inside the zip should be correctly identified + List installers = install.getInstallers(); + assertEquals(1, installers.size()); + + MiddlewareInstallPackage pkg = installers.get(0); + assertTrue(pkg.isZip); + assertEquals("the-installer.jar", pkg.jarName); + assertEquals("dummyResponse.txt", pkg.responseFile.name()); + assertInstanceOf(ProvidedResponseFile.class, pkg.responseFile); + } +} diff --git a/imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java b/imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java index 92a0c6be9..a869d28fe 100644 --- a/imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java +++ b/imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java @@ -1,4 +1,4 @@ -// Copyright (c) 2019, 2022, Oracle and/or its affiliates. +// Copyright (c) 2019, 2024, Oracle and/or its affiliates. // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. package com.oracle.weblogic.imagetool.util; @@ -43,10 +43,117 @@ class UtilsTest { private SystemProperties overrideProperties; @Test - void compareVersions() { - assertEquals(0, Utils.compareVersions("12.2.1.3.0", "12.2.1.3.0")); - assertTrue(Utils.compareVersions("1.0", "1.1") < 0); - assertTrue(Utils.compareVersions("1.1", "1.0") > 0); + void firstGreaterThanLast() throws Exception { + String thisVersion = "12.2.1.3.0"; + String thatVersion = "12.2.1.2.0"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "0.7.4"; + thatVersion = "0.7.3"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "0.8"; + thatVersion = "0.7.4"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "1.2.3"; + thatVersion = "1.2"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "13.9.4.2.10"; + thatVersion = "13.9.4.2.9"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "1.2.3"; + thatVersion = "1.2.3-SNAPSHOT"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "1.2.3-BETA1"; + thatVersion = "1.2.3-ALPHA3"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + + thisVersion = "1.2.3-SNAPSHOT"; + thatVersion = "1.2.2"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) > 0, + "Expected this " + thisVersion + " to be newer than that " + thatVersion); + } + + @Test + void secondGreaterThanFirst() throws Exception { + String thisVersion = "12.2.1.3.0"; + String thatVersion = "12.2.1.4.0"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "0.7.3"; + thatVersion = "0.7.4"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "0.7.4"; + thatVersion = "1"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "1.2"; + thatVersion = "1.2.3"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "1.2.3-SNAPSHOT"; + thatVersion = "1.2.3"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "1.2.3-ALPHA4"; + thatVersion = "1.2.3-ALPHA5"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + + thisVersion = "1.2.1"; + thatVersion = "1.2.2-SNAPSHOT"; + assertTrue(Utils.compareVersions(thisVersion, thatVersion) < 0, + "Expected that " + thatVersion + " to be newer than this " + thisVersion); + } + + @Test + void versionsShouldBeEqual() throws Exception { + String thisVersion = "12.2.1.3.0"; + String thatVersion = "12.2.1.3.0"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); + + thisVersion = "0.7.4"; + thatVersion = "0.7.4"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); + + thisVersion = "1"; + thatVersion = "1"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); + + thisVersion = "1.2.3-ALPHA1"; + thatVersion = "1.2.3-ALPHA1"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); + + thisVersion = "1.2.3.4.5.6.7.8.9"; + thatVersion = "1.2.3.4.5.6.7.8.9"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); + + thisVersion = "0.7.4-SNAPSHOT"; + thatVersion = "0.7.4-SNAPSHOT"; + assertEquals(0, Utils.compareVersions(thisVersion, thatVersion), + "Expected server " + thatVersion + " to be the same as client " + thisVersion); } @Test diff --git a/imagetool/src/test/resources/dummyInstallers/dummyResponse.txt b/imagetool/src/test/resources/dummyInstallers/dummyResponse.txt new file mode 100644 index 000000000..2995a4d0e --- /dev/null +++ b/imagetool/src/test/resources/dummyInstallers/dummyResponse.txt @@ -0,0 +1 @@ +dummy \ No newline at end of file diff --git a/imagetool/src/test/resources/dummyInstallers/test-installer.zip b/imagetool/src/test/resources/dummyInstallers/test-installer.zip new file mode 100644 index 0000000000000000000000000000000000000000..f87e0b812a22be8da72d5bbbc680f336d28eb59f GIT binary patch literal 506 zcmWIWW@h1H00IB%&WLQ8eol5E8-%$SWEg@{6H|Os^-3yALPIzin9G)krh#y21vdjD z%U4DQ1{RRcjMSW*d@im4piv?~E(b#l(5T$()Tg{a9zPI+jLOVQNv+V!D9OzM8`Tdq z287X!+I&*uv@+$f-#AdF^iNosKk$c2nda?H5AD*-f^fdS|#h9!+47P9AAA)ZGw6=EJPKO>vx v4Kxoq1c2sY@jbHpFujay-W;HLSONfOEEdlPc(Z~6je!{mzXR#FAPxfn7A$7= literal 0 HcmV?d00001 diff --git a/imagetool/src/test/resources/patches/patch-2818673x.xml b/imagetool/src/test/resources/patches/patch-2818673x.xml index 22888e82c..695483759 100644 --- a/imagetool/src/test/resources/patches/patch-2818673x.xml +++ b/imagetool/src/test/resources/patches/patch-2818673x.xml @@ -1,10 +1,56 @@ - + 2020-12-01 19:13:17 + + + 28186730 + + + 28186730 + Patch + Available + Open access + + + + + 23901536 + + + + + + + + + + + + + No + General + General + General Support + + + + 45855234 + + + p28186730_139425_Generic.zip + 45855234 + + 8BFC99E439DA1D1663F88D6859EC19E9926A473C96B95889ABE5F45C055E1BB3 + 41E3536305E6A71776717D700FA41B1A1AB0A493 + + + 2020-11-05 16:46:51 + 2020-11-05 16:09:31 + 28186730