Skip to content

Commit

Permalink
Added test for inlined element with simple type restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
realmfoo committed Sep 27, 2017
1 parent ce98f31 commit 1d06367
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 37 deletions.
106 changes: 69 additions & 37 deletions fixtures/test.wsdl
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://www.mnb.hu/webservices/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://www.mnb.hu/webservices/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">MNB curreny exchange rate webservice.</wsdl:documentation>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.mnb.hu/webservices/">
<s:element name="GetInfo">
<s:complexType />
</s:element>
<s:element name="GetInfoResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetInfoResult" type="s:string">
<s:annotation>
<s:documentation>this is a comment</s:documentation>
</s:annotation>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="GetInfoSoapIn">
<wsdl:part name="parameters" element="tns:GetInfo" />
</wsdl:message>
<wsdl:message name="GetInfoSoapOut">
<wsdl:part name="parameters" element="tns:GetInfoResponse" />
</wsdl:message>
<wsdl:service name="MNBArfolyamService">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">MNB curreny exchange rate webservice.</wsdl:documentation>
<wsdl:port name="MNBArfolyamServiceSoap" binding="tns:MNBArfolyamServiceSoap">
<soap:address location="http://www.mnb.hu/arfolyamok.asmx" />
</wsdl:port>
<wsdl:port name="MNBArfolyamServiceSoap12" binding="tns:MNBArfolyamServiceSoap12">
<soap12:address location="http://www.mnb.hu/arfolyamok.asmx" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.mnb.hu/webservices/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
targetNamespace="http://www.mnb.hu/webservices/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">MNB curreny exchange rate webservice.</wsdl:documentation>
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://www.mnb.hu/webservices/">
<s:element name="GetInfo">
<s:complexType>
<s:sequence>
<s:element name="Id">
<s:annotation>
<s:documentation>comment</s:documentation>
</s:annotation>
<s:simpleType>
<s:restriction base="s:string">
<s:minLength value="2"/>
</s:restriction>
</s:simpleType>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
<s:element name="GetInfoResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetInfoResult" type="s:string">
<s:annotation>
<s:documentation>this is a comment</s:documentation>
</s:annotation>
</s:element>
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="GetInfoSoapIn">
<wsdl:part name="parameters" element="tns:GetInfo" />
</wsdl:message>
<wsdl:message name="GetInfoSoapOut">
<wsdl:part name="parameters" element="tns:GetInfoResponse" />
</wsdl:message>
<wsdl:portType name="MNBArfolyamServiceType">
<wsdl:operation name="GetInfoSoap">
<wsdl:input message="tns:GetInfoSoapIn"/>
<wsdl:output message="tns:GetInfoSoapOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MNBArfolyamBinding" type="tns:MNBArfolyamServiceType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="GetInfoSoap">
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="MNBArfolyamService">
<wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">MNB curreny exchange rate webservice.</wsdl:documentation>
<wsdl:port name="MNBArfolyamServiceSoap" binding="tns:MNBArfolyamBinding">
<soap:address location="http://example.org/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
54 changes: 54 additions & 0 deletions gowsdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ package gowsdl

import (
"bytes"
"errors"
"go/format"
"go/parser"
"go/printer"
"go/token"
"path/filepath"
"regexp"
"strings"
Expand All @@ -31,6 +35,32 @@ func TestElementGenerationDoesntCommentOutStructProperty(t *testing.T) {
}
}

func TestComplexTypeWithInlineSimpleType(t *testing.T) {
g := GoWSDL{
file: "fixtures/test.wsdl",
pkg: "myservice",
makePublicFn: makePublic,
}

resp, err := g.Start()
if err != nil {
t.Fatal(err)
}
actual, err := getTypeDeclaration(resp, "GetInfo")
if err != nil {
t.Fatal(err)
}

expected := `type GetInfo struct {
XMLName xml.Name ` + "`" + `xml:"http://www.mnb.hu/webservices/ GetInfo"` + "`" + `
Id string ` + "`" + `xml:"Id,omitempty"` + "`" + `
}`
if actual != expected {
t.Error("got " + actual + " want " + expected)
}
}

func TestVboxGeneratesWithoutSyntaxErrors(t *testing.T) {
files, err := filepath.Glob("fixtures/*.wsdl")
if err != nil {
Expand Down Expand Up @@ -105,3 +135,27 @@ func TestEnumerationsGeneratedCorrectly(t *testing.T) {
enumStringTest(t, "vboxweb.wsdl", "SettingsVersionV1_14", "SettingsVersion", "v1_14")

}

func getTypeDeclaration(resp map[string][]byte, name string) (string, error) {
source, err := format.Source([]byte(string(resp["header"]) + string(resp["types"])))
if err != nil {
return "", err
}
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "myservice.go", string(source), parser.DeclarationErrors)
if err != nil {
return "", err
}
o := f.Scope.Lookup(name)
if o == nil {
return "", errors.New("type " + name + " is missing")
}
var buf bytes.Buffer
buf.WriteString(o.Kind.String())
buf.WriteString(" ")
err = printer.Fprint(&buf, fset, o.Decl)
if err != nil {
return "", err
}
return buf.String(), nil
}

0 comments on commit 1d06367

Please sign in to comment.