From d78dbc27bb261ef49a8a8d07ffed56320d6df144 Mon Sep 17 00:00:00 2001 From: jan-vcapgemini Date: Fri, 10 Jan 2025 13:20:43 +0100 Subject: [PATCH] #759: added more tests fixed typo added test of convert to CustomToolsJsonMapperTest --- .../ide/repo/AbstractToolRepository.java | 2 +- .../ide/repo/CustomToolRepositoryImpl.java | 6 +- .../ide/repo/CustomToolsJsonMapperTest.java | 64 +++++++++++++++++++ 3 files changed, 68 insertions(+), 4 deletions(-) diff --git a/cli/src/main/java/com/devonfw/tools/ide/repo/AbstractToolRepository.java b/cli/src/main/java/com/devonfw/tools/ide/repo/AbstractToolRepository.java index 95955aa29..41c5d4976 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/repo/AbstractToolRepository.java +++ b/cli/src/main/java/com/devonfw/tools/ide/repo/AbstractToolRepository.java @@ -164,7 +164,7 @@ protected Path download(String url, Path target, String downloadFilename, Versio this.context.getFileAccess().download(url, tmpDownloadFile); if (resolvedVersion.toString().equals("latest")) { // Some software vendors violate best-practices and provide the latest version only under a fixed URL. - // Therefore if a newer version of that file gets released, the same URL suddenly leads to a different + // Therefore, if a newer version of that file gets released, the same URL suddenly leads to a different // download file with a newer version and a different checksum. // In order to still support such tools we had to implement this workaround so we cannot move the file in the // download cache for later reuse, cannot verify its checksum and also delete the downloaded file on exit diff --git a/cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolRepositoryImpl.java b/cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolRepositoryImpl.java index b29d87df3..b6cab89d8 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolRepositoryImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/repo/CustomToolRepositoryImpl.java @@ -122,11 +122,11 @@ private CustomToolMetadata getCustomTool(String tool) { public VersionIdentifier resolveVersion(String tool, String edition, GenericVersionRange version) { CustomToolMetadata customTool = getCustomTool(tool); - VersionIdentifier customToolVerstion = customTool.getVersion(); - if (!version.contains(customToolVerstion)) { + VersionIdentifier customToolVersion = customTool.getVersion(); + if (!version.contains(customToolVersion)) { throw new IllegalStateException(customTool + " does not satisfy version to install " + version); } - return customToolVerstion; + return customToolVersion; } @Override diff --git a/cli/src/test/java/com/devonfw/tools/ide/repo/CustomToolsJsonMapperTest.java b/cli/src/test/java/com/devonfw/tools/ide/repo/CustomToolsJsonMapperTest.java index 8baf84e60..4b66b0b92 100644 --- a/cli/src/test/java/com/devonfw/tools/ide/repo/CustomToolsJsonMapperTest.java +++ b/cli/src/test/java/com/devonfw/tools/ide/repo/CustomToolsJsonMapperTest.java @@ -1,6 +1,7 @@ package com.devonfw.tools.ide.repo; import java.nio.file.Path; +import java.util.ArrayList; import java.util.List; import org.assertj.core.api.Assertions; @@ -10,8 +11,11 @@ import com.devonfw.tools.ide.context.IdeContext; import com.devonfw.tools.ide.context.IdeSlf4jContext; import com.devonfw.tools.ide.context.IdeTestContext; +import com.devonfw.tools.ide.os.OperatingSystem; +import com.devonfw.tools.ide.os.SystemArchitecture; import com.devonfw.tools.ide.os.SystemInfo; import com.devonfw.tools.ide.os.SystemInfoMock; +import com.devonfw.tools.ide.version.VersionIdentifier; /** * Test of {@link CustomToolsJsonMapper}. @@ -30,6 +34,12 @@ public void testReadCustomToolsFromJson() { List customToolsMetadata = CustomToolsJsonMapper.convert(customToolsJson, context); // assert assertThat(customToolsJson.url()).isEqualTo("https://some-file-server.company.com/projects/my-project"); + // assert that custom tools content matches to json file + assertThat(customToolsJson.tools()).containsExactly(new CustomToolJson("jboss-eap", "7.1.4.GA", true, true, + null), + new CustomToolJson("firefox", "70.0.1", false, false, + "https://some-file-server.company.com/projects/my-project2")); + // assert that url was properly created assertThat(customToolsMetadata.get(0).getUrl()).isEqualTo( "https://some-file-server.company.com/projects/my-project/jboss-eap/7.1.4.GA/jboss-eap-7.1.4.GA.tgz"); assertThat(customToolsMetadata.get(1).getUrl()).isEqualTo( @@ -46,6 +56,10 @@ public void testReadCustomToolsFromLegacyConfig() { List customToolsMetadata = CustomToolsJsonMapper.convert(customToolsJson, context); // assert assertThat(customToolsJson.url()).isEqualTo("https://host.tld/projects/my-project"); + assertThat(customToolsJson.tools()).containsExactly(new CustomToolJson("jboss-eap", "7.1.4.GA", true, true, + null), + new CustomToolJson("firefox", "70.0.1", true, true, "")); + assertThat(customToolsMetadata.get(0).getUrl()).isEqualTo( "https://host.tld/projects/my-project/jboss-eap/7.1.4.GA/jboss-eap-7.1.4.GA.tgz"); assertThat(customToolsMetadata.get(1).getUrl()).isEqualTo( @@ -73,4 +87,54 @@ public void testReadFaultyCustomToolsFromLegacyConfig() { // assert assertThat(customToolsJson).isNull(); } + + /** + * Tests the convert of a {@link CustomToolsJson} with different os and arch agnostic settings to a proper {@link CustomToolMetadata}. + */ + @Test + public void testProperConvertFromCustomToolsJsonToCustomToolMetaData() { + + // arrange + AbstractIdeTestContext context = new IdeSlf4jContext(Path.of("")); + SystemInfo systemInfo = SystemInfoMock.LINUX_X64; + context.setSystemInfo(systemInfo); + String name = "jboss-eap"; + String version = "7.4.5.GA"; + String repositoryUrl = "https://host.domain.tld:8443/folder/repo/"; + String url = repositoryUrl + "jboss-eap/7.4.5.GA/jboss-eap-7.4.5.GA.tgz"; + OperatingSystem os = null; + SystemArchitecture arch = null; + + String name1 = "firefox"; + String version1 = "70.0.1"; + String repositoryUrl1 = "https://host.domain.tld:8443/folder/repo/"; + String checkOsArchUrl = repositoryUrl1 + "firefox/70.0.1/firefox-70.0.1-linux-x64.tgz"; + OperatingSystem os1 = OperatingSystem.LINUX; + SystemArchitecture arch1 = SystemArchitecture.X64; + + CustomToolJson customToolJson = new CustomToolJson(name, version, true, true, repositoryUrl); + CustomToolJson customToolJsonWithOs = new CustomToolJson(name1, version1, false, false, repositoryUrl1); + List customToolJsonList = new ArrayList<>(); + customToolJsonList.add(customToolJson); + customToolJsonList.add(customToolJsonWithOs); + CustomToolsJson customToolsJson = new CustomToolsJson(repositoryUrl, customToolJsonList); + // act + List customToolMetadata = CustomToolsJsonMapper.convert(customToolsJson, context); + // assert + assertThat(customToolMetadata.get(0).getTool()).isEqualTo(name); + assertThat(customToolMetadata.get(0).getVersion()).isEqualTo(VersionIdentifier.of(version)); + assertThat(customToolMetadata.get(0).getOs()).isEqualTo(os); + assertThat(customToolMetadata.get(0).getArch()).isEqualTo(arch); + assertThat(customToolMetadata.get(0).getUrl()).isEqualTo(url); + assertThat(customToolMetadata.get(0).getChecksum()).isNull(); + assertThat(customToolMetadata.get(0).getRepositoryUrl()).isEqualTo(repositoryUrl); + + assertThat(customToolMetadata.get(1).getTool()).isEqualTo(name1); + assertThat(customToolMetadata.get(1).getVersion()).isEqualTo(VersionIdentifier.of(version1)); + assertThat(customToolMetadata.get(1).getOs()).isEqualTo(os1); + assertThat(customToolMetadata.get(1).getArch()).isEqualTo(arch1); + assertThat(customToolMetadata.get(1).getUrl()).isEqualTo(checkOsArchUrl); + assertThat(customToolMetadata.get(1).getChecksum()).isNull(); + assertThat(customToolMetadata.get(1).getRepositoryUrl()).isEqualTo(repositoryUrl1); + } }