From 812057b43cad1b07aa2133898e608cd04b8048ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer?= <59844362+omertopuz@users.noreply.github.com> Date: Sat, 5 Jun 2021 23:04:19 +0300 Subject: [PATCH 001/148] Update Graph.java for dfsWithoutRecursion, when a node popped from the stack it should be checked that the current node is visited or not. Since stack has duplicated nodes, some nodes is visired doubly. --- .../main/java/com/baeldung/algorithms/dfs/Graph.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java index d2cc723cf9..4623dbb7a4 100644 --- a/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java +++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/dfs/Graph.java @@ -29,11 +29,13 @@ public class Graph { stack.push(start); while (!stack.isEmpty()) { int current = stack.pop(); - isVisited[current] = true; - visit(current); - for (int dest : adjVertices.get(current)) { - if (!isVisited[dest]) - stack.push(dest); + if(!isVisited[current]){ + isVisited[current] = true; + visit(current); + for (int dest : adjVertices.get(current)) { + if (!isVisited[dest]) + stack.push(dest); + } } } } From b9fd869c02184d81ae695e7138935fa7da492bfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Goossens?= Date: Thu, 15 Jul 2021 23:26:49 +0200 Subject: [PATCH 002/148] Also consider string interpolation The above example only works when logging a string without using string interpolation. For example the following log statement: log.debug("This is a log from {}", "David"). This would result in event.getMessage() returning "This is a log from {}" while you would like to see the processed form "This is a log from David". The getMessage().toString() only returns the former while toString() on the event will return the latter. Furthermore the toString() method is redundant on getMessage() as it already is a string. --- .../test/java/com/baeldung/junit/log/MemoryAppender.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testing-modules/testing-assertions/src/test/java/com/baeldung/junit/log/MemoryAppender.java b/testing-modules/testing-assertions/src/test/java/com/baeldung/junit/log/MemoryAppender.java index 31c5c69766..95b41e02a5 100644 --- a/testing-modules/testing-assertions/src/test/java/com/baeldung/junit/log/MemoryAppender.java +++ b/testing-modules/testing-assertions/src/test/java/com/baeldung/junit/log/MemoryAppender.java @@ -19,7 +19,7 @@ public class MemoryAppender extends ListAppender { public boolean contains(String string, Level level) { return this.list.stream() - .anyMatch(event -> event.getMessage().toString().contains(string) + .anyMatch(event -> event.toString().contains(string) && event.getLevel().equals(level)); } @@ -30,13 +30,13 @@ public class MemoryAppender extends ListAppender { public List search(String string) { return this.list.stream() - .filter(event -> event.getMessage().toString().contains(string)) + .filter(event -> event.toString().contains(string)) .collect(Collectors.toList()); } public List search(String string, Level level) { return this.list.stream() - .filter(event -> event.getMessage().toString().contains(string) + .filter(event -> event.toString().contains(string) && event.getLevel().equals(level)) .collect(Collectors.toList()); } From a61d1c3efba8dce11aa07e57d2f9ef1fce28ba81 Mon Sep 17 00:00:00 2001 From: Thomas Duxbury Date: Sun, 18 Jul 2021 14:25:34 +0100 Subject: [PATCH 003/148] BAEL-4797: Default Values for Maven Properties --- maven-modules/maven-properties/pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/maven-modules/maven-properties/pom.xml b/maven-modules/maven-properties/pom.xml index 2cd92da42f..9454664c3f 100644 --- a/maven-modules/maven-properties/pom.xml +++ b/maven-modules/maven-properties/pom.xml @@ -13,12 +13,12 @@ 1.0.0-SNAPSHOT ../.. - + junit junit - 4.13 + ${junit.version} @@ -46,6 +46,7 @@ ${project.name} property-from-pom + 4.13 - \ No newline at end of file + From a20b32c41313210258b1e4870bf462213152983c Mon Sep 17 00:00:00 2001 From: rmkellogg Date: Tue, 27 Jul 2021 15:30:33 -0400 Subject: [PATCH 004/148] Added comments on settings. --- .../src/main/resources/application.properties | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-security-modules/spring-security-saml/src/main/resources/application.properties b/spring-security-modules/spring-security-saml/src/main/resources/application.properties index f9d6a5df3c..1d93a12737 100644 --- a/spring-security-modules/spring-security-saml/src/main/resources/application.properties +++ b/spring-security-modules/spring-security-saml/src/main/resources/application.properties @@ -1,6 +1,8 @@ saml.keystore.location=classpath:/saml/samlKeystore.jks +# Password for Java keystore and item therein saml.keystore.password= saml.keystore.alias= +# SAML Entity ID extracted from top of SAML metadata file saml.idp= saml.sp=http://localhost:8080/saml/metadata \ No newline at end of file From 9c3bf05bb32be6828ee15cbe10eebce53c1aedbb Mon Sep 17 00:00:00 2001 From: rmkellogg Date: Tue, 27 Jul 2021 15:32:47 -0400 Subject: [PATCH 005/148] Correction to allow execution outside of Eclipse. --- .../main/java/com/baeldung/saml/config/SamlSecurityConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java index 378db478cf..8bc97cb81e 100644 --- a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java +++ b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java @@ -143,7 +143,7 @@ public class SamlSecurityConfig { public ExtendedMetadataDelegate oktaExtendedMetadataProvider() throws MetadataProviderException { File metadata = null; try { - metadata = new File("./src/main/resources/saml/metadata/sso.xml"); + metadata = new ClassPathResource("saml/metadata/sso.xml").getFile(); } catch (Exception e) { e.printStackTrace(); } From 404c05ad321838450de24285392d3e47c238aaee Mon Sep 17 00:00:00 2001 From: rmkellogg Date: Tue, 27 Jul 2021 15:39:59 -0400 Subject: [PATCH 006/148] Added missing import. --- .../main/java/com/baeldung/saml/config/SamlSecurityConfig.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java index 8bc97cb81e..7c6f5defdf 100644 --- a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java +++ b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.security.saml.*; From 30329073cd5e689305471115b3a0cfae4b7fa0a6 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Wed, 28 Jul 2021 18:21:44 +0300 Subject: [PATCH 007/148] JAVA-2802 update article links --- persistence-modules/spring-data-mongodb-reactive/README.md | 2 -- spring-5-data-reactive/README.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/persistence-modules/spring-data-mongodb-reactive/README.md b/persistence-modules/spring-data-mongodb-reactive/README.md index 0931161700..4fbdb87785 100644 --- a/persistence-modules/spring-data-mongodb-reactive/README.md +++ b/persistence-modules/spring-data-mongodb-reactive/README.md @@ -8,5 +8,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles - [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive) - [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors) -- [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) -- [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) diff --git a/spring-5-data-reactive/README.md b/spring-5-data-reactive/README.md index 0931161700..ecb6d01267 100644 --- a/spring-5-data-reactive/README.md +++ b/spring-5-data-reactive/README.md @@ -6,7 +6,5 @@ This module contains articles about reactive Spring 5 Data The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles -- [Spring Data Reactive Repositories with MongoDB](https://www.baeldung.com/spring-data-mongodb-reactive) -- [Spring Data MongoDB Tailable Cursors](https://www.baeldung.com/spring-data-mongodb-tailable-cursors) - [A Quick Look at R2DBC with Spring Data](https://www.baeldung.com/spring-data-r2dbc) - [Spring Data Reactive Repositories with Couchbase](https://www.baeldung.com/spring-data-reactive-couchbase) From 93637134e9ac0cc8d84eafd02465779b444d6324 Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sun, 1 Aug 2021 23:56:06 +0700 Subject: [PATCH 008/148] BAEL-4883 Exception handling in Project Reactor --- .../reactor/exception/ExceptionUnitTest.java | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java diff --git a/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java b/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java new file mode 100644 index 0000000000..f4da2e325a --- /dev/null +++ b/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java @@ -0,0 +1,89 @@ +package com.baeldung.reactor.exception; + +import org.junit.Test; +import org.reactivestreams.Publisher; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import reactor.core.publisher.SynchronousSink; +import reactor.test.StepVerifier; + +import java.util.function.BiConsumer; +import java.util.function.Function; + +public class ExceptionUnitTest { + @Test + public void givenInputStreamWithAnInvalidElement_whenAPipelineOperatorThrowsAnException_thenAnErrorIsSentDownstream() { + Function mapper = input -> { + if (input.matches("\\D")) { + throw new NumberFormatException(); + } else { + return Integer.parseInt(input); + } + }; + + Flux inFlux = Flux.just("1", "1.5", "2"); + Flux outFlux = inFlux.map(mapper); + + StepVerifier.create(outFlux) + .expectNext(1) + .expectError(NumberFormatException.class) + .verify(); + } + + @Test + public void givenInputStreamWithAnInvalidElement_whenTheHandleOperatorCallsSinkErrorMethod_thenAnErrorIsSentDownstream() { + BiConsumer> handler = (input, sink) -> { + if (input.matches("\\D")) { + sink.error(new NumberFormatException()); + } else { + sink.next(Integer.parseInt(input)); + } + }; + + Flux inFlux = Flux.just("1", "1.5", "2"); + Flux outFlux = inFlux.handle(handler); + + StepVerifier.create(outFlux) + .expectNext(1) + .expectError(NumberFormatException.class) + .verify(); + } + + @Test + public void givenInputStreamWithAnInvalidElement_whenTheFlatMapOperatorCallsMonoErrorMethod_thenAnErrorIsSentDownstream() { + Function> mapper = input -> { + if (input.matches("\\D")) { + return Mono.error(new NumberFormatException()); + } else { + return Mono.just(Integer.parseInt(input)); + } + }; + + Flux inFlux = Flux.just("1", "1.5", "2"); + Flux outFlux = inFlux.flatMap(mapper); + + StepVerifier.create(outFlux) + .expectNext(1) + .expectError(NumberFormatException.class) + .verify(); + } + + @Test + public void givenInputStreamWithANullElement_whenAPipelineOperatorIsCalled_thenAnNpeIsSentDownstream() { + Function mapper = input -> { + if (input == null) { + return 0; + } else { + return Integer.parseInt(input); + } + }; + + Flux inFlux = Flux.just("1", null, "2"); + Flux outFlux = inFlux.map(mapper); + + StepVerifier.create(outFlux) + .expectNext(1) + .expectError(NullPointerException.class) + .verify(); + } +} From dddf541bb863d75d02f456b9bcdcb8d7dbff2ee1 Mon Sep 17 00:00:00 2001 From: rmkellogg Date: Mon, 2 Aug 2021 16:05:00 -0400 Subject: [PATCH 009/148] Revised to use built in Sprint Security SAML resource resolution. Otherwise when used from Spring Boot self-contained JAR the File could not be located. --- .../saml/config/SamlSecurityConfig.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java index 7c6f5defdf..10e37b346f 100644 --- a/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java +++ b/spring-security-modules/spring-security-saml/src/main/java/com/baeldung/saml/config/SamlSecurityConfig.java @@ -5,17 +5,19 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Timer; import org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider; import org.opensaml.saml2.metadata.provider.MetadataProvider; import org.opensaml.saml2.metadata.provider.MetadataProviderException; +import org.opensaml.saml2.metadata.provider.ResourceBackedMetadataProvider; +import org.opensaml.util.resource.ClasspathResource; import org.opensaml.util.resource.ResourceException; import org.opensaml.xml.parse.StaticBasicParserPool; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.security.saml.*; @@ -142,13 +144,19 @@ public class SamlSecurityConfig { @Bean @Qualifier("okta") public ExtendedMetadataDelegate oktaExtendedMetadataProvider() throws MetadataProviderException { - File metadata = null; - try { - metadata = new ClassPathResource("saml/metadata/sso.xml").getFile(); - } catch (Exception e) { - e.printStackTrace(); - } - FilesystemMetadataProvider provider = new FilesystemMetadataProvider(metadata); + // Use the Spring Security SAML resource mechanism to load + // metadata from the Java classpath. This works from Spring Boot + // self contained JAR file. + org.opensaml.util.resource.Resource resource = null; + + try { + resource = new ClasspathResource("/saml/metadata/sso.xml"); + } catch (ResourceException e) { + e.printStackTrace(); + } + + Timer timer = new Timer("saml-metadata"); + ResourceBackedMetadataProvider provider = new ResourceBackedMetadataProvider(timer,resource); provider.setParserPool(parserPool()); return new ExtendedMetadataDelegate(provider, extendedMetadata()); } From dcf8b902dcfe260193e82bd08d2593e1d11e133e Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 7 Aug 2021 12:33:12 +0530 Subject: [PATCH 010/148] Update pom.xml --- core-java-modules/core-java-string-algorithms-3/pom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index c8243258c1..6d1c0b0e48 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -32,6 +32,11 @@ junit-jupiter test + + commons-validator + commons-validator + ${validator.version} + @@ -59,6 +64,7 @@ 3.6.1 28.1-jre + 1.7 - \ No newline at end of file + From 6b7dcdf847e0b7875f97c5b80760d2d6ba36c70c Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 7 Aug 2021 12:34:38 +0530 Subject: [PATCH 011/148] Add files via upload --- .../emailvalidation/EmailValidation.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java diff --git a/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java new file mode 100644 index 0000000000..97d1b90ff3 --- /dev/null +++ b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java @@ -0,0 +1,64 @@ +package com.baeldung.emailvalidation; + +import java.util.regex.Pattern; + +public class EmailValidation { + + private static String regexPattern; + + public static boolean usingSimpleRegex(String emailAddress) { + regexPattern = "^(.+)@(\\S+)$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean usingStrictRegex(String emailAddress) { + regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@" + "[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean usingUnicodeRegex(String emailAddress) { + regexPattern = "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@" + "[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean usingRFC5322Regex(String emailAddress) { + regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean restrictDots(String emailAddress) { + regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@" + "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean owaspValidation(String emailAddress) { + regexPattern = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } + + public static boolean topLevelDomain(String emailAddress) { + regexPattern = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*" + "@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$"; + + return Pattern.compile(regexPattern) + .matcher(emailAddress) + .matches(); + } +} \ No newline at end of file From 0d22a1fdeea1cdd70c9fbac829d514dbb586cd49 Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Sat, 7 Aug 2021 12:38:09 +0530 Subject: [PATCH 012/148] Add files via upload --- .../EmailValidationUnitTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java diff --git a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java new file mode 100644 index 0000000000..3b2b77fc4a --- /dev/null +++ b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java @@ -0,0 +1,59 @@ +package com.baeldung.emailvalidation; + +import static org.junit.Assert.assertEquals; +import org.apache.commons.validator.routines.EmailValidator; +import org.junit.Test; + +public class EmailValidationUnitTest { + + private String emailAddress; + + @Test + public void testUsingEmailValidator() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidator.getInstance() + .isValid(emailAddress), true); + } + + @Test + public void testUsingSimpleRegex() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.usingSimpleRegex(emailAddress), true); + } + + @Test + public void testUsingStrictRegex() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.usingStrictRegex(emailAddress), true); + } + + @Test + public void testUsingUnicodeRegex() { + emailAddress = "用户名@领域.电脑"; + assertEquals(EmailValidation.usingUnicodeRegex(emailAddress), true); + } + + @Test + public void testUsingRFC5322Regex() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.usingRFC5322Regex(emailAddress), true); + } + + @Test + public void testRestrictDots() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.restrictDots(emailAddress), true); + } + + @Test + public void testOwaspValidation() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.owaspValidation(emailAddress), true); + } + + @Test + public void testTopLevelDomain() { + emailAddress = "username@domain.com"; + assertEquals(EmailValidation.topLevelDomain(emailAddress), true); + } +} \ No newline at end of file From 75e9acc874ef3a54b0c590080af95b7b2874b774 Mon Sep 17 00:00:00 2001 From: Trixi Turny Date: Sun, 1 Aug 2021 14:26:57 +0100 Subject: [PATCH 013/148] BAEL-5054 2 examples of file upload with webclient --- webclient_upload/pom.xml | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 webclient_upload/pom.xml diff --git a/webclient_upload/pom.xml b/webclient_upload/pom.xml new file mode 100644 index 0000000000..69f7f78cd1 --- /dev/null +++ b/webclient_upload/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + com.baeldung + webclient_upload + 1.0-SNAPSHOT + jar + + + + org.springframework.boot + spring-boot-starter-parent + 2.5.0 + + + webclient_upload Maven Webapp + + 16 + 1.0.1.RELEASE + + + + + + + org.projectreactor + reactor-spring + ${reactor-spring.version} + + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + org.projectreactor + reactor-spring + + + org.springframework.boot + spring-boot-starter-test + test + + + io.rest-assured + json-schema-validator + test + + + org.springframework.boot + spring-boot-starter-web + + + + + From 58b12b04f20123623bc59db95629f3c58ba3837e Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Thu, 12 Aug 2021 12:46:15 +0700 Subject: [PATCH 014/148] BAEL-4883 Update Reactor version --- reactor-core/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reactor-core/pom.xml b/reactor-core/pom.xml index 6bd725b3b5..c13dda63d5 100644 --- a/reactor-core/pom.xml +++ b/reactor-core/pom.xml @@ -41,8 +41,8 @@ - 3.3.9.RELEASE + 3.4.9 3.6.1 - \ No newline at end of file + From ab3fc12268f9367a94226ac920507afac0d6eb4f Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Sun, 15 Aug 2021 23:03:32 +0700 Subject: [PATCH 015/148] BAEL-4883 Shorten test method names --- .../com/baeldung/reactor/exception/ExceptionUnitTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java b/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java index f4da2e325a..d1d2b3c4d6 100644 --- a/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java +++ b/reactor-core/src/test/java/com/baeldung/reactor/exception/ExceptionUnitTest.java @@ -12,7 +12,7 @@ import java.util.function.Function; public class ExceptionUnitTest { @Test - public void givenInputStreamWithAnInvalidElement_whenAPipelineOperatorThrowsAnException_thenAnErrorIsSentDownstream() { + public void givenInvalidElement_whenPipelineThrowsException_thenErrorIsSentDownstream() { Function mapper = input -> { if (input.matches("\\D")) { throw new NumberFormatException(); @@ -31,7 +31,7 @@ public class ExceptionUnitTest { } @Test - public void givenInputStreamWithAnInvalidElement_whenTheHandleOperatorCallsSinkErrorMethod_thenAnErrorIsSentDownstream() { + public void givenInvalidElement_whenHandleCallsSinkErrorMethod_thenErrorIsSentDownstream() { BiConsumer> handler = (input, sink) -> { if (input.matches("\\D")) { sink.error(new NumberFormatException()); @@ -50,7 +50,7 @@ public class ExceptionUnitTest { } @Test - public void givenInputStreamWithAnInvalidElement_whenTheFlatMapOperatorCallsMonoErrorMethod_thenAnErrorIsSentDownstream() { + public void givenInvalidElement_whenFlatMapCallsMonoErrorMethod_thenErrorIsSentDownstream() { Function> mapper = input -> { if (input.matches("\\D")) { return Mono.error(new NumberFormatException()); @@ -69,7 +69,7 @@ public class ExceptionUnitTest { } @Test - public void givenInputStreamWithANullElement_whenAPipelineOperatorIsCalled_thenAnNpeIsSentDownstream() { + public void givenNullElement_whenPipelineOperatorExecutes_thenNpeIsSentDownstream() { Function mapper = input -> { if (input == null) { return 0; From 6d75bb0cc1751ccc2d35b2b2f4347909c6461cfa Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:50:58 +0530 Subject: [PATCH 016/148] Update EmailValidation.java --- .../emailvalidation/EmailValidation.java | 56 +------------------ 1 file changed, 2 insertions(+), 54 deletions(-) diff --git a/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java index 97d1b90ff3..4d68ea9c55 100644 --- a/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java +++ b/core-java-modules/core-java-string-algorithms-3/src/main/java/com/baeldung/emailvalidation/EmailValidation.java @@ -4,61 +4,9 @@ import java.util.regex.Pattern; public class EmailValidation { - private static String regexPattern; - - public static boolean usingSimpleRegex(String emailAddress) { - regexPattern = "^(.+)@(\\S+)$"; - + public static boolean patternMatcher(String emailAddress, String regexPattern) { return Pattern.compile(regexPattern) .matcher(emailAddress) .matches(); } - - public static boolean usingStrictRegex(String emailAddress) { - regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@" + "[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } - - public static boolean usingUnicodeRegex(String emailAddress) { - regexPattern = "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@" + "[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } - - public static boolean usingRFC5322Regex(String emailAddress) { - regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } - - public static boolean restrictDots(String emailAddress) { - regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@" + "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } - - public static boolean owaspValidation(String emailAddress) { - regexPattern = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } - - public static boolean topLevelDomain(String emailAddress) { - regexPattern = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*" + "@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$"; - - return Pattern.compile(regexPattern) - .matcher(emailAddress) - .matches(); - } -} \ No newline at end of file +} From e817cffca0bd9c33b132e45636746bc2f2782054 Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:51:31 +0530 Subject: [PATCH 017/148] Update EmailValidationUnitTest.java --- .../EmailValidationUnitTest.java | 35 +++++++++++++------ 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java index 3b2b77fc4a..b387cc9dc5 100644 --- a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java +++ b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java @@ -1,59 +1,72 @@ package com.baeldung.emailvalidation; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import org.apache.commons.validator.routines.EmailValidator; import org.junit.Test; public class EmailValidationUnitTest { private String emailAddress; + private String regexPattern; @Test public void testUsingEmailValidator() { emailAddress = "username@domain.com"; - assertEquals(EmailValidator.getInstance() - .isValid(emailAddress), true); + assertTrue(EmailValidator.getInstance() + .isValid(emailAddress)); } @Test public void testUsingSimpleRegex() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.usingSimpleRegex(emailAddress), true); + regexPattern = "^(.+)@(\\S+)$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testUsingStrictRegex() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.usingStrictRegex(emailAddress), true); + regexPattern = "^(?=.{1,64}@)[A-Za-z0-9_-]+(\\.[A-Za-z0-9_-]+)*@" + + "[^-][A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,})$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testUsingUnicodeRegex() { emailAddress = "用户名@领域.电脑"; - assertEquals(EmailValidation.usingUnicodeRegex(emailAddress), true); + regexPattern = "^(?=.{1,64}@)[\\p{L}0-9_-]+(\\.[\\p{L}0-9_-]+)*@" + + "[^-][\\p{L}0-9-]+(\\.[\\p{L}0-9-]+)*(\\.[\\p{L}]{2,})$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testUsingRFC5322Regex() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.usingRFC5322Regex(emailAddress), true); + regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^.-]+@[a-zA-Z0-9.-]+$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testRestrictDots() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.restrictDots(emailAddress), true); + regexPattern = "^[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+(?:\\.[a-zA-Z0-9_!#$%&'*+/=?`{|}~^-]+)*@" + + "[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testOwaspValidation() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.owaspValidation(emailAddress), true); + regexPattern = "^[a-zA-Z0-9_+&*-]+(?:\\.[a-zA-Z0-9_+&*-]+)*@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,7}$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } @Test public void testTopLevelDomain() { emailAddress = "username@domain.com"; - assertEquals(EmailValidation.topLevelDomain(emailAddress), true); + regexPattern = "^[\\w!#$%&'*+/=?`{|}~^-]+(?:\\.[\\w!#$%&'*+/=?`{|}~^-]+)*" + + "@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}$"; + assertTrue(EmailValidation.patternMatcher(emailAddress, regexPattern)); } -} \ No newline at end of file +} From 7caefe62b70c637fd4c933c5ce5a89b51926c6c5 Mon Sep 17 00:00:00 2001 From: Ashish Gupta <30566001+gupta-ashu01@users.noreply.github.com> Date: Mon, 16 Aug 2021 11:58:55 +0530 Subject: [PATCH 018/148] Update EmailValidationUnitTest.java --- .../com/baeldung/emailvalidation/EmailValidationUnitTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java index b387cc9dc5..c49690289a 100644 --- a/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java +++ b/core-java-modules/core-java-string-algorithms-3/src/test/java/com/baeldung/emailvalidation/EmailValidationUnitTest.java @@ -1,7 +1,6 @@ package com.baeldung.emailvalidation; import static org.junit.Assert.assertTrue; - import org.apache.commons.validator.routines.EmailValidator; import org.junit.Test; From 1d2d3e9e759b997b1407d11a7281223c22c679c5 Mon Sep 17 00:00:00 2001 From: majewsk6 Date: Fri, 20 Aug 2021 12:23:01 +0200 Subject: [PATCH 019/148] BAEL-5009 - fix test name --- ...itoryIntegrationTest.java => ArticleRepositoryLiveTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/{ArticleRepositoryIntegrationTest.java => ArticleRepositoryLiveTest.java} (98%) diff --git a/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java b/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java similarity index 98% rename from persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java rename to persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java index 1d4258688a..9d0aa5e6f5 100644 --- a/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java @@ -17,7 +17,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @SpringBootTest -public class ArticleRepositoryIntegrationTest { +public class ArticleRepositoryLiveTest { @Autowired ArticleRepository articleRepository; From b6a5974f856fd550c018384c84a33dec9cacb828 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 21 Aug 2021 14:14:24 +0530 Subject: [PATCH 020/148] JAVA-3247 Reduce logging of tutorials-integration job --- .../algorithms/astar/RouteFinder.java | 13 +- .../RouteFinderIntegrationTest.java | 9 +- drools/src/main/resources/logback.xml | 3 +- .../server/config/HelloDynamicBinding.java | 6 - .../JMapperRelationalIntegrationTest.java | 6 - .../LazyCollectionIntegrationTest.java | 7 +- .../src/test/resources/log4j.xml | 11 +- .../src/test/resources/log4j2.xml | 6 +- .../src/test/resources/logback.xml | 6 +- .../test/resources/META-INF/persistence.xml | 212 ++++++++++++++++++ .../test/resources/META-INF/persistence.xml | 152 +++++++++++++ .../java-jpa-3/src/test/resources/logback.xml | 15 ++ persistence-modules/java-jpa/README.md | 2 +- ...lication-lazy-load-no-trans-off.properties | 2 +- ...plication-lazy-load-no-trans-on.properties | 2 +- .../application/entities/User.java | 9 + .../src/test/resources/application.properties | 2 +- ...st.java => ArticleRepositoryLiveTest.java} | 5 +- 18 files changed, 427 insertions(+), 41 deletions(-) create mode 100644 persistence-modules/java-jpa-2/src/test/resources/META-INF/persistence.xml create mode 100644 persistence-modules/java-jpa-3/src/test/resources/META-INF/persistence.xml create mode 100644 persistence-modules/java-jpa-3/src/test/resources/logback.xml rename persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/{ArticleRepositoryIntegrationTest.java => ArticleRepositoryLiveTest.java} (96%) diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/RouteFinder.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/RouteFinder.java index 35458093c5..f8b66fec88 100644 --- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/RouteFinder.java +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/RouteFinder.java @@ -8,6 +8,9 @@ import java.util.PriorityQueue; import java.util.Queue; import java.util.stream.Collectors; +import lombok.extern.slf4j.Slf4j; + +@Slf4j public class RouteFinder { private final Graph graph; private final Scorer nextNodeScorer; @@ -28,11 +31,11 @@ public class RouteFinder { openSet.add(start); while (!openSet.isEmpty()) { - System.out.println("Open Set contains: " + openSet.stream().map(RouteNode::getCurrent).collect(Collectors.toSet())); + log.debug("Open Set contains: " + openSet.stream().map(RouteNode::getCurrent).collect(Collectors.toSet())); RouteNode next = openSet.poll(); - System.out.println("Looking at node: " + next); + log.debug("Looking at node: " + next); if (next.getCurrent().equals(to)) { - System.out.println("Found our destination!"); + log.debug("Found our destination!"); List route = new ArrayList<>(); RouteNode current = next; @@ -41,7 +44,7 @@ public class RouteFinder { current = allNodes.get(current.getPrevious()); } while (current != null); - System.out.println("Route: " + route); + log.debug("Route: " + route); return route; } @@ -55,7 +58,7 @@ public class RouteFinder { nextNode.setRouteScore(newScore); nextNode.setEstimatedScore(newScore + targetScorer.computeCost(connection, to)); openSet.add(nextNode); - System.out.println("Found a better route to node: " + nextNode); + log.debug("Found a better route to node: " + nextNode); } }); } diff --git a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/underground/RouteFinderIntegrationTest.java b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/underground/RouteFinderIntegrationTest.java index 1e4ad56d94..aba7f149da 100644 --- a/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/underground/RouteFinderIntegrationTest.java +++ b/algorithms-miscellaneous-2/src/test/java/com/baeldung/algorithms/astar/underground/RouteFinderIntegrationTest.java @@ -1,5 +1,7 @@ package com.baeldung.algorithms.astar.underground; +import static org.assertj.core.api.Assertions.assertThat; + import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -10,9 +12,13 @@ import java.util.stream.Stream; import com.baeldung.algorithms.astar.Graph; import com.baeldung.algorithms.astar.RouteFinder; + +import lombok.extern.slf4j.Slf4j; + import org.junit.Before; import org.junit.Test; +@Slf4j public class RouteFinderIntegrationTest { private Graph underground; @@ -637,7 +643,8 @@ public class RouteFinderIntegrationTest { @Test public void findRoute() { List route = routeFinder.findRoute(underground.getNode("74"), underground.getNode("7")); + assertThat(route).size().isPositive(); - System.out.println(route.stream().map(Station::getName).collect(Collectors.toList())); + route.stream().map(Station::getName).collect(Collectors.toList()).forEach(station -> log.debug(station)); } } diff --git a/drools/src/main/resources/logback.xml b/drools/src/main/resources/logback.xml index 7d900d8ea8..b928039804 100644 --- a/drools/src/main/resources/logback.xml +++ b/drools/src/main/resources/logback.xml @@ -6,7 +6,8 @@ - + + diff --git a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java index e56cdec140..19c407f80d 100644 --- a/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java +++ b/jersey/src/main/java/com/baeldung/jersey/server/config/HelloDynamicBinding.java @@ -5,20 +5,14 @@ import javax.ws.rs.container.ResourceInfo; import javax.ws.rs.core.FeatureContext; import javax.ws.rs.ext.Provider; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.baeldung.jersey.server.Greetings; import com.baeldung.jersey.server.filter.ResponseServerFilter; @Provider public class HelloDynamicBinding implements DynamicFeature { - private static final Logger LOG = LoggerFactory.getLogger(HelloDynamicBinding.class); - @Override public void configure(ResourceInfo resourceInfo, FeatureContext context) { - LOG.info("Hello dynamic binding"); if (Greetings.class.equals(resourceInfo.getResourceClass()) && resourceInfo.getResourceMethod() .getName() diff --git a/libraries-data/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java index 7a497c4a83..15a16e22da 100644 --- a/libraries-data/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java +++ b/libraries-data/src/test/java/com/baeldung/jmapper/JMapperRelationalIntegrationTest.java @@ -22,8 +22,6 @@ public class JMapperRelationalIntegrationTest { UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); UserDto2 result2= relationalMapper.oneToMany(UserDto2.class, user); - System.out.println(result1); - System.out.println(result2); assertEquals(user.getId(), result1.getId()); assertEquals(user.getEmail(), result1.getUsername()); assertEquals(user.getId(), result2.getId()); @@ -40,8 +38,6 @@ public class JMapperRelationalIntegrationTest { UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); UserDto2 result2 = relationalMapper.oneToMany(UserDto2.class, user); - System.out.println(result1); - System.out.println(result2); assertEquals(user.getId(), result1.getId()); assertEquals(user.getEmail(), result1.getUsername()); assertEquals(user.getId(), result2.getId()); @@ -64,8 +60,6 @@ public class JMapperRelationalIntegrationTest { UserDto1 result1 = relationalMapper.oneToMany(UserDto1.class, user); UserDto2 result2 = relationalMapper.oneToMany(UserDto2.class, user); - System.out.println(result1); - System.out.println(result2); assertEquals(user.getId(), result1.getId()); assertEquals(user.getEmail(), result1.getUsername()); assertEquals(user.getId(), result2.getId()); diff --git a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java index 97888471a4..dd86820c03 100644 --- a/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java +++ b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/lazycollection/LazyCollectionIntegrationTest.java @@ -1,7 +1,5 @@ package com.baeldung.hibernate.lazycollection; -import com.baeldung.hibernate.lazycollection.model.Branch; -import com.baeldung.hibernate.lazycollection.model.Employee; import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.SessionFactory; @@ -9,15 +7,14 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.cfg.Configuration; import org.hibernate.dialect.H2Dialect; import org.hibernate.service.ServiceRegistry; - -import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; -import javax.annotation.PostConstruct; +import com.baeldung.hibernate.lazycollection.model.Branch; +import com.baeldung.hibernate.lazycollection.model.Employee; public class LazyCollectionIntegrationTest { diff --git a/persistence-modules/hibernate-annotations/src/test/resources/log4j.xml b/persistence-modules/hibernate-annotations/src/test/resources/log4j.xml index 2d153af124..7e2895f1e0 100644 --- a/persistence-modules/hibernate-annotations/src/test/resources/log4j.xml +++ b/persistence-modules/hibernate-annotations/src/test/resources/log4j.xml @@ -1,6 +1,5 @@ - - + @@ -10,16 +9,16 @@ - + - + - + - \ No newline at end of file + \ No newline at end of file diff --git a/persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml b/persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml index c5d0f12462..69352715da 100644 --- a/persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml +++ b/persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml @@ -8,9 +8,9 @@ - - - + + + diff --git a/persistence-modules/hibernate-annotations/src/test/resources/logback.xml b/persistence-modules/hibernate-annotations/src/test/resources/logback.xml index 9e591977d7..ed39d69fc2 100644 --- a/persistence-modules/hibernate-annotations/src/test/resources/logback.xml +++ b/persistence-modules/hibernate-annotations/src/test/resources/logback.xml @@ -8,9 +8,9 @@ - - - + + + diff --git a/persistence-modules/java-jpa-2/src/test/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-2/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..00c7274dd4 --- /dev/null +++ b/persistence-modules/java-jpa-2/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,212 @@ + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.queryparams.Employee + true + + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.text.Exam + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.defaultvalues.User + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.querytypes.UserEntity + true + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.projections.Product + true + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.criteria.Item + true + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.multipletables.multipleentities.MealWithMultipleEntities + com.baeldung.jpa.multipletables.multipleentities.AllergensAsEntity + + com.baeldung.jpa.multipletables.secondarytable.MealAsSingleEntity + + com.baeldung.jpa.multipletables.secondarytable.embeddable.MealWithEmbeddedAllergens + com.baeldung.jpa.multipletables.secondarytable.embeddable.AllergensAsEmbeddable + + true + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.unrelated.entities.Cocktail + com.baeldung.jpa.unrelated.entities.Recipe + com.baeldung.jpa.unrelated.entities.MultipleRecipe + true + + + + + + + + + + + + + + org.eclipse.persistence.jpa.PersistenceProvider + com.baeldung.jpa.generateidvalue.Admin + com.baeldung.jpa.generateidvalue.Article + com.baeldung.jpa.generateidvalue.IdGenerator + com.baeldung.jpa.generateidvalue.Task + com.baeldung.jpa.generateidvalue.User + true + + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/resources/META-INF/persistence.xml b/persistence-modules/java-jpa-3/src/test/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..9a33f912bf --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/resources/META-INF/persistence.xml @@ -0,0 +1,152 @@ + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.equality.EqualByJavaDefault + com.baeldung.jpa.equality.EqualById + com.baeldung.jpa.equality.EqualByBusinessKey + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.removal.ShipmentInfo + com.baeldung.jpa.removal.LineItem + com.baeldung.jpa.removal.OrderRequest + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.index.Student + true + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.multiplebagfetchexception.Album + com.baeldung.jpa.multiplebagfetchexception.Song + com.baeldung.jpa.multiplebagfetchexception.User + com.baeldung.jpa.multiplebagfetchexception.Artist + com.baeldung.jpa.multiplebagfetchexception.Offer + com.baeldung.jpa.multiplebagfetchexception.Playlist + com.baeldung.jpa.multiplebagfetchexception.FavoriteSong + true + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.hibernateunproxy.Payment + com.baeldung.jpa.hibernateunproxy.CreditCardPayment + com.baeldung.jpa.hibernateunproxy.PaymentReceipt + com.baeldung.jpa.hibernateunproxy.WebUser + true + + + + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.IdGeneration.User + true + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.uniqueconstraints.Person + com.baeldung.jpa.uniqueconstraints.Address + true + + + + + + + + + + + + + org.hibernate.jpa.HibernatePersistenceProvider + com.baeldung.jpa.returnmultipleentities.Channel + com.baeldung.jpa.returnmultipleentities.Subscription + com.baeldung.jpa.returnmultipleentities.User + com.baeldung.jpa.returnmultipleentities.ReportRepository + true + + + + + + + + + + + + + + diff --git a/persistence-modules/java-jpa-3/src/test/resources/logback.xml b/persistence-modules/java-jpa-3/src/test/resources/logback.xml new file mode 100644 index 0000000000..0e1b193434 --- /dev/null +++ b/persistence-modules/java-jpa-3/src/test/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - + %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/java-jpa/README.md b/persistence-modules/java-jpa/README.md index be4c7fb79a..9dd76b13d6 100644 --- a/persistence-modules/java-jpa/README.md +++ b/persistence-modules/java-jpa/README.md @@ -14,4 +14,4 @@ This module contains articles about the Java Persistence API (JPA) in Java. - [Defining JPA Entities](https://www.baeldung.com/jpa-entities) - [JPA @Basic Annotation](https://www.baeldung.com/jpa-basic-annotation) - [Persisting Enums in JPA](https://www.baeldung.com/jpa-persisting-enums-in-jpa) -- More articles: [[next -->]](/java-jpa-2) +- More articles: [[next -->]](/persistence-modules/java-jpa-2) diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties index 1055806ecf..ca60ef3ce3 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties @@ -8,7 +8,7 @@ spring.h2.console.path=/h2-console spring.datasource.data=data-trans.sql logging.level.org.hibernate.SQL=INFO -logging.level.org.hibernate.type=TRACE +logging.level.org.hibernate.type=INFO spring.jpa.properties.hibernate.validator.apply_to_ddl=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=false spring.jpa.open-in-view=false \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties index 77aacf0d77..0469ea0dde 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties @@ -8,7 +8,7 @@ spring.h2.console.path=/h2-console spring.datasource.data=data-trans.sql logging.level.org.hibernate.SQL=INFO -logging.level.org.hibernate.type=TRACE +logging.level.org.hibernate.type=INFO spring.jpa.properties.hibernate.validator.apply_to_ddl=false spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true spring.jpa.open-in-view=false \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/springbootdatasourceconfig/application/entities/User.java b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/springbootdatasourceconfig/application/entities/User.java index 518a11701f..84a9ae74ff 100644 --- a/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/springbootdatasourceconfig/application/entities/User.java +++ b/persistence-modules/spring-boot-persistence/src/main/java/com/baeldung/springbootdatasourceconfig/application/entities/User.java @@ -13,6 +13,7 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; + private long status; private String name; private String email; @@ -39,6 +40,14 @@ public class User { this.email = email; } + public void setStatus(long status) { + this.status = status; + } + + public long getStatus() { + return status; + } + @Override public String toString() { return "User{" + "id=" + id + ", name=" + name + ", email=" + email + '}'; diff --git a/persistence-modules/spring-boot-persistence/src/test/resources/application.properties b/persistence-modules/spring-boot-persistence/src/test/resources/application.properties index 3a6470c8dc..559522ddbc 100644 --- a/persistence-modules/spring-boot-persistence/src/test/resources/application.properties +++ b/persistence-modules/spring-boot-persistence/src/test/resources/application.properties @@ -12,5 +12,5 @@ hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory -spring.jpa.properties.hibernate.hbm2ddl.import_files=migrated_users.sql, import_books.sql +#spring.jpa.properties.hibernate.hbm2ddl.import_files=import_active_users.sql,import_inactive_users.sql spring.datasource.data=import_*_users.sql \ No newline at end of file diff --git a/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java b/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java similarity index 96% rename from persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java rename to persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java index 1d4258688a..35232766ab 100644 --- a/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-arangodb/src/test/java/com/baeldung/arangodb/ArticleRepositoryLiveTest.java @@ -16,8 +16,11 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * ArangoDB server should be up and running for this test case to run successfully + */ @SpringBootTest -public class ArticleRepositoryIntegrationTest { +public class ArticleRepositoryLiveTest { @Autowired ArticleRepository articleRepository; From fae92b4fa6df692c5dac60c3f3fb817e357ca1d7 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 21 Aug 2021 14:35:49 +0530 Subject: [PATCH 021/148] JAVA-3247 further changes to reduce logging build pass --- .../src/main/resources/schema.sql | 9 ++++++++- .../src/test/resources/application.properties | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/persistence-modules/spring-boot-persistence/src/main/resources/schema.sql b/persistence-modules/spring-boot-persistence/src/main/resources/schema.sql index 4cfc8a7927..296d319b33 100644 --- a/persistence-modules/spring-boot-persistence/src/main/resources/schema.sql +++ b/persistence-modules/spring-boot-persistence/src/main/resources/schema.sql @@ -1,5 +1,6 @@ drop table if exists USERS; drop table if exists country; +drop table if exists BOOK; create table USERS( ID int not null AUTO_INCREMENT, @@ -12,4 +13,10 @@ CREATE TABLE country ( id INTEGER NOT NULL AUTO_INCREMENT, name VARCHAR(128) NOT NULL, PRIMARY KEY (id) -); \ No newline at end of file +); + +create table BOOK( + ID int not null AUTO_INCREMENT, + NAME varchar(128) not null, + PRIMARY KEY ( ID ) +); diff --git a/persistence-modules/spring-boot-persistence/src/test/resources/application.properties b/persistence-modules/spring-boot-persistence/src/test/resources/application.properties index 559522ddbc..07101ca2f5 100644 --- a/persistence-modules/spring-boot-persistence/src/test/resources/application.properties +++ b/persistence-modules/spring-boot-persistence/src/test/resources/application.properties @@ -12,5 +12,5 @@ hibernate.cache.use_second_level_cache=true hibernate.cache.use_query_cache=true hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory -#spring.jpa.properties.hibernate.hbm2ddl.import_files=import_active_users.sql,import_inactive_users.sql +spring.jpa.properties.hibernate.hbm2ddl.import_files=import_books.sql spring.datasource.data=import_*_users.sql \ No newline at end of file From 5dfb39712d62767c74f81ad2c12f73a4ad2e1dc6 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sat, 21 Aug 2021 17:18:36 +0200 Subject: [PATCH 022/148] first commit (#11118) --- maven-modules/maven-surefire-plugin/pom.xml | 17 +++++++++++ .../runasingletest/TheFirstUnitTest.java | 14 +++++++++ .../runasingletest/TheSecondUnitTest.java | 30 +++++++++++++++++++ maven-modules/pom.xml | 3 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 maven-modules/maven-surefire-plugin/pom.xml create mode 100644 maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java create mode 100644 maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java diff --git a/maven-modules/maven-surefire-plugin/pom.xml b/maven-modules/maven-surefire-plugin/pom.xml new file mode 100644 index 0000000000..903adf3c11 --- /dev/null +++ b/maven-modules/maven-surefire-plugin/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + maven-surefire-plugin + 0.0.1-SNAPSHOT + maven-surefire-plugin + jar + + com.baeldung + maven-modules + 0.0.1-SNAPSHOT + + + + diff --git a/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java new file mode 100644 index 0000000000..1e7fce885e --- /dev/null +++ b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.runasingletest; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class TheFirstUnitTest { + private static final Logger logger = LoggerFactory.getLogger(TheFirstUnitTest.class); + + @Test + void whenTestCase_thenPass() { + logger.info("Running a dummyTest"); + } +} diff --git a/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java new file mode 100644 index 0000000000..fd05751599 --- /dev/null +++ b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.runasingletest; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class TheSecondUnitTest { + + private static final Logger logger = LoggerFactory.getLogger(TheSecondUnitTest.class); + + @Test + void whenTestCase1_thenPrintTest1_1() { + logger.info("Running When Case1: test1_1"); + } + + @Test + void whenTestCase1_thenPrintTest1_2() { + logger.info("Running When Case1: test1_2"); + } + + @Test + void whenTestCase1_thenPrintTest1_3() { + logger.info("Running When Case1: test1_3"); + } + + @Test + void whenTestCase2_thenPrintTest2_1() { + logger.info("Running When Case2: test2_1"); + } +} diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 5b4b567ae6..a0c45234d2 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -35,6 +35,7 @@ maven-builder-plugin host-maven-repo-example plugin-management + maven-surefire-plugin - \ No newline at end of file + From cf452d7add33fba456c75f5d496a1364690518c1 Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sat, 21 Aug 2021 19:09:19 +0300 Subject: [PATCH 023/148] Added JavaFX demo app for ListView CellFactory (#11133) * Added JavaFX demo app for ListView CellFactory * Moved to the common project --- .../baeldung/listview/ExampleController.java | 38 +++++++++++++++++++ .../main/java/com/baeldung/listview/Main.java | 28 ++++++++++++++ .../java/com/baeldung/listview/Person.java | 25 ++++++++++++ .../cellfactory/CheckboxCellFactory.java | 29 ++++++++++++++ .../cellfactory/PersonCellFactory.java | 23 +++++++++++ javafx/src/main/resources/example.fxml | 14 +++++++ 6 files changed, 157 insertions(+) create mode 100644 javafx/src/main/java/com/baeldung/listview/ExampleController.java create mode 100644 javafx/src/main/java/com/baeldung/listview/Main.java create mode 100644 javafx/src/main/java/com/baeldung/listview/Person.java create mode 100644 javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java create mode 100644 javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java create mode 100644 javafx/src/main/resources/example.fxml diff --git a/javafx/src/main/java/com/baeldung/listview/ExampleController.java b/javafx/src/main/java/com/baeldung/listview/ExampleController.java new file mode 100644 index 0000000000..c02fa68d2e --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/ExampleController.java @@ -0,0 +1,38 @@ +package com.baeldung.listview; + +import com.baeldung.listview.cellfactory.CheckboxCellFactory; +import com.baeldung.listview.cellfactory.PersonCellFactory; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.ListView; + +import java.net.URL; +import java.util.ResourceBundle; + +public class ExampleController implements Initializable { + @FXML + private ListView listView; + + @Override + public void initialize(URL location, ResourceBundle resources) { + ObservableList wordsList = FXCollections.observableArrayList(); + wordsList.add(new Person("Isaac", "Newton")); + wordsList.add(new Person("Albert", "Einstein")); + wordsList.add(new Person("Ludwig", "Boltzmann")); + listView.setItems(wordsList); + } + + public void defaultButtonClick() { + listView.setCellFactory(null); + } + + public void cellFactoryButtonClick() { + listView.setCellFactory(new PersonCellFactory()); + } + + public void checkboxCellFactoryButtonClick() { + listView.setCellFactory(new CheckboxCellFactory()); + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/Main.java b/javafx/src/main/java/com/baeldung/listview/Main.java new file mode 100644 index 0000000000..a067971758 --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/Main.java @@ -0,0 +1,28 @@ +package com.baeldung.javafx.listview; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.net.URL; + +public class Main extends Application { + + public static void main(String args[]) { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + FXMLLoader loader = new FXMLLoader(); + URL xmlUrl = getClass().getResource("/example.fxml"); + loader.setLocation(xmlUrl); + Parent root = loader.load(); + + primaryStage.setTitle("List View Demo"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/Person.java b/javafx/src/main/java/com/baeldung/listview/Person.java new file mode 100644 index 0000000000..cdc0ab2dc8 --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/Person.java @@ -0,0 +1,25 @@ +package com.baeldung.listview; + +public class Person { + + private final String firstName; + private final String lastName; + + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + @Override + public String toString() { + return firstName + " " + lastName; + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java b/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java new file mode 100644 index 0000000000..522afcb76e --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java @@ -0,0 +1,29 @@ +package com.baeldung.listview.cellfactory; + +import com.baeldung.listview.Person; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.util.Callback; + +public class CheckboxCellFactory implements Callback, ListCell> { + @Override + public ListCell call(ListView param) { + return new ListCell(){ + @Override + public void updateItem(Person person, boolean empty) { + super.updateItem(person, empty); + if (empty) { + setText(null); + setGraphic(null); + } else if (person != null) { + setText(null); + setGraphic(new CheckBox(person.getFirstName() + " " + person.getLastName())); + } else { + setText("null"); + setGraphic(null); + } + } + }; + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java b/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java new file mode 100644 index 0000000000..57866b9ead --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java @@ -0,0 +1,23 @@ +package com.baeldung.listview.cellfactory; + +import com.baeldung.listview.Person; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.util.Callback; + +public class PersonCellFactory implements Callback, ListCell> { + @Override + public ListCell call(ListView param) { + return new ListCell(){ + @Override + public void updateItem(Person person, boolean empty) { + super.updateItem(person, empty); + if (empty || person == null) { + setText(null); + } else { + setText(person.getFirstName() + " " + person.getLastName()); + } + } + }; + } +} diff --git a/javafx/src/main/resources/example.fxml b/javafx/src/main/resources/example.fxml new file mode 100644 index 0000000000..c68df076d0 --- /dev/null +++ b/javafx/src/main/resources/example.fxml @@ -0,0 +1,14 @@ + + + + + + + + + +