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.
 
 
 

145 lines
4.9 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. from ZSI.wstools.Utility import DOM
  8. import utils
  9. class WSDLToolsTestCase(unittest.TestCase):
  10. def __init__(self, methodName='runTest'):
  11. unittest.TestCase.__init__(self, methodName)
  12. def setUp(self):
  13. global configLoader
  14. # not thread safe
  15. self.path = configLoader.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 wsdlTestAll(self):
  39. try:
  40. self.wsdl = utils.setUpWsdl(self.path)
  41. except:
  42. self.path = self.path + ": load failed, unable to start"
  43. raise
  44. try:
  45. self.checkWSDLCollection('service', self.wsdl.services)
  46. except:
  47. self.path = self.path + ": wsdl.services"
  48. raise
  49. try:
  50. self.checkWSDLCollection('message', self.wsdl.messages)
  51. except:
  52. self.path = self.path + ": wsdl.messages"
  53. raise
  54. try:
  55. self.checkWSDLCollection('portType', self.wsdl.portTypes)
  56. except:
  57. self.path = self.path + ": wsdl.portTypes"
  58. raise
  59. try:
  60. self.checkWSDLCollection('binding', self.wsdl.bindings)
  61. except:
  62. self.path = self.path + ": wsdl.bindings"
  63. raise
  64. try:
  65. self.checkWSDLCollection('import', self.wsdl.imports, key='namespace')
  66. except:
  67. self.path = self.path + ": wsdl.imports"
  68. raise
  69. try:
  70. for key in self.wsdl.types.keys():
  71. schema = self.wsdl.types[key]
  72. self.failUnlessEqual(key, schema.getTargetNamespace())
  73. definition = self.wsdl.document.documentElement
  74. version = DOM.WSDLUriToVersion(definition.namespaceURI)
  75. nspname = DOM.GetWSDLUri(version)
  76. for node in DOM.getElements(definition, 'types', nspname):
  77. for snode in DOM.getElements(node, 'schema'):
  78. tns = DOM.findTargetNS(snode)
  79. schema = self.wsdl.types[tns]
  80. self.schemaAttributesDeclarations(schema, snode)
  81. self.schemaAttributeGroupDeclarations(schema, snode)
  82. self.schemaElementDeclarations(schema, snode)
  83. self.schemaTypeDefinitions(schema, snode)
  84. except:
  85. self.path = self.path + ": wsdl.types"
  86. raise
  87. if self.wsdl.extensions:
  88. print 'No check for WSDLTools(%s) Extensions:' %(self.wsdl.name)
  89. for ext in self.wsdl.extensions: print '\t', ext
  90. def schemaAttributesDeclarations(self, schema, node):
  91. self.checkXSDCollection('attribute', schema.attr_decl, node)
  92. def schemaAttributeGroupDeclarations(self, schema, node):
  93. self.checkXSDCollection('group', schema.attr_groups, node)
  94. def schemaElementDeclarations(self, schema, node):
  95. self.checkXSDCollection('element', schema.elements, node)
  96. def schemaTypeDefinitions(self, schema, node):
  97. self.checkXSDCollection('complexType', schema.types, node)
  98. self.checkXSDCollection('simpleType', schema.types, node)
  99. def makeTestSuite(section=None):
  100. global configLoader
  101. suite = unittest.TestSuite()
  102. configLoader = utils.MatchTestLoader(False, "config.py", "WSDLToolsTestCase")
  103. if not section:
  104. found = configLoader.setSection(sys.argv)
  105. if not found:
  106. configLoader.setSection("services_by_http")
  107. else:
  108. configLoader.setSection(section)
  109. configLoader.testMethodPrefix = "wsdlTest"
  110. suite.addTest(configLoader.loadTestsFromConfig(WSDLToolsTestCase))
  111. return suite
  112. def main():
  113. loader = utils.MatchTestLoader(False, None, "makeTestSuite")
  114. unittest.main(defaultTest="makeTestSuite", testLoader=loader)
  115. if __name__ == "__main__" : main()