Skip to content
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

Tests implementation liberty-ls support in server.xml for diagnostic and quickfix #377

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
08aefcd
code to open server.xml and entry for logging
SuparnaSuresh Nov 12, 2024
c1a82a4
code added for hover and quicfix
SuparnaSuresh Nov 14, 2024
121f17b
Code added to open server.xml
SuparnaSuresh Nov 18, 2024
2771093
Code Added for write text in server.xml
SuparnaSuresh Nov 18, 2024
80d8e87
Code for hover data
SuparnaSuresh Nov 18, 2024
01d668f
Code for quick fix
SuparnaSuresh Nov 18, 2024
3f5e62f
Code formatted
SuparnaSuresh Nov 18, 2024
dbba2a0
removed unwanted code
SuparnaSuresh Nov 18, 2024
3e4affe
Copyright and docuementation
SuparnaSuresh Nov 18, 2024
883f757
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Nov 18, 2024
150019c
Renamed file
SuparnaSuresh Nov 20, 2024
7fdc278
Renamed file to GradleSingleModLCLSTest
SuparnaSuresh Nov 20, 2024
108bfd5
added code to update the old content
SuparnaSuresh Nov 20, 2024
f238c52
updated quick fix element name
SuparnaSuresh Nov 21, 2024
41114d8
Timeout value updated
SuparnaSuresh Nov 21, 2024
fab341b
Timeout value updated
SuparnaSuresh Nov 21, 2024
26b5cdb
GHA build fix - timeout value updated
SuparnaSuresh Nov 21, 2024
8986c67
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Nov 21, 2024
7c60cd8
Added mpHealth
SuparnaSuresh Nov 25, 2024
e7490fa
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Nov 25, 2024
13498f5
await added for find element
SuparnaSuresh Nov 25, 2024
7ee5da3
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Dec 4, 2024
499247d
updated server.xml file
SuparnaSuresh Dec 4, 2024
9c3b83a
updated - added code for new config folder
SuparnaSuresh Dec 4, 2024
4d2fa91
updated the function removeConfigDir
SuparnaSuresh Dec 4, 2024
3515049
server.env file added
SuparnaSuresh Dec 5, 2024
e320f4d
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Dec 6, 2024
a582ac6
GHA build failure - Increased timeout value
SuparnaSuresh Dec 6, 2024
b193cc5
Added test case to coppy server.xml content
SuparnaSuresh Dec 6, 2024
288d1e0
Diagnostic server.xml test case added
SuparnaSuresh Dec 9, 2024
4492afc
updated test case
SuparnaSuresh Dec 9, 2024
45f2c84
changed server.xml path
SuparnaSuresh Dec 9, 2024
2cdd24d
Merge branch 'OpenLiberty:main' into issue124-AutomatedTestcaseLCLS
SuparnaSuresh Dec 16, 2024
80d2951
addressed review comment
SuparnaSuresh Jan 15, 2025
a3ffad9
addressed review comments
SuparnaSuresh Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 122 additions & 0 deletions src/test/GradleSingleModLCLSTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Copyright (c) 2024 IBM Corporation.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
import { By, EditorView, SideBarView, TextEditor, VSBrowser } from "vscode-extension-tester";
import * as utils from './utils/testUtils';
import * as constants from './definitions/constants';

const path = require('path');
const assert = require('assert');

describe('LCLS tests for Gradle Project', function () {
let editor: TextEditor;
let actualSeverXMLContent: string;

before(() => {
utils.copyConfig(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config'), path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2'));
});

it('Should copy content of server.xml', async () => {
const section = await new SideBarView().getContent().getSection(constants.GRADLE_PROJECT);
section.expand();
await VSBrowser.instance.openResources(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2', 'server.xml'));

editor = await new EditorView().openEditor('server.xml') as TextEditor;
actualSeverXMLContent = await editor.getText();

assert(actualSeverXMLContent.length !== 0, 'Content of server.xml is not in copied.');
console.log('Sever.xml content:', actualSeverXMLContent);

}).timeout(10000);

it('Should show diagnostic for server.xml invalid value', async () => {

await VSBrowser.instance.openResources(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2', 'server.xml'));
editor = await new EditorView().openEditor('server.xml') as TextEditor;

const hverExpectdOutcome = `'wrong' is not a valid value of union type 'booleanType'.`;
const testHverTarget = '<logging appsWriteJson = \"wrong\" />';

await editor.typeTextAt(17, 5, testHverTarget);
const focusTargtElemnt = editor.findElement(By.xpath("//*[contains(text(), 'wrong')]"));
await utils.delay(3000);
focusTargtElemnt.click();
await editor.click();

const actns = VSBrowser.instance.driver.actions();
await actns.move({ origin: focusTargtElemnt }).perform();
await utils.delay(5000);

const hverContent = editor.findElement(By.className('hover-contents'));
const hverValue = await hverContent.getText();
console.log("Hover text:" + hverValue);

assert(hverValue.includes(hverExpectdOutcome), 'Did not get expected diagnostic in server.xml');

editor.clearText();
editor.setText(actualSeverXMLContent);
console.log("Content restored");

}).timeout(35000);

it('Should apply quick fix for invalid value in server.xml', async () => {
const section = await new SideBarView().getContent().getSection(constants.GRADLE_PROJECT);
section.expand();
await VSBrowser.instance.openResources(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2', 'server.xml'));

editor = await new EditorView().openEditor('server.xml') as TextEditor;
const stanzaSnipet = "<logging appsWriteJson = \"wrong\" />";
const expectedHoverData = "<logging appsWriteJson = \"true\" />";
await editor.typeTextAt(17, 5, stanzaSnipet);
await utils.delay(2000);
const flagedString = await editor.findElement(By.xpath("//*[contains(text(), '\"wrong\"')]"));
await utils.delay(7000);

const actions = VSBrowser.instance.driver.actions();
await actions.move({ origin: flagedString }).perform();
await utils.delay(3000);

const driver = VSBrowser.instance.driver;
const hoverTxt = await editor.findElement(By.className('hover-row status-bar'));
await utils.delay(2000);

const qckFixPopupLink = await hoverTxt.findElement(By.xpath("//*[contains(text(), 'Quick Fix')]"));
await qckFixPopupLink.click();

const hoverTaskBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed'));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is hoverTaskBar required? There is no actionable task performed by hoverTaskBar. It seems that removing below two lines does not affect the test. Kindly confirm.

await hoverTaskBar.findElement(By.className('actionList'));
await utils.delay(2000);

const pointerBlockedElement = await driver.findElement(By.css('.context-view-pointerBlock'));
// Setting pointer block element display value as none to choose option from Quickfix menu
if (pointerBlockedElement) {
await driver.executeScript("arguments[0].style.display = 'none';", pointerBlockedElement);
} else {
console.log('pointerBlockElementt not found!');
}
const qckfixOption = await editor.findElement(By.xpath("//*[contains(text(), \"Replace with 'true'\")]"));
await qckfixOption.click();

const updatedSeverXMLContent = await editor.getText();
await utils.delay(3000);
console.log("Content after Quick fix : ", updatedSeverXMLContent);
assert(updatedSeverXMLContent.includes(expectedHoverData), 'Quick fix not applied correctly for the invalid value in server.xml.');

editor.clearText();
editor.setText(actualSeverXMLContent);
console.log("Content restored");

}).timeout(38000);

after(() => {
utils.removeConfigDir(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2'));
console.log("Removed new config folder:");
});

});
34 changes: 34 additions & 0 deletions src/test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MAVEN_PROJECT, STOP_DASHBOARD_MAC_ACTION } from '../definitions/consta
import { MapContextMenuforMac } from './macUtils';
import clipboard = require('clipboardy');
import { expect } from 'chai';
import * as fse from 'fs-extra';

export function delay(millisec: number) {
return new Promise( resolve => setTimeout(resolve, millisec) );
Expand Down Expand Up @@ -192,4 +193,37 @@ export async function clearCommandPalette() {
expect(buttons.length).equals(2);
await dialog.pushButton('Clear');
}

/**
* Remove newly created Project folder with content
*/
export async function removeConfigDir(projectPath: string): Promise<void> {
try {
fs.accessSync(projectPath);
const projectContent = fs.readdirSync(projectPath);
await Promise.all(
projectContent.map(async (projectFiles) => {
const projectContentPath = path.join(projectPath, projectFiles);
const stats = fs.lstatSync(projectContentPath);
if (stats.isDirectory()) {
await removeConfigDir(projectContentPath);
} else {
fs.unlinkSync(projectContentPath);
}
})
);
fs.rmdirSync(projectPath);
} catch (error) {
console.error(`Error removing new project: ${error}`);
}
}

/**
* Copy config directory and create new config
*/
export async function copyConfig(existingConfigPath: string, copyConfigPath: string): Promise<void> {
fse.copy(existingConfigPath, copyConfigPath)
.then(() => console.log("New config folder created :" + copyConfigPath))
.catch(err => console.log("Error creating config folder"));
}

Loading