forked from devonfw/IDEasy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUninstallCommandletTest.java
More file actions
171 lines (149 loc) · 7.31 KB
/
UninstallCommandletTest.java
File metadata and controls
171 lines (149 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.devonfw.tools.ide.commandlet;
import java.nio.file.Files;
import java.nio.file.Path;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.log.IdeLogEntry;
import com.devonfw.tools.ide.os.SystemInfo;
import com.devonfw.tools.ide.os.SystemInfoMock;
import com.devonfw.tools.ide.os.WindowsHelper;
import com.devonfw.tools.ide.property.ToolProperty;
import com.devonfw.tools.ide.tool.az.Azure;
import com.devonfw.tools.ide.tool.dotnet.DotNet;
import com.devonfw.tools.ide.tool.eclipse.Eclipse;
import com.devonfw.tools.ide.tool.npm.Npm;
import com.devonfw.tools.ide.variable.IdeVariables;
/**
* Integration test of {@link UninstallCommandlet}.
*/
public class UninstallCommandletTest extends AbstractIdeContextTest {
private static final String PROJECT = "edition-version-get-uninstall";
/**
* Mocks the installation of a tool, since forceUninstall depends on symlinks which are not distributed with git
*
* @param context the {@link IdeContext} to use.
* @param tool the tool to mock installation of.
*/
private static void mockInstallTool(IdeTestContext context, String tool) {
Path pathToInstallationOfDummyTool = context.getSoftwareRepositoryPath()
.resolve(context.getDefaultToolRepository().getId()).resolve(tool).resolve(tool).resolve("testVersion");
Path pathToLinkedSoftware = context.getSoftwarePath().resolve(tool);
context.getFileAccess().symlink(pathToInstallationOfDummyTool, pathToLinkedSoftware);
}
/**
* Test of {@link UninstallCommandlet} run.
*/
@Test
public void testUninstallNpmAndDontButDotNetNotInstalled() {
// arrange
String npm = "npm";
String dotnet = "dotnet";
IdeTestContext context = newContext(PROJECT_BASIC);
CommandletManager commandletManager = context.getCommandletManager();
UninstallCommandlet uninstallCommandlet = commandletManager.getCommandlet(UninstallCommandlet.class);
Npm npmCommandlet = commandletManager.getCommandlet(Npm.class);
DotNet dotnetCommandlet = commandletManager.getCommandlet(DotNet.class);
ToolProperty tools = uninstallCommandlet.tools;
tools.addValue(npmCommandlet);
tools.addValue(dotnetCommandlet);
// act
uninstallCommandlet.run();
// assert
assertThat(context).log().hasEntries(IdeLogEntry.ofSuccess("Successfully uninstalled " + npm),
IdeLogEntry.ofWarning("Couldn't uninstall " + dotnet + " because we could not find an installation"));
assertThat(context.getSoftwarePath().resolve(npm)).doesNotExist();
}
@Test
public void testUninstallEclipseFailsWhenNotInstalled() {
// arrange
String eclipse = "eclipse";
IdeTestContext context = newContext(PROJECT_BASIC);
CommandletManager commandletManager = context.getCommandletManager();
UninstallCommandlet uninstallCommandlet = commandletManager.getCommandlet(UninstallCommandlet.class);
Eclipse eclipseCommandlet = commandletManager.getCommandlet(Eclipse.class);
uninstallCommandlet.tools.addValue(eclipseCommandlet);
// act
uninstallCommandlet.run();
// assert
assertThat(context).logAtWarning().hasMessage("Couldn't uninstall " + eclipse + " because we could not find an installation");
assertThat(Files.notExists(context.getSoftwarePath().resolve(eclipse)));
}
@Test
public void testUninstallNpm() {
// arrange
IdeTestContext context = newContext(PROJECT_BASIC);
CommandletManager commandletManager = context.getCommandletManager();
UninstallCommandlet uninstallCommandlet = commandletManager.getCommandlet(UninstallCommandlet.class);
Npm npmCommandlet = commandletManager.getCommandlet(Npm.class);
uninstallCommandlet.tools.addValue(npmCommandlet);
// act
uninstallCommandlet.run();
//assert
assertThat(context).log().hasEntries(IdeLogEntry.ofSuccess("Successfully uninstalled npm"));
}
/** Test of {@link UninstallCommandlet} run with --force. */
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testForceUninstallAzure(String os) {
// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
String tool = "az";
IdeTestContext context = newContext(PROJECT, null, true);
context.setSystemInfo(systemInfo);
mockInstallTool(context, tool);
CommandletManager commandletManager = context.getCommandletManager();
UninstallCommandlet uninstallCommandlet = commandletManager.getCommandlet(UninstallCommandlet.class);
Azure azureCommandlet = commandletManager.getCommandlet(Azure.class);
uninstallCommandlet.tools.addValue(azureCommandlet);
uninstallCommandlet.tools.setValueAsString(tool, context);
context.getStartContext().setForceMode(true);
// act
uninstallCommandlet.run();
// assert
assertThat(context).log()
.hasEntries(IdeLogEntry.ofSuccess("Successfully deleted " + context.getSoftwareRepositoryPath()
.resolve(context.getDefaultToolRepository().getId()).resolve(tool).resolve(tool).resolve("testVersion") + " from your computer."));
assertThat(context).log().hasEntries(IdeLogEntry.ofSuccess("Successfully uninstalled " + tool));
assertThat(context.getSoftwareRepositoryPath()
.resolve(context.getDefaultToolRepository().getId()).resolve(tool).resolve(tool).resolve("testVersion")).doesNotExist();
}
/** Test {@link UninstallCommandlet} without arguments uninstalls IDEasy. */
@ParameterizedTest
@ValueSource(strings = { "windows", "mac", "linux" })
public void testUninstallIdeasy(String os) {
// arrange
SystemInfo systemInfo = SystemInfoMock.of(os);
IdeTestContext context = newContext("uninstall");
context.setSystemInfo(systemInfo);
CommandletManager commandletManager = context.getCommandletManager();
UninstallCommandlet uninstallCommandlet = commandletManager.getCommandlet(UninstallCommandlet.class);
context.getStartContext().setForceMode(true);
WindowsHelper helper = context.getWindowsHelper();
String originalPath = helper.getUserEnvironmentValue(IdeVariables.PATH.getName());
if (systemInfo.isWindows()) {
helper.setUserEnvironmentValue(IdeVariables.PATH.getName(), "C:\\projects\\_ide\\installation\\bin;" + originalPath);
}
// act
uninstallCommandlet.run();
// assert
assertThat(context.getIdePath()).doesNotExist();
assertThat(context.getUserHome().resolve(".bashrc")).hasContent("#already exists\n"
+ "alias devon=\"source ~/.devon/devon\"\n"
+ "devon\n"
+ "source ~/.devon/autocomplete\n");
assertThat(context.getUserHome().resolve(".zshrc")).hasContent("#already exists\n"
+ "autoload -U +X bashcompinit && bashcompinit\n"
+ "alias devon=\"source ~/.devon/devon\"\n"
+ "devon\n"
+ "source ~/.devon/autocomplete\n");
if (systemInfo.isWindows()) {
assertThat(helper.getUserEnvironmentValue("IDE_ROOT")).isNull();
assertThat(helper.getUserEnvironmentValue("PATH")).isEqualTo(
"C:\\Users\\testuser\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\testuser\\scoop\\apps\\python\\current\\Scripts;C:\\Users\\testuser\\scoop\\apps\\python\\current;C:\\Users\\testuser\\scoop\\shims");
}
}
}