PoolSample

using System;  using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI;
using TestFramework;  namespace Tests.pool { 	/// <summary>
	/// Summary description for PoolSample.
	/// 
	/// this sample tries to query a pool
	/// if the pool dosen't exist, it creates it
	/// </summary>
	public class PoolSample
	{
		public PoolSample()
		{

		}

		//All these variables are used in this sample
		public static String poolName = "IBMPOOL_123";
		public static String poolDesc = "ABCDEF123";
		public static String poolAdr = "IBMADRESSE";
		public static String poolCont = "IBMCONTACT";
		public static String poolFax = "IBMFAX";

		//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 attribute
			PoolScope pScope = new PoolScope();

			// declare a save result object
			SaveResult pSave = null;

			// Find the pool in RPM using XPath. 
			// If pool doesn't exist, create it using a new pool. 
			// Fill the name.
			LoadResult load = APISetup.application.
				loadFromXpath(sessionid, 
				"/Pool[name='" + poolName + "']",pScope);

			// This if logic verifies the result of the xpath query
			// rpmObjectList contains resources returned
			if( load.rpmObjectList == null || 
				load.rpmObjectList.Length == 0 )
			{
	
				// create a new pool
				pool = new Pool();

				// initialize the pool
				pool.name = poolName;
				pool.description = poolDesc;

				// save the pool in the RPM repository
				// use the sessionid acquired in the setUp
				// a scope is not necessary because only the 
				// resource is being saved
				// use a reloadType that alows you to continue 
				// working with the pool
				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 );

				// reload the pool
				pool = (Pool)APISetup.application.
					loadFromXpath(sessionid, 
					"/Pool[name='" + poolName + "']",
					pScope).rpmObjectList[0];
	
			}
			else
			{
				// update existing pool
				// in this case the pool already exists
				pool = (Pool)load.rpmObjectList[0];
			}

			// update the pool with new data
			pool.address = poolAdr;
			pool.contactName = poolCont;
			pool.fax = poolFax;

			// save the pool in the RPM repository
			// use the sessionid acquired in the setUp
			// a scope is not necessary because only the 
			// resource is being saved
			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);

		}
	}
}