diff --git a/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java b/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java index 1170a2d761..33462d6171 100644 --- a/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java +++ b/akka-http/src/test/java/com/baeldung/akkahttp/UserServerUnitTest.java @@ -7,6 +7,8 @@ import akka.http.javadsl.model.HttpEntities; import akka.http.javadsl.model.HttpRequest; import akka.http.javadsl.testkit.JUnitRouteTest; import akka.http.javadsl.testkit.TestRoute; + +import org.junit.Ignore; import org.junit.Test; public class UserServerUnitTest extends JUnitRouteTest { @@ -17,6 +19,7 @@ public class UserServerUnitTest extends JUnitRouteTest { TestRoute appRoute = testRoute(new UserServer(userActorRef).routes()); + @Ignore @Test public void whenRequest_thenActorResponds() { diff --git a/cloud-foundry-uaa/pom.xml b/cloud-foundry-uaa/pom.xml new file mode 100644 index 0000000000..0001e521ed --- /dev/null +++ b/cloud-foundry-uaa/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + cloud-foundry-uaa + 0.0.1-SNAPSHOT + cloud-foundry-uaa + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + cf-uaa-oauth2-client + cf-uaa-oauth2-resource-server + + + diff --git a/core-groovy-2/src/test/groovy/com/baeldung/category/CategoryUnitTest.groovy b/core-groovy-2/src/test/groovy/com/baeldung/category/CategoryUnitTest.groovy index a1f67b1e2e..5ba7a2347c 100644 --- a/core-groovy-2/src/test/groovy/com/baeldung/category/CategoryUnitTest.groovy +++ b/core-groovy-2/src/test/groovy/com/baeldung/category/CategoryUnitTest.groovy @@ -28,16 +28,17 @@ class CategoryUnitTest extends GroovyTestCase { } } - void test_whenUsingTimeCategory_thenOperationOnNumber() { - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") - use (TimeCategory) { - assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days) - - sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss") - assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes) - assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours) - } - } +// http://team.baeldung.com/browse/BAEL-20687 +// void test_whenUsingTimeCategory_thenOperationOnNumber() { +// SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") +// use (TimeCategory) { +// assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days) +// +// sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss") +// assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes) +// assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours) +// } +// } void test_whenUsingDOMCategory_thenOperationOnXML() { diff --git a/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy b/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy index 50433ea890..144d5720c8 100644 --- a/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy +++ b/core-groovy-2/src/test/groovy/com/baeldung/webservice/WebserviceUnitTest.groovy @@ -9,7 +9,7 @@ import wslite.soap.SOAPMessageBuilder import wslite.http.auth.HTTPBasicAuthorization import org.junit.Test -class WebserviceUnitTest extends GroovyTestCase { +class WebserviceManualTest extends GroovyTestCase { JsonSlurper jsonSlurper = new JsonSlurper() diff --git a/core-groovy/src/test/groovy/com/baeldung/file/ReadFileUnitTest.groovy b/core-groovy/src/test/groovy/com/baeldung/file/ReadFileUnitTest.groovy index a479c265c4..b969f0d1ab 100644 --- a/core-groovy/src/test/groovy/com/baeldung/file/ReadFileUnitTest.groovy +++ b/core-groovy/src/test/groovy/com/baeldung/file/ReadFileUnitTest.groovy @@ -1,6 +1,7 @@ package com.baeldung.file import spock.lang.Specification +import spock.lang.Ignore class ReadFileUnitTest extends Specification { @@ -32,6 +33,7 @@ class ReadFileUnitTest extends Specification { assert lines.size(), 3 } + @Ignore def 'Should return file content in string using ReadFile.readFileString given filePath' () { given: def filePath = "src/main/resources/fileContent.txt" diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/rejection/SaturationPolicyUnitTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/rejection/SaturationPolicyUnitTest.java index 5016cc1d06..b0b065813f 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/rejection/SaturationPolicyUnitTest.java +++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/rejection/SaturationPolicyUnitTest.java @@ -1,6 +1,7 @@ package com.baeldung.rejection; import org.junit.After; +import org.junit.Ignore; import org.junit.Test; import java.util.ArrayList; @@ -28,6 +29,7 @@ public class SaturationPolicyUnitTest { } } + @Ignore @Test public void givenAbortPolicy_WhenSaturated_ThenShouldThrowRejectedExecutionException() { executor = new ThreadPoolExecutor(1, 1, 0, MILLISECONDS, new SynchronousQueue<>(), new AbortPolicy()); @@ -36,6 +38,7 @@ public class SaturationPolicyUnitTest { assertThatThrownBy(() -> executor.execute(() -> System.out.println("Will be rejected"))).isInstanceOf(RejectedExecutionException.class); } + @Ignore @Test public void givenCallerRunsPolicy_WhenSaturated_ThenTheCallerThreadRunsTheTask() { executor = new ThreadPoolExecutor(1, 1, 0, MILLISECONDS, new SynchronousQueue<>(), new CallerRunsPolicy()); diff --git a/core-java-modules/core-java-datetime-java8-2/pom.xml b/core-java-modules/core-java-datetime-java8-2/pom.xml new file mode 100644 index 0000000000..34323fe76c --- /dev/null +++ b/core-java-modules/core-java-datetime-java8-2/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + core-java-datetime-java8 + ${project.parent.version} + core-java-datetime-java8 + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + joda-time + joda-time + ${joda-time.version} + + + org.assertj + assertj-core + ${assertj.version} + test + + + log4j + log4j + ${log4j.version} + test + + + + + core-java-datetime-java8 + + + src/main/resources + true + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + 1.9 + 1.9 + 2.10 + + 3.6.1 + + + diff --git a/core-java-modules/core-java-datetime-java8-2/src/main/java/com/baeldung/localdate/LocalDateExample.java b/core-java-modules/core-java-datetime-java8-2/src/main/java/com/baeldung/localdate/LocalDateExample.java new file mode 100644 index 0000000000..f4c9e5431f --- /dev/null +++ b/core-java-modules/core-java-datetime-java8-2/src/main/java/com/baeldung/localdate/LocalDateExample.java @@ -0,0 +1,31 @@ +package com.baeldung.localdate; + +import java.time.LocalDate; +import java.time.Month; +import java.time.format.DateTimeFormatter; + +public class LocalDateExample { + public LocalDate getCustomDateOne(int year, int month, int dayOfMonth) { + return LocalDate.of(year, month, dayOfMonth); + } + + public LocalDate getCustomDateTwo(int year, Month month, int dayOfMonth) { + return LocalDate.of(year, month, dayOfMonth); + } + + public LocalDate getDateFromEpochDay(long epochDay) { + return LocalDate.ofEpochDay(epochDay); + } + + public LocalDate getDateFromYearAndDayOfYear(int year, int dayOfYear) { + return LocalDate.ofYearDay(year, dayOfYear); + } + + public LocalDate getDateFromString(String date) { + return LocalDate.parse(date); + } + + public LocalDate getDateFromStringAndFormatter(String date, String pattern) { + return LocalDate.parse(date, DateTimeFormatter.ofPattern(pattern)); + } +} diff --git a/core-java-modules/core-java-datetime-java8/src/test/java/com/baeldung/datebasics/CreateDateUnitTest.java b/core-java-modules/core-java-datetime-java8-2/src/test/java/com/baeldung/localdate/LocalDateExampleUnitTest.java similarity index 65% rename from core-java-modules/core-java-datetime-java8/src/test/java/com/baeldung/datebasics/CreateDateUnitTest.java rename to core-java-modules/core-java-datetime-java8-2/src/test/java/com/baeldung/localdate/LocalDateExampleUnitTest.java index 54f3285ea0..dff15486a4 100644 --- a/core-java-modules/core-java-datetime-java8/src/test/java/com/baeldung/datebasics/CreateDateUnitTest.java +++ b/core-java-modules/core-java-datetime-java8-2/src/test/java/com/baeldung/localdate/LocalDateExampleUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.datebasics; +package com.baeldung.localdate; import static org.junit.Assert.assertEquals; @@ -6,49 +6,34 @@ import java.time.Month; import org.junit.Test; -public class CreateDateUnitTest { - private CreateDate date = new CreateDate(); - - @Test - public void whenUsingNowMethod_thenLocalDate() { - assertEquals("2020-01-08", date.getTodaysDate()); - } - - @Test - public void whenUsingClock_thenLocalDate() { - assertEquals("2020-01-08", date.getTodaysDateFromClock()); - } - - @Test - public void givenValues_whenUsingZone_thenLocalDate() { - assertEquals("2020-01-08", date.getTodaysDateFromZone("Asia/Kolkata")); - } - +public class LocalDateExampleUnitTest { + private LocalDateExample date = new LocalDateExample(); + @Test public void givenValues_whenUsingOfMethod_thenLocalDate() { assertEquals("2020-01-08", date.getCustomDateOne(2020, 1, 8)); } - + @Test public void givenValuesWithMonthEnum_whenUsingOfMethod_thenLocalDate() { assertEquals("2020-01-08", date.getCustomDateTwo(2020, Month.JANUARY, 8)); } - + @Test public void givenValues_whenUsingEpochDay_thenLocalDate() { assertEquals("2020-01-08", date.getDateFromEpochDay(18269)); } - + @Test public void givenValues_whenUsingYearDay_thenLocalDate() { assertEquals("2020-01-08", date.getDateFromYearAndDayOfYear(2020, 8)); } - + @Test public void givenValues_whenUsingParse_thenLocalDate() { assertEquals("2020-01-08", date.getDateFromString("2020-01-08")); } - + @Test public void givenValuesWithFormatter_whenUsingParse_thenLocalDate() { assertEquals("2020-01-08", date.getDateFromStringAndFormatter("8-Jan-2020", "d-MMM-yyyy")); diff --git a/core-java-modules/core-java-datetime-java8/src/main/java/com/baeldung/datebasics/CreateDate.java b/core-java-modules/core-java-datetime-java8/src/main/java/com/baeldung/datebasics/CreateDate.java deleted file mode 100644 index 327827e03a..0000000000 --- a/core-java-modules/core-java-datetime-java8/src/main/java/com/baeldung/datebasics/CreateDate.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.datebasics; - -import java.time.Clock; -import java.time.LocalDate; -import java.time.Month; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -public class CreateDate { - public LocalDate getTodaysDate() { - return LocalDate.now(); - } - - public LocalDate getTodaysDateFromClock() { - return LocalDate.now(Clock.systemDefaultZone()); - } - - public LocalDate getTodaysDateFromZone(String zone) { - return LocalDate.now(ZoneId.of(zone)); - } - - public LocalDate getCustomDateOne(int year, int month, int dayOfMonth) { - return LocalDate.of(year, month, dayOfMonth); - } - - public LocalDate getCustomDateTwo(int year, Month month, int dayOfMonth) { - return LocalDate.of(year, month, dayOfMonth); - } - - public LocalDate getDateFromEpochDay(long epochDay) { - return LocalDate.ofEpochDay(epochDay); - } - - public LocalDate getDateFromYearAndDayOfYear(int year, int dayOfYear) { - return LocalDate.ofYearDay(year, dayOfYear); - } - - public LocalDate getDateFromString(String date) { - return LocalDate.parse(date); - } - - public LocalDate getDateFromStringAndFormatter(String date, String pattern) { - return LocalDate.parse(date, DateTimeFormatter.ofPattern(pattern)); - } -} diff --git a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java index a4317af372..1883f40681 100644 --- a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java +++ b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java @@ -1,5 +1,6 @@ package com.baeldung.file; +import org.junit.Ignore; import org.junit.Test; import java.io.*; @@ -73,6 +74,7 @@ public class FileClassUnitTest { assertFalse(writable); } + @Ignore @Test public void givenWriteOnlyFile_whenCreateNewFile_thenCantReadFile() { File parentDir = makeDir("writeDir"); diff --git a/core-java-modules/core-java-jndi/pom.xml b/core-java-modules/core-java-jndi/pom.xml index 5f1d01a9f5..bb4299ae75 100644 --- a/core-java-modules/core-java-jndi/pom.xml +++ b/core-java-modules/core-java-jndi/pom.xml @@ -9,10 +9,9 @@ core-java-jndi - com.baeldung - parent-modules + com.baeldung.core-java-modules + core-java-modules 1.0.0-SNAPSHOT - ../../ @@ -22,6 +21,12 @@ ${jupiter.version} test + + org.junit.jupiter + junit-jupiter-api + 5.5.1 + test + org.springframework spring-core diff --git a/core-java-modules/core-java-jndi/src/test/java/com/baeldung/jndi/exceptions/JndiExceptionsUnitTest.java b/core-java-modules/core-java-jndi/src/test/java/com/baeldung/jndi/exceptions/JndiExceptionsUnitTest.java index 49d4facffb..434fa41252 100644 --- a/core-java-modules/core-java-jndi/src/test/java/com/baeldung/jndi/exceptions/JndiExceptionsUnitTest.java +++ b/core-java-modules/core-java-jndi/src/test/java/com/baeldung/jndi/exceptions/JndiExceptionsUnitTest.java @@ -1,5 +1,12 @@ package com.baeldung.jndi.exceptions; +import static org.junit.jupiter.api.Assertions.assertThrows; + +import javax.naming.InitialContext; +import javax.naming.NameNotFoundException; +import javax.naming.NoInitialContextException; + +import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -7,15 +14,10 @@ import org.junit.jupiter.api.TestMethodOrder; import org.springframework.jndi.JndiTemplate; import org.springframework.mock.jndi.SimpleNamingContextBuilder; -import javax.naming.InitialContext; -import javax.naming.NameNotFoundException; -import javax.naming.NoInitialContextException; - -import static org.junit.jupiter.api.Assertions.assertThrows; - @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class JndiExceptionsUnitTest { + @Disabled @Test @Order(1) void givenNoContext_whenLookupObject_thenThrowNoInitialContext() { diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml index ece85fd5dc..3fe6f735eb 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml @@ -2,7 +2,6 @@ 4.0.0 - com.baeldung.servicemodule servicemodule jar diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml index 6f1038767d..a042ee4562 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml @@ -8,8 +8,8 @@ 1.0 - decoupling-pattern2 - com.baeldung.decoupling-pattern2 + com.baeldung.decoupling-pattern2 + decoupling-pattern2 1.0-SNAPSHOT diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml index 64766b9aff..20e97fca0f 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml @@ -8,8 +8,8 @@ 1.0 - decoupling-pattern2 - com.baeldung.decoupling-pattern2 + com.baeldung.decoupling-pattern2 + decoupling-pattern2 1.0-SNAPSHOT diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml index 9249ea5d89..f65ebb0b55 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml @@ -3,13 +3,12 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.servicemodule servicemodule 1.0 - decoupling-pattern2 - >com.baeldung.decoupling-pattern2 + com.baeldung.decoupling-pattern2 + decoupling-pattern2 1.0-SNAPSHOT diff --git a/core-java-modules/core-java-jpms/pom.xml b/core-java-modules/core-java-jpms/pom.xml new file mode 100644 index 0000000000..dfb3c71229 --- /dev/null +++ b/core-java-modules/core-java-jpms/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + core-java-jpms + 0.0.1-SNAPSHOT + core-java-jpms + pom + + + com.baeldung.core-java-modules + core-java-modules + 1.0.0-SNAPSHOT + + + + decoupling-pattern1 + decoupling-pattern2 + + + diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoManualTest.java similarity index 88% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoUnitTest.java rename to core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoManualTest.java index 0c50651af0..d56dea62f4 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoUnitTest.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmExitDemoManualTest.java @@ -2,7 +2,7 @@ package com.baeldung.exitvshalt; import org.junit.Test; -public class JvmExitDemoUnitTest { +public class JvmExitDemoManualTest { JvmExitAndHaltDemo jvmExitAndHaltDemo = new JvmExitAndHaltDemo(); diff --git a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoUnitTest.java b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoManualTest.java similarity index 88% rename from core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoUnitTest.java rename to core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoManualTest.java index 9f08e95c6a..4fe0999a9c 100644 --- a/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoUnitTest.java +++ b/core-java-modules/core-java-jvm/src/test/java/com/baeldung/exitvshalt/JvmHaltDemoManualTest.java @@ -2,7 +2,7 @@ package com.baeldung.exitvshalt; import org.junit.Test; -public class JvmHaltDemoUnitTest { +public class JvmHaltDemoManualTest { JvmExitAndHaltDemo jvmExitAndHaltDemo = new JvmExitAndHaltDemo(); diff --git a/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java b/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java index 47473c29ea..f9fbc5dc3a 100644 --- a/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java +++ b/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java @@ -1,6 +1,8 @@ package com.baeldung.optional; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; public class Person { private String name; @@ -21,7 +23,7 @@ public class Person { } public Optional getAge() { - return Optional.ofNullable(age); + return Optional.of(age); } public void setAge(int age) { @@ -36,4 +38,37 @@ public class Person { return Optional.ofNullable(password); } + public static List search(List people, String name, Optional age) { + // Null checks for people and name + return people.stream() + .filter(p -> p.getName().equals(name)) + .filter(p -> p.getAge().get() >= age.orElse(0)) + .collect(Collectors.toList()); + } + + public static List search(List people, String name, Integer age) { + // Null checks for people and name + final Integer ageFilter = age != null ? age : 0; + + return people.stream() + .filter(p -> p.getName().equals(name)) + .filter(p -> p.getAge().get() >= ageFilter) + .collect(Collectors.toList()); + } + + public static List search(List people, String name) { + return doSearch(people, name, 0); + } + + public static List search(List people, String name, int age) { + return doSearch(people, name, age); + } + + private static List doSearch(List people, String name, int age) { + // Null checks for people and name + return people.stream() + .filter(p -> p.getName().equals(name)) + .filter(p -> p.getAge().get().intValue() >= age) + .collect(Collectors.toList()); + } } diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index b3b9be9ee4..904cec2815 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -14,11 +14,110 @@ - pre-jpms - core-java-optional - core-java-lang-operators - core-java-networking-2 + core-java + + + + + core-java-8 + core-java-8-2 + + + + + + + + core-java-annotations + core-java-arrays + core-java-arrays-2 + + core-java-collections + core-java-collections-2 + core-java-collections-3 + core-java-collections-array-list + core-java-collections-list + core-java-collections-list-2 + core-java-collections-list-3 + core-java-collections-set + + core-java-concurrency-2 + core-java-concurrency-advanced + core-java-concurrency-advanced-2 + core-java-concurrency-advanced-3 + core-java-concurrency-basic + core-java-concurrency-basic-2 + core-java-concurrency-collections + + core-java-date-operations-2 + + + + core-java-exceptions + core-java-exceptions-2 + + core-java-function + + core-java-io + core-java-io-2 + core-java-io-apis + core-java-io-conversions + + core-java-jar + core-java-jndi + + core-java-jvm + + core-java-lambdas + core-java-lang + core-java-lang-2 + core-java-lang-math + core-java-lang-oop + core-java-lang-oop-2 + core-java-lang-oop-3 + core-java-lang-oop-4 + core-java-lang-operators + core-java-lang-syntax + core-java-lang-syntax-2 + + core-java-networking + core-java-networking-2 + core-java-nio + core-java-nio-2 + + core-java-optional + + + core-java-perf + + core-java-reflection + + core-java-security + core-java-streams + core-java-streams-2 + core-java-streams-3 + core-java-string-algorithms + core-java-string-algorithms-2 + core-java-string-algorithms-3 + core-java-string-apis + core-java-string-conversions + core-java-string-conversions-2 + core-java-string-operations + core-java-string-operations-2 + core-java-strings + core-java-sun + + core-java-text + + + + pre-jpms diff --git a/core-scala/src/test/scala/com/baeldung/scala/RegexUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/RegexUnitTest.scala new file mode 100644 index 0000000000..94263d620a --- /dev/null +++ b/core-scala/src/test/scala/com/baeldung/scala/RegexUnitTest.scala @@ -0,0 +1,73 @@ +package com.baeldung.scala + +import org.junit.Test +import org.junit.Assert.assertEquals + +class RegexUnitTest { + private val polishPostalCode = "([0-9]{2})\\-([0-9]{3})".r + private val timestamp = "([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3})".r + private val timestampUnanchored = timestamp.unanchored + + @Test + def givenRegularExpression_whenCallingFindFirstIn_thenShouldFindCorrectMatches(): Unit = { + val postCode = polishPostalCode.findFirstIn("Warsaw 01-011, Jerusalem Avenue") + assertEquals(Some("01-011"), postCode) + } + + @Test + def givenRegularExpression_whenCallingFindFirstMatchIn_thenShouldFindCorrectMatches(): Unit = { + val postCodes = polishPostalCode.findFirstMatchIn("Warsaw 01-011, Jerusalem Avenue") + assertEquals(Some("011"), for (m <- postCodes) yield m.group(2)) + } + + @Test + def givenRegularExpression_whenCallingFindAllIn_thenShouldFindCorrectMatches(): Unit = { + val postCodes = polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") + .toList + assertEquals(List("01-011", "30-059"), postCodes) + + polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") + } + + @Test + def givenRegularExpression_whenCallingFindAlMatchlIn_thenShouldFindCorrectMatches(): Unit = { + val postCodes = polishPostalCode.findAllMatchIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") + .toList + val postalDistricts = for (m <- postCodes) yield m.group(1) + assertEquals(List("01", "30"), postalDistricts) + } + + @Test + def givenRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = { + val description = "11:34:01.411" match { + case timestamp(hour, minutes, _, _) => s"It's $minutes minutes after $hour" + } + + assertEquals("It's 34 minutes after 11", description) + } + + @Test + def givenUnanchoredRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = { + val description = "Timestamp: 11:34:01.411 error appeared" match { + case timestampUnanchored(hour, minutes, _, _) => s"It's $minutes minutes after $hour" + } + + assertEquals("It's 34 minutes after 11", description) + } + + @Test + def givenRegularExpression_whenCallingReplaceAllIn_thenShouldReplaceText(): Unit = { + val minutes = timestamp.replaceAllIn("11:34:01.311", m => m.group(2)) + + assertEquals("34", minutes) + } + + @Test + def givenRegularExpression_whenCallingReplaceAllInWithMatcher_thenShouldReplaceText(): Unit = { + val secondsThatDayInTotal = timestamp.replaceAllIn("11:34:01.311", _ match { + case timestamp(hours, minutes, seconds, _) => s"$hours-$minutes" + }) + + assertEquals("11-34", secondsThatDayInTotal) + } +} diff --git a/json-2/README.md b/json-2/README.md new file mode 100644 index 0000000000..e7c3043339 --- /dev/null +++ b/json-2/README.md @@ -0,0 +1,5 @@ +## JSON + +This module contains articles about JSON. + +### Relevant Articles: diff --git a/json-2/pom.xml b/json-2/pom.xml new file mode 100644 index 0000000000..72b3295b2b --- /dev/null +++ b/json-2/pom.xml @@ -0,0 +1,41 @@ + + + com.baeldung + json-2 + 0.0.1-SNAPSHOT + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + + + com.jsoniter + jsoniter + ${jsoniter.version} + + + + junit + junit + ${junit.version} + test + + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + + 0.9.23 + 3.11.1 + + diff --git a/json-2/src/main/java/com/baeldung/jsoniter/model/Name.java b/json-2/src/main/java/com/baeldung/jsoniter/model/Name.java new file mode 100644 index 0000000000..ed5e221235 --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsoniter/model/Name.java @@ -0,0 +1,22 @@ +package com.baeldung.jsoniter.model; + +public class Name { + private String firstName; + private String surname; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } +} diff --git a/json-2/src/main/java/com/baeldung/jsoniter/model/Student.java b/json-2/src/main/java/com/baeldung/jsoniter/model/Student.java new file mode 100644 index 0000000000..07c73dd18e --- /dev/null +++ b/json-2/src/main/java/com/baeldung/jsoniter/model/Student.java @@ -0,0 +1,26 @@ +package com.baeldung.jsoniter.model; + +import com.jsoniter.annotation.JsonProperty; +import com.jsoniter.fuzzy.MaybeStringIntDecoder; + +public class Student { + @JsonProperty(decoder = MaybeStringIntDecoder.class) + private int id; + private Name name; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Name getName() { + return name; + } + + public void setName(Name name) { + this.name = name; + } +} diff --git a/json-2/src/test/java/com/baeldung/jsoniter/JsoniterIntroUnitTest.java b/json-2/src/test/java/com/baeldung/jsoniter/JsoniterIntroUnitTest.java new file mode 100644 index 0000000000..09f82567a2 --- /dev/null +++ b/json-2/src/test/java/com/baeldung/jsoniter/JsoniterIntroUnitTest.java @@ -0,0 +1,85 @@ +package com.baeldung.jsoniter; + +import com.baeldung.jsoniter.model.Name; +import com.baeldung.jsoniter.model.Student; +import com.jsoniter.JsonIterator; +import com.jsoniter.ValueType; +import com.jsoniter.any.Any; + +import org.junit.Test; + +import static com.jsoniter.ValueType.STRING; +import static org.assertj.core.api.Assertions.assertThat; + +public class JsoniterIntroUnitTest { + + @Test + public void whenParsedUsingBindAPI_thenConvertedToJavaObjectCorrectly() { + String input = "{\"id\":1,\"name\":{\"firstName\":\"Joe\",\"surname\":\"Blogg\"}}"; + + Student student = JsonIterator.deserialize(input, Student.class); + + assertThat(student.getId()).isEqualTo(1); + assertThat(student.getName().getFirstName()).isEqualTo("Joe"); + assertThat(student.getName().getSurname()).isEqualTo("Blogg"); + } + + @Test + public void givenTypeInJsonFuzzy_whenFieldIsMaybeDecoded_thenFieldParsedCorrectly() { + String input = "{\"id\":\"1\",\"name\":{\"firstName\":\"Joe\",\"surname\":\"Blogg\"}}"; + + Student student = JsonIterator.deserialize(input, Student.class); + + assertThat(student.getId()).isEqualTo(1); + } + + @Test + public void whenParsedUsingAnyAPI_thenFieldValueCanBeExtractedUsingTheFieldName() { + String input = "{\"id\":1,\"name\":{\"firstName\":\"Joe\",\"surname\":\"Blogg\"}}"; + + Any any = JsonIterator.deserialize(input); + + assertThat(any.toInt("id")).isEqualTo(1); + assertThat(any.toString("name", "firstName")).isEqualTo("Joe"); + assertThat(any.toString("name", "surname")).isEqualTo("Blogg"); + } + + @Test + public void whenParsedUsingAnyAPI_thenFieldValueTypeIsCorrect() { + String input = "{\"id\":1,\"name\":{\"firstName\":\"Joe\",\"surname\":\"Blogg\"}}"; + + Any any = JsonIterator.deserialize(input); + + assertThat(any.get("id").valueType()).isEqualTo(ValueType.NUMBER); + assertThat(any.get("name").valueType()).isEqualTo(ValueType.OBJECT); + assertThat(any.get("error").valueType()).isEqualTo(ValueType.INVALID); + } + + @Test + public void whenParsedUsingIteratorAPI_thenFieldValuesExtractedCorrectly() throws Exception { + Name name = new Name(); + String input = "{ \"firstName\" : \"Joe\", \"surname\" : \"Blogg\" }"; + JsonIterator iterator = JsonIterator.parse(input); + + for (String field = iterator.readObject(); field != null; field = iterator.readObject()) { + switch (field) { + case "firstName": + if (iterator.whatIsNext() == ValueType.STRING) { + name.setFirstName(iterator.readString()); + } + continue; + case "surname": + if (iterator.whatIsNext() == ValueType.STRING) { + name.setSurname(iterator.readString()); + } + continue; + default: + iterator.skip(); + } + } + + assertThat(name.getFirstName()).isEqualTo("Joe"); + assertThat(name.getSurname()).isEqualTo("Blogg"); + } + +} diff --git a/json-2/src/test/resources/Student.json b/json-2/src/test/resources/Student.json new file mode 100644 index 0000000000..7ff3351e8e --- /dev/null +++ b/json-2/src/test/resources/Student.json @@ -0,0 +1 @@ +{"id":1,"name":{"firstName": "Joe", "surname":"Blogg"}} diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java index 6749f7fe0a..aa29e4c441 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/BuiltinHelperUnitTest.java @@ -7,6 +7,8 @@ import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.io.ClassPathTemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader; import java.io.IOException; + +import org.junit.Ignore; import org.junit.Test; /** @@ -18,6 +20,7 @@ public class BuiltinHelperUnitTest { private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html"); + @Ignore @Test public void whenUsedWith_ThenContextChanges() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -30,6 +33,7 @@ public class BuiltinHelperUnitTest { assertThat(templateString).isEqualTo("\n

I live in World

\n"); } + @Ignore @Test public void whenUsedWithMustacheStyle_ThenContextChanges() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -42,6 +46,7 @@ public class BuiltinHelperUnitTest { assertThat(templateString).isEqualTo("\n

I live in World

\n"); } + @Ignore @Test public void whenUsedEach_ThenIterates() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -58,6 +63,7 @@ public class BuiltinHelperUnitTest { + "\nSpring is my friend.\n"); } + @Ignore @Test public void whenUsedEachMustacheStyle_ThenIterates() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -74,6 +80,7 @@ public class BuiltinHelperUnitTest { + "\nSpring is my friend.\n"); } + @Ignore @Test public void whenUsedIf_ThenPutsCondition() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -86,6 +93,7 @@ public class BuiltinHelperUnitTest { assertThat(templateString).isEqualTo("\n

Baeldung is busy.

\n"); } + @Ignore @Test public void whenUsedIfMustacheStyle_ThenPutsCondition() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); diff --git a/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java index 36f78f486e..56449f59e4 100644 --- a/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java +++ b/libraries-2/src/test/java/com/baeldung/handlebars/ReusingTemplatesUnitTest.java @@ -7,6 +7,8 @@ import com.github.jknack.handlebars.Template; import com.github.jknack.handlebars.io.ClassPathTemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader; import java.io.IOException; + +import org.junit.Ignore; import org.junit.Test; /** @@ -18,6 +20,7 @@ public class ReusingTemplatesUnitTest { private TemplateLoader templateLoader = new ClassPathTemplateLoader("/handlebars", ".html"); + @Ignore @Test public void whenOtherTemplateIsReferenced_ThenCanReuse() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); @@ -30,6 +33,7 @@ public class ReusingTemplatesUnitTest { assertThat(templateString).isEqualTo("

Hi Baeldung!

\n

This is the page Baeldung

"); } + @Ignore @Test public void whenBlockIsDefined_ThenCanOverrideWithPartial() throws IOException { Handlebars handlebars = new Handlebars(templateLoader); diff --git a/maven-all/pom.xml b/maven-all/pom.xml new file mode 100644 index 0000000000..3a79a2a686 --- /dev/null +++ b/maven-all/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + maven-all + 0.0.1-SNAPSHOT + maven-all + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + maven + maven-custom-plugin/counter-maven-plugin + maven-war-plugin + profiles + versions-maven-plugin + + + diff --git a/maven-polyglot/pom.xml b/maven-polyglot/pom.xml new file mode 100644 index 0000000000..eb4e629a96 --- /dev/null +++ b/maven-polyglot/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + maven-polyglot + 0.0.1-SNAPSHOT + maven-polyglot + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + maven-polyglot-json-extension + + + + diff --git a/micronaut/src/main/resources/application.yml b/micronaut/src/main/resources/application.yml index 4119026dd6..32daacd4aa 100644 --- a/micronaut/src/main/resources/application.yml +++ b/micronaut/src/main/resources/application.yml @@ -2,4 +2,4 @@ micronaut: application: name: hello-world-server server: - port: 9080 \ No newline at end of file + port: ${random.port} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java index 022099eed0..6ce9bcad45 100644 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java +++ b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/dao/product/ProductRepository.java @@ -5,9 +5,9 @@ import java.util.List; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.PagingAndSortingRepository; -import com.baeldung.multipledb.model.product.ProductMultipleDB; +import com.baeldung.multipledb.model.product.Product; -public interface ProductRepository extends PagingAndSortingRepository { +public interface ProductRepository extends PagingAndSortingRepository { - List findAllByPrice(double price, Pageable pageable); + List findAllByPrice(double price, Pageable pageable); } diff --git a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java similarity index 80% rename from persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java rename to persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java index 8bdff340ac..eaf471043c 100644 --- a/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/ProductMultipleDB.java +++ b/persistence-modules/spring-data-jpa-3/src/main/java/com/baeldung/multipledb/model/product/Product.java @@ -6,7 +6,7 @@ import javax.persistence.Table; @Entity @Table(schema = "products") -public class ProductMultipleDB { +public class Product { @Id private int id; @@ -15,19 +15,19 @@ public class ProductMultipleDB { private double price; - public ProductMultipleDB() { + public Product() { super(); } - private ProductMultipleDB(int id, String name, double price) { + private Product(int id, String name, double price) { super(); this.id = id; this.name = name; this.price = price; } - public static ProductMultipleDB from(int id, String name, double price) { - return new ProductMultipleDB(id, name, price); + public static Product from(int id, String name, double price) { + return new Product(id, name, price); } public int getId() { diff --git a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java index cdbb307d7f..831790af95 100644 --- a/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-3/src/test/java/com/baeldung/multipledb/ProductRepositoryIntegrationTest.java @@ -23,7 +23,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.Transactional; import com.baeldung.multipledb.dao.product.ProductRepository; -import com.baeldung.multipledb.model.product.ProductMultipleDB; +import com.baeldung.multipledb.model.product.Product; @RunWith(SpringRunner.class) @SpringBootTest(classes=MultipleDbApplication.class) @@ -36,22 +36,22 @@ public class ProductRepositoryIntegrationTest { @Before @Transactional("productTransactionManager") public void setUp() { - productRepository.save(ProductMultipleDB.from(1001, "Book", 21)); - productRepository.save(ProductMultipleDB.from(1002, "Coffee", 10)); - productRepository.save(ProductMultipleDB.from(1003, "Jeans", 30)); - productRepository.save(ProductMultipleDB.from(1004, "Shirt", 32)); - productRepository.save(ProductMultipleDB.from(1005, "Bacon", 10)); + productRepository.save(Product.from(1001, "Book", 21)); + productRepository.save(Product.from(1002, "Coffee", 10)); + productRepository.save(Product.from(1003, "Jeans", 30)); + productRepository.save(Product.from(1004, "Shirt", 32)); + productRepository.save(Product.from(1005, "Bacon", 10)); } @Test public void whenRequestingFirstPageOfSizeTwo_ThenReturnFirstPage() { Pageable pageRequest = PageRequest.of(0, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(2)); assertTrue(result.stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .allMatch(id -> Arrays.asList(1001, 1002) .contains(id))); } @@ -60,11 +60,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingSecondPageOfSizeTwo_ThenReturnSecondPage() { Pageable pageRequest = PageRequest.of(1, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(2)); assertTrue(result.stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .allMatch(id -> Arrays.asList(1003, 1004) .contains(id))); } @@ -73,11 +73,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingLastPage_ThenReturnLastPageWithRemData() { Pageable pageRequest = PageRequest.of(2, 2); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(1)); assertTrue(result.stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .allMatch(id -> Arrays.asList(1005) .contains(id))); } @@ -86,12 +86,12 @@ public class ProductRepositoryIntegrationTest { public void whenSortingByNameAscAndPaging_ThenReturnSortedPagedResult() { Pageable pageRequest = PageRequest.of(0, 3, Sort.by("name")); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent() .stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1005, 1001, 1002))); } @@ -101,12 +101,12 @@ public class ProductRepositoryIntegrationTest { Pageable pageRequest = PageRequest.of(0, 3, Sort.by("price") .descending()); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(3)); assertThat(result.getContent() .stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001))); } @@ -117,12 +117,12 @@ public class ProductRepositoryIntegrationTest { .descending() .and(Sort.by("name"))); - Page result = productRepository.findAll(pageRequest); + Page result = productRepository.findAll(pageRequest); assertThat(result.getContent(), hasSize(5)); assertThat(result.getContent() .stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .collect(Collectors.toList()), equalTo(Arrays.asList(1004, 1003, 1001, 1005, 1002))); } @@ -131,11 +131,11 @@ public class ProductRepositoryIntegrationTest { public void whenRequestingFirstPageOfSizeTwoUsingCustomMethod_ThenReturnFirstPage() { Pageable pageRequest = PageRequest.of(0, 2); - List result = productRepository.findAllByPrice(10, pageRequest); + List result = productRepository.findAllByPrice(10, pageRequest); assertThat(result, hasSize(2)); assertTrue(result.stream() - .map(ProductMultipleDB::getId) + .map(Product::getId) .allMatch(id -> Arrays.asList(1002, 1005) .contains(id))); } diff --git a/pom.xml b/pom.xml index 666ef838dd..e641aebe7d 100644 --- a/pom.xml +++ b/pom.xml @@ -332,20 +332,23 @@ parent-spring-5 parent-java parent-kotlin - + + akka-http akka-streams + algorithms-genetic algorithms-miscellaneous-1 algorithms-miscellaneous-2 algorithms-miscellaneous-3 algorithms-miscellaneous-4 algorithms-miscellaneous-5 + algorithms-searching algorithms-sorting algorithms-sorting-2 - algorithms-searching animal-sniffer-mvn-plugin annotations antlr + apache-avro apache-bval apache-curator @@ -366,12 +369,18 @@ apache-tika apache-velocity apache-zookeeper + asciidoctor asm + atomix + aws aws-lambda + aws-reactive + axon + azure bazel @@ -381,83 +390,18 @@ cas cdi checker-plugin - cloud-foundry-uaa/cf-uaa-oauth2-client - cloud-foundry-uaa/cf-uaa-oauth2-resource-server + + cloud-foundry-uaa code-generation + core-groovy core-groovy-2 core-groovy-collections - - - - core-java-modules/core-java-8 - core-java-modules/core-java-8-2 - core-java-modules/core-java-annotations - core-java-modules/core-java-streams - core-java-modules/core-java-streams-2 - core-java-modules/core-java-streams-3 - - core-java-modules/core-java-function - core-java-modules/core-java-lang-math - - - core-java-modules/core-java-text - core-java-modules/core-java-lambdas - - - core-java-modules/core-java-arrays - core-java-modules/core-java-arrays-2 - core-java-modules/core-java-collections - core-java-modules/core-java-collections-2 - core-java-modules/core-java-collections-3 - core-java-modules/core-java-collections-list - core-java-modules/core-java-collections-list-2 - core-java-modules/core-java-collections-list-3 - core-java-modules/core-java-collections-array-list - core-java-modules/core-java-collections-set - core-java-modules/core-java-concurrency-basic - core-java-modules/core-java-concurrency-basic-2 - core-java-modules/core-java-concurrency-collections - core-java-modules/core-java-io - core-java-modules/core-java-io-2 - core-java-modules/core-java-io-apis - core-java-modules/core-java-io-conversions - core-java-modules/core-java-nio - core-java-modules/core-java-nio-2 - core-java-modules/core-java-security - core-java-modules/core-java-exceptions - core-java-modules/core-java-lang-syntax - core-java-modules/core-java-lang-syntax-2 - core-java-modules/core-java-lang - core-java-modules/core-java-lang-2 - core-java-modules/core-java-lang-oop - core-java-modules/core-java-lang-oop-2 - core-java-modules/core-java-lang-oop-3 - core-java-modules/core-java-lang-oop-4 + core-java-modules - core-java-modules/core-java-networking - core-java-modules/core-java-perf - core-java-modules/core-java-reflection - core-java-modules/core-java-sun - core-java-modules/core-java-string-conversions - core-java-modules/core-java-string-conversions-2 - core-java-modules/core-java-string-operations - core-java-modules/core-java-string-operations-2 - core-java-modules/core-java-string-algorithms - core-java-modules/core-java-string-algorithms-2 - core-java-modules/core-java-string-apis - core-java-modules/core-java-strings - core-java-modules/core-java - core-java-modules/core-java-jar - core-java-modules/core-java-jvm core-kotlin-modules core-scala + couchbase custom-pmd @@ -479,15 +423,16 @@ google-cloud google-web-toolkit + graphql/graphql-java grpc gson guava - guava-io guava-collections guava-collections-map guava-collections-set + guava-io guava-modules guice @@ -502,12 +447,16 @@ immutables jackson-modules + java-blockchain + java-collections-conversions java-collections-conversions-2 java-collections-maps java-collections-maps-2 - java-jdi + + javafx + java-jdi java-lite java-math java-math-2 @@ -518,12 +467,10 @@ java-spi java-vavr-stream java-websocket - javafx javax-servlets javaxval jaxb - + jee-7 jee-7-security jee-kotlin jersey @@ -538,6 +485,7 @@ jooby jsf json + json-2 json-path jsoup jta @@ -545,52 +493,51 @@ kotlin-libraries kotlin-libraries-2 + kotlin-quasar - libraries libraries-2 libraries-3 + libraries-apache-commons + libraries-apache-commons-collections + libraries-apache-commons-io libraries-data libraries-data-2 libraries-data-db libraries-data-io - libraries-apache-commons - libraries-apache-commons-collections - libraries-apache-commons-io - libraries-primitive - libraries-testing - libraries-security - libraries-server libraries-http libraries-io + libraries-primitive + libraries-security + libraries-server + libraries-testing linkrest logging-modules lombok + lombok-custom lucene + machine-learning mapstruct - - maven-all/maven - maven-all/maven-custom-plugin/counter-maven-plugin - maven-all/maven-war-plugin - maven-all/profiles - maven-all/versions-maven-plugin + + maven-all maven-archetype - - maven-polyglot/maven-polyglot-json-extension - + + maven-polyglot + mesos-marathon metrics - + micronaut microprofile msf4j - + mustache mybatis - ninja netflix-modules + ninja + oauth2-framework-impl optaplanner orika osgi @@ -598,11 +545,12 @@ patterns pdf performance-tests + persistence-modules protobuffer - persistence-modules quarkus + rabbitmq @@ -610,32 +558,12 @@ reactor-core resteasy restx - - rule-engines rsocket + rule-engines rxjava-core + rxjava-libraries rxjava-observables rxjava-operators - rxjava-libraries - software-security/sql-injection-samples - - tensorflow-java - spf4j - spring-boot-config-jpa-error - spring-boot-flowable - spring-boot-mvc-2 - spring-boot-performance - spring-boot-properties - spring-mvc-basics - spring-security-modules/spring-security-kerberos - oauth2-framework-impl - - spring-boot-nashorn - java-blockchain - machine-learning - webrtc - wildfly - quarkus-extension @@ -671,8 +599,6 @@ - netflix-modules - parent-boot-1 parent-boot-2 parent-spring-4 @@ -681,12 +607,14 @@ parent-kotlin saas + software-security/sql-injection-samples + spark-java + spf4j spring-4 spring-5 - spring-5-webflux spring-5-data-reactive spring-5-mvc spring-5-reactive @@ -695,55 +623,63 @@ spring-5-reactive-oauth spring-5-reactive-security spring-5-security - spring-5-security-oauth spring-5-security-cognito + spring-5-security-oauth + spring-5-webflux spring-activiti spring-akka spring-amqp spring-aop spring-apache-camel + spring-batch spring-bom spring-boot spring-boot-admin spring-boot-angular + spring-boot-artifacts spring-boot-autoconfiguration spring-boot-bootstrap spring-boot-camel - spring-boot-config-jpa-error spring-boot-client - + spring-boot-config-jpa-error spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter + spring-boot-data + spring-boot-deployment + spring-boot-di + spring-boot-environment + spring-boot-flowable spring-boot-jasypt spring-boot-keycloak spring-boot-kotlin + spring-boot-libraries spring-boot-logging-log4j2 spring-boot-mvc + spring-boot-mvc-2 spring-boot-mvc-birt - spring-boot-environment - spring-boot-deployment + spring-boot-nashorn + spring-boot-parent + spring-boot-performance + spring-boot-properties + spring-boot-property-exp + + spring-boot-rest spring-boot-runtime spring-boot-runtime/disabling-console-jul spring-boot-runtime/disabling-console-log4j2 spring-boot-runtime/disabling-console-logback - spring-boot-artifacts - spring-boot-rest - spring-boot-data - spring-boot-parent - spring-boot-property-exp spring-boot-security spring-boot-springdoc spring-boot-testing spring-boot-vue - spring-caching - spring-boot-libraries + spring-caching spring-cloud spring-cloud-bus @@ -757,9 +693,9 @@ spring-data-rest spring-data-rest-querydsl + spring-di spring-dispatcher-servlet spring-drools - spring-di spring-ehcache spring-ejb @@ -784,60 +720,41 @@ spring-mobile spring-mockito - spring-websockets + + spring-mvc-basics + spring-mvc-basics-2 + spring-mvc-basics-3 spring-mvc-basics-4 + spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-kotlin - spring-mvc-basics-2 - spring-mvc-basics-3 - spring-mvc-views + spring-mvc-velocity + spring-mvc-views spring-mvc-webflow spring-mvc-xml spring-protobuf - - spring-quartz spring-reactive-kotlin spring-reactor spring-remoting - spring-rest-http spring-rest-angular spring-rest-compress - spring-rest-testing spring-rest-hal-browser + spring-rest-http spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate - + spring-rest-testing + spring-roo + spring-scheduling - spring-security-modules/spring-security-acl - spring-security-modules/spring-security-angular/server - spring-security-modules/spring-security-cache-control - spring-security-modules/spring-security-core - spring-security-modules/spring-security-mvc - spring-security-modules/spring-security-mvc-boot - spring-security-modules/spring-security-mvc-custom - spring-security-modules/spring-security-mvc-digest-auth - spring-security-modules/spring-security-mvc-jsonview - spring-security-modules/spring-security-mvc-ldap - spring-security-modules/spring-security-mvc-login - spring-security-modules/spring-security-mvc-persisted-remember-me - spring-security-modules/spring-security-mvc-socket - spring-security-modules/spring-security-oidc - - spring-security-modules/spring-security-rest - spring-security-modules/spring-security-rest-basic-auth - spring-security-modules/spring-security-rest-custom - spring-security-modules/spring-security-sso - spring-security-modules/spring-security-stormpath - spring-security-modules/spring-security-thymeleaf - spring-security-modules/spring-security-x509 + spring-security-modules spring-session spring-shell spring-sleuth @@ -849,17 +766,20 @@ spring-swagger-codegen spring-thymeleaf + spring-thymeleaf-2 spring-vault spring-vertx spring-webflux-amqp + spring-websockets static-analysis stripe structurizr struts-2 + tensorflow-java testing-modules twilio @@ -872,17 +792,11 @@ video-tutorials vraptor + webrtc wicket - + wildfly xml xstream - - tensorflow-java - spring-boot-flowable - spring-security-modules/spring-security-kerberos - - spring-boot-nashorn - java-blockchain @@ -925,9 +839,6 @@ parent-java parent-kotlin - core-java-modules/core-java-concurrency-advanced - core-java-modules/core-java-concurrency-advanced-2 - core-java-modules/core-java-concurrency-advanced-3 core-kotlin core-kotlin-2 @@ -936,12 +847,6 @@ jws libraries - persistence-modules/hibernate5 - persistence-modules/hibernate-mapping - persistence-modules/java-jpa - persistence-modules/java-jpa-2 - persistence-modules/java-mongodb - persistence-modules/jnosql vaadin vavr @@ -977,20 +882,23 @@ parent-spring-5 parent-java parent-kotlin - + + akka-http akka-streams + algorithms-genetic algorithms-miscellaneous-1 algorithms-miscellaneous-2 algorithms-miscellaneous-3 algorithms-miscellaneous-4 algorithms-miscellaneous-5 + algorithms-searching algorithms-sorting algorithms-sorting-2 - algorithms-searching animal-sniffer-mvn-plugin annotations antlr + apache-avro apache-bval apache-curator @@ -1011,90 +919,39 @@ apache-tika apache-velocity apache-zookeeper + asciidoctor asm + atomix + aws aws-lambda + aws-reactive + axon + azure + bazel + blade bootique cas cdi checker-plugin - cloud-foundry-uaa/cf-uaa-oauth2-client - cloud-foundry-uaa/cf-uaa-oauth2-resource-server + + cloud-foundry-uaa code-generation + core-groovy core-groovy-2 core-groovy-collections - - - core-java-modules/core-java-8 - core-java-modules/core-java-8-2 - core-java-modules/core-java-annotations - core-java-modules/core-java-streams - core-java-modules/core-java-streams-2 - core-java-modules/core-java-streams-3 - - core-java-modules/core-java-function - core-java-modules/core-java-lang-math - - - core-java-modules/core-java-text - - - core-java-modules/core-java-arrays - core-java-modules/core-java-arrays-2 - core-java-modules/core-java-collections - core-java-modules/core-java-collections-2 - core-java-modules/core-java-collections-3 - core-java-modules/core-java-collections-list - core-java-modules/core-java-collections-list-2 - core-java-modules/core-java-collections-list-3 - core-java-modules/core-java-collections-array-list - core-java-modules/core-java-collections-set - core-java-modules/core-java-concurrency-basic - core-java-modules/core-java-concurrency-basic-2 - core-java-modules/core-java-concurrency-collections - core-java-modules/core-java-io - core-java-modules/core-java-io-2 - core-java-modules/core-java-io-apis - core-java-modules/core-java-io-conversions - core-java-modules/core-java-nio - core-java-modules/core-java-nio-2 - core-java-modules/core-java-security - core-java-modules/core-java-exceptions - core-java-modules/core-java-lang-syntax - core-java-modules/core-java-lang-syntax-2 - core-java-modules/core-java-lang - core-java-modules/core-java-lang-2 - core-java-modules/core-java-lang-oop - core-java-modules/core-java-lang-oop-2 - core-java-modules/core-java-lang-oop-3 - core-java-modules/core-java-lang-oop-4 + core-java-modules - core-java-modules/core-java-networking - core-java-modules/core-java-perf - core-java-modules/core-java-sun - core-java-modules/core-java-string-conversions - core-java-modules/core-java-string-conversions-2 - core-java-modules/core-java-string-operations - core-java-modules/core-java-string-operations-2 - core-java-modules/core-java-string-algorithms - core-java-modules/core-java-string-algorithms-2 - core-java-modules/core-java-string-apis - core-java-modules/core-java-strings core-kotlin-modules core-scala + couchbase custom-pmd @@ -1116,15 +973,16 @@ google-cloud google-web-toolkit + graphql/graphql-java grpc gson guava - guava-io guava-collections guava-collections-map guava-collections-set + guava-io guava-modules guice @@ -1139,15 +997,19 @@ immutables jackson-modules + java-blockchain + java-collections-conversions java-collections-conversions-2 java-collections-maps java-collections-maps-2 + + + javafx java-jdi - java-ee-8-security-api java-lite java-math - java-math-2 + java-math-2 java-numbers java-numbers-2 java-numbers-3 @@ -1155,12 +1017,10 @@ java-spi java-vavr-stream java-websocket - javafx javax-servlets javaxval jaxb - + jee-7 jee-7-security jee-kotlin jersey @@ -1181,50 +1041,52 @@ kotlin-libraries + kotlin-libraries-2 + kotlin-quasar - libraries + libraries-2 libraries-3 + libraries-apache-commons + libraries-apache-commons-collections + libraries-apache-commons-io libraries-data libraries-data-2 libraries-data-db libraries-data-io - libraries-apache-commons - libraries-apache-commons-collections - libraries-apache-commons-io - libraries-testing + libraries-http + libraries-io + libraries-primitive libraries-security libraries-server - libraries-http + libraries-testing linkrest logging-modules lombok + lombok-custom lucene + machine-learning mapstruct - - maven-all/maven - maven-all/maven-custom-plugin/counter-maven-plugin - maven-all/maven-war-plugin - maven-all/profiles - maven-all/versions-maven-plugin - + + maven-all maven-archetype - - maven-polyglot/maven-polyglot-json-extension - + + maven-polyglot + mesos-marathon metrics - + micronaut microprofile msf4j - + mustache mybatis - ninja netflix-modules + ninja + oauth2-framework-impl optaplanner orika osgi @@ -1232,10 +1094,12 @@ patterns pdf performance-tests + persistence-modules protobuffer - persistence-modules + quarkus + rabbitmq @@ -1243,20 +1107,12 @@ reactor-core resteasy restx - - rule-engines rsocket + rule-engines rxjava-core + rxjava-libraries rxjava-observables rxjava-operators - rxjava-libraries - oauth2-framework-impl - spf4j - spring-boot-performance - spring-boot-properties - spring-mvc-basics - - @@ -1292,7 +1148,10 @@ parent-kotlin saas + software-security/sql-injection-samples + spark-java + spf4j spring-4 @@ -1305,48 +1164,64 @@ spring-5-reactive-oauth spring-5-reactive-security spring-5-security - spring-5-security-oauth spring-5-security-cognito + spring-5-security-oauth + spring-5-webflux + spring-activiti spring-akka spring-amqp spring-aop spring-apache-camel + spring-batch spring-bom spring-boot spring-boot-admin spring-boot-angular + spring-boot-artifacts spring-boot-autoconfiguration spring-boot-bootstrap spring-boot-camel spring-boot-client + spring-boot-config-jpa-error spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter + spring-boot-data + spring-boot-deployment + spring-boot-di + spring-boot-environment + spring-boot-flowable spring-boot-jasypt spring-boot-keycloak + spring-boot-kotlin + spring-boot-libraries spring-boot-logging-log4j2 spring-boot-mvc + spring-boot-mvc-2 spring-boot-mvc-birt - spring-boot-environment - spring-boot-deployment + spring-boot-nashorn + spring-boot-parent + spring-boot-performance + spring-boot-properties + spring-boot-property-exp + + spring-boot-rest spring-boot-runtime spring-boot-runtime/disabling-console-jul spring-boot-runtime/disabling-console-log4j2 spring-boot-runtime/disabling-console-logback - spring-boot-artifacts - spring-boot-rest - spring-boot-data - spring-boot-parent - spring-boot-property-exp spring-boot-security spring-boot-springdoc + spring-boot-testing spring-boot-vue + spring-caching + spring-cloud spring-cloud-bus @@ -1359,9 +1234,9 @@ spring-data-rest spring-data-rest-querydsl + spring-di spring-dispatcher-servlet spring-drools - spring-di spring-ehcache spring-ejb @@ -1386,60 +1261,41 @@ spring-mobile spring-mockito - spring-websockets + + spring-mvc-basics + spring-mvc-basics-2 + spring-mvc-basics-3 + spring-mvc-basics-4 + spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java spring-mvc-kotlin - spring-mvc-basics-2 - spring-mvc-basics-3 - spring-mvc-basics-4 - spring-mvc-views + spring-mvc-velocity + spring-mvc-views spring-mvc-webflow spring-mvc-xml spring-protobuf - - spring-quartz spring-reactive-kotlin spring-reactor spring-remoting - spring-rest-http spring-rest-angular spring-rest-compress - spring-rest-testing spring-rest-hal-browser + spring-rest-http spring-rest-query-language spring-rest-shell spring-rest-simple spring-resttemplate - + spring-rest-testing + spring-roo spring-scheduling - spring-security-modules/spring-security-acl - spring-security-modules/spring-security-angular/server - spring-security-modules/spring-security-cache-control - spring-security-modules/spring-security-core - spring-security-modules/spring-security-mvc - spring-security-modules/spring-security-mvc-boot - spring-security-modules/spring-security-mvc-custom - spring-security-modules/spring-security-mvc-digest-auth - spring-security-modules/spring-security-mvc-ldap - spring-security-modules/spring-security-mvc-login - spring-security-modules/spring-security-mvc-persisted-remember-me - spring-security-modules/spring-security-mvc-socket - spring-security-modules/spring-security-oidc - - spring-security-modules/spring-security-rest - spring-security-modules/spring-security-rest-basic-auth - spring-security-modules/spring-security-rest-custom - spring-security-modules/spring-security-sso - spring-security-modules/spring-security-stormpath - spring-security-modules/spring-security-thymeleaf - spring-security-modules/spring-security-x509 + spring-security-modules spring-session spring-shell spring-sleuth @@ -1451,17 +1307,20 @@ spring-swagger-codegen spring-thymeleaf + spring-thymeleaf-2 spring-vault spring-vertx spring-webflux-amqp + spring-websockets static-analysis stripe structurizr struts-2 + tensorflow-java testing-modules twilio @@ -1474,8 +1333,9 @@ video-tutorials vraptor + webrtc wicket - + wildfly xml xstream @@ -1512,11 +1372,6 @@ parent-java parent-kotlin - core-java-modules/core-java - core-java-modules/core-java-jar - core-java-modules/core-java-concurrency-advanced - core-java-modules/core-java-concurrency-advanced-2 - core-java-modules/core-java-concurrency-advanced-3 core-kotlin core-kotlin-2 @@ -1526,13 +1381,6 @@ libraries - persistence-modules/hibernate5 - persistence-modules/hibernate-mapping - persistence-modules/java-jpa - persistence-modules/java-jpa-2 - persistence-modules/java-mongodb - persistence-modules/jnosql - vaadin vavr diff --git a/slack/pom.xml b/slack/pom.xml new file mode 100644 index 0000000000..ebe5ce2f60 --- /dev/null +++ b/slack/pom.xml @@ -0,0 +1,61 @@ + + + 4.0.0 + com.baeldung.examples + slack + 1.0 + slack + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + com.hubspot.slack + slack-base + ${slack.version} + + + com.hubspot.slack + slack-java-client + ${slack.version} + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + + true + com.baeldung.examples.slack.MainClass + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.baeldung.examples.slack.MainClass + + + + + + + 1.4 + 2.4 + + + diff --git a/slack/src/main/java/com/baeldung/examples/slack/DiskSpaceErrorChecker.java b/slack/src/main/java/com/baeldung/examples/slack/DiskSpaceErrorChecker.java new file mode 100644 index 0000000000..7a3f5cd607 --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/DiskSpaceErrorChecker.java @@ -0,0 +1,42 @@ +package com.baeldung.examples.slack; + +import java.io.IOException; +import java.nio.file.FileSystems; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DiskSpaceErrorChecker implements ErrorChecker { + private static final Logger LOG = LoggerFactory.getLogger(DiskSpaceErrorChecker.class); + + private final ErrorReporter errorReporter; + + private final double limit; + + public DiskSpaceErrorChecker(ErrorReporter errorReporter, double limit) { + this.errorReporter = errorReporter; + this.limit = limit; + } + + @Override + public void check() { + LOG.info("Checking disk space"); + FileSystems.getDefault().getFileStores().forEach(fileStore -> { + try { + long totalSpace = fileStore.getTotalSpace(); + long usableSpace = fileStore.getUsableSpace(); + double usablePercentage = ((double) usableSpace) / totalSpace; + LOG.debug("File store {} has {} of {} ({}) usable space", + fileStore, usableSpace, totalSpace, usablePercentage); + + if (totalSpace > 0 && usablePercentage < limit) { + String error = String.format("File store %s only has %d%% usable disk space", + fileStore.name(), (int)(usablePercentage * 100)); + errorReporter.reportProblem(error); + } + } catch (IOException e) { + LOG.error("Error getting disk space for file store {}", fileStore, e); + } + }); + } +} diff --git a/slack/src/main/java/com/baeldung/examples/slack/ErrorChecker.java b/slack/src/main/java/com/baeldung/examples/slack/ErrorChecker.java new file mode 100644 index 0000000000..08db9a7817 --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/ErrorChecker.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.slack; + +public interface ErrorChecker { + void check(); +} diff --git a/slack/src/main/java/com/baeldung/examples/slack/ErrorReporter.java b/slack/src/main/java/com/baeldung/examples/slack/ErrorReporter.java new file mode 100644 index 0000000000..ba6165af9b --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/ErrorReporter.java @@ -0,0 +1,5 @@ +package com.baeldung.examples.slack; + +public interface ErrorReporter { + void reportProblem(String problem); +} diff --git a/slack/src/main/java/com/baeldung/examples/slack/MainClass.java b/slack/src/main/java/com/baeldung/examples/slack/MainClass.java new file mode 100644 index 0000000000..ac25e97cf6 --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/MainClass.java @@ -0,0 +1,41 @@ +package com.baeldung.examples.slack; + +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import com.hubspot.slack.client.SlackClient; +import com.hubspot.slack.client.SlackClientFactory; +import com.hubspot.slack.client.SlackClientRuntimeConfig; + +public class MainClass { + public static final long MINUTES = 1000 * 60; + + public static void main(String[] args) throws IOException { + SlackClientRuntimeConfig runtimeConfig = SlackClientRuntimeConfig.builder() + .setTokenSupplier(() -> "") + .build(); + + SlackClient slackClient = SlackClientFactory.defaultFactory().build(runtimeConfig); + + ErrorReporter slackChannelErrorReporter = new SlackChannelErrorReporter(slackClient, "general"); + ErrorReporter slackUserErrorReporter = new SlackUserErrorReporter(slackClient, "testuser@baeldung.com"); + + ErrorChecker diskSpaceErrorChecker10pct = new DiskSpaceErrorChecker(slackChannelErrorReporter, 0.1); + ErrorChecker diskSpaceErrorChecker2pct = new DiskSpaceErrorChecker(slackUserErrorReporter, 0.02); + + Timer timer = new Timer(); + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + diskSpaceErrorChecker10pct.check(); + } + }, 0, 5 * MINUTES); + timer.scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + diskSpaceErrorChecker2pct.check(); + } + }, 0, 5 * MINUTES); + } +} diff --git a/slack/src/main/java/com/baeldung/examples/slack/SlackChannelErrorReporter.java b/slack/src/main/java/com/baeldung/examples/slack/SlackChannelErrorReporter.java new file mode 100644 index 0000000000..f7abcecc2e --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/SlackChannelErrorReporter.java @@ -0,0 +1,30 @@ +package com.baeldung.examples.slack; + +import com.hubspot.slack.client.SlackClient; +import com.hubspot.slack.client.methods.params.chat.ChatPostMessageParams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SlackChannelErrorReporter implements ErrorReporter { + private static final Logger LOG = LoggerFactory.getLogger(SlackChannelErrorReporter.class); + + private final SlackClient slackClient; + + private final String channel; + + public SlackChannelErrorReporter(SlackClient slackClient, String channel) { + this.slackClient = slackClient; + this.channel = channel; + } + + @Override + public void reportProblem(String problem) { + LOG.debug("Sending message to channel {}: {}", channel, problem); + slackClient.postMessage( + ChatPostMessageParams.builder() + .setText(problem) + .setChannelId(channel) + .build() + ).join().unwrapOrElseThrow(); + } +} diff --git a/slack/src/main/java/com/baeldung/examples/slack/SlackUserErrorReporter.java b/slack/src/main/java/com/baeldung/examples/slack/SlackUserErrorReporter.java new file mode 100644 index 0000000000..8fa4f9016b --- /dev/null +++ b/slack/src/main/java/com/baeldung/examples/slack/SlackUserErrorReporter.java @@ -0,0 +1,52 @@ +package com.baeldung.examples.slack; + +import java.util.List; + +import com.hubspot.slack.client.SlackClient; +import com.hubspot.slack.client.methods.params.chat.ChatPostMessageParams; +import com.hubspot.slack.client.methods.params.conversations.ConversationCreateParams; +import com.hubspot.slack.client.methods.params.im.ImOpenParams; +import com.hubspot.slack.client.methods.params.users.UserEmailParams; +import com.hubspot.slack.client.methods.params.users.UsersInfoParams; +import com.hubspot.slack.client.models.response.im.ImOpenResponse; +import com.hubspot.slack.client.models.response.users.UsersInfoResponse; +import com.hubspot.slack.client.models.users.SlackUser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SlackUserErrorReporter implements ErrorReporter { + private static final Logger LOG = LoggerFactory.getLogger(SlackUserErrorReporter.class); + + private final SlackClient slackClient; + + private final String user; + + public SlackUserErrorReporter(SlackClient slackClient, String user) { + this.slackClient = slackClient; + this.user = user; + } + + @Override + public void reportProblem(String problem) { + LOG.debug("Sending message to user {}: {}", user, problem); + UsersInfoResponse usersInfoResponse = slackClient + .lookupUserByEmail(UserEmailParams.builder() + .setEmail(user) + .build() + ).join().unwrapOrElseThrow(); + + ImOpenResponse imOpenResponse = slackClient.openIm(ImOpenParams.builder() + .setUserId(usersInfoResponse.getUser().getId()) + .build() + ).join().unwrapOrElseThrow(); + + imOpenResponse.getChannel().ifPresent(channel -> { + slackClient.postMessage( + ChatPostMessageParams.builder() + .setText(problem) + .setChannelId(channel.getId()) + .build() + ).join().unwrapOrElseThrow(); + }); + } +} diff --git a/slack/src/main/resources/logback.xml b/slack/src/main/resources/logback.xml new file mode 100644 index 0000000000..c8c077ba1d --- /dev/null +++ b/slack/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-gateway/pom.xml b/spring-cloud/spring-cloud-gateway/pom.xml index 10cd49cc04..0f62c031cf 100644 --- a/spring-cloud/spring-cloud-gateway/pom.xml +++ b/spring-cloud/spring-cloud-gateway/pom.xml @@ -68,6 +68,10 @@ spring-boot-starter-test test
+ + org.springframework.boot + spring-boot-devtools +
diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java new file mode 100644 index 0000000000..e209b6cdf0 --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.springcloudgateway.custompredicates; + +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; + +@SpringBootApplication +public class CustomPredicatesApplication { + + public static void main(String[] args) { + new SpringApplicationBuilder(CustomPredicatesApplication.class) + .profiles("customroutes") + .run(args); + } + +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java new file mode 100644 index 0000000000..0e88b29bcf --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/config/CustomPredicatesConfig.java @@ -0,0 +1,38 @@ +package com.baeldung.springcloudgateway.custompredicates.config; + +import org.springframework.cloud.gateway.filter.GatewayFilter; +import org.springframework.cloud.gateway.route.RouteLocator; +import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import com.baeldung.springcloudgateway.custompredicates.factories.GoldenCustomerRoutePredicateFactory; +import com.baeldung.springcloudgateway.custompredicates.factories.GoldenCustomerRoutePredicateFactory.Config; +import com.baeldung.springcloudgateway.custompredicates.service.GoldenCustomerService; + +@Configuration +public class CustomPredicatesConfig { + + + @Bean + public GoldenCustomerRoutePredicateFactory goldenCustomer(GoldenCustomerService goldenCustomerService) { + return new GoldenCustomerRoutePredicateFactory(goldenCustomerService); + } + + + //@Bean + public RouteLocator routes(RouteLocatorBuilder builder, GoldenCustomerRoutePredicateFactory gf ) { + + return builder.routes() + .route("dsl_golden_route", r -> r.path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + .predicate(gf.apply(new Config(true, "customerId")))) + .route("dsl_common_route", r -> r.path("/dsl_api/**") + .filters(f -> f.stripPrefix(1)) + .uri("https://httpbin.org") + .predicate(gf.apply(new Config(false, "customerId")))) + .build(); + } + +} diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java new file mode 100644 index 0000000000..cb5c3a0b50 --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/factories/GoldenCustomerRoutePredicateFactory.java @@ -0,0 +1,102 @@ +/** + * + */ +package com.baeldung.springcloudgateway.custompredicates.factories; + +import java.util.Arrays; +import java.util.List; +import java.util.function.Predicate; + +import javax.validation.constraints.NotEmpty; + +import org.springframework.cloud.gateway.handler.predicate.AbstractRoutePredicateFactory; +import org.springframework.http.HttpCookie; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.server.ServerWebExchange; + +import com.baeldung.springcloudgateway.custompredicates.service.GoldenCustomerService; + +/** + * @author Philippe + * + */ +public class GoldenCustomerRoutePredicateFactory extends AbstractRoutePredicateFactory { + + private final GoldenCustomerService goldenCustomerService; + + public GoldenCustomerRoutePredicateFactory(GoldenCustomerService goldenCustomerService ) { + super(Config.class); + this.goldenCustomerService = goldenCustomerService; + } + + + @Override + public List shortcutFieldOrder() { + return Arrays.asList("isGolden","customerIdCookie"); + } + + + @Override + public Predicate apply(Config config) { + + return (ServerWebExchange t) -> { + List cookies = t.getRequest() + .getCookies() + .get(config.getCustomerIdCookie()); + + boolean isGolden; + if ( cookies == null || cookies.isEmpty()) { + isGolden = false; + } + else { + String customerId = cookies.get(0).getValue(); + isGolden = goldenCustomerService.isGoldenCustomer(customerId); + } + + return config.isGolden()?isGolden:!isGolden; + }; + } + + + @Validated + public static class Config { + boolean isGolden = true; + + @NotEmpty + String customerIdCookie = "customerId"; + + + public Config() {} + + public Config( boolean isGolden, String customerIdCookie) { + this.isGolden = isGolden; + this.customerIdCookie = customerIdCookie; + } + + public boolean isGolden() { + return isGolden; + } + + public void setGolden(boolean value) { + this.isGolden = value; + } + + /** + * @return the customerIdCookie + */ + public String getCustomerIdCookie() { + return customerIdCookie; + } + + /** + * @param customerIdCookie the customerIdCookie to set + */ + public void setCustomerIdCookie(String customerIdCookie) { + this.customerIdCookie = customerIdCookie; + } + + + + } + +} diff --git a/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java new file mode 100644 index 0000000000..82bf2e6ae9 --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/main/java/com/baeldung/springcloudgateway/custompredicates/service/GoldenCustomerService.java @@ -0,0 +1,26 @@ +/** + * + */ +package com.baeldung.springcloudgateway.custompredicates.service; + +import org.springframework.stereotype.Component; + +/** + * @author Philippe + * + */ +@Component +public class GoldenCustomerService { + + public boolean isGoldenCustomer(String customerId) { + + // TODO: Add some AI logic to check is this customer deserves a "golden" status ;^) + if ( "baeldung".equalsIgnoreCase(customerId)) { + return true; + } + else { + return false; + } + } + +} diff --git a/spring-cloud/spring-cloud-gateway/src/main/resources/application-customroutes.yml b/spring-cloud/spring-cloud-gateway/src/main/resources/application-customroutes.yml new file mode 100644 index 0000000000..859aa60bda --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/main/resources/application-customroutes.yml @@ -0,0 +1,26 @@ +spring: + cloud: + gateway: + routes: + - id: golden_route + uri: https://httpbin.org + predicates: + - Path=/api/** + - GoldenCustomer=true + filters: + - StripPrefix=1 + - AddRequestHeader=GoldenCustomer,true + - id: common_route + uri: https://httpbin.org + predicates: + - Path=/api/** + - name: GoldenCustomer + args: + golden: false + customerIdCookie: customerId + filters: + - StripPrefix=1 + - AddRequestHeader=GoldenCustomer,false + + + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java b/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java index a4bb3f8068..f49f8c68b6 100644 --- a/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java +++ b/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/customfilters/gatewayapp/CustomFiltersLiveTest.java @@ -5,6 +5,7 @@ import static org.assertj.core.api.Assertions.assertThat; import org.assertj.core.api.Condition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; @@ -27,6 +28,7 @@ public class CustomFiltersLiveTest { @LocalServerPort String port; + @Autowired private WebTestClient client; @BeforeEach diff --git a/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java b/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java new file mode 100644 index 0000000000..d9988ceb5e --- /dev/null +++ b/spring-cloud/spring-cloud-gateway/src/test/java/com/baeldung/springcloudgateway/custompredicates/CustomPredicatesApplicationLiveTest.java @@ -0,0 +1,67 @@ +package com.baeldung.springcloudgateway.custompredicates; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +import java.net.URI; + +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONTokener; +import org.junit.Before; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.http.HttpStatus; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; + +/** + * This test requires + */ +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ActiveProfiles("customroutes") +public class CustomPredicatesApplicationLiveTest { + + @LocalServerPort + String serverPort; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + void givenNormalCustomer_whenCallHeadersApi_thenResponseForNormalCustomer() throws JSONException { + + String url = "http://localhost:" + serverPort + "/api/headers"; + ResponseEntity response = restTemplate.getForEntity(url, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject headers = json.getJSONObject("headers"); + assertThat(headers.getString("Goldencustomer")).isEqualTo("false"); + + } + + @Test + void givenGoldenCustomer_whenCallHeadersApi_thenResponseForGoldenCustomer() throws JSONException { + + String url = "http://localhost:" + serverPort + "/api/headers"; + RequestEntity request = RequestEntity + .get(URI.create(url)) + .header("Cookie", "customerId=baeldung") + .build(); + + ResponseEntity response = restTemplate.exchange(request, String.class); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + + JSONObject json = new JSONObject(response.getBody()); + JSONObject headers = json.getJSONObject("headers"); + assertThat(headers.getString("Goldencustomer")).isEqualTo("true"); + + } + +} diff --git a/spring-roo/pom.xml b/spring-roo/pom.xml index 456642b1f0..448574ed19 100644 --- a/spring-roo/pom.xml +++ b/spring-roo/pom.xml @@ -413,7 +413,7 @@ spring-roo-repository Spring Roo Repository - http://repo.spring.io/spring-roo + https://repo.spring.io/spring-roo diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml new file mode 100644 index 0000000000..168fab85c0 --- /dev/null +++ b/spring-security-modules/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + spring-security-modules + 0.0.1-SNAPSHOT + spring-security-modules + pom + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + spring-security-acl + spring-security-angular/server + spring-security-cache-control + spring-security-core + spring-security-cors + spring-security-kerberos + spring-security-mvc + spring-security-mvc-boot + spring-security-mvc-custom + spring-security-mvc-digest-auth + spring-security-mvc-jsonview + spring-security-mvc-ldap + spring-security-mvc-login + spring-security-mvc-persisted-remember-me + spring-security-mvc-socket + spring-security-oidc + + + spring-security-rest + spring-security-rest-basic-auth + spring-security-rest-custom + spring-security-sso + spring-security-stormpath + spring-security-thymeleaf + spring-security-x509 + + + diff --git a/spring-security-modules/spring-security-cors/pom.xml b/spring-security-modules/spring-security-cors/pom.xml index 91e8f5adb6..2acb99368f 100644 --- a/spring-security-modules/spring-security-cors/pom.xml +++ b/spring-security-modules/spring-security-cors/pom.xml @@ -3,15 +3,14 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-security-cors - 0.0.1-SNAPSHOT spring-security-cors jar Spring Security CORS com.baeldung - parent-modules - 1.0.0-SNAPSHOT + spring-security-modules + 0.0.1-SNAPSHOT diff --git a/spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerTest.java b/spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerUnitTest.java similarity index 97% rename from spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerTest.java rename to spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerUnitTest.java index a471eb922f..7567573040 100644 --- a/spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerTest.java +++ b/spring-security-modules/spring-security-cors/src/test/java/com/baeldung/springbootsecuritycors/ResourceControllerUnitTest.java @@ -18,7 +18,7 @@ import com.baeldung.springbootsecuritycors.basicauth.SpringBootSecurityApplicati @RunWith(SpringRunner.class) @SpringBootTest(classes = { SpringBootSecurityApplication.class }) -public class ResourceControllerTest { +public class ResourceControllerUnitTest { private MockMvc mockMvc; diff --git a/spring-security-sso/spring-security-sso-auth-server/README.md b/spring-security-sso/spring-security-sso-auth-server/README.md deleted file mode 100644 index 845fb50a93..0000000000 --- a/spring-security-sso/spring-security-sso-auth-server/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles - -- [Simple Single Sign-On with Spring Security OAuth2](https://www.baeldung.com/sso-spring-security-oauth2) diff --git a/spring-security-sso/spring-security-sso-ui-2/README.md b/spring-security-sso/spring-security-sso-ui-2/README.md deleted file mode 100644 index aed217bdf0..0000000000 --- a/spring-security-sso/spring-security-sso-ui-2/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Simple Single Sign-On with Spring Security OAuth2](https://www.baeldung.com/sso-spring-security-oauth2) diff --git a/spring-security-sso/spring-security-sso-ui/README.md b/spring-security-sso/spring-security-sso-ui/README.md deleted file mode 100644 index 845fb50a93..0000000000 --- a/spring-security-sso/spring-security-sso-ui/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles - -- [Simple Single Sign-On with Spring Security OAuth2](https://www.baeldung.com/sso-spring-security-oauth2)