Skip to content

Commit

Permalink
devonfw#1024: added AwsGithubUrlUpdaterTest
Browse files Browse the repository at this point in the history
added test and resources
added getter of baseUrl to AwsUrlUpdater to be able to mock it
  • Loading branch information
jan-vcapgemini committed Feb 20, 2025
1 parent 0ace365 commit fa51e42
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
public class AwsUrlUpdater extends GithubUrlUpdater {

private static final String BASE_URL = "https://awscli.amazonaws.com/";

@Override
protected String getTool() {

Expand All @@ -27,6 +29,13 @@ protected String getGithubRepository() {
return "aws-cli";
}

/**
* @return the base url.
*/
protected String getBaseUrl() {
return BASE_URL;
}

@Override
protected String mapVersion(String version) {

Expand All @@ -52,7 +61,7 @@ protected String mapVersion(String version) {
@Override
protected void addVersion(UrlVersion urlVersion) {

String baseUrl = "https://awscli.amazonaws.com/";
String baseUrl = getBaseUrl();
boolean ok = doAddVersion(urlVersion, baseUrl + "AWSCLIV2-${version}.msi", OperatingSystem.WINDOWS);
if (!ok) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.devonfw.tools.ide.url.tool.aws;

import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;

/**
* Mock of {@link AwsUrlUpdater} to allow integration testing with wiremock.
*/
public class AwsGithubUrlUpdaterMock extends AwsUrlUpdater {

private final WireMockRuntimeInfo wmRuntimeInfo;

/**
* The constructor
*
* @param wmRuntimeInfo the {@link WireMockRuntimeInfo} holding the http url and port of the wiremock server.
*/
public AwsGithubUrlUpdaterMock(WireMockRuntimeInfo wmRuntimeInfo) {
this.wmRuntimeInfo = wmRuntimeInfo;
}

@Override
protected String getBaseUrl() {
return this.wmRuntimeInfo.getHttpBaseUrl() + "/download/";
}

@Override
protected String doGetVersionUrl() {

return this.wmRuntimeInfo.getHttpBaseUrl() + "/repos/" + getGithubOrganization() + "/" + getGithubRepository() + "/git/refs/tags";

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.devonfw.tools.ide.url.tool.aws;

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.any;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;

import com.devonfw.tools.ide.url.model.folder.UrlRepository;
import com.devonfw.tools.ide.url.tool.AbstractUrlUpdaterTest;
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
import com.github.tomakehurst.wiremock.junit5.WireMockTest;

/**
* Test class for integrations of the {@link AwsUrlUpdater}
*/
@WireMockTest
public class AwsGithubUrlUpdaterTest extends AbstractUrlUpdaterTest {

/**
* Test resource location
*/
private final static String TEST_DATA_ROOT = "src/test/resources/integrationtest/AwsGithubUrlUpdater";

/**
* Test of {@link JsonUrlUpdater} for the creation of {@link AwsUrlUpdater} download URLs and checksums.
*
* @param tempDir Path to a temporary directory
* @param wmRuntimeInfo the {@link WireMockRuntimeInfo}.
* @throws IOException test fails
*/
@Test
public void testAwsGithubUrlUpdater(@TempDir Path tempDir, WireMockRuntimeInfo wmRuntimeInfo) throws IOException {

stubFor(get(urlMatching("/repos/.*")).willReturn(aResponse().withStatus(200)
.withBody(Files.readAllBytes(Path.of(TEST_DATA_ROOT).resolve("github-tags.json")))));

stubFor(any(urlMatching("/download/.*")).willReturn(aResponse().withStatus(200).withBody("aBody")));

UrlRepository urlRepository = UrlRepository.load(tempDir);
AwsGithubUrlUpdaterMock updater = new AwsGithubUrlUpdaterMock(wmRuntimeInfo);

// when
updater.update(urlRepository);

assertThat(tempDir.resolve("aws").resolve("aws").resolve("2.7.22").resolve("status.json")).exists();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[
{
"ref": "refs/tags/2.7.22",
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjIy",
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.22",
"object": {
"sha": "9c35fe49b1d5620e0c1fa9de8e2dc129e983428e",
"type": "tag",
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/9c35fe49b1d5620e0c1fa9de8e2dc129e983428e"
}
},
{
"ref": "refs/tags/2.7.23",
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjIz",
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.23",
"object": {
"sha": "7a6d67fecfa29d433ff54f9600f84ef6b7537dcf",
"type": "tag",
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/7a6d67fecfa29d433ff54f9600f84ef6b7537dcf"
}
},
{
"ref": "refs/tags/2.7.24",
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjI0",
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.24",
"object": {
"sha": "544732f08cd7f8a725f62248189fcc8a14fb0253",
"type": "tag",
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/544732f08cd7f8a725f62248189fcc8a14fb0253"
}
}
]

0 comments on commit fa51e42

Please sign in to comment.