using System; using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI; using TestFramework; namespace Tests.pool { /// <summary> /// Summary description for PoolRes. /// /// this sample loads a pool from the RPM repository. /// It creates a Resource and assigns it to the pool. /// It loads a security role and assigns it to the pool. /// </summary> public class PoolRes { public PoolRes() { } //All these variables are used in this sample public static String poolName = "IBMPOOL_123"; public static String resName = "IBMRESOURCE"; public static String roleName = "Pool Participant"; //Session ID is use for all transaction and is get from the //Authenticate.login function. The session ID will replace // the User password while transacting public static String sessionid = ""; public void sampleTest() { // start the communication with the api sessionid = APISetup.SetUp(); // Declare the pool wich we are going to use Pool pool = null; // create a poolscope to keep track of the relation // between the pool and its resource PoolScope pScope = new PoolScope(); // create new resource Resource res = new Resource(); // assign the scope to link with its resource pScope.resourceAssignments = true; // declare a save result object SaveResult pSave = null; // retrieve the pool in RPM using XPath. pool = (Pool)APISetup.application. loadFromXpath(sessionid, "/Pool[name='" + poolName + "']", pScope).rpmObjectList[0]; // create resource role assignement ResourceRoleAssignment rrAssign = new ResourceRoleAssignment(); // initialize resource res.fullName = resName; res.parent = pool; // save the new resource // use a reload type that enables you to // use youre saved data pSave = new SaveResult(); pSave = APISetup.application.save(sessionid, res, null, ReloadType.SavedResult ); // method showing the detail of any error in the save APISetup.checkForErrors( pSave ); // load the new resource to use it res = (Resource)APISetup.application. loadFromXpath(sessionid, "/Resource[fullName='" + resName + "']", null).rpmObjectList[0]; // create a new security role SecurityRole sRole = new SecurityRole(); // assign a security role from RPM repository sRole = (SecurityRole)APISetup.application. loadFromXpath(sessionid, "/SecurityRole[name='" + roleName + "']", null).rpmObjectList[0]; // initialize the resource role assignement rrAssign.resource = res; rrAssign.securityRole = sRole; rrAssign.parent = pool; // assign the resource role assignement to the pool pool.resourceAssignments = new ResourceRoleAssignment[] {rrAssign}; // save the pool in the RPM repository // use the sessionid acquired in the setUp // a scope is necessary because // we keep the resource assignement pSave = new SaveResult(); pSave = APISetup.application.save(sessionid, pool, pScope, ReloadType.SavedResult ); // method showing the detail of any error in the save APISetup.checkForErrors( pSave ); // end the communication with the api. APISetup.CleanUp(sessionid); } } }