diff --git a/src/test/GradleSingleModLCLSTest.ts b/src/test/GradleSingleModLCLSTest.ts new file mode 100755 index 00000000..19c32fb9 --- /dev/null +++ b/src/test/GradleSingleModLCLSTest.ts @@ -0,0 +1,470 @@ +/** + * Copyright (c) 2025 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, 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 actualServerXMLContent: string; + + before(() => { + utils.copyDirectoryByPath(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config'), path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2')); + }); + + it('Should copy content of server.xml', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + actualServerXMLContent = await editor.getText(); + assert(actualServerXMLContent.length !== 0, 'Content of server.xml is not in copied.'); + console.log('Sever.xml content is:', actualServerXMLContent); + + }).timeout(30000); + + it('Should show diagnostic for server.xml invalid value', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML); + + await editor.typeTextAt(17, 5, constants.TARGETED_VALUE_LOGGING); + const focusTargetedElement = editor.findElement(By.xpath(constants.FOCUS_WRONG)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const hoverContents = editor.findElement(By.className('hover-contents')); + const hoverFoundOutcome = await hoverContents.getText(); + console.log("Hover text is:" + hoverFoundOutcome); + + assert(hoverFoundOutcome.includes(constants.EXPECTED_OUTCOME_WRONG), 'Did not get expected diagnostic in server.xml'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("server.xml content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(38000); + + it('Should apply quick fix for invalid value in server.xml', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(17, 5, constants.TARGETED_VALUE_LOGGING); + await utils.delay(2000); + const hoverTargetValue = await editor.findElement(By.xpath(constants.FOCUS_WRONG)); + await utils.delay(7000); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: hoverTargetValue }).perform(); + await utils.delay(3000); + + const driver = VSBrowser.instance.driver; + const hoverRowStatusBar = await editor.findElement(By.className('hover-row status-bar')); + await utils.delay(2000); + + const quickFixPopupLink = await hoverRowStatusBar.findElement(By.xpath(constants.FOCUS_QUICKFIX)); + await quickFixPopupLink.click(); + + const hoverWindowTaskBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed')); + await hoverWindowTaskBar.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('pointerBlockElement is not found!'); + } + const quickfixOptionValues = await editor.findElement(By.xpath(constants.LOGGING_TRUE)); + await quickfixOptionValues.click(); + + const updatedSeverXMLContent = await editor.getText(); + await utils.delay(3000); + console.log("Content after Quick fix is: ", updatedSeverXMLContent); + assert(updatedSeverXMLContent.includes(constants.SNIPPET_LOGGING), 'Quick fix is not applied correctly for the invalid value in server.xml.'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("server.xml content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show hover support for server.xml Liberty Server Attribute', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML); + + const focusTargetedElement = editor.findElement(By.xpath(constants.FOCUS_HTTPENDPOINT)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const hoverContent = editor.findElement(By.className('hover-contents')); + const hoveredTextValue = await hoverContent.getText(); + console.log("Hover text is: " + hoveredTextValue); + + assert(hoveredTextValue.includes(constants.DESCRIPTION_HTTPENDPOINT), 'Did not get expected hover data Liberty for Server Attribute.'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("server.xml content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show hover support for server.xml Liberty Server Feature', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML); + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await utils.delay(1000); + await editor.typeTextAt(16, 9, constants.FEATURE_MPHEALTH); + const focusTargetElement = editor.findElement(By.xpath(constants.FOCUS_MPHEALTH)); + await utils.delay(3000); + focusTargetElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetElement }).perform(); + await utils.delay(5000); + + const hoverContents = editor.findElement(By.className('hover-contents')); + const hoveredValue = await hoverContents.getText(); + console.log("Hover text is :" + hoveredValue); + + assert(hoveredValue.includes(constants.DESCRIPTION_MPHEALTH), 'Did not get expected hover data for Liberty Server Feature.'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("server.xml content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show type ahead support in server.xml Liberty Server Feature', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML); + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + const featureTag = " { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML); + + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + const stanzaSnippet = "log"; + + await editor.typeTextAt(17, 5, stanzaSnippet); + await utils.delay(5000); + //open the assistant + await utils.callAssitantAction(editor, constants.LOGGING) + + // close the assistant + await editor.toggleContentAssist(false); + + const updatedServerxmlContent = await editor.getText(); + await utils.delay(3000); + console.log("Updated content in Sever.xml : ", updatedServerxmlContent); + assert(updatedServerxmlContent.includes(constants.LOGGING_TAG), 'Type ahead support is not worked as expected in server.xml for Liberty Server Configuration Stanza'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("server.xml content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show hover text in server.xml for server platform', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.PLATFORM_JAKARTA_VALUE); + await utils.delay(2000); + const focusTargetedElement = await editor.findElement(By.xpath(constants.FOCUS_JAKARTA)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const hoverContents = editor.findElement(By.className('hover-contents')); + const hoverValue = await hoverContents.getText(); + console.log("Hover text is:" + hoverValue); + + assert(hoverValue.includes(constants.DESCRIPTION_PLATFORM), 'Did not get expected hover text in server.xml for server platform'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show diagnostic for invalid value in server.xml for server platform', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.PLATFORM_JAKARTA); + await utils.delay(2000); + const focusTargetedElement = await editor.findElement(By.xpath(constants.FOCUS_JAKARTA)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const hoverContents = editor.findElement(By.className('hover-contents')); + const hoverValue = await hoverContents.getText(); + console.log("Hover text is:" + hoverValue); + + assert(hoverValue.includes(constants.PLATFORM_JAKARTA_ERROR), 'Did not get expected diagnostic in server.xml for server platform'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should apply quick fix for invalid value in server.xml for server platform', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.PLATFORM_JAKARTA); + await utils.delay(2000); + const flaggedString = await editor.findElement(By.xpath(constants.FOCUS_JAKARTA)); + await utils.delay(7000); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: flaggedString }).perform(); + await utils.delay(3000); + + const driver = VSBrowser.instance.driver; + const hoverRowStatusBar = await editor.findElement(By.className('hover-row status-bar')); + await utils.delay(2000); + + const quickFixPopupLink = await hoverRowStatusBar.findElement(By.xpath(constants.FOCUS_QUICKFIX)); + await quickFixPopupLink.click(); + + const hoverTaskBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed')); + 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('PointerBlockedElement is not found!'); + } + const quickfixOption = await editor.findElement(By.xpath(constants.FOCUS_JAKARTA_ELEVEN)); + await quickfixOption.click(); + + const updatedSeverXMLContent = await editor.getText(); + await utils.delay(3000); + console.log("Content after Quick fix : ", updatedSeverXMLContent); + assert(updatedSeverXMLContent.includes(constants.PLATFORM_JAKARTA_VALUE), 'Quick fix not applied correctly for the invalid value in server.xml for server platform.'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show diagnostic for invalid value in server.xml for server feature', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.FEATURE_SERVLET); + await utils.delay(2000); + const focusTargetedElement = await editor.findElement(By.xpath(constants.FOCUS_SERVLET)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const hoverContents = editor.findElement(By.className('hover-contents')); + const hoverValue = await hoverContents.getText(); + console.log("Hover text is:" + hoverValue); + + assert(hoverValue.includes(constants.SERVLET_ERROR), 'Did not get expected diagnostic in server.xml for server feature'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should apply quick fix for invalid value in server.xml for server feature', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.FEATURE_SERVLET); + await utils.delay(2000); + const flaggedString = await editor.findElement(By.xpath(constants.FOCUS_SERVLET)); + await utils.delay(7000); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: flaggedString }).perform(); + await utils.delay(3000); + + const driver = VSBrowser.instance.driver; + const hoverRowStatusBar = await editor.findElement(By.className('hover-row status-bar')); + await utils.delay(2000); + + const quickFixPopupLink = await hoverRowStatusBar.findElement(By.xpath(constants.FOCUS_QUICKFIX)); + await quickFixPopupLink.click(); + + const hoverTaskBar = await editor.findElement(By.className('context-view monaco-component bottom left fixed')); + 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('PointerBlockElement is not found!'); + } + const quickfixOption = await editor.findElement(By.xpath(constants.FOCUS_SERVLET_VALUE)); + await quickfixOption.click(); + + const updatedSeverXMLContent = await editor.getText(); + await utils.delay(3000); + console.log("Content after Quick fix is: ", updatedSeverXMLContent); + assert(updatedSeverXMLContent.includes(constants.SERVLET_VALUE), 'Quick fix is not applied correctly for the invalid value in server.xml for server feature.'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + it('Should show type ahead support in server.xml Liberty Server platform', async () => { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + const featureTag = " { + await utils.openConfigFile(constants.CONFIG_TWO, constants.SERVER_XML) + editor = await new EditorView().openEditor(constants.SERVER_XML) as TextEditor; + + await editor.typeTextAt(15, 35, constants.NEWLINE); + await editor.typeTextAt(16, 9, constants.FEATURE_SERVLET); + await utils.delay(2000); + const focusTargetedElement = await editor.findElement(By.xpath(constants.FOCUS_SERVLET)); + await utils.delay(3000); + focusTargetedElement.click(); + await editor.click(); + + const driverActionList = VSBrowser.instance.driver.actions(); + await driverActionList.move({ origin: focusTargetedElement }).perform(); + await utils.delay(5000); + + const holverContents = editor.findElement(By.className('hover-contents')); + const hoverValue = await holverContents.getText(); + console.log("Hover text is:" + hoverValue); + if (hoverValue.includes(constants.SERVLET_ERROR)) { + await editor.typeTextAt(16, 35, constants.NEWLINE); + await editor.typeTextAt(17, 9, constants.PLATFORM_JAKARTA_NINE); + await utils.delay(2000); + } + const updatedServerxmlContent = await editor.getText(); + console.log("Updated server.xml content is:" + updatedServerxmlContent); + + assert(updatedServerxmlContent.includes(constants.FEATURE_SERVLET) && updatedServerxmlContent.includes(constants.PLATFORM_JAKARTA_NINE), 'Did not get expected entries in server.xml for versionless combination for server feature and platform'); + + editor.clearText(); + editor.setText(actualServerXMLContent); + console.log("Content is restored"); + await utils.closeEditor(constants.SERVER_XML); + + }).timeout(45000); + + after(() => { + utils.removeDirectoryByPath(path.join(utils.getGradleProjectPath(), 'src', 'main', 'liberty', 'config2')); + console.log("Removed new config folder:"); + }); + +}); \ No newline at end of file diff --git a/src/test/definitions/constants.ts b/src/test/definitions/constants.ts index d421e824..08f63190 100755 --- a/src/test/definitions/constants.ts +++ b/src/test/definitions/constants.ts @@ -1,3 +1,4 @@ + /** * Copyright (c) 2020, 2022 IBM Corporation. * @@ -9,7 +10,7 @@ */ export const MAVEN_PROJECT = "liberty.maven.test.wrapper.app"; -export const GRADLE_PROJECT= "liberty.gradle.test.wrapper.app"; +export const GRADLE_PROJECT = "liberty.gradle.test.wrapper.app"; export const START_DASHBOARD_ACTION = "Start"; export const STOP_DASHBOARD_ACTION = "Stop"; export const START_DASHBOARD_MAC_ACTION = "Liberty: Start"; @@ -37,6 +38,68 @@ export const GRADLE_TEST_REPORT_TITLE = "liberty.gradle.test.wrapper.app test re export const ATTACH_DEBUGGER_DASHBOARD_ACTION = "Attach debugger"; export const ATTACH_DEBUGGER_DASHBOARD_MAC_ACTION = "Liberty: Attach debugger"; /** Maven: Dev mode debug port argument key. */ -export const MAVEN_DEVMODE_DEBUG_PORT_PARM = "-DdebugPort"; +export const MAVEN_DEVMODE_DEBUG_PORT_PARM = "-DdebugPort"; /** Gradle: Dev mode debug port argument key. */ export const GRADLE_DEVMODE_DEBUG_PORT_PARM = "--libertyDebugPort"; +export const CONFIG = "config"; +export const CONFIG_TWO = "config2"; +export const BOOTSTRAP_PROPERTIES = "bootstrap.properties"; +export const SERVER_XML = "server.xml"; +export const SERVER_ENV = "server.env"; +export const CLOSE_EDITOR = "View: Close Editor"; +export const CONFIRM_MESSAGES = { + [SERVER_XML]: 'Do you want to save the changes you made to server.xml?', + [SERVER_ENV]: 'Do you want to save the changes you made to server.env?', + [BOOTSTRAP_PROPERTIES]: 'Do you want to save the changes you made to bootstrap.properties?' +}; +export const EXPECTED_OUTCOME_WRONG = "'wrong' is not a valid value of union type 'booleanType'."; +export const TARGETED_VALUE_LOGGING = ''; +export const FOCUS_WRONG = "//*[contains(text(), 'wrong')]"; +export const SNIPPET_LOGGING = ""; +export const FOCUS_QUICKFIX = "//*[contains(text(), 'Quick Fix')]"; +export const LOGGING_TRUE = "//*[contains(text(), \"Replace with 'true'\")]"; +export const FOCUS_HTTPENDPOINT = "//*[contains(text(), 'httpEndpoint')]"; +export const FOCUS_MPHEALTH = "//*[contains(text(), 'mpHealth')]"; +export const FEATURE_MPHEALTH = 'mpHealth-4.0'; +export const NEWLINE = '\n'; +export const DESCRIPTION_MPHEALTH = "Description: This feature provides support for the MicroProfile Health specification."; +export const DESCRIPTION_HTTPENDPOINT = `Configuration properties for an HTTP endpoint.`; +export const FEATURE_EL = "el-3.0"; +export const LOGGING_TAG = ""; +export const LOGGING = 'logging'; +export const FEATURE_TAG = 'feature'; +export const EL_VALUE = 'el-3.0'; +export const PLATFORM_JAKARTA_VALUE = "jakartaee-11.0"; +export const DESCRIPTION_PLATFORM = `Description: This platform resolves the Liberty features that support the Jakarta EE 11.0 platform.`; +export const FOCUS_JAKARTA = "//*[contains(text(), '\jakarta\')]"; +export const PLATFORM_JAKARTA = "jakarta"; +export const PLATFORM_JAKARTA_ERROR = `ERROR: The platform "jakarta" does not exist.`; +export const FOCUS_JAKARTA_ELEVEN = "//*[contains(text(), \"Replace platform with jakartaee-11.0\")]"; +export const FEATURE_SERVLET = "servlet"; +export const SERVLET_ERROR = `ERROR: The "servlet" versionless feature cannot be resolved since there are more than one common platform. Specify a platform or a feature with a version to enable resolution`; +export const FOCUS_SERVLET = "//*[contains(text(), '\servlet\')]"; +export const SERVLET_VALUE = "servlet-3.1"; +export const FOCUS_SERVLET_VALUE = "//*[contains(text(), \"Replace feature with servlet-3.1\")]"; +export const PLATFORM = "platform"; +export const JAKARTA_ELEVEN = 'jakartaee-11.0'; +export const PLATFORM_JAKARTA_NINE = "jakartaee-9.1"; +export const WLP_LOGGING_CONSOLE_FORMAT = 'WLP_LOGGING_CONSOLE_FORMAT'; +export const CONSOLE_FORMAT_TBASIC = 'WLP_LOGGING_CONSOLE_FORMAT=TBASIC'; +export const TBASIC = 'TBASIC'; +export const TBA = "=TBA"; +export const WLP_LOGGING_CON = 'WLP_LOGGING_CON'; +export const LOG_LEVEL_INFO_MSG = 'This setting controls the granularity of messages that go to the console. The valid values are INFO, AUDIT, WARNING, ERROR, and OFF. The default is AUDIT. If using with the Eclipse developer tools this must be set to the default.'; +export const FOCUS_LOGLEVEL = "//*[contains(text(), 'CONSOLE_LOGLEVEL')]"; +export const LOGLEVEL_WITH_VALUE = 'WLP_LOGGING_CONSOLE_LOGLEVEL=OFF'; +export const CONSOLE_FORMAT_DIAGNOSTIC = 'The value `sample_value_is_updating_as_nodata` is not valid for the variable `WLP_LOGGING_CONSOLE_FORMAT`.'; +export const FOCUS_NODATA = "//*[contains(text(), 'nodata')]"; +export const VALUE_NODATA = '=sample_value_is_updating_as_nodata'; +export const WS_LOGGING_CON = "com.ibm.ws.logging.con"; +export const VALUE_WRONG = "=wrong"; +export const WS_LOGGING_CONSOLE_FORMAT = "com.ibm.ws.logging.console.format"; +export const WS_LOGGING_CONSOLE_DIAGNOSTIC = "The value `wrong` is not valid for the property `com.ibm.ws.logging.console.format`."; +export const WS_LOGGING_CONSOLE_VALUE = "com.ibm.ws.logging.console.log.level=OFF"; +export const FOCUS_WS_LOGLEVEL = "//*[contains(text(), 'ws.logging.console.log.level')]"; +export const WS_LOGLEVEL_TBASIC = 'com.ibm.ws.logging.trace.format=TBASIC'; +export const WS_LOG_TRACE_FORMAT = 'com.ibm.ws.logging.trace.format'; +export const WS_LOGGING_T = "com.ibm.ws.logging.t"; \ No newline at end of file diff --git a/src/test/resources/gradle/liberty.gradle.test.wrapper.app/src/main/liberty/config/server.env b/src/test/resources/gradle/liberty.gradle.test.wrapper.app/src/main/liberty/config/server.env new file mode 100644 index 00000000..e69de29b diff --git a/src/test/utils/testUtils.ts b/src/test/utils/testUtils.ts index 0e5f6a33..21639750 100755 --- a/src/test/utils/testUtils.ts +++ b/src/test/utils/testUtils.ts @@ -1,10 +1,11 @@ import path = require('path'); -import { Workbench, InputBox, DefaultTreeItem, ModalDialog } from 'vscode-extension-tester'; +import { Workbench, InputBox, DefaultTreeItem, ModalDialog, SideBarView, VSBrowser, TextEditor } from 'vscode-extension-tester'; import * as fs from 'fs'; -import { STOP_DASHBOARD_MAC_ACTION } from '../definitions/constants'; +import * as constants from '../definitions/constants'; 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) ); @@ -171,7 +172,7 @@ export function getMvnProjectPath(): string { export async function stopLibertyserver(projectName: string) { console.log("Stop Server action for Project : " + projectName); const workbench = new Workbench(); - await workbench.executeCommand(STOP_DASHBOARD_MAC_ACTION); + await workbench.executeCommand(constants.STOP_DASHBOARD_MAC_ACTION); const input = InputBox.create(); (await input).clear(); (await input).setText(projectName); @@ -193,4 +194,86 @@ export async function clearCommandPalette() { await dialog.pushButton('Clear'); } - \ No newline at end of file +/** + * + * @param projectPath + * Remove specific directory with contents + */ +export async function removeDirectoryByPath(dirPath: string): Promise { + try { + fs.accessSync(dirPath); + const dirContent = fs.readdirSync(dirPath); + await Promise.all( + dirContent.map(async (dirFiles) => { + const projectContentPath = path.join(dirPath, dirFiles); + const stats = fs.lstatSync(projectContentPath); + if (stats.isDirectory()) { + await removeDirectoryByPath(projectContentPath); + } else { + fs.unlinkSync(projectContentPath); + } + }) + ); + fs.rmdirSync(dirPath); + } catch (error) { + console.error(`Error removing directory: ${error}`); + } +} + +/** + * + * @param existingConfigPath + * @param copyConfigPath + * Copy a specific directory + */ +export async function copyDirectoryByPath(existingDirPath: string, copyDirPath: string): Promise { + fse.copy(existingDirPath, copyDirPath) + .then(() => console.log("Folder content copied :" + copyDirPath)) + .catch(err => console.log("Error occuried while copying content")); +} + +/** + * + * @param parentDir + * @param configFileName + * Open specific config file from parent directory + */ +export async function openConfigFile(parentDir: string, configFileName: string) { + const section = await new SideBarView().getContent().getSection(constants.GRADLE_PROJECT); + section.expand(); + await VSBrowser.instance.openResources(path.join(getGradleProjectPath(), 'src', 'main', 'liberty', parentDir, configFileName)); +} + +/** + * Function to close currently opened config file tab + */ +export async function closeEditor(fileType: string) { + const workbench = new Workbench(); + await workbench.openCommandPrompt(); + await delay(3000); + await workbench.executeCommand(constants.CLOSE_EDITOR); + await delay(3000); + const dialog = new ModalDialog(); + const message = await dialog.getMessage(); + + if (fileType in constants.CONFIRM_MESSAGES) { + expect(message).contains(constants.CONFIRM_MESSAGES[fileType as keyof typeof constants.CONFIRM_MESSAGES]); + } + const buttons = await dialog.getButtons(); + expect(buttons.length).equals(3); + await dialog.pushButton('Don\'t Save'); +} +/** + * + * @param editor + * @param selectValue + * Function to call toggle assistant to select value from suggestion list + */ +export async function callAssitantAction(editor: TextEditor, selectValue: string) { + let assist = await editor.toggleContentAssist(true); + // toggle can return void, so we need to make sure the object is present + if (assist) { + // to select an item use + await assist.select(selectValue); + } +} \ No newline at end of file