PEGASUS_NAMESPACE_BEGIN // // Given the two references in the association, this function creates an // instance of the PG_ElementConformsToProfile class. // CIMInstance buildElementConformsToProfile( const CIMObjectPath & currentProfile, const CIMObjectPath & currentElement, const CIMClass & elementConformsClass) { Array<CIMName> elementPropArray; elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD); elementPropArray.append( ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT); CIMPropertyList elementPropList(elementPropArray); CIMInstance tmpInstance = elementConformsClass.buildInstance(false, false, elementPropList); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_CONFORMANTSTANDARD, currentProfile); setPropertyValue(tmpInstance, ELEMENTCONFORMSTOPROFILE_PROPERTY_MANAGEDELEMENT, currentElement); tmpInstance.setPath(tmpInstance.buildPath( elementConformsClass)); return tmpInstance; }
/** Stores a copy of the provided instance locally in the errorInstance class property, and also creates a copy of the instance in the static repository namespace. The instance is then read back out of the repository and compared against the one stored by the class. */ void EmbeddedInstanceProvider::createInstance( const OperationContext& context, const CIMObjectPath& ref, const CIMInstance& obj, ObjectPathResponseHandler& handler) { handler.processing(); errorInstance.reset(new CIMInstance(obj)); Array<CIMName> propNameList; propNameList.append(CIMName("errorKey")); propNameList.append(CIMName("EmbeddedInst")); CIMPropertyList propList(propNameList); CIMClass objClass = cimom.getClass( context, STATIC_REPOSITORY, obj.getClassName(), false, true, false, propList); CIMObjectPath objPath = obj.buildPath(objClass); errorInstance->setPath(objPath); repositoryPath = cimom.createInstance( context, STATIC_REPOSITORY, *errorInstance); CIMInstance repositoryInstance = cimom.getInstance( context, STATIC_REPOSITORY, repositoryPath, false, false, false, propList); repositoryInstance.setPath(repositoryPath); if (!errorInstance->identical(repositoryInstance)) { throw Exception( "Repository instance and local instance for embedded error not " "identical"); } handler.deliver(objPath); handler.complete(); }
// // Test identical() function with keys that are references // void test04() { // // Create classes A and B referenced classes, C - Association // CIMClass classA (CIMName ("A"), CIMName ()); CIMProperty propertyX ("x", String ()); propertyX.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyY ("y", String ()); propertyY.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyZ ("z", String ()); propertyZ.addQualifier (CIMQualifier (CIMName ("Key"), true)); classA.addProperty (propertyX); classA.addProperty (propertyY); classA.addProperty (propertyZ); CIMClass classB ("B"); CIMProperty propertyQ ("q", String ()); propertyQ.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyR ("r", String ()); propertyR.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyS ("s", String ()); propertyS.addQualifier (CIMQualifier (CIMName ("Key"), true)); classB.addProperty (propertyQ); classB.addProperty (propertyR); classB.addProperty (propertyS); CIMClass classC ("C"); CIMProperty propertyA ("a", CIMValue ()); propertyA.addQualifier (CIMQualifier (CIMName ("Key"), true)); CIMProperty propertyB ("b", CIMValue ()); propertyB.addQualifier (CIMQualifier (CIMName ("Key"), true)); classC.addProperty (propertyA); classC.addProperty (propertyB); // // Create instances of each classa // CIMInstance instanceA (CIMName ("A")); instanceA.addProperty (CIMProperty (CIMName ("x"), String ("rose"))); instanceA.addProperty (CIMProperty (CIMName ("y"), String ("lavender"))); instanceA.addProperty (CIMProperty (CIMName ("z"), String ("rosemary"))); CIMObjectPath aPath = instanceA.buildPath (classA); CIMObjectPath aPath2 ("A.y=\"lavender\",x=\"rose\",z=\"rosemary\""); PEGASUS_TEST_ASSERT (aPath.identical (aPath2)); CIMInstance instanceB (CIMName ("B")); instanceB.addProperty (CIMProperty (CIMName ("q"), String ("pelargonium"))); instanceB.addProperty (CIMProperty (CIMName ("r"), String ("thyme"))); instanceB.addProperty (CIMProperty (CIMName ("s"), String ("sage"))); // Test to assure that the buildpath function works. CIMObjectPath bPath = instanceB.buildPath (classB); CIMObjectPath bPath2 ("B.s=\"sage\",q=\"pelargonium\",r=\"thyme\""); PEGASUS_TEST_ASSERT (bPath.identical (bPath2)); // Build instance of C and build path from buildPath function. CIMInstance instanceC (CIMName ("C")); instanceC.addProperty (CIMProperty (CIMName ("a"), aPath, 0, CIMName ("A"))); instanceC.addProperty (CIMProperty (CIMName ("b"), bPath, 0, CIMName ("B"))); CIMObjectPath cPath = instanceC.buildPath (classC); // Build CIMObjectPath from keybindings. Array <CIMKeyBinding> keyBindings; CIMKeyBinding aBinding ("a", "A.y=\"lavender\",x=\"rose\",z=\"rosemary\"", CIMKeyBinding::REFERENCE); CIMKeyBinding bBinding ("b", "B.s=\"sage\",q=\"pelargonium\",r=\"thyme\"", CIMKeyBinding::REFERENCE); keyBindings.append (aBinding); keyBindings.append (bBinding); CIMObjectPath cPath2 ("", CIMNamespaceName (), cPath.getClassName (), keyBindings); // Assert that the CIMObjectPaths for C from build path and direct // from keybindings are equal. PEGASUS_TEST_ASSERT (cPath.identical (cPath2)); // ATTN: KS 25 Feb 2003 P3 - Think we can extend these tests // since this is creation of classes and // instnaces for associations and referenced classes. }
void TestAssociations(CIMRepository& r) { String nameSpace = "root"; { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObjectPath> names = r.associatorNames( nameSpace, instanceName, CIMName ("A"), CIMName ("Y"), "left", "right"); assert(names.size() == 1); Boolean cond = names[0] == CIMObjectPath("Y.key=\"John Jones\""); assert(cond); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObject> result = r.associators( nameSpace, instanceName, CIMName ("a"), CIMName ("y"), "LEFT", "RIGHT"); assert(result.size() == 1); CIMObjectPath cimReference = result[0].getPath (); CIMInstance cimInstance = CIMInstance(result[0]); CIMClass tmpClass = r.getClass(nameSpace, cimInstance.getClassName()); CIMObjectPath tmpInstanceName = cimInstance.buildPath(tmpClass); Boolean t = tmpInstanceName == CIMObjectPath("Y.key=\"John Jones\""); assert(t); // result[0].print(); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObjectPath> result = r.referenceNames( nameSpace, instanceName, CIMName ("A"), "left"); assert(result.size() == 1); CIMObjectPath tmp = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); Boolean cond = (result[0] == tmp); assert(cond); } { CIMObjectPath instanceName = CIMObjectPath ("X.key=\"John Smith\""); Array<CIMObject> result = r.references( nameSpace, instanceName, CIMName ("A"), "left"); assert(result.size() == 1); CIMClass tmpClass = r.getClass( nameSpace, CIMInstance(result[0]).getClassName()); CIMObjectPath tmpInstanceName = CIMInstance(result[0]).buildPath(tmpClass); CIMObjectPath tmp = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); Boolean cond = (tmpInstanceName == tmp); assert(cond); } // Delete all the object we created: { // First delete the association: CIMObjectPath assocInstanceName = CIMObjectPath ("A." "left=\"x.key=\\\"John Smith\\\"\"," "right=\"y.key=\\\"John Jones\\\"\""); r.deleteInstance(nameSpace, assocInstanceName); } }