void _testReferenceNames(CIMClient& client, CIMObjectPath instancePath,
                         Uint32 numExpectedObjects)
{
    if (verbose)
    {
        cout << "Object Name: " << instancePath.toString() << endl;
    }

    try
    {
        // get the reference instance names
        //
        Array<CIMObjectPath> resultObjectPaths;
        CIMName resultClass;
        String role;

        resultObjectPaths = client.referenceNames(
            providerNamespace,
            instancePath,
            resultClass,
            role);

        // verify result
        _verifyResult(resultObjectPaths.size(), numExpectedObjects);

        // display result
        _displayResult(resultObjectPaths);
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }
}
Esempio n. 2
0
void _testReferences(CIMClient& client, CIMObjectPath instancePath)
{
    try
    {
        // get the association reference instances
        Array<CIMObject> resultObjects;
        Array<CIMObjectPath> resultObjectPaths;
        CIMName resultClass;
        String role;

        resultObjects = client.references(
            providerNamespace,
            instancePath,
            resultClass,
            role);
        resultObjectPaths = client.referenceNames(
            providerNamespace,
            instancePath,
            resultClass,
            role);
    }
    catch (const Exception& e)
    {
         _errorExit(e.getMessage());
    }
}
void _testAssociatorNames(CIMClient& client, CIMName assocClass,
                          CIMObjectPath instancePath, Uint32 numExpectedObjects)
{
    if (verbose)
    {
        cout << "Association Class: " << assocClass.getString() << endl;
        cout << "Object Name: " << instancePath.toString() << endl;
    }

    try
    {
        // 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(providerNamespace, instancePath,
                                   assocClass, resultClass, role, resultRole);
        // verify result
        _verifyResult(resultObjectPaths.size(), numExpectedObjects);

        // display result
        _displayResult(resultObjectPaths);
    }
    catch (Exception& e)
    {
         _errorExit(e.getMessage());
    }
}
Esempio n. 4
0
int main(int argc, char** argv)
{
    providerNamespace = CIMNamespaceName ("test/TestProvider");
    CIMClient client;

    // Connect to server
    try
    {
        client.connectLocal();
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }

    // Get the instance object paths for the Person and Vehicle class
    Array<CIMObjectPath> personRefs;
    try
    {
        personRefs =
            client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON);
    }
    catch (Exception& e)
    {
        cerr << "enumerateInstanceNames() failed." << endl;
        _errorExit(e.getMessage());
    }
    Uint32 numPersonInstances = personRefs.size();

    // Test associators
    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testAssociators(client, CMPI_TEST_FAIL, personRefs[i]);
    }

    // Test references
    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testReferences(client, personRefs[i]);
    }

    _testInstanceError(client);
    _testMethodError(client);

    cout << argv[0] << " +++++ passed all tests" << endl;
    return(0);
}
Esempio n. 5
0
static void _testInstanceError(CIMClient &client)
{
#ifndef PEGASUS_DISABLE_EXECQUERY
    try
    {
        String wql ("WQL");

        Array < CIMObject > objects = client.execQuery(
            providerNamespace,
            wql,
            queries);
    }
    catch (const Exception & e)
    {
        _errorExit(e.getMessage());
    }
#endif
}
Esempio n. 6
0
int main()
{
    // Connect to server
    try
    {
        client.connectLocal();
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }

    try
    {
        cout << "\n+++++ passed all tests" << endl;
    }
    catch(Exception)
    {
        cout << "\n----- Test Static Client Failed" << endl;
    }
    return(0);
}
Esempio n. 7
0
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)
{
    // Variables to collect the CIMServer properties.
    Array<String> propertyValues;
    String currentValue;
    CIMClient client;

    // Check command line option

    if (argc > 2)
    {
        cerr << "Usage: TestAggregationOutputClient [-v]" << endl;
        return 1;
    }

    if (2 == argc)
    {
        const char *opt = argv[1];
        if (0 == strcmp(opt, "-v"))
        {
            verbose = true;
        }
        else
        {
            cerr << "Usage: TestAggregationOutputClient [-v]" << endl;
            return 1;
        }
    }

    // Connect to server
    try
    {
        client.connectLocal();
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }

    // Get the Property value from CIMServer with REPOSITORY_DEFAULT

    getPropertiesFromCIMServer(client, REPOSITORY_DEFAULT, propertyValues);
    currentValue = propertyValues[2];

    if (currentValue == "true")
       My_isDefaultInstanceProvider = 1;

    cout << "+++++ Test AggregationOutput Provider" << endl;
    cout << endl;

    if (verbose)
    {
        cout << "+++++ Testing with repositoryIsDefaultInstanceProvider =  "
             << My_isDefaultInstanceProvider << endl;
    }
    try
    {
        _testaggregation(client);
        _testFromRepository(client);
        _testNotSupported(client);
        _testNotFound(client);
    }
    catch (Exception&)
    {
        cout << "\n----- Test Aggregation Failed" << endl;
    }
    // Disconnect from server
    try
    {
        client.disconnect();
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }

    return 0;
}
void _testaggregation(CIMClient& client)
{
    Uint32 a_count = 0;
    Uint32 an_count = 0;
    Uint32 r_count = 0;
    Uint32 rn_count = 0;

    cout << "\n+++++ Test aggregation of Static and Dynamic instances" << endl;
    try
    {
        Array<CIMObjectPath> teachesRefs;
        Array<CIMObjectPath> personRefs;
        Uint32 numteachesInstances ;
        Uint32 numpersonInstances ;

        teachesRefs = client.enumerateInstanceNames(NAMESPACE, TEST_TEACHES);
        numteachesInstances = teachesRefs.size();
        if (verbose)
        {
            cout << "     TEST_Teaches :: " ;
            cout << "     Number of instances " << numteachesInstances << endl;
        }

        // Checking the RepositoryIsDefaultInstanceProvider and the number
        // of instances returned.

        if (My_isDefaultInstanceProvider == 1 && 2 != numteachesInstances)
        {
            throw Exception(" Unexpected number of instances returned with "
                "Repository Enabled. ");
        }
        else if (My_isDefaultInstanceProvider == 0 && 1 != numteachesInstances)
        {
            throw Exception(" Unexpected number of instances returned with "
                "Repository Disabled. ");
        }

        personRefs = client.enumerateInstanceNames(NAMESPACE, TEST_PERSON);
        numpersonInstances = personRefs.size();

        for (Uint32 i = 0; i < numpersonInstances; ++i)
        {
            a_count  += _testAssociators(client, TEST_TEACHES, personRefs[i]);
            an_count +=
                _testAssociatorNames(client, TEST_TEACHES, personRefs[i]);
            r_count  += _testReferences(client, personRefs[i],TEST_TEACHES);
            rn_count +=
                _testReferenceNames(client, personRefs[i], TEST_TEACHES);
        }
        if (a_count != 2*numteachesInstances ||
            an_count != 2*numteachesInstances ||
            r_count != 2*numteachesInstances ||
            rn_count != 2*numteachesInstances)
        {
            throw Exception(" The number of instances returned is incorrect.");
        }
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }
    cout << "\n+++++ Test aggregation of Static and Dynamic instances passed"
         << endl;
}
int main(int argc, char** argv)
{
    verbose = (getenv("PEGASUS_TEST_VERBOSE")) ? true : false;

    //
    // Check for command line option
    //
    if (argc != 2)
    {
        cerr << "Usage: TestCMPIAssociation {namespace}" << endl;
        return(1);
    }

    providerNamespace = CIMNamespaceName (argv[1]);

    CIMClient client;

    // Connect to server
    try
    {
        client.connectLocal();
    }
    catch (Exception& e)
    {
        _errorExit(e.getMessage());
    }

    // =======================================================================
    // Test passing Instance object path to the Association Methods
    // =======================================================================

    // Get the instance object paths for the Person and Vehicle class
    //
    Array<CIMObjectPath> personRefs;
    Array<CIMObjectPath> vehicleRefs;
    try
    {
        personRefs =
            client.enumerateInstanceNames(providerNamespace, CMPI_TEST_PERSON);
        vehicleRefs =
            client.enumerateInstanceNames(providerNamespace, CMPI_TEST_VEHICLE);
    }
    catch (Exception& e)
    {
        cerr << "enumerateInstanceNames() failed." << endl;
        _errorExit(e.getMessage());
    }

    for(Uint32 i=0;i<personRefs.size();i++)
    {
        cout<<"PersonRefs values : "<<personRefs[i].toString()<<endl;
    }
    for(Uint32 i=0;i<vehicleRefs.size();i++)
    {
        cout<<"VehicleRefs values : "<<vehicleRefs[i].toString()<<endl;
    }
    Uint32 numPersonInstances = personRefs.size();
    Uint32 numVehicleInstances = vehicleRefs.size();

    cout << "Number of PersonInstances: " << numPersonInstances << endl;
    cout << "Number of VehicleInstances: " << numVehicleInstances << endl;
    


    // =======================================================================
    // Test associators
    //
    // Get the CIM instances that are associated with the specified source CIM
    // instance via an instance of a specified association class.
    // =======================================================================

    if (verbose)
    {
        cout << "+++++ Test associators" << endl;
    }

    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testAssociators(
            client,
            CMPI_TEST_RACING,
            personRefs[i],
            resultArray_asso_P1[i]);
    }

    for (Uint32 i = 0; i < numVehicleInstances; i++)
    {
       _testAssociators(client, CMPI_TEST_RACING, vehicleRefs[i],
                        resultArray_asso_V1[i]);
    }

    // =======================================================================
    // Test associatorNames
    //
    // Get the names of the CIM instances that are associated with the specified
    // source CIM instance via an instance of a association class.
    // =======================================================================

    if (verbose)
    {
        cout << "+++++ Test associatorNames" << endl;
    }

    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testAssociatorNames(client, CMPI_TEST_RACING, personRefs[i],
            resultArray_asso_P1[i]);
    }
    for (Uint32 i = 0; i < numVehicleInstances; i++)
    {
        _testAssociatorNames(client, CMPI_TEST_RACING, vehicleRefs[i],
            resultArray_asso_V1[i]);
    }

    // =======================================================================
    // Test references
    //
    // Get the association instances that refer to the specified target CIM
    // instance.
    // =======================================================================

    if (verbose)
    {
        cout << "+++++ Test references" << endl;
    }

    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testReferences(client, personRefs[i], resultArray_ref_P[i]);
    }
    for (Uint32 i = 0; i < numVehicleInstances; i++)
    {
        _testReferences(client, vehicleRefs[i], resultArray_ref_V[i]);
    }
    
    // =======================================================================
    // Test property filter for associators and references
    // =======================================================================
    _testCMPIFilterOfAssociation(client);

    // =======================================================================
    // Test referenceNames
    //
    // Get the names of the association instances that refer to the specified
    // source CIM instance.
    // =======================================================================

    if (verbose)
    {
        cout << "+++++ Test referenceNames" << endl;
    }

    for (Uint32 i = 0; i < numPersonInstances; i++)
    {
        _testReferenceNames(client, personRefs[i], resultArray_ref_P[i]);
    }
    for (Uint32 i = 0; i < numVehicleInstances; i++)
    {
        _testReferenceNames(client, vehicleRefs[i], resultArray_ref_V[i]);
    }

    // =======================================================================
    // Test passing Class object path to the Association Methods
    // =======================================================================

    if (verbose)
    {
        cout << "+++++ Test association class operations" << endl;
    }

    _testCMPIAssociationClassOperations(client, CMPI_TEST_PERSON);
    _testCMPIAssociationClassOperations(client, CMPI_TEST_VEHICLE);

    // =======================================================================
    // Association tests completed
    // =======================================================================

    cout << argv[0] << " +++++ passed all tests" << endl;
    return(0);
}
void _testCMPIFilterOfAssociation(CIMClient& client)
{
    try
    {
        Array<CIMObjectPath> personRefs;
        Uint32 numPersonInstances ;
        personRefs = 
            client.enumerateInstanceNames(providerNamespace,CMPI_TEST_PERSON);
        numPersonInstances = personRefs.size();
        CIMName resultClass;
        String role;
        String resultRole;
        cout<<"++++++++Filtering the NULL propery list+++"<<endl;
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList());
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                Uint32 propNameCount = 0;
                if(propCount != 0)
                {
                    String propName=
                        resultObjects[j].getProperty(0).getName().getString();
                    if(verbose)
                    {
                        cout<<"Property Name of :"<<i<<":"<<propName<<endl;
                    }
                    if(propName == "vehiclename") 
                    {
                        propNameCount++;
                    }
                }
                if((size != 0)&&(propCount == 1) &&(propNameCount == 1))
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
                        <<":Filtering the ciminstance with a NULL property list"
                        <<" returned all properties as expected"<<endl;
                }
                else
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a NULL property list"
                        <<" did not return all properties as expected"<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }

        }
        cout<<"++++++Filtering the empty propery list+++"<<endl;
        Array<CIMName> propList;
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList(propList));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                if((size != 0)&&(propCount == 0))
                {
                    cout<<"Filter associator test on CMPI_TEST_RACING SUCCEEDED"
                        <<":Filtering the ciminstance with a empty property "
                        <<"list returned zero properties as expected"<<endl;
                }
                else
                { 
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a empty property "
                        <<"list returned some properties which is not expected"
                        <<endl; 
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
        cout<<"+++filtering the wrong properties ++++++"<<endl;
        Array<CIMName> propList1;
        propList1.append(CIMName(String("nam")));
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList(propList1));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                if((size != 0)&&(propCount == 0))
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING "
                        <<"SUCCEEDED:Filtering the ciminstance with a wrong "
                        <<"property list returned zero properties as " 
                        <<"expected"<<endl;
                }
                else
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                         <<":Filtering the ciminstance with a wrong property "
                         <<"list returned some properties which is not"
                         <<" expected"<<endl; 
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
        cout<<"++++++++Filtering the mentioned propery list+++"<<endl;
        Array<CIMName> propArr;
        propArr.append(CIMName(String("vehiclename")));
        for (Uint32 i = 0; i < numPersonInstances; ++i)
        {
            Array<CIMObject> resultObjects =
                client.associators(
                    providerNamespace,
                    personRefs[i],
                    CMPI_TEST_RACING,
                    resultClass,
                    role,
                    resultRole,
                    false,
                    false,
                    CIMPropertyList( propArr));
            Uint32 size = resultObjects.size();
            for(Uint32 j = 0;j<size;j++)
            {
                Uint32 propCount = resultObjects[j].getPropertyCount();
                Uint32 propNameCount = 0;
                if(propCount != 0)
                {
                    String propName=
                        resultObjects[j].getProperty(0).getName().getString();
                    if(verbose)
                    {
                        cout<<"Property Name of :"<<i<<":"<<propName<<endl;
                    }
                    if(propName == "vehiclename")
                    {
                        propNameCount++;
                    }
                }
                if((size != 0)&&(propCount == 1) &&(propNameCount == 1))
                {
                     cout<<"Filter associators test on CMPI_TEST_RACING "
                         <<"SUCCEEDED:Filtering the ciminstance with a "
                         <<"mentioned property list returned all properties"
                         <<" as expected"<<endl;
                }
                else
                {
                    cout<<"Filter associators test on CMPI_TEST_RACING FAILED"
                        <<":Filtering the ciminstance with a mentioned property"
                        <<" list did not return properties as expected "<<endl;
                    PEGASUS_TEST_ASSERT(false);
                }
            }
        }
    }
    catch(Exception& e)
    {
        cerr << "enumerateInstanceNames() failed." << endl;
            _errorExit(e.getMessage());
    }
}
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());
    }
}