Getting error while testing modfied Rule using Rule development Kit

Hi members

While testing the rdk rule for calculating LCS I am getting below errors. Have validated the rule in the rule validator utility and showing success status.

Below is the error:

<[INFO] Changes detected - recompiling the module! :source
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files with javac [debug target 11] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,5] illegal start of type
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,12] invalid method declaration; return type required
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,41] <identifier> expected
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,58] <identifier> expected
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,70] <identifier> expected
[ERROR] /C:/Users//Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,72] illegal start of type
[INFO] 6 errors/>
1 Like

Hello @mabhavsa,

Would you be able to share your CalculateLifecycleState.java file and the corresponding xml rule that you’ve validated using the rule validator utility?

This will help myself and other community members dig into what might be the error.

1 Like

Hi @tyler_mairose
Java file attached.
CalculateLifecycleState.java (4.5 KB)

Hello @mabhavsa,

Thank you for uploading your rule!

With the two files below I am getting results back from the rule with the RDK.

Rule - AttributeGenerator - CalculateLifecycleState.xml (4.1 KB) - This file will go under src/main/resources/rules/
CalculateLifecycleStateTest.java (1.4 KB) - This file will go under src/test/java/sailpoint/

You can read more here about running and testing rules:

1 Like

Hi @tyler_mairose

Placed the files to the designated path but still facing the issue.
Screenshot.

Executed the below command after files are placed to the path.

C:\Users\MABHAVSA\Documents\SailPoint IDN Rules\rule-development-kit> mvn test -Dtest="CalculateLifecycleStateTest"

PS C:\Users\MABHAVSA\Documents\SailPoint IDN Rules\rule-development-kit> mvn test -Dtest="CalculateLifecycleStateTest"
[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------< sailpoint:rule-development-kit >-------------------
[INFO] Building rule-development-kit 1.0-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- resources:3.3.1:resources (default-resources) @ rule-development-kit ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 9 resources from src\main\resources to target\classes
[INFO] 
[INFO] --- compiler:3.11.0:compile (default-compile) @ rule-development-kit ---
[INFO] Changes detected - recompiling the module! :source
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 3 source files with javac [debug target 11] to target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,5] illegal start of type
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,12] invalid method declaration; return type required
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,41] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,58] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,70] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,72] illegal start of type
[INFO] 6 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.377 s
[INFO] Finished at: 2024-03-19T13:12:31+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project rule-development-kit: Compilation failure: Compilation failure:
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,5] illegal start of type
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,12] invalid method declaration; return type required
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,41] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,58] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,70] <identifier> expected
[ERROR] /C:/Users/MABHAVSA/Documents/SailPoint IDN Rules/rule-development-kit/src/main/java/CalculateLifecycleState.java:[110,72] illegal start of type
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Okay got it, I see what is happening now.

This error is showing us issues with the .java file. Since we are dealing in two different languages beanshell via xml and java the syntax and structure of the file needs to be different.

I’ve changed your file to be in the correct format here:
CalculateLifecycleState.java (4.3 KB)

  • Moved the getAttribute and return determineLifecycleState function into a main() function block.
  • With using java all variables must be instantiated, I initialize the identity object where in beanshell we pass this object into the beanshell context.
  • removed package sailpoint;
1 Like

Hi @tyler_mairose

The code was successful for me, thank you very much.

Does this imply that we need to be mindful of the following whenever we implement the Rule using RDK?

  1. CalculateLifecycleState.Java file - The code must be in Java.
  2. CalculateLifecycleStateTest.Java - The code must be in Bean shell.
  3. Rule - AttributeGenerator - CalculateLifecycleState.xml - The code must be in Beanshell.

Have I understood this correctly?

This file does not need to exist for the tests to run. It must be in java and helps us write the rule giving us syntax highlighting and code completion.

This code is in java as well. When you look in the src/test/java/sailpoint/ directory we setup tests where we create a beanshell interpreter.

Interpreter i = new Interpreter();

Since our rule xml file does not initialize identity we have to pass that in. (You can look at other tests in the RDK to see examples passing in more than just identity). We can mock the identity class and when certain functions are called within our xml it will return our result we’ve defined in that test. This allows you to test different logic and make sure you get the results you expect.

Identity identity = mock();

when(identity.getAttribute("startDate")).thenReturn("18-1-2024");
when(identity.getAttribute("endDate")).thenReturn("18-3-2024");
when(identity.getAttribute("cloudLifecycleState")).thenReturn("joining"); when(identity.getAttribute("employeeGroup")).thenReturn("7");
i.set("identity", identity);

You are correct this code is beanshell and is what is provided to be uploaded to Identity Security Cloud to run.

2 Likes

Awesome. Now I understood it.