Skip to content

Commit

Permalink
Initial import for issue 28
Browse files Browse the repository at this point in the history
  • Loading branch information
indika-dev committed Aug 26, 2024
1 parent 889e41a commit 2f21553
Show file tree
Hide file tree
Showing 4 changed files with 238 additions and 34 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.idea/

target/

# files from jdtls
.settings/
.classpath
.project
81 changes: 47 additions & 34 deletions src/test/java/org/wso2/soaptorest/SOAPToRESTConverterTest.java
Original file line number Diff line number Diff line change
@@ -1,57 +1,70 @@
/*
* Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you 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
* WSO2 Inc. licenses this file to you 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.
* 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 org.wso2.soaptorest;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;
import org.wso2.soaptorest.exceptions.SOAPToRESTException;
import org.wso2.soaptorest.models.SOAPtoRESTConversionData;

import java.net.MalformedURLException;
import java.net.URL;
class SOAPToRESTConverterTest {

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Test
void testFileGetSOAPtoRESTConversionData() throws SOAPToRESTException {

class SOAPToRESTConverterTest {
SOAPtoRESTConversionData soaPtoRESTConversionData =
SOAPToRESTConverter.getSOAPtoRESTConversionData(
"src/test/resources" + "/calculator/calculator.wsdl", "Test API", "1.0.0");
assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString()));
assertEquals(soaPtoRESTConversionData.getAllSOAPRequestBodies().size(), 4);
assertEquals(soaPtoRESTConversionData.getSoapService(), "CalculatorService");
assertEquals(soaPtoRESTConversionData.getSoapPort(), "CalculatorPort");

}

@Test
void testURLGetSOAPtoRESTConversionData() throws MalformedURLException, SOAPToRESTException {

@Test
void testFileGetSOAPtoRESTConversionData() throws SOAPToRESTException {
URL url = new URL(
"https://raw.githubusercontent.com/wso2/soap-to-rest/main/src/test/resources/calculator-remote/calculator.wsdl");
SOAPtoRESTConversionData soaPtoRESTConversionData =
SOAPToRESTConverter.getSOAPtoRESTConversionData(url, "Test API", "1.0.0");
assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString()));
assertEquals(soaPtoRESTConversionData.getAllSOAPRequestBodies().size(), 4);
assertEquals(soaPtoRESTConversionData.getSoapService(), "CalculatorService");
assertEquals(soaPtoRESTConversionData.getSoapPort(), "CalculatorPort");

SOAPtoRESTConversionData soaPtoRESTConversionData = SOAPToRESTConverter.getSOAPtoRESTConversionData("src/test/resources" +
"/calculator/calculator.wsdl", "Test API", "1.0.0");
assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString()));
assertEquals(soaPtoRESTConversionData.getAllSOAPRequestBodies().size(), 4);
assertEquals(soaPtoRESTConversionData.getSoapService(), "CalculatorService");
assertEquals(soaPtoRESTConversionData.getSoapPort(), "CalculatorPort");
}

}
@Test
void testIssue28() throws MalformedURLException, SOAPToRESTException {

@Test
void testURLGetSOAPtoRESTConversionData() throws MalformedURLException, SOAPToRESTException {
URL url = new URL(
"https://raw.githubusercontent.com/wso2/soap-to-rest/main/src/test/resources/issue-28/failing.wsdl");
SOAPtoRESTConversionData soaPtoRESTConversionData =
SOAPToRESTConverter.getSOAPtoRESTConversionData(url, "Test API", "1.0.0");
assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString()));
assertEquals(soaPtoRESTConversionData.getAllSOAPRequestBodies().size(), 4);
assertEquals(soaPtoRESTConversionData.getSoapService(), "CalculatorService");
assertEquals(soaPtoRESTConversionData.getSoapPort(), "CalculatorPort");

URL url = new URL("https://raw.githubusercontent.com/wso2/soap-to-rest/main/src/test/resources/calculator-remote/calculator.wsdl");
SOAPtoRESTConversionData soaPtoRESTConversionData = SOAPToRESTConverter.getSOAPtoRESTConversionData(url, "Test API", "1.0.0");
assertTrue(StringUtils.isNotBlank(soaPtoRESTConversionData.getOASString()));
assertEquals(soaPtoRESTConversionData.getAllSOAPRequestBodies().size(), 4);
assertEquals(soaPtoRESTConversionData.getSoapService(), "CalculatorService");
assertEquals(soaPtoRESTConversionData.getSoapPort(), "CalculatorPort");
}

}
}

}
92 changes: 92 additions & 0 deletions src/test/resources/issue-28/failing.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="urn:ServerWsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="myServer"
targetNamespace="urn:ServerWsdl">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ServerWsdl">
<xsd:complexType name="getRequestType">
<xsd:sequence>
<xsd:element name="header" type="tns:standardheaderType" />
<xsd:element name="body" type="tns:getRequestBodyType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getResultType">
<xsd:sequence>
<xsd:element name="result" type="tns:resultType" maxOccurs="1" minOccurs="0" />
<xsd:element name="error" type="tns:errorType" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="standardheaderType">
<xsd:sequence>
<xsd:element name="applicationversionnr" type="xsd:string" maxOccurs="1" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getRequestBodyType">
<xsd:sequence>
<xsd:element name="transactioncode" type="xsd:string" maxOccurs="1" minOccurs="1" />
<xsd:element name="languageisocode" type="xsd:string" maxOccurs="1" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="disclosureinformationType">
<xsd:sequence>
<xsd:element name="companyname" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="street" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="countryisocode" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="city" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element name="postcode"
type="xsd:string" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="clientinformationType">
<xsd:sequence>
<xsd:element name="fieldname" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element name="fieldvalue" type="xsd:string" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="resultType">
<xsd:sequence>
<xsd:element name="transactioncode" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="errorType">
<xsd:sequence>
<xsd:element name="errorcode" type="xsd:string" />
<xsd:element name="errortext" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getRequest">
<wsdl:part name="getRequest" type="tns:getRequestType" />
</wsdl:message>
<wsdl:message name="getResponse">
<wsdl:part name="getResponse" type="tns:getResultType" />
</wsdl:message>
<wsdl:portType name="myServer">
<wsdl:operation name="get">
<wsdl:input message="tns:getRequest" />
<wsdl:output message="tns:getResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="myServerSOAP" type="tns:myServer">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="get">
<soap:operation soapAction="urn:ServerWsdl/get" />
<wsdl:input>
<soap:body namespace="urn:ServerWsdl" use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body namespace="urn:ServerWsdl" use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="myServer">
<wsdl:port binding="tns:myServerSOAP" name="myServerSOAP">
<soap:address
location="https://some.server.de/myServer.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
92 changes: 92 additions & 0 deletions target/test-classes/issue-28/failing.wsdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="urn:ServerWsdl" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="myServer"
targetNamespace="urn:ServerWsdl">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:ServerWsdl">
<xsd:complexType name="getRequestType">
<xsd:sequence>
<xsd:element name="header" type="tns:standardheaderType" />
<xsd:element name="body" type="tns:getRequestBodyType" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getResultType">
<xsd:sequence>
<xsd:element name="result" type="tns:resultType" maxOccurs="1" minOccurs="0" />
<xsd:element name="error" type="tns:errorType" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="standardheaderType">
<xsd:sequence>
<xsd:element name="applicationversionnr" type="xsd:string" maxOccurs="1" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="getRequestBodyType">
<xsd:sequence>
<xsd:element name="transactioncode" type="xsd:string" maxOccurs="1" minOccurs="1" />
<xsd:element name="languageisocode" type="xsd:string" maxOccurs="1" minOccurs="1" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="disclosureinformationType">
<xsd:sequence>
<xsd:element name="companyname" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="street" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="countryisocode" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element
name="city" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element name="postcode"
type="xsd:string" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="clientinformationType">
<xsd:sequence>
<xsd:element name="fieldname" type="xsd:string" maxOccurs="1" minOccurs="0" />
<xsd:element name="fieldvalue" type="xsd:string" maxOccurs="1" minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="resultType">
<xsd:sequence>
<xsd:element name="transactioncode" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="errorType">
<xsd:sequence>
<xsd:element name="errorcode" type="xsd:string" />
<xsd:element name="errortext" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="getRequest">
<wsdl:part name="getRequest" type="tns:getRequestType" />
</wsdl:message>
<wsdl:message name="getResponse">
<wsdl:part name="getResponse" type="tns:getResultType" />
</wsdl:message>
<wsdl:portType name="myServer">
<wsdl:operation name="get">
<wsdl:input message="tns:getRequest" />
<wsdl:output message="tns:getResponse" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="myServerSOAP" type="tns:myServer">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="get">
<soap:operation soapAction="urn:ServerWsdl/get" />
<wsdl:input>
<soap:body namespace="urn:ServerWsdl" use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body namespace="urn:ServerWsdl" use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="myServer">
<wsdl:port binding="tns:myServerSOAP" name="myServerSOAP">
<soap:address
location="https://some.server.de/myServer.php" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

0 comments on commit 2f21553

Please sign in to comment.