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

Issue#354 Test cases added to handle maven project - directory with space #365

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 23 additions & 0 deletions src/test/MavenTestDevModeActionsWSPathInit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import { WebDriver, VSBrowser } from 'vscode-extension-tester';
import * as utils from './utils/testUtils';



describe('Open Maven Project - path with space', () => {

let driver: WebDriver;


before(() => {
driver = VSBrowser.instance.driver;
utils.createMvnProjectPathWithSpace();
});

it('Open Sample Maven Project - path with space', async () => {
await VSBrowser.instance.openResources(utils.getMvnProjectDirWithSpace());

}).timeout(15000);


});
282 changes: 282 additions & 0 deletions src/test/MavenTestDevModeActionsWSPathTasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
import { expect } from 'chai';
import { InputBox, Workbench,SideBarView, ViewItem, ViewSection,EditorView, DefaultTreeItem , DebugView } from 'vscode-extension-tester';
import * as utils from './utils/testUtils';
import * as constants from './definitions/constants';
import path = require('path');

describe('Devmode action tests for Maven Project - path with space', () => {
let sidebar: SideBarView;
let debugView: DebugView;
let section: ViewSection;
let menu: ViewItem[];
let item: DefaultTreeItem;
let tabs: string[];

before(() => {
sidebar = new SideBarView();
debugView = new DebugView();
});


it('getViewControl works with the correct label', async() => {

const contentPart = sidebar.getContent();
section = await contentPart.getSection('Liberty Dashboard');
console.log("Found Liberty Dashboard....");
expect(section).not.undefined;

}).timeout(15000);


it('Open dasboard shows items - Maven', async () => {


await utils.delay(65000);
section.expand();
await utils.delay(6000);
const menu = await section.getVisibleItems();
expect(menu).not.empty;
item = await section.findItem(constants.MAVEN_PROJECT) as DefaultTreeItem;
expect(item).not.undefined;


}).timeout(275000);


it('Start maven project from liberty dashboard', async () => {


await utils.launchDashboardAction(item,constants.START_DASHBOARD_ACTION,constants.START_DASHBOARD_MAC_ACTION);
await utils.delay(30000);
const serverStartStatus = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
if(!serverStartStatus)
console.log("Server started message not found in the terminal");
else
{
console.log("Server succuessfully started");
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
console.error("Server stopped message not found in the terminal");
}
else
console.log("Server stopped successfully");
expect (serverStopStatus).to.be.true;
}
expect (serverStartStatus).to.be.true;


}).timeout(550000);

it('Run tests for sample maven project', async () => {

await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION, constants.START_DASHBOARD_MAC_ACTION);
await utils.delay(30000);
const serverStartStatus = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
console.log("after checkTerminalforServerState");
if(!serverStartStatus)
console.log("Server started message not found in the terminal");
else
{
console.log("Server succuessfully started");
await utils.launchDashboardAction(item,constants.RUNTEST_DASHBOARD_ACTION,constants.RUNTEST_DASHBOARD_MAC_ACTION);
const testStatus = await utils.checkTestStatus(constants.MAVEN_RUN_TESTS_STRING);
expect (testStatus).to.be.true;
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
console.error("Server stopped message not found in the terminal");
}
else
console.log("Server stopped successfully");
expect (serverStopStatus).to.be.true;
}
expect (serverStartStatus).to.be.true;


}).timeout(350000);


it('start maven with options from liberty dashboard', async () => {

const reportPath = path.join(utils.getMvnProjectDirWithSpace(),"target","site","failsafe-report.html");
const reportPath35 = path.join(utils.getMvnProjectDirWithSpace(),"target","reports","failsafe.html");
let deleteReport = await utils.deleteReports(reportPath);
let deleteReport35 = await utils.deleteReports(reportPath35);
expect (deleteReport||deleteReport35).to.be.true;
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
await utils.setCustomParameter("-DhotTests=true");
await utils.delay(30000);
const serverStartStatus = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
if(!serverStartStatus)
console.log("Server started with params message not found in terminal ");
else
{
console.log("Server succuessfully started");
let checkFile = await utils.checkIfTestReportExists(reportPath);
let checkFile35 = await utils.checkIfTestReportExists(reportPath35);
expect (checkFile || checkFile35).to.be.true;
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
console.error("Server stopped message not found in ther terminal");
}
else
console.log("Server stopped successfully");
expect (serverStopStatus).to.be.true;
}
expect (serverStartStatus).to.be.true;

}).timeout(350000);


it('start maven with history from liberty dashboard', async () => {

const reportPath = path.join(utils.getMvnProjectDirWithSpace(),"target","site","failsafe-report.html");
const reportPath35 = path.join(utils.getMvnProjectDirWithSpace(),"target","reports","failsafe.html");
let deleteReport = await utils.deleteReports(reportPath);
let deleteReport35 = await utils.deleteReports(reportPath35);
expect (deleteReport || deleteReport35).to.be.true;
await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
const foundCommand = await utils.chooseCmdFromHistory("-DhotTests=true");
expect (foundCommand).to.be.true;
await utils.delay(30000);
const serverStartStatus = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
if(!serverStartStatus)
console.log("Server started with params message not found in the terminal ");
else
{
console.log("Server succuessfully started");
let checkFile = await utils.checkIfTestReportExists(reportPath);
let checkFile35 = await utils.checkIfTestReportExists(reportPath35);
expect (checkFile || checkFile35).to.be.true;
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
console.error("Server stopped message not found in terminal");
}
else
console.log("Server stopped successfully");
expect (serverStopStatus).to.be.true;
}
expect (serverStartStatus).to.be.true;

}).timeout(550000);









it('View Unit test report for maven project', async () => {

await utils.launchDashboardAction(item,constants.UTR_DASHABOARD_ACTION, constants.UTR_DASHABOARD_MAC_ACTION);
tabs = await new EditorView().getOpenEditorTitles();
//expect (tabs[1], "Unit test report not found").to.equal(constants.SUREFIRE_REPORT_TITLE);
expect (tabs.indexOf(constants.SUREFIRE_REPORT_TITLE)>-1, "Unit test report not found").to.equal(true);

}).timeout(10000);

it('View Integration test report for maven project', async () => {

await utils.launchDashboardAction(item, constants.ITR_DASHBOARD_ACTION, constants.ITR_DASHBOARD_MAC_ACTION);
tabs = await new EditorView().getOpenEditorTitles();
//expect (tabs[2], "Integration test report not found").to.equal(constants.FAILSAFE_REPORT_TITLE);
expect (tabs.indexOf(constants.FAILSAFE_REPORT_TITLE)>-1, "Integration test report not found").to.equal(true);

}).timeout(10000);

it('attach debugger for start with custom parameter event', async () => {
console.log("start attach debugger");
let isServerRunning: Boolean = true;
let attachStatus: Boolean = false;
try {
await utils.launchDashboardAction(item,constants.START_DASHBOARD_ACTION_WITH_PARAM, constants.START_DASHBOARD_MAC_ACTION_WITH_PARAM);
await utils.setCustomParameter("-DdebugPort=7777");
await utils.delay(30000);

isServerRunning = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
if (!isServerRunning)
console.log("Server started with params message not found in terminal");
else {
console.log("Server succuessfully started");

await utils.launchDashboardAction(item,constants.ATTACH_DEBUGGER_DASHBOARD_ACTION, constants.ATTACH_DEBUGGER_DASHBOARD_MAC_ACTION);
console.log("Attach Debugger action done");
await utils.delay(8000);
const contentPart = debugView.getContent();
console.log("Get Content");

let mysecarry: Promise<ViewSection[]> = contentPart.getSections();
let mysecmap: IterableIterator<[number, ViewSection]> = (await mysecarry).entries();
for (const [key, value] of (mysecmap)) {
if ((await value.getEnclosingElement().getText()).includes("BREAKPOINTS")) {
//console.log("******** mysecmap getEnclosingElement " + (await value.getEnclosingElement().getText()).valueOf());
console.log("Found Breakpoints");
attachStatus = true;
break;
}
}

await utils.stopLibertyserver();
isServerRunning = !await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING); //negate isServerRunning
if (!isServerRunning)
console.log("Server stopped successfully ");
}
} catch (e) {
console.error("error - ", e)
} finally {
console.log("finally block: is server running - ", isServerRunning);
if (isServerRunning) {
utils.stopLibertyserver();
}
else
console.log("good to close test - Attach Debugger for start with custom parameter(-DdebugPort=7777) event");
}
expect(attachStatus).to.be.true;
}).timeout(350000);

it('start maven with docker from liberty dashboard', async () => {

if((process.platform === 'darwin' ) || (process.platform === 'win32') || (process.platform == 'linux'))
{
//skip running for platforms , enable them for linux after resolving docker setup in GHA
return true;
}


await utils.launchDashboardAction(item, constants.START_DASHBOARD_ACTION_WITHDOCKER, constants.START_DASHBOARD_MAC_ACTION_WITHDOCKER);
await utils.delay(60000);
const serverStartStatus = await utils.checkTerminalforServerState(constants.SERVER_START_STRING);
if(!serverStartStatus)
console.log("Server started message not found in the terminal");
else
{
console.log("Server succuessfully started");
await utils.launchDashboardAction(item, constants.STOP_DASHBOARD_ACTION, constants.STOP_DASHBOARD_MAC_ACTION);
const serverStopStatus= await utils.checkTerminalforServerState(constants.SERVER_STOP_STRING);
if(!serverStopStatus){
console.error("Server stopped message not found in the terminal");
}
else
console.log("Server stopped successfully");
expect (serverStopStatus).to.be.true;
}
expect (serverStartStatus).to.be.true;


}).timeout(350000);

after(() => {
const mavenProjectPath = path.join(__dirname,"..","..","src", "test","resources","maven project");
console.log("Current path __dirname"+ mavenProjectPath);
console.log("Project path to remove"+ mavenProjectPath);
utils.removeProjectFolder(mavenProjectPath);
console.log("Project removed from the path:"+ mavenProjectPath);
});

});

74 changes: 73 additions & 1 deletion src/test/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,76 @@ export async function clearCommandPalette() {
expect(buttons.length).equals(2);
await dialog.pushButton('Clear');
}

/**
* Function return project path with space
*/
export function getMvnProjectDirWithSpace(): any {

const mavenProjectPath = path.join(__dirname, "..","..","..","src", "test","resources","maven project", "liberty.maven.test.wrapper.app");

console.log("Maven project path is ",mavenProjectPath);
return mavenProjectPath;
}
/*
* Create new maven project with space in the directory
*/
export function createMvnProjectPathWithSpace(): void {
const existingMavenProjectPath = path.join(__dirname, "..","..","..","src", "test","resources");

const sourcepath=path.join(existingMavenProjectPath, 'maven');
const mavenProjectFolder = path.join(existingMavenProjectPath, 'maven project');

/* function will copy Maven project from existing Maven project */
copyDirectoryAndProject(sourcepath, mavenProjectFolder);
const mavenProjectPath = path.join(__dirname, "..","..","..","src", "test","resources","maven project", "liberty.maven.test.wrapper.app");
console.log("Maven project copy created - path: ",mavenProjectPath);

}
/**
* Function to create new folder and create a copy of the project
*/
async function copyDirectoryAndProject(src : string, dest : string){
try {
await fs.mkdirSync(dest, { recursive: true });

const projectFiles = await fs.readdirSync(src, { withFileTypes: true });

for (const projectFile of projectFiles) {
const srcPath = path.join(src, projectFile.name);
const destPath = path.join(dest, projectFile.name);

if (projectFile.isDirectory()) {
await copyDirectoryAndProject(srcPath, destPath);
} else {
await fs.copyFileSync(srcPath, destPath);
}
}
} catch (err) {
console.error(`Error copying project directory: ${err}`);
}
}
/**
* Remove newly created Project folder with content
*/

export async function removeProjectFolder(projectPath: string): Promise<void> {
try {
await fs.accessSync(projectPath);
const projectFiles = await fs.readdirSync(projectPath);
await Promise.all(
projectFiles.map(async (projectFile) => {
const projectFilePath = path.join(projectPath, projectFile);
const stats = await fs.lstatSync(projectFilePath);

if (stats.isDirectory()) {
await removeProjectFolder(projectFilePath);
} else {
await fs.unlinkSync(projectFilePath);
}
})
);
await fs.rmdirSync(projectPath);
} catch (error) {
console.error(`Error removing project folder: ${error}`);
}
}
Loading