-
Notifications
You must be signed in to change notification settings - Fork 26
/
SingleModNLTRestProjectTestCommon.java
313 lines (269 loc) · 12.5 KB
/
SingleModNLTRestProjectTestCommon.java
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/*******************************************************************************
* Copyright (c) 2023, 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package io.openliberty.tools.intellij.it;
import com.automation.remarks.junit5.Video;
import com.intellij.remoterobot.RemoteRobot;
import io.openliberty.tools.intellij.it.fixtures.WelcomeFrameFixture;
import org.junit.jupiter.api.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.time.Duration;
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Holds common tests that use a single module non Liberty Tools compliant REST project.
*/
public abstract class SingleModNLTRestProjectTestCommon {
/**
* URL to display the UI Component hierarchy. This is used to obtain xPath related
* information to find UI components.
*/
public static final String REMOTE_BOT_URL = "http://localhost:8082";
/**
* The remote robot object.
*/
public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTE_BOT_URL);
/**
* The path to the folder containing helper test files.
*/
public String helperFilesPath = null;
/**
* The path to the folder containing the test projects.
*/
private String projectsPath = null;
/**
* Single module REST project that lacks the configuration to be recognized by Liberty tools.
*/
private String smNLTRestProjectName = null;
/**
* Build file name.
*/
private String buildFileName = null;
/**
* Processes actions before each test.
*
* @param info Test information.
*/
@BeforeEach
public void beforeEach(TestInfo info) {
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Entry");
}
/**
* Processes actions after each test.
*
* @param info Test information.
*/
@AfterEach
public void afterEach(TestInfo info) {
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Exit");
}
/**
* Cleanup.
*/
@AfterAll
public static void cleanup() {
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);
UIBotTestUtils.closeProjectView(remoteRobot);
UIBotTestUtils.closeProjectFrame(remoteRobot);
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
}
/**
* Returns the directory path containing helper files.
*
* @return The directory path containing helper files.
*/
public String getHelperFilesDirPath() {
return helperFilesPath;
}
public void setHelperFilesDirPath(String path) {
helperFilesPath = path;
}
/**
* Returns the projects directory path.
*
* @return The projects directory path.
*/
public String getProjectsDirPath() {
return projectsPath;
}
public void setProjectsDirPath(String path) {
projectsPath = path;
}
/**
* Returns the name of the single module REST project that does not meet
* the requirements needed to automatically show in the Liberty tool window.
* This project's Liberty config file does not the expected name and the
* build file does not have any Liberty plugin related entries.
*
* @return The name of the single module REST project that does not meet the
* requirements needed to automatically show in the Liberty tool window.
*/
public String getSmNLTRestProjectName() {
return smNLTRestProjectName;
}
public void setSmNLTRestProjectName(String name) {
smNLTRestProjectName = name;
}
/**
* Returns the name of the build file used by the project.
*
* @return The name of the build file used by the project.
*/
public String getBuildFileName() {
return buildFileName;
}
public void setBuildFileName(String name) {
buildFileName = name;
}
/**
* Tests manually Adding/Removing project from the tool window using the Liberty add/remove
* options available through search everywhere panel.
*/
@Test
@Video
public void testManualProjectAddRemoveActionUsingSearch() {
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
// Add the project to the Liberty tool window.
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Liberty: Add project to the tool window", 3);
// Select project from the 'Add Liberty project' dialog.
UIBotTestUtils.selectProjectFromAddLibertyProjectDialog(remoteRobot, getSmNLTRestProjectName());
try {
// Validate that the project is displayed in the Liberty tool window.
UIBotTestUtils.findProjectInLibertyToolWindow(remoteRobot, getSmNLTRestProjectName(), "10");
} finally {
// Remove the project from the Liberty tool window.
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Liberty: Remove project from the tool window", 3);
// Select project from the 'Remote Liberty project' dialog.
UIBotTestUtils.selectProjectFromRemoveLibertyProjectDialog(remoteRobot, getSmNLTRestProjectName());
// Answer the 'Remove Liberty project' dialog in the affirmative.
UIBotTestUtils.respondToRemoveProjectQueryDialog(remoteRobot);
// Refresh the Liberty tool window using the refresh icon on the toolbar.
UIBotTestUtils.refreshLibertyToolWindow(remoteRobot);
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
}
}
/**
* Tests:
* - Refresh button on Liberty tool window toolbar.
* - Detecting a project with a src/main/liberty/config/server.xml file only.
*/
@Test
@Video
public void testsRefreshProjectWithServerXmlOnly() {
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
// Copy a valid server.xml file to this project's src/main/liberty/config directory.
Path validServerXml = Paths.get(getHelperFilesDirPath(), "server.xml");
Path destination = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), "src", "main", "liberty", "config", "server.xml");
try {
Files.copy(validServerXml, destination, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
fail("Unable to copy " + validServerXml + " to " + destination + ".", e);
}
// Refresh the Liberty tool window using the refresh icon on the toolbar.
UIBotTestUtils.refreshLibertyToolWindow(remoteRobot);
// Validate that the project is displayed in the Liberty tool window.
try {
UIBotTestUtils.findProjectInLibertyToolWindow(remoteRobot, getSmNLTRestProjectName(), "10");
} finally {
// Remove the previously added server.xml file.
if (!TestUtils.deleteFile(destination)) {
fail("Unable to delete " + destination);
}
// Refresh the Liberty tool window using the refresh icon on the toolbar.
UIBotTestUtils.refreshLibertyToolWindow(remoteRobot);
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
}
}
/**
* Tests:
* - Refresh button on Liberty tool window toolbar.
* - Detecting a project with a valid Liberty M/G plugin configuration in build file only.
* The build file in this case uses a buildscript block to customize the version and the
* location of the Liberty Tools binary dependency.
*/
@Test
@Video
public void testsRefreshProjectWithLTBuildCfgOnlyWithBldScriptBlock() {
testsRefreshProjectWithLTBuildCfgOnly(getBuildFileName());
}
/**
* Tests:
* - Refresh button on Liberty tool window toolbar.
* - Detecting a project with a valid Liberty M/G plugin configuration in build file only.
*/
public void testsRefreshProjectWithLTBuildCfgOnly(String buildFile) {
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
// Replace the current build file with the file containing Liberty plugin config.
Path newCfg = Paths.get(getHelperFilesDirPath(), buildFile);
Path originalCfg = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), getBuildFileName());
Path backupCfg = Paths.get(getProjectsDirPath(), getSmNLTRestProjectName(), getBuildFileName() + ".bak");
try {
Files.copy(originalCfg, backupCfg, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
fail("Unable to backup " + originalCfg + " to " + backupCfg + ".", e);
}
try {
Files.copy(newCfg, originalCfg, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
fail("Unable to copy " + newCfg + " to " + originalCfg + ".", e);
}
// User the refresh icon on the Liberty tool window.
UIBotTestUtils.refreshLibertyToolWindow(remoteRobot);
try {
// Validate that the project is displayed in the Liberty tool window.
UIBotTestUtils.findProjectInLibertyToolWindow(remoteRobot, getSmNLTRestProjectName(), "10");
} finally {
// Replace the current build file with the backup file.
try {
Files.copy(backupCfg, originalCfg, StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
} catch (Exception e) {
fail("Unable to copy " + backupCfg + " to " + originalCfg + ".", e);
}
// Delete the backup file.
if (!TestUtils.deleteFile(backupCfg)) {
fail("Unable to delete " + backupCfg);
}
// Refresh the Liberty tool window using the refresh icon on the toolbar.
UIBotTestUtils.refreshLibertyToolWindow(remoteRobot);
// Validate that the Liberty tool window project tree is not showing. No projects are expected.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 10);
}
}
/**
* Prepares the environment to run the tests.
*
* @param projectPath The path of the project.
* @param projectName The name of the project being used.
*/
public static void prepareEnv(String projectPath, String projectName) {
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO,
"prepareEnv. Entry. ProjectPath: " + projectPath + ". ProjectName: " + projectName);
waitForIgnoringError(Duration.ofMinutes(4), Duration.ofSeconds(5), "Wait for IDE to start", "IDE did not start", () -> remoteRobot.callJs("true"));
remoteRobot.find(WelcomeFrameFixture.class, Duration.ofMinutes(2));
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
UIBotTestUtils.openProjectView(remoteRobot);
// IntelliJ does not start building and indexing until the Project View is open
UIBotTestUtils.waitForIndexing(remoteRobot);
UIBotTestUtils.openLibertyToolWindow(remoteRobot);
// Wait for indexing to complete. Once indexing completes and Liberty Tools to take control
// of the window, it will display the project it detected, or a message stating that no
// projects were detected. A message stating that no projects were detected is what is expected here.
UIBotTestUtils.waitForLTWNoProjectDetectedMsg(remoteRobot, 300);
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO,
"prepareEnv. Exit. ProjectName: " + projectName);
}
}