Skip to content

Commit 68f4e3f

Browse files
committed
chore: fix integration tests
Signed-off-by: Stephane Bouchet <[email protected]>
1 parent 0ed465c commit 68f4e3f

File tree

6 files changed

+44
-63
lines changed

6 files changed

+44
-63
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ build/
3232
target/
3333
pom.xml
3434

35+
/src/test-project/.intellijPlatform/self-update.lock

src/main/java/com/redhat/devtools/intellij/commonuitest/UITestRunner.java

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,11 @@ public static RemoteRobot runIde(IntelliJVersion ideaVersion, int port) {
7272
UITestRunner.ideaVersion = ideaVersion;
7373

7474
acceptAllTermsAndConditions();
75-
if (ideaVersion.isUltimate()) {
76-
activateEvaluateForFree();
77-
}
7875

7976
String fileExtension = OS_NAME.contains("windows") ? ".bat" : "";
8077
String[] platformTypeVersion = generatePlatformTypeVersion();
8178

82-
ProcessBuilder pb = null;
79+
ProcessBuilder pb;
8380

8481
if (ideaVersion.toInt() < 20242) {
8582
pb = new ProcessBuilder("." + File.separator + "gradlew" + fileExtension, "runIdeForUiTests", "-PideaVersion=" + ideaVersion, "-Drobot-server.port=" + port);
@@ -176,18 +173,14 @@ public static RemoteRobot getRemoteRobotConnection(int port) {
176173

177174
private static void acceptAllTermsAndConditions() {
178175
String osxPlistSourceLocation;
179-
if (ideaVersion.isUltimate()) {
180-
osxPlistSourceLocation = "plist/ultimate_all/com.apple.java.util.prefs.plist";
181-
} else if (ideaVersion.toInt() <= 20213) {
176+
if (ideaVersion.toInt() <= 20213) {
182177
osxPlistSourceLocation = "plist/2021_3_and_older/com.apple.java.util.prefs.plist";
183178
} else {
184179
osxPlistSourceLocation = "plist/2022_1/com.apple.java.util.prefs.plist";
185180
}
186181

187182
String linuxPrefsXmlSourceLocation;
188-
if (ideaVersion.isUltimate()) {
189-
linuxPrefsXmlSourceLocation = "prefs_xml/ultimate_all/prefs.xml";
190-
} else if (ideaVersion.toInt() <= 20213) {
183+
if (ideaVersion.toInt() <= 20213) {
191184
linuxPrefsXmlSourceLocation = "prefs_xml/2021_3_and_older/prefs.xml";
192185
} else {
193186
linuxPrefsXmlSourceLocation = "prefs_xml/2022_1/prefs.xml";
@@ -259,18 +252,6 @@ private static void acceptAllTermsAndConditions() {
259252
}
260253
}
261254

262-
private static void activateEvaluateForFree() {
263-
String targetEvaluationKeysDir = System.getProperty("user.dir") + "/build/idea-sandbox/config-uiTest/eval/";
264-
createDirectoryHierarchy(targetEvaluationKeysDir);
265-
266-
for (String ideaVersionSubstring : new String[]{"202", "203", "211", "212"}) {
267-
String keyFilename = "idea" + ideaVersionSubstring + ".evaluation.key";
268-
String sourcePathToKey = "evaluate_for_free_keys/" + keyFilename;
269-
String targetPathToKey = targetEvaluationKeysDir + keyFilename;
270-
copyFileFromJarResourceDir(sourcePathToKey, targetPathToKey);
271-
}
272-
}
273-
274255
private static void waitUntilIntelliJStarts(int port) {
275256
waitFor(Duration.ofSeconds(600), Duration.ofSeconds(3), "The IntelliJ Idea did not start in 10 minutes.", () -> isIntelliJUIVisible(port));
276257
}
@@ -308,14 +289,16 @@ private static void createDirectoryHierarchy(String location) {
308289
}
309290

310291
private static void copyFileFromJarResourceDir(String sourceFileLocation, String destFileLocation) {
311-
InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation);
312-
try (OutputStream outStream = new FileOutputStream(new File(destFileLocation))) {
313-
byte[] buffer = new byte[resourceStream.available()];
314-
int count = resourceStream.read(buffer);
315-
if (count == 0) {
316-
throw new UITestException("Reading from buffer was unsuccessful.");
292+
try (OutputStream outStream = new FileOutputStream(destFileLocation);
293+
InputStream resourceStream = UITestRunner.class.getClassLoader().getResourceAsStream(sourceFileLocation)) {
294+
if (resourceStream != null) {
295+
byte[] buffer = new byte[resourceStream.available()];
296+
int count = resourceStream.read(buffer);
297+
if (count == 0) {
298+
throw new UITestException("Reading from buffer was unsuccessful.");
299+
}
300+
outStream.write(buffer);
317301
}
318-
outStream.write(buffer);
319302
} catch (IOException e) {
320303
LOGGER.log(Level.SEVERE, e.getMessage(), e);
321304
}
@@ -324,7 +307,7 @@ private static void copyFileFromJarResourceDir(String sourceFileLocation, String
324307
/**
325308
* Redirect stdout and stderr of running subprocess to files
326309
*
327-
* @param pb Process builder of running subprocess
310+
* @param pb Process builder of running subprocess
328311
*/
329312
private static void redirectProcessOutputs(ProcessBuilder pb) {
330313
String outDir = System.getProperty("user.dir") + File.separator + "intellij_debug";
@@ -346,7 +329,7 @@ private static void redirectProcessOutputs(ProcessBuilder pb) {
346329
*/
347330
private static String[] generatePlatformTypeVersion() {
348331
String[] platformTypeVersion = ideaVersion.toString().split("-", 2);
349-
if (2 > platformTypeVersion.length){
332+
if (2 > platformTypeVersion.length) {
350333
throw new UITestException("ideaVersion is not recognized.");
351334
}
352335
return platformTypeVersion;

src/main/java/com/redhat/devtools/intellij/commonuitest/fixtures/dialogs/FlatWelcomeFrame.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,20 @@
2323
import com.redhat.devtools.intellij.commonuitest.utils.constants.ButtonLabels;
2424
import com.redhat.devtools.intellij.commonuitest.utils.constants.XPathDefinitions;
2525
import com.redhat.devtools.intellij.commonuitest.utils.project.CreateCloseUtils;
26-
import com.redhat.devtools.intellij.commonuitest.utils.runner.IntelliJVersion;
2726
import com.redhat.devtools.intellij.commonuitest.utils.steps.SharedSteps;
2827
import org.jetbrains.annotations.NotNull;
2928

3029
import java.io.File;
3130
import java.io.IOException;
3231
import java.nio.file.Files;
32+
import java.nio.file.Path;
3333
import java.nio.file.Paths;
3434
import java.time.Duration;
35+
import java.util.Comparator;
3536
import java.util.List;
3637
import java.util.logging.Level;
3738
import java.util.logging.Logger;
39+
import java.util.stream.Stream;
3840

3941
import static com.intellij.remoterobot.search.locators.Locators.byXpath;
4042

@@ -50,14 +52,12 @@ public class FlatWelcomeFrame extends CommonContainerFixture {
5052
private static final String PROJECTS_BUTTON = "Projects";
5153
private static final String TIP_OF_THE_DAY = "Tip of the Day";
5254
private final RemoteRobot remoteRobot;
53-
private final IntelliJVersion intelliJVersion;
5455
private final int ideaVersion;
5556

5657
public FlatWelcomeFrame(@NotNull RemoteRobot remoteRobot, @NotNull RemoteComponent remoteComponent) {
5758
super(remoteRobot, remoteComponent);
5859
this.remoteRobot = remoteRobot;
59-
this.intelliJVersion = UITestRunner.getIdeaVersion();
60-
this.ideaVersion = intelliJVersion.toInt();
60+
this.ideaVersion = UITestRunner.getIdeaVersion().toInt();
6161
}
6262

6363
/**
@@ -100,11 +100,16 @@ public void clearWorkspace() {
100100
// Remove projects on disk
101101
try {
102102
String pathToDirToMakeEmpty = CreateCloseUtils.PROJECT_LOCATION;
103-
boolean doesProjectDirExists = Files.exists(Paths.get(pathToDirToMakeEmpty));
103+
Path path = Paths.get(pathToDirToMakeEmpty);
104+
boolean doesProjectDirExists = Files.exists(path);
104105
if (doesProjectDirExists) {
105-
Files.delete(new File(pathToDirToMakeEmpty).toPath());
106+
try (Stream<Path> pathStream = Files.walk(new File(pathToDirToMakeEmpty).toPath())) {
107+
pathStream.sorted(Comparator.reverseOrder())
108+
.map(Path::toFile)
109+
.forEach(File::delete);
110+
}
106111
} else {
107-
Files.createDirectories(Paths.get(pathToDirToMakeEmpty));
112+
Files.createDirectories(path);
108113
}
109114
} catch (IOException e) {
110115
LOGGER.log(Level.SEVERE, e.getMessage(), e);

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/constants/XPathDefinitions.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package com.redhat.devtools.intellij.commonuitest.utils.constants;
1212

1313
import com.redhat.devtools.intellij.commonuitest.exceptions.UITestException;
14+
import org.intellij.lang.annotations.Language;
1415

1516
/**
1617
* XPath definitions
@@ -39,10 +40,15 @@ public class XPathDefinitions {
3940
public static final String IDE_FATAL_ERRORS_DIALOG = "//div[@accessiblename='IDE Fatal Errors' and @class='MyDialog']";
4041
public static final String PROJECT_STRUCTURE_DIALOG = "//div[@accessiblename='Project Structure' and @class='MyDialog']";
4142
public static final String TIP_DIALOG = "//div[@accessiblename='Tip of the Day' and @class='MyDialog']";
43+
@Language("XPath")
4244
public static final String TIP_DIALOG_2 = "//div[@text='Tip of the Day']";
45+
@Language("XPath")
4346
public static final String RECENT_PROJECTS = "//div[@accessiblename='Recent Projects']";
47+
@Language("XPath")
4448
public static final String RECENT_PROJECT_PANEL_NEW = "//div[@class='NewRecentProjectPanel']";
49+
@Language("XPath")
4550
public static final String RECENT_PROJECT_PANEL_NEW_2 = "//div[@class='JBViewport']/*";
51+
@Language("XPath")
4652
public static final String IDE_ERROR_ICON = "//div[@class='IdeErrorsIcon']";
4753
public static final String BUILD_VIEW_EDITOR = "//div[@accessiblename='Editor']";
4854
public static final String JCOMBOBOX = "//div[@class='JComboBox']";
@@ -51,7 +57,9 @@ public class XPathDefinitions {
5157
public static final String HEAVY_WEIGHT_WINDOW = "//div[@class='HeavyWeightWindow']";
5258
public static final String JDK_COMBOBOX = "//div[@class='JdkComboBox']";
5359
public static final String JDK_COMBOBOX_PROJECT_WIZARD = "//div[@class='ProjectWizardJdkComboBox']"; // works for IntelliJ Idea 2024.1 and higher
60+
@Language("XPath")
5461
public static final String MY_DIALOG = "//div[@class='MyDialog']";
62+
@Language("XPath")
5563
public static final String TREE = "//div[@class='Tree']";
5664
public static final String TOOLTIP_TEXT_PROJECT = "//div[@tooltiptext='Project']";
5765
public static final String TOOLTIP_TEXT_HIDE = "//div[contains(@myvisibleactions, 'View),')]//div[@tooltiptext='Hide']";
@@ -68,8 +76,11 @@ public class XPathDefinitions {
6876
public static final String MY_ICON_LOCATE_SVG = "//div[@myicon='locate.svg']";
6977
public static final String MY_ICON_REFRESH = "//div[@myicon='refresh.svg']";
7078
public static final String CONTENT_COMBO_LABEL = "//div[@class='ContentComboLabel']";
79+
@Language("XPath")
7180
public static final String JBLIST = "//div[@class='JBList']";
81+
@Language("XPath")
7282
public static final String DIALOG_PANEL = "//div[@class='DialogPanel']";
83+
@Language("XPath")
7384
public static final String MY_LIST = "//div[@class='MyList']";
7485
public static final String CODE_WITH_ME_JPANEL = "//div[@class='Wrapper'][.//div[@class='JBLabel']]//div[@class='JPanel']";
7586
public static final String BREAD_CRUMBS = "//div[@class='Breadcrumbs']";
@@ -81,6 +92,7 @@ public class XPathDefinitions {
8192
public static final String COLLAPSIBLE_TITLED_SEPARATOR_NEW_SIBLINGS = COLLAPSIBLE_TITLED_SEPARATOR_NEW + "/../*";
8293
public static final String EXTENDABLE_TEXT_FIELD = "//div[@class='ExtendableTextField']";
8394
public static final String JBTEXT_FIELD = "//div[@class='JBTextField']";
95+
@Language("XPath")
8496
public static final String REMOVE_PROJECT_BUTTON = "//div[contains(@text.key, 'button.remove')]";
8597
public static final String SET_LANGUAGE = "//div[@class='SegmentedButtonComponent'][.//div[contains(@action.key, 'language.groovy')]]";
8698
public static final String SET_BUILD_SYSTEM = "//div[@class='SegmentedButtonComponent'][.//div[@action.key='buildsystem.type.intellij']]";
@@ -89,6 +101,7 @@ public class XPathDefinitions {
89101
public static final String GET_SET_MODULE_NAME_2024_2_AND_NEWER = "//div[@accessiblename='Module name:' and @class='JBTextField']";
90102
public static final String GET_SET_CONTENT_ROOT = "//div[@accessiblename='Content root:' and @class='ExtendableTextField']";
91103
public static final String GET_SET_MODULE_FILE_LOCATION = "//div[@accessiblename='Module file location:' and @class='ExtendableTextField']";
104+
@Language("XPath")
92105
public static final String CREATE_NEW_PROJECT = "//div[@defaulticon='createNewProjectTab.svg']"; // works for IntelliJ Idea 2024.1 and higher
93106

94107
private XPathDefinitions() {

src/main/java/com/redhat/devtools/intellij/commonuitest/utils/runner/IntelliJVersion.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,17 @@ public enum IntelliJVersion {
2828
COMMUNITY_V_2023_2("IC-2023.2"),
2929
COMMUNITY_V_2024_1("IC-2024.1"),
3030
COMMUNITY_V_2024_2("IC-2024.2"),
31-
ULTIMATE_V_2020_2("IU-2020.2"),
32-
ULTIMATE_V_2020_3("IU-2020.3"),
33-
ULTIMATE_V_2021_1("IU-2021.1"),
34-
ULTIMATE_V_2021_2("IU-2021.2"),
35-
ULTIMATE_V_2023_2("IU-2023.2"),
36-
ULTIMATE_V_2024_1("IU-2024.1"),
37-
ULTIMATE_V_2024_2("IU-2024.2");
31+
COMMUNITY_V_2024_3("IC-2024.3");
3832

3933
private final String ideaVersionStringRepresentation;
4034
private final int ideaVersionIntRepresentation;
41-
private final boolean isIdeaUltimate;
4235

4336
IntelliJVersion(String ideaVersionStringRepresentation) {
4437
this.ideaVersionStringRepresentation = ideaVersionStringRepresentation;
4538

4639
String ideaVersionString = this.ideaVersionStringRepresentation.substring(3).replace(".", "");
4740
this.ideaVersionIntRepresentation = Integer.parseInt(ideaVersionString);
4841

49-
this.isIdeaUltimate = this.ideaVersionStringRepresentation.charAt(1) == 'U';
5042
}
5143

5244
@Override
@@ -58,7 +50,4 @@ public int toInt() {
5850
return this.ideaVersionIntRepresentation;
5951
}
6052

61-
public boolean isUltimate() {
62-
return this.isIdeaUltimate;
63-
}
6453
}

src/test-project/src/test/java/com/redhat/devtools/intellij/commonuitest/LibraryTestBase.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.junit.jupiter.api.extension.ExtendWith;
2222

2323
import java.time.Duration;
24-
import java.util.logging.Level;
2524
import java.util.logging.Logger;
2625

2726
/**
@@ -33,25 +32,16 @@
3332
public class LibraryTestBase {
3433
protected static final Logger LOGGER = Logger.getLogger(LibraryTestBase.class.getName());
3534
private static final IntelliJVersion communityIdeaVersion = IntelliJVersion.COMMUNITY_V_2024_2;
36-
private static final IntelliJVersion ultimateIdeaVersion = IntelliJVersion.ULTIMATE_V_2024_2;
3735
protected static RemoteRobot remoteRobot;
3836
protected static int ideaVersionInt;
3937
private static boolean intelliJHasStarted = false;
40-
private static final int port = 8580;
38+
private static final int TEST_RUNNER_PORT = 8580;
4139

4240
@BeforeAll
4341
protected static void startIntelliJ() {
4442
if (!intelliJHasStarted) {
45-
String taskName = System.getProperty("task.name");
46-
if (taskName != null && taskName.equalsIgnoreCase("integrationUITestUltimate")) {
47-
// Run UI tests for ultimate version
48-
ideaVersionInt = ultimateIdeaVersion.toInt();
49-
remoteRobot = UITestRunner.runIde(ultimateIdeaVersion, port);
50-
} else {
51-
// Run UI tests for community version
52-
ideaVersionInt = communityIdeaVersion.toInt();
53-
remoteRobot = UITestRunner.runIde(communityIdeaVersion, port);
54-
}
43+
ideaVersionInt = communityIdeaVersion.toInt();
44+
remoteRobot = UITestRunner.runIde(communityIdeaVersion, TEST_RUNNER_PORT);
5545

5646
intelliJHasStarted = true;
5747
Runtime.getRuntime().addShutdownHook(new CloseIntelliJBeforeQuit());

0 commit comments

Comments
 (0)