diff --git a/azure/pom.xml b/azure/pom.xml index ae20ae7785..6a06282a71 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -36,8 +36,8 @@ runtime - mysql - mysql-connector-java + com.mysql + mysql-connector-j runtime diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md index 00fd2fa320..97be9391fb 100644 --- a/core-java-modules/core-java-14/README.md +++ b/core-java-modules/core-java-14/README.md @@ -12,3 +12,4 @@ This module contains articles about Java 14. - [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword) - [New Features in Java 14](https://www.baeldung.com/java-14-new-features) - [Java 14 Record vs. Lombok](https://www.baeldung.com/java-record-vs-lombok) +- [Record vs. Final Class in Java](https://www.baeldung.com/java-record-vs-final-class) diff --git a/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/combine2liststomap/CombineTwoListsInAMapUnitTest.java b/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/combine2liststomap/CombineTwoListsInAMapUnitTest.java new file mode 100644 index 0000000000..501ec16a21 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-2/src/test/java/com/baeldung/combine2liststomap/CombineTwoListsInAMapUnitTest.java @@ -0,0 +1,62 @@ +package com.baeldung.combine2liststomap; + +import static java.lang.Math.min; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +import org.junit.jupiter.api.Test; + +public class CombineTwoListsInAMapUnitTest { + private static final List KEY_LIST = Arrays.asList("Number One", "Number Two", "Number Three", "Number Four", "Number Five"); + private static final List VALUE_LIST = Arrays.asList(1, 2, 3, 4, 5); + private static final Map EXPECTED_MAP = new HashMap() {{ + put("Number One", 1); + put("Number Two", 2); + put("Number Three", 3); + put("Number Four", 4); + put("Number Five", 5); + }}; + + @Test + void givenTwoLists_whenUsingLoopAndListGet_shouldGetExpectedMap() { + Map result = new HashMap<>(); + int size = KEY_LIST.size(); + if (KEY_LIST.size() != VALUE_LIST.size()) { + // throw an exception or print a warning + size = min(KEY_LIST.size(), VALUE_LIST.size()); + } + for (int i = 0; i < size; i++) { + result.put(KEY_LIST.get(i), VALUE_LIST.get(i)); + } + assertEquals(EXPECTED_MAP, result); + } + + @Test + void givenTwoLists_whenUsingStreamApiAndListGet_shouldGetExpectedMap() { + Map result = IntStream.range(0, KEY_LIST.size()) + .boxed() + .collect(Collectors.toMap(KEY_LIST::get, VALUE_LIST::get)); + assertEquals(EXPECTED_MAP, result); + } + + @Test + void givenTwoLists_whenUsingIterators_shouldGetExpectedMap() { + Map result = new HashMap<>(); + + Iterator ik = KEY_LIST.iterator(); + Iterator iv = VALUE_LIST.iterator(); + while (ik.hasNext() && iv.hasNext()) { + result.put(ik.next(), iv.next()); + } + + assertEquals(EXPECTED_MAP, result); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-3/pom.xml b/core-java-modules/core-java-concurrency-basic-3/pom.xml index 7771d1200c..7289877550 100644 --- a/core-java-modules/core-java-concurrency-basic-3/pom.xml +++ b/core-java-modules/core-java-concurrency-basic-3/pom.xml @@ -24,4 +24,16 @@ + + 4.2.0 + + + + + org.awaitility + awaitility + ${awaitility.version} + test + + \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/RequestProcessor.java b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/RequestProcessor.java new file mode 100644 index 0000000000..9557a27f2a --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/main/java/com/baeldung/concurrent/RequestProcessor.java @@ -0,0 +1,35 @@ +package com.baeldung.concurrent; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class RequestProcessor { + + private Map requestStatuses = new HashMap<>(); + + public String processRequest() { + String requestId = UUID.randomUUID().toString(); + requestStatuses.put(requestId, "PROCESSING"); + + ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); + executorService.schedule((() -> { + requestStatuses.put(requestId, "DONE"); + }), getRandomNumberBetween(500, 2000), TimeUnit.MILLISECONDS); + + return requestId; + } + + public String getStatus(String requestId) { + return requestStatuses.get(requestId); + } + + private int getRandomNumberBetween(int min, int max) { + Random random = new Random(); + return random.nextInt(max - min) + min; + } +} diff --git a/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/RequestProcessorUnitTest.java b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/RequestProcessorUnitTest.java new file mode 100644 index 0000000000..c437b08b34 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-3/src/test/java/com/baeldung/concurrent/RequestProcessorUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.concurrent; + +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.concurrent.TimeUnit; + +import org.awaitility.Awaitility; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("Request processor") +public class RequestProcessorUnitTest { + + RequestProcessor requestProcessor = new RequestProcessor(); + + @Test + @DisplayName("Wait for completion using Thread.sleep") + void whenWaitingWithThreadSleep_thenStatusIsDone() throws InterruptedException { + String requestId = requestProcessor.processRequest(); + + Thread.sleep(2000); + + assertEquals("DONE", requestProcessor.getStatus(requestId)); + } + + @Test + @DisplayName("Wait for completion using Awaitility") + void whenWaitingWithAwaitility_thenStatusIsDone() { + String requestId = requestProcessor.processRequest(); + + Awaitility.await() + .atMost(2, TimeUnit.SECONDS) + .pollDelay(500, TimeUnit.MILLISECONDS) + .until(() -> requestProcessor.getStatus(requestId), not(equalTo("PROCESSING"))); + + assertEquals("DONE", requestProcessor.getStatus(requestId)); + } + +} diff --git a/core-java-modules/core-java-functional/README.md b/core-java-modules/core-java-functional/README.md index 51185f13a1..addb312542 100644 --- a/core-java-modules/core-java-functional/README.md +++ b/core-java-modules/core-java-functional/README.md @@ -2,3 +2,4 @@ - [Functional Programming in Java](https://www.baeldung.com/java-functional-programming) - [Functors in Java](https://www.baeldung.com/java-functors) +- [Callback Functions in Java](https://www.baeldung.com/java-callback-functions) diff --git a/core-java-modules/core-java-hex/README.md b/core-java-modules/core-java-hex/README.md index e69de29bb2..0ba4d1372f 100644 --- a/core-java-modules/core-java-hex/README.md +++ b/core-java-modules/core-java-hex/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Convert Hex to RGB Using Java](https://www.baeldung.com/java-convert-hex-to-rgb) diff --git a/core-java-modules/core-java-httpclient/README.md b/core-java-modules/core-java-httpclient/README.md index 68f828e81b..5dbb7a08ef 100644 --- a/core-java-modules/core-java-httpclient/README.md +++ b/core-java-modules/core-java-httpclient/README.md @@ -5,3 +5,4 @@ This module contains articles about Java HttpClient ### Relevant articles - [Posting with Java HttpClient](https://www.baeldung.com/java-httpclient-post) - [Custom HTTP Header With the Java HttpClient](https://www.baeldung.com/java-http-client-custom-header) +- [Java HttpClient Connection Management](https://www.baeldung.com/java-httpclient-connection-management) diff --git a/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/reflection/PrivateConstructorClass.java b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/reflection/PrivateConstructorClass.java new file mode 100644 index 0000000000..24e7d435c7 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/main/java/com/baeldung/reflection/PrivateConstructorClass.java @@ -0,0 +1,8 @@ +package com.baeldung.reflection; + +public class PrivateConstructorClass { + + private PrivateConstructorClass() { + System.out.println("Used the private constructor!"); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/reflection/PrivateConstructorUnitTest.java b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/reflection/PrivateConstructorUnitTest.java new file mode 100644 index 0000000000..cd1f48d720 --- /dev/null +++ b/core-java-modules/core-java-lang-oop-constructors/src/test/java/com/baeldung/reflection/PrivateConstructorUnitTest.java @@ -0,0 +1,17 @@ +package com.baeldung.reflection; + +import java.lang.reflect.Constructor; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class PrivateConstructorUnitTest { + + @Test + public void whenConstructorIsPrivate_thenInstanceSuccess() throws Exception { + Constructor pcc = PrivateConstructorClass.class.getDeclaredConstructor(); + pcc.setAccessible(true); + PrivateConstructorClass privateConstructorInstance = pcc.newInstance(); + Assertions.assertTrue(privateConstructorInstance instanceof PrivateConstructorClass); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-streams-4/README.md b/core-java-modules/core-java-streams-4/README.md index b0b42324d6..67b16ac153 100644 --- a/core-java-modules/core-java-streams-4/README.md +++ b/core-java-modules/core-java-streams-4/README.md @@ -8,3 +8,4 @@ - [Batch Processing of Stream Data in Java](https://www.baeldung.com/java-stream-batch-processing) - [Stream to Iterable in Java](https://www.baeldung.com/java-stream-to-iterable) - [Understanding the Difference Between Stream.of() and IntStream.range()](https://www.baeldung.com/java-stream-of-and-intstream-range) +- [Check if Object Is an Array in Java](https://www.baeldung.com/java-check-if-object-is-an-array) diff --git a/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/intarraytostrings/ArrayConversionUtils.java b/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/intarraytostrings/ArrayConversionUtils.java new file mode 100644 index 0000000000..3bb58b43d2 --- /dev/null +++ b/core-java-modules/core-java-streams-4/src/main/java/com/baeldung/streams/intarraytostrings/ArrayConversionUtils.java @@ -0,0 +1,43 @@ +package com.baeldung.streams.intarraytostrings; + +import java.util.Arrays; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +public class ArrayConversionUtils { + + public static void createStreamExample() { + int[] intArray = { 1, 2, 3, 4, 5 }; + IntStream intStream = Arrays.stream(intArray); + + Integer[] integerArray = { 1, 2, 3, 4, 5 }; + Stream integerStream = Arrays.stream(integerArray); + } + + public static String[] convertToStringArray(Integer[] input) { + return Arrays.stream(input) + .map(Object::toString) + .toArray(String[]::new); + } + + public static String[] convertToStringArray(int[] input) { + return Arrays.stream(input) + .mapToObj(Integer::toString) + .toArray(String[]::new); + } + + public static String[] convertToStringArrayWithBoxing(int[] input) { + return Arrays.stream(input) + .boxed() + .map(Object::toString) + .toArray(String[]::new); + } + + public static String convertToString(int[] input){ + return Arrays.stream(input) + .mapToObj(Integer::toString) + .collect(Collectors.joining(", ")); + } + +} diff --git a/core-java-modules/core-java-streams-4/src/test/java/com/baeldung/streams/intarraytostrings/IntArrayToStringUnitTest.java b/core-java-modules/core-java-streams-4/src/test/java/com/baeldung/streams/intarraytostrings/IntArrayToStringUnitTest.java new file mode 100644 index 0000000000..3f6fb0be8e --- /dev/null +++ b/core-java-modules/core-java-streams-4/src/test/java/com/baeldung/streams/intarraytostrings/IntArrayToStringUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.streams.intarraytostrings; + +import static com.baeldung.streams.intarraytostrings.ArrayConversionUtils.convertToString; +import static com.baeldung.streams.intarraytostrings.ArrayConversionUtils.convertToStringArray; +import static com.baeldung.streams.intarraytostrings.ArrayConversionUtils.convertToStringArrayWithBoxing; + +import org.junit.Assert; +import org.junit.Test; + +public class IntArrayToStringUnitTest { + + @Test + public void whenConvertingIntegers_thenHandleStreamOfIntegers() { + Integer[] integerNumbers = { 1, 2, 3, 4, 5 }; + String[] expectedOutput = { "1", "2", "3", "4", "5" }; + + String[] strings = convertToStringArray(integerNumbers); + + Assert.assertArrayEquals(expectedOutput, strings); + } + + @Test + public void whenConvertingInts_thenHandleIntStream() { + int[] intNumbers = { 1, 2, 3, 4, 5 }; + String[] expectedOutput = { "1", "2", "3", "4", "5" }; + + String[] strings = convertToStringArray(intNumbers); + + Assert.assertArrayEquals(expectedOutput, strings); + } + + @Test + public void givenAnIntArray_whenBoxingToInteger_thenHandleStreamOfIntegers() { + int[] intNumbers = { 1, 2, 3, 4, 5 }; + String[] expectedOutput = { "1", "2", "3", "4", "5" }; + + String[] strings = convertToStringArrayWithBoxing(intNumbers); + + Assert.assertArrayEquals(expectedOutput, strings); + } + + @Test + public void givenAnIntArray_whenUsingCollectorsJoining_thenReturnCommaSeparatedString(){ + int[] intNumbers = { 1, 2, 3, 4, 5 }; + String expectedOutput = "1, 2, 3, 4, 5"; + + String string = convertToString(intNumbers); + + Assert.assertEquals(expectedOutput, string); + } + +} diff --git a/core-java-modules/core-java-string-algorithms-3/README.md b/core-java-modules/core-java-string-algorithms-3/README.md index 622730c834..d2863be8e5 100644 --- a/core-java-modules/core-java-string-algorithms-3/README.md +++ b/core-java-modules/core-java-string-algorithms-3/README.md @@ -9,3 +9,4 @@ This module contains articles about string-related algorithms. - [Email Validation in Java](https://www.baeldung.com/java-email-validation-regex) - [Check if the First Letter of a String is Uppercase](https://www.baeldung.com/java-check-first-letter-uppercase) - [Find the First Non Repeating Character in a String in Java](https://www.baeldung.com/java-find-the-first-non-repeating-character) +- [Find the First Embedded Occurrence of an Integer in a Java String](https://www.baeldung.com/java-string-find-embedded-integer) diff --git a/ddd/pom.xml b/ddd/pom.xml index 3beb43bb35..6128bb1cd9 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -59,8 +59,8 @@ runtime - mysql - mysql-connector-java + com.mysql + mysql-connector-j runtime diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml index ccf7a3c85e..ccaa802a39 100644 --- a/jhipster-5/bookstore-monolith/pom.xml +++ b/jhipster-5/bookstore-monolith/pom.xml @@ -94,10 +94,6 @@ org.apache.commons commons-lang3 - - mysql - mysql-connector-java - org.assertj assertj-core @@ -1175,7 +1171,7 @@ 2.1.1 - 2.0.8.RELEASE + 2.7.8 5.2.17.Final diff --git a/libraries-data-db/pom.xml b/libraries-data-db/pom.xml index 8e5140458e..6c72a4902c 100644 --- a/libraries-data-db/pom.xml +++ b/libraries-data-db/pom.xml @@ -127,8 +127,8 @@ - mysql - mysql-connector-java + com.mysql + mysql-connector-j diff --git a/messaging-modules/rabbitmq/README.md b/messaging-modules/rabbitmq/README.md index 6a74c297fc..93bb795d7b 100644 --- a/messaging-modules/rabbitmq/README.md +++ b/messaging-modules/rabbitmq/README.md @@ -7,5 +7,5 @@ This module contains articles about RabbitMQ. - [Exchanges, Queues, and Bindings in RabbitMQ](https://www.baeldung.com/java-rabbitmq-exchanges-queues-bindings) - [Pub-Sub vs. Message Queues](https://www.baeldung.com/pub-sub-vs-message-queues) - [Channels and Connections in RabbitMQ](https://www.baeldung.com/java-rabbitmq-channels-connections) - +- [Create Dynamic Queues in RabbitMQ](https://www.baeldung.com/rabbitmq-dynamic-queues) diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 115589b1b0..a1f16c4a64 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -24,6 +24,11 @@ pom import + + mysql + mysql-connector-java + ${mysql-connector-java.version} + org.springframework.boot spring-boot-dependencies @@ -89,8 +94,9 @@ 3.3.0 1.0.22.RELEASE - 2.7.5 + 2.7.8 1.9.1 + 8.0.31 \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-query-3/README.md b/persistence-modules/spring-data-jpa-query-3/README.md index f49bb19217..c0cc4f6511 100644 --- a/persistence-modules/spring-data-jpa-query-3/README.md +++ b/persistence-modules/spring-data-jpa-query-3/README.md @@ -7,6 +7,7 @@ This module contains articles about querying data using Spring Data JPA. - [JPA and Hibernate – Criteria vs. JPQL vs. HQL Query](https://www.baeldung.com/jpql-hql-criteria-query) - [Joining Tables With Spring Data JPA Specifications](https://www.baeldung.com/spring-jpa-joining-tables) - [NonUniqueResultException in Spring Data JPA](https://www.baeldung.com/spring-jpa-non-unique-result-exception) +- [Spring Data Repositories – Collections vs. Stream](https://www.baeldung.com/spring-data-collections-vs-stream) - More articles: [[<-- prev]](../spring-data-jpa-query-2) ### Eclipse Config diff --git a/persistence-modules/spring-data-jpa-repo-2/README.md b/persistence-modules/spring-data-jpa-repo-2/README.md index 6f19577606..23134ec02d 100644 --- a/persistence-modules/spring-data-jpa-repo-2/README.md +++ b/persistence-modules/spring-data-jpa-repo-2/README.md @@ -8,4 +8,5 @@ - [How to Access EntityManager with Spring Data](https://www.baeldung.com/spring-data-entitymanager) - [Difference Between JPA and Spring Data JPA](https://www.baeldung.com/spring-data-jpa-vs-jpa) - [Differences Between Spring Data JPA findFirst() and findTop()](https://www.baeldung.com/spring-data-jpa-findfirst-vs-findtop) +- [Difference Between findBy and findAllBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-find-by-vs-find-all-by) - More articles: [[<-- prev]](../spring-data-jpa-repo) diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index 22f7fb3d63..21d25915de 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -6,3 +6,4 @@ - [Using a List of Values in a JdbcTemplate IN Clause](https://www.baeldung.com/spring-jdbctemplate-in-list) - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Spring JDBC Batch Inserts](https://www.baeldung.com/spring-jdbc-batch-inserts) +- [Fix EmptyResultDataAccessException When Using JdbcTemplate](https://www.baeldung.com/jdbctemplate-fix-emptyresultdataaccessexception) diff --git a/quarkus-modules/quarkus-funqy/README.md b/quarkus-modules/quarkus-funqy/README.md new file mode 100644 index 0000000000..a97005bb00 --- /dev/null +++ b/quarkus-modules/quarkus-funqy/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Guide to Quarkus Funqy](https://www.baeldung.com/java-quarkus-funqy) diff --git a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml index 69e1dc3ab0..13508d7086 100644 --- a/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml +++ b/quarkus-modules/quarkus-vs-springboot/spring-project/pom.xml @@ -71,8 +71,8 @@ test - mysql - mysql-connector-java + com.mysql + mysql-connector-j test diff --git a/spring-boot-modules/spring-boot-3/README.md b/spring-boot-modules/spring-boot-3/README.md index ea30573163..0d79f006e1 100644 --- a/spring-boot-modules/spring-boot-3/README.md +++ b/spring-boot-modules/spring-boot-3/README.md @@ -2,3 +2,4 @@ ### Relevant Articles: - [Spring Boot 3 and Spring Framework 6.0 – What’s New](https://www.baeldung.com/spring-boot-3-spring-6-new) +- [Singleton Design Pattern vs Singleton Beans in Spring Boot](https://www.baeldung.com/spring-boot-singleton-vs-beans) diff --git a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml index ef5d4f66dd..7a3f9f01e8 100644 --- a/spring-boot-modules/spring-boot-autoconfiguration/pom.xml +++ b/spring-boot-modules/spring-boot-autoconfiguration/pom.xml @@ -38,8 +38,8 @@ test - mysql - mysql-connector-java + com.mysql + mysql-connector-j org.springframework.boot diff --git a/spring-boot-modules/spring-boot-bootstrap/pom.xml b/spring-boot-modules/spring-boot-bootstrap/pom.xml index efcfcb71ee..4ceae26f60 100644 --- a/spring-boot-modules/spring-boot-bootstrap/pom.xml +++ b/spring-boot-modules/spring-boot-bootstrap/pom.xml @@ -32,8 +32,8 @@ h2 - mysql - mysql-connector-java + com.mysql + mysql-connector-j org.springframework.boot diff --git a/spring-boot-modules/spring-boot-data-3/pom.xml b/spring-boot-modules/spring-boot-data-3/pom.xml index cac5016ebd..cf53c25697 100644 --- a/spring-boot-modules/spring-boot-data-3/pom.xml +++ b/spring-boot-modules/spring-boot-data-3/pom.xml @@ -25,8 +25,8 @@ spring-boot-starter-data-jpa - mysql - mysql-connector-java + com.mysql + mysql-connector-j runtime diff --git a/spring-boot-modules/spring-boot-mvc/pom.xml b/spring-boot-modules/spring-boot-mvc/pom.xml index 6d3f722146..d5ec7742c9 100644 --- a/spring-boot-modules/spring-boot-mvc/pom.xml +++ b/spring-boot-modules/spring-boot-mvc/pom.xml @@ -41,8 +41,8 @@ spring-boot-starter-data-rest - mysql - mysql-connector-java + com.mysql + mysql-connector-j org.hsqldb diff --git a/spring-boot-modules/spring-boot-swagger-2/pom.xml b/spring-boot-modules/spring-boot-swagger-2/pom.xml index 1cd8e5b850..d2d1d10ad9 100644 --- a/spring-boot-modules/spring-boot-swagger-2/pom.xml +++ b/spring-boot-modules/spring-boot-swagger-2/pom.xml @@ -20,6 +20,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-validation + org.springdoc springdoc-openapi-ui @@ -59,6 +63,7 @@ ${swagger-codegen-maven-plugin.version} + two-responses generate @@ -71,6 +76,59 @@ + + dates + + generate + + + ${project.basedir}/src/main/resources/static/event.yaml + spring + + true + custom + + + DateTime=Instant + Date=Date + + + Instant=java.time.Instant + Date=java.util.Date + + + + + + + org.openapitools + openapi-generator-maven-plugin + ${openapi-generator.version} + + + + generate + + + true + ${project.basedir}/src/main/resources/static/event.yaml + spring + + true + custom + false + true + + + DateTime=Instant + Date=Date + + + Instant=java.time.Instant + Date=java.util.Date + + + @@ -84,6 +142,7 @@ + 6.2.1 3.0.0 3.0.34 1.6.10 diff --git a/spring-boot-modules/spring-boot-swagger-2/src/main/resources/static/event.yaml b/spring-boot-modules/spring-boot-swagger-2/src/main/resources/static/event.yaml new file mode 100644 index 0000000000..f8a7b01b43 --- /dev/null +++ b/spring-boot-modules/spring-boot-swagger-2/src/main/resources/static/event.yaml @@ -0,0 +1,23 @@ +openapi: 3.0.0 +info: + title: an example api with dates + version: 0.1.0 +paths: +components: + schemas: + Event: + type: object + properties: + organizer: + type: string + startDate: + type: string + format: date + endDate: + type: string + format: date-time + ticketSales: + type: string + description: Beginning of the ticket sales + example: "01-01-2023" + pattern: "[0-9]{2}-[0-9]{2}-[0-9]{4}" \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-swagger-2/src/test/java/com/baeldung/dates/EventUnitTest.java b/spring-boot-modules/spring-boot-swagger-2/src/test/java/com/baeldung/dates/EventUnitTest.java new file mode 100644 index 0000000000..378882c964 --- /dev/null +++ b/spring-boot-modules/spring-boot-swagger-2/src/test/java/com/baeldung/dates/EventUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.dates; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.Set; + +import javax.validation.ConstraintViolation; +import javax.validation.Validation; +import javax.validation.Validator; + +import org.junit.jupiter.api.Test; + +import io.swagger.model.Event; + +class EventUnitTest { + + private static final Validator VALIDATOR = Validation.buildDefaultValidatorFactory() + .getValidator(); + + @Test + void givenACorrectlyFormattedTicketSales_WhenBuildingEvent_ThenSuccess() { + Set> violations = VALIDATOR.validate(new Event().ticketSales("01-01-2024")); + assertTrue(violations.isEmpty()); + } + + @Test + void givenAWronglyFormattedTicketSales_WhenBuildingEvent_ThenSuccess() { + Set> violations = VALIDATOR.validate(new Event().ticketSales("2024-01-01")); + assertEquals(1, violations.size()); + } + +} diff --git a/spring-core-2/pom.xml b/spring-core-2/pom.xml index 719bf56e0b..3cd9adf451 100644 --- a/spring-core-2/pom.xml +++ b/spring-core-2/pom.xml @@ -92,8 +92,8 @@ ${javassist.version} - mysql - mysql-connector-java + com.mysql + mysql-connector-j runtime diff --git a/spring-core-6/README.md b/spring-core-6/README.md index 90e2dfed01..e10db19a54 100644 --- a/spring-core-6/README.md +++ b/spring-core-6/README.md @@ -4,3 +4,4 @@ - [Using Environment Variables in Spring Boot’s application.properties](https://www.baeldung.com/spring-boot-properties-env-variables) - [Reinitialize Singleton Bean in Spring Context](https://www.baeldung.com/spring-reinitialize-singleton-bean) - [HTTP Interface in Spring 6](https://www.baeldung.com/spring-6-http-interface) +- [Getting the Current ApplicationContext in Spring](https://www.baeldung.com/spring-get-current-applicationcontext) diff --git a/spring-web-modules/spring-resttemplate-3/README.md b/spring-web-modules/spring-resttemplate-3/README.md index 3add0073b2..1944221138 100644 --- a/spring-web-modules/spring-resttemplate-3/README.md +++ b/spring-web-modules/spring-resttemplate-3/README.md @@ -11,4 +11,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Download a Large File Through a Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-download-large-file) - [Access HTTPS REST Service Using Spring RestTemplate](https://www.baeldung.com/spring-resttemplate-secure-https-service) - [Encoding of URI Variables on RestTemplate](https://www.baeldung.com/spring-resttemplate-uri-variables-encode) -- [Difference Between exchange(), postForEntity() and execute() in RestTemplate](https://www.baeldung.com/difference-between-exchange-postForEntity-and-execute) +- [Difference Between exchange(), postForEntity() and execute() in RestTemplate](https://www.baeldung.com/spring-resttemplate-exchange-postforentity-execute) diff --git a/testing-modules/junit5-annotations/README.md b/testing-modules/junit5-annotations/README.md index 6fd524592b..49d596607c 100644 --- a/testing-modules/junit5-annotations/README.md +++ b/testing-modules/junit5-annotations/README.md @@ -8,3 +8,4 @@ This module contains articles about JUnit 5 Annotations - [JUnit5 Programmatic Extension Registration with @RegisterExtension](https://www.baeldung.com/junit-5-registerextension-annotation) - [Guide to JUnit 5 Parameterized Tests](https://www.baeldung.com/parameterized-tests-junit-5) - [Writing Templates for Test Cases Using JUnit 5](https://www.baeldung.com/junit5-test-templates) +- [JUnit 5 @Nested Test Classes](https://www.baeldung.com/junit-5-nested-test-classes)