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

Source Code for Module tests.axis2

  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  import sys 
 18  sys.path.append('../') 
 19   
 20  import logging 
 21  import traceback as tb 
 22  import suds.metrics as metrics 
 23  from tests import * 
 24  from suds import * 
 25  from suds.client import Client 
 26  from datetime import datetime 
 27   
 28  errors = 0 
 29   
 30  setup_logging() 
 31   
 32  #logging.getLogger('suds.client').setLevel(logging.DEBUG) 
 33   
 34  url = 'http://localhost:8080/axis2/services/BasicService?wsdl' 
 35       
 36  print 'url=%s' % url 
 37   
 38  # 
 39  # create a service client using the wsdl. 
 40  # 
 41  client = Client(url) 
 42   
 43  # 
 44  # print the service (introspection) 
 45  # 
 46  print client 
 47   
 48  print 'printList()' 
 49  print client.service.printList(['a','b']) 
 50   
 51  # 
 52  # create a name object using the wsdl 
 53  # 
 54  print 'create name' 
 55  name = client.factory.create('ns2:Name') 
 56  name.first = u'jeff'+unichr(1234) 
 57  name.last = 'ortel' 
 58   
 59  print name 
 60   
 61  # 
 62  # create a phone object using the wsdl 
 63  # 
 64  print 'create phone' 
 65  phoneA = client.factory.create('ns2:Phone') 
 66  phoneA.npa = 410 
 67  phoneA.nxx = 822 
 68  phoneA.number = 5138 
 69   
 70  phoneB = client.factory.create('ns2:Phone') 
 71  phoneB.npa = 919 
 72  phoneB.nxx = 606 
 73  phoneB.number = 4406 
 74   
 75  # 
 76  # create a dog 
 77  # 
 78  dog = client.factory.create('ns2:Dog') 
 79  print dog 
 80  dog.name = 'Chance' 
 81  dog.trained = True 
 82  print dog 
 83   
 84  # 
 85  # create a person object using the wsdl 
 86  # 
 87  person = client.factory.create('ns2:Person') 
 88   
 89  # 
 90  # inspect empty person 
 91  # 
 92  print '{empty} person=\n%s' % person 
 93   
 94  person.name = name 
 95  person.age = None 
 96  person.birthday = datetime.now() 
 97  person.phone.append(phoneA) 
 98  person.phone.append(phoneB) 
 99  person.pets.append(dog) 
100   
101  # 
102  # inspect person 
103  # 
104  print 'person=\n%s' % person 
105   
106  # 
107  # add the person (using the webservice) 
108  # 
109  print 'addPersion()' 
110  result = client.service.addPerson(person) 
111  print '\nreply(\n%s\n)\n' % result.encode('utf-8') 
112   
113  # 
114  # create a new name object used to update the person 
115  # 
116  newname = client.factory.create('ns2:Name') 
117  newname.first = 'Todd' 
118  newname.last = None 
119   
120  # 
121  # update the person's name (using the webservice) and print return person object 
122  # 
123  print 'updatePersion()' 
124  result = client.service.updatePerson(person, newname) 
125  print '\nreply(\n%s\n)\n' % str(result) 
126  result = client.service.updatePerson(person, None) 
127  print '\nreply(\n%s\n)\n' % str(result) 
128   
129   
130  # 
131  # invoke the echo service 
132  # 
133  print 'echo()' 
134  client.service.echo(None) 
135  result = client.service.echo('this is cool') 
136  print '\nreply( %s )\n' % str(result) 
137   
138  print 'echo() with {none}' 
139  result = client.service.echo(None) 
140  print '\nreply( %s )\n' % str(result) 
141   
142  # 
143  # invoke the hello service 
144  # 
145  print 'hello()' 
146  result = client.service.hello() 
147  print '\nreply( %s )\n' % str(result) 
148   
149  # 
150  # invoke the testVoid service 
151  # 
152  try: 
153      print 'getVoid()' 
154      result = client.service.getVoid() 
155      print '\nreply( %s )\n' % str(result) 
156  except Exception, e: 
157      print e 
158   
159  # 
160  # test list args 
161  # 
162  print 'getList(list)' 
163  mylist = ['my', 'dog', 'likes', 'steak'] 
164  result = client.service.printList(mylist) 
165  print '\nreply( %s )\n' % str(result) 
166  # tuple 
167  print 'testListArgs(tuple)' 
168  mylist = ('my', 'dog', 'likes', 'steak') 
169  result = client.service.printList(mylist) 
170  print '\nreply( %s )\n' % str(result) 
171   
172  # 
173  # test list returned 
174  # 
175  for n in range(0, 3): 
176      print 'getList(str, %d)' % n 
177      result = client.service.getList('hello', n) 
178      print '\nreply( %s )\n' % str(result) 
179      assert ( isinstance(result, list) and len(result) == n ) 
180   
181  print 'addPet()' 
182  dog = client.factory.create('ns2:Dog') 
183  dog.name = 'Chance' 
184  dog.trained = True 
185  print dog 
186  try: 
187      result = client.service.addPet(person, dog) 
188      print '\nreply( %s )\n' % str(result) 
189  except Exception, e: 
190      print e 
191   
192  print '___________________ E X C E P T I O N S __________________________' 
193   
194  # 
195  # test exceptions 
196  # 
197  try: 
198      print 'throwException() faults=True' 
199      result = client.service.throwException() 
200      print '\nreply( %s )\n' % tostr(result) 
201  except Exception, e: 
202      print e 
203       
204  # 
205  # test faults 
206  # 
207  try: 
208      print 'throwException() faults=False' 
209      client.set_options(faults=False) 
210      result = client.service.throwException() 
211      print '\nreply( %s )\n' % tostr(result) 
212  except Exception, e: 
213      print e 
214   
215  print '\nfinished: errors=%d' % errors 
216