From 6733ed715bad85369bb89ed9c62893a4f05ef05e Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 14 Feb 2021 12:12:48 +0100 Subject: [PATCH 01/26] BASE-4618: Create new module, local variable example --- core-java-modules/core-java-lang-4/README.md | 5 +++ core-java-modules/core-java-lang-4/pom.xml | 42 +++++++++++++++++++ .../finalkeyword/LocalVariableFinal.java | 22 ++++++++++ .../finalkeyword/LocalVariableNonFinal.java | 22 ++++++++++ 4 files changed, 91 insertions(+) create mode 100644 core-java-modules/core-java-lang-4/README.md create mode 100644 core-java-modules/core-java-lang-4/pom.xml create mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java create mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java diff --git a/core-java-modules/core-java-lang-4/README.md b/core-java-modules/core-java-lang-4/README.md new file mode 100644 index 0000000000..ff00688772 --- /dev/null +++ b/core-java-modules/core-java-lang-4/README.md @@ -0,0 +1,5 @@ +## Core Java Lang (Part 4) + +This module contains articles about core features in the Java language + +- TODO diff --git a/core-java-modules/core-java-lang-4/pom.xml b/core-java-modules/core-java-lang-4/pom.xml new file mode 100644 index 0000000000..0761bffcd0 --- /dev/null +++ b/core-java-modules/core-java-lang-4/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + core-java-lang-4 + 0.1.0-SNAPSHOT + core-java-lang-4 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + ../ + + + + + org.assertj + assertj-core + ${assertj.version} + test + + + + + core-java-lang-4 + + + src/main/resources + true + + + + + + 3.19.0 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java new file mode 100644 index 0000000000..74f454508f --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java @@ -0,0 +1,22 @@ +package com.baeldung.finalkeyword; + +public class LocalVariableFinal { + + public static void main(String[] args) { + for (int i = 0; i < 1500; i++) { + long startTime = System.nanoTime(); + String result = concatStrings(); + long totalTime = System.nanoTime() - startTime; + if (i >= 500) { + System.out.println(totalTime); + } + } + } + + private static String concatStrings() { + final String x = "x"; + final String y = "y"; + return x + y; + } + +} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java new file mode 100644 index 0000000000..14b8401d76 --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java @@ -0,0 +1,22 @@ +package com.baeldung.finalkeyword; + +public class LocalVariableNonFinal { + + public static void main(String[] args) { + for (int i = 0; i < 1500; i++) { + long startTime = System.nanoTime(); + String result = concatStrings(); + long totalTime = System.nanoTime() - startTime; + if (i >= 500) { + System.out.println(totalTime); + } + } + } + + private static String concatStrings() { + String x = "x"; + String y = "y"; + return x + y; + } + +} From a50909b228cd6ff98005625d1dcbec5990b4a88f Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Sun, 14 Feb 2021 19:27:43 +0000 Subject: [PATCH 02/26] 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 78a8d0bc772074b9cb3c1be4ad22b5c4e31d6d43 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 20 Feb 2021 18:13:18 +0100 Subject: [PATCH 03/26] BASE-4618: Class variable example --- .../finalkeyword/ClassVariableFinal.java | 23 +++++++++++++++++++ .../finalkeyword/ClassVariableNonFinal.java | 23 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java create mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java new file mode 100644 index 0000000000..5d5f5d7ab6 --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java @@ -0,0 +1,23 @@ +package com.baeldung.finalkeyword; + +public class ClassVariableFinal { + + final static String X = "x"; + final static String Y = "y"; + + public static void main(String[] args) { + for (int i = 0; i < 1500; i++) { + long startTime = System.nanoTime(); + String result = concatStrings(); + long totalTime = System.nanoTime() - startTime; + if (i >= 500) { + System.out.println(totalTime); + } + } + } + + private static String concatStrings() { + return X + Y; + } + +} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java new file mode 100644 index 0000000000..8219b1688f --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java @@ -0,0 +1,23 @@ +package com.baeldung.finalkeyword; + +public class ClassVariableNonFinal { + + static String x = "x"; + static String y = "y"; + + public static void main(String[] args) { + for (int i = 0; i < 1500; i++) { + long startTime = System.nanoTime(); + String result = concatStrings(); + long totalTime = System.nanoTime() - startTime; + if (i >= 500) { + System.out.println(totalTime); + } + } + } + + private static String concatStrings() { + return x + y; + } + +} From 8d8e1b43ca0c5ebe7bdc1c2829fd8cf37bdbdd0e Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 21 Feb 2021 11:18:05 +0100 Subject: [PATCH 04/26] BASE-4618: Update class variable example --- .../finalkeyword/ClassVariableFinal.java | 22 ++++++++----------- .../finalkeyword/ClassVariableNonFinal.java | 22 ++++++++----------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java index 5d5f5d7ab6..1aeef76e58 100644 --- a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java @@ -1,23 +1,19 @@ package com.baeldung.finalkeyword; +import java.io.Console; + public class ClassVariableFinal { - final static String X = "x"; - final static String Y = "y"; + static final boolean doX = false; + static final boolean doY = true; public static void main(String[] args) { - for (int i = 0; i < 1500; i++) { - long startTime = System.nanoTime(); - String result = concatStrings(); - long totalTime = System.nanoTime() - startTime; - if (i >= 500) { - System.out.println(totalTime); - } + Console console = System.console(); + if (doX) { + console.writer().println("x"); + } else if (doY) { + console.writer().println("y"); } } - private static String concatStrings() { - return X + Y; - } - } diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java index 8219b1688f..a6d83a66cb 100644 --- a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java @@ -1,23 +1,19 @@ package com.baeldung.finalkeyword; +import java.io.Console; + public class ClassVariableNonFinal { - static String x = "x"; - static String y = "y"; + static boolean doX = false; + static boolean doY = true; public static void main(String[] args) { - for (int i = 0; i < 1500; i++) { - long startTime = System.nanoTime(); - String result = concatStrings(); - long totalTime = System.nanoTime() - startTime; - if (i >= 500) { - System.out.println(totalTime); - } + Console console = System.console(); + if (doX) { + console.writer().println("x"); + } else if (doY) { + console.writer().println("y"); } } - private static String concatStrings() { - return x + y; - } - } From ee65b0f8de908aa9e24e96f197768cdad855c869 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sun, 21 Feb 2021 11:23:55 +0100 Subject: [PATCH 05/26] BASE-4618: Remove unsed deps --- core-java-modules/core-java-lang-4/pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/core-java-modules/core-java-lang-4/pom.xml b/core-java-modules/core-java-lang-4/pom.xml index 0761bffcd0..520de40529 100644 --- a/core-java-modules/core-java-lang-4/pom.xml +++ b/core-java-modules/core-java-lang-4/pom.xml @@ -16,15 +16,6 @@ ../ - - - org.assertj - assertj-core - ${assertj.version} - test - - - core-java-lang-4 @@ -34,9 +25,5 @@ - - - 3.19.0 - \ No newline at end of file From 7c4fd01620a2a109bd9db254e18840080006fd82 Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Sat, 27 Feb 2021 17:19:33 +0000 Subject: [PATCH 06/26] 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 07/26] 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 f0ee9ddf0233757bcfbe49797475bc62dfe7b4e0 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 6 Mar 2021 09:02:04 +0100 Subject: [PATCH 08/26] BASE-4618: Add new module --- core-java-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index a6aecef741..832c148cb8 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -77,6 +77,7 @@ core-java-lang core-java-lang-2 core-java-lang-3 + core-java-lang-4 core-java-lang-math core-java-lang-math-2 core-java-lang-oop-constructors From c8b3ecbd36ff1c5192e1a67673145726354c44d2 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Sat, 6 Mar 2021 10:00:01 +0100 Subject: [PATCH 09/26] BASE-4618: Use JMH benchmark tool --- core-java-modules/core-java-lang-4/pom.xml | 18 ++++++++++ .../finalkeyword/BenchmarkRunner.java | 34 +++++++++++++++++++ .../finalkeyword/LocalVariableFinal.java | 22 ------------ .../finalkeyword/LocalVariableNonFinal.java | 22 ------------ 4 files changed, 52 insertions(+), 44 deletions(-) create mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java delete mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java delete mode 100644 core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java diff --git a/core-java-modules/core-java-lang-4/pom.xml b/core-java-modules/core-java-lang-4/pom.xml index 520de40529..3e92e9f9c7 100644 --- a/core-java-modules/core-java-lang-4/pom.xml +++ b/core-java-modules/core-java-lang-4/pom.xml @@ -16,6 +16,20 @@ ../ + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + test + + + core-java-lang-4 @@ -25,5 +39,9 @@ + + + 1.28 + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java new file mode 100644 index 0000000000..ee34114195 --- /dev/null +++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java @@ -0,0 +1,34 @@ +package com.baeldung.finalkeyword; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; + +import java.util.concurrent.TimeUnit; + +public class BenchmarkRunner { + + public static void main(String[] args) throws Exception { + org.openjdk.jmh.Main.main(args); + } + + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public static String concatNonFinalStrings() { + String x = "x"; + String y = "y"; + return x + y; + } + + @Benchmark + @OutputTimeUnit(TimeUnit.NANOSECONDS) + @BenchmarkMode(Mode.AverageTime) + public static String concatFinalStrings() { + final String x = "x"; + final String y = "y"; + return x + y; + } + +} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java deleted file mode 100644 index 74f454508f..0000000000 --- a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableFinal.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.finalkeyword; - -public class LocalVariableFinal { - - public static void main(String[] args) { - for (int i = 0; i < 1500; i++) { - long startTime = System.nanoTime(); - String result = concatStrings(); - long totalTime = System.nanoTime() - startTime; - if (i >= 500) { - System.out.println(totalTime); - } - } - } - - private static String concatStrings() { - final String x = "x"; - final String y = "y"; - return x + y; - } - -} diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java deleted file mode 100644 index 14b8401d76..0000000000 --- a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/LocalVariableNonFinal.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.finalkeyword; - -public class LocalVariableNonFinal { - - public static void main(String[] args) { - for (int i = 0; i < 1500; i++) { - long startTime = System.nanoTime(); - String result = concatStrings(); - long totalTime = System.nanoTime() - startTime; - if (i >= 500) { - System.out.println(totalTime); - } - } - } - - private static String concatStrings() { - String x = "x"; - String y = "y"; - return x + y; - } - -} From fc5d08d3f613b016777f061bd54e009d2d268ada Mon Sep 17 00:00:00 2001 From: mdhtr Date: Sun, 7 Mar 2021 23:51:30 +0100 Subject: [PATCH 10/26] BAEL-3938: Add new section on Java 10 Collectors.toUnmodifiableList() (#10488) * Add java10 examples in the style of the existing examples The existing examples in core-java-streams-2 module still had system out in them instead of assertions, so I kept that style to keep the article consistent. * Remove code example that is not in the article --- core-java-modules/core-java-10/README.md | 1 + .../StreamToImmutableJava10UnitTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java diff --git a/core-java-modules/core-java-10/README.md b/core-java-modules/core-java-10/README.md index 11c2051816..9a110449bc 100644 --- a/core-java-modules/core-java-10/README.md +++ b/core-java-modules/core-java-10/README.md @@ -11,3 +11,4 @@ This module contains articles about Java 10 core features - [Copying Sets in Java](https://www.baeldung.com/java-copy-sets) - [Converting between a List and a Set in Java](https://www.baeldung.com/convert-list-to-set-and-set-to-list) - [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception) +- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection) diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java new file mode 100644 index 0000000000..8b1ef54fd2 --- /dev/null +++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.java10.streams; + +import static java.util.stream.Collectors.toUnmodifiableList; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +public class StreamToImmutableJava10UnitTest { + + @Test + public void whenUsingCollectorsToUnmodifiableList_thenSuccess() { + List givenList = Arrays.asList("a", "b", "c"); + List result = givenList.stream() + .collect(toUnmodifiableList()); + + System.out.println(result.getClass()); + } +} From ce6f1e878e6abebcec0a7137005d38ac7fded1c6 Mon Sep 17 00:00:00 2001 From: psevestre Date: Mon, 8 Mar 2021 12:45:37 -0300 Subject: [PATCH 11/26] [BAEL-4782] Initial import (#10513) * [BAEL-4782] Initial import * [BAEL-4782] LiveTest & Readme * [BAEL-4782] spacing issues --- kubernetes/k8s-intro/README.md | 13 +++++++ kubernetes/k8s-intro/pom.xml | 35 +++++++++++++++++++ .../baeldung/kubernetes/intro/ListNodes.java | 31 ++++++++++++++++ .../kubernetes/intro/ListNodesLiveTest.java | 10 ++++++ kubernetes/pom.xml | 13 +++++++ pom.xml | 2 +- 6 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 kubernetes/k8s-intro/README.md create mode 100644 kubernetes/k8s-intro/pom.xml create mode 100644 kubernetes/k8s-intro/src/main/java/com/baeldung/kubernetes/intro/ListNodes.java create mode 100644 kubernetes/k8s-intro/src/test/java/com/baeldung/kubernetes/intro/ListNodesLiveTest.java create mode 100644 kubernetes/pom.xml diff --git a/kubernetes/k8s-intro/README.md b/kubernetes/k8s-intro/README.md new file mode 100644 index 0000000000..37ca5f3686 --- /dev/null +++ b/kubernetes/k8s-intro/README.md @@ -0,0 +1,13 @@ +# Kubernetes Java API Sample Code + +This module contains sample code used to show how to use the Kubernetes client Java API. + +Before running those samples, make sure that your environment is correctly configured to access +a working Kubernetes cluster. + +An easy way to check that everything is working as expected is issuing any *kubectl get* command: + +```shell +$ kubectl get nodes +``` +If you get a valid response, then you're good to go. \ No newline at end of file diff --git a/kubernetes/k8s-intro/pom.xml b/kubernetes/k8s-intro/pom.xml new file mode 100644 index 0000000000..26d6a872d4 --- /dev/null +++ b/kubernetes/k8s-intro/pom.xml @@ -0,0 +1,35 @@ + + 4.0.0 + + com.baeldung + kubernetes-parent + 1.0.0-SNAPSHOT + + k8s-intro + 0.0.1-SNAPSHOT + + + + io.kubernetes + client-java + 11.0.0 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/kubernetes/k8s-intro/src/main/java/com/baeldung/kubernetes/intro/ListNodes.java b/kubernetes/k8s-intro/src/main/java/com/baeldung/kubernetes/intro/ListNodes.java new file mode 100644 index 0000000000..b0e540eb3a --- /dev/null +++ b/kubernetes/k8s-intro/src/main/java/com/baeldung/kubernetes/intro/ListNodes.java @@ -0,0 +1,31 @@ +/** + * + */ +package com.baeldung.kubernetes.intro; + + +import io.kubernetes.client.openapi.ApiClient; +import io.kubernetes.client.openapi.apis.CoreV1Api; +import io.kubernetes.client.openapi.models.V1NodeList; +import io.kubernetes.client.util.Config; + +/** + * @author Philippe + * + */ +public class ListNodes { + + /** + * @param args + */ + public static void main(String[] args) throws Exception { + + ApiClient client = Config.defaultClient(); + CoreV1Api api = new CoreV1Api(client); + V1NodeList nodeList = api.listNode(null, null, null, null, null, null, null, null, 10, false); + nodeList.getItems() + .stream() + .forEach((node) -> System.out.println(node.getMetadata())); + } + +} diff --git a/kubernetes/k8s-intro/src/test/java/com/baeldung/kubernetes/intro/ListNodesLiveTest.java b/kubernetes/k8s-intro/src/test/java/com/baeldung/kubernetes/intro/ListNodesLiveTest.java new file mode 100644 index 0000000000..84a3efb903 --- /dev/null +++ b/kubernetes/k8s-intro/src/test/java/com/baeldung/kubernetes/intro/ListNodesLiveTest.java @@ -0,0 +1,10 @@ +package com.baeldung.kubernetes.intro; + +import org.junit.jupiter.api.Test; + +class ListNodesLiveTest { + @Test + void whenListNodes_thenSuccess() throws Exception { + ListNodes.main(new String[] {}); + } +} diff --git a/kubernetes/pom.xml b/kubernetes/pom.xml new file mode 100644 index 0000000000..fe10295e44 --- /dev/null +++ b/kubernetes/pom.xml @@ -0,0 +1,13 @@ + + 4.0.0 + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + kubernetes-parent + pom + + k8s-intro + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 52ebabb727..5c75b19324 100644 --- a/pom.xml +++ b/pom.xml @@ -471,7 +471,7 @@ json-path jsoup jta - + kubernetes language-interop libraries-2 From 8a11b92f465827422fadaa84c18fa9ecf7e8e861 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Mon, 8 Mar 2021 21:40:36 +0100 Subject: [PATCH 12/26] shutdown the pool --- .../ThreadPoolInParallelStreamIntegrationTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java index 7ee849b0a2..ce96c107f8 100644 --- a/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java +++ b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java @@ -21,14 +21,16 @@ public class ThreadPoolInParallelStreamIntegrationTest { long lastNum = 1_000_000; List aList = LongStream.rangeClosed(firstNum, lastNum).boxed().collect(Collectors.toList()); - ForkJoinPool customThreadPool = new ForkJoinPool(4); - long actualTotal = customThreadPool - .submit(() -> aList.parallelStream() - .reduce(0L, Long::sum)) - .get(); - assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal); + try { + long actualTotal = customThreadPool + .submit(() -> aList.parallelStream().reduce(0L, Long::sum)) + .get(); + assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal); + } finally { + customThreadPool.shutdown(); + } } @Test From dddfc053490ac793930e4cd799bc929dad2e297f Mon Sep 17 00:00:00 2001 From: Sallo Szrajbman Date: Mon, 8 Mar 2021 21:15:42 +0000 Subject: [PATCH 13/26] 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(); From a83d25884ec954f8fb9dc348e4c270bfeb732644 Mon Sep 17 00:00:00 2001 From: "Kent@lhind.hp.g5" Date: Wed, 10 Mar 2021 11:28:43 +0100 Subject: [PATCH 14/26] using query method --- .../com/baeldung/springdatajdbcintro/Application.java | 2 +- .../repository/PersonRepository.java | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java index 7f50aa87f1..8fff82de32 100644 --- a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/Application.java @@ -50,7 +50,7 @@ public class Application implements CommandLineRunner { LOGGER.info("@@ findByFirstName() call..."); repository.findByFirstName("Franz") .forEach(person -> LOGGER.info(person.toString())); - LOGGER.info("@@ findByFirstName() call..."); + LOGGER.info("@@ updateByFirstName() call..."); repository.updateByFirstName(2L, "Date Inferno"); repository.findAll() .forEach(person -> LOGGER.info(person.toString())); diff --git a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java index 2f2329caec..b2f026fa0c 100644 --- a/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java +++ b/persistence-modules/spring-data-jdbc/src/main/java/com/baeldung/springdatajdbcintro/repository/PersonRepository.java @@ -1,23 +1,20 @@ package com.baeldung.springdatajdbcintro.repository; -import java.util.List; - +import com.baeldung.springdatajdbcintro.entity.Person; import org.springframework.data.jdbc.repository.query.Modifying; import org.springframework.data.jdbc.repository.query.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; import org.springframework.stereotype.Repository; -import com.baeldung.springdatajdbcintro.entity.Person; +import java.util.List; @Repository -public interface PersonRepository extends CrudRepository { +public interface PersonRepository extends CrudRepository { - @Query("select * from person where first_name=:firstName") - List findByFirstName(@Param("firstName") String firstName); + List findByFirstName(String firstName); @Modifying @Query("UPDATE person SET first_name = :name WHERE id = :id") boolean updateByFirstName(@Param("id") Long id, @Param("name") String name); - } From 8c86197317d419bd1e8582e5051418d0f7daa3e9 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Mar 2021 21:14:40 +0800 Subject: [PATCH 15/26] Update README.md --- core-java-modules/core-java-reflection-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-reflection-2/README.md b/core-java-modules/core-java-reflection-2/README.md index 9ed14f08dc..3195cddc42 100644 --- a/core-java-modules/core-java-reflection-2/README.md +++ b/core-java-modules/core-java-reflection-2/README.md @@ -4,3 +4,4 @@ - [Set Field Value With Reflection](https://www.baeldung.com/java-set-private-field-value) - [Checking If a Method is Static Using Reflection in Java](https://www.baeldung.com/java-check-method-is-static) - [Checking if a Java Class is ‘abstract’ Using Reflection](https://www.baeldung.com/java-reflection-is-class-abstract) +- [Invoking a Private Method in Java](https://www.baeldung.com/java-call-private-method) From c98d1d243e76d811855f4155a8e313692908c6fd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Mar 2021 21:19:07 +0800 Subject: [PATCH 16/26] Update README.md --- libraries-http-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-http-2/README.md b/libraries-http-2/README.md index c0d6e76f1b..f3fdf1becb 100644 --- a/libraries-http-2/README.md +++ b/libraries-http-2/README.md @@ -7,5 +7,6 @@ This module contains articles about HTTP libraries. - [Jetty ReactiveStreams HTTP Client](https://www.baeldung.com/jetty-reactivestreams-http-client) - [Decode an OkHttp JSON Response](https://www.baeldung.com/okhttp-json-response) - [Retrofit 2 – Dynamic URL](https://www.baeldung.com/retrofit-dynamic-url) +- [Adding Interceptors in OkHTTP](https://www.baeldung.com/java-okhttp-interceptors) - More articles [[<-- prev]](/libraries-http) From 5ffb5e9ecae4421674c1f74b3d834da3e200bcad Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Mar 2021 22:52:28 +0800 Subject: [PATCH 17/26] Create README.md --- spring-security-modules/spring-security-saml/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-security-modules/spring-security-saml/README.md diff --git a/spring-security-modules/spring-security-saml/README.md b/spring-security-modules/spring-security-saml/README.md new file mode 100644 index 0000000000..271b29632e --- /dev/null +++ b/spring-security-modules/spring-security-saml/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [A Guide to SAML with Spring Security](https://www.baeldung.com/spring-security-saml) From f31bbf290d2443b2e8d47f2f443140996284b388 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 10 Mar 2021 22:55:00 +0800 Subject: [PATCH 18/26] Create README.md --- maven-modules/maven-plugins/jaxws/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 maven-modules/maven-plugins/jaxws/README.md diff --git a/maven-modules/maven-plugins/jaxws/README.md b/maven-modules/maven-plugins/jaxws/README.md new file mode 100644 index 0000000000..d17df7a5f6 --- /dev/null +++ b/maven-modules/maven-plugins/jaxws/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Generate WSDL Stubs with Maven](https://www.baeldung.com/maven-wsdl-stubs) From 13970d355b76568f3cabe72ae570efd7691a019b Mon Sep 17 00:00:00 2001 From: MeenaGawande <45625809+MeenaGawande@users.noreply.github.com> Date: Thu, 11 Mar 2021 12:14:57 +0530 Subject: [PATCH 19/26] [BAEL-4208] Java compiled classes contain dollar signs (#10533) Java class file naming conventions Co-authored-by: MeenaGawande --- .../java/com/baeldung/classfile/Outer.java | 131 ++++++++++++++++++ .../com/baeldung/classfile/OuterUnitTest.java | 46 ++++++ 2 files changed, 177 insertions(+) create mode 100644 core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/classfile/Outer.java create mode 100644 core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/classfile/OuterUnitTest.java diff --git a/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/classfile/Outer.java b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/classfile/Outer.java new file mode 100644 index 0000000000..b140f7085b --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/main/java/com/baeldung/classfile/Outer.java @@ -0,0 +1,131 @@ +package com.baeldung.classfile; + +import org.apache.commons.lang3.StringUtils; +import com.baeldung.classfile.HelloWorld.HelloSomeone; + +public class Outer { + + // Static Nested class + static class StaticNested { + public String message() { + return "This is a static Nested Class"; + } + } + + // Non-static Nested class + class Nested { + public String message() { + return "This is a non-static Nested Class"; + } + } + + // Local class + public String message() { + class Local { + private String message() { + return "This is a Local Class within a method"; + } + } + Local local = new Local(); + return local.message(); + } + + // Local class within if clause + public String message(String name) { + if (StringUtils.isEmpty(name)) { + class Local { + private String message() { + return "This is a Local Class within if clause"; + } + } + Local local = new Local(); + return local.message(); + } else + return "Welcome to " + name; + } + + // Anonymous Inner class extending a class + public String greet() { + Outer anonymous = new Outer() { + public String greet() { + return "Running Anonymous Class..."; + } + }; + return anonymous.greet(); + } + + // Anonymous inner class implementing an interface + public String greet(String name) { + + HelloWorld helloWorld = new HelloWorld() { + public String greet(String name) { + return "Welcome to " + name; + } + + }; + return helloWorld.greet(name); + } + + // Anonymous inner class implementing nested interface + public String greetSomeone(String name) { + + HelloSomeone helloSomeOne = new HelloSomeone() { + public String greet(String name) { + return "Hello " + name; + } + + }; + return helloSomeOne.greet(name); + } + + // Nested interface within a class + interface HelloOuter { + public String hello(String name); + } + + // Enum within a class + enum Color { + RED, GREEN, BLUE; + } +} + +interface HelloWorld { + + public String greet(String name); + + // Nested class within an interface + class InnerClass { + public String greet(String name) { + return "Inner class within an interface"; + } + } + + // Nested interface within an interfaces + interface HelloSomeone { + public String greet(String name); + } + + // Enum within an interface + enum Directon { + NORTH, SOUTH, EAST, WEST; + } +} + +enum Level { + LOW, MEDIUM, HIGH; + +} + +enum Foods { + + DRINKS, EATS; + + // Enum within Enum + enum DRINKS { + APPLE_JUICE, COLA; + } + + enum EATS { + POTATO, RICE; + } +} diff --git a/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/classfile/OuterUnitTest.java b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/classfile/OuterUnitTest.java new file mode 100644 index 0000000000..3ffe7d561a --- /dev/null +++ b/core-java-modules/core-java-lang-oop-types/src/test/java/com/baeldung/classfile/OuterUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.classfile; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.Test; +import com.baeldung.classfile.Outer.Nested; + +public class OuterUnitTest { + + @Test + public void when_static_nestedClass_then_verifyOutput() { + Outer.StaticNested nestedClass = new Outer.StaticNested(); + assertEquals("This is a static Nested Class", nestedClass.message()); + } + + @Test + public void when_nestedClass_then_verifyOutput() { + Outer outer = new Outer(); + Nested nestedClass = outer.new Nested(); + assertEquals("This is a non-static Nested Class", nestedClass.message()); + } + + @Test + public void when_localClass_then_verifyOutput() { + Outer outer = new Outer(); + assertEquals("This is a Local Class within a method", outer.message()); + } + + @Test + public void when_localClassInIfClause_then_verifyOutput() { + Outer outer = new Outer(); + assertEquals("Welcome to Baeldung", outer.message("Baeldung")); + assertEquals("This is a Local Class within if clause", outer.message("")); + } + + @Test + public void when_anonymousClass_then_verifyOutput() { + Outer outer = new Outer(); + assertEquals("Running Anonymous Class...", outer.greet()); + } + + @Test + public void when_anonymousClassHelloWorld_then_verifyOutput() { + Outer outer = new Outer(); + assertEquals("Welcome to Baeldung", outer.greet("Baeldung")); + } +} \ No newline at end of file From 4e88e662f63810cd6bb68474f5c3095248987766 Mon Sep 17 00:00:00 2001 From: Daniel Strmecki Date: Thu, 11 Mar 2021 11:28:49 +0100 Subject: [PATCH 20/26] BASE-4618: Use space --- core-java-modules/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 832c148cb8..db808e5fda 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -77,7 +77,7 @@ core-java-lang core-java-lang-2 core-java-lang-3 - core-java-lang-4 + core-java-lang-4 core-java-lang-math core-java-lang-math-2 core-java-lang-oop-constructors From bd81992f665ab2316eb3e61b382519129a650e6c Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Thu, 11 Mar 2021 16:53:44 +0530 Subject: [PATCH 21/26] JAVA-4802: Upgrade parent-spring-5 to the latest version of Spring 5 --- parent-spring-5/pom.xml | 2 +- spring-web-modules/spring-mvc-views/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 5893701c68..3219c504d5 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -31,7 +31,7 @@ - 5.2.8.RELEASE + 5.3.3 5.2.3.RELEASE 1.5.10.RELEASE diff --git a/spring-web-modules/spring-mvc-views/pom.xml b/spring-web-modules/spring-mvc-views/pom.xml index 2c3be5a33e..2e80a60966 100644 --- a/spring-web-modules/spring-mvc-views/pom.xml +++ b/spring-web-modules/spring-mvc-views/pom.xml @@ -11,7 +11,7 @@ com.baeldung parent-spring-5 0.0.1-SNAPSHOT - parent-spring-5/pom.xml + ../../parent-spring-5 From 0545265255f0bab0eab8679ff57767b7b204b25e Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 11 Mar 2021 20:12:28 +0100 Subject: [PATCH 22/26] JAVA-4669: Fix CircularBuffer constructor --- .../main/java/com/baeldung/circularbuffer/CircularBuffer.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java index 6b315265b4..cde07728ba 100644 --- a/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java +++ b/data-structures/src/main/java/com/baeldung/circularbuffer/CircularBuffer.java @@ -10,10 +10,8 @@ public class CircularBuffer { @SuppressWarnings("unchecked") public CircularBuffer(int capacity) { - this.capacity = (capacity < 1) ? DEFAULT_CAPACITY : capacity; - this.data = (E[]) new Object[capacity]; - + this.data = (E[]) new Object[this.capacity]; this.readSequence = 0; this.writeSequence = -1; } From 47db80077de8d515cb63e02eeac7039a7f143e87 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 11 Mar 2021 20:39:47 +0100 Subject: [PATCH 23/26] JAVA-4240: Add exception's message to the log --- .../test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java index 66bfbe49eb..0c63306adb 100644 --- a/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java +++ b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java @@ -20,7 +20,7 @@ public class JavaRMIIntegrationTest { MessengerServiceImpl server = new MessengerServiceImpl(); server.createStubAndBind(); } catch (RemoteException e) { - fail("Exception Occurred"); + fail("Exception Occurred: " + e); } } @@ -35,9 +35,9 @@ public class JavaRMIIntegrationTest { String expectedMessage = "Server Message"; assertEquals(responseMessage, expectedMessage); } catch (RemoteException e) { - fail("Exception Occurred"); + fail("Exception Occurred: " + e); } catch (NotBoundException nb) { - fail("Exception Occurred"); + fail("Exception Occurred: " + e); } } From 6332f7eba4db1b32c5f04074d01521ec9407da33 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 11 Mar 2021 20:58:45 +0100 Subject: [PATCH 24/26] JAVA-4240: Fix catch block --- .../test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java index 0c63306adb..5e4ecb3e76 100644 --- a/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java +++ b/java-rmi/src/test/java/com/baeldung/rmi/JavaRMIIntegrationTest.java @@ -34,11 +34,9 @@ public class JavaRMIIntegrationTest { String expectedMessage = "Server Message"; assertEquals(responseMessage, expectedMessage); - } catch (RemoteException e) { + } catch (RemoteException | NotBoundException e) { fail("Exception Occurred: " + e); - } catch (NotBoundException nb) { - fail("Exception Occurred: " + e); - } + }; } } \ No newline at end of file From eea3ae3084226f8a6e379eb5f00747704ea5489c Mon Sep 17 00:00:00 2001 From: Jordan Simpson Date: Fri, 12 Mar 2021 01:04:20 -0600 Subject: [PATCH 25/26] BAEL-4685 (#10418) * Add code examples for article BAEL-4685 * Add tests for the endpoints. * Rename RequestTimeoutTests.java to RequestTimeoutUnitTest.java --- spring-web-modules/spring-rest-http-2/pom.xml | 17 ++++++ .../RequestTimeoutRestController.java | 61 +++++++++++++++++++ .../configuration/WebClientConfiguration.java | 21 +++++++ .../baeldung/requesttimeout/domain/Book.java | 28 +++++++++ .../requesttimeout/domain/BookRepository.java | 14 +++++ .../src/main/resources/application.properties | 1 + .../RequestTimeoutUnitTest.java | 46 ++++++++++++++ .../src/test/resources/application.properties | 1 + 8 files changed, 189 insertions(+) create mode 100644 spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/RequestTimeoutRestController.java create mode 100644 spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/configuration/WebClientConfiguration.java create mode 100644 spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/Book.java create mode 100644 spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/BookRepository.java create mode 100644 spring-web-modules/spring-rest-http-2/src/main/resources/application.properties create mode 100644 spring-web-modules/spring-rest-http-2/src/test/com/baeldung/requesttimeout/RequestTimeoutUnitTest.java create mode 100644 spring-web-modules/spring-rest-http-2/src/test/resources/application.properties diff --git a/spring-web-modules/spring-rest-http-2/pom.xml b/spring-web-modules/spring-rest-http-2/pom.xml index 6aa8be365c..0ea3fd6840 100644 --- a/spring-web-modules/spring-rest-http-2/pom.xml +++ b/spring-web-modules/spring-rest-http-2/pom.xml @@ -19,6 +19,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-webflux + io.springfox springfox-swagger2 @@ -29,6 +33,19 @@ springfox-swagger-ui ${swagger2.version} + + com.h2database + h2 + + + org.springframework.boot + spring-boot-starter-data-jpa + + + io.github.resilience4j + resilience4j-timelimiter + 1.6.1 + diff --git a/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/RequestTimeoutRestController.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/RequestTimeoutRestController.java new file mode 100644 index 0000000000..d425737bab --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/RequestTimeoutRestController.java @@ -0,0 +1,61 @@ +package com.baeldung.requesttimeout; + +import com.baeldung.requesttimeout.domain.Book; +import com.baeldung.requesttimeout.domain.BookRepository; +import io.github.resilience4j.timelimiter.TimeLimiter; +import io.github.resilience4j.timelimiter.TimeLimiterConfig; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.reactive.function.client.WebClient; + +import java.time.Duration; +import java.util.concurrent.Callable; +import java.util.concurrent.CompletableFuture; + +@RestController +public class RequestTimeoutRestController { + + private final BookRepository bookRepository; + private final WebClient webClient; + + public RequestTimeoutRestController(BookRepository bookRepository, WebClient webClient) { + this.bookRepository = bookRepository; + this.webClient = webClient; + } + + @GetMapping("/author/transactional") + @Transactional(timeout = 1) + public String getWithTransactionTimeout(@RequestParam String title) { + return getAuthor(title); + } + + private final TimeLimiter ourTimeLimiter = TimeLimiter.of(TimeLimiterConfig.custom().timeoutDuration(Duration.ofMillis(500)).build()); + @GetMapping("/author/resilience4j") + public Callable getWithResilience4jTimeLimiter(@RequestParam String title) { + return TimeLimiter.decorateFutureSupplier(ourTimeLimiter, () -> CompletableFuture.supplyAsync(() -> getAuthor(title))); + } + + @GetMapping("/author/mvc-request-timeout") + public Callable getWithMvcRequestTimeout(@RequestParam String title) { + return () -> getAuthor(title); + } + + @GetMapping("/author/webclient") + public String getWithWebClient(@RequestParam String title) { + return webClient.get() + .uri(uriBuilder -> uriBuilder + .path("/author/transactional") + .queryParam("title", title) + .build()) + .retrieve() + .bodyToMono(String.class) + .block(); + } + + private String getAuthor(String title) { + bookRepository.wasteTime(); + return bookRepository.findById(title).map(Book::getAuthor).orElse("No book found for this title."); + } +} diff --git a/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/configuration/WebClientConfiguration.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/configuration/WebClientConfiguration.java new file mode 100644 index 0000000000..52b3573411 --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/configuration/WebClientConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.requesttimeout.configuration; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.reactive.ReactorClientHttpConnector; +import org.springframework.web.reactive.function.client.WebClient; +import reactor.netty.http.client.HttpClient; + +import java.time.Duration; + +@Configuration +public class WebClientConfiguration { + + @Bean + public WebClient webClient() { + return WebClient.builder() + .baseUrl("http://localhost:8080") + .clientConnector(new ReactorClientHttpConnector(HttpClient.create().responseTimeout(Duration.ofMillis(250)))) + .build(); + } +} diff --git a/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/Book.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/Book.java new file mode 100644 index 0000000000..846bfb2cec --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/Book.java @@ -0,0 +1,28 @@ +package com.baeldung.requesttimeout.domain; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Book { + + @Id + private String title; + private String author; + + public void setTitle(String title) { + this.title = title; + } + + public String getTitle() { + return title; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } +} diff --git a/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/BookRepository.java b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/BookRepository.java new file mode 100644 index 0000000000..8ecab0f1d2 --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/main/java/com/baeldung/requesttimeout/domain/BookRepository.java @@ -0,0 +1,14 @@ +package com.baeldung.requesttimeout.domain; + +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BookRepository extends JpaRepository { + + default int wasteTime() { + int i = Integer.MIN_VALUE; + while(i < Integer.MAX_VALUE) { + i++; + } + return i; + } +} diff --git a/spring-web-modules/spring-rest-http-2/src/main/resources/application.properties b/spring-web-modules/spring-rest-http-2/src/main/resources/application.properties new file mode 100644 index 0000000000..ff4af943ec --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.mvc.async.request-timeout=750 \ No newline at end of file diff --git a/spring-web-modules/spring-rest-http-2/src/test/com/baeldung/requesttimeout/RequestTimeoutUnitTest.java b/spring-web-modules/spring-rest-http-2/src/test/com/baeldung/requesttimeout/RequestTimeoutUnitTest.java new file mode 100644 index 0000000000..da7d40d53c --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/test/com/baeldung/requesttimeout/RequestTimeoutUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.requesttimeout; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientRequestException; + +@SpringBootTest +@RunWith(SpringRunner.class) +public class RequestTimeoutTests { + + private static final WebClient WEB_CLIENT = WebClient.builder().baseUrl("http://localhost:8080").build(); + + @Test(expected = WebClientRequestException.class) + public void givenTransactionTimeout_whenTimeExpires_thenReceiveException() { + getAuthor("transactional"); + } + + @Test(expected = WebClientRequestException.class) + public void givenResilience4jTimeLimiter_whenTimeExpires_thenReceiveException() { + getAuthor("resilience4j"); + } + + @Test(expected = WebClientRequestException.class) + public void givenMvcRequestTimeout_whenTimeExpires_thenReceiveException() { + getAuthor("mvc-request-timeout"); + } + + @Test(expected = WebClientRequestException.class) + public void givenWebClientTimeout_whenTimeExpires_thenReceiveException() { + getAuthor("webclient"); + } + + private void getAuthor(String authorPath) { + WEB_CLIENT.get() + .uri(uriBuilder -> uriBuilder + .path("/author/" + authorPath) + .queryParam("title", "title") + .build()) + .retrieve() + .bodyToMono(String.class) + .block(); + } +} diff --git a/spring-web-modules/spring-rest-http-2/src/test/resources/application.properties b/spring-web-modules/spring-rest-http-2/src/test/resources/application.properties new file mode 100644 index 0000000000..ff4af943ec --- /dev/null +++ b/spring-web-modules/spring-rest-http-2/src/test/resources/application.properties @@ -0,0 +1 @@ +spring.mvc.async.request-timeout=750 \ No newline at end of file From 639ac629cd81541ebdd9adcd4e81c3cb267849b5 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Fri, 12 Mar 2021 16:34:29 +0100 Subject: [PATCH 26/26] BAEL-4835: Initialize test data (#10548) --- .../list/primitive/PrimitivesListPerformance.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java index bd37e5e74e..5dd1eaef09 100644 --- a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java +++ b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java @@ -8,6 +8,7 @@ import org.openjdk.jmh.runner.options.Options; import org.openjdk.jmh.runner.options.OptionsBuilder; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; @@ -18,12 +19,12 @@ import java.util.concurrent.TimeUnit; @State(Scope.Thread) public class PrimitivesListPerformance { - private List arrayList = new ArrayList<>(); - private TIntArrayList tList = new TIntArrayList(); - private cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList(); - private IntArrayList fastUtilList = new IntArrayList(); + private List arrayList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)); + private TIntArrayList tList = new TIntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + private cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + private IntArrayList fastUtilList = new IntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); - private int getValue = 10; + private int getValue = 4; @Benchmark public boolean addArrayList() {