|
Groovy example source code file (XmlSlurperTest.groovy)
The Groovy XmlSlurperTest.groovy source code
/*
* Copyright 2003-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package groovy.util
import groovy.xml.TraversalTestSupport
import groovy.xml.GpathSyntaxTestSupport
import groovy.xml.MixedMarkupTestSupport
import groovy.xml.StreamingMarkupBuilder
class XmlSlurperTest extends GroovyTestCase {
def getRoot = { xml -> new XmlSlurper().parseText(xml) }
void testWsdl() {
def wsdl = '''
<definitions name="AgencyManagementService"
xmlns:ns1="http://www.example.org/NS1"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns="http://schemas.xmlsoap.org/wsdl/">
<message name="SomeRequest">
<part name="parameters" element="ns1:SomeReq" />
</message>
<message name="SomeResponse">
<part name="result" element="ns1:SomeRsp" />
</message>
</definitions>
'''
def xml = new XmlSlurper().parseText(wsdl)
assert xml.message.part.@element.findAll {it =~ /.Req$/}.size() == 1
assert xml.message.part.findAll { true }.size() == 2
assert xml.message.part.find { it.name() == 'part' }.name() == 'part'
assert xml.message.findAll { true }.size() == 2
assert xml.message.part.lookupNamespace("ns1") == "http://www.example.org/NS1"
assert xml.message.part.lookupNamespace("") == "http://schemas.xmlsoap.org/wsdl/"
assert xml.message.part.lookupNamespace("undefinedPrefix") == null
xml.message.findAll { true }.each { assert it.name() == "message"}
}
void testElement() {
GpathSyntaxTestSupport.checkElement(getRoot)
GpathSyntaxTestSupport.checkFindElement(getRoot)
GpathSyntaxTestSupport.checkElementTypes(getRoot)
GpathSyntaxTestSupport.checkElementClosureInteraction(getRoot)
GpathSyntaxTestSupport.checkElementTruth(getRoot)
}
void testAttribute() {
GpathSyntaxTestSupport.checkAttribute(getRoot)
GpathSyntaxTestSupport.checkAttributes(getRoot)
GpathSyntaxTestSupport.checkAttributeTruth(getRoot)
}
void testNavigation() {
GpathSyntaxTestSupport.checkChildren(getRoot)
GpathSyntaxTestSupport.checkParent(getRoot)
GpathSyntaxTestSupport.checkNestedSizeExpressions(getRoot)
}
void testTraversal() {
TraversalTestSupport.checkDepthFirst(getRoot)
TraversalTestSupport.checkBreadthFirst(getRoot)
}
void testIndices() {
GpathSyntaxTestSupport.checkNegativeIndices(getRoot)
GpathSyntaxTestSupport.checkRangeIndex(getRoot)
}
void testReplacementsAndAdditions() {
GpathSyntaxTestSupport.checkReplaceNode(getRoot)
GpathSyntaxTestSupport.checkPlus(getRoot)
}
void testMixedMarkup() {
MixedMarkupTestSupport.checkMixedMarkup(getRoot)
}
void testReplace() {
def input = "<doc>
Other Groovy examples (source code examples)Here is a short list of links related to this Groovy XmlSlurperTest.groovy source code file: |
Other websites by Alvin Alexander:
Life/living in Alaska (OneMansAlaska.com)
How I Sold My Business (HowISoldMyBusiness.com)
Copyright 1998-2011 Alvin Alexander, devdaily.com
All Rights Reserved.