PEP 55 Update license on source files to current license text and date
[tpot/pegasus/.git] / src / Pegasus / Server / ProviderRegistrationManager / tests / lookupMethodProvider / lookupMethodProvider.cpp
1 //%2003////////////////////////////////////////////////////////////////////////
2 //
3 // 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 // IBM Corp.; EMC Corporation, The Open Group.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 // 
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
27 //
28 // Modified By: Carol Ann Krug Graves, Hewlett-Packard Company
29 //              (carolann_graves@hp.com)
30 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33 #include <Pegasus/Common/Config.h>
34 #include <cassert>
35 #include <Pegasus/Repository/CIMRepository.h>
36 #include <Pegasus/Client/CIMClient.h>
37 #include <Pegasus/Server/ProviderRegistrationManager/ProviderRegistrationManager.h>
38
39 PEGASUS_USING_PEGASUS;
40 PEGASUS_USING_STD;
41
42 const CIMNamespaceName NAMESPACE = CIMNamespaceName ("root/test");
43 const CIMName CLASSNAME = CIMName ("PG_ProviderModule");
44 const CIMName CLASSNAME2 = CIMName ("PG_Provider");
45 const CIMName CLASSNAME3 = CIMName ("PG_ProviderCapabilities");
46
47 Boolean TestLookupMethodProvider(ProviderRegistrationManager & prmanager)
48 {
49
50     //
51     // create Provider module instances
52     //
53     CIMObjectPath returnRef;
54
55     CIMClass cimClass(CLASSNAME);
56
57     CIMInstance cimInstance(CLASSNAME);
58
59     cimInstance.addProperty(CIMProperty(CIMName ("Name"), 
60         String("providersModule1")));
61     cimInstance.addProperty(CIMProperty(CIMName ("Vendor"), String("HP")));
62     cimInstance.addProperty(CIMProperty(CIMName ("Version"), String("2.0")));
63     cimInstance.addProperty(CIMProperty(CIMName ("InterfaceType"), 
64         String("PG_DefaultC++")));
65     cimInstance.addProperty(CIMProperty(CIMName ("InterfaceVersion"), 
66         String("2.0")));
67     cimInstance.addProperty(CIMProperty(CIMName ("Location"), 
68         String("/tmp/module1")));
69
70     CIMObjectPath instanceName = cimInstance.buildPath(cimClass);
71
72     instanceName.setNameSpace(NAMESPACE);
73     instanceName.setClassName(CLASSNAME);
74
75     try
76     {
77         returnRef = prmanager.createInstance(instanceName, cimInstance);
78     }
79     catch(CIMException& e)
80     {
81         throw (e);
82     }
83
84     // create PG_Provider instances
85
86     CIMObjectPath returnRef2;
87
88     CIMClass cimClass2(CLASSNAME2);
89
90     CIMInstance cimInstance2(CLASSNAME2);
91
92     cimInstance2.addProperty(CIMProperty(CIMName ("ProviderModuleName"), 
93         String("providersModule1")));
94     cimInstance2.addProperty(CIMProperty(CIMName ("Name"), 
95         String("PG_ProviderInstance1")));
96
97     CIMObjectPath instanceName2 = cimInstance2.buildPath(cimClass2);
98
99     instanceName2.setNameSpace(NAMESPACE);
100     instanceName2.setClassName(CLASSNAME2);
101
102     try
103     {
104         returnRef2 = prmanager.createInstance(instanceName2, cimInstance2);
105     }
106     catch(CIMException& e)
107     {
108         throw (e);
109     }
110
111     //
112     // create provider capability instances
113     //
114
115     Array <String> namespaces;
116     Array <Uint16> providerType;
117     Array <String> supportedMethods;
118
119     namespaces.append("test_namespace1");
120     namespaces.append("test_namespace2");
121     
122     providerType.append(2);
123     providerType.append(5);
124
125     supportedMethods.append("test_method1");
126     supportedMethods.append("test_method2");
127
128     CIMObjectPath returnRef3;
129
130     CIMClass cimClass3(CLASSNAME3);
131
132     CIMInstance cimInstance3(CLASSNAME3);
133
134     cimInstance3.addProperty(CIMProperty(CIMName ("ProviderModuleName"), 
135         String("providersModule1")));
136     cimInstance3.addProperty(CIMProperty(CIMName ("ProviderName"), 
137         String("PG_ProviderInstance1")));
138     cimInstance3.addProperty(CIMProperty(CIMName ("CapabilityID"), 
139         String("capability1")));
140     cimInstance3.addProperty(CIMProperty(CIMName ("ClassName"), 
141         String("test_class1")));
142     cimInstance3.addProperty(CIMProperty(CIMName ("Namespaces"), namespaces));
143     cimInstance3.addProperty(CIMProperty(CIMName ("ProviderType"), 
144         providerType));
145     cimInstance3.addProperty(CIMProperty(CIMName ("SupportedMethods"), 
146         supportedMethods));
147
148     CIMObjectPath instanceName3 = cimInstance3.buildPath(cimClass3);
149
150     instanceName3.setNameSpace(NAMESPACE);
151     instanceName3.setClassName(CLASSNAME3);
152
153     try 
154     {
155         returnRef3 = prmanager.createInstance(instanceName3, cimInstance3);
156     }
157     catch(CIMException& e)
158     {
159         throw (e);
160     }
161
162     //
163     // test lookupMethodProvider Interface
164     //
165     String _providerModuleName;
166     String _providerModuleName2;
167
168     CIMInstance providerIns;
169     CIMInstance providerModuleIns;
170
171     if (prmanager.lookupMethodProvider(CIMNamespaceName ("test_namespace1"), 
172         CIMName ("test_class1"), CIMName ("test_method2"), 
173         providerIns, providerModuleIns))
174     {
175         providerIns.getProperty(providerIns.findProperty
176             (CIMName ("ProviderModuleName"))).getValue().get
177             (_providerModuleName);
178
179         providerModuleIns.getProperty(providerModuleIns.findProperty
180             (CIMName ("Name"))).getValue().get(_providerModuleName2);
181
182         if (String::equal(_providerModuleName, _providerModuleName2))
183         {
184             return (true);
185         }
186         else
187         {
188             return (false);
189         }
190     }
191     else
192     {
193         return (false);
194     }
195 }
196
197 int main(int argc, char** argv)
198 {
199     const char* tmpDir = getenv ("PEGASUS_TMP");
200     String repositoryRoot;
201     if (tmpDir == NULL)
202     {
203         repositoryRoot = ".";
204     }
205     else
206     {
207         repositoryRoot = tmpDir;
208     }
209     repositoryRoot.append("/repository");
210     CIMRepository r (repositoryRoot) ;
211     ProviderRegistrationManager prmanager(&r);
212
213     try
214     {
215         if (!TestLookupMethodProvider(prmanager))
216         {
217             PEGASUS_STD(cerr) << "Error: lookupMethodProvider Failed" << PEGASUS_STD(endl);
218             exit (-1);
219         }
220     }
221
222     catch(Exception& e)
223     {
224         PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl);
225         PEGASUS_STD (cout) << "+++++ lookup method provider failed"
226                            << PEGASUS_STD (endl);
227         exit(-1);
228     }
229
230     PEGASUS_STD(cout) << "+++++ passed all tests" << PEGASUS_STD(endl);
231     
232     exit (0);
233 }