1+ /*
2+ * IBM Confidential
3+ * Copyright IBM Corp. 2023, 2026
4+ */
5+ import * as path from 'path' ;
6+ import { logger } from './utils/testLogger' ;
7+ import { EditorView , VSBrowser } from 'vscode-extension-tester' ;
8+ import { EditorPage } from './pages/EditorPage' ;
19import * as utils from './utils/testUtils' ;
2- import { runServerEnvSuite } from './shared/serverEnvSuite' ;
10+ import { expect } from 'chai' ;
11+ import { CodeAssistPage } from './pages/CodeAssistPage' ;
12+ import { ProblemsPage } from './pages/ProblemsPage' ;
13+ import { QuickFixPage } from './pages/QuickFixPage' ;
14+ import * as editorUtils from './utils/editorUtils' ;
315
4- runServerEnvSuite ( {
5- buildTool : 'maven' ,
6- getProjectPath : utils . getMvnProjectPath ,
7- } ) ;
16+ const HOVER_INITIAL_CONTENT = 'WLP_USER_DIR=/opt/wlp/usr\nLOG_DIR=/logs\n' ;
17+
18+ const HOVER_TEST_CASES = [
19+ {
20+ element : 'WLP_USER_DIR' ,
21+ line : 1 ,
22+ column : 1 ,
23+ expectedDoc : 'The user or custom configuration directory that is used to store shared and server-specific configuration. See the path_to_liberty/wlp/README.TXT file for details about shared resource locations. A server configuration is at the %WLP_USER_DIR%/servers/serverName location. The default value is the user directory in the installation directory.' ,
24+ } ,
25+ {
26+ element : 'LOG_DIR' ,
27+ line : 2 ,
28+ column : 1 ,
29+ expectedDoc : 'The directory that contains the log file. The default value is %WLP_OUTPUT_DIR%/serverName/logs' ,
30+ } ,
31+ ] ;
32+
33+ describe ( 'Server Env functionality tests for Maven Project' , ( ) => {
34+ let serverEnv : EditorPage ;
35+ let wait : any ;
36+
37+ before ( async function ( ) {
38+ this . timeout ( 60000 ) ;
39+
40+ logger . info ( 'Setting up Maven server.env tests' ) ;
41+
42+ await VSBrowser . instance . openResources ( utils . getMvnProjectPath ( ) ) ;
43+ await VSBrowser . instance . waitForWorkbench ( ) ;
44+
45+ wait = utils . getWaitHelper ( ) ;
46+
47+ logger . info ( 'Opening server.env file for all tests' ) ;
48+ const serverEnvPath = path . resolve (
49+ utils . getMvnProjectPath ( ) ,
50+ 'src' , 'main' , 'liberty' , 'config' , 'server.env'
51+ ) ;
52+ logger . info ( `Server.env path: ${ serverEnvPath } ` ) ;
53+
54+ serverEnv = await new EditorPage ( ) . openFile ( serverEnvPath , 'server.env' ) ;
55+ logger . info ( 'Server.env file opened and editor obtained' ) ;
56+ } ) ;
57+
58+ afterEach ( async function ( ) {
59+ if ( this . currentTest ?. state === 'failed' ) {
60+ await VSBrowser . instance . driver . takeScreenshot ( ) ;
61+ logger . error ( `Test failed: ${ this . currentTest . title } ` ) ;
62+ }
63+ } ) ;
64+
65+ after ( async function ( ) {
66+ this . timeout ( 10000 ) ;
67+ try {
68+ if ( serverEnv ) {
69+ const currentText = await serverEnv . getEditor ( ) . getText ( ) ;
70+ try {
71+ await serverEnv . getEditor ( ) . selectText ( currentText ) ;
72+ await wait . sleep ( 300 ) ;
73+ } catch ( selectError ) {
74+ // selectText may fail but setText still works
75+ }
76+ await editorUtils . clearEditor ( serverEnv . getEditor ( ) ) ;
77+ logger . info ( 'Reset server.env to empty after tests' ) ;
78+ }
79+ } catch ( error ) {
80+ logger . error ( 'Failed to reset server.env' , error ) ;
81+ }
82+ try {
83+ await new EditorView ( ) . closeAllEditors ( ) ;
84+ logger . info ( 'Closed all editors after test suite' ) ;
85+ } catch ( error ) {
86+ logger . error ( 'Failed to close editors in after hook' , error ) ;
87+ }
88+ utils . copyScreenshotsToProjectFolder ( 'maven' ) ;
89+ } ) ;
90+
91+ it ( 'Liberty Language Server should initialize' , async function ( ) {
92+ this . timeout ( 60000 ) ;
93+ logger . testStart ( 'Liberty Language Server should initialize' ) ;
94+ try {
95+ await utils . waitForLanguageServerInit (
96+ 'Language Support for Liberty' ,
97+ 'Initialized Liberty Language server' ,
98+ 60
99+ ) ;
100+ logger . testComplete ( 'Liberty Language Server initialized successfully' ) ;
101+ } catch ( error ) {
102+ logger . testFailed ( 'Liberty Language Server should initialize' , error ) ;
103+ throw error ;
104+ }
105+ } ) ;
106+
107+ HOVER_TEST_CASES . forEach ( testCase => {
108+ it ( `Hover over ${ testCase . element } shows Liberty Language Server documentation` , async function ( ) {
109+ this . timeout ( 30000 ) ;
110+ logger . testStart ( `Hover over ${ testCase . element } shows Liberty Language Server documentation` ) ;
111+ await serverEnv . getEditor ( ) . setText ( HOVER_INITIAL_CONTENT ) ;
112+ await serverEnv . getEditor ( ) . save ( ) ;
113+ await wait . sleep ( 1000 ) ;
114+
115+ try {
116+ const hoverText = await editorUtils . hoverOver ( serverEnv . getEditor ( ) , testCase . line , testCase . column , testCase . element ) ;
117+ expect ( hoverText ) . to . not . be . empty ;
118+ logger . stepSuccess ( 3 , `Hover widget displayed with Liberty Language Server content for ${ testCase . element } ` ) ;
119+
120+ logger . step ( 4 , 'Verifying hover contains expected documentation' ) ;
121+ expect ( hoverText ) . to . include ( testCase . expectedDoc ) ;
122+ logger . stepSuccess ( 4 , `Hover text contains expected documentation: "${ testCase . expectedDoc } "` ) ;
123+
124+ logger . testComplete ( `Hover over ${ testCase . element } shows Liberty Language Server documentation` ) ;
125+ } catch ( error ) {
126+ logger . testFailed ( `Hover over ${ testCase . element } shows Liberty Language Server documentation` , error ) ;
127+ throw error ;
128+ }
129+ } ) ;
130+ } ) ;
131+
132+ it ( 'server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT type ahead' , async function ( ) {
133+ this . timeout ( 275000 ) ;
134+ logger . testStart ( 'server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT type ahead' ) ;
135+
136+ try {
137+ logger . step ( 1 , 'Positioning cursor' ) ;
138+ await serverEnv . getEditor ( ) . setCursor ( 3 , 1 ) ;
139+
140+ logger . step ( 2 , 'Opening content assist' ) ;
141+ const codeAssist = new CodeAssistPage ( ) ;
142+ await codeAssist . insertSnippet ( serverEnv , 'WLP_LOG' , 'WLP_LOGGING_MESSAGE_FORMAT' ) ;
143+ logger . stepSuccess ( 2 , 'Completion inserted' ) ;
144+ const after = await serverEnv . getEditor ( ) . getText ( ) ;
145+ expect ( after ) . to . include ( 'WLP_LOGGING_MESSAGE_FORMAT' ) ;
146+ await wait . sleep ( 1000 ) ;
147+
148+ const lineText = await serverEnv . getEditor ( ) . getTextAtLine ( 3 ) ;
149+ await serverEnv . getEditor ( ) . setTextAtLine ( 3 , lineText . trimEnd ( ) + '=JSON' ) ;
150+
151+ await serverEnv . getEditor ( ) . save ( ) ;
152+ await wait . sleep ( 500 ) ;
153+
154+ logger . testComplete ( 'server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT completion' ) ;
155+ } catch ( error ) {
156+ logger . testFailed ( 'server.env WLP_LOG populates correct WLP_LOGGING_MESSAGE_FORMAT completion' , error ) ;
157+ throw error ;
158+ }
159+ } ) ;
160+
161+ it ( 'Show that INVALID text displays diagnostic and quick fix removes it' , async function ( ) {
162+ this . timeout ( 90000 ) ;
163+ logger . testStart ( 'Show that INVALID text displays diagnostic and quick fix removes it' ) ;
164+ try {
165+ await editorUtils . replaceTextWithinLineContaining ( serverEnv . getEditor ( ) , 'WLP_LOGGING_MESSAGE_FORMAT' , 'JSON' , 'INVALID' ) ;
166+
167+ await serverEnv . getEditor ( ) . save ( ) ;
168+ await wait . sleep ( 500 ) ;
169+
170+ const problems = new ProblemsPage ( ) ;
171+ const found = await problems . hasDiagnostic ( 'The value `INVALID` is not valid for the variable `WLP_LOGGING_MESSAGE_FORMAT`.' ) ;
172+ expect ( found ) . to . be . true ;
173+ logger . testComplete ( 'Diagnostic shows INVALID variable' ) ;
174+
175+ const buffer = await serverEnv . getEditor ( ) . getText ( ) ;
176+ logger . info ( 'Buffer before quick fix: ' + JSON . stringify ( buffer ) ) ;
177+
178+ await new QuickFixPage ( ) . applyFix ( serverEnv , 'INVALID' , 'Replace value with JSON' ) ;
179+ await wait . sleep ( 3000 ) ;
180+ await serverEnv . getEditor ( ) . save ( ) ;
181+ await wait . sleep ( 5000 ) ;
182+
183+ const afterFix = await serverEnv . getEditor ( ) . getText ( ) ;
184+ expect ( afterFix ) . to . include ( 'JSON' ) ;
185+ expect ( await problems . hasDiagnostic ( 'The value `INVALID` is not valid for the variable `WLP_LOGGING_MESSAGE_FORMAT`.' ) ) . to . be . false ;
186+ } catch ( error ) {
187+ logger . testFailed ( 'Diagnostic/quick-fix test flow failed' , error ) ;
188+ throw error ;
189+ }
190+ } ) ;
191+ } ) ;
0 commit comments