Skip to content

Sed 4562 support junit ap tests with keyword accessing the ap content for step 29#598

Merged
david-stephan merged 8 commits into29from
SED-4562-support-junit-ap-tests-with-keyword-accessing-the-ap-content-for-step-29
Feb 25, 2026
Merged

Sed 4562 support junit ap tests with keyword accessing the ap content for step 29#598
david-stephan merged 8 commits into29from
SED-4562-support-junit-ap-tests-with-keyword-accessing-the-ap-content-for-step-29

Conversation

@david-stephan
Copy link
Contributor

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @david-stephan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the local execution capabilities for JUnit Automation Package tests. It introduces a specialized operation mode for local automation packages and provides a new utility to dynamically archive classpath contents, allowing keywords to access resources within the running automation package. This change improves the flexibility and functionality of local test execution by ensuring that the necessary resources are correctly identified and made available.

Highlights

  • Enhanced Local Execution Modes: Introduced a new OperationMode.LOCAL_AUTOMATION_PACKAGE to specifically handle local execution contexts for Automation Packages, alongside a new isLocal() helper method for broader local mode checks.
  • Classpath Archiving Utility: Added a ClassLoaderArchiver utility class to dynamically create JAR archives from the current classpath, enabling the packaging of resources and classes for local Automation Package execution.
  • Dedicated Local Function Handler: Implemented LocalFunctionHandler to manage automation package files for local functions, which now leverages the ClassLoaderArchiver to create a virtual automation package from the application's classloader.
  • Refactored Operation Mode Checks: Updated various execution engine plugins and handlers to utilize the new isLocal() method for more robust and consistent checks across different local operation modes.
  • Automation Package Name Consistency: Refactored AutomationPackageReader and AutomationPackageDescriptorReader to consistently use getAutomationPackageName() instead of getOriginalFileName() for better clarity and accuracy in identifying automation packages.
  • Sample Keyword for AP Content Access: Added a new sample keyword MyKeywordUsingAutomationPackageFile in the JUnit sample project, demonstrating how keywords can retrieve and access content from the automation package during local execution.
Changelog
  • .gitignore
    • Added an entry to ignore .claude files.
  • step-automation-packages/step-automation-packages-junit-core/src/main/java/step/engine/plugins/AutomationPackageLocalOSPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
  • step-automation-packages/step-automation-packages-junit-core/src/main/java/step/engine/plugins/ParameterManagerLocalPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
  • step-automation-packages/step-automation-packages-junit/src/main/java/step/junit/runner/Step.java
    • Imported OperationMode and configured the execution engine to use OperationMode.LOCAL_AUTOMATION_PACKAGE.
  • step-automation-packages/step-automation-packages-junit5/src/main/java/step/junit5/runner/StepJUnit5.java
    • Imported OperationMode and configured the execution engine to use OperationMode.LOCAL_AUTOMATION_PACKAGE.
  • step-automation-packages/step-automation-packages-manager/src/main/java/step/automation/packages/AutomationPackageReader.java
    • Updated calls to readAutomationPackageDescriptor and readAutomationPackageFragment to use automationPackageArchive.getAutomationPackageName() instead of getOriginalFileName().
  • step-automation-packages/step-automation-packages-manager/src/main/java/step/automation/packages/JavaAutomationPackageReader.java
    • Updated logging messages to use archive.getAutomationPackageName() instead of getOriginalFileName().
  • step-automation-packages/step-automation-packages-samples/step-automation-packages-sample-junit/src/main/java/step/automation/packages/functions/MyKeywordLibraryAutopack.java
    • Added new imports for File, Arrays, and Objects.
    • Implemented a new keyword MyKeywordUsingAutomationPackageFile to demonstrate retrieving and accessing automation package content.
  • step-automation-packages/step-automation-packages-samples/step-automation-packages-sample-junit/src/main/resources/plans.yml
    • Added a call to the newly introduced MyKeywordUsingAutomationPackageFile keyword.
  • step-automation-packages/step-automation-packages-yaml/src/main/java/step/automation/packages/yaml/AutomationPackageDescriptorReader.java
    • Refactored method signatures for readAutomationPackageDescriptor, readAutomationPackageFragment, and readAutomationPackageYamlFile to use packageName instead of packageFileName.
    • Updated logging messages to use packageName for consistency.
  • step-functions-plugins/step-functions-plugins-composite/step-functions-plugins-local-composite/src/main/java/step/plugins/functions/types/LocalCompositeFunctionPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
    • Modified the saving of local functions to be conditional, skipping it when OperationMode.LOCAL_AUTOMATION_PACKAGE is active.
  • step-functions-plugins/step-functions-plugins-java/step-functions-plugins-java-def/src/main/java/step/plugins/java/GeneralScriptFunctionPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
  • step-functions-plugins/step-functions-plugins-jmeter/step-functions-plugins-jmeter-def/src/main/java/step/plugins/jmeter/JMeterFunctionTypeLocalPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
  • step-functions-plugins/step-functions-plugins-node/step-functions-plugins-node-def/src/main/java/step/plugins/node/NodeLocalPlugin.java
    • Removed the import for OperationMode.
    • Updated the operation mode check to use the new isLocal() method.
  • step-functions/step-functions-handler/src/main/java/step/functions/handler/AbstractFunctionHandler.java
    • Added @Nullable annotation import.
    • Extracted the logic for extracting automation package files into a new protected method extractAutomationPackageFile.
  • step-plans/step-plans-base-artefacts/src/main/java/step/artefacts/handlers/CallFunctionHandler.java
    • Updated the operation mode check to use the new isLocal() method.
  • step-plans/step-plans-base-artefacts/src/main/java/step/engine/plugins/ClassLoaderArchiver.java
    • Added a new utility class ClassLoaderArchiver for creating JAR archives from the classpath, including methods for adding files, directories, and existing JARs, with exclusion rules for META-INF files and class files.
  • step-plans/step-plans-base-artefacts/src/main/java/step/engine/plugins/LocalFunctionHandler.java
    • Added a new class LocalFunctionHandler extending KeywordHandler, which overrides retrieveAndExtractAutomationPackageFile to create an artificial automation package from the classloader and always reports containsAutomationPackageFileReference as true for local keywords.
  • step-plans/step-plans-base-artefacts/src/main/java/step/engine/plugins/LocalFunctionPlugin.java
    • Updated the operation mode check to use the new isLocal() method.
    • Modified the saving of local functions to be conditional, skipping it when OperationMode.LOCAL_AUTOMATION_PACKAGE is active.
    • Changed the getHandlerChain method in LocalFunctionType to return LocalFunctionHandler.class.getName().
  • step-plans/step-plans-base-artefacts/src/test/java/step/engine/plugins/ClassLoaderArchiverTest.java
    • Added a new JUnit test class ClassLoaderArchiverTest to verify the functionality of the ClassLoaderArchiver, including directory structure preservation, file content integrity, exclusion of directory entries, handling of resourcesOnly flag, manifest generation, duplicate entry prevention, and signature file exclusion.
  • step-plans/step-plans-core/src/main/java/step/core/execution/OperationMode.java
    • Added a new enum value LOCAL_AUTOMATION_PACKAGE.
    • Introduced a new helper method isLocal() to check for any local execution mode.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces support for JUnit tests to access Automation Package (AP) content by simulating an AP from the current classpath. This is a significant improvement for testing keywords that rely on AP resources. The implementation uses a new OperationMode.LOCAL_AUTOMATION_PACKAGE and a LocalFunctionHandler to bundle the classpath into a temporary JAR. Feedback includes addressing efficiency and resource management in LocalFunctionHandler due to lack of caching, ensuring correct isLocalPackage flag usage, and resolving unused code and documentation mismatches in utility classes.

Comment on lines +14 to +23
public File retrieveAndExtractAutomationPackageFile(Map<String, String> properties) throws FileManagerException {
try {
// For local Function we artificially create an archive using the application classloader defined as system property
File tempFile = FileHelper.createTempFile();
ClassLoaderArchiver.createArchive(tempFile, true);
return extractAutomationPackageFile(tempFile);
} catch (IOException e) {
throw new RuntimeException("Unable to create temporary archive file for the classloader", e);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation creates a new temporary JAR file and unzips it into a new temporary directory every time retrieveAndExtractAutomationPackageFile is called. Since FileHelper.createTempFile() returns a unique path each time, it bypasses the caching mechanism in extractAutomationPackageFile (which uses the file path as a key in the session). This results in significant performance overhead and disk space consumption.

Consider caching the generated archive file so it can be reused across multiple calls within the same execution context.

Comment on lines +27 to +29
//for local Keyword we always consider that we hare in the context of an AP
return true;
}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Fix typo in comment ('hare' -> 'are') and remove double closing brace at the end of the file. The return true for isLocalPackage is appropriate here, as the local keyword context implies the automation package is part of the running process's classloader, aligning with the rule for setting isLocalPackage to true.

Suggested change
//for local Keyword we always consider that we hare in the context of an AP
return true;
}}
//for local Keyword we always consider that we are in the context of an AP
return true;
}
}
References
  1. The isLocalPackage flag should be set to true only when the automation package is part of the running process's classloader (e.g., for a JUnit runner). For external packages, such as those used in CLI executions, it should be false.

*/
public class ClassLoaderArchiver {

private static final Logger logger = LoggerFactory.getLogger(ClassLoaderArchiver.class);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logger field is defined but never used in this class.


/**
* Creates a JAR archive at {@code outputFile} that contains all classes and
* resources reachable from {@code classLoader}.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Javadoc mentions a classLoader parameter that is not present in the method signature. The method currently uses the system property java.class.path directly.

Comment on lines +154 to +157
private static boolean containsClassesDirectory(Set<File> files) {
return files.stream().anyMatch(f -> f.isDirectory() &&
(f.getPath().contains("classes") || f.getPath().contains("resources")));
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The method containsClassesDirectory is unused and can be removed.


@Override
public boolean containsAutomationPackageFileReference(Map<String, String> properties) {
//for local Keyword we always consider that we hare in the context of an AP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//for local Keyword we always consider that we hare in the context of an AP
//for local Keyword we always consider that we are in the context of an AP

@david-stephan david-stephan merged commit 6c3363a into 29 Feb 25, 2026
@david-stephan david-stephan deleted the SED-4562-support-junit-ap-tests-with-keyword-accessing-the-ap-content-for-step-29 branch February 25, 2026 13:52
david-stephan added a commit that referenced this pull request Mar 2, 2026
… for step 29 (#598)

* SED-4555 Local execution of AP with Keyword accessing the AP content is not supported

* SED-4555 PR feedback and cleanup

* SED-4555 ClassLoaderArchiver must exclude signature files

* SED-4555 switching to sequential unzip

* SED-4555 PR feedbacks

* SED-4562 Support Junit AP tests with Keyword accessing the AP content for Step 29

* SED-4562 PR feedbacks

* SED-4562 fixing cases where operation mode is null in execution context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants