diff --git a/fcli-core/fcli-tool/src/test/java/com/fortify/cli/tool/versionHandling/VersionHandlingTest.java b/fcli-core/fcli-tool/src/test/java/com/fortify/cli/tool/versionHandling/VersionHandlingTest.java new file mode 100644 index 0000000000..d610b39119 --- /dev/null +++ b/fcli-core/fcli-tool/src/test/java/com/fortify/cli/tool/versionHandling/VersionHandlingTest.java @@ -0,0 +1,40 @@ +package com.fortify.cli.tool.versionHandling; + +import java.io.InputStream; + +import org.junit.jupiter.api.Test; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fortify.cli.tool._common.helper.ToolDownloadDescriptor; +import com.fortify.cli.tool._common.helper.ToolHelper; + +import org.junit.jupiter.api.Assertions; + + +public class VersionHandlingTest { + private static final ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory()); + String toolName = "sc-client"; + + @Test + public void testVersionHandling() throws Exception { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + String resourceFile = ToolHelper.getResourceFile(toolName, String.format("%s.yaml", toolName)); + try (InputStream file = classLoader.getResourceAsStream(resourceFile)) { + + var downloadDescriptor = yamlObjectMapper.readValue(file, ToolDownloadDescriptor.class); + var d = downloadDescriptor.getVersion("20"); + var d2 = downloadDescriptor.getVersion("20."); + var d3 = downloadDescriptor.getVersion("21.1"); + var d4 = downloadDescriptor.getVersion("21.1.2"); + + Assertions.assertEquals(d.getVersion(), "20.2.4"); + Assertions.assertEquals(d2.getVersion(), "20.2.4"); + Assertions.assertEquals(d3.getVersion(), "21.1.4"); + Assertions.assertEquals(d4.getVersion(), "21.1.2"); + } catch(Exception e) { + throw e; + } + } +} + diff --git a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/tool/ToolVersionHandlingSpec.groovy b/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/tool/ToolVersionHandlingSpec.groovy deleted file mode 100644 index 8d7461b0f8..0000000000 --- a/fcli-other/fcli-functional-test/src/ftest/groovy/com/fortify/cli/ftest/tool/ToolVersionHandlingSpec.groovy +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2023 Open Text. - * - * The only warranties for products and services of Open Text - * and its affiliates and licensors ("Open Text") are as may - * be set forth in the express warranty statements accompanying - * such products and services. Nothing herein should be construed - * as constituting an additional warranty. Open Text shall not be - * liable for technical or editorial errors or omissions contained - * herein. The information contained herein is subject to change - * without notice. - */ -package com.fortify.cli.ftest.tool - -import static com.fortify.cli.ftest._common.spec.FcliSessionType.SSC - -import com.fasterxml.jackson.databind.ObjectMapper -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory -import com.fortify.cli.ftest._common.Fcli -import com.fortify.cli.ftest._common.spec.FcliBaseSpec -import com.fortify.cli.ftest._common.spec.FcliSession -import com.fortify.cli.ftest._common.spec.Prefix -import com.fortify.cli.ftest.ssc._common.SSCRoleSupplier -import com.fortify.cli.ftest.ssc._common.SSCRoleSupplier.SSCRole -import spock.lang.AutoCleanup -import spock.lang.Requires -import spock.lang.Shared -import spock.lang.Stepwise - -import com.fortify.cli.tool._common.helper.ToolDownloadDescriptor -import com.fortify.cli.tool._common.helper.ToolHelper; - -@Prefix("tool.VersionHandling") @Stepwise -class ToolVersionHandlingSpec extends FcliBaseSpec { - private static final ObjectMapper yamlObjectMapper = new ObjectMapper(new YAMLFactory()); - - def "testVersionHandling"() { - String toolName = "sc-client" - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - String resourceFile = ToolHelper.getResourceFile(toolName, String.format("%s.yaml", toolName)); - InputStream file = classLoader.getResourceAsStream(resourceFile); - def downloadDescriptor = yamlObjectMapper.readValue(file, ToolDownloadDescriptor.class); - file.close(); - when: - def d = downloadDescriptor.getVersion("20"); - def d2 = downloadDescriptor.getVersion("20."); - def d3 = downloadDescriptor.getVersion("22.2"); - def d4 = downloadDescriptor.getVersion("22.2.0"); - then: - d.version == "20.2.4"; - d2.version == "20.2.4"; - d3.version == "22.2.1"; - d4.version == "22.2.0"; - - } - - -}