diff --git a/tests/test_insights.py b/tests/test_insights.py new file mode 100644 index 0000000..4195859 --- /dev/null +++ b/tests/test_insights.py @@ -0,0 +1,22 @@ +import os +import subprocess + +from utils import constants +from utils.command import build_analysis_command +from utils.report import assert_insights_from_report_file + +# Polarion TC 598 +def test_insights_binary_app(analysis_data): + application_data = analysis_data['jee_example_app'] + custom_rule_path = os.path.join(os.getenv(constants.PROJECT_PATH), 'data/xml', 'weblogic-custom.windup.yaml') + + command = build_analysis_command( + application_data['file_name'], + application_data['source'], + application_data['target'] + ) + + output = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, encoding='utf-8').stdout + + assert 'generating static report' in output + assert_insights_from_report_file() diff --git a/utils/report.py b/utils/report.py index be912bd..0c52a90 100644 --- a/utils/report.py +++ b/utils/report.py @@ -56,3 +56,33 @@ def assert_story_points_from_report_file(): story_points += len(violation['incidents']) * violation['effort'] assert story_points >= 0, "Non valid value found in Story Points from Report: " + str(story_points) + +def assert_insights_from_report_file(): + """ + Asserts that the Insights occurrence count in the report file is > 0. + + Args: + **kwargs: Optional keyword arguments. + report_path (str): The path to the report file. If not provided, + the function will use the value of the 'REPORT_OUTPUT_PATH' environment variable. + + Raises: + AssertionError: If the story points in the report file do not match the provided value. + + Returns: + None. + + """ + report_data = get_json_from_report_output_file() + + occurrences = -1 + for rule in report_data['rulesets']: + insights = rule.get('insights', {}) + + for insight in insights.values(): + if 'incidents' in insight: + if occurrences == -1: + occurrences = 0 + occurrences += len(insight['incidents']) + + assert occurrences >= 0, "Invalid value found for Insights occurrences in Report: " + str(occurrences)