Skip to content

Commit

Permalink
test(soap): improves WSDL parser coverage for faults and HTTP bindings.
Browse files Browse the repository at this point in the history
  • Loading branch information
outofcoffee committed Oct 19, 2024
1 parent 6725f31 commit b29d737
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Wsdl2Parser(
expressionTemplate = "./wsdl:operation[@name='%s']",
name = operationName
)
return operation?.let { parseOperation(operationName, operation) }
return operation?.let { parseOperation(operationName, interfaceNode, operation) }
}

private fun getInterfaceNode(interfaceName: String): Element? {
Expand All @@ -163,13 +163,16 @@ class Wsdl2Parser(
)
}

private fun parseOperation(operationName: String, operation: Element): WsdlOperation {
private fun parseOperation(operationName: String, iface: Element, operation: Element): WsdlOperation {
val soapOperation = selectSingleNode(operation, "./soap:operation") ?: throw IllegalStateException(
"Unable to find soap:operation for operation $operationName"
)
val input = getMessage(operation, "./wsdl:input", required = true)
val output = getMessage(operation, "./wsdl:output", required = true)

// fall back to fault defined at interface level
val fault = getMessage(operation, "./wsdl:fault", required = false)
?: getMessage(iface, "./wsdl:fault", required = false)

return WsdlOperation(
name = operation.getAttributeValue("name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Wsdl1Soap11ParserTest {
}

@Test
fun getBinding() {
fun `get SOAP binding, getPetById operation`() {
val binding = parser.getBinding("SoapBinding")
assertNotNull("SoapBinding should not be null", binding)

Expand All @@ -102,7 +102,10 @@ class Wsdl1Soap11ParserTest {
operation!!
assertEquals("getPetById", operation.name)
assertEquals("getPetById", operation.soapAction)

// operation style defined at operation level in this service
assertEquals("document", operation.style)

assertEquals(
QName("urn:com:example:petstore", "getPetByIdRequest"),
(operation.inputRef as ElementOperationMessage).elementName,
Expand All @@ -111,11 +114,45 @@ class Wsdl1Soap11ParserTest {
QName("urn:com:example:petstore", "getPetByIdResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
fun `get HTTP binding, getPetByName operation`() {
val binding = parser.getBinding("HttpBinding")
assertNotNull("HttpBinding should not be null", binding)

binding!!
assertEquals("HttpBinding", binding.name)
assertEquals(BindingType.HTTP, binding.type)
assertEquals("tns:PetPortType", binding.interfaceRef)

assertEquals(2, binding.operations.size)
val operation = binding.operations.find { it.name == "getPetByName" }
assertNotNull("getPetByName operation should not be null", operation)

operation!!
assertEquals("getPetByName", operation.name)
assertEquals("getPetByName", operation.soapAction)

// operation style should fall back to binding style in WSDL 1.x
val petNameOp = binding.operations.find { it.name == "getPetByName" }
assertNotNull(petNameOp)
assertEquals("document", petNameOp?.style)
assertEquals("document", operation.style)

assertEquals(
QName("urn:com:example:petstore", "getPetByNameRequest"),
(operation.inputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetByNameResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Wsdl1Soap12ParserTest {
}

@Test
fun getBinding() {
fun `get SOAP binding, getPetById operation`() {
val binding = parser.getBinding("SoapBinding")
assertNotNull("SoapBinding should not be null", binding)

Expand All @@ -102,7 +102,10 @@ class Wsdl1Soap12ParserTest {
operation!!
assertEquals("getPetById", operation.name)
assertEquals("getPetById", operation.soapAction)

// operation style defined at operation level in this service
assertEquals("document", operation.style)

assertEquals(
QName("urn:com:example:petstore","getPetByIdRequest"),
(operation.inputRef as ElementOperationMessage).elementName,
Expand All @@ -111,11 +114,45 @@ class Wsdl1Soap12ParserTest {
QName("urn:com:example:petstore","getPetByIdResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
fun `get HTTP binding, getPetByName operation`() {
val binding = parser.getBinding("HttpBinding")
assertNotNull("HttpBinding should not be null", binding)

binding!!
assertEquals("HttpBinding", binding.name)
assertEquals(BindingType.HTTP, binding.type)
assertEquals("tns:PetPortType", binding.interfaceRef)

assertEquals(2, binding.operations.size)
val operation = binding.operations.find { it.name == "getPetByName" }
assertNotNull("getPetByName operation should not be null", operation)

operation!!
assertEquals("getPetByName", operation.name)
assertEquals("getPetByName", operation.soapAction)

// operation style should fall back to binding style in WSDL 1.x
val petNameOp = binding.operations.find { it.name == "getPetByName" }
assertNotNull(petNameOp)
assertEquals("document", petNameOp?.style)
assertEquals("document", operation.style)

assertEquals(
QName("urn:com:example:petstore","getPetByNameRequest"),
(operation.inputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore","getPetByNameResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Wsdl2Soap12ParserTest {
}

@Test
fun getBinding() {
fun `get SOAP binding, getPetById operation`() {
val binding = parser.getBinding("SoapBinding")
assertNotNull("SoapBinding should not be null", binding)

Expand All @@ -111,6 +111,46 @@ class Wsdl2Soap12ParserTest {
QName("urn:com:example:petstore", "getPetByIdResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)

// fault defined at interface level
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
fun `get HTTP binding, getPetByName operation`() {
val binding = parser.getBinding("HttpBinding")
assertNotNull("HttpBinding should not be null", binding)

binding!!
assertEquals("HttpBinding", binding.name)
assertEquals(BindingType.HTTP, binding.type)
assertEquals("tns:PetInterface", binding.interfaceRef)

assertEquals(2, binding.operations.size)
val operation = binding.operations.find { it.name == "getPetByName" }
assertNotNull("getPetByName operation should not be null", operation)

operation!!
assertEquals("getPetByName", operation.name)
assertEquals("getPetByName", operation.soapAction)
assertEquals("document", operation.style)
assertEquals(
QName("urn:com:example:petstore", "getPetByNameRequest"),
(operation.inputRef as ElementOperationMessage).elementName,
)
assertEquals(
QName("urn:com:example:petstore", "getPetByNameResponse"),
(operation.outputRef as ElementOperationMessage).elementName,
)

// fault defined in operation
assertEquals(
QName("urn:com:example:petstore", "getPetFault"),
(operation.faultRef as ElementOperationMessage?)?.elementName,
)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
</xs:all>
</xs:complexType>

<xs:complexType name="fault">
<xs:all>
<xs:element name="code" type="xs:int" />
<xs:element name="description" type="xs:string" />
</xs:all>
</xs:complexType>

<xs:complexType name="getPetByIdRequest">
<xs:all>
<xs:element name="id" type="xs:int"/>
Expand All @@ -27,5 +34,5 @@
<xs:element name="getPetByNameRequest" type="tns:getPetByNameRequest"/>
<xs:element name="getPetByNameResponse" type="tns:petType"/>

<xs:element name="fault" type="xs:string"/>
<xs:element name="getPetFault" type="tns:fault"/>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,21 @@
<message name="getPetByNameResponse">
<part element="tns:getPetByNameResponse" name="parameters"/>
</message>
<message name="getPetFault">
<part element="tns:getPetFault" name="parameters"/>
</message>

<!-- Abstract port types -->
<portType name="PetPortType">
<operation name="getPetById">
<input message="tns:getPetByIdRequest" name="getPetByIdRequest"/>
<output message="tns:getPetByIdResponse" name="getPetByIdResponse"/>
<fault message="tns:getPetFault" name="getPetFault" />
</operation>
<operation name="getPetByName">
<input message="tns:getPetByNameRequest" name="getPetByNameRequest"/>
<output message="tns:getPetByNameResponse" name="getPetByNameResponse"/>
<fault message="tns:getPetFault" name="getPetFault" />
</operation>
</portType>

Expand All @@ -130,6 +135,9 @@
<output name="getPetByIdResponse">
<soap:body use="literal"/>
</output>
<fault name="getPetFault">
<soap:body use="literal"/>
</fault>
</operation>
<operation name="getPetByName">
<soap:operation soapAction="getPetByName" style="document"/>
Expand All @@ -139,6 +147,9 @@
<output name="getPetByNameResponse">
<soap:body use="literal"/>
</output>
<fault name="getPetFault">
<soap:body use="literal"/>
</fault>
</operation>
</binding>

Expand All @@ -154,6 +165,9 @@
<output name="getPetByIdResponse">
<soap:body use="literal"/>
</output>
<fault name="getPetFault">
<soap:body use="literal"/>
</fault>
</operation>

<operation name="getPetByName">
Expand All @@ -165,6 +179,9 @@
<output name="getPetByNameResponse">
<soap:body use="literal"/>
</output>
<fault name="getPetFault">
<soap:body use="literal"/>
</fault>
</operation>
</binding>

Expand Down
9 changes: 8 additions & 1 deletion mock/soap/src/test/resources/wsdl1-soap12/schema.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
</xs:all>
</xs:complexType>

<xs:complexType name="fault">
<xs:all>
<xs:element name="code" type="xs:int" />
<xs:element name="description" type="xs:string" />
</xs:all>
</xs:complexType>

<xs:complexType name="getPetByIdRequest">
<xs:all>
<xs:element name="id" type="xs:int"/>
Expand All @@ -27,5 +34,5 @@
<xs:element name="getPetByNameRequest" type="tns:getPetByNameRequest"/>
<xs:element name="getPetByNameResponse" type="tns:petType"/>

<xs:element name="fault" type="xs:string"/>
<xs:element name="getPetFault" type="tns:fault"/>
</xs:schema>
17 changes: 17 additions & 0 deletions mock/soap/src/test/resources/wsdl1-soap12/service.wsdl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,21 @@
<message name="getPetByNameResponse">
<part element="tns:getPetByNameResponse" name="parameters"/>
</message>
<message name="getPetFault">
<part element="tns:getPetFault" name="parameters"/>
</message>

<!-- Abstract port types -->
<portType name="PetPortType">
<operation name="getPetById">
<input message="tns:getPetByIdRequest" name="getPetByIdRequest"/>
<output message="tns:getPetByIdResponse" name="getPetByIdResponse"/>
<fault message="tns:getPetFault" name="getPetFault" />
</operation>
<operation name="getPetByName">
<input message="tns:getPetByNameRequest" name="getPetByNameRequest"/>
<output message="tns:getPetByNameResponse" name="getPetByNameResponse"/>
<fault message="tns:getPetFault" name="getPetFault" />
</operation>
</portType>

Expand All @@ -129,6 +134,9 @@
<output name="getPetByIdResponse">
<soap12:body use="literal"/>
</output>
<fault name="getPetFault">
<soap12:body use="literal"/>
</fault>
</operation>
<operation name="getPetByName">
<soap12:operation soapAction="getPetByName" style="document"/>
Expand All @@ -138,6 +146,9 @@
<output name="getPetByNameResponse">
<soap12:body use="literal"/>
</output>
<fault name="getPetFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>

Expand All @@ -153,6 +164,9 @@
<output name="getPetByIdResponse">
<soap12:body use="literal"/>
</output>
<fault name="getPetFault">
<soap12:body use="literal"/>
</fault>
</operation>

<operation name="getPetByName">
Expand All @@ -164,6 +178,9 @@
<output name="getPetByNameResponse">
<soap12:body use="literal"/>
</output>
<fault name="getPetFault">
<soap12:body use="literal"/>
</fault>
</operation>
</binding>

Expand Down
Loading

0 comments on commit b29d737

Please sign in to comment.