3 ############################################################################
4 # Joshua R. Boverhof, David W. Robertson, LBNL
5 # See LBNLCopyright for copyright notice!
6 ###########################################################################
11 from wstools.Utility import DOM
12 from wstools.WSDLTools import WSDLReader
13 from wstools.TimeoutSocket import TimeoutError
15 from wstools import tests
16 cwd = os.path.dirname(tests.__file__)
18 class WSDLToolsTestCase(unittest.TestCase):
20 def __init__(self, methodName='runTest'):
21 unittest.TestCase.__init__(self, methodName)
24 self.path = nameGenerator.next()
29 teststr = unittest.TestCase.__str__(self)
30 if hasattr(self, "path"):
31 return "%s: %s" % (teststr, self.path )
33 return "%s" % (teststr)
35 def checkWSDLCollection(self, tag_name, component, key='name'):
38 definition = self.wsdl.document.documentElement
39 version = DOM.WSDLUriToVersion(definition.namespaceURI)
40 nspname = DOM.GetWSDLUri(version)
41 for node in DOM.getElements(definition, tag_name, nspname):
42 name = DOM.getAttr(node, key)
43 comp = component[name]
44 self.failUnlessEqual(eval('comp.%s' %key), name)
46 def checkXSDCollection(self, tag_name, component, node, key='name'):
47 for cnode in DOM.getElements(node, tag_name):
48 name = DOM.getAttr(cnode, key)
53 if self.path[:7] == 'http://':
54 self.wsdl = WSDLReader().loadFromURL(self.path)
56 self.wsdl = WSDLReader().loadFromFile(self.path)
59 print "connection timed out"
63 self.path = self.path + ": load failed, unable to start"
67 self.checkWSDLCollection('service', self.wsdl.services)
69 self.path = self.path + ": wsdl.services"
73 self.checkWSDLCollection('message', self.wsdl.messages)
75 self.path = self.path + ": wsdl.messages"
79 self.checkWSDLCollection('portType', self.wsdl.portTypes)
81 self.path = self.path + ": wsdl.portTypes"
85 self.checkWSDLCollection('binding', self.wsdl.bindings)
87 self.path = self.path + ": wsdl.bindings"
91 self.checkWSDLCollection('import', self.wsdl.imports, key='namespace')
93 self.path = self.path + ": wsdl.imports"
97 for key in self.wsdl.types.keys():
98 schema = self.wsdl.types[key]
99 self.failUnlessEqual(key, schema.getTargetNamespace())
101 definition = self.wsdl.document.documentElement
102 version = DOM.WSDLUriToVersion(definition.namespaceURI)
103 nspname = DOM.GetWSDLUri(version)
104 for node in DOM.getElements(definition, 'types', nspname):
105 for snode in DOM.getElements(node, 'schema'):
106 tns = DOM.findTargetNS(snode)
107 schema = self.wsdl.types[tns]
108 self.schemaAttributesDeclarations(schema, snode)
109 self.schemaAttributeGroupDeclarations(schema, snode)
110 self.schemaElementDeclarations(schema, snode)
111 self.schemaTypeDefinitions(schema, snode)
113 self.path = self.path + ": wsdl.types"
116 if self.wsdl.extensions:
117 print 'No check for WSDLTools(%s) Extensions:' %(self.wsdl.name)
118 for ext in self.wsdl.extensions: print '\t', ext
120 def schemaAttributesDeclarations(self, schema, node):
121 self.checkXSDCollection('attribute', schema.attr_decl, node)
123 def schemaAttributeGroupDeclarations(self, schema, node):
124 self.checkXSDCollection('group', schema.attr_groups, node)
126 def schemaElementDeclarations(self, schema, node):
127 self.checkXSDCollection('element', schema.elements, node)
129 def schemaTypeDefinitions(self, schema, node):
130 self.checkXSDCollection('complexType', schema.types, node)
131 self.checkXSDCollection('simpleType', schema.types, node)
134 def setUpOptions(section):
135 cp = ConfigParser.ConfigParser()
136 cp.read(cwd+'/config.txt')
137 if not cp.sections():
138 print 'fatal error: configuration file config.txt not present'
140 if not cp.has_section(section):
141 print '%s section not present in configuration file, exiting' % section
143 return cp, len(cp.options(section))
145 def getOption(cp, section):
146 for name, value in cp.items(section):
149 def makeTestSuite(section='services_by_file'):
152 cp, numTests = setUpOptions(section)
153 nameGenerator = getOption(cp, section)
154 suite = unittest.TestSuite()
155 for i in range(0, numTests):
156 suite.addTest(unittest.makeSuite(WSDLToolsTestCase, 'test_'))
161 unittest.main(defaultTest="makeTestSuite")
164 if __name__ == "__main__" : main()