-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
154 additions
and
4 deletions.
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
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
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
95 changes: 95 additions & 0 deletions
95
cli/src/test/java/com/devonfw/tools/ide/tool/mvn/MvnTest.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,95 @@ | ||
package com.devonfw.tools.ide.tool.mvn; | ||
|
||
import com.devonfw.tools.ide.commandlet.InstallCommandlet; | ||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeTestContext; | ||
import com.devonfw.tools.ide.log.IdeLogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Integration test of {@link Mvn}. | ||
*/ | ||
public class MvnTest extends AbstractIdeContextTest { | ||
|
||
private static final String PROJECT_MVN = "mvn"; | ||
|
||
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\[(.*?)\\]"); | ||
|
||
/** | ||
* Tests the installation of {@link Mvn} | ||
* | ||
* @throws IOException if an I/O error occurs during the installation process | ||
*/ | ||
@Test | ||
public void testMvnInstall() throws IOException { | ||
|
||
// arrange | ||
IdeTestContext context = newContext(PROJECT_MVN); | ||
context.setInputValues(List.of("testLogin", "testPassword")); | ||
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class); | ||
install.tool.setValueAsString("mvn", context); | ||
|
||
// act | ||
install.run(); | ||
|
||
// assert | ||
checkInstallation(context); | ||
} | ||
|
||
/** | ||
* Tests the execution of {@link Mvn} | ||
* | ||
* @throws IOException if an I/O error occurs during the installation process | ||
*/ | ||
@Test | ||
public void testMvnRun() throws IOException { | ||
// arrange | ||
IdeTestContext context = newContext(PROJECT_MVN); | ||
context.setInputValues(List.of("testLogin", "testPassword")); | ||
InstallCommandlet install = context.getCommandletManager().getCommandlet(InstallCommandlet.class); | ||
install.tool.setValueAsString("mvn", context); | ||
Mvn commandlet = (Mvn) install.tool.getValue(); | ||
commandlet.arguments.addValue("foo"); | ||
commandlet.arguments.addValue("bar"); | ||
|
||
// act | ||
commandlet.run(); | ||
|
||
// assert | ||
assertLogMessage(context, IdeLogLevel.INFO, "mvn " + "foo bar"); | ||
checkInstallation(context); | ||
} | ||
|
||
private void checkInstallation(IdeTestContext context) throws IOException { | ||
|
||
assertThat(context.getSoftwarePath().resolve("java/bin/java")).exists(); | ||
|
||
assertThat(context.getSoftwarePath().resolve("mvn/.ide.software.version")).exists().hasContent("3.9.7"); | ||
assertLogMessage(context, IdeLogLevel.SUCCESS, "Successfully installed mvn in version 3.9.7"); | ||
|
||
Path settingsFile = context.getConfPath().resolve(Mvn.MVN_CONFIG_FOLDER).resolve(Mvn.SETTINGS_FILE); | ||
assertThat(settingsFile).exists(); | ||
assertFileContent(settingsFile, List.of("testLogin", "testPassword")); | ||
|
||
Path settingsSecurityFile = context.getConfPath().resolve(Mvn.MVN_CONFIG_FOLDER).resolve(Mvn.SETTINGS_SECURITY_FILE); | ||
assertThat(settingsSecurityFile).exists(); | ||
assertFileContent(settingsSecurityFile, List.of("masterPassword")); | ||
} | ||
|
||
private void assertFileContent(Path filePath, List<String> expectedValues) throws IOException { | ||
|
||
String content = new String(Files.readAllBytes(filePath)); | ||
Matcher matcher = VARIABLE_PATTERN.matcher(content); | ||
List<String> values = matcher.results().map(matchResult -> matchResult.group(1)).collect(Collectors.toList()); | ||
|
||
assertThat(values).containsExactlyElementsOf(expectedValues); | ||
} | ||
} |
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 @@ | ||
this is the download metadata |
Empty file.
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 @@ | ||
this is the users HOME directory |
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 @@ | ||
this is the IDE_HOME directory |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/mvn/project/settings/ide.properties
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,2 @@ | ||
JAVA_VERSION=17.0.10_7 | ||
MVN_VERSION=3.9.7 |
13 changes: 13 additions & 0 deletions
13
cli/src/test/resources/ide-projects/mvn/project/settings/templates/conf/mvn/settings.xml
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,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<settings> | ||
<localRepository>${env.M2_REPO}</localRepository> | ||
|
||
<servers> | ||
<server> | ||
<id>repository</id> | ||
<username>$[login]</username> | ||
<password>$[password]</password> | ||
</server> | ||
</servers> | ||
|
||
</settings> |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/mvn/project/workspaces/main/readme
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 @@ | ||
this is the main workspace of jmc test case |
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 @@ | ||
this is the IDE_ROOT directory |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/mvn/repository/java/java/default/bin/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,2 @@ | ||
#!/bin/bash | ||
echo "java mvn" |
9 changes: 9 additions & 0 deletions
9
cli/src/test/resources/ide-projects/mvn/repository/mvn/mvn/default/bin/mvn
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,9 @@ | ||
#!/bin/bash | ||
|
||
if [ "$1" == "--encrypt-master-password" ]; then | ||
echo "masterPassword" | ||
elif [ "$1" == "--encrypt-password" ]; then | ||
echo "$2" | ||
else | ||
echo "mvn $*" | ||
fi |