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