Skip to content

Commit

Permalink
#759: added more tests
Browse files Browse the repository at this point in the history
fixed typo
added test of convert to CustomToolsJsonMapperTest
  • Loading branch information
jan-vcapgemini committed Jan 10, 2025
1 parent db02a0c commit d78dbc2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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}.
Expand All @@ -30,6 +34,12 @@ public void testReadCustomToolsFromJson() {
List<CustomToolMetadata> 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(
Expand All @@ -46,6 +56,10 @@ public void testReadCustomToolsFromLegacyConfig() {
List<CustomToolMetadata> 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(
Expand Down Expand Up @@ -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<CustomToolJson> customToolJsonList = new ArrayList<>();
customToolJsonList.add(customToolJson);
customToolJsonList.add(customToolJsonWithOs);
CustomToolsJson customToolsJson = new CustomToolsJson(repositoryUrl, customToolJsonList);
// act
List<CustomToolMetadata> 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);
}
}

0 comments on commit d78dbc2

Please sign in to comment.