Package tests :: Module rhq
[hide private]
[frames] | no frames]

Source Code for Module tests.rhq

  1  # This program is free software; you can redistribute it and/or modify 
  2  # it under the terms of the (LGPL) GNU Lesser General Public License as 
  3  # published by the Free Software Foundation; either version 3 of the  
  4  # License, or (at your option) any later version. 
  5  # 
  6  # This program is distributed in the hope that it will be useful, 
  7  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
  8  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  9  # GNU Library Lesser General Public License for more details at 
 10  # ( http://www.gnu.org/licenses/lgpl.html ). 
 11  # 
 12  # You should have received a copy of the GNU Lesser General Public License 
 13  # along with this program; if not, write to the Free Software 
 14  # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 15  # written by: Jeff Ortel ( jortel@redhat.com ) 
 16   
 17  # 
 18  # This test requires installation or visability to an RHQ server. 
 19  # ( http://www.rhq-project.org ) 
 20  # 
 21   
 22  import sys 
 23  sys.path.append('../') 
 24   
 25  import logging 
 26  import traceback as tb 
 27  import suds.metrics as metrics 
 28  from tests import * 
 29  from suds import null, WebFault 
 30  from suds.client import Client 
 31   
 32   
 33  errors = 0 
 34   
 35  setup_logging() 
 36   
 37  logging.getLogger('suds.client').setLevel(logging.DEBUG) 
 38  #logging.getLogger('suds.metrics').setLevel(logging.DEBUG) 
 39  #logging.getLogger('suds').setLevel(logging.DEBUG) 
 40   
 41   
42 -def start(url):
43 global errors 44 print '\n________________________________________________________________\n' 45 print 'Test @ ( %s ) %d' % (url, errors)
46 47
48 -def rhqTest():
49 50 global errors 51 52 url = 'http://localhost.localdomain:7080/rhq-rhq-enterprise-server-ejb3/WebservicesManagerBean?wsdl' 53 start(url) 54 client = Client(url) 55 print client 56 57 try: 58 59 # 60 # create name 61 # 62 name = client.factory.create('name') 63 name.first = u'Jeff'+unichr(1234) 64 name.last = 'Ortel < Company' 65 # 66 # create a phone object using the wsdl 67 # 68 phoneA = client.factory.create('phone') 69 phoneA.npa = 410 70 phoneA.nxx = 555 71 phoneA.number = 5138 72 phoneB = client.factory.create('phone') 73 phoneB.npa = 919 74 phoneB.nxx = 555 75 phoneB.number = 4406 76 # 77 # lets add some animals 78 # 79 dog = client.factory.create('dog') 80 dog.name = 'rover' 81 dog.age = 3 82 cat = client.factory.create('cat') 83 cat.name = 'kitty' 84 cat.age = 4 85 # 86 # create a person object using the wsdl 87 # 88 person = client.factory.create('person') 89 print person 90 person.name = name 91 person.age = 43 92 person.phone.append(phoneA) 93 person.phone.append(phoneB) 94 person.pet.append(dog) 95 person.pet.append(cat) 96 print person 97 # 98 # addPerson() 99 # 100 print 'addPersion()' 101 result = client.service.addPerson(person) 102 sent = client.last_sent() 103 rcvd = client.last_received() 104 print '\nreply(\n%s\n)\n' % result 105 # 106 # create a new name object used to update the person 107 # 108 newname = client.factory.create('name') 109 newname.first = 'Todd' 110 newname.last = None 111 # 112 # update the person's name (using the webservice) 113 # 114 print 'updatePersion()' 115 result = client.service.updatePerson(person, newname) 116 print '\nreply(\n%s\n)\n' % str(result) 117 result = client.service.updatePerson(person, None) 118 print '\nreply(\n%s\n)\n' % str(result) 119 except WebFault, f: 120 errors += 1 121 print f 122 print f.fault 123 except Exception, e: 124 errors += 1 125 print e 126 tb.print_exc() 127 128 try: 129 print "echo('this is cool')" 130 result = client.service.echo('this is cool') 131 print '\nreply( %s )\n' % str(result) 132 print 'echo(None)' 133 result = client.service.echo(None) 134 print '\nreply( %s )\n' % str(result) 135 except WebFault, f: 136 errors += 1 137 print f 138 print f.fault 139 except Exception, e: 140 errors += 1 141 print e 142 tb.print_exc() 143 144 try: 145 print 'hello()' 146 result = client.service.hello() 147 print '\nreply( %s )\n' % str(result) 148 except WebFault, f: 149 errors += 1 150 print f 151 print f.fault 152 except Exception, e: 153 errors += 1 154 print e 155 tb.print_exc() 156 157 try: 158 print 'testVoid()' 159 result = client.service.testVoid() 160 print '\nreply( %s )\n' % str(result) 161 except WebFault, f: 162 errors += 1 163 print f 164 print f.fault 165 except Exception, e: 166 errors += 1 167 print e 168 tb.print_exc() 169 170 try: 171 mylist = ['my', 'dog', 'likes', 'steak'] 172 print 'testListArgs(%s)' % mylist 173 result = client.service.testListArg(mylist) 174 print '\nreply( %s )\n' % str(result) 175 except WebFault, f: 176 errors += 1 177 print f 178 print f.fault 179 except Exception, e: 180 errors += 1 181 print e 182 tb.print_exc() 183 184 try: 185 s = 'hello' 186 for n in range(0, 3): 187 print 'getList(%s, %d)' % (s, n) 188 result = client.service.getList(s, n) 189 print '\nreply( %s )\n' % str(result) 190 if len(result) != n: 191 errors += 1 192 print 'expected (%d), reply (%d)' % (n, len(result)) 193 except WebFault, f: 194 errors += 1 195 print f 196 print f.fault 197 except Exception, e: 198 errors += 1 199 print e 200 tb.print_exc() 201 202 try: 203 print 'testExceptions()' 204 result = client.service.testExceptions() 205 print '\nreply( %s )\n' % tostr(result) 206 raise Exception('Fault expected and not raised') 207 except WebFault, f: 208 print f 209 print f.fault 210 print f.document 211 except Exception, e: 212 errors += 1 213 print e 214 tb.print_exc()
215 216 217 if __name__ == '__main__': 218 errors = 0 219 rhqTest() 220 print '\nFinished: errors=%d' % errors 221