|
| 1 | +package com.devonfw.tools.ide.url.tool.obsidian; |
| 2 | + |
| 3 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 4 | +import static com.github.tomakehurst.wiremock.client.WireMock.any; |
| 5 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 6 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 7 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; |
| 8 | + |
| 9 | +import java.io.IOException; |
| 10 | +import java.nio.file.Path; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +import org.junit.jupiter.api.Test; |
| 14 | +import org.junit.jupiter.api.io.TempDir; |
| 15 | + |
| 16 | +import com.devonfw.tools.ide.url.model.folder.UrlRepository; |
| 17 | +import com.devonfw.tools.ide.url.updater.AbstractUrlUpdaterTest; |
| 18 | +import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo; |
| 19 | +import com.github.tomakehurst.wiremock.junit5.WireMockTest; |
| 20 | + |
| 21 | +/** |
| 22 | + * Test of {@link ObsidianUrlUpdater}. |
| 23 | + */ |
| 24 | +@WireMockTest |
| 25 | +public class ObsidianUrlUpdaterTest extends AbstractUrlUpdaterTest { |
| 26 | + |
| 27 | + /** |
| 28 | + * Test of {@link ObsidianUrlUpdater} for the creation of download URLs and checksums. |
| 29 | + * |
| 30 | + * @param tempDir Path to a temporary directory. |
| 31 | + * @param wmRuntimeInfo the {@link WireMockRuntimeInfo}. |
| 32 | + */ |
| 33 | + @Test |
| 34 | + void testObsidianUrlUpdater(@TempDir Path tempDir, WireMockRuntimeInfo wmRuntimeInfo) throws IOException { |
| 35 | + |
| 36 | + // arrange |
| 37 | + stubFor(get(urlMatching("/repos/obsidianmd/obsidian-releases/releases")) |
| 38 | + .willReturn(aResponse() |
| 39 | + .withStatus(200) |
| 40 | + .withBody(readAndResolve(PATH_INTEGRATION_TEST.resolve("ObsidianUrlUpdater") |
| 41 | + .resolve("obsidian-releases.json"), wmRuntimeInfo)))); |
| 42 | + |
| 43 | + stubFor(any(urlMatching("/obsidianmd/obsidian-releases/releases/download/v\\d+\\.\\d+\\.\\d+/Obsidian-.*\\.exe")) |
| 44 | + .willReturn(aResponse() |
| 45 | + .withStatus(200) |
| 46 | + .withBody(DOWNLOAD_CONTENT))); |
| 47 | + stubFor(any(urlMatching("/obsidianmd/obsidian-releases/releases/download/v\\d+\\.\\d+\\.\\d+/Obsidian-.*\\.dmg")) |
| 48 | + .willReturn(aResponse() |
| 49 | + .withStatus(200) |
| 50 | + .withBody(DOWNLOAD_CONTENT))); |
| 51 | + stubFor(any(urlMatching("/obsidianmd/obsidian-releases/releases/download/v\\d+\\.\\d+\\.\\d+/obsidian_.*_amd64\\.deb")) |
| 52 | + .willReturn(aResponse() |
| 53 | + .withStatus(200) |
| 54 | + .withBody(DOWNLOAD_CONTENT))); |
| 55 | + stubFor(any(urlMatching("/obsidianmd/obsidian-releases/releases/download/v\\d+\\.\\d+\\.\\d+/obsidian-.*\\.tar\\.gz")) |
| 56 | + .willReturn(aResponse() |
| 57 | + .withStatus(200) |
| 58 | + .withBody(DOWNLOAD_CONTENT))); |
| 59 | + stubFor(any(urlMatching("/obsidianmd/obsidian-releases/releases/download/v\\d+\\.\\d+\\.\\d+/obsidian-.*-arm64\\.tar\\.gz")) |
| 60 | + .willReturn(aResponse() |
| 61 | + .withStatus(200) |
| 62 | + .withBody(DOWNLOAD_CONTENT))); |
| 63 | + |
| 64 | + UrlRepository urlRepository = UrlRepository.load(tempDir); |
| 65 | + ObsidianUrlUpdater updater = new ObsidianUrlUpdater(wmRuntimeInfo.getHttpBaseUrl(), wmRuntimeInfo.getHttpBaseUrl()); |
| 66 | + |
| 67 | + // act |
| 68 | + update(updater, urlRepository); |
| 69 | + |
| 70 | + // assert |
| 71 | + List<String> expectedPlatforms = List.of("windows_x64", "mac_x64", "linux_x64"); |
| 72 | + Path obsidianDir = tempDir.resolve("obsidian").resolve("obsidian"); |
| 73 | + assertUrlVersion(obsidianDir.resolve("1.9.10"), expectedPlatforms); |
| 74 | + assertUrlVersion(obsidianDir.resolve("1.10.6"), expectedPlatforms); |
| 75 | + assertUrlVersion(obsidianDir.resolve("1.11.7"), expectedPlatforms); |
| 76 | + assertUrlVersion(obsidianDir.resolve("1.12.7"), expectedPlatforms); |
| 77 | + } |
| 78 | +} |
0 commit comments