forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw#1024: added AwsGithubUrlUpdaterTest
added test and resources added getter of baseUrl to AwsUrlUpdater to be able to mock it
- Loading branch information
1 parent
0ace365
commit fa51e42
Showing
4 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
url-updater/src/test/java/com/devonfw/tools/ide/url/tool/aws/AwsGithubUrlUpdaterMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
url-updater/src/test/java/com/devonfw/tools/ide/url/tool/aws/AwsGithubUrlUpdaterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
url-updater/src/test/resources/integrationtest/AwsGithubUrlUpdater/github-tags.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] |