Merge pull request #10524 from saleco/master

BAEL-4362 - Generate WSDL Stubs with Maven
This commit is contained in:
Eric Martin 2021-03-08 19:13:11 -06:00 committed by GitHub
commit 1df7c8a287
7 changed files with 213 additions and 0 deletions

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>maven-plugins</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jaxws</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<configuration>
<wsdlDirectory>${project.basedir}/src/main/resources/</wsdlDirectory>
<packageName>com.baeldung.soap.ws.client</packageName>
<sourceDestDir>
${project.build.directory}/generated-sources/
</sourceDestDir>
</configuration>
</plugin>
<plugin>
<artifactId>maven-verifier-plugin</artifactId>
<version>${maven.verifier.version}</version>
<configuration>
<verificationFile>../input-resources/verifications.xml</verificationFile>
<failOnError>false</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,8 @@
package com.baeldung.soap.ws.client;
public class CountryNotFoundException extends RuntimeException {
public CountryNotFoundException() {
super("Country not found!");
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.soap.ws.client;
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);
}
}

View File

@ -0,0 +1,38 @@
<!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
<!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://server.ws.soap.baeldung.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://server.ws.soap.baeldung.com/" name="CountryServiceImplService">
<types>
<xsd:schema>
<xsd:import namespace="http://server.ws.soap.baeldung.com/" schemaLocation="country.xsd"/>
</xsd:schema>
</types>
<message name="findByName">
<part name="arg0" type="xsd:string"/>
</message>
<message name="findByNameResponse">
<part name="return" type="tns:country"/>
</message>
<portType name="CountryService">
<operation name="findByName">
<input wsam:Action="http://server.ws.soap.baeldung.com/CountryService/findByNameRequest" message="tns:findByName"/>
<output wsam:Action="http://server.ws.soap.baeldung.com/CountryService/findByNameResponse" message="tns:findByNameResponse"/>
</operation>
</portType>
<binding name="CountryServiceImplPortBinding" type="tns:CountryService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"/>
<operation name="findByName">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal" namespace="http://server.ws.soap.baeldung.com/"/>
</input>
<output>
<soap:body use="literal" namespace="http://server.ws.soap.baeldung.com/"/>
</output>
</operation>
</binding>
<service name="CountryServiceImplService">
<port name="CountryServiceImplPort" binding="tns:CountryServiceImplPortBinding">
<soap:address location="http://localhost:8888/ws/country"/>
</port>
</service>
</definitions>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
<xs:schema xmlns:tns="http://server.ws.soap.baeldung.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0"
targetNamespace="http://server.ws.soap.baeldung.com/">
<xs:complexType name="country">
<xs:sequence>
<xs:element name="capital" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="currency" type="tns:currency" minOccurs="0"></xs:element>
<xs:element name="name" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="population" type="xs:int"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="currency">
<xs:restriction base="xs:string">
<xs:enumeration value="EUR"></xs:enumeration>
<xs:enumeration value="INR"></xs:enumeration>
<xs:enumeration value="USD"></xs:enumeration>
</xs:restriction>
</xs:simpleType>
</xs:schema>

View File

@ -0,0 +1,73 @@
package com.baeldung.soap.ws.client;
import org.junit.jupiter.api.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
class CountryServiceClientUnitTest {
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 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 givenCountryIndia_whenGetCapitalByCountryName_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 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 givenCountryIndia_getPopulationByCountryName_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 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 givenCountryIndia_getCurrencyByCountryName_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"));
}
}

View File

@ -17,6 +17,7 @@
<modules> <modules>
<module>custom-rule</module> <module>custom-rule</module>
<module>maven-enforcer</module> <module>maven-enforcer</module>
<module>jaxws</module>
</modules> </modules>
<build> <build>