(file) Return to SystemLogHandler.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Handler / SystemLogListenerDestination / tests

  1 martin 1.2 //%2005////////////////////////////////////////////////////////////////////////
  2 yi.zhou 1.1 //
  3 martin  1.2 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4             // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5             // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 yi.zhou 1.1 // IBM Corp.; EMC Corporation, The Open Group.
  7             // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8             // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9 martin  1.2 // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10             // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 yi.zhou 1.1 //
 12             // Permission is hereby granted, free of charge, to any person obtaining a copy
 13             // of this software and associated documentation files (the "Software"), to
 14             // deal in the Software without restriction, including without limitation the
 15             // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 16             // sell copies of the Software, and to permit persons to whom the Software is
 17             // furnished to do so, subject to the following conditions:
 18             // 
 19             // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 20             // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 21             // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 22             // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 23             // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 24             // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 25             // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 26             // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 27             //
 28             //==============================================================================
 29             //
 30             // Author: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
 31             //
 32 yi.zhou 1.1 //%/////////////////////////////////////////////////////////////////////////////
 33             
 34             #include <Pegasus/Common/Config.h>
 35             #include <Pegasus/Common/FileSystem.h>
 36             #include <Pegasus/Common/Constants.h>
 37             #include <Pegasus/Common/System.h>
 38             #include <cassert>
 39             #include <Pegasus/Client/CIMClient.h>
 40             
 41             PEGASUS_USING_PEGASUS;
 42             PEGASUS_USING_STD;
 43             
 44             const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/PG_InterOp");
 45             
 46             CIMObjectPath CreateHandler1Instance (CIMClient& client)
 47             {
 48                 CIMInstance handlerInstance(PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG);
 49                 handlerInstance.addProperty (CIMProperty (CIMName
 50                     ("SystemCreationClassName"), System::getSystemCreationClassName ()));
 51                 handlerInstance.addProperty (CIMProperty (CIMName ("SystemName"),
 52                     System::getFullyQualifiedHostName ()));
 53 yi.zhou 1.1     handlerInstance.addProperty (CIMProperty (CIMName ("CreationClassName"),
 54                     PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG.getString ()));
 55                 handlerInstance.addProperty(CIMProperty(CIMName ("Name"), 
 56             	String("Handler1")));
 57             
 58                 CIMObjectPath Ref = client.createInstance(NAMESPACE, handlerInstance);
 59                 return (Ref);
 60             }
 61             
 62             CIMObjectPath CreateFilterInstance (CIMClient& client, 
 63                 const String & query, 
 64                 const String & name)
 65             {
 66                 CIMInstance filterInstance(PEGASUS_CLASSNAME_INDFILTER);
 67                 filterInstance.addProperty (CIMProperty (CIMName
 68             	("SystemCreationClassName"), System::getSystemCreationClassName ()));
 69                 filterInstance.addProperty (CIMProperty (CIMName ("SystemName"),
 70             	System::getFullyQualifiedHostName ()));
 71                 filterInstance.addProperty(CIMProperty(CIMName ("CreationClassName"),
 72                     PEGASUS_CLASSNAME_INDFILTER.getString()));
 73                 filterInstance.addProperty(CIMProperty(CIMName ("Name"), name));
 74 yi.zhou 1.1     filterInstance.addProperty (CIMProperty(CIMName ("Query"), query));
 75                 filterInstance.addProperty (CIMProperty(CIMName ("QueryLanguage"),
 76                     String("WQL")));
 77                 filterInstance.addProperty (CIMProperty(CIMName ("SourceNamespace"),
 78                     String("root/SampleProvider")));
 79             
 80                 CIMObjectPath Ref = client.createInstance(NAMESPACE, filterInstance);
 81                 return (Ref);
 82             }
 83             
 84             CIMObjectPath CreateFormattedSubscriptionIns (CIMClient& client,
 85                 const CIMObjectPath & handlerRef, 
 86                 const CIMObjectPath & filterRef,
 87                 const String & textFormat,
 88                 const Array<String> & textFormatParams)
 89             {
 90                 CIMInstance subscriptionInstance
 91                     (PEGASUS_CLASSNAME_FORMATTEDINDSUBSCRIPTION);
 92                 subscriptionInstance.addProperty(CIMProperty(CIMName ("Filter"),
 93                     filterRef, 0, PEGASUS_CLASSNAME_INDFILTER));
 94                 subscriptionInstance.addProperty(CIMProperty(CIMName ("Handler"),
 95 yi.zhou 1.1         handlerRef, 0, PEGASUS_CLASSNAME_LSTNRDST_SYSTEM_LOG));
 96                 subscriptionInstance.addProperty (CIMProperty
 97                     (CIMName ("SubscriptionState"), CIMValue ((Uint16) 2)));
 98                 subscriptionInstance.addProperty (CIMProperty
 99                     (CIMName ("TextFormat"), textFormat));
100                 subscriptionInstance.addProperty (CIMProperty
101                     (CIMName ("TextFormatParameters"), textFormatParams));
102             
103                 CIMObjectPath Ref = client.createInstance(NAMESPACE, 
104             	subscriptionInstance);
105                 return (Ref);
106             }
107             
108             void generateIndication(CIMClient& client)
109             {
110                 CIMInstance indicationInstance (CIMName("RT_TestIndication"));
111             
112                 CIMObjectPath path ;
113                 path.setNameSpace("root/SampleProvider");
114                 path.setClassName("RT_TestIndication");
115             
116 yi.zhou 1.1     indicationInstance.setPath(path);
117             
118                 Array<CIMParamValue> inParams;
119                 Array<CIMParamValue> outParams;
120             
121                 CIMValue ret_value = client.invokeMethod(
122             	"root/SampleProvider",
123                     path,
124             	"SendTestIndication",
125                     inParams,
126             	outParams);
127             }
128             
129             void DeleteInstance (CIMClient& client, const CIMObjectPath Ref)
130             {
131                 client.deleteInstance(NAMESPACE, Ref);
132             }
133             
134             int main(int argc, char** argv)
135             {
136                 CIMClient client;
137 yi.zhou 1.1     try
138                 {
139                     client.connectLocal();
140                 }
141                 catch (Exception & e)
142                 {
143                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
144                                        << PEGASUS_STD (endl);
145                     PEGASUS_STD (cerr) << "Client connects local failed" 
146                                        << PEGASUS_STD (endl);
147                     return (-1);
148                 }
149             
150                 CIMObjectPath Handler1Ref; 
151                 CIMObjectPath Filter1Ref, Filter2Ref;
152                 CIMObjectPath Subscription1Ref, Subscription2Ref;
153             
154                 try
155                 {
156                     Handler1Ref = CreateHandler1Instance (client);
157                 }
158 yi.zhou 1.1     catch (Exception& e)
159                 {
160                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
161                                        << PEGASUS_STD (endl);
162                     PEGASUS_STD (cerr) << "create handler instance failed" 
163                                        << PEGASUS_STD (endl);
164                     return (-1);
165                 }
166             
167                 PEGASUS_STD (cout) << "+++++ handler instances created" 
168                                    << PEGASUS_STD (endl);
169                 try
170                 {
171             	String query="SELECT * FROM rt_testindication";
172             	String name1 = "TestFilter01";
173                     Filter1Ref = CreateFilterInstance (client, query, name1);
174                 }
175                 catch (Exception& e)
176                 {
177                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
178                                        << PEGASUS_STD (endl);
179 yi.zhou 1.1         PEGASUS_STD (cerr) << "create filter instances failed" 
180                                        << PEGASUS_STD (endl);
181                     return (-1);
182                 }
183             
184                 PEGASUS_STD (cout) << "+++++ filter instances created" 
185                                    << PEGASUS_STD (endl);
186                 try
187                 {
188             	Array<String> textFormatParams;
189             	textFormatParams.append("IndicationTime");
190             	textFormatParams.append("IndicationIdentifier");
191             
192             	// create a formatted subscription
193                     Subscription1Ref = 
194                       CreateFormattedSubscriptionIns (client, Handler1Ref, Filter1Ref, 
195             	  "The indication occured at {0, datetime} with Indication ID {1}.",
196             	  textFormatParams);
197             
198                 }
199                 catch (Exception& e)
200 yi.zhou 1.1     {
201                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
202                                        << PEGASUS_STD (endl);
203                     PEGASUS_STD (cerr) << "create subscription instance failed" 
204                                        << PEGASUS_STD (endl);
205                     return (-1);
206                 }
207             
208                 PEGASUS_STD (cout) << "+++++ subscription instances created" 
209                                    << PEGASUS_STD (endl);
210             
211                 try
212                 {
213                     // generate indication
214             
215                     generateIndication(client);
216                 }
217                 catch (Exception& e)
218                 {
219                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
220                                        << PEGASUS_STD (endl);
221 yi.zhou 1.1         PEGASUS_STD (cerr) << "generate indication failed" 
222                                        << PEGASUS_STD (endl);
223                     return (-1);
224                 }
225             
226                 PEGASUS_STD (cout) << "+++++ indications generated" 
227                                    << PEGASUS_STD (endl);
228             
229                 try
230                 {
231                     DeleteInstance (client, Subscription1Ref);
232                     DeleteInstance (client, Filter1Ref);
233                     DeleteInstance (client, Handler1Ref);
234                 }
235                 catch (Exception& e)
236                 {
237                     PEGASUS_STD (cerr) << "Exception: " << e.getMessage () 
238                                        << PEGASUS_STD (endl);
239                     PEGASUS_STD (cerr) << "delete instance failed" 
240                                        << PEGASUS_STD (endl);
241                     exit (-1);
242 yi.zhou 1.1     }
243             
244                 PEGASUS_STD (cout) << "+++++ instances deleted" 
245                                    << PEGASUS_STD (endl);
246             
247                 PEGASUS_STD (cout) << "+++++ TestSyslogHandler passed all tests" 
248                                    << PEGASUS_STD (endl);
249             
250             }

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2