From a50909b228cd6ff98005625d1dcbec5990b4a88f Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Sun, 14 Feb 2021 19:27:43 +0000 Subject: [PATCH 1/4] BAEL-4362 - Generate WSDL Stubs with Maven Initial version of the codebase --- maven-modules/maven-plugins/jaxws/pom.xml | 39 +++++ .../ws/client/CountryNotFoundException.java | 8 ++ .../soap/ws/client/CountryServiceClient.java | 32 +++++ .../soap/ws/client/generated/Country.java | 135 ++++++++++++++++++ .../ws/client/generated/CountryService.java | 40 ++++++ .../generated/CountryServiceImplService.java | 94 ++++++++++++ .../soap/ws/client/generated/Currency.java | 40 ++++++ .../ws/client/generated/ObjectFactory.java | 40 ++++++ .../ws/client/generated/package-info.java | 2 + .../jaxws/src/main/resources/country.wsdl | 38 +++++ .../ws/client/CountryServiceClientTest.java | 76 ++++++++++ maven-modules/maven-plugins/pom.xml | 1 + 12 files changed, 545 insertions(+) create mode 100644 maven-modules/maven-plugins/jaxws/pom.xml create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryNotFoundException.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl create mode 100644 maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java diff --git a/maven-modules/maven-plugins/jaxws/pom.xml b/maven-modules/maven-plugins/jaxws/pom.xml new file mode 100644 index 0000000000..8100b56bba --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/pom.xml @@ -0,0 +1,39 @@ + + + + maven-plugins + com.baeldung + 0.0.1-SNAPSHOT + + 4.0.0 + + jaxws + + + + org.codehaus.mojo + jaxws-maven-plugin + 2.6 + + + + wsimport + + + + + ${project.basedir}/src/main/resources/ + + + + true + com.baeldung.soap.ws.client.generated + src/main/java + + + + + + \ No newline at end of file diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryNotFoundException.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryNotFoundException.java new file mode 100644 index 0000000000..c68d65abb1 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryNotFoundException.java @@ -0,0 +1,8 @@ +package com.baeldung.soap.ws.client; + +public class CountryNotFoundException extends RuntimeException { + + public CountryNotFoundException() { + super("Country not found!"); + } +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java new file mode 100644 index 0000000000..11bc91f3af --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java @@ -0,0 +1,32 @@ +package com.baeldung.soap.ws.client; + +import com.baeldung.soap.ws.client.generated.Country; +import com.baeldung.soap.ws.client.generated.CountryService; +import com.baeldung.soap.ws.client.generated.Currency; + +import java.util.Optional; + +public class CountryServiceClient { + + private CountryService countryService; + + public CountryServiceClient(CountryService countryService) { + this.countryService = countryService; + } + public String getCapitalByCountryName(String countryName) { + return Optional.of(countryService.findByName(countryName)) + .map(Country::getCapital).orElseThrow(CountryNotFoundException::new); + } + + public int getPopulationByCountryName(String countryName) { + return Optional.of(countryService.findByName(countryName)) + .map(Country::getPopulation).orElseThrow(CountryNotFoundException::new); + } + + public Currency getCurrencyByCountryName(String countryName) { + return Optional.of(countryService.findByName(countryName)) + .map(Country::getCurrency).orElseThrow(CountryNotFoundException::new); + } + + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java new file mode 100644 index 0000000000..950d588661 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java @@ -0,0 +1,135 @@ + +package com.baeldung.soap.ws.client.generated; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlSchemaType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for country complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="country">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="capital" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="currency" type="{http://server.ws.soap.baeldung.com/}currency" minOccurs="0"/>
+ *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="population" type="{http://www.w3.org/2001/XMLSchema}int"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "country", propOrder = { + "capital", + "currency", + "name", + "population" +}) +public class Country { + + protected String capital; + @XmlSchemaType(name = "string") + protected Currency currency; + protected String name; + protected int population; + + /** + * Gets the value of the capital property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getCapital() { + return capital; + } + + /** + * Sets the value of the capital property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setCapital(String value) { + this.capital = value; + } + + /** + * Gets the value of the currency property. + * + * @return + * possible object is + * {@link Currency } + * + */ + public Currency getCurrency() { + return currency; + } + + /** + * Sets the value of the currency property. + * + * @param value + * allowed object is + * {@link Currency } + * + */ + public void setCurrency(Currency value) { + this.currency = value; + } + + /** + * Gets the value of the name property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getName() { + return name; + } + + /** + * Sets the value of the name property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setName(String value) { + this.name = value; + } + + /** + * Gets the value of the population property. + * + */ + public int getPopulation() { + return population; + } + + /** + * Sets the value of the population property. + * + */ + public void setPopulation(int value) { + this.population = value; + } + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java new file mode 100644 index 0000000000..807d152cf1 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java @@ -0,0 +1,40 @@ + +package com.baeldung.soap.ws.client.generated; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.jws.soap.SOAPBinding; +import javax.xml.bind.annotation.XmlSeeAlso; +import javax.xml.ws.Action; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.3.2 + * Generated source version: 2.2 + * + */ +@WebService(name = "CountryService", targetNamespace = "http://server.ws.soap.baeldung.com/") +@SOAPBinding(style = SOAPBinding.Style.RPC) +@XmlSeeAlso({ + ObjectFactory.class +}) +public interface CountryService { + + + /** + * + * @param arg0 + * @return + * returns com.baeldung.soap.ws.client.generated.Country + */ + @WebMethod + @WebResult(partName = "return") + @Action(input = "http://server.ws.soap.baeldung.com/CountryService/findByNameRequest", output = "http://server.ws.soap.baeldung.com/CountryService/findByNameResponse") + public Country findByName( + @WebParam(name = "arg0", partName = "arg0") + String arg0); + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java new file mode 100644 index 0000000000..e741934375 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java @@ -0,0 +1,94 @@ + +package com.baeldung.soap.ws.client.generated; + +import java.net.MalformedURLException; +import java.net.URL; +import javax.xml.namespace.QName; +import javax.xml.ws.Service; +import javax.xml.ws.WebEndpoint; +import javax.xml.ws.WebServiceClient; +import javax.xml.ws.WebServiceException; +import javax.xml.ws.WebServiceFeature; + + +/** + * This class was generated by the JAX-WS RI. + * JAX-WS RI 2.3.2 + * Generated source version: 2.2 + * + */ +@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl") +public class CountryServiceImplService + extends Service +{ + + private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION; + private final static WebServiceException COUNTRYSERVICEIMPLSERVICE_EXCEPTION; + private final static QName COUNTRYSERVICEIMPLSERVICE_QNAME = new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplService"); + + static { + URL url = null; + WebServiceException e = null; + try { + url = new URL("file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl"); + } catch (MalformedURLException ex) { + e = new WebServiceException(ex); + } + COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION = url; + COUNTRYSERVICEIMPLSERVICE_EXCEPTION = e; + } + + public CountryServiceImplService() { + super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME); + } + + public CountryServiceImplService(WebServiceFeature... features) { + super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME, features); + } + + public CountryServiceImplService(URL wsdlLocation) { + super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME); + } + + public CountryServiceImplService(URL wsdlLocation, WebServiceFeature... features) { + super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME, features); + } + + public CountryServiceImplService(URL wsdlLocation, QName serviceName) { + super(wsdlLocation, serviceName); + } + + public CountryServiceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { + super(wsdlLocation, serviceName, features); + } + + /** + * + * @return + * returns CountryService + */ + @WebEndpoint(name = "CountryServiceImplPort") + public CountryService getCountryServiceImplPort() { + return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class); + } + + /** + * + * @param features + * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the features parameter will have their default values. + * @return + * returns CountryService + */ + @WebEndpoint(name = "CountryServiceImplPort") + public CountryService getCountryServiceImplPort(WebServiceFeature... features) { + return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class, features); + } + + private static URL __getWsdlLocation() { + if (COUNTRYSERVICEIMPLSERVICE_EXCEPTION!= null) { + throw COUNTRYSERVICEIMPLSERVICE_EXCEPTION; + } + return COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION; + } + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java new file mode 100644 index 0000000000..c010f5533c --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java @@ -0,0 +1,40 @@ + +package com.baeldung.soap.ws.client.generated; + +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for currency. + * + *

The following schema fragment specifies the expected content contained within this class. + *

+ *

+ * <simpleType name="currency">
+ *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
+ *     <enumeration value="EUR"/>
+ *     <enumeration value="INR"/>
+ *     <enumeration value="USD"/>
+ *   </restriction>
+ * </simpleType>
+ * 
+ * + */ +@XmlType(name = "currency") +@XmlEnum +public enum Currency { + + EUR, + INR, + USD; + + public String value() { + return name(); + } + + public static Currency fromValue(String v) { + return valueOf(v); + } + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java new file mode 100644 index 0000000000..9ed85fe2b9 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java @@ -0,0 +1,40 @@ + +package com.baeldung.soap.ws.client.generated; + +import javax.xml.bind.annotation.XmlRegistry; + + +/** + * This object contains factory methods for each + * Java content interface and Java element interface + * generated in the com.baeldung.soap.ws.client.generated package. + *

An ObjectFactory allows you to programatically + * construct new instances of the Java representation + * for XML content. The Java representation of XML + * content can consist of schema derived interfaces + * and classes representing the binding of schema + * type definitions, element declarations and model + * groups. Factory methods for each of these are + * provided in this class. + * + */ +@XmlRegistry +public class ObjectFactory { + + + /** + * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.soap.ws.client.generated + * + */ + public ObjectFactory() { + } + + /** + * Create an instance of {@link Country } + * + */ + public Country createCountry() { + return new Country(); + } + +} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java new file mode 100644 index 0000000000..dfc556859f --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java @@ -0,0 +1,2 @@ +@javax.xml.bind.annotation.XmlSchema(namespace = "http://server.ws.soap.baeldung.com/") +package com.baeldung.soap.ws.client.generated; diff --git a/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl b/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl new file mode 100644 index 0000000000..4720cc4cd2 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java new file mode 100644 index 0000000000..8a09f1308c --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java @@ -0,0 +1,76 @@ +package com.baeldung.soap.ws.client; + +import com.baeldung.soap.ws.client.generated.Country; +import com.baeldung.soap.ws.client.generated.CountryService; +import com.baeldung.soap.ws.client.generated.Currency; +import org.junit.jupiter.api.*; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.*; + +class CountryServiceClientTest { + + CountryServiceClient countryServiceClient; + CountryService countryService; + + @BeforeEach + void setUp() { + countryService = mock(CountryService.class); + countryServiceClient = new CountryServiceClient(countryService); + } + + @DisplayName("Get capital by country name when country not found") + @Test + void getCapitalByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); + Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getCapitalByCountryName(any())); + } + + @DisplayName("Get capital by country name when country is India then should return capital") + @Test + void getCapitalByCountryName_WhenCountryEqualsIndia_ThenShouldReturnCapital() { + Country country = mock(Country.class); + + doReturn("New Delhi").when(country).getCapital(); + doReturn(country).when(countryService).findByName("India"); + + Assertions.assertEquals("New Delhi", countryServiceClient.getCapitalByCountryName("India")); + } + + @DisplayName("Get population by country name when country not found") + @Test + void getPopulationByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); + Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getPopulationByCountryName(any())); + } + + @DisplayName("Get population by country name when country is India then should return population") + @Test + void getPopulationByCountryName_WhenCountryEqualsIndia_ThenShouldReturnPopulation() { + Country country = mock(Country.class); + + doReturn(1000000).when(country).getPopulation(); + doReturn(country).when(countryService).findByName("India"); + + Assertions.assertEquals(1000000, countryServiceClient.getPopulationByCountryName("India")); + } + + @DisplayName("Get currency by country name when country not found") + @Test + void getCurrencyByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); + Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getCurrencyByCountryName(any())); + } + + @DisplayName("Get currency by country name when country is India then should return currency") + @Test + void getCurrencyByCountryName_WhenCountryEqualsIndia_ThenShouldReturnCurrency() { + Country country = mock(Country.class); + + doReturn(Currency.INR).when(country).getCurrency(); + doReturn(country).when(countryService).findByName("India"); + + Assertions.assertEquals(Currency.INR, countryServiceClient.getCurrencyByCountryName("India")); + } + +} \ No newline at end of file diff --git a/maven-modules/maven-plugins/pom.xml b/maven-modules/maven-plugins/pom.xml index 9f28871ec0..20bdb4b45a 100644 --- a/maven-modules/maven-plugins/pom.xml +++ b/maven-modules/maven-plugins/pom.xml @@ -17,6 +17,7 @@ custom-rule maven-enforcer + jaxws From 7c4fd01620a2a109bd9db254e18840080006fd82 Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Sat, 27 Feb 2021 17:19:33 +0000 Subject: [PATCH 2/4] BAEL-4362 - Generate WSDL Stubs with Maven Initial version of the codebase --- maven-modules/maven-plugins/jaxws/pom.xml | 18 ++- .../soap/ws/client/CountryServiceClient.java | 4 - .../soap/ws/client/generated/Country.java | 135 ------------------ .../ws/client/generated/CountryService.java | 40 ------ .../generated/CountryServiceImplService.java | 94 ------------ .../soap/ws/client/generated/Currency.java | 40 ------ .../ws/client/generated/ObjectFactory.java | 40 ------ .../ws/client/generated/package-info.java | 2 - .../jaxws/src/main/resources/country.wsdl | 2 +- .../jaxws/src/main/resources/country.xsd | 21 +++ ...java => CountryServiceClientUnitTest.java} | 5 +- 11 files changed, 35 insertions(+), 366 deletions(-) delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java delete mode 100644 maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java create mode 100644 maven-modules/maven-plugins/jaxws/src/main/resources/country.xsd rename maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/{CountryServiceClientTest.java => CountryServiceClientUnitTest.java} (93%) diff --git a/maven-modules/maven-plugins/jaxws/pom.xml b/maven-modules/maven-plugins/jaxws/pom.xml index 8100b56bba..161c1dc731 100644 --- a/maven-modules/maven-plugins/jaxws/pom.xml +++ b/maven-modules/maven-plugins/jaxws/pom.xml @@ -25,12 +25,18 @@ ${project.basedir}/src/main/resources/ - - - - true - com.baeldung.soap.ws.client.generated - src/main/java + com.baeldung.soap.ws.client + + ${project.build.directory}/generated-sources/ + + + + + maven-verifier-plugin + ${maven.verifier.version} + + ../input-resources/verifications.xml + false diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java index 11bc91f3af..d179a50396 100644 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java @@ -1,9 +1,5 @@ package com.baeldung.soap.ws.client; -import com.baeldung.soap.ws.client.generated.Country; -import com.baeldung.soap.ws.client.generated.CountryService; -import com.baeldung.soap.ws.client.generated.Currency; - import java.util.Optional; public class CountryServiceClient { diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java deleted file mode 100644 index 950d588661..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Country.java +++ /dev/null @@ -1,135 +0,0 @@ - -package com.baeldung.soap.ws.client.generated; - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlSchemaType; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for country complex type. - * - *

The following schema fragment specifies the expected content contained within this class. - * - *

- * <complexType name="country">
- *   <complexContent>
- *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
- *       <sequence>
- *         <element name="capital" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         <element name="currency" type="{http://server.ws.soap.baeldung.com/}currency" minOccurs="0"/>
- *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
- *         <element name="population" type="{http://www.w3.org/2001/XMLSchema}int"/>
- *       </sequence>
- *     </restriction>
- *   </complexContent>
- * </complexType>
- * 
- * - * - */ -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "country", propOrder = { - "capital", - "currency", - "name", - "population" -}) -public class Country { - - protected String capital; - @XmlSchemaType(name = "string") - protected Currency currency; - protected String name; - protected int population; - - /** - * Gets the value of the capital property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getCapital() { - return capital; - } - - /** - * Sets the value of the capital property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setCapital(String value) { - this.capital = value; - } - - /** - * Gets the value of the currency property. - * - * @return - * possible object is - * {@link Currency } - * - */ - public Currency getCurrency() { - return currency; - } - - /** - * Sets the value of the currency property. - * - * @param value - * allowed object is - * {@link Currency } - * - */ - public void setCurrency(Currency value) { - this.currency = value; - } - - /** - * Gets the value of the name property. - * - * @return - * possible object is - * {@link String } - * - */ - public String getName() { - return name; - } - - /** - * Sets the value of the name property. - * - * @param value - * allowed object is - * {@link String } - * - */ - public void setName(String value) { - this.name = value; - } - - /** - * Gets the value of the population property. - * - */ - public int getPopulation() { - return population; - } - - /** - * Sets the value of the population property. - * - */ - public void setPopulation(int value) { - this.population = value; - } - -} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java deleted file mode 100644 index 807d152cf1..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryService.java +++ /dev/null @@ -1,40 +0,0 @@ - -package com.baeldung.soap.ws.client.generated; - -import javax.jws.WebMethod; -import javax.jws.WebParam; -import javax.jws.WebResult; -import javax.jws.WebService; -import javax.jws.soap.SOAPBinding; -import javax.xml.bind.annotation.XmlSeeAlso; -import javax.xml.ws.Action; - - -/** - * This class was generated by the JAX-WS RI. - * JAX-WS RI 2.3.2 - * Generated source version: 2.2 - * - */ -@WebService(name = "CountryService", targetNamespace = "http://server.ws.soap.baeldung.com/") -@SOAPBinding(style = SOAPBinding.Style.RPC) -@XmlSeeAlso({ - ObjectFactory.class -}) -public interface CountryService { - - - /** - * - * @param arg0 - * @return - * returns com.baeldung.soap.ws.client.generated.Country - */ - @WebMethod - @WebResult(partName = "return") - @Action(input = "http://server.ws.soap.baeldung.com/CountryService/findByNameRequest", output = "http://server.ws.soap.baeldung.com/CountryService/findByNameResponse") - public Country findByName( - @WebParam(name = "arg0", partName = "arg0") - String arg0); - -} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java deleted file mode 100644 index e741934375..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/CountryServiceImplService.java +++ /dev/null @@ -1,94 +0,0 @@ - -package com.baeldung.soap.ws.client.generated; - -import java.net.MalformedURLException; -import java.net.URL; -import javax.xml.namespace.QName; -import javax.xml.ws.Service; -import javax.xml.ws.WebEndpoint; -import javax.xml.ws.WebServiceClient; -import javax.xml.ws.WebServiceException; -import javax.xml.ws.WebServiceFeature; - - -/** - * This class was generated by the JAX-WS RI. - * JAX-WS RI 2.3.2 - * Generated source version: 2.2 - * - */ -@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl") -public class CountryServiceImplService - extends Service -{ - - private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION; - private final static WebServiceException COUNTRYSERVICEIMPLSERVICE_EXCEPTION; - private final static QName COUNTRYSERVICEIMPLSERVICE_QNAME = new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplService"); - - static { - URL url = null; - WebServiceException e = null; - try { - url = new URL("file:/D:/projetos/baeldung/tutorials/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl"); - } catch (MalformedURLException ex) { - e = new WebServiceException(ex); - } - COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION = url; - COUNTRYSERVICEIMPLSERVICE_EXCEPTION = e; - } - - public CountryServiceImplService() { - super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME); - } - - public CountryServiceImplService(WebServiceFeature... features) { - super(__getWsdlLocation(), COUNTRYSERVICEIMPLSERVICE_QNAME, features); - } - - public CountryServiceImplService(URL wsdlLocation) { - super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME); - } - - public CountryServiceImplService(URL wsdlLocation, WebServiceFeature... features) { - super(wsdlLocation, COUNTRYSERVICEIMPLSERVICE_QNAME, features); - } - - public CountryServiceImplService(URL wsdlLocation, QName serviceName) { - super(wsdlLocation, serviceName); - } - - public CountryServiceImplService(URL wsdlLocation, QName serviceName, WebServiceFeature... features) { - super(wsdlLocation, serviceName, features); - } - - /** - * - * @return - * returns CountryService - */ - @WebEndpoint(name = "CountryServiceImplPort") - public CountryService getCountryServiceImplPort() { - return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class); - } - - /** - * - * @param features - * A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the features parameter will have their default values. - * @return - * returns CountryService - */ - @WebEndpoint(name = "CountryServiceImplPort") - public CountryService getCountryServiceImplPort(WebServiceFeature... features) { - return super.getPort(new QName("http://server.ws.soap.baeldung.com/", "CountryServiceImplPort"), CountryService.class, features); - } - - private static URL __getWsdlLocation() { - if (COUNTRYSERVICEIMPLSERVICE_EXCEPTION!= null) { - throw COUNTRYSERVICEIMPLSERVICE_EXCEPTION; - } - return COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION; - } - -} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java deleted file mode 100644 index c010f5533c..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/Currency.java +++ /dev/null @@ -1,40 +0,0 @@ - -package com.baeldung.soap.ws.client.generated; - -import javax.xml.bind.annotation.XmlEnum; -import javax.xml.bind.annotation.XmlType; - - -/** - *

Java class for currency. - * - *

The following schema fragment specifies the expected content contained within this class. - *

- *

- * <simpleType name="currency">
- *   <restriction base="{http://www.w3.org/2001/XMLSchema}string">
- *     <enumeration value="EUR"/>
- *     <enumeration value="INR"/>
- *     <enumeration value="USD"/>
- *   </restriction>
- * </simpleType>
- * 
- * - */ -@XmlType(name = "currency") -@XmlEnum -public enum Currency { - - EUR, - INR, - USD; - - public String value() { - return name(); - } - - public static Currency fromValue(String v) { - return valueOf(v); - } - -} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java deleted file mode 100644 index 9ed85fe2b9..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/ObjectFactory.java +++ /dev/null @@ -1,40 +0,0 @@ - -package com.baeldung.soap.ws.client.generated; - -import javax.xml.bind.annotation.XmlRegistry; - - -/** - * This object contains factory methods for each - * Java content interface and Java element interface - * generated in the com.baeldung.soap.ws.client.generated package. - *

An ObjectFactory allows you to programatically - * construct new instances of the Java representation - * for XML content. The Java representation of XML - * content can consist of schema derived interfaces - * and classes representing the binding of schema - * type definitions, element declarations and model - * groups. Factory methods for each of these are - * provided in this class. - * - */ -@XmlRegistry -public class ObjectFactory { - - - /** - * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.soap.ws.client.generated - * - */ - public ObjectFactory() { - } - - /** - * Create an instance of {@link Country } - * - */ - public Country createCountry() { - return new Country(); - } - -} diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java deleted file mode 100644 index dfc556859f..0000000000 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/generated/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -@javax.xml.bind.annotation.XmlSchema(namespace = "http://server.ws.soap.baeldung.com/") -package com.baeldung.soap.ws.client.generated; diff --git a/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl b/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl index 4720cc4cd2..b6efb7087f 100644 --- a/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl +++ b/maven-modules/maven-plugins/jaxws/src/main/resources/country.wsdl @@ -3,7 +3,7 @@ - + diff --git a/maven-modules/maven-plugins/jaxws/src/main/resources/country.xsd b/maven-modules/maven-plugins/jaxws/src/main/resources/country.xsd new file mode 100644 index 0000000000..c94b6047f9 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/src/main/resources/country.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java similarity index 93% rename from maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java rename to maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java index 8a09f1308c..b4e870415f 100644 --- a/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientTest.java +++ b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java @@ -1,14 +1,11 @@ package com.baeldung.soap.ws.client; -import com.baeldung.soap.ws.client.generated.Country; -import com.baeldung.soap.ws.client.generated.CountryService; -import com.baeldung.soap.ws.client.generated.Currency; import org.junit.jupiter.api.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; -class CountryServiceClientTest { +class CountryServiceClientUnitTest { CountryServiceClient countryServiceClient; CountryService countryService; From 422d2359e5d04319beaf9019b3c99b6240d30e3c Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Mon, 1 Mar 2021 10:06:40 +0000 Subject: [PATCH 3/4] BAEL-4362 - Generate WSDL Stubs with Maven Fixing identation on new lines --- .../java/com/baeldung/soap/ws/client/CountryServiceClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java index d179a50396..5e6b4b135e 100644 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java @@ -11,7 +11,7 @@ public class CountryServiceClient { } public String getCapitalByCountryName(String countryName) { return Optional.of(countryService.findByName(countryName)) - .map(Country::getCapital).orElseThrow(CountryNotFoundException::new); + .map(Country::getCapital).orElseThrow(CountryNotFoundException::new); } public int getPopulationByCountryName(String countryName) { From dddfc053490ac793930e4cd799bc929dad2e297f Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Mon, 8 Mar 2021 21:15:42 +0000 Subject: [PATCH 4/4] BAEL-4362 - Generate WSDL Stubs with Maven Removing blank lines Fixing test names to BDD-style --- .../soap/ws/client/CountryServiceClient.java | 3 +-- .../soap/ws/client/CountryServiceClientUnitTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java index 5e6b4b135e..d6175890f9 100644 --- a/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java +++ b/maven-modules/maven-plugins/jaxws/src/main/java/com/baeldung/soap/ws/client/CountryServiceClient.java @@ -9,6 +9,7 @@ public class CountryServiceClient { public CountryServiceClient(CountryService countryService) { this.countryService = countryService; } + public String getCapitalByCountryName(String countryName) { return Optional.of(countryService.findByName(countryName)) .map(Country::getCapital).orElseThrow(CountryNotFoundException::new); @@ -23,6 +24,4 @@ public class CountryServiceClient { return Optional.of(countryService.findByName(countryName)) .map(Country::getCurrency).orElseThrow(CountryNotFoundException::new); } - - } diff --git a/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java index b4e870415f..65c4f39ee4 100644 --- a/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java +++ b/maven-modules/maven-plugins/jaxws/src/test/java/com/baeldung/soap/ws/client/CountryServiceClientUnitTest.java @@ -18,14 +18,14 @@ class CountryServiceClientUnitTest { @DisplayName("Get capital by country name when country not found") @Test - void getCapitalByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + void givenCountryDoesNotExist_whenGetCapitalByCountryName_thenThrowsCountryNotFoundException() { doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getCapitalByCountryName(any())); } @DisplayName("Get capital by country name when country is India then should return capital") @Test - void getCapitalByCountryName_WhenCountryEqualsIndia_ThenShouldReturnCapital() { + void givenCountryIndia_whenGetCapitalByCountryName_thenShouldReturnCapital() { Country country = mock(Country.class); doReturn("New Delhi").when(country).getCapital(); @@ -36,14 +36,14 @@ class CountryServiceClientUnitTest { @DisplayName("Get population by country name when country not found") @Test - void getPopulationByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + void givenCountryDoesNotExist_getPopulationByCountryName_thenThrowsCountryNotFoundException() { doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getPopulationByCountryName(any())); } @DisplayName("Get population by country name when country is India then should return population") @Test - void getPopulationByCountryName_WhenCountryEqualsIndia_ThenShouldReturnPopulation() { + void givenCountryIndia_getPopulationByCountryName_thenShouldReturnPopulation() { Country country = mock(Country.class); doReturn(1000000).when(country).getPopulation(); @@ -54,14 +54,14 @@ class CountryServiceClientUnitTest { @DisplayName("Get currency by country name when country not found") @Test - void getCurrencyByCountryName_WhenCountryDoesNotExists_ThenShouldThrowCountryNotFoundException() { + void givenCountryDoesNotExist_getCurrencyByCountryName_thenThrowsCountryNotFoundException() { doThrow(CountryNotFoundException.class).when(countryService).findByName(any()); Assertions.assertThrows(CountryNotFoundException.class, () -> countryServiceClient.getCurrencyByCountryName(any())); } @DisplayName("Get currency by country name when country is India then should return currency") @Test - void getCurrencyByCountryName_WhenCountryEqualsIndia_ThenShouldReturnCurrency() { + void givenCountryIndia_getCurrencyByCountryName_thenShouldReturnCurrency() { Country country = mock(Country.class); doReturn(Currency.INR).when(country).getCurrency();