# Rule Development Kit - Help with setting up tests

**URL:** <https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543>\
**Category:** SHF Discussion and Questions\
**Tags:** identity-security-cloud, rules\
**Created:** [January 2, 2024, 7:07pm UTC](https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543 "2024-01-02T19:07:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mpotti](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/mpotti/32/2916_2.png) [@mpotti](https://developer.sailpoint.com/discuss/u/mpotti)\
**Post date:** [January 2, 2024, 7:07pm UTC](https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543/1 "2024-01-02T19:07:52Z")

</div>

> Happy New Year everyone,

I am working on updating some rules that have been causing issues in our tenant s. I am trying to follow the official documentation on the RDT ([Rule Development Kit | SailPoint Developer Community](https://developer.sailpoint.com/idn/tools/rule-development-kit#mock-the-objects-and-return-the-mocked-data)). I get to the point of mocking up data and I am left scratching my head as to how I would mock the data up there is not a lot of detail in the example provided on the page.

I have created the .java and .xml files for the logic I want to test. I am not stuck on what I should do next in order to start testing out my new logic that was built. Any pointers on how to complete the next steps in the document would be really helpful thank you.

for reference here is the logic I have built out.

```auto
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import sailpoint.object.Application;
import sailpoint.object.Field;
import sailpoint.object.Identity;
import sailpoint.server.IdnRuleUtil;
import sailpoint.tools.GeneralException;
import sailpoint.object.Identity;

public class GenerateNetworkID
{
    Logger log = LogManager.getLogger(GenerateNetworkID.class);
    IdnRuleUtil idn;
    Identity identity = new Identity();

    /**
     * Remove all special characters, prefix, and suffix from the inputted string.
     *
     * @param name The first or last name of an identity.
     * @return The inputted string without special characters, prefix, or suffix
     */

    public String FirstIntial(String FirstName)
    {
        log.debug("Filtering substring of FirstName to extract First Char.");
        if(FirstName != null)
        {
            String FirstIntial = FirstName.substring(0,1);
            return FirstIntial;
        }
        else
        {
            log.error("No input data was entered. Please imput a string value."); 
            return "ERROR";
        }
    }

    public String LastNameSubString(String LastName)
    {
        log.debug("Filtering the Lastname to the first 5 chars.");
        if(LastName != null)
        {
            String LastName5Char = LastName.substring(0,6);
            return LastName5Char;
        }
        else
        {
            log.error("No input data was entered. Please imput a string value."); 
            return "ERROR";
        }
    }

    public String GetUID()
    {
        String UID = identity.getStringAttribute("uid");
        if(UID != null)
        {
            return UID;
        }
        else
        {
            log.error("No Value returned for UID.");
            return "ERROR";
        }
        
    }

    public String GetcloudAuthoritativeSource()
    {
        String cloudAuthoritativeSource = identity.getStringAttribute("cloudAuthoritativeSource");
        if(cloudAuthoritativeSource != null)
        {
            return cloudAuthoritativeSource;
        }
        else
        {
            log.error("No value returned for cloudAuthoritativeSource");
            return "ERROR";
        }
        
    }

    public String SamAccountName()
    {
        String firstName = FirstIntial(identity.getFirstname().toLowerCase());
        String lastName = LastNameSubString(identity.getLastname().toLowerCase());
        if(firstName != null && lastName != null)
        {
            return firstName + lastName;
        }
        else
        {
            log.error("A value returned Null please verify Identity");
            return "ERROR";
        }
    }

    public boolean IsUnique( String SamAccountName)
    {
        
        List SOURCE_IDS = new ArrayList(Arrays.asList(new String[]{ "2c9180857f221d2b017f23154bbe1644", "2c91808983e6f7250183f66daa0237a9"}));
        String PROMOTED_ATTR_NAME = "newSamAccountName";
        String SEARCH_OP = "Equals";
        List SEARCH_VALUES = new ArrayList( Arrays.asList( new String[]{ SamAccountName } ) );
        int count = idn.attrSearchCountAccounts( SOURCE_IDS, PROMOTED_ATTR_NAME, SEARCH_OP, SEARCH_VALUES );
        return count == 0;
    }

    public String CreateSamAccountName()
    {
        String SamAccountName = SamAccountName();
        String CloudAuthoritativeSource = GetcloudAuthoritativeSource();
        int usernameIdentifier;
        int uniqueIndex;
        if ( CloudAuthoritativeSource.contains( "2c9180837fdb5fe6017ffa27a7081a5e" ) || CloudAuthoritativeSource.contains( "2c9180888222e5a701823b3c70940398" ) ) {
            usernameIdentifier = 9;
            uniqueIndex = 1;
        } 
        else {
            usernameIdentifier = 0;
            uniqueIndex = 2;
        }

        while(IsUnique(SamAccountName + Integer.toString(usernameIdentifier) + Integer.toString(uniqueIndex)) == false)
        {
            uniqueIndex ++;
        }
        return SamAccountName + Integer.toString(usernameIdentifier) + Integer.toString( uniqueIndex );
    }
}

```

Here is what I want it to replace:

```auto
import sailpoint.tools.Util;
import sailpoint.object.QueryOptions;
import sailpoint.object.Filter;
import sailpoint.object.Link;
import sailpoint.object.Application;
import sailpoint.thunderbolt.service.LDAPConnectorService;
import sailpoint.thunderbolt.service.module.ServiceModule;
import sailpoint.thunderbolt.service.ConnectorService;
import sailpoint.object.Field;
import sailpoint.tools.GeneralException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;

public class SamAccountNameGenerator{
    Logger log = LogManager.getLogger(SamAccountNameGenerator.class);
    //debug("[ENTERING] AttributeGenerator :: Generate sAMAccountName.");

    /**
     * Remove all special characters, prefix, and suffix from the inputted string.
     *
     * @param name The first or last name of an identity.
     * @return The inputted string without special characters, prefix, or suffix
     */
    public String cleanupName( String name ) {
        log.debug("Entering cleanupName( \""+ name +"\" )" );
        if ( name != null) {
            if ( name.contains( " " ) ) {
                log.debug( "Space in " + name + " detected....checking for suffix" );
                String [] split = name.split(" ");
                String cleanName = "";
                for ( int i = 0; i < split.length; i++ ) {
                    log.debug( "split[" + i + "] = " + split[i] );
                    if ( split[i].matches( "jr|jr.|jR|jR.|JR|JR.|Jr|Jr.|sr|sr.|sR|sR.|SR|SR.|Sr|Sr.|ii|iii|iv|v|II|III|IV|V" ) ) {
                        split[i] = "";
                    }
                    cleanName += split[i];
                }
                name = cleanName;
                log.debug( "Suffix Detected....Removing" );
                log.debug( "Updated Name" );
            }
            name = name.replaceAll( "[^a-zA-Z0-9_-]", "" );
        }
        log.debug( "Name : " + name );
        return name;
    }

    /**
     * check all AD applications.
     *
     * @param sAMAccountName - The generated value for testing.
     * @return true if the count is 0, false if the count is greater than 0.
     */
    public boolean isUnique( String sAMAccountName ) {
        List SOURCE_IDS = new ArrayList( Arrays.asList( new String[]{ "2c9180857f221d2b017f23154bbe1644", "2c91808983e6f7250183f66daa0237a9" } ) );
        String PROMOTED_ATTR_NAME = "newSamAccountName";
        String SEARCH_OP = "Equals";
        List SEARCH_VALUES = new ArrayList( Arrays.asList( new String[]{ sAMAccountName } ) );
        int count = idn.attrSearchCountAccounts( SOURCE_IDS, PROMOTED_ATTR_NAME, SEARCH_OP, SEARCH_VALUES );
        return count == 0;
    }

    //Create the sAMAccountName using the first 5 character of the lastname + firstname initial
    String firstName = cleanupName( identity.getFirstname().toLowerCase() );
    String lastName = cleanupName( identity.getLastname().toLowerCase() );
    String accountLastname = lastName.length() > 5 ?
        lastName.substring( 0, 5 ) : lastName;
    String samFirstname = firstName.substring( 0, 1 );
    String sAMAccountName = identity.getAttribute( "uid" );
    String cloudAuthoritativeSource = identity.getAttribute( "cloudAuthoritativeSource" );
    String usernameIdentifier = "";
    int uniqueIndex = 0;
    if ( cloudAuthoritativeSource.contains( "2c9180837fdb5fe6017ffa27a7081a5e" ) || cloudAuthoritativeSource.contains( "2c9180888222e5a701823b3c70940398" ) ) {
    usernameIdentifier = "9";
    uniqueIndex = 1;
    } else {
    usernameIdentifier = "0";
    uniqueIndex = 2;
    }

    while ( !isUnique( sAMAccountName ) && 99 > uniqueIndex ) {
        sAMAccountName = samFirstname + accountLastname + usernameIdentifier + Integer.toString( uniqueIndex );
        uniqueIndex++;
    }
    log.debug( "sAMAccountName :: returning \"" + sAMAccountName + "\"." );
    log.debug( "[EXITING] AttributeGenerator :: Generate sAMAccountName." );
    return sAMAccountName;

}

  

```

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [January 11, 2024, 2:33pm UTC](https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543/2 "2024-01-11T14:33:16Z")

</div>

Hi Mark. Have you watched this video where @tyler_mairose explains how the RDK works? I believe he discusses how to test a rule with mock data.

> [@Dev Live Stream, October - Introducing the Rule Development Kit](https://developer.sailpoint.com/discuss/t/dev-live-stream-october-introducing-the-rule-development-kit/14114):
>
> This month, we’ll be hearing from @tyler_mairose as he teaches us what SailPoint’s new Rule Development Kit is and how to use it to develop rules faster, and with less effort. This will save you time and money by reducing the time spent developing and debugging rules, leading to less PS time evaluating and implementing them!

---

<div class="post-metadata">

**Author:** ![mpotti](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/mpotti/32/2916_2.png) [@mpotti](https://developer.sailpoint.com/discuss/u/mpotti)\
**Post date:** [January 11, 2024, 3:25pm UTC](https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543/3 "2024-01-11T15:25:55Z")

</div>

Thank you @colin_mckibben I will check this out I was not able to attend when this live stream took place.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [March 11, 2024, 3:26pm UTC](https://developer.sailpoint.com/discuss/t/rule-development-kit-help-with-setting-up-tests/23543/4 "2024-03-11T15:26:03Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
