Skip to content

Commit fa51e42

Browse files
devonfw#1024: added AwsGithubUrlUpdaterTest
added test and resources added getter of baseUrl to AwsUrlUpdater to be able to mock it
1 parent 0ace365 commit fa51e42

File tree

4 files changed

+133
-1
lines changed

4 files changed

+133
-1
lines changed

Diff for: url-updater/src/main/java/com/devonfw/tools/ide/url/tool/aws/AwsUrlUpdater.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
public class AwsUrlUpdater extends GithubUrlUpdater {
1111

12+
private static final String BASE_URL = "https://awscli.amazonaws.com/";
13+
1214
@Override
1315
protected String getTool() {
1416

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

32+
/**
33+
* @return the base url.
34+
*/
35+
protected String getBaseUrl() {
36+
return BASE_URL;
37+
}
38+
3039
@Override
3140
protected String mapVersion(String version) {
3241

@@ -52,7 +61,7 @@ protected String mapVersion(String version) {
5261
@Override
5362
protected void addVersion(UrlVersion urlVersion) {
5463

55-
String baseUrl = "https://awscli.amazonaws.com/";
64+
String baseUrl = getBaseUrl();
5665
boolean ok = doAddVersion(urlVersion, baseUrl + "AWSCLIV2-${version}.msi", OperatingSystem.WINDOWS);
5766
if (!ok) {
5867
return;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.devonfw.tools.ide.url.tool.aws;
2+
3+
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
4+
5+
/**
6+
* Mock of {@link AwsUrlUpdater} to allow integration testing with wiremock.
7+
*/
8+
public class AwsGithubUrlUpdaterMock extends AwsUrlUpdater {
9+
10+
private final WireMockRuntimeInfo wmRuntimeInfo;
11+
12+
/**
13+
* The constructor
14+
*
15+
* @param wmRuntimeInfo the {@link WireMockRuntimeInfo} holding the http url and port of the wiremock server.
16+
*/
17+
public AwsGithubUrlUpdaterMock(WireMockRuntimeInfo wmRuntimeInfo) {
18+
this.wmRuntimeInfo = wmRuntimeInfo;
19+
}
20+
21+
@Override
22+
protected String getBaseUrl() {
23+
return this.wmRuntimeInfo.getHttpBaseUrl() + "/download/";
24+
}
25+
26+
@Override
27+
protected String doGetVersionUrl() {
28+
29+
return this.wmRuntimeInfo.getHttpBaseUrl() + "/repos/" + getGithubOrganization() + "/" + getGithubRepository() + "/git/refs/tags";
30+
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.devonfw.tools.ide.url.tool.aws;
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.Files;
11+
import java.nio.file.Path;
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.tool.AbstractUrlUpdaterTest;
18+
import com.devonfw.tools.ide.url.updater.JsonUrlUpdater;
19+
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
20+
import com.github.tomakehurst.wiremock.junit5.WireMockTest;
21+
22+
/**
23+
* Test class for integrations of the {@link AwsUrlUpdater}
24+
*/
25+
@WireMockTest
26+
public class AwsGithubUrlUpdaterTest extends AbstractUrlUpdaterTest {
27+
28+
/**
29+
* Test resource location
30+
*/
31+
private final static String TEST_DATA_ROOT = "src/test/resources/integrationtest/AwsGithubUrlUpdater";
32+
33+
/**
34+
* Test of {@link JsonUrlUpdater} for the creation of {@link AwsUrlUpdater} download URLs and checksums.
35+
*
36+
* @param tempDir Path to a temporary directory
37+
* @param wmRuntimeInfo the {@link WireMockRuntimeInfo}.
38+
* @throws IOException test fails
39+
*/
40+
@Test
41+
public void testAwsGithubUrlUpdater(@TempDir Path tempDir, WireMockRuntimeInfo wmRuntimeInfo) throws IOException {
42+
43+
stubFor(get(urlMatching("/repos/.*")).willReturn(aResponse().withStatus(200)
44+
.withBody(Files.readAllBytes(Path.of(TEST_DATA_ROOT).resolve("github-tags.json")))));
45+
46+
stubFor(any(urlMatching("/download/.*")).willReturn(aResponse().withStatus(200).withBody("aBody")));
47+
48+
UrlRepository urlRepository = UrlRepository.load(tempDir);
49+
AwsGithubUrlUpdaterMock updater = new AwsGithubUrlUpdaterMock(wmRuntimeInfo);
50+
51+
// when
52+
updater.update(urlRepository);
53+
54+
assertThat(tempDir.resolve("aws").resolve("aws").resolve("2.7.22").resolve("status.json")).exists();
55+
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[
2+
{
3+
"ref": "refs/tags/2.7.22",
4+
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjIy",
5+
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.22",
6+
"object": {
7+
"sha": "9c35fe49b1d5620e0c1fa9de8e2dc129e983428e",
8+
"type": "tag",
9+
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/9c35fe49b1d5620e0c1fa9de8e2dc129e983428e"
10+
}
11+
},
12+
{
13+
"ref": "refs/tags/2.7.23",
14+
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjIz",
15+
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.23",
16+
"object": {
17+
"sha": "7a6d67fecfa29d433ff54f9600f84ef6b7537dcf",
18+
"type": "tag",
19+
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/7a6d67fecfa29d433ff54f9600f84ef6b7537dcf"
20+
}
21+
},
22+
{
23+
"ref": "refs/tags/2.7.24",
24+
"node_id": "MDM6UmVmNjc4MDc2NzpyZWZzL3RhZ3MvMi43LjI0",
25+
"url": "https://api.github.com/repos/aws/aws-cli/git/refs/tags/2.7.24",
26+
"object": {
27+
"sha": "544732f08cd7f8a725f62248189fcc8a14fb0253",
28+
"type": "tag",
29+
"url": "https://api.github.com/repos/aws/aws-cli/git/tags/544732f08cd7f8a725f62248189fcc8a14fb0253"
30+
}
31+
}
32+
]

0 commit comments

Comments
 (0)