Skip to content

Commit

Permalink
Verifying number of rules when uploading file (#1232)
Browse files Browse the repository at this point in the history
* Verifying number of rules when uploading file

Signed-off-by: Maayan Hadasi <[email protected]>

* Changes after review

Signed-off-by: Maayan Hadasi <[email protected]>

* Mark test with bug number

Signed-off-by: Maayan Hadasi <[email protected]>

---------

Signed-off-by: Maayan Hadasi <[email protected]>
  • Loading branch information
mguetta1 authored Oct 1, 2024
1 parent 0a29cbd commit 532ff47
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 7 deletions.
25 changes: 25 additions & 0 deletions cypress/e2e/models/migration/applicationinventory/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import {
languageSelectionDropdown,
manageCredentials,
mavenCredential,
numberOfRulesColumn,
openjdkToggleButton,
panelBody,
rightSideMenu,
Expand Down Expand Up @@ -112,6 +113,7 @@ export class Analysis extends Application {
information?: number;
total?: number;
};
ruleFileToQuantity?: { [id: string]: number };

constructor(appData: applicationData, analysisData: analysisData) {
super(appData);
Expand All @@ -138,6 +140,7 @@ export class Analysis extends Application {
openSourceLibraries,
customRuleRepository,
language,
ruleFileToQuantity,
} = analysisData;
this.name = appData.name;
this.source = source;
Expand All @@ -158,6 +161,7 @@ export class Analysis extends Application {
if (incidents) this.incidents = incidents;
if (openSourceLibraries) this.openSourceLibraries = openSourceLibraries;
if (language) this.language = language;
if (ruleFileToQuantity) this.ruleFileToQuantity = ruleFileToQuantity;
}

public selectSourceofAnalysis(source: string): void {
Expand Down Expand Up @@ -533,4 +537,25 @@ export class Analysis extends Application {
}
cy.get(closeWizard).click({ force: true });
}

// verifyRulesNumber verifies the number of rules found in an uploaded custom rules file
public verifyRulesNumber(): void {
Application.open();
this.selectApplication();
cy.contains(button, analyzeButton).should("be.enabled").click();
this.selectSourceofAnalysis(this.source);
next();
next();
next();
this.uploadCustomRule();
for (let fileName in this.numberOfRules) {
const numOfrules = this.numberOfRules[fileName];
cy.get(trTag)
.filter(':contains("' + fileName + '")')
.within(() => {
cy.get(numberOfRulesColumn).contains(numOfrules.toString());
});
}
cy.get(closeWizard).click({ force: true });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ import { deleteByList } from "../../../../../utils/utils";
import { CredentialsMaven } from "../../../../models/administration/credentials/credentialsMaven";
import { Application } from "../../../../models/migration/applicationinventory/application";

describe(["@tier2"], "Bug MTA-2015: Custom Rules in analyses", function () {
describe(["@tier2"], "Custom Rules in analyses", function () {
const applications: Analysis[] = [];
let tackleTestappName: string;
let tackleTestapp: Analysis;
let sourceCredential: CredentialsSourceControlUsername;
let mavenCredential: CredentialsMaven;

Expand Down Expand Up @@ -95,14 +95,14 @@ describe(["@tier2"], "Bug MTA-2015: Custom Rules in analyses", function () {
});

// Automates Bug MTA-2001
it("Verify triggered rule for dependency", function () {
it("Bug MTA-3863: Verify triggered rule for dependency", function () {
const app = new Analysis(
getRandomApplicationData("tackle-testapp-custom-rules", {
sourceData: this.appData["tackle-testapp-git"],
}),
getRandomAnalysisData(this.analysisData["tackle_test_app_custom_rules"])
);
tackleTestappName = app.name;
tackleTestapp = app;
Application.open();
applications.push(app);
app.create();
Expand All @@ -115,10 +115,15 @@ describe(["@tier2"], "Bug MTA-2015: Custom Rules in analyses", function () {

// Automates Bug MTA-2000
it("Verify triggered rule for javax.* package import", function () {
Issues.openSingleApplication(tackleTestappName);
Issues.openSingleApplication(tackleTestapp.name);
exists("CUSTOM RULE for javax.* package import");
});

// Automates Bug MTA-2003
it("Verify number of rules detected in uploaded yaml file", function () {
tackleTestapp.verifyRulesNumber();
});

it("Verify a file is not a valid XML", function () {
const app = new Analysis(
getRandomApplicationData("tackle-testapp-fileNotValidXML", {
Expand All @@ -127,6 +132,7 @@ describe(["@tier2"], "Bug MTA-2015: Custom Rules in analyses", function () {
getRandomAnalysisData(this.analysisData["tackle_testapp_fileNotValidXML"])
);
app.create();
applications.push(app);
app.verifyFileNotValidXML();
});

Expand All @@ -137,7 +143,6 @@ describe(["@tier2"], "Bug MTA-2015: Custom Rules in analyses", function () {
}),
getRandomAnalysisData(this.analysisData["python_demo_application"])
);
tackleTestappName = app.name;
applications.push(app);
app.create();
app.analyze();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export type analysisData = {
total?: number;
};
techTags?: string[][];
ruleFileToQuantity?: { [id: string]: number };
};

export type UserData = {
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/views/analysis.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ export const codeEditorControls = "div.pf-v5-c-code-editor__controls";
export const menuToggle = "button.pf-v5-c-menu-toggle";
export const menuList = "div.pf-v5-c-menu";
export const languageSelectionDropdown = "#filter-control-name-Languages";
export const numberOfRulesColumn = "td[data-label='Number of rules']";
6 changes: 5 additions & 1 deletion cypress/fixtures/analysis.json
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@
},
"upload_binary_analysis_on_jee_app_custom_rules": {
"source": "Upload a local binary",
"target": ["Application server migration"],
"target": ["Application server migration to"],
"binary": ["jee-example-app-1.0.0.ear"],
"customRule": ["hibernate-custom.windup.xml"],
"appName": "jee-example-app custom rules"
Expand All @@ -1040,6 +1040,10 @@
"01-custom-rule-example.windup.yaml",
"01-javax-package-custom-target.windup.yaml"
],
"numberOfRules": {
"01-custom-rule-example.windup.yaml": 1,
"01-javax-package-custom-target.windup.yaml": 1
},
"openSourceLibraries": true
},
"affected_files_on_day_trader_app": {
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ export function getRandomAnalysisData(analysisdata): analysisData {
excludedPackagesList: analysisdata.excludedPackagesList,
incidents: analysisdata.incidents,
openSourceLibraries: analysisdata.openSourceLibraries,
numberOfRules: analysisdata.numberOfRules,
};
}

Expand Down

0 comments on commit 532ff47

Please sign in to comment.