Skip to content

Commit

Permalink
[RFR] Add advanced options tests (#8)
Browse files Browse the repository at this point in the history
* Add advanced options tests

Signed-off-by: Alejandro Brugarolas <abrugaro@redhat.com>

* fix pr

Signed-off-by: Alejandro Brugarolas <abrugaro@redhat.com>

---------

Signed-off-by: Alejandro Brugarolas <abrugaro@redhat.com>
  • Loading branch information
abrugaro authored Apr 18, 2023
1 parent 80d5dbb commit a500f04
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data/xml/javax-package-custom-target.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" id="javax-package"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<metadata>
<description>
This ruleset evaluates whether a custom target can be used within a custom rule
</description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final" />
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final" />
</dependencies>
<targetTechnology id="phil" versionRange="[7,8)" />
</metadata>
<rules>
<rule id="javax-package-custom-target-00001">
<when>
<javaclass references="javax.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<hint title="CUSTOM RULE for javax.* package import" effort="1" category-id="potential">
<message>`javax.*` packages must be renamed to `jakarta.*` for Jakarta EE9 compatibility.</message>
<link title="Renamed Packages" href="https://github.com/wildfly-extras/batavia/blob/master/impl/ecl/src/main/resources/org/wildfly/extras/transformer/eclipse/jakarta-renames.properties"/>
</hint>
</perform>
</rule>
</rules>
</ruleset>
25 changes: 25 additions & 0 deletions data/xml/javax-package-custom.windup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<ruleset xmlns="http://windup.jboss.org/schema/jboss-ruleset" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="javax-package" xsi:schemaLocation="http://windup.jboss.org/schema/jboss-ruleset http://windup.jboss.org/schema/jboss-ruleset/windup-jboss-ruleset.xsd">
<metadata>
<description> This ruleset provides analysis of applications that use RESTEasy 3.0 and may require individual attention when migrating to RESTEasy 3.6. </description>
<dependencies>
<addon id="org.jboss.windup.rules,windup-rules-javaee,3.0.0.Final"/>
<addon id="org.jboss.windup.rules,windup-rules-java,3.0.0.Final"/>
</dependencies>
</metadata>
<rules>
<rule id="javax-package-00001">
<when>
<javaclass references="javax.{*}">
<location>IMPORT</location>
</javaclass>
</when>
<perform>
<hint title="CUSTOM RULE for javax.* package import" effort="1" category-id="potential">
<message>`javax.*` packages must be renamed to `jakarta.*` for Jakarta EE9 compatibility.</message>
<link title="Renamed Packages" href="https://github.com/wildfly-extras/batavia/blob/master/impl/ecl/src/main/resources/org/wildfly/extras/transformer/eclipse/jakarta-renames.properties"/>
<tag>tag</tag>
</hint>
</perform>
</rule>
</rules>
</ruleset>
43 changes: 43 additions & 0 deletions tests/test_advanced_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from utils.command import build_command
from utils.report import assert_story_points_from_report_file
from utils.report import assert_valid_csv


def test_skip_report(analysis_data):
Expand Down Expand Up @@ -65,3 +66,45 @@ def test_transaction_analysis(analysis_data):
assert_story_points_from_report_file(application_data['story_points'])

assert os.path.exists(report_path + '/reports/divareport_petclinic.html') is True


def test_csv_report(analysis_data):
application_data = analysis_data['jee_example_app']
report_path = os.getenv('REPORT_OUTPUT_PATH')

command = build_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'exportCSV': ''}
)
output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout

assert 'Report created' in output

assert_valid_csv(os.path.join(report_path, 'AllIssues.csv'))
assert_valid_csv(os.path.join(report_path, 'ApplicationFileTechnologies.csv'))
assert_valid_csv(os.path.join(report_path, 'jee_example_app_1_0_0_ear.csv'))


def test_custom_rules_analysis(analysis_data):
application_data = analysis_data['complete_duke']
report_path = os.getenv('REPORT_OUTPUT_PATH')
custom_rule_path = os.path.join(os.getenv('PROJECT_PATH'), 'data/xml', 'javax-package-custom.windup.xml')

command = build_command(
application_data['file_name'],
application_data['source'],
application_data['target'],
**{'userRulesDirectory': custom_rule_path}
)

output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout
assert 'Report created' in output

migration_issues_path = os.path.join(report_path, 'reports/migration_issues.html')
assert os.path.exists(migration_issues_path) is True

with open(migration_issues_path) as file:
file_content = file.read()
assert 'CUSTOM RULE for javax.* package import' in file_content
26 changes: 26 additions & 0 deletions utils/report.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import csv
import os

from bs4 import BeautifulSoup
Expand All @@ -13,3 +14,28 @@ def assert_story_points_from_report_file(story_points):
report_story_points = int(parsed_report.find('span', class_='points').text)

assert report_story_points == story_points


def assert_valid_csv(csv_file_path, **kwargs):
"""
Asserts that the given CSV file is valid.
A CSV file is considered valid if it exists and all of its rows have the same number of columns.
Args:
csv_file_path (str): The file path of the CSV file to validate.
**kwargs (str): Optional keyword arguments.
delimiter (str): The delimiter used in the CSV file. Defaults to ','.
Raises:
AssertionError: If the CSV file does not exist or if its rows have different numbers of columns.
Returns:
None.
"""
assert os.path.exists(csv_file_path) is True
delimiter = kwargs.get('delimiter', ',')

with open(csv_file_path, mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file, delimiter=delimiter)
columns_number = len(next(csv_reader))
assert all(len(row) == columns_number for row in csv_reader) is True

0 comments on commit a500f04

Please sign in to comment.