Skip to content

Commit a560e65

Browse files
authored
Create a new test case for Run/Debug Configurations (#1239)
* Check if no Liberty projects are detected in workspace when creating a Run/Debug config * Update comments to clarify meaning of class variables * Add new test case to create new run config for issue 1202 * Update the comments for code review * Use new util method * Fix comment Signed-off-by: Paul Gooderham <[email protected]>
1 parent 1be47ee commit a560e65

File tree

5 files changed

+383
-2
lines changed

5 files changed

+383
-2
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package io.openliberty.tools.intellij.it;
11+
12+
import org.junit.jupiter.api.AfterAll;
13+
import org.junit.jupiter.api.Assertions;
14+
import org.junit.jupiter.api.BeforeAll;
15+
16+
import java.io.IOException;
17+
import java.nio.file.Files;
18+
import java.nio.file.Path;
19+
import java.nio.file.Paths;
20+
import java.nio.file.StandardCopyOption;
21+
22+
/**
23+
* Test Liberty Tools creation of a Run/Debug configuration without a null pointer exception
24+
* using a single module MicroProfile Gradle project.
25+
*/
26+
public class GradleSingleModMPCfgProjectTest extends SingleModMPProjectCfgTestCommon {
27+
28+
/**
29+
* Single module Microprofile project name specified in file settings.gradle.
30+
*/
31+
private static final String SM_MP_PROJECT_NAME = "singleModGradleMP";
32+
33+
/**
34+
* Project name of Microprofile single module in file settings-copy.gradle.
35+
*/
36+
private static final String SM_MP_PROJECT_NAME_NEW = "singleMod GradleMP";
37+
38+
/**
39+
* The path to the folder containing the test projects.
40+
*/
41+
private static final String PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "gradle").toAbsolutePath().toString();
42+
43+
/**
44+
* The path to the folder containing the copy of the test project.
45+
*/
46+
private static final String PROJECTS_PATH_NEW = Paths.get("src", "test", "resources", "projects", "gsample2").toAbsolutePath().toString();
47+
48+
/**
49+
* Prepares the environment for test execution.
50+
*/
51+
@BeforeAll
52+
public static void setup() {
53+
try {
54+
// Copy the directory to allow renaming.
55+
TestUtils.copyDirectory(PROJECTS_PATH, PROJECTS_PATH_NEW);
56+
57+
Path pathNew = Path.of(PROJECTS_PATH_NEW);
58+
Path projectDirPath = pathNew.resolve(SM_MP_PROJECT_NAME);
59+
60+
// Define paths for the original and copy of settings.gradle
61+
Path originalPath = projectDirPath.resolve("settings.gradle");
62+
Path originalPathCopy = projectDirPath.resolve("settings-copy.gradle");
63+
64+
// Rename settings.gradle to settings-duplicate.gradle
65+
Files.move(originalPath, originalPath.resolveSibling("settings-duplicate.gradle"));
66+
// Rename settings-copy.gradle to settings.gradle
67+
Files.move(originalPathCopy, originalPathCopy.resolveSibling("settings.gradle"));
68+
69+
Path projectDirNewPath = pathNew.resolve(SM_MP_PROJECT_NAME_NEW);
70+
71+
// Rename the project directory to a new name, replacing it if it already exists
72+
Files.move(projectDirPath, projectDirNewPath, StandardCopyOption.REPLACE_EXISTING);
73+
74+
// Prepare the environment with the new project path and name
75+
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME_NEW);
76+
77+
} catch (IOException e) {
78+
System.err.println("Setup failed: " + e.getMessage());
79+
e.printStackTrace();
80+
Assertions.fail("Test setup failed due to an IOException: " + e.getMessage());
81+
}
82+
}
83+
84+
/**
85+
* Cleanup includes deleting the created project path.
86+
*/
87+
@AfterAll
88+
public static void cleanup() {
89+
try {
90+
closeProjectView();
91+
} finally {
92+
deleteDirectoryIfExists(PROJECTS_PATH_NEW);
93+
}
94+
}
95+
96+
GradleSingleModMPCfgProjectTest() {
97+
// set the new locations for the test, not the original locations
98+
setProjectsDirPath(PROJECTS_PATH_NEW);
99+
setSmMPProjectName(SM_MP_PROJECT_NAME_NEW);
100+
setWLPInstallPath("build");
101+
}
102+
}

src/test/java/io/openliberty/tools/intellij/it/GradleSingleModMPSIDProjectTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
public class GradleSingleModMPSIDProjectTest extends SingleModMPProjectTestCommon {
2626

2727
/**
28-
* Single module Microprofile project name.
28+
* Single module Microprofile project name specified in file settings.gradle.
2929
*/
3030
private static final String SM_MP_PROJECT_NAME = "singleModGradleMP";
3131

3232
/**
33-
* Single module Microprofile project name with space.
33+
* Project name of Microprofile single module in file settings-copy.gradle.
3434
*/
3535
private static final String SM_MP_PROJECT_NAME_NEW = "singleMod GradleMP";
3636

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package io.openliberty.tools.intellij.it;
11+
12+
import com.intellij.remoterobot.stepsProcessing.StepLogger;
13+
import com.intellij.remoterobot.stepsProcessing.StepWorker;
14+
import io.openliberty.tools.intellij.it.SingleModMPProjectTestCommon;
15+
import io.openliberty.tools.intellij.it.TestUtils;
16+
import org.junit.jupiter.api.AfterAll;
17+
import org.junit.jupiter.api.Assertions;
18+
import org.junit.jupiter.api.BeforeAll;
19+
20+
import java.io.IOException;
21+
import java.nio.file.Path;
22+
import java.nio.file.Paths;
23+
24+
/**
25+
* Test Liberty Tools creation of a Run/Debug configuration without a null pointer exception
26+
* using a single module MicroProfile Maven project.
27+
*/
28+
public class MavenSingleModMPCfgProjectTest extends SingleModMPProjectCfgTestCommon {
29+
30+
/**
31+
* Single module Microprofile project name.
32+
*/
33+
private static final String SM_MP_PROJECT_NAME = "singleModMavenMP";
34+
35+
/**
36+
* The path to the folder containing the test projects.
37+
*/
38+
private static final String PROJECTS_PATH = Paths.get("src", "test", "resources", "projects", "maven").toAbsolutePath().toString();
39+
40+
/**
41+
* The path to the folder containing the copy of the test project.
42+
*/
43+
private static final String PROJECTS_PATH_NEW = Paths.get("src", "test", "resources", "projects", "msample2").toAbsolutePath().toString();
44+
45+
/**
46+
* Prepares the environment for test execution.
47+
*/
48+
@BeforeAll
49+
public static void setup() {
50+
try {
51+
StepWorker.registerProcessor(new StepLogger());
52+
// Copy the directory from PROJECTS_PATH to PROJECTS_PATH_NEW
53+
TestUtils.copyDirectory(PROJECTS_PATH, PROJECTS_PATH_NEW);
54+
prepareEnv(PROJECTS_PATH_NEW, SM_MP_PROJECT_NAME);
55+
} catch (IOException e) {
56+
System.err.println("Setup failed: " + e.getMessage());
57+
e.printStackTrace();
58+
Assertions.fail("Test setup failed due to an IOException: " + e.getMessage());
59+
}
60+
}
61+
62+
/**
63+
* Cleanup includes deleting the created project path.
64+
*/
65+
@AfterAll
66+
public static void cleanup() {
67+
try {
68+
closeProjectView();
69+
} finally {
70+
deleteDirectoryIfExists(PROJECTS_PATH_NEW);
71+
}
72+
}
73+
74+
MavenSingleModMPCfgProjectTest() {
75+
setProjectsDirPath(PROJECTS_PATH_NEW);
76+
setSmMPProjectName(SM_MP_PROJECT_NAME);
77+
setWLPInstallPath(Paths.get("target", "liberty").toString());
78+
}
79+
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 IBM Corporation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*******************************************************************************/
10+
package io.openliberty.tools.intellij.it;
11+
12+
import com.automation.remarks.junit5.Video;
13+
import com.intellij.remoterobot.RemoteRobot;
14+
import org.junit.jupiter.api.*;
15+
16+
import java.io.File;
17+
import java.nio.file.Paths;
18+
import java.time.Duration;
19+
20+
import static com.intellij.remoterobot.utils.RepeatUtilsKt.waitForIgnoringError;
21+
22+
/**
23+
* Holds common tests that use a single module MicroProfile project.
24+
*/
25+
public abstract class SingleModMPProjectCfgTestCommon {
26+
27+
// In this test case the environment has been set up so that there is a new project
28+
// that has not been used in a previous execution of IntelliJ. Also, the Liberty explorer
29+
// or dashboard has not been opened as it is in all other tests. This means the LibertyModules
30+
// object is not yet populated.
31+
// When we create a new Run/Debug configuration, the "Liberty project" field is populated by
32+
// default with one of the build files from one of the Liberty projects in the workspace. If
33+
// there is no default build file then there will be a Null Pointer Exception if we press Run.
34+
35+
/**
36+
* URL to display the UI Component hierarchy. This is used to obtain xPath related
37+
* information to find UI components.
38+
*/
39+
public static final String REMOTE_BOT_URL = "http://localhost:8082";
40+
41+
/**
42+
* The remote robot object.
43+
*/
44+
public static final RemoteRobot remoteRobot = new RemoteRobot(REMOTE_BOT_URL);
45+
46+
/**
47+
* Single module Microprofile project name.
48+
*/
49+
private String smMpProjectName = null;
50+
51+
/**
52+
* The path to the folder containing the test projects.
53+
*/
54+
private String projectsPath = null;
55+
56+
/**
57+
* Relative location of the WLP installation.
58+
*/
59+
private String wlpInstallPath = null;
60+
61+
/**
62+
* Returns the path where the Liberty server was installed.
63+
*
64+
* @return The path where the Liberty server was installed.
65+
*/
66+
public String getWLPInstallPath() {
67+
return wlpInstallPath;
68+
}
69+
public void setWLPInstallPath(String path) {
70+
wlpInstallPath = path;
71+
}
72+
73+
/**
74+
* Returns the projects directory path.
75+
*
76+
* @return The projects directory path.
77+
*/
78+
public String getProjectsDirPath() {
79+
return projectsPath;
80+
}
81+
public void setProjectsDirPath(String path) {
82+
projectsPath = path;
83+
}
84+
85+
/**
86+
* Returns the name of the single module MicroProfile project.
87+
*
88+
* @return The name of the single module MicroProfile project.
89+
*/
90+
public String getSmMPProjectName() {
91+
return smMpProjectName;
92+
}
93+
public void setSmMPProjectName(String name) {
94+
smMpProjectName = name;
95+
}
96+
97+
/**
98+
* Processes actions before each test.
99+
*
100+
* @param info Test information.
101+
*/
102+
@BeforeEach
103+
public void beforeEach(TestInfo info) {
104+
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Entry");
105+
}
106+
107+
/**
108+
* Processes actions after each test.
109+
*
110+
* @param info Test information.
111+
*/
112+
@AfterEach
113+
public void afterEach(TestInfo info) {
114+
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO, this.getClass().getSimpleName() + "." + info.getDisplayName() + ". Exit");
115+
TestUtils.detectFatalError();
116+
}
117+
118+
/**
119+
* Cleanup.
120+
*/
121+
@AfterAll
122+
public static void cleanup() {
123+
closeProjectView();
124+
}
125+
126+
/**
127+
* Close project.
128+
*/
129+
protected static void closeProjectView() {
130+
if (!remoteRobot.isMac()) {
131+
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Close All Tabs", 3);
132+
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
133+
}
134+
UIBotTestUtils.closeLibertyToolWindow(remoteRobot);
135+
UIBotTestUtils.closeProjectView(remoteRobot);
136+
UIBotTestUtils.closeProjectFrame(remoteRobot);
137+
UIBotTestUtils.validateProjectFrameClosed(remoteRobot);
138+
}
139+
140+
/**
141+
* Create a run configuration and see if it caused a null pointer exception
142+
*/
143+
@Test
144+
@Video
145+
public void testCreateRunConfigAction() {
146+
String testName = "testCreateRunConfigAction";
147+
// Remove all other configurations first.
148+
UIBotTestUtils.deleteLibertyRunConfigurations(remoteRobot);
149+
150+
// Add a new Liberty configurations. Throws an exception if there is an error.
151+
// Note: the method will throw a NoSuchElementException if there are no Liberty projects
152+
// detected when the Edit Liberty Run/Debug Configuration dialog is opened.
153+
UIBotTestUtils.createLibertyConfiguration(remoteRobot, "newCfg1", false, null);
154+
}
155+
156+
/**
157+
* Prepares the environment to run the tests.
158+
*
159+
* @param projectPath The path of the project.
160+
* @param projectName The name of the project being used.
161+
*/
162+
public static void prepareEnv(String projectPath, String projectName) {
163+
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO,
164+
"prepareEnv. Entry. ProjectPath: " + projectPath + ". ProjectName: " + projectName);
165+
waitForIgnoringError(Duration.ofMinutes(4), Duration.ofSeconds(5), "Wait for IDE to start", "IDE did not start", () -> remoteRobot.callJs("true"));
166+
UIBotTestUtils.findWelcomeFrame(remoteRobot);
167+
UIBotTestUtils.importProject(remoteRobot, projectPath, projectName);
168+
UIBotTestUtils.openProjectView(remoteRobot);
169+
if (!remoteRobot.isMac()) {
170+
UIBotTestUtils.runActionFromSearchEverywherePanel(remoteRobot, "Compact Mode", 3);
171+
}
172+
// IntelliJ does not start building and indexing until the Project View is open
173+
UIBotTestUtils.waitForIndexing(remoteRobot);
174+
TestUtils.printTrace(TestUtils.TraceSevLevel.INFO,
175+
"prepareEnv. Exit. ProjectName: " + projectName);
176+
}
177+
178+
/**
179+
* Deletes the directory specified by dirPath if it exists.
180+
*
181+
* @param dirPath The path to the directory that may be deleted.
182+
*/
183+
public static void deleteDirectoryIfExists(String dirPath) {
184+
File dir = new File(dirPath);
185+
if (dir.exists()) {
186+
TestUtils.deleteDirectory(dir);
187+
}
188+
}
189+
}

0 commit comments

Comments
 (0)