int testAssocNames(const CIMObjectPath& objectName, const CIMName& assocClass, const CIMName& resultClass, const String& role, const String& resultRole, Uint32 expectedCount ) { //CIMObjectPath instanceName = CIMObjectPath ("Person.name=\"Mike\""); CDEBUG ("testReferenceNames " << objectName.toString() << " resultClass " << resultClass << " role " << role); Array<CIMObjectPath> result = c.associatorNames( NAMESPACE, objectName, assocClass, resultClass, role, resultRole); Array<CIMObject> resultObjects = c.associators( NAMESPACE, objectName, assocClass, resultClass, role, resultClass); if (result.size() != resultObjects.size()) { cout << "ERROR, Associator and AssociatorName count returned difference" << endl; } for (Uint32 i = 0; i < result.size(); i++) { if (resultObjects[i].getPath().toString() != result[i].toString()) { cout << "Name response Error" << endl; } } if (verbose) { cout << "REQUEST: Associators, Object: " << objectName << " assocClass " << assocClass << " resultClass " << resultClass << " role " << role << " resultClass " << resultClass << endl << "RESPONSE: "; for (Uint32 i = 0; i < result.size(); i++) cout << " " << result[i].toString() << " "; cout << endl; } if (result.size() != expectedCount) { cout << "AssociatorName Error Object " << objectName.toString() << "Expected count = " << expectedCount << " received " << result.size(); return 1; } return 0; }
void testDMTFProfileInstances(CIMClient &client) { cout << "Testing DMTF Profiles instances..."; // Get All Registered profile names Array<CIMObjectPath> regInstanceNames = client.enumerateInstanceNames( interopNamespace, CIMName("CIM_RegisteredProfile")); // Find out DMTF autonomous and component profiles. for(Uint32 i = 0, n = regInstanceNames.size() ; i < n ; ++i) { // Filter SNIA sub profile names. if (regInstanceNames[i].getClassName().equal("PG_RegisteredSubProfile")) { continue; } Array<CIMObjectPath> result = client.associatorNames( interopNamespace, regInstanceNames[i], CIMName("CIM_ReferencedProfile")); Uint32 dmtfProfiles = 0; for (Uint32 j = 0, k = result.size(); j < k ; ++j) { // Get only DMTF component profiles. if (result[j].getClassName().equal("PG_RegisteredProfile")) { Array<CIMKeyBinding> keys = result[j].getKeyBindings(); String value = keys[0].getValue(); Uint32 index = value.find("DMTF"); if (index != PEG_NOT_FOUND) { dmtfProfiles++; } } } if (dmtfProfiles && dmtfProfiles != result.size()) { exitFailure( String("Invalid component profiles for ") + regInstanceNames[i].toString()); } } cout << "Test Complete" << endl; }
Uint32 _testAssociatorNames(CIMClient& client, CIMName assocClass, CIMObjectPath instancePath) { if (verbose) { cout << "\nAssociation Class: " << assocClass.getString() << endl; cout << "\nObject Name: " << instancePath.toString() << endl; } // Get the names of the CIM instances that are associated to the // specified source instance via an instance of the AssocClass. // CIMName resultClass; String role; String resultRole; Array<CIMObjectPath> resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); return resultObjectPaths.size(); }
void _testAssociators( CIMClient& client, CIMName assocClass, CIMObjectPath instancePath ) { try { CIMName resultClass; String role; String resultRole; // Get the CIM instances that are associated with the specified source // instance via an instance of the AssocClass Array<CIMObject> resultObjects = client.associators( providerNamespace, instancePath, assocClass, resultClass, role, resultRole); Array<CIMObjectPath> resultObjectPaths = client.associatorNames( providerNamespace, instancePath, assocClass, resultClass, role, resultRole); } catch (Exception& e) { _errorExit(e.getMessage()); } }
int main(int argc, char** argv) { CIMClient client; Boolean verbose = false; Uint32 numObjects; Array<CIMObjectPath> resultObjectPaths; Array<CIMObject> resultObjects; CIMName assocClass; CIMName resultClass; String role; String resultRole; // // Check command line option // if (argc > 2) { cerr << "Usage: AssociationClient [-v]" << endl; return 1; } if (argc == 2) { const char *opt = argv[1]; if (strcmp(opt, "-v") == 0) { verbose = true; } else { cerr << "Usage: AssociationClient [-v]" << endl; return 1; } } try { // =================================================================== // connectLocal // // The connectLocal Client API creates a connection to the server for // a local client. The connection is automatically authenticated // for the current user. (The connect Client API can be used to create // an HTTP connection with the server defined by the URL in address. // User name and Password information can be passed using the connect // Client API.) // =================================================================== client.connectLocal(); // =================================================================== // associators // // Get the CIM instances (Sample_Student instances) that are associated // to the source CIM instance (Sample_Teacher.Name = "Teacher1") via an // instance of the Sample_TeacherStudent association class. // =================================================================== assocClass = SAMPLE_TEACHERSTUDENT; CIMObjectPath instancePath("Sample_Teacher.Name=\"Teacher1\""); resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // =================================================================== // associators // // Validate role and resultRole parameters syntax. // =================================================================== // invalid role parameter syntax String invalidRole = "Teaches_*student"; Boolean gotException = false; try { resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, invalidRole, resultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // invalid resultRole parameter syntax String invalidResultRole = "3Taught_By"; gotException = false; try { resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, invalidResultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test resultRole parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // associatorNames // // Get the names of the CIM instances (Sample_Student instances) that // are associated to the source CIM instance (Sample_Teacher.Name = // "Teacher1") via an instance of the Sample_TeacherStudent association // class. // =================================================================== resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // associatorNames // // Validate role and resultRole parameters syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, invalidRole, resultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // invalid resultRole parameter syntax gotException = false; try { resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, invalidResultRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test resultRole parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // references // // Get the association instances (Sample_TeacherStudent instances) that // refer to the specified target CIM instance (Sample_Teacher.Name = // "Teacher1"). // =================================================================== resultObjects = client.references( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 5) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // =================================================================== // references // // Validate role parameter syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjects = client.references( NAMESPACE, instancePath, resultClass, invalidRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // referenceNames // // Get the names of the association instances (Sample_TeacherStudent // instances) that refer to the specified target CIM instance // (Sample_Teacher.Name = "Teacher1"). // =================================================================== resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 5) != 0) return -1; // display result // cout << "Number of reference name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // referenceNames // // Validate role parameter syntax. // =================================================================== // invalid role parameter syntax gotException = false; try { resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, invalidRole); } catch (CIMException& e) { if (e.getCode() == CIM_ERR_INVALID_PARAMETER) { gotException = true; if (verbose) { cout << "Test role parameter syntax: " << e.getMessage() << endl; } } else { throw; } } PEGASUS_TEST_ASSERT(gotException); // =================================================================== // Call the association methods with different filters specified. // Filters used are: role, resultClass, resultRole, assocClass. // =================================================================== // // get all the students who are taught by 'Teacher1' // role = "Teaches"; resultRole = "TaughtBy"; resultClass = CIMName("Sample_Student"); assocClass = SAMPLE_TEACHERSTUDENT; resultObjects = client.associators( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of associator objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // // get all the students who have 'Teacher1' as an advisor // role = "Advises"; resultRole = "AdvisedBy"; resultClass = CIMName("Sample_Student"); assocClass = SAMPLE_ADVISORSTUDENT; resultObjectPaths = client.associatorNames( NAMESPACE, instancePath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of associator name objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // // get all the TeacherStudent association instances in which 'Teacher1' // plays the role of a teacher. // role = "Teaches"; resultClass = CIMName("Sample_TeacherStudent"); resultObjects = client.references( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 3) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjects, verbose); // // get all the AdvisorStudent association instances in which 'Teacher1' // plays the role of an advisor. // role = "Advises"; resultClass = CIMName("Sample_AdvisorStudent"); resultObjectPaths = client.referenceNames( NAMESPACE, instancePath, resultClass, role); // verify result numObjects = resultObjectPaths.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of reference objects = " << numObjects << endl; _displayResult(resultObjectPaths, verbose); // =================================================================== // Pass Class object to the Association Methods // =================================================================== // // get the CIM classes that are associated with the Sample_Teacher class // CIMObjectPath classPath("Sample_Teacher"); assocClass = CIMName(); resultClass = CIMName(); role = String::EMPTY; resultRole = String::EMPTY; resultObjects = client.associators( NAMESPACE, classPath, assocClass, resultClass, role, resultRole); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 1) != 0) return -1; // display result // cout << "Number of associated class objects = " << // numObjects << endl; _displayResult(resultObjects, verbose); // // get the association classes that refer to the Sample_Teacher class // resultObjects = client.references( NAMESPACE, classPath, resultClass, role); // verify result numObjects = resultObjects.size(); if (_verifyResult(numObjects, 2) != 0) return -1; // display result // cout << "Number of association class objects = " << // numObjects << endl; _displayResult(resultObjects, verbose); } catch (Exception& e) { cerr << "Error: " << e.getMessage() << endl; return -1; } cout << "AssociationClient +++++ passed all tests" << endl; return 0; }
void testInstanceClass(CIMClient & client, const CIMName & className) { cout << "Testing Instance Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { CIMInstance currentInstance = instances[i]; CIMObjectPath currentPath = currentInstance.getPath(); if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); // // Now test association traversal // Note that the "TestAssociationClass" method does a very good job // of testing association traversal between references contained in // instances of the supplied association class. Therefore, all we // really have to do here is make sure that the results of the // associators, associatorNames, references, and referenceNames // operations are consistent. // Boolean failure = false; try { Array<CIMObject> associatorsResults = client.associators( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> associatorNamesResults = client.associatorNames( currentPath.getNameSpace(), currentPath); Array<CIMObject> referencesResults = client.references( currentPath.getNameSpace(), currentPath); Array<CIMObjectPath> referenceNamesResults = client.referenceNames( currentPath.getNameSpace(), currentPath); Uint32 numResults = associatorsResults.size(); if(numResults != associatorNamesResults.size() || numResults != referencesResults.size() || numResults != referenceNamesResults.size()) { failure = true; } else { // Check that the results for the references and referenceNames // operations are consistent. unsigned int j = 0; for(j = 0; j < numResults; ++j) { CIMObjectPath currentReferenceName = referenceNamesResults[j]; Boolean found = false; for(unsigned int k = 0; k < numResults; ++k) { if(currentReferenceName == referencesResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } } // Check that that results for the associatorNames call is // consistent with the associators call and the references // call. for(j = 0; j < numResults; ++j) { CIMObjectPath currentAssociatorName = associatorNamesResults[j]; Boolean found = false; unsigned int k = 0; for(k = 0; k < numResults; ++k) { if(currentAssociatorName == associatorsResults[k].getPath()) { found = true; break; } } if(!found) { failure = true; break; } found = false; for(k = 0; k < numResults; ++k) { CIMObject referenceInstance = referencesResults[k]; for(unsigned int x = 0, m = referenceInstance.getPropertyCount(); x < m; ++x) { CIMProperty currentProp = referenceInstance.getProperty(x); if(currentProp.getType() == CIMTYPE_REFERENCE) { CIMObjectPath currentRef; currentProp.getValue().get(currentRef); currentRef.setHost( currentAssociatorName.getHost()); if(currentRef == currentAssociatorName) { found = true; break; } } } if(found) break; } if(!found) { failure = true; break; } } } if(failure) { exitFailure( String("Association Operations returned inconsistent ") + String("results for instance ") + currentPath.toString()); } } catch(CIMException & e) { exitFailure(String("Caught exception while performing ") + String("association operations on instance ") + currentPath.toString() + String(": ") + e.getMessage()); } } cout << "Test Complete" << endl; }
void testAssociationClass(CIMClient & client, const CIMName & className) { cout << "Testing Association Class " << (const char *)className.getString().getCString() << "..."; Array<CIMInstance> instances = testAnyClass(client, className); for(unsigned int i = 0, n = instances.size(); i < n; ++i) { // // Now make sure that the references are valid and that association // traversal between them is working properly. // CIMObjectPath referenceA; CIMObjectPath referenceB; CIMInstance currentInstance = instances[i]; CIMObjectPath currentInstanceName = currentInstance.getPath(); if(currentInstanceName.getNameSpace().isNull()) currentInstanceName.setNameSpace(interopNamespace); for(unsigned int j = 0, m = currentInstance.getPropertyCount(); j < m; ++j) { CIMProperty currentProp = currentInstance.getProperty(j); if(currentProp.getValue().getType() == CIMTYPE_REFERENCE) { if(referenceA.getKeyBindings().size() == 0) { currentProp.getValue().get(referenceA); } else { currentProp.getValue().get(referenceB); break; } } } if(referenceA.getKeyBindings().size() == 0 || referenceB.getKeyBindings().size() == 0) { exitFailure( String("Could not find reference properties for ") + String("association: ") + currentInstanceName.toString()); } try { client.getInstance(referenceA.getNameSpace(), referenceA); client.getInstance(referenceB.getNameSpace(), referenceB); } catch(CIMException &) { exitFailure(String("Could not get instances for association : ") + currentInstanceName.toString()); } Boolean associationFailure = false; try { Array<CIMObjectPath> results = client.associatorNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceB.getHost()); result.setNameSpace(referenceB.getNameSpace()); if(result == referenceB) { found = true; break; } } if(found) { results = client.associatorNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath result = results[j]; result.setHost(referenceA.getHost()); result.setNameSpace(referenceA.getNameSpace()); if(result == referenceA) { found = true; break; } } } if(!found) { associationFailure = true; } } catch(CIMException & e) { cout << "Exception: " << e.getMessage() << endl; associationFailure = true; } if(associationFailure) { exitFailure(String("Association traversal failed between ") + String("instances of association: ") + currentInstanceName.toString()); } Boolean referencesFailure = false; try { Array<CIMObjectPath> results = client.referenceNames( referenceA.getNameSpace(), referenceA, className); Boolean found = false; for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } if(found) { results = client.referenceNames(referenceB.getNameSpace(), referenceB, className); for(unsigned int j = 0, m = results.size(); j < m; ++j) { CIMObjectPath currentPath = results[j]; if(currentPath.getNameSpace().isNull()) currentPath.setNameSpace(interopNamespace); if(currentPath.getHost().size() != 0) currentPath.setHost(String::EMPTY); if(currentPath == currentInstanceName) { found = true; break; } } } if(!found) { referencesFailure = true; } } catch(CIMException &) { referencesFailure = true; } if(referencesFailure) { exitFailure(String("References operation failed for ") + String("instances of association: ") + currentInstanceName.toString()); } } cout << "Test Complete" << endl; }
void _testCMPIAssociationClassOperations(CIMClient& client, CIMName className) { Array<CIMObjectPath> resultObjectPaths; Array<CIMObject> resultObjects; CIMObjectPath op(className.getString()); CIMName assocClass; CIMName resultClass; String role; String resultRole; // ======================================================================= // associators // // Get the CIM classes that are associated with the specified CIM Class // ======================================================================= if (verbose) { cout << "+++++ Test associators for (" << className.getString(); cout << ")" << endl; } try { // get the association classes resultObjects = client.associators(providerNamespace, op, assocClass, resultClass, role, resultRole); // display result _displayResult(resultObjects); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // associatorNames // // Get the name of the CIM classes that are associated with the specified // CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test associatorNames for (" << className.getString(); cout << ")" << endl; } try { resultObjectPaths = client.associatorNames( providerNamespace, op, assocClass, resultClass, role, resultRole); // display result _displayResult(resultObjectPaths); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // references // // Get the association classes that refer to the specified CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test references for (" << className.getString() << ")" << endl; } try { resultObjects = client.references( providerNamespace, op, resultClass, role); // display result _displayResult(resultObjects); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } // ======================================================================= // referenceNames // // Get the names of the association classes that refer to the specified // CIM class. // ======================================================================= if (verbose) { cout << "+++++ Test referenceNames for (" << className.getString(); cout << ")" << endl; } try { resultObjectPaths = client.referenceNames(providerNamespace, op, resultClass, role); // display result _displayResult(resultObjectPaths); } catch (Exception& e) { // Do nothing. _errorExit(e.getMessage()); } }