-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
bae97bc
commit b1493b6
Showing
10 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
cli/src/test/java/com/devonfw/tools/ide/commandlet/InstallCommandletTest.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,112 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
|
||
/** | ||
* Integration test of {@link InstallCommandlet}. | ||
*/ | ||
|
||
public class InstallCommandletTest extends AbstractIdeContextTest { | ||
|
||
private static WireMockServer server; | ||
|
||
private static Path resourcePath = Paths.get("src/test/resources"); | ||
|
||
@BeforeAll | ||
static void setUp() throws IOException { | ||
|
||
server = new WireMockServer(WireMockConfiguration.wireMockConfig().port(1111)); | ||
server.start(); | ||
} | ||
|
||
@AfterAll | ||
static void tearDown() throws IOException { | ||
|
||
server.shutdownServer(); | ||
} | ||
|
||
private void mockWebServer() throws IOException { | ||
|
||
Path windowsFilePath = resourcePath.resolve("__files").resolve("java-17.0.6-windows-x64.zip"); | ||
String windowsLength = String.valueOf(Files.size(windowsFilePath)); | ||
server.stubFor( | ||
get(urlPathEqualTo("/installTest/windows")).willReturn(aResponse().withHeader("Content-Type", "application/zip") | ||
.withHeader("Content-Length", windowsLength).withStatus(200).withBodyFile("java-17.0.6-windows-x64.zip"))); | ||
|
||
Path linuxFilePath = resourcePath.resolve("__files").resolve("java-17.0.6-linux-x64.tgz"); | ||
String linuxLength = String.valueOf(Files.size(linuxFilePath)); | ||
server.stubFor( | ||
get(urlPathEqualTo("/installTest/linux")).willReturn(aResponse().withHeader("Content-Type", "application/tgz") | ||
.withHeader("Content-Length", linuxLength).withStatus(200).withBodyFile("java-17.0.6-linux-x64.tgz"))); | ||
|
||
server.stubFor( | ||
get(urlPathEqualTo("/installTest/macOS")).willReturn(aResponse().withHeader("Content-Type", "application/tgz") | ||
.withHeader("Content-Length", linuxLength).withStatus(200).withBodyFile("java-17.0.6-linux-x64.tgz"))); | ||
} | ||
|
||
/** | ||
* Test of {@link InstallCommandlet} run, when Installed Version is null. | ||
*/ | ||
@Test | ||
public void testInstallCommandletRunWithVersion() throws IOException { | ||
|
||
// arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, true); | ||
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class); | ||
install.tool.setValueAsString("java"); | ||
mockWebServer(); | ||
// act | ||
install.run(); | ||
// assert | ||
assertTestInstall(context); | ||
} | ||
|
||
/** | ||
* Test of {@link InstallCommandlet} run, when Installed Version is set. | ||
*/ | ||
@Test | ||
public void testInstallCommandletRunWithVersionAndVersionIdentifier() throws IOException { | ||
|
||
// arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, true); | ||
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class); | ||
install.tool.setValueAsString("java"); | ||
install.version.setValueAsString("17.0.6"); | ||
mockWebServer(); | ||
|
||
// act | ||
install.run(); | ||
// assert | ||
assertTestInstall(context); | ||
} | ||
|
||
private void assertTestInstall(IdeContext context) { | ||
|
||
assertThat(context.getSoftwarePath().resolve("java")).exists(); | ||
assertThat(context.getSoftwarePath().resolve("java/InstallTest.txt")).hasContent("This is a test file."); | ||
assertThat(context.getSoftwarePath().resolve("java/bin/HelloWorld.txt")).hasContent("Hello World!"); | ||
if(context.getSystemInfo().isWindows()){ | ||
assertThat(context.getSoftwarePath().resolve("java/bin/java.cmd")).exists(); | ||
} else if (context.getSystemInfo().isLinux() || context.getSystemInfo().isMac()) { | ||
assertThat(context.getSoftwarePath().resolve("java/bin/java")).exists(); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/linux_x64.sha256
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 @@ | ||
c2de7dfbd9f8faaa21b4cdd8518f826dd558c9ab24a0616b3ed28437a674a97b |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/linux_x64.urls
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 @@ | ||
http://localhost:1111/installTest/linux |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/mac_x64.sha256
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 @@ | ||
c2de7dfbd9f8faaa21b4cdd8518f826dd558c9ab24a0616b3ed28437a674a97b |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/mac_x64.urls
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 @@ | ||
http://localhost:1111/installTest/macOS |
20 changes: 20 additions & 0 deletions
20
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/status.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,20 @@ | ||
{ | ||
"manual" : true, | ||
"urls" : { | ||
"-680270697" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T16:27:32.819394600Z" | ||
} | ||
}, | ||
"-896197542" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T16:27:47.658175400Z" | ||
} | ||
}, | ||
"-310367019" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T16:28:02.221367500Z" | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/windows_x64.urls
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 @@ | ||
http://localhost:1111/installTest/windows |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/_ide/urls/java/java/17.0.6/windows_x64.urls.sha256
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 @@ | ||
aa64bee5f7ba56fbbd60d766f3a652600f81571ae5e996804694c69bf731af8b |