You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

161 lines
5.4 KiB

  1. #!/usr/bin/env python
  2. ############################################################################
  3. # Joshua R. Boverhof, David W. Robertson, LBNL
  4. # See LBNLCopyright for copyright notice!
  5. ###########################################################################
  6. import sys, unittest
  7. import ConfigParser
  8. from ZSI.wstools.Utility import DOM
  9. from ZSI.wstools.WSDLTools import WSDLReader
  10. from ZSI.wstools.TimeoutSocket import TimeoutError
  11. class WSDLToolsTestCase(unittest.TestCase):
  12. def __init__(self, methodName='runTest'):
  13. unittest.TestCase.__init__(self, methodName)
  14. def setUp(self):
  15. self.path = nameGenerator.next()
  16. print self.path
  17. sys.stdout.flush()
  18. def __str__(self):
  19. teststr = unittest.TestCase.__str__(self)
  20. if hasattr(self, "path"):
  21. return "%s: %s" % (teststr, self.path )
  22. else:
  23. return "%s" % (teststr)
  24. def checkWSDLCollection(self, tag_name, component, key='name'):
  25. if self.wsdl is None:
  26. return
  27. definition = self.wsdl.document.documentElement
  28. version = DOM.WSDLUriToVersion(definition.namespaceURI)
  29. nspname = DOM.GetWSDLUri(version)
  30. for node in DOM.getElements(definition, tag_name, nspname):
  31. name = DOM.getAttr(node, key)
  32. comp = component[name]
  33. self.failUnlessEqual(eval('comp.%s' %key), name)
  34. def checkXSDCollection(self, tag_name, component, node, key='name'):
  35. for cnode in DOM.getElements(node, tag_name):
  36. name = DOM.getAttr(cnode, key)
  37. component[name]
  38. def test_all(self):
  39. try:
  40. if self.path[:7] == 'http://':
  41. self.wsdl = WSDLReader().loadFromURL(self.path)
  42. else:
  43. self.wsdl = WSDLReader().loadFromFile(self.path)
  44. except TimeoutError:
  45. print "connection timed out"
  46. sys.stdout.flush()
  47. return
  48. except:
  49. self.path = self.path + ": load failed, unable to start"
  50. raise
  51. try:
  52. self.checkWSDLCollection('service', self.wsdl.services)
  53. except:
  54. self.path = self.path + ": wsdl.services"
  55. raise
  56. try:
  57. self.checkWSDLCollection('message', self.wsdl.messages)
  58. except:
  59. self.path = self.path + ": wsdl.messages"
  60. raise
  61. try:
  62. self.checkWSDLCollection('portType', self.wsdl.portTypes)
  63. except:
  64. self.path = self.path + ": wsdl.portTypes"
  65. raise
  66. try:
  67. self.checkWSDLCollection('binding', self.wsdl.bindings)
  68. except:
  69. self.path = self.path + ": wsdl.bindings"
  70. raise
  71. try:
  72. self.checkWSDLCollection('import', self.wsdl.imports, key='namespace')
  73. except:
  74. self.path = self.path + ": wsdl.imports"
  75. raise
  76. try:
  77. for key in self.wsdl.types.keys():
  78. schema = self.wsdl.types[key]
  79. self.failUnlessEqual(key, schema.getTargetNamespace())
  80. definition = self.wsdl.document.documentElement
  81. version = DOM.WSDLUriToVersion(definition.namespaceURI)
  82. nspname = DOM.GetWSDLUri(version)
  83. for node in DOM.getElements(definition, 'types', nspname):
  84. for snode in DOM.getElements(node, 'schema'):
  85. tns = DOM.findTargetNS(snode)
  86. schema = self.wsdl.types[tns]
  87. self.schemaAttributesDeclarations(schema, snode)
  88. self.schemaAttributeGroupDeclarations(schema, snode)
  89. self.schemaElementDeclarations(schema, snode)
  90. self.schemaTypeDefinitions(schema, snode)
  91. except:
  92. self.path = self.path + ": wsdl.types"
  93. raise
  94. if self.wsdl.extensions:
  95. print 'No check for WSDLTools(%s) Extensions:' %(self.wsdl.name)
  96. for ext in self.wsdl.extensions: print '\t', ext
  97. def schemaAttributesDeclarations(self, schema, node):
  98. self.checkXSDCollection('attribute', schema.attr_decl, node)
  99. def schemaAttributeGroupDeclarations(self, schema, node):
  100. self.checkXSDCollection('group', schema.attr_groups, node)
  101. def schemaElementDeclarations(self, schema, node):
  102. self.checkXSDCollection('element', schema.elements, node)
  103. def schemaTypeDefinitions(self, schema, node):
  104. self.checkXSDCollection('complexType', schema.types, node)
  105. self.checkXSDCollection('simpleType', schema.types, node)
  106. def setUpOptions(section):
  107. cp = ConfigParser.ConfigParser()
  108. cp.read('config.txt')
  109. if not cp.sections():
  110. print 'fatal error: configuration file config.txt not present'
  111. sys.exit(0)
  112. if not cp.has_section(section):
  113. print '%s section not present in configuration file, exiting' % section
  114. sys.exit(0)
  115. return cp, len(cp.options(section))
  116. def getOption(cp, section):
  117. for name, value in cp.items(section):
  118. yield value
  119. def makeTestSuite(section='services_by_file'):
  120. global nameGenerator
  121. cp, numTests = setUpOptions(section)
  122. nameGenerator = getOption(cp, section)
  123. suite = unittest.TestSuite()
  124. for i in range(0, numTests):
  125. suite.addTest(unittest.makeSuite(WSDLToolsTestCase, 'test_'))
  126. return suite
  127. def main():
  128. unittest.main(defaultTest="makeTestSuite")
  129. if __name__ == "__main__" : main()