using System; using TestFramework.ApplicationAPI; using TestFramework.AuthenticateAPI; using TestFramework; namespace Tests.resource { /// <summary> /// Summary description for ResourceGeo. /// /// this exemple creates a geographical, /// loads it and then assigns it to a resource /// in RPM repository /// </summary> public class ResourceGeo { public ResourceGeo() { } //All these variables are used in this sample public static String resourceName = "IBM_testABCDEF"; public static String regionName = "IBMREGION"; public static String regionDesc = "ABCDEF123"; public static String countryName = "IBMCOUNTRY"; public static String countryDesc = "ABCDEF123"; public static String stateName = "IBMSTATE"; public static String cityName = "IBMCITY"; public static String cityDesc = "ABCDEF123"; public static String locationName = "IBMLOCATION"; public static String locationDesc = "ABCDEF123"; //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 geographical ResourceScope rScope = new ResourceScope(); // create a geographical scope to link every geographical // element you create GeographicalScope geoScope = new GeographicalScope(); // create geographical elements you need Region region = new Region(); CountryState state = new CountryState(); Country country = new Country(); City city = new City(); Location location = new Location(); // initialise each element // adjust geographical scope so that every link is kept region.name = regionName; region.description = regionDesc; geoScope.regions = new GeographicalScope(); country.name = countryName; country.description = countryDesc; region.countries = new Country[] {country}; geoScope.countries = new GeographicalScope(); state.name = stateName; country.states = new CountryState[] {state}; geoScope.countries.states = new GeographicalScope(); city.name = cityName; city.description = cityDesc; state.cities = new City[] {city}; geoScope.countries.states.cities = new GeographicalScope(); location.name = locationName; location.description = locationDesc; city.locations = new Location[] {location}; geoScope.countries.states.cities.locations = new GeographicalScope(); // when creation is done // save the geographical in the RPM repository // with the scope SaveResult save = APISetup.application.save(sessionid, region, geoScope, ReloadType.SavedResult ); APISetup.checkForErrors( save ); region = (Region)APISetup.application.loadFromXpath( sessionid, "/Region[name = '" + regionName + "']", geoScope ).rpmObjectList[0]; // adjust the resource scope so that it keeps the // relation with the geographical rScope.geographicalAssignment = true; // 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]; // assign the geographical assignment to the ressource res.geographicalAssignment.geographical = region; // 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); } } }