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#5: added Tests for Help and Version Commandlets (devonfw#73)
- Loading branch information
1 parent
071f82c
commit 754f7e8
Showing
10 changed files
with
238 additions
and
3 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
89 changes: 89 additions & 0 deletions
89
cli/src/test/java/com/devonfw/tools/ide/commandlet/HelpCommandletTest.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,89 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.context.IdeTestContextMock; | ||
import com.devonfw.tools.ide.log.IdeLogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* Integration test of {@link HelpCommandlet}. | ||
*/ | ||
public class HelpCommandletTest extends AbstractIdeContextTest { | ||
|
||
/** | ||
* Test of {@link HelpCommandlet} does not require home. | ||
*/ | ||
@Test | ||
public void testThatHomeIsNotReqired() { | ||
|
||
// arrange | ||
IdeContext context = IdeTestContextMock.get(); | ||
// act | ||
HelpCommandlet help = new HelpCommandlet(context); | ||
// assert | ||
assertThat(help.isIdeHomeRequired()).isEqualTo(false); | ||
} | ||
|
||
/** | ||
* Test of {@link HelpCommandlet} run. | ||
*/ | ||
@Test | ||
public void testRun() { | ||
|
||
// arrange | ||
IdeContext context = IdeTestContextMock.get(); | ||
HelpCommandlet help = new HelpCommandlet(context); | ||
// act | ||
help.run(); | ||
// assert | ||
assertLogoMessage(context); | ||
assertLogMessage(context, IdeLogLevel.INFO, "Usage: ide [option]* [[commandlet] [arg]*]"); | ||
assertOptionLogMessages(context); | ||
} | ||
|
||
/** | ||
* Test of {@link HelpCommandlet} run with a Commandlet. | ||
*/ | ||
@Test | ||
public void testRunWithCommandlet() { | ||
|
||
// arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, true); | ||
HelpCommandlet help = context.getCommandletManager().getCommandlet(HelpCommandlet.class); | ||
help.commandlet.setValueAsString("mvn"); | ||
// act | ||
help.run(); | ||
// assert | ||
assertLogoMessage(context); | ||
assertLogMessage(context, IdeLogLevel.INFO, "Usage: ide [option]* mvn [<args>*]"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "Tool commandlet for Maven (Build-Tool)"); | ||
assertOptionLogMessages(context); | ||
} | ||
|
||
/** | ||
* Assertion for the options that should be displayed. | ||
*/ | ||
public void assertOptionLogMessages(IdeContext context) { | ||
|
||
assertLogMessage(context, IdeLogLevel.INFO, "--locale the locale (e.g. 'de' for German language)"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "-b | --batch enable batch mode (non-interactive)"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "-d | --debug enable debug logging"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "-f | --force enable force mode"); | ||
assertLogMessage(context, IdeLogLevel.INFO, | ||
"-o | --offline enable offline mode (skip updates or git pull, fail downloads or git clone)"); | ||
assertLogMessage(context, IdeLogLevel.INFO, | ||
"-q | --quiet disable info logging (only log success, warning or error)"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "-t | --trace enable trace logging"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "-v | --version Print the IDE version and exit."); | ||
} | ||
|
||
/** | ||
* Assertion for the IDE-Logo that should be displayed. | ||
*/ | ||
public void assertLogoMessage(IdeContext context) { | ||
|
||
assertLogMessage(context, IdeLogLevel.INFO, HelpCommandlet.LOGO); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionGetCommandletTest.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,51 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.cli.CliException; | ||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.log.IdeLogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
/** | ||
* Integration test of {@link VersionGetCommandlet}. | ||
*/ | ||
public class VersionGetCommandletTest extends AbstractIdeContextTest{ | ||
|
||
/** | ||
* Test of {@link VersionGetCommandlet} run, when Installed Version is null. | ||
*/ | ||
@Test | ||
public void testVersionGetCommandletRunThrowsCliExeption(){ | ||
// arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, false); | ||
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); | ||
versionGet.tool.setValueAsString("java"); | ||
// act | ||
try { | ||
versionGet.run(); | ||
failBecauseExceptionWasNotThrown(CliException.class); | ||
} catch (CliException e) { | ||
//assert | ||
assertThat(e).hasMessageContaining("Tool java is not installed!"); | ||
} | ||
} | ||
|
||
/** | ||
* Test of {@link VersionGetCommandlet} run. | ||
*/ | ||
@Test | ||
public void testVersionGetCommandletRun(){ | ||
//arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, false); | ||
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class); | ||
//act | ||
versionGet.tool.setValueAsString("mvn"); | ||
versionGet.run(); | ||
//assert | ||
assertLogMessage(context, IdeLogLevel.INFO, "3.9.4"); | ||
} | ||
} | ||
|
32 changes: 32 additions & 0 deletions
32
cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionListCommandletTest.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,32 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.context.IdeTestContextMock; | ||
import com.devonfw.tools.ide.log.IdeLogLevel; | ||
import org.junit.jupiter.api.Test; | ||
|
||
|
||
/** | ||
* Integration test of {@link VersionListCommandlet}. | ||
*/ | ||
public class VersionListCommandletTest extends AbstractIdeContextTest { | ||
|
||
/** | ||
* Test of {@link VersionListCommandlet} run. | ||
*/ | ||
@Test | ||
public void testVersionListCommandletRun() { | ||
//arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, false); | ||
VersionListCommandlet versionList = context.getCommandletManager().getCommandlet(VersionListCommandlet.class); | ||
versionList.tool.setValueAsString("mvn"); | ||
//act | ||
versionList.run(); | ||
//assert | ||
assertLogMessage(context, IdeLogLevel.INFO, "3.0.5"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "3.1.0"); | ||
assertLogMessage(context, IdeLogLevel.INFO, "3.2.1"); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
cli/src/test/java/com/devonfw/tools/ide/commandlet/VersionSetCommandletTest.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,32 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
/** | ||
* Integration test of {@link VersionSetCommandlet}. | ||
*/ | ||
public class VersionSetCommandletTest extends AbstractIdeContextTest { | ||
|
||
/** | ||
* Test of {@link VersionSetCommandlet} run. | ||
* @throws IOException on error. | ||
*/ | ||
@Test | ||
public void testVersionSetCommandletRun() throws IOException { | ||
//arrange | ||
String path = "workspaces/foo-test/my-git-repo"; | ||
IdeContext context = newContext("basic", path, true); | ||
VersionSetCommandlet versionSet = context.getCommandletManager().getCommandlet(VersionSetCommandlet.class); | ||
versionSet.tool.setValueAsString("mvn"); | ||
versionSet.version.setValueAsString("3.1.0"); | ||
//act | ||
versionSet.run(); | ||
//assert | ||
assertThat(Files.readAllLines(context.getSettingsPath().resolve("ide.properties"))).contains("MVN_VERSION=3.1.0"); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
cli/src/test/resources/ide-projects/_ide/urls/mvn/mvn/3.0.5/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,10 @@ | ||
{ | ||
"manual" : false, | ||
"urls" : { | ||
"-997329125" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T07:12:26.601818Z" | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
cli/src/test/resources/ide-projects/_ide/urls/mvn/mvn/3.1.0/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,10 @@ | ||
{ | ||
"manual" : false, | ||
"urls" : { | ||
"-997329125" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T07:12:26.601818Z" | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
cli/src/test/resources/ide-projects/_ide/urls/mvn/mvn/3.2.1/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,10 @@ | ||
|
||
"manual" : false, | ||
"urls" : { | ||
"-997329125" : { | ||
"success" : { | ||
"timestamp" : "2023-04-28T07:12:26.601818Z" | ||
} | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
cli/src/test/resources/ide-projects/basic/software/mvn/.devon.software.version
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 @@ | ||
3.9.4 |