-
Notifications
You must be signed in to change notification settings - Fork 39
Add LSP4Jakarta diagnostic + quick fix tests for Maven and Gradle (#125) #599
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
|
|
||
| /* | ||
| * IBM Confidential | ||
| * Copyright IBM Corp. 2026 | ||
| */ | ||
| import { expect } from 'chai'; | ||
| import { EditorView, TextEditor, VSBrowser, Workbench, WebDriver, BottomBarPanel, MarkerType, Key, By } from 'vscode-extension-tester'; | ||
| import * as utils from './utils/testUtils'; | ||
| import { logger } from './utils/testLogger'; | ||
| import * as path from 'path'; | ||
|
|
||
| describe('Rest Class Snippet Test for Gradle Project', () => { | ||
| let editorView: EditorView; | ||
| let javaEditor: TextEditor; | ||
| let wait: any; | ||
| let driver: WebDriver; | ||
|
|
||
| const testRestPath = path.resolve( | ||
| utils.getGradleProjectPath(), | ||
| 'src', 'main', 'java', 'test', 'gradle', 'liberty', 'web', 'app', | ||
| 'TestRest.java' | ||
| ); | ||
|
|
||
| before(async function() { | ||
| this.timeout(60000); | ||
| logger.info('Setting up rest_class snippet test'); | ||
|
|
||
| driver = VSBrowser.instance.driver; | ||
| await VSBrowser.instance.openResources(utils.getGradleProjectPath()); | ||
|
|
||
| // Wait for workbench to be ready | ||
| await VSBrowser.instance.waitForWorkbench(); | ||
| editorView = new EditorView(); | ||
| wait = utils.getWaitHelper(); | ||
|
|
||
| // Open the file | ||
| await VSBrowser.instance.openResources(testRestPath, async () => { | ||
| await wait.sleep(3000); | ||
| }); | ||
| javaEditor = await editorView.openEditor('TestRest.java') as TextEditor; | ||
| }); | ||
|
|
||
| afterEach(async function() { | ||
| // Take screenshot on failure but don't close editor | ||
| if (this.currentTest?.state === 'failed') { | ||
| const driver = VSBrowser.instance.driver; | ||
| const screenshot = await driver.takeScreenshot(); | ||
| logger.error(`Test failed: ${this.currentTest.title}`); | ||
| } | ||
| }); | ||
|
|
||
| after(async function() { | ||
| this.timeout(10000); // Increase timeout for cleanup operations | ||
| // Close editor after all tests complete | ||
| try { | ||
| if(javaEditor){ | ||
| await javaEditor.setText(''); | ||
| await javaEditor.save(); | ||
| logger.info('Reset TestRest.java to empty after test') | ||
|
|
||
| } | ||
| } catch (error){ | ||
| logger.error('Failed to reset TestRest.java ', error); | ||
|
mattbsox marked this conversation as resolved.
Outdated
|
||
| } | ||
| try { | ||
| await editorView.closeAllEditors(); | ||
| logger.info('Closed all editors after test suite'); | ||
| } catch (error) { | ||
| logger.error('Failed to close editors in after hook', error); | ||
| } | ||
|
|
||
| utils.copyScreenshotsToProjectFolder('gradle'); | ||
| }); | ||
|
|
||
| it('LSP4Jakarta Language Server should initialize', async function() { | ||
| this.timeout(60000); | ||
| logger.testStart('LSP4Jakarta Language Server should initialize'); | ||
|
|
||
| try { | ||
| await utils.waitForLanguageServerInit( | ||
| 'Language Support for Jakarta EE', | ||
| 'Initializing Jakarta EE server', | ||
| 60 | ||
| ); | ||
| logger.testComplete('LSP4Jakarta Language Server initialized successfully'); | ||
| } catch (error) { | ||
| logger.testFailed('LSP4Jakarta Language Server should initialize', error); | ||
| throw error; | ||
| } | ||
| }); | ||
|
|
||
| it('rest_class snippet populates correct REST class', async function () { | ||
| this.timeout(275000); | ||
| logger.testStart('rest_class snippet inserts correct REST class'); | ||
|
|
||
| // at the top of the rest_class snippet test, before positioning the cursor | ||
| await javaEditor.setText(''); | ||
| await javaEditor.save(); | ||
| await wait.sleep(1500); // let any auto-stub settle, then confirm | ||
| const check = await javaEditor.getText(); | ||
| logger.info('Buffer before snippet: ' + JSON.stringify(check)); | ||
|
|
||
| try { | ||
| logger.step(1, 'Positioning cursor for snippet insertion'); | ||
| // Position cursor at end of file | ||
| const lastLine = (await javaEditor.getText()).split('\n').length; | ||
| await javaEditor.setCursor(lastLine - 1, 1); | ||
|
|
||
| logger.step(2, 'Typing "rest" to trigger snippet'); | ||
| await javaEditor.typeText('rest'); | ||
| logger.stepSuccess(2, 'Typed "rest"'); | ||
|
|
||
| logger.step(3, 'Opening content assist'); | ||
| const assist = await javaEditor.toggleContentAssist(true); | ||
| if (assist) { | ||
| logger.step(4,'Selecting rest_class snippet'); | ||
| await assist.select('rest_class'); | ||
| await new Promise(res => setTimeout(res, 600)); // 300–800ms | ||
| logger.stepSuccess(4, 'rest_class snippet selected'); | ||
| } | ||
| await javaEditor.toggleContentAssist(false); | ||
|
|
||
| logger.step(5, 'Verifying snippet insertion'); | ||
| const codeInsertion = await javaEditor.getText(); | ||
| logger.info('Inserted code snapshot: ' + codeInsertion); | ||
|
mattbsox marked this conversation as resolved.
Outdated
|
||
| expect(codeInsertion).to.include('@GET') | ||
| expect(codeInsertion).to.include('methodname'); | ||
| logger.stepSuccess(5, 'Snippet rest_class was inserted correctly'); | ||
|
|
||
| logger.testComplete('rest_class snippet inserts correct REST class'); | ||
| } catch (error) { | ||
| logger.testFailed('rest_class snippet inserts correct REST class', error); | ||
| throw error; | ||
| } | ||
| }); | ||
| it('Show that private @GET method displays diagnostic and quick fix removes it ', async function () { | ||
| this.timeout(90000); | ||
|
sharma1208 marked this conversation as resolved.
|
||
| logger.testStart('Diagnostic for a private @GET method and quick fix clears it'); | ||
| try { | ||
| // Find the method with @GET and change it to private | ||
| let lineNum = await javaEditor.getLineOfText('methodname'); | ||
| if (lineNum < 1) throw new Error('Could not find the methodname line'); | ||
| const oldLine = await javaEditor.getTextAtLine(lineNum); | ||
| const newLine = oldLine.replace("public", "private"); | ||
| await javaEditor.setTextAtLine(lineNum, newLine); | ||
|
|
||
| // Save file and wait for reanalysis | ||
| await javaEditor.save(); | ||
| await wait.sleep(500); | ||
|
|
||
| // Open problems view | ||
| const bottomBar = new BottomBarPanel(); | ||
| await bottomBar.toggle(true); | ||
| let problemsView = await bottomBar.openProblemsView(); | ||
| let markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); | ||
|
|
||
| // Check if the marker is present | ||
| let found = false; | ||
| for (const marker of markers) { | ||
| const text = await marker.getText(); | ||
| // Check if text contains your diagnostic message | ||
| if(text.includes('Only public methods can be exposed as resource methods.')){ | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
| expect(found).to.be.true; | ||
| logger.testComplete('Diagnostic shows for private @GET method'); | ||
|
|
||
| // Quick fix implementation to get rid of diagnostic | ||
| // Re-find line and place cursor on "methodname()" | ||
| const buffer = await javaEditor.getText(); | ||
| logger.info('Buffer before quick fix: ' + JSON.stringify(buffer)); | ||
|
|
||
| // Get column on the method name | ||
| await javaEditor.selectText('methodname'); | ||
| await wait.sleep(300); | ||
|
|
||
| // Open the quick-fix menu with Cmd+. (Mac) / Ctrl+. (Linux/Windows) | ||
| const modKey = process.platform === 'darwin' ? Key.COMMAND : Key.CONTROL; | ||
| await driver.actions().keyDown(modKey).sendKeys('.').keyUp(modKey).perform(); | ||
| await wait.sleep(2000); | ||
|
|
||
| // Click on the option to make the method public within the quick-fixes options | ||
| const options = await driver.findElements(By.css('.action-widget .action-list-item, .action-widget .monaco-list-row')); | ||
| let clicked = false; | ||
| for (const opt of options) { | ||
| const text = await opt.getText(); | ||
| logger.info('OPTION: ' + JSON.stringify(text)); | ||
| if (text.toLowerCase().includes('make method public')) { | ||
| await driver.executeScript('arguments[0].click();', opt); | ||
| clicked = true; | ||
| break; | ||
| } | ||
| } | ||
| if (!clicked) { | ||
| await driver.actions().sendKeys(Key.ESCAPE).perform(); // close menu cleanly | ||
| throw new Error('No "make public" quick fix was offered — see OPTION logs above'); | ||
| } | ||
|
|
||
| await wait.sleep(3000); | ||
| await javaEditor.save(); | ||
| await wait.sleep(5000); | ||
|
|
||
| // Check quick fix was implemented at correct line number | ||
| const after = await javaEditor.getText(); | ||
| logger.info('Buffer after quick fix: ' + JSON.stringify(after)); | ||
| expect(after).to.include('public String methodname'); | ||
|
|
||
| problemsView = await bottomBar.openProblemsView(); | ||
| markers = await problemsView.getAllVisibleMarkers(MarkerType.Any); | ||
|
|
||
| // Check if the marker is present | ||
| let stillPresent = false; | ||
| for (const marker of markers) { | ||
| const text = await marker.getText(); | ||
| // Check if text contains diagnostic message | ||
| if(text.includes('Only public methods can be exposed as resource methods.')){ | ||
| stillPresent = true; | ||
| break; | ||
| } | ||
| } | ||
| expect(stillPresent).to.be.false; | ||
| logger.testComplete('Diagnostic no longer shows for public @GET method as expected'); | ||
|
|
||
| } catch (error) { | ||
| logger.testFailed('Diagnostic/quick-fix test flow failed', error); | ||
| throw error; | ||
| } | ||
|
|
||
| }); | ||
| }); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.