(file) Return to SubscribeIndTest.java CVS log (file) (dir) Up to [Pegasus] / pegasus-JavaCIMClient / cimclient / tests / IndTests

File: [Pegasus] / pegasus-JavaCIMClient / cimclient / tests / IndTests / SubscribeIndTest.java (download)
Revision: 1.1, Thu Feb 12 18:12:28 2004 UTC (20 years, 4 months ago) by kumpf
Branch: MAIN
CVS Tags: pegasus25BeforeLicenseUpdate, SLPPERFINST-root, SLPPERFINST-branch, RELEASE_2_4_FC_CANDIDATE_1, RELEASE_2_4_1-BETA3, RELEASE_2_4_1-BETA2, RELEASE_2_4_1-BETA1, RELEASE_2_4_1, RELEASE_2_4_0-RC3, RELEASE_2_4_0-RC2, RELEASE_2_4_0, RELEASE_2_4-root, RELEASE_2_4-branch, RELEASE_2_3_2-branch-freeze, PEP217_PRE_BRANCH, PEP217_POST_BRANCH, PEP217_BRANCH, PEP214ROOT, PEP214BRANCH, PEP214-root, PEP214-branch, PEP213_SIZE_OPTIMIZATIONS, PEP-214B-root, MONITOR_CONSOLIDATION_2_5_BRANCH, IBM_241_April1405, CQL_2_5_BRANCH, CHUNKTESTDONE_PEP140, BUG2493_BINREP-root, BUG2493_BINREP-branch
HP-BAPU: PEP125 Enhancements to Pegasus Java Client and Java Listener

// SubscribeIndTest.java
//
// The contents of this file are subject to the SNIA Public License Version 1.0
// (the "License"); you may not use this file except in compliance with the
// License. You may obtain a copy of the License at
//
//      http://www.snia.org/resources/openSource.html
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
// License for the specific language governing rights and limitations
// under the License.
//
// The Initial Developers of the Original Code 
//     Bapu Patil ( bapu_patil@hp.com)
//     Hewlett-Packard Company.
//
// Contributor(s):
//
//

/**
 File Name: SubscribeIndTest.java
            Test program to create indication subscriptions.

 Usage:
   java SubscribeIndTest <system> <namespace> <port> [ssl]

 examples:
    java -Dorg.snia.wbem.cimom.properties=./cim.properties SubscribeIndTest

    java -Dorg.snia.wbem.cimom.properties=./cim.properties SubscribeIndTest \
				       oludeniz root/cimv2 5988

    java -Dorg.snia.wbem.cimom.properties=./cim.properties SubscribeIndTest \
                                       oludeniz root/cimv2 5989 ssl
*/
package tests.IndTests;

import java.util.Enumeration;
import java.util.Vector;
import java.util.Random;
import java.net.*;
import java.io.File;
import org.snia.wbem.client.CIMClient;
import org.snia.wbem.cim.*;
import org.snia.wbemcmd.utils.Log;

public class SubscribeIndTest {


    static final String FCCN="CIM_IndicationFilter";
    static final String IHCXML="CIM_IndicationHandlerCIMXML";
    static final String SCCN="CIM_IndicationSubscription";

    private void TestInstanceOperations(CIMClient cc, CIMNameSpace clientNameSpace)
    {
        System.out.println("\n++++ Test Instance Operations ++++");

        Random rand  =  new Random();
	int randInt = rand.nextInt(100);

        //
        // Create instance
        //
        System.out.println("\n*** create instance : CIM_IndicationFilter");
        CIMInstance cimInstance = null;
        CIMObjectPath filterPath = null;
        CIMObjectPath handlerPath = null;
        CIMObjectPath subscrPath = null;

        CIMObjectPath filterPathRef = null;
        CIMObjectPath handlerPathRef = null;

        boolean localOnly;
        boolean includeQualifiers;
        boolean includeClassOrigin;
        boolean deepInheritance;

        try
        {
            //
            // NOTE:   Filter CIM_IndicationFilter
            //
            localOnly = false;
            includeQualifiers = true;
            includeClassOrigin = true;

            CIMClass cimClass = cc.getClass(new CIMObjectPath(FCCN), 
                                            localOnly, 
                                            includeQualifiers,
                                            includeClassOrigin,
                                            null);
            CIMInstance ciFilter = cimClass.newInstance();

            ciFilter.setProperty("SystemCreationClassName", new CIMValue("Main"));
            ciFilter.setProperty("SystemName",new CIMValue("localhost"));
            ciFilter.setProperty("CreationClassName",new CIMValue(FCCN));
            ciFilter.setProperty("Name",new CIMValue("Filter"+randInt));
            ciFilter.setProperty("query",new CIMValue("SELECT * FROM RT_TestIndication"));
            ciFilter.setProperty("QueryLanguage",new CIMValue("WQL"));
            ciFilter.setProperty("sourcenamespace",new CIMValue("root/SampleProvider"));

            // create instance
            filterPath = new CIMObjectPath(FCCN, ciFilter.getKeyValuePairs()); 

	    //
	    // WORK AROUND
            // create another copy of the above instance and hold reference for later use
	    //
            filterPathRef = new CIMObjectPath(FCCN, ciFilter.getKeyValuePairs()); 
	    

            cc.createInstance(filterPath, ciFilter);
        }
        catch (CIMException ce) 
        {
            System.err.println("\nFailed to create CIM_IndicationFilter instance: " + ce);
	    ce.printStackTrace();
            System.exit(1);
        }

        System.out.println("\n*** get instance : CIM_IndicationFilter");
        //
        // Verify that the instance gets created
        //
        CIMInstance newInstance = null;
        try
        {
            localOnly = false;
            includeQualifiers = false;
            includeClassOrigin = false;

            newInstance=cc.getInstance(filterPath,
                                       localOnly,
                                       includeQualifiers,
                                       includeClassOrigin,
                                       null);
        }
        catch (CIMException ce) 
        {
                System.err.println("\nFailed to get CIM_IndicationFilter instance: " + ce);
        }
    


/*********************** Create Indication CIMXML Handler  Instance ******/
        //
        // Create Indication CIMXML Handler  Instance
        //
        try 
        {
          localOnly = false;
          includeQualifiers = true;
          includeClassOrigin = true;

          CIMClass IndHdlr=cc.getClass(new CIMObjectPath(IHCXML),
                                            localOnly, 
                                            includeQualifiers,
                                            includeClassOrigin,
                                            null);
          CIMInstance ciHandler=IndHdlr.newInstance();

          ciHandler.setProperty("SystemCreationClassName", new CIMValue("Main"));
          ciHandler.setProperty("SystemName",new CIMValue("localhost"));
          ciHandler.setProperty("CreationClassName",new CIMValue(IHCXML));
          ciHandler.setProperty("Name",new CIMValue("Handler"+randInt));
          ciHandler.setProperty("Destination", 
		        new CIMValue("https://oludeniz:8189/cimom/RT_IndicationConsumer"));

          // create instance
          System.out.println("\n*** create instance : IndicationCIMXMLHandler");

          handlerPath = new CIMObjectPath(IHCXML, ciHandler.getKeyValuePairs()); 

	  //
	  // WORK AROUND
          // create another copy of the above instance and hold reference for later use
	  //
          handlerPathRef = new CIMObjectPath(IHCXML, ciHandler.getKeyValuePairs()); 
          cc.createInstance(handlerPath, ciHandler);
        }
        catch (CIMException e) 
        {
          System.err.println("--- Create Indication CIMXML Handler  Instance failed: "+e);
	  e.printStackTrace();
          System.exit(5);
        }

        //
        // Verify that the Handler instance gets created
        //
        System.out.println("\n*** get instance : IndicationCIMXMLHandler");
        CIMInstance newHandler = null;
        try
        {
            localOnly = false;
            includeQualifiers = false;
            includeClassOrigin = false;

            newHandler=cc.getInstance(handlerPath,
                                       localOnly,
                                       includeQualifiers,
                                       includeClassOrigin,
                                       null);
        }
        catch (CIMException ce) 
        {
                System.err.println("\nFailed to get IndicationCIMXMLHandler instance: " + ce);
        }

/*********************** Create Subscription Instance ****** */
        //
        // Create Indication Subscription Instance
        //
        try 
        {

          localOnly = false;
          includeQualifiers = true;
          includeClassOrigin = true;

          System.out.println("\n*** create instance : " + SCCN);
          CIMClass subscrp =cc.getClass(new CIMObjectPath(SCCN),
                                            localOnly, 
                                            includeQualifiers,
                                            includeClassOrigin,
                                            null);
          CIMInstance ciSubscrp=subscrp.newInstance();

         // Bapu
         // Creates a REFERENCE data type
         // we could do like this
         //   new CIMValue(path,CIMDataType.getPredefinedType(CIMDataType.REFERENCE));
         //

	 //
         // setHost to NotSet  - do not use this if there is work around
	 // defined above in  WORK AROUND to store references.
	 //  
	 //filterPath.setHost(CIMObjectPath.NOT_SET);
	 //filterPath.setNameSpace(CIMObjectPath.NOT_SET);
	 //handlerPath.setHost(CIMObjectPath.NOT_SET);
	 //handlerPath.setNameSpace(CIMObjectPath.NOT_SET);
	 //

         CIMDataType filterDT = new CIMDataType(FCCN);
         CIMDataType handlerDT = new CIMDataType(IHCXML);
         ciSubscrp.setProperty("Filter", new CIMValue(filterPathRef, filterDT));
         ciSubscrp.setProperty("Handler", new CIMValue(handlerPathRef, handlerDT));
	 
	 // If I set this to 4 , I can not delete handler instance
         //ciSubscrp.setProperty("SubscriptionState", 
         //            new CIMValue(new Integer(4), new CIMDataType(CIMDataType.UINT16)));


	 // If I set this to 2 , I can not create this instance
         // Fails
         ciSubscrp.setProperty("SubscriptionState", 
                    new CIMValue(new Integer(2), new CIMDataType(CIMDataType.UINT16)));

          // create instance
          subscrPath = new CIMObjectPath(SCCN,
                                     ciSubscrp.getKeyValuePairs());
          cc.createInstance(subscrPath, ciSubscrp);
        }
        catch (CIMException e) 
        {
          System.err.println("--- make subscription failed: "+e);
	  e.printStackTrace();
          System.exit(5);
        }

        //
        // Verify that the Handler instance gets created
        //
        System.out.println("\n*** get instance : " + SCCN);
        CIMInstance newSubscrption = null;
        try
        {
            localOnly = false;
            includeQualifiers = false;
            includeClassOrigin = false;

            newSubscrption=cc.getInstance(subscrPath,
                                       localOnly,
                                       includeQualifiers,
                                       includeClassOrigin,
                                       null);
        }
        catch (CIMException ce) 
        {
                System.err.println("\nFailed to get instance: " + ce);
        }

/**************/
        System.out.println("\n*** Delete subscriptions ");
        try
        {
            System.out.println("\n*** Delete subscription instance");
            cc.deleteInstance(subscrPath);

            System.out.println("\n*** Delete filter instance");
            cc.deleteInstance(filterPath);

            System.out.println("\n*** Delete handler instance");
            cc.deleteInstance(handlerPath);

        }
        catch (CIMException ce) 
        {
                System.err.println("\nFailed to delete instance: " + ce);
	        ce.printStackTrace();
                System.exit(1);
        }
    }


    public void runTests(String args[])
    {
        CIMNameSpace clientNameSpace = null;
        String hostName = "localhost";          // host for cimom
        String nameSpace = "root/PG_InterOp";        // namespace
        CIMClient cc=null;
        int portNo=CIMNameSpace.DEFAULT_PORT;
        String hostURL;
        String isSSL=null;
                
        if (args.length>=3) {
            hostName=args[0];
            nameSpace=args[1];
            portNo=Integer.parseInt(args[2]);
        } else 
        if (args.length!=0) {
            System.out.println("TestClient [hostname namespace port [ssl] ]");
            System.exit(1);
        }
        if (args.length==4 && args[3].equalsIgnoreCase("ssl") )
        {
            isSSL=args[3];
        }
        if ( isSSL != null )
            hostURL="https://"+hostName+":"+portNo;
        else
            hostURL="http://"+hostName+":"+portNo;
        
        System.out.println("Connecting to "+hostURL+
                           " for namespace "+nameSpace);
        try 
        {
            clientNameSpace = new CIMNameSpace(hostURL, nameSpace);  
            cc = new CIMClient(clientNameSpace, "guest", "guest", CIMClient.XML);
        } catch (CIMException e) {
            System.err.println("\nFailed to connect to CIMOM: " + e);
            System.exit(1);
        }
        
        System.out.println("\nCIM client created.");


        TestInstanceOperations(cc, clientNameSpace);

    }

    public SubscribeIndTest() 
    { 
    }

///////////////////////////////////////////////////////////////
//    Main
///////////////////////////////////////////////////////////////

   public static void main(String args[])
   {
        System.setProperty("org.snia.wbem.cimom.properties", "./cim.properties");

        String logFileName = "/tmp/javaclienttest.log"; 
        File logFile = new File(logFileName);
        logFile.delete();

        SubscribeIndTest ea=new SubscribeIndTest();
        ea.runTests(args);

        System.out.println("\n++++ Java Indications TestClient Terminated Normally.");
        System.exit(0);
   }
}

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2