using System; using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI; using TestFramework; namespace Tests.resource { /// <summary> /// Summary description for ResourceContactGroup. /// /// this sample creates a contact group and assigns it /// to a resource taken in the RPM repository. /// </summary> public class ResourceContactGroup { public ResourceContactGroup() { } //All these variables are used in this sample public static String resourceName = "IBM_testABCDEF"; public static String cGroupName = "IBMGROUP_ABCDEF"; //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 resource wich we are going to use Resource res = null; // create a resourceScope to keep track of the relation // between the resource and the contact group ResourceScope rScope = new ResourceScope(); // adjust the resopurce scope to keep the relation // with the contact group rScope.contactGroupAssignments = true; // create a contact group ContactGroup cGroup = new ContactGroup(); // Find the resource in RPM using XPath. // take resource in RPM repository by its fullname // or externalid res = (Resource)APISetup.application. loadFromXpath(sessionid, "/Resource[fullname='" + resourceName + "']", rScope ).rpmObjectList[0]; // initialise the contact group with default values cGroup.name = cGroupName; // create a scope contact group ContactGroupScope cgScope = new ContactGroupScope(); // first save contact group to RPM repository SaveResult save = APISetup.application.save(sessionid, cGroup, cgScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); cGroup = (ContactGroup)APISetup.application. loadFromXpath(sessionid, "/Contactgroup[name='" + cGroupName + "']", cgScope ).rpmObjectList[0]; // initialise the contact group assignment // put your contact group as one of the groups assigned res.contactGroupAssignments[0].groups = cGroup; // save the resource in the RPM repository // use the sessionid acquired in the setUp // use the resource scope save = APISetup.application.save(sessionid, res, rScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); // end the communication with the api. APISetup.CleanUp(sessionid); } } }