diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml
index 0fec5d0175..c2ed19b401 100644
--- a/animal-sniffer-mvn-plugin/pom.xml
+++ b/animal-sniffer-mvn-plugin/pom.xml
@@ -26,14 +26,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
org.codehaus.mojo
animal-sniffer-maven-plugin
diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml
index b5219d57ba..7dabe7a9a7 100644
--- a/annotations/annotation-processing/pom.xml
+++ b/annotations/annotation-processing/pom.xml
@@ -19,32 +19,11 @@
-
com.google.auto.service
auto-service
${auto-service.version}
provided
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml
index 1b9ba22230..c584fcfe5b 100644
--- a/apache-cxf/cxf-introduction/pom.xml
+++ b/apache-cxf/cxf-introduction/pom.xml
@@ -25,15 +25,6 @@
com.baeldung.cxf.introduction.Server
-
- maven-surefire-plugin
- ${surefire.version}
-
-
- **/*LiveTest.java
-
-
-
diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml
index 981e0ef7aa..32b93c9e78 100644
--- a/apache-cxf/cxf-jaxrs-implementation/pom.xml
+++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml
@@ -27,15 +27,6 @@
com.baeldung.cxf.jaxrs.implementation.RestfulServer
-
- maven-surefire-plugin
- ${surefire.version}
-
-
- **/*LiveTest.java
-
-
-
diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml
index 2cd700680b..9bfc2dd889 100644
--- a/apache-cxf/cxf-spring/pom.xml
+++ b/apache-cxf/cxf-spring/pom.xml
@@ -52,15 +52,6 @@
false
-
- maven-surefire-plugin
- ${surefire.version}
-
-
- **/*LiveTest.java
-
-
-
@@ -102,24 +93,6 @@
-
-
- maven-surefire-plugin
- ${surefire.version}
-
-
- integration-test
-
- test
-
-
-
- none
-
-
-
-
-
diff --git a/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java b/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java
index d9c18862e8..5eb649dae1 100644
--- a/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java
+++ b/apache-opennlp/src/test/java/com/baeldung/apache/opennlp/LanguageDetectorAndTrainingDataTest.java
@@ -16,6 +16,7 @@ import opennlp.tools.util.ObjectStream;
import opennlp.tools.util.PlainTextByLineStream;
import opennlp.tools.util.TrainingParameters;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.tuple;
import org.junit.Test;
public class LanguageDetectorAndTrainingDataTest {
@@ -35,7 +36,9 @@ public class LanguageDetectorAndTrainingDataTest {
LanguageDetector ld = new LanguageDetectorME(model);
Language[] languages = ld.predictLanguages("estava em uma marcenaria na Rua Bruno");
- assertThat(Arrays.asList(languages).toString()).contains("pob (0.9999999950605625)", "ita (4.939427661577956E-9)", "spa (9.665954064665144E-15)",
- "fra (8.250349924885834E-25)");
+
+ assertThat(Arrays.asList(languages)).extracting("lang", "confidence").contains(tuple("pob", 0.9999999950605625),
+ tuple("ita", 4.939427661577956E-9), tuple("spa", 9.665954064665144E-15),
+ tuple("fra", 8.250349924885834E-25));
}
}
diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml
index 2f94987b11..e53e115ddd 100644
--- a/apache-spark/pom.xml
+++ b/apache-spark/pom.xml
@@ -32,17 +32,4 @@
test
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
diff --git a/atomix/pom.xml b/atomix/pom.xml
index 80c573dd86..0ecdf8987d 100644
--- a/atomix/pom.xml
+++ b/atomix/pom.xml
@@ -29,18 +29,4 @@
1.2.17
-
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
-
-
diff --git a/aws/pom.xml b/aws/pom.xml
index c62b1b9913..34870bb736 100644
--- a/aws/pom.xml
+++ b/aws/pom.xml
@@ -24,6 +24,8 @@
3.8.0
1.11.86
https://s3-us-west-2.amazonaws.com/dynamodb-local/release
+ 1.10.L001
+ 0.9.4.0006L
@@ -97,6 +99,19 @@
${dynamodblocal.version}
test
+
+
+
+ org.lucee
+ jets3t
+ ${jets3t-version}
+
+
+ org.lucee
+ commons-codec
+ ${commons-codec-version}
+
+
diff --git a/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java
new file mode 100644
index 0000000000..cf0b203e10
--- /dev/null
+++ b/aws/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java
@@ -0,0 +1,351 @@
+package com.baeldung.jets3t;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jets3t.service.S3Service;
+import org.jets3t.service.ServiceException;
+import org.jets3t.service.impl.rest.httpclient.RestS3Service;
+import org.jets3t.service.model.S3Bucket;
+import org.jets3t.service.model.S3Object;
+import org.jets3t.service.model.StorageObject;
+import org.jets3t.service.security.AWSCredentials;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
+import static junit.framework.TestCase.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class JetS3tLiveTest {
+
+ private Log log = LogFactory.getLog(JetS3tLiveTest.class);
+
+ private static final String BucketName = "baeldung-barfoo";
+ private static final String TestString = "test string";
+ private static final String TestStringName = "string object";
+ private static final String TgtBucket = "baeldung-tgtbucket";
+
+ private static S3Service s3Service;
+
+ @BeforeClass
+ public static void connectS3() throws Exception {
+
+ // Replace with your keys
+ String awsAccessKey = "your access key";
+ String awsSecretKey = "your secret key";
+
+ // Create credentials
+ AWSCredentials awsCredentials = new AWSCredentials(awsAccessKey, awsSecretKey);
+
+ // Create service
+ s3Service = new RestS3Service(awsCredentials);
+ }
+
+ @Test
+ public void givenCreate_AndDeleteBucket_CountGoesUpThenDown() throws Exception {
+
+ // List buckets, get a count
+ S3Bucket[] myBuckets = s3Service.listAllBuckets();
+ int count = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size();
+
+ // Create a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // List again
+ myBuckets = s3Service.listAllBuckets();
+ int newCount = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size();
+
+ // We should have one more
+ assertEquals((count + 1), newCount);
+
+ // Delete so next test doesn't fail
+ deleteBucket();
+
+ // Check the count again, just for laughs
+ myBuckets = s3Service.listAllBuckets();
+ newCount = Arrays.stream(myBuckets).map(S3Bucket::getName).collect(Collectors.toList()).size();
+ assertEquals(count, newCount);
+
+ }
+
+ private S3Bucket createBucket() throws Exception {
+ S3Bucket bucket = s3Service.createBucket(BucketName);
+ log.info(bucket);
+ return bucket;
+ }
+
+
+ private void deleteBucket() throws ServiceException {
+ s3Service.deleteBucket(BucketName);
+ }
+
+ @Test
+ public void givenString_Uploaded_StringInfoIsAvailable() throws Exception {
+
+ // Create a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // Upload a string
+ uploadStringData();
+
+ // Get the details
+ StorageObject objectDetailsOnly = s3Service.getObjectDetails(BucketName, TestStringName);
+ log.info("Content type: " + objectDetailsOnly.getContentType() + " length: " + objectDetailsOnly.getContentLength());
+
+ // Delete it
+ deleteObject(TestStringName);
+
+ // For next test
+ deleteBucket();
+ }
+
+ private void uploadStringData() throws Exception {
+ S3Object stringObject = new S3Object(TestStringName, TestString);
+ s3Service.putObject(BucketName, stringObject);
+ log.info("Content type:" + stringObject.getContentType());
+ }
+
+ private void deleteObject(String objectName) throws ServiceException {
+ s3Service.deleteObject(BucketName, objectName);
+ }
+
+ @Test
+ public void givenStringUploaded_StringIsDownloaded() throws Exception {
+
+ // Get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ uploadStringData();
+
+ // Download
+ S3Object stringObject = s3Service.getObject(BucketName, TestStringName);
+
+ // Process stream into a string
+ String downloadedString = new BufferedReader(new InputStreamReader(stringObject.getDataInputStream())).lines().collect(Collectors.joining("\n"));
+
+ // Verify
+ assertTrue(TestString.equals(downloadedString));
+
+
+ // Clean up for next test
+ deleteObject(TestStringName);
+ deleteBucket();
+ }
+
+ @Test
+ public void givenBinaryFileUploaded_FileIsDownloaded() throws Exception {
+
+ // get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // Put a binary file
+ S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
+ s3Service.putObject(BucketName, fileObject);
+
+ // Print info about type and name
+ log.info("Content type:" + fileObject.getContentType());
+ log.info("File object name is " + fileObject.getName());
+
+ // Download
+ S3Object newFileObject = s3Service.getObject(BucketName, "test.jpg");
+
+ // Save to a different name
+ File newFile = new File("src/test/resources/newtest.jpg");
+ Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
+
+
+ // Get hashes and compare
+ String origMD5 = getFileMD5("src/test/resources/test.jpg");
+ String newMD5 = getFileMD5("src/test/resources/newtest.jpg");
+ assertTrue(origMD5.equals(newMD5));
+
+ // Clean up
+ deleteObject("test.jpg");
+ deleteBucket();
+ }
+
+ // Get MD5 hash for a file
+ private String getFileMD5(String filename) throws IOException {
+ try (FileInputStream fis = new FileInputStream(new File(filename))) {
+ return DigestUtils.md5Hex(fis);
+ }
+ }
+
+
+
+ @Test
+ public void givenStreamDataUploaded_StreamDataIsDownloaded() throws Exception {
+
+ // get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ ArrayList numbers = new ArrayList<>();
+ numbers.add(2);
+ numbers.add(3);
+ numbers.add(5);
+ numbers.add(7);
+
+ // Serialize ArrayList
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes);
+ objectOutputStream.writeObject(numbers);
+
+ // Wrap bytes
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray());
+
+ // Create and populate object
+ S3Object streamObject = new S3Object("stream");
+ streamObject.setDataInputStream(byteArrayInputStream);
+ streamObject.setContentLength(byteArrayInputStream.available());
+ streamObject.setContentType("binary/octet-stream");
+
+ // Put it
+ s3Service.putObject(BucketName, streamObject);
+
+ // Get it
+ S3Object newStreamObject = s3Service.getObject(BucketName, "stream");
+
+ // Convert back to ArrayList
+ ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream());
+ ArrayList newNumbers = (ArrayList)objectInputStream.readObject();
+
+ assertEquals(2, (int)newNumbers.get(0));
+ assertEquals(3, (int)newNumbers.get(1));
+ assertEquals(5, (int)newNumbers.get(2));
+ assertEquals(7, (int)newNumbers.get(3));
+
+ // Clean up
+ deleteObject("stream");
+ deleteBucket();
+ }
+
+ @Test
+ public void whenFileCopied_CopyIsSame() throws Exception {
+
+ // get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // Put a binary file
+ S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
+ s3Service.putObject(BucketName, fileObject);
+
+
+ // Copy it
+ S3Object targetObject = new S3Object("testcopy.jpg");
+ s3Service.copyObject(BucketName, "test.jpg", BucketName, targetObject, false);
+
+
+ // Download
+ S3Object newFileObject = s3Service.getObject(BucketName, "testcopy.jpg");
+
+ // Save to a different name
+ File newFile = new File("src/test/resources/testcopy.jpg");
+ Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
+
+
+ // Get hashes and compare
+ String origMD5 = getFileMD5("src/test/resources/test.jpg");
+ String newMD5 = getFileMD5("src/test/resources/testcopy.jpg");
+ assertTrue(origMD5.equals(newMD5));
+
+ // Clean up
+ deleteObject("test.jpg");
+ deleteObject("testcopy.jpg");
+ deleteBucket();
+
+ }
+
+
+ @Test
+ public void whenFileRenamed_NewNameIsSame() throws Exception {
+
+ // get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // Put a binary file
+ S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
+ s3Service.putObject(BucketName, fileObject);
+
+
+ // Copy it
+ s3Service.renameObject(BucketName, "test.jpg", new S3Object("spidey.jpg"));
+
+
+ // Download
+ S3Object newFileObject = s3Service.getObject(BucketName, "spidey.jpg");
+
+ // Save to a different name
+ File newFile = new File("src/test/resources/spidey.jpg");
+ Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
+
+
+ // Get hashes and compare
+ String origMD5 = getFileMD5("src/test/resources/test.jpg");
+ String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
+ assertTrue(origMD5.equals(newMD5));
+
+ // Clean up
+ deleteObject("test.jpg");
+ deleteObject("spidey.jpg");
+ deleteBucket();
+
+ }
+
+ @Test
+ public void whenFileMoved_NewInstanceIsSame() throws Exception {
+
+ // get a bucket
+ S3Bucket bucket = createBucket();
+ assertNotNull(bucket);
+
+ // create another bucket
+ S3Bucket tgtBucket = s3Service.createBucket(TgtBucket);
+
+
+ // Put a binary file
+ S3Object fileObject = new S3Object(new File("src/test/resources/test.jpg"));
+ s3Service.putObject(BucketName, fileObject);
+
+
+ // Copy it
+ s3Service.moveObject(BucketName, "test.jpg", TgtBucket,
+ new S3Object("spidey.jpg"), false);
+
+
+ // Download
+ S3Object newFileObject = s3Service.getObject(TgtBucket, "spidey.jpg");
+
+ // Save to a different name
+ File newFile = new File("src/test/resources/spidey.jpg");
+ Files.copy(newFileObject.getDataInputStream(), newFile.toPath(), REPLACE_EXISTING);
+
+
+ // Get hashes and compare
+ String origMD5 = getFileMD5("src/test/resources/test.jpg");
+ String newMD5 = getFileMD5("src/test/resources/spidey.jpg");
+ assertTrue(origMD5.equals(newMD5));
+
+ // Clean up
+ deleteBucket();
+
+ s3Service.deleteObject(TgtBucket, "spidey.jpg");
+ s3Service.deleteBucket(TgtBucket);
+ }
+
+
+}
diff --git a/bootique/dependency-reduced-pom.xml b/bootique/dependency-reduced-pom.xml
deleted file mode 100644
index ab09cfb7b1..0000000000
--- a/bootique/dependency-reduced-pom.xml
+++ /dev/null
@@ -1,56 +0,0 @@
-
-
-
- bootique-parent
- io.bootique.parent
- 0.12
-
- 4.0.0
- com.baeldung.bootique
- bootique
- bootique
- 1.0-SNAPSHOT
- http://maven.apache.org
-
-
-
- maven-shade-plugin
-
-
-
-
-
- io.bootique
- bootique-test
- 0.23
- test
-
-
- junit
- junit
- 4.12
- test
-
-
- hamcrest-core
- org.hamcrest
-
-
-
-
-
-
-
- io.bootique.bom
- bootique-bom
- 0.23
- pom
- import
-
-
-
-
- com.baeldung.bootique.App
-
-
-
diff --git a/camel-api/pom.xml b/camel-api/pom.xml
index 3f96e2209c..a1cdb1064e 100644
--- a/camel-api/pom.xml
+++ b/camel-api/pom.xml
@@ -45,14 +45,6 @@
spring-boot:run
-
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
org.springframework.boot
spring-boot-maven-plugin
@@ -71,7 +63,6 @@
UTF-8
3.7.0
- 2.19.1
2.19.1
1.5.4.RELEASE
diff --git a/cas/cas-secured-app/pom.xml b/cas/cas-secured-app/pom.xml
index d52597412e..947aa2f351 100644
--- a/cas/cas-secured-app/pom.xml
+++ b/cas/cas-secured-app/pom.xml
@@ -65,24 +65,6 @@
org.springframework.boot
spring-boot-maven-plugin
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
- 3
- true
-
- **/*IntegrationTest.java
- **/*LongRunningUnitTest.java
- **/*ManualTest.java
- **/JdbcTest.java
- **/*LiveTest.java
-
-
-
-
-
diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml
index 91cbe66e35..e645e95a88 100644
--- a/core-groovy/pom.xml
+++ b/core-groovy/pom.xml
@@ -78,10 +78,6 @@
-
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
maven-failsafe-plugin
2.19.1
diff --git a/core-java-9/pom.xml b/core-java-9/pom.xml
index 40e29af35f..5f07a62e13 100644
--- a/core-java-9/pom.xml
+++ b/core-java-9/pom.xml
@@ -75,13 +75,6 @@
1.9
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
-
diff --git a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java
index 8770cb4e90..731ae887e1 100644
--- a/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java
+++ b/core-java-concurrency/src/test/java/com/baeldung/concurrent/volatilekeyword/SharedObjectManualTest.java
@@ -1,55 +1,36 @@
package com.baeldung.concurrent.volatilekeyword;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import static junit.framework.Assert.assertEquals;
+import static org.junit.Assert.*;
public class SharedObjectManualTest {
- private SharedObject sharedObject;
- private int valueReadByThread2;
- private int valueReadByThread3;
-
- @Before
- public void setUp() {
- sharedObject = new SharedObject();
- }
-
@Test
public void whenOneThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException {
+ SharedObject sharedObject = new SharedObject();
+
Thread writer = new Thread(() -> sharedObject.increamentCount());
writer.start();
-
+ Thread.sleep(100);
Thread readerOne = new Thread(() -> {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- valueReadByThread2 = sharedObject.getCount();
+ int valueReadByThread2 = sharedObject.getCount();
+ assertEquals(1, valueReadByThread2);
});
readerOne.start();
Thread readerTwo = new Thread(() -> {
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- valueReadByThread3 = sharedObject.getCount();
+ int valueReadByThread3 = sharedObject.getCount();
+ assertEquals(1, valueReadByThread3);
});
readerTwo.start();
- assertEquals(1, valueReadByThread2);
- assertEquals(1, valueReadByThread3);
-
}
@Test
public void whenTwoThreadWrites_thenVolatileReadsFromMainMemory() throws InterruptedException {
+ SharedObject sharedObject = new SharedObject();
Thread writerOne = new Thread(() -> sharedObject.increamentCount());
writerOne.start();
Thread.sleep(100);
@@ -58,14 +39,17 @@ public class SharedObjectManualTest {
writerTwo.start();
Thread.sleep(100);
- Thread readerOne = new Thread(() -> valueReadByThread2 = sharedObject.getCount());
+ Thread readerOne = new Thread(() -> {
+ int valueReadByThread2 = sharedObject.getCount();
+ assertEquals(2, valueReadByThread2);
+ });
readerOne.start();
- Thread readerTwo = new Thread(() -> valueReadByThread3 = sharedObject.getCount());
+ Thread readerTwo = new Thread(() -> {
+ int valueReadByThread3 = sharedObject.getCount();
+ assertEquals(2, valueReadByThread3);
+ });
readerTwo.start();
- assertEquals(2, valueReadByThread2);
- assertEquals(2, valueReadByThread3);
-
}
}
diff --git a/core-java-io/pom.xml b/core-java-io/pom.xml
index 1c2a9b1249..03fd5799c9 100644
--- a/core-java-io/pom.xml
+++ b/core-java-io/pom.xml
@@ -232,18 +232,7 @@
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
-
+
org.apache.maven.plugins
maven-surefire-plugin
@@ -256,7 +245,6 @@
true
-
org.springframework.boot
spring-boot-maven-plugin
diff --git a/core-java-sun/pom.xml b/core-java-sun/pom.xml
index 2b654fa3a5..04c2454872 100644
--- a/core-java-sun/pom.xml
+++ b/core-java-sun/pom.xml
@@ -238,31 +238,6 @@
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- **/*LiveTest.java
- **/*IntegrationTest.java
- **/*LongRunningUnitTest.java
- **/*ManualTest.java
-
-
-
-
-
org.apache.maven.plugins
maven-dependency-plugin
diff --git a/core-java/.gitignore b/core-java/.gitignore
index 3de4cc647e..374c8bf907 100644
--- a/core-java/.gitignore
+++ b/core-java/.gitignore
@@ -16,7 +16,6 @@
*.ear
# Files generated by integration tests
-*.txt
backup-pom.xml
/bin/
/temp
diff --git a/core-java/externalizable.txt b/core-java/externalizable.txt
new file mode 100644
index 0000000000..ddd3e143a8
Binary files /dev/null and b/core-java/externalizable.txt differ
diff --git a/core-java/pom.xml b/core-java/pom.xml
index 11458f4f60..f7bf9ed12a 100644
--- a/core-java/pom.xml
+++ b/core-java/pom.xml
@@ -231,10 +231,9 @@
1.5.8.RELEASE
- org.hsqldb
- hsqldb
- 2.4.0
- runtime
+ com.h2database
+ h2
+ 1.4.197
@@ -248,17 +247,6 @@
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
org.apache.maven.plugins
maven-surefire-plugin
diff --git a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java
index d5c53c3ffc..ad6a064c98 100644
--- a/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java
+++ b/core-java/src/main/java/com/baeldung/jdbc/BatchProcessing.java
@@ -13,8 +13,8 @@ public class BatchProcessing {
public void getConnection(){
try {
- Class.forName("org.hsqldb.jdbcDriver");
- connection = DriverManager.getConnection("jdbc:hsqldb:file:C:\\EMPLOYEEDB", "SA", "");
+ Class.forName("org.h2.Driver");
+ connection = DriverManager.getConnection("jdbc:h2:mem:db", "SA", "");
connection.setAutoCommit(false);
} catch (Exception e) {
e.printStackTrace(System.out);
diff --git a/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java
new file mode 100644
index 0000000000..29cba37d43
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/keystore/JavaKeyStore.java
@@ -0,0 +1,92 @@
+package com.baeldung.keystore;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.PrivateKey;
+import java.security.UnrecoverableEntryException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.util.Enumeration;
+
+/**
+ * Created by adi on 3/7/18.
+ */
+public class JavaKeyStore {
+
+ private KeyStore keyStore;
+
+ private String keyStoreName;
+ private String keyStoreType;
+ private String keyStorePassword;
+
+ JavaKeyStore(String keyStoreType, String keyStorePassword, String keyStoreName) throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException {
+ this.keyStoreName = keyStoreName;
+ this.keyStoreType = keyStoreType;
+ this.keyStorePassword = keyStorePassword;
+ }
+
+ void createEmptyKeyStore() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException {
+ if(keyStoreType ==null || keyStoreType.isEmpty()){
+ keyStoreType = KeyStore.getDefaultType();
+ }
+ keyStore = KeyStore.getInstance(keyStoreType);
+ //load
+ char[] pwdArray = keyStorePassword.toCharArray();
+ keyStore.load(null, pwdArray);
+
+ // Save the keyStore
+ FileOutputStream fos = new FileOutputStream(keyStoreName);
+ keyStore.store(fos, pwdArray);
+ fos.close();
+ }
+
+ void loadKeyStore() throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
+ char[] pwdArray = keyStorePassword.toCharArray();
+ keyStore.load(new FileInputStream(keyStoreName), pwdArray);
+ }
+
+ void setEntry(String alias, KeyStore.SecretKeyEntry secretKeyEntry, KeyStore.ProtectionParameter protectionParameter) throws KeyStoreException {
+ keyStore.setEntry(alias, secretKeyEntry, protectionParameter);
+ }
+
+ KeyStore.Entry getEntry(String alias) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException {
+ KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(keyStorePassword.toCharArray());
+ return keyStore.getEntry(alias, protParam);
+ }
+
+ void setKeyEntry(String alias, PrivateKey privateKey, String keyPassword, Certificate[] certificateChain) throws KeyStoreException {
+ keyStore.setKeyEntry(alias, privateKey, keyPassword.toCharArray(), certificateChain);
+ }
+
+ void setCertificateEntry(String alias, Certificate certificate) throws KeyStoreException {
+ keyStore.setCertificateEntry(alias, certificate);
+ }
+
+ Certificate getCertificate(String alias) throws KeyStoreException {
+ return keyStore.getCertificate(alias);
+ }
+
+ void deleteEntry(String alias) throws KeyStoreException {
+ keyStore.deleteEntry(alias);
+ }
+
+ void deleteKeyStore() throws KeyStoreException, IOException {
+ Enumeration aliases = keyStore.aliases();
+ while (aliases.hasMoreElements()) {
+ String alias = aliases.nextElement();
+ keyStore.deleteEntry(alias);
+ }
+ keyStore = null;
+ Files.delete(Paths.get(keyStoreName));
+ }
+
+ KeyStore getKeyStore() {
+ return this.keyStore;
+ }
+}
diff --git a/core-java/src/main/resources/file.txt b/core-java/src/main/resources/file.txt
new file mode 100644
index 0000000000..558d8bbf35
--- /dev/null
+++ b/core-java/src/main/resources/file.txt
@@ -0,0 +1 @@
+baeldung.com
\ No newline at end of file
diff --git a/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java
new file mode 100644
index 0000000000..ff1d337597
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/keystore/JavaKeyStoreTest.java
@@ -0,0 +1,205 @@
+package com.baeldung.keystore;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import sun.security.x509.AlgorithmId;
+import sun.security.x509.CertificateAlgorithmId;
+import sun.security.x509.CertificateSerialNumber;
+import sun.security.x509.CertificateValidity;
+import sun.security.x509.CertificateVersion;
+import sun.security.x509.CertificateX509Key;
+import sun.security.x509.X500Name;
+import sun.security.x509.X509CertImpl;
+import sun.security.x509.X509CertInfo;
+
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKey;
+import java.io.IOException;
+import java.math.BigInteger;
+import java.security.InvalidKeyException;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.KeyStore;
+import java.security.NoSuchAlgorithmException;
+import java.security.NoSuchProviderException;
+import java.security.SecureRandom;
+import java.security.SignatureException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.Date;
+
+/**
+ * Created by adi on 4/14/18.
+ */
+public class JavaKeyStoreTest {
+
+ private JavaKeyStore keyStore;
+
+ private static final String KEYSTORE_PWD = "abc123";
+ private static final String KEYSTORE_NAME = "myKeyStore";
+ private static final String KEY_STORE_TYPE = "JCEKS";
+
+ private static final String MY_SECRET_ENTRY = "mySecretEntry";
+ private static final String DN_NAME = "CN=test, OU=test, O=test, L=test, ST=test, C=CY";
+ private static final String SHA1WITHRSA = "SHA1withRSA";
+ private static final String MY_PRIVATE_KEY = "myPrivateKey";
+ private static final String MY_CERTIFICATE = "myCertificate";
+
+ @Before
+ public void setUp() throws Exception {
+ //using java cryptography extension keyStore instead of Keystore.getDefaultType
+ keyStore = new JavaKeyStore(KEY_STORE_TYPE, KEYSTORE_PWD, KEYSTORE_NAME);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ if (keyStore.getKeyStore() != null) {
+ keyStore.deleteKeyStore();
+ }
+ }
+
+ @Test
+ public void givenNoKeyStore_whenCreateEmptyKeyStore_thenGetKeyStoreNotNull() throws Exception {
+ keyStore.createEmptyKeyStore();
+ KeyStore result = keyStore.getKeyStore();
+ Assert.assertNotNull(result);
+ }
+
+ @Test
+ public void givenEmptyKeystore_whenLoadKeyStore_thenKeyStoreLoadedAndSizeZero() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+ KeyStore result = keyStore.getKeyStore();
+ Assert.assertNotNull(result);
+ Assert.assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void givenLoadedKeyStore_whenSetEntry_thenSizeIsOneAndGetKeyNotNull() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+
+ KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256");
+ SecretKey secretKey = keygen.generateKey();
+ //ideally, password should be different for every key
+ KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray());
+ KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey);
+ keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam);
+
+ KeyStore result = keyStore.getKeyStore();
+ Assert.assertTrue(result.size() == 1);
+ KeyStore.Entry entry = keyStore.getEntry(MY_SECRET_ENTRY);
+ Assert.assertTrue(entry != null);
+ }
+
+ @Test
+ public void givenLoadedKeyStore_whenSetKeyEntry_thenSizeIsOneAndGetEntryNotNull() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+
+ // Generate the key pair
+ KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
+ keyPairGenerator.initialize(1024);
+ KeyPair keyPair = keyPairGenerator.generateKeyPair();
+
+ // Generate a self signed certificate
+ X509Certificate certificate = generateSelfSignedCertificate(keyPair);
+
+ X509Certificate[] certificateChain = new X509Certificate[1];
+ certificateChain[0] = certificate;
+ keyStore.setKeyEntry(MY_PRIVATE_KEY, keyPair.getPrivate(), KEYSTORE_PWD, certificateChain);
+
+ KeyStore result = keyStore.getKeyStore();
+ Assert.assertTrue(result.size() == 1);
+ KeyStore.Entry entry = keyStore.getEntry(MY_PRIVATE_KEY);
+ Assert.assertTrue(entry != null);
+ }
+
+ @Test
+ public void givenLoadedKeyStore_whenSetCertificateEntry_thenSizeIsOneAndGetCertificateEntryNotNull() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+
+ // Generate the key pair
+ KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
+ keyPairGenerator.initialize(1024);
+ KeyPair keyPair = keyPairGenerator.generateKeyPair();
+
+ // Generate a self signed certificate
+ X509Certificate certificate = generateSelfSignedCertificate(keyPair);
+
+ keyStore.setCertificateEntry(MY_CERTIFICATE, certificate);
+
+ KeyStore result = this.keyStore.getKeyStore();
+ Assert.assertTrue(result.size() == 1);
+ java.security.cert.Certificate resultCertificate = keyStore.getCertificate(MY_CERTIFICATE);
+ Assert.assertNotNull(resultCertificate);
+ }
+
+ @Test
+ public void givenLoadedKeyStoreWithOneEntry_whenDeleteEntry_thenKeyStoreSizeIsZero() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+
+ KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256");
+ SecretKey secretKey = keygen.generateKey();
+ //ideally, password should be different for every key
+ KeyStore.ProtectionParameter protParam = new KeyStore.PasswordProtection(KEYSTORE_PWD.toCharArray());
+ KeyStore.SecretKeyEntry secretKeyEntry = new KeyStore.SecretKeyEntry(secretKey);
+ keyStore.setEntry(MY_SECRET_ENTRY, secretKeyEntry, protParam);
+
+ keyStore.deleteEntry(MY_SECRET_ENTRY);
+
+ KeyStore result = this.keyStore.getKeyStore();
+ Assert.assertTrue(result.size() == 0);
+ }
+
+ @Test
+ public void givenLoadedKeystore_whenDeleteKeyStore_thenKeyStoreIsNull() throws Exception {
+ keyStore.createEmptyKeyStore();
+ keyStore.loadKeyStore();
+
+ keyStore.deleteKeyStore();
+
+ KeyStore result = this.keyStore.getKeyStore();
+ Assert.assertTrue(result == null);
+ }
+
+ private X509Certificate generateSelfSignedCertificate(KeyPair keyPair) throws CertificateException, IOException, NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, SignatureException {
+ X509CertInfo certInfo = new X509CertInfo();
+ // Serial number and version
+ certInfo.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(new BigInteger(64, new SecureRandom())));
+ certInfo.set(X509CertInfo.VERSION, new CertificateVersion(CertificateVersion.V3));
+
+ // Subject & Issuer
+ X500Name owner = new X500Name(DN_NAME);
+ certInfo.set(X509CertInfo.SUBJECT, owner);
+ certInfo.set(X509CertInfo.ISSUER, owner);
+
+ // Key and algorithm
+ certInfo.set(X509CertInfo.KEY, new CertificateX509Key(keyPair.getPublic()));
+ AlgorithmId algorithm = new AlgorithmId(AlgorithmId.sha1WithRSAEncryption_oid);
+ certInfo.set(X509CertInfo.ALGORITHM_ID, new CertificateAlgorithmId(algorithm));
+
+ // Validity
+ Date validFrom = new Date();
+ Date validTo = new Date(validFrom.getTime() + 50L * 365L * 24L * 60L * 60L * 1000L); //50 years
+ CertificateValidity validity = new CertificateValidity(validFrom, validTo);
+ certInfo.set(X509CertInfo.VALIDITY, validity);
+
+ // Create certificate and sign it
+ X509CertImpl cert = new X509CertImpl(certInfo);
+ cert.sign(keyPair.getPrivate(), SHA1WITHRSA);
+
+ // Since the SHA1withRSA provider may have a different algorithm ID to what we think it should be,
+ // we need to reset the algorithm ID, and resign the certificate
+ AlgorithmId actualAlgorithm = (AlgorithmId) cert.get(X509CertImpl.SIG_ALG);
+ certInfo.set(CertificateAlgorithmId.NAME + "." + CertificateAlgorithmId.ALGORITHM, actualAlgorithm);
+ X509CertImpl newCert = new X509CertImpl(certInfo);
+ newCert.sign(keyPair.getPrivate(), SHA1WITHRSA);
+
+ return newCert;
+ }
+}
\ No newline at end of file
diff --git a/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java b/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java
index bbae75091a..4fca27f96c 100644
--- a/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java
+++ b/core-java/src/test/java/com/baeldung/system/SystemPropertiesTest.java
@@ -1,6 +1,7 @@
package com.baeldung.system;
import org.junit.Assert;
+import org.junit.Ignore;
import org.junit.Test;
import java.util.Properties;
@@ -44,6 +45,7 @@ public class SystemPropertiesTest {
}
@Test
+ @Ignore
public void givenSystem_whenCalledClearProperties_thenDeleteAllPropertiesasResult() {
// Clears all system properties. Use with care!
diff --git a/core-java/yofile.txt b/core-java/yofile.txt
new file mode 100644
index 0000000000..ad56bf35f7
Binary files /dev/null and b/core-java/yofile.txt differ
diff --git a/core-java/yofile2.txt b/core-java/yofile2.txt
new file mode 100644
index 0000000000..8393b6e98b
Binary files /dev/null and b/core-java/yofile2.txt differ
diff --git a/core-kotlin/.gitignore b/core-kotlin/.gitignore
new file mode 100644
index 0000000000..ae3c172604
--- /dev/null
+++ b/core-kotlin/.gitignore
@@ -0,0 +1 @@
+/bin/
diff --git a/core-kotlin/README.md b/core-kotlin/README.md
index 54528a076b..d6bd41a111 100644
--- a/core-kotlin/README.md
+++ b/core-kotlin/README.md
@@ -23,3 +23,4 @@
- [Kotlin Dependency Injection with Kodein](http://www.baeldung.com/kotlin-kodein-dependency-injection)
- [Regular Expressions in Kotlin](http://www.baeldung.com/kotlin-regular-expressions)
- [Objects in Kotlin](http://www.baeldung.com/kotlin-objects)
+- [Reading from a File in Kotlin](http://www.baeldung.com/kotlin-read-file)
diff --git a/core-kotlin/pom.xml b/core-kotlin/pom.xml
index 36298ca084..b5aeb264e1 100644
--- a/core-kotlin/pom.xml
+++ b/core-kotlin/pom.xml
@@ -21,6 +21,11 @@
+
+ org.apache.commons
+ commons-math3
+ ${commons-math3.version}
+
org.junit.jupiter
junit-jupiter-engine
@@ -33,12 +38,6 @@
${junit.platform.version}
test
-
- junit
- junit
- ${junit4.version}
- test
-
org.jetbrains.kotlin
kotlin-stdlib
@@ -46,7 +45,7 @@
org.jetbrains.kotlin
- kotlin-stdlib-jre8
+ kotlin-stdlib-jdk8
${kotlin-stdlib.version}
@@ -160,10 +159,6 @@
-
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
maven-failsafe-plugin
2.19.1
@@ -194,14 +189,16 @@
UTF-8
- 1.1.2
- 1.1.2
- 1.1.2
- 1.1.2
+ 1.2.31
+ 1.2.31
+ 1.2.31
+ 1.2.31
0.15
1.5.0
4.1.0
+ 3.6.1
+
5.0.0
1.0.0
4.12.0
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt
new file mode 100644
index 0000000000..20797cc633
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt
@@ -0,0 +1,39 @@
+package com.baeldung.filter
+
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Test
+
+internal class ChunkedTest {
+
+ @Test
+ fun givenDNAFragmentString_whenChunking_thenProduceListOfChunks() {
+ val dnaFragment = "ATTCGCGGCCGCCAA"
+
+ val fragments = dnaFragment.chunked(3)
+
+ assertIterableEquals(listOf("ATT", "CGC", "GGC", "CGC", "CAA"), fragments)
+ }
+
+ @Test
+ fun givenDNAString_whenChunkingWithTransformer_thenProduceTransformedList() {
+ val codonTable = mapOf("ATT" to "Isoleucine", "CAA" to "Glutamine", "CGC" to "Arginine", "GGC" to "Glycine")
+ val dnaFragment = "ATTCGCGGCCGCCAA"
+
+ val proteins = dnaFragment.chunked(3) { codon ->
+ codonTable[codon.toString()] ?: error("Unknown codon")
+ }
+
+ assertIterableEquals(listOf("Isoleucine", "Arginine", "Glycine", "Arginine", "Glutamine"), proteins)
+ }
+
+ @Test
+ fun givenListOfValues_whenChunking_thenProduceListOfArrays() {
+ val whole = listOf(1, 4, 7, 4753, 2, 34, 62, 76, 5868, 0)
+ val chunks = whole.chunked(6)
+
+ val expected = listOf(listOf(1, 4, 7, 4753, 2, 34), listOf(62, 76, 5868, 0))
+
+ assertIterableEquals(expected, chunks)
+ }
+
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt
new file mode 100644
index 0000000000..4cc6f647e1
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DistinctTest.kt
@@ -0,0 +1,71 @@
+package com.baeldung.filter
+
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Test
+
+internal class DistinctTest {
+ data class SmallClass(val key: String, val num: Int)
+
+ @Test
+ fun whenApplyingDistinct_thenReturnListOfNoDuplicateValues() {
+ val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9)
+ val result = array.distinct()
+ val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
+
+ assertIterableEquals(expected, result)
+ }
+
+ @Test
+ fun givenArrayOfClassObjects_whenApplyingDistinctOnClassProperty_thenReturnListDistinctOnThatValue() {
+
+ val original = arrayOf(
+ SmallClass("key1", 1),
+ SmallClass("key2", 2),
+ SmallClass("key3", 3),
+ SmallClass("key4", 3),
+ SmallClass("er", 9),
+ SmallClass("er", 10),
+ SmallClass("er", 11))
+
+ val actual = original.distinctBy { it.key }
+
+ val expected = listOf(
+ SmallClass("key1", 1),
+ SmallClass("key2", 2),
+ SmallClass("key3", 3),
+ SmallClass("key4", 3),
+ SmallClass("er", 9))
+
+
+ assertIterableEquals(expected, actual)
+ }
+
+ @Test
+ fun givenArrayOfClassObjects_whenApplyingComplicatedSelector_thenReturnFirstElementToMatchEachSelectorValue() {
+ val array = arrayOf(
+ SmallClass("key1", 1),
+ SmallClass("key2", 2),
+ SmallClass("key3", 3),
+ SmallClass("key4", 3),
+ SmallClass("er", 9),
+ SmallClass("er", 10),
+ SmallClass("er", 11),
+ SmallClass("er", 11),
+ SmallClass("er", 91),
+ SmallClass("blob", 22),
+ SmallClass("dob", 27),
+ SmallClass("high", 201_434_314))
+
+ val actual = array.distinctBy { Math.floor(it.num / 10.0) }
+
+ val expected = listOf(
+ SmallClass("key1", 1),
+ SmallClass("er", 10),
+ SmallClass("er", 91),
+ SmallClass("blob", 22),
+ SmallClass("high", 201_434_314))
+
+ assertIterableEquals(expected, actual)
+ }
+
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt
new file mode 100644
index 0000000000..7c2685f39b
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/DropTest.kt
@@ -0,0 +1,53 @@
+package com.baeldung.filter
+
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Test
+
+internal class DropTest {
+
+ @Test
+ fun whenDroppingFirstTwoItemsOfArray_thenTwoLess() {
+ val array = arrayOf(1, 2, 3, 4)
+ val result = array.drop(2)
+ val expected = listOf(3, 4)
+
+ assertIterableEquals(expected, result)
+ }
+
+ @Test
+ fun whenDroppingMoreItemsOfArray_thenEmptyList() {
+ val array = arrayOf(1, 2, 3, 4)
+ val result = array.drop(5)
+ val expected = listOf()
+
+ assertIterableEquals(expected, result)
+ }
+
+ @Test
+ fun givenArray_whenDroppingLastElement_thenReturnListWithoutLastElement() {
+ val array = arrayOf("1", "2", "3", "4")
+ val result = array.dropLast(1)
+ val expected = listOf("1", "2", "3")
+
+ assertIterableEquals(expected, result)
+ }
+
+ @Test
+ fun givenArrayOfFloats_whenDroppingLastUntilPredicateIsFalse_thenReturnSubsetListOfFloats() {
+ val array = arrayOf(1f, 1f, 1f, 1f, 1f, 2f, 1f, 1f, 1f)
+ val result = array.dropLastWhile { it == 1f }
+ val expected = listOf(1f, 1f, 1f, 1f, 1f, 2f)
+
+ assertIterableEquals(expected, result)
+ }
+
+ @Test
+ fun givenList_whenDroppingMoreThanAvailable_thenThrowException() {
+ val list = listOf('a', 'e', 'i', 'o', 'u')
+ val result = list.drop(6)
+ val expected: List = listOf()
+
+ assertIterableEquals(expected, result)
+ }
+
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt
new file mode 100644
index 0000000000..efe6354f25
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/FilterTest.kt
@@ -0,0 +1,39 @@
+package com.baeldung.filter
+
+import org.apache.commons.math3.primes.Primes
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Test
+import kotlin.test.assertTrue
+
+internal class FilterTest {
+
+ @Test
+ fun givenAscendingValueMap_whenFilteringOnValue_ThenReturnSubsetOfMap() {
+ val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3)
+ val filteredMap = originalMap.filter { it.value < 2 }
+ val expectedMap = mapOf("key1" to 1)
+
+ assertTrue { expectedMap == filteredMap }
+ }
+
+ @Test
+ fun givenSeveralCollections_whenFilteringToAccumulativeList_thenListContainsAllContents() {
+ val array1 = arrayOf(90, 92, 93, 94, 92, 95, 93)
+ val array2 = sequenceOf(51, 31, 83, 674_506_111, 256_203_161, 15_485_863)
+ val list1 = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
+ val primes = mutableListOf()
+
+ val expected = listOf(2, 3, 5, 7, 31, 83, 15_485_863, 256_203_161, 674_506_111)
+
+ val primeCheck = { num: Int -> Primes.isPrime(num) }
+
+ array1.filterTo(primes, primeCheck)
+ list1.filterTo(primes, primeCheck)
+ array2.filterTo(primes, primeCheck)
+
+ primes.sort()
+
+ assertIterableEquals(expected, primes)
+ }
+
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt
new file mode 100644
index 0000000000..dca167928d
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/SliceTest.kt
@@ -0,0 +1,44 @@
+package com.baeldung.filter
+
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Assertions.assertThrows
+import org.junit.jupiter.api.Test
+
+internal class SliceTest {
+
+ @Test
+ fun whenSlicingAnArrayWithDotRange_ThenListEqualsTheSlice() {
+ val original = arrayOf(1, 2, 3, 2, 1)
+ val actual = original.slice(1..3)
+ val expected = listOf(2, 3, 2)
+
+ assertIterableEquals(expected, actual)
+ }
+
+ @Test
+ fun whenSlicingAnArrayWithDownToRange_thenListMadeUpOfReverseSlice() {
+ val original = arrayOf(1, 2, 3, 2, 1)
+ val actual = original.slice(3 downTo 0)
+ val expected = listOf(2, 3, 2, 1)
+
+ assertIterableEquals(expected, actual)
+ }
+
+ @Test
+ fun whenSlicingBeyondTheRangeOfTheArray_thenContainManyNulls() {
+ val original = arrayOf(12, 3, 34, 4)
+ val actual = original.slice(3..8)
+ val expected = listOf(4, null, null, null, null, null)
+
+ assertIterableEquals(expected, actual)
+ }
+
+ @Test
+ fun whenSlicingBeyondRangeOfArrayWithStep_thenOutOfBoundsException() {
+ assertThrows(ArrayIndexOutOfBoundsException::class.java) {
+ val original = arrayOf(12, 3, 34, 4)
+ original.slice(3..8 step 2)
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt
new file mode 100644
index 0000000000..d021177de8
--- /dev/null
+++ b/core-kotlin/src/test/kotlin/com/baeldung/filter/TakeTest.kt
@@ -0,0 +1,38 @@
+package com.baeldung.filter
+
+import org.junit.jupiter.api.Assertions.assertIterableEquals
+import org.junit.jupiter.api.Test
+
+internal class TakeTest {
+
+ @Test
+ fun `given array of alternating types, when predicating on 'is String', then produce list of array up until predicate is false`() {
+ val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6)
+ val actualList = originalArray.takeWhile { it is String }
+ val expectedList = listOf("val1")
+
+ assertIterableEquals(expectedList, actualList)
+ }
+
+ @Test
+ fun `given array of alternating types, when taking 4 items, then produce list of first 4 items`() {
+ val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6)
+ val actualList = originalArray.take(4)
+ val expectedList = listOf("val1", 2, "val3", 4)
+
+ println(originalArray.drop(4))
+ println(actualList)
+
+ assertIterableEquals(expectedList, actualList)
+ }
+
+ @Test
+ fun `when taking more items than available, then return all elements`() {
+ val originalArray = arrayOf(1, 2)
+ val actual = originalArray.take(10)
+ val expected = listOf(1, 2)
+
+ assertIterableEquals(expected, actual)
+ }
+
+}
\ No newline at end of file
diff --git a/drools/pom.xml b/drools/pom.xml
index 5f228802fa..35f3f7331c 100644
--- a/drools/pom.xml
+++ b/drools/pom.xml
@@ -60,28 +60,5 @@
spring-core
4.3.6.RELEASE
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
- 3
- true
-
- **/*IntegrationTest.java
- **/*LongRunningUnitTest.java
- **/*ManualTest.java
- **/JdbcTest.java
- **/*LiveTest.java
-
-
-
-
-
-
diff --git a/dubbo/pom.xml b/dubbo/pom.xml
index af242e5905..866d1c49c9 100644
--- a/dubbo/pom.xml
+++ b/dubbo/pom.xml
@@ -47,27 +47,4 @@
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
- maven-surefire-plugin
- ${surefire.version}
-
-
- **/*LiveTest.java
-
-
-
-
-
-
diff --git a/ejb/ejb-session-beans/pom.xml b/ejb/ejb-session-beans/pom.xml
index b89ff6ed15..8d05389a95 100644
--- a/ejb/ejb-session-beans/pom.xml
+++ b/ejb/ejb-session-beans/pom.xml
@@ -80,14 +80,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-war-plugin
2.4
@@ -95,10 +87,6 @@
false
-
- maven-surefire-plugin
- 2.17
-
diff --git a/geotools/pom.xml b/geotools/pom.xml
index 01bd6448bb..edd3c4bf3a 100644
--- a/geotools/pom.xml
+++ b/geotools/pom.xml
@@ -57,20 +57,6 @@
http://repo.opengeo.org
-
-
-
- true
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
15.2
15.2
diff --git a/guest/core-java/pom.xml b/guest/core-java/pom.xml
index 35756f784b..ccad9b87cf 100644
--- a/guest/core-java/pom.xml
+++ b/guest/core-java/pom.xml
@@ -40,19 +40,6 @@
test
-
-
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
2.8.2
1.3
diff --git a/guest/deep-jsf/pom.xml b/guest/deep-jsf/pom.xml
index 4697bbf588..bbb544443f 100644
--- a/guest/deep-jsf/pom.xml
+++ b/guest/deep-jsf/pom.xml
@@ -29,17 +29,6 @@
deep-jsf
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
\ No newline at end of file
diff --git a/guest/junit5-example/pom.xml b/guest/junit5-example/pom.xml
index 0e92060a71..c9ea232715 100644
--- a/guest/junit5-example/pom.xml
+++ b/guest/junit5-example/pom.xml
@@ -44,14 +44,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-surefire-plugin
2.19.1
diff --git a/guest/log4j2-example/pom.xml b/guest/log4j2-example/pom.xml
index 594b759538..26e026448f 100644
--- a/guest/log4j2-example/pom.xml
+++ b/guest/log4j2-example/pom.xml
@@ -41,16 +41,6 @@
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
diff --git a/guest/logback-example/pom.xml b/guest/logback-example/pom.xml
index 1f277787d3..8240e45b6a 100644
--- a/guest/logback-example/pom.xml
+++ b/guest/logback-example/pom.xml
@@ -28,19 +28,5 @@
janino
3.0.7
-
-
-
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
\ No newline at end of file
diff --git a/guest/memory-leaks/pom.xml b/guest/memory-leaks/pom.xml
index e0f256b2d5..63d5af9474 100644
--- a/guest/memory-leaks/pom.xml
+++ b/guest/memory-leaks/pom.xml
@@ -30,15 +30,5 @@
src/test/resources/
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
\ No newline at end of file
diff --git a/guest/thread-pools/pom.xml b/guest/thread-pools/pom.xml
index 32ae6384e2..42770edb2a 100644
--- a/guest/thread-pools/pom.xml
+++ b/guest/thread-pools/pom.xml
@@ -17,17 +17,4 @@
1.2.3
-
-
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
\ No newline at end of file
diff --git a/guest/tomcat-app/pom.xml b/guest/tomcat-app/pom.xml
index 02f3abcc32..2ea5190248 100644
--- a/guest/tomcat-app/pom.xml
+++ b/guest/tomcat-app/pom.xml
@@ -55,14 +55,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-war-plugin
3.0.0
diff --git a/guest/webservices/rest-client/pom.xml b/guest/webservices/rest-client/pom.xml
index d74d713a29..b124e632a3 100644
--- a/guest/webservices/rest-client/pom.xml
+++ b/guest/webservices/rest-client/pom.xml
@@ -12,14 +12,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-war-plugin
2.6
diff --git a/guest/webservices/rest-server/pom.xml b/guest/webservices/rest-server/pom.xml
index be43a85166..a183d4110c 100644
--- a/guest/webservices/rest-server/pom.xml
+++ b/guest/webservices/rest-server/pom.xml
@@ -36,14 +36,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-war-plugin
3.0.0
diff --git a/hibernate5/pom.xml b/hibernate5/pom.xml
index 31fe10ee97..a9dcf56c1c 100644
--- a/hibernate5/pom.xml
+++ b/hibernate5/pom.xml
@@ -67,33 +67,5 @@
true
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- 3
- true
-
- **/*IntegrationTest.java
- **/*LiveTest.java
-
-
-
-
-
-
-
diff --git a/java-difference-date/pom.xml b/java-difference-date/pom.xml
index ac3f0fa3b5..7a1ee5f1eb 100644
--- a/java-difference-date/pom.xml
+++ b/java-difference-date/pom.xml
@@ -36,22 +36,7 @@
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
-
-
- 1.8
4.12
2.9.9
1.5.1
diff --git a/javafx/README.md b/javafx/README.md
index 483c556ca7..66c81f17ad 100644
--- a/javafx/README.md
+++ b/javafx/README.md
@@ -1,3 +1,3 @@
### Relevant Articles:
--
+-[Introduction to JavaFX](http://www.baeldung.com/javafx)
diff --git a/javax-servlets/pom.xml b/javax-servlets/pom.xml
index 7407666309..a75af414cd 100644
--- a/javax-servlets/pom.xml
+++ b/javax-servlets/pom.xml
@@ -3,7 +3,6 @@
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
javax-servlets
1.0-SNAPSHOT
@@ -13,8 +12,6 @@
1.0.0-SNAPSHOT
-
-
@@ -35,6 +32,12 @@
+
+ org.springframework
+ spring-test
+ 5.0.5.RELEASE
+ test
+
diff --git a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
index de69efa43a..3c9dbcc5a5 100644
--- a/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
+++ b/jee-7/src/main/java/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
@@ -6,7 +6,11 @@
war
JavaEEAnnotationsSample
JavaEEAnnotationsSample
-
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
@@ -31,15 +35,6 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
org.apache.maven.plugins
maven-war-plugin
diff --git a/jpa-storedprocedure/pom.xml b/jpa-storedprocedure/pom.xml
index cbda37a7b3..a054994fcb 100644
--- a/jpa-storedprocedure/pom.xml
+++ b/jpa-storedprocedure/pom.xml
@@ -19,7 +19,6 @@
5.2.5.Final
6.0.5
2.5
- 2.19.1
diff --git a/jsonb/pom.xml b/jsonb/pom.xml
index 03f4f227b1..63dc331f7a 100644
--- a/jsonb/pom.xml
+++ b/jsonb/pom.xml
@@ -99,7 +99,6 @@
1.8
1.0.0
5.0.0
- 2.20
1.0
1.1.3
1.0
diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml
index 4727ca2222..d19d03b3ff 100644
--- a/libraries-data/pom.xml
+++ b/libraries-data/pom.xml
@@ -65,19 +65,30 @@
test
test
+
+ org.apache.ignite
+ ignite-core
+ ${ignite.version}
+
+
+ org.apache.ignite
+ ignite-spring
+ ${ignite.version}
+
+
+ org.apache.ignite
+ ignite-indexing
+ ${ignite.version}
+
+
+ com.google.code.gson
+ gson
+ ${gson.version}
+
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
@@ -181,5 +192,7 @@
3.7.0
5.0
1.0.0
+ 2.3.0
+ 2.8.2
\ No newline at end of file
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java b/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java
new file mode 100644
index 0000000000..0b603dcee0
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/cache/CustomLifecycleBean.java
@@ -0,0 +1,14 @@
+package com.baeldung.ignite.cache;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.lifecycle.LifecycleBean;
+import org.apache.ignite.lifecycle.LifecycleEventType;
+
+public class CustomLifecycleBean implements LifecycleBean {
+ @Override
+ public void onLifecycleEvent(LifecycleEventType lifecycleEventType) throws IgniteException {
+ if (lifecycleEventType == LifecycleEventType.AFTER_NODE_START) {
+ //do something right after the Ignite node starts
+ }
+ }
+}
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java b/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java
new file mode 100644
index 0000000000..8c40b8f312
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/cache/IgniteCacheExample.java
@@ -0,0 +1,58 @@
+package com.baeldung.ignite.cache;
+
+import com.baeldung.ignite.model.Employee;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.IgniteConfiguration;
+
+import java.util.List;
+
+public class IgniteCacheExample {
+
+ public static void main(String[] args) {
+
+ Ignite ignite = Ignition.ignite();
+
+ IgniteCache cache = ignite.cache("baeldungCache");
+
+ cache.put(1, "baeldung cache value");
+
+ String message = cache.get(1);
+ }
+
+ private static void getObjectFromCache(Ignite ignite) {
+
+ IgniteCache cache = ignite.getOrCreateCache("baeldungCache");
+
+ cache.put(1, new Employee(1, "John", true));
+ cache.put(2, new Employee(2, "Anna", false));
+ cache.put(3, new Employee(3, "George", true));
+
+ Employee employee = cache.get(1);
+ }
+
+ private static void getFromCacheWithSQl(Ignite ignite) {
+
+ IgniteCache cache = ignite.cache("baeldungCache");
+
+ SqlFieldsQuery sql = new SqlFieldsQuery(
+ "select name from Employee where isEmployed = 'true'");
+
+ QueryCursor> cursor = cache.query(sql);
+
+ for (List> row : cursor) {
+ System.out.println(row.get(0));
+ }
+ }
+
+ private static void customInitialization() {
+
+ IgniteConfiguration configuration = new IgniteConfiguration();
+ configuration.setLifecycleBeans(new CustomLifecycleBean());
+ Ignite ignite = Ignition.start(configuration);
+ }
+
+}
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java b/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java
new file mode 100644
index 0000000000..de144711b3
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/jdbc/IgniteJDBC.java
@@ -0,0 +1,58 @@
+package com.baeldung.ignite.jdbc;
+
+import java.sql.*;
+
+/**
+ * Created by Gebruiker on 3/14/2018.
+ */
+public class IgniteJDBC {
+
+ public static void main(String[] args) throws ClassNotFoundException, SQLException {
+
+ Class.forName("org.apache.ignite.IgniteJdbcThinDriver");
+
+ Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1/");
+
+ createDatabaseTables(conn);
+
+ insertData(conn);
+
+ getData(conn);
+ }
+
+ private static void createDatabaseTables(Connection conn) throws SQLException {
+
+ Statement sql = conn.createStatement();
+ sql.executeUpdate("CREATE TABLE Employee (" +
+ " id INTEGER PRIMARY KEY, name VARCHAR, isEmployed timyint(1)) " +
+ " WITH \"template=replicated\"");
+
+ sql.executeUpdate("CREATE INDEX idx_employee_name ON Employee (name)");
+ }
+
+ private static void insertData(Connection conn) throws SQLException {
+
+ PreparedStatement sql =
+ conn.prepareStatement("INSERT INTO Employee (id, name, isEmployed) VALUES (?, ?, ?)");
+ sql.setLong(1, 1);
+ sql.setString(2, "James");
+ sql.setBoolean(3, true);
+ sql.executeUpdate();
+
+ sql.setLong(1, 2);
+ sql.setString(2, "Monica");
+ sql.setBoolean(3, false);
+ sql.executeUpdate();
+ }
+
+ private static void getData(Connection conn) throws SQLException {
+
+ Statement sql = conn.createStatement();
+ ResultSet rs = sql.executeQuery("SELECT e.name, e.isEmployed " +
+ " FROM Employee e " +
+ " WHERE e.isEmployed = TRUE ");
+
+ while (rs.next())
+ System.out.println(rs.getString(1) + ", " + rs.getString(2));
+ }
+}
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java b/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java
new file mode 100644
index 0000000000..21f5ef89d0
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/model/Employee.java
@@ -0,0 +1,48 @@
+package com.baeldung.ignite.model;
+
+
+public class Employee {
+
+ private Integer id;
+ private String name;
+ private boolean isEmployed;
+
+ public Employee(Integer id, String name, boolean isEmployed) {
+ this.id = id;
+ this.name = name;
+ this.isEmployed = isEmployed;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isEmployed() {
+ return isEmployed;
+ }
+
+ public void setEmployed(boolean employed) {
+ isEmployed = employed;
+ }
+
+ @Override
+ public String toString() {
+ return "Employee{" +
+ "id=" + id +
+ ", name='" + name + '\'' +
+ ", isEmployed=" + isEmployed +
+ '}';
+ }
+}
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java b/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java
new file mode 100644
index 0000000000..2b0f71e0b9
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/stream/CacheConfig.java
@@ -0,0 +1,24 @@
+package com.baeldung.ignite.stream;
+
+import com.baeldung.ignite.model.Employee;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.expiry.CreatedExpiryPolicy;
+import javax.cache.expiry.Duration;
+import java.util.concurrent.TimeUnit;
+
+
+public class CacheConfig {
+
+ public static CacheConfiguration employeeCache() {
+
+ CacheConfiguration config = new CacheConfiguration<>("baeldungEmployees");
+
+ config.setIndexedTypes(Integer.class, Employee.class);
+ config.setExpiryPolicyFactory(FactoryBuilder.factoryOf(
+ new CreatedExpiryPolicy(new Duration(TimeUnit.SECONDS, 5))));
+
+ return config;
+ }
+}
\ No newline at end of file
diff --git a/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java b/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java
new file mode 100644
index 0000000000..839da36c22
--- /dev/null
+++ b/libraries-data/src/main/java/com/baeldung/ignite/stream/IgniteStream.java
@@ -0,0 +1,44 @@
+package com.baeldung.ignite.stream;
+
+import com.baeldung.ignite.model.Employee;
+import com.google.gson.Gson;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.Ignition;
+import org.apache.ignite.stream.StreamTransformer;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class IgniteStream {
+
+ public static void main(String[] args) throws Exception {
+
+ Ignition.setClientMode(true);
+ Ignite ignite = Ignition.start();
+
+ IgniteCache cache = ignite.getOrCreateCache(CacheConfig.employeeCache());
+ IgniteDataStreamer streamer = ignite.dataStreamer(cache.getName());
+ streamer.allowOverwrite(true);
+
+ streamer.receiver(StreamTransformer.from((e, arg) -> {
+
+ Employee employee = e.getValue();
+ employee.setEmployed(true);
+ e.setValue(employee);
+
+ return null;
+ }));
+
+ Path path = Paths.get(IgniteStream.class.getResource("employees.txt").toURI());
+
+ Files.lines(path)
+ .forEach(line -> {
+ Employee employee = new Gson().fromJson(line, Employee.class);
+ streamer.addData(employee.getId(), employee);
+ });
+
+ }
+}
diff --git a/libraries-data/src/main/resources/employee.txt b/libraries-data/src/main/resources/employee.txt
new file mode 100644
index 0000000000..6c476f39fa
--- /dev/null
+++ b/libraries-data/src/main/resources/employee.txt
@@ -0,0 +1,3 @@
+{id:"1", name="John", isEmployed: "true"}
+{id:"1", name="Anna", isEmployed: "false"}
+{id:"1", name="George", isEmployed: "true"}
\ No newline at end of file
diff --git a/libraries/pom.xml b/libraries/pom.xml
index be2876ec3b..43c8239e96 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -785,16 +785,6 @@
-
-
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
diff --git a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java
index 3b0cc9b4c1..cf0b203e10 100644
--- a/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java
+++ b/libraries/src/test/java/com/baeldung/jets3t/JetS3tLiveTest.java
@@ -15,6 +15,7 @@ import org.junit.Test;
import java.io.*;
import java.nio.file.Files;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
@@ -191,14 +192,25 @@ public class JetS3tLiveTest {
S3Bucket bucket = createBucket();
assertNotNull(bucket);
- // Create a stream
- ByteArrayInputStream testStream = new ByteArrayInputStream("test stream".getBytes());
+ ArrayList numbers = new ArrayList<>();
+ numbers.add(2);
+ numbers.add(3);
+ numbers.add(5);
+ numbers.add(7);
+
+ // Serialize ArrayList
+ ByteArrayOutputStream bytes = new ByteArrayOutputStream();
+ ObjectOutputStream objectOutputStream = new ObjectOutputStream(bytes);
+ objectOutputStream.writeObject(numbers);
+
+ // Wrap bytes
+ ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes.toByteArray());
// Create and populate object
S3Object streamObject = new S3Object("stream");
- streamObject.setDataInputStream(testStream);
- streamObject.setContentLength(testStream.available());
- streamObject.setContentType("text/plain");
+ streamObject.setDataInputStream(byteArrayInputStream);
+ streamObject.setContentLength(byteArrayInputStream.available());
+ streamObject.setContentType("binary/octet-stream");
// Put it
s3Service.putObject(BucketName, streamObject);
@@ -206,11 +218,14 @@ public class JetS3tLiveTest {
// Get it
S3Object newStreamObject = s3Service.getObject(BucketName, "stream");
- // Convert back to string
- String testString = new BufferedReader(new InputStreamReader(newStreamObject.getDataInputStream()))
- .lines().collect(Collectors.joining("\n"));
+ // Convert back to ArrayList
+ ObjectInputStream objectInputStream = new ObjectInputStream(newStreamObject.getDataInputStream());
+ ArrayList newNumbers = (ArrayList)objectInputStream.readObject();
- assertTrue("test stream".equals(testString));
+ assertEquals(2, (int)newNumbers.get(0));
+ assertEquals(3, (int)newNumbers.get(1));
+ assertEquals(5, (int)newNumbers.get(2));
+ assertEquals(7, (int)newNumbers.get(3));
// Clean up
deleteObject("stream");
diff --git a/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java b/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java
index 8a324ebc72..ca723a7b7f 100644
--- a/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java
+++ b/libraries/src/test/java/com/baeldung/netty/EmbeddedChannelUnitTest.java
@@ -1,11 +1,10 @@
package com.baeldung.netty;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
import java.nio.charset.Charset;
-import org.junit.Assert;
+import static org.assertj.core.api.Assertions.*;
+
+import org.assertj.core.api.Assertions;
import org.junit.Test;
import io.netty.channel.embedded.EmbeddedChannel;
@@ -17,91 +16,82 @@ import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;
public class EmbeddedChannelUnitTest {
-
+
@Test
public void givenTwoChannelHandlers_testPipeline() {
-
- final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/calculate?a=10&b=5");
- httpRequest.headers().add("Operator", "Add");
- EmbeddedChannel channel = new EmbeddedChannel(
- new HttpMessageHandler(), new CalculatorOperationHandler());
-
- channel.pipeline()
- .addFirst(new HttpMessageHandler())
- .addLast(new CalculatorOperationHandler());
+ final FullHttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
+ "/calculate?a=10&b=5");
+ httpRequest.headers().add("Operator", "Add");
+ EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler());
- // send HTTP request to server and check that the message is on the inbound pipeline
- assertTrue(channel.writeInbound(httpRequest));
+ channel.pipeline().addFirst(new HttpMessageHandler()).addLast(new CalculatorOperationHandler());
- long inboundChannelResponse = channel.readInbound();
- assertEquals(15, inboundChannelResponse);
+ // send HTTP request to server and check that the message is on the inbound pipeline
+ assertThat(channel.writeInbound(httpRequest)).isTrue();
- // we should have an outbound message in the form of a HTTP response
- assertEquals(1, channel.outboundMessages().size());
- // Object response = channel.readOutbound();
+ long inboundChannelResponse = channel.readInbound();
+ assertThat(inboundChannelResponse).isEqualTo(15);
- FullHttpResponse httpResponse = channel.readOutbound();
- String httpResponseContent = httpResponse.content().toString(Charset.defaultCharset());
- assertTrue("15".equalsIgnoreCase(httpResponseContent));
+ // we should have an outbound message in the form of a HTTP response
+ assertThat(channel.outboundMessages().size()).isEqualTo(1);
+ // Object response = channel.readOutbound();
+
+ FullHttpResponse httpResponse = channel.readOutbound();
+ String httpResponseContent = httpResponse.content().toString(Charset.defaultCharset());
+ assertThat(httpResponseContent).isEqualTo("15");
}
-
+
@Test
public void givenTwoChannelHandlers_testExceptionHandlingInHttpMessageHandler() {
-
- EmbeddedChannel channel = new EmbeddedChannel(
- new HttpMessageHandler(), new CalculatorOperationHandler());
- final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/calculate?a=10&b=5");
- wrongHttpRequest.headers().add("Operator", "Add");
+ EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler());
- try {
- // send invalid HTTP request to server and expect and error
- channel.pipeline().fireChannelRead(wrongHttpRequest);
- channel.checkException();
- // channel.writeInbound(wrongHttpRequest);
- Assert.fail();
+ final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST,
+ "/calculate?a=10&b=5");
+ wrongHttpRequest.headers().add("Operator", "Add");
- } catch (Exception ex) {
+ Throwable thrownException = catchThrowable(() -> {
+ // send invalid HTTP request to server and expect and error
+ channel.pipeline().fireChannelRead(wrongHttpRequest);
+ channel.checkException();
+ Assertions.failBecauseExceptionWasNotThrown(UnsupportedOperationException.class);
+ });
- // the HttpMessageHandler does not handle the exception and throws it down the pipeline
- assertTrue(ex instanceof UnsupportedOperationException);
- assertTrue(ex.getMessage().equalsIgnoreCase("HTTP method not supported"));
+ assertThat(thrownException)
+ .isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage("HTTP method not supported");
- FullHttpResponse errorHttpResponse = channel.readOutbound();
- String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset());
- assertTrue("Operation not defined".equalsIgnoreCase(errorHttpResponseContent));
- assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, errorHttpResponse.status());
- }
+ FullHttpResponse errorHttpResponse = channel.readOutbound();
+ String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset());
+ assertThat(errorHttpResponseContent).isEqualToIgnoringCase("Operation not defined");
+ assertThat(errorHttpResponse.status()).isEqualTo(HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
-
-
+
@Test
public void givenTwoChannelHandlers_testExceptionHandlingInCalculatorOperationHandler() {
- EmbeddedChannel channel = new EmbeddedChannel(
- new HttpMessageHandler(), new CalculatorOperationHandler());
+ EmbeddedChannel channel = new EmbeddedChannel(new HttpMessageHandler(), new CalculatorOperationHandler());
- final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/calculate?a=10&b=5");
- wrongHttpRequest.headers().add("Operator", "Invalid_operation");
+ final FullHttpRequest wrongHttpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
+ "/calculate?a=10&b=5");
+ wrongHttpRequest.headers().add("Operator", "Invalid_operation");
- try {
- // send invalid HTTP request to server and expect and error
- channel.writeInbound(wrongHttpRequest);
- Assert.fail();
+ Throwable thrownException = catchThrowable(() -> {
+ // send invalid HTTP request to server and expect and error
+ channel.writeInbound(wrongHttpRequest);
+ Assertions.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
+ });
- } catch (Exception ex) {
+ // the HttpMessageHandler does not handle the exception and throws it down the
+ // pipeline
+ assertThat(thrownException).isInstanceOf(IllegalArgumentException.class).hasMessage("Operation not defined");
- // the HttpMessageHandler does not handle the exception and throws it down the pipeline
- assertTrue(ex instanceof IllegalArgumentException);
- assertTrue(ex.getMessage().equalsIgnoreCase("Operation not defined"));
-
- // the outbound message is a HTTP response with the status code 500
- FullHttpResponse errorHttpResponse = channel.readOutbound();
- String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset());
- assertTrue("Operation not defined".equalsIgnoreCase(errorHttpResponseContent));
- assertEquals(HttpResponseStatus.INTERNAL_SERVER_ERROR, errorHttpResponse.status());
- }
+ // the outbound message is a HTTP response with the status code 500
+ FullHttpResponse errorHttpResponse = channel.readOutbound();
+ String errorHttpResponseContent = errorHttpResponse.content().toString(Charset.defaultCharset());
+ assertThat(errorHttpResponseContent).isEqualToIgnoringCase("Operation not defined");
+ assertThat(errorHttpResponse.status()).isEqualTo(HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
}
diff --git a/linkrest/pom.xml b/linkrest/pom.xml
index 819436236f..1dac87c4e9 100644
--- a/linkrest/pom.xml
+++ b/linkrest/pom.xml
@@ -35,14 +35,6 @@
-
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
maven-war-plugin
2.6
diff --git a/mustache/pom.xml b/mustache/pom.xml
index 1c64dbdb0b..5e40402cbc 100644
--- a/mustache/pom.xml
+++ b/mustache/pom.xml
@@ -71,24 +71,7 @@
org.springframework.boot
spring-boot-maven-plugin
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
- 3
- true
-
- **/*IntegrationTest.java
- **/*LongRunningUnitTest.java
- **/*ManualTest.java
- **/JdbcTest.java
- **/*LiveTest.java
-
-
-
-
diff --git a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
index de69efa43a..89ea844fc8 100644
--- a/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
+++ b/out/production/main180/com/baeldung/javaeeannotations/JavaEEAnnotationsSample/pom.xml
@@ -31,15 +31,6 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
org.apache.maven.plugins
maven-war-plugin
diff --git a/patterns/behavioral-patterns/pom.xml b/patterns/behavioral-patterns/pom.xml
index 3c40520ce1..11170b70bc 100644
--- a/patterns/behavioral-patterns/pom.xml
+++ b/patterns/behavioral-patterns/pom.xml
@@ -20,15 +20,6 @@
test
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
-
-
UTF-8
1.8
diff --git a/patterns/facade/README.md b/patterns/facade/README.md
new file mode 100644
index 0000000000..cb44bf4bc4
--- /dev/null
+++ b/patterns/facade/README.md
@@ -0,0 +1,2 @@
+### Relevant Articles:
+- [Facade Design Pattern in Java](http://www.baeldung.com/java-facade-pattern)
diff --git a/patterns/facade/pom.xml b/patterns/facade/pom.xml
index ee46a2a80d..6b9bc739db 100644
--- a/patterns/facade/pom.xml
+++ b/patterns/facade/pom.xml
@@ -20,15 +20,6 @@
test
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
-
-
UTF-8
1.8
diff --git a/patterns/front-controller/pom.xml b/patterns/front-controller/pom.xml
index b746d5dc6c..c41e2f5e09 100644
--- a/patterns/front-controller/pom.xml
+++ b/patterns/front-controller/pom.xml
@@ -22,15 +22,6 @@
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
org.apache.maven.plugins
maven-war-plugin
diff --git a/persistence-modules/liquibase/pom.xml b/persistence-modules/liquibase/pom.xml
index a70483437f..bb5a3700b1 100644
--- a/persistence-modules/liquibase/pom.xml
+++ b/persistence-modules/liquibase/pom.xml
@@ -23,16 +23,6 @@
baeldung-liquibase-demo
-
- org.apache.maven.plugins
- maven-compiler-plugin
- 3.7.0
-
- 1.8
- 1.8
-
-
-
org.liquibase
liquibase-maven-plugin
diff --git a/persistence-modules/spring-hibernate-5/pom.xml b/persistence-modules/spring-hibernate-5/pom.xml
index 86e952c0e4..5b244dfd63 100644
--- a/persistence-modules/spring-hibernate-5/pom.xml
+++ b/persistence-modules/spring-hibernate-5/pom.xml
@@ -149,32 +149,6 @@
true
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
- ${maven-compiler-plugin.version}
-
- 1.8
- 1.8
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
-
- **/*IntegrationTest.java
-
-
-
-
-
-
diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java
new file mode 100644
index 0000000000..99f50abf4c
--- /dev/null
+++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/config/PersistenceConfig.java
@@ -0,0 +1,28 @@
+package com.baeldung.jdbc.autogenkey.config;
+
+import javax.sql.DataSource;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.env.Environment;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
+import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
+
+@Configuration
+public class PersistenceConfig {
+
+ @Bean
+ public DataSource dataSource(Environment env) {
+ return new EmbeddedDatabaseBuilder()
+ .setType(EmbeddedDatabaseType.H2)
+ .addScript("autogenkey-schema.sql")
+ .build();
+ }
+
+ @Bean
+ public JdbcTemplate jdbcTemplate(DataSource dataSource) {
+ return new JdbcTemplate(dataSource);
+ }
+
+}
diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java
new file mode 100644
index 0000000000..cf0dbe4681
--- /dev/null
+++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositoryJDBCTemplate.java
@@ -0,0 +1,38 @@
+package com.baeldung.jdbc.autogenkey.repository;
+
+import java.sql.PreparedStatement;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.GeneratedKeyHolder;
+import org.springframework.jdbc.support.KeyHolder;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class MessageRepositoryJDBCTemplate {
+
+ @Autowired
+ JdbcTemplate jdbcTemplate;
+
+ final String INSERT_MESSAGE_SQL = "insert into sys_message (message) values(?) ";
+
+ public long insert(final String message) {
+
+ KeyHolder keyHolder = new GeneratedKeyHolder();
+
+ jdbcTemplate.update(connection -> {
+ PreparedStatement ps = connection.prepareStatement(INSERT_MESSAGE_SQL);
+ ps.setString(1, message);
+ return ps;
+ }, keyHolder);
+
+ return (long) keyHolder.getKey();
+ }
+
+ final String SELECT_BY_ID = "select message from sys_message where id = ?";
+
+ public String getMessageById(long id) {
+ return this.jdbcTemplate.queryForObject(SELECT_BY_ID, String.class, new Object[] { id });
+ }
+
+}
diff --git a/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java
new file mode 100644
index 0000000000..022ea29ed6
--- /dev/null
+++ b/persistence-modules/spring-jpa/src/main/java/com/baeldung/jdbc/autogenkey/repository/MessageRepositorySimpleJDBCInsert.java
@@ -0,0 +1,29 @@
+package com.baeldung.jdbc.autogenkey.repository;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public class MessageRepositorySimpleJDBCInsert {
+
+ SimpleJdbcInsert messageInsert;
+
+ @Autowired
+ public MessageRepositorySimpleJDBCInsert(DataSource dataSource) {
+ messageInsert = new SimpleJdbcInsert(dataSource).withTableName("sys_message").usingGeneratedKeyColumns("id");
+ }
+
+ public long insert(String message) {
+ Map parameters = new HashMap(1);
+ parameters.put("message", message);
+ Number newId = messageInsert.executeAndReturnKey(parameters);
+ return (long) newId;
+ }
+
+}
diff --git a/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql b/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql
new file mode 100644
index 0000000000..925b27143c
--- /dev/null
+++ b/persistence-modules/spring-jpa/src/main/resources/autogenkey-schema.sql
@@ -0,0 +1,5 @@
+CREATE TABLE IF NOT EXISTS sys_message (
+ id bigint(20) NOT NULL AUTO_INCREMENT,
+ message varchar(100) NOT NULL,
+ PRIMARY KEY (id)
+);
\ No newline at end of file
diff --git a/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java b/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java
new file mode 100644
index 0000000000..aa4d061997
--- /dev/null
+++ b/persistence-modules/spring-jpa/src/test/java/com/baeldung/jdbc/autogenkey/GetAutoGenKeyByJDBC.java
@@ -0,0 +1,49 @@
+package com.baeldung.jdbc.autogenkey;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import com.baeldung.jdbc.autogenkey.repository.MessageRepositoryJDBCTemplate;
+import com.baeldung.jdbc.autogenkey.repository.MessageRepositorySimpleJDBCInsert;
+
+@RunWith(SpringRunner.class)
+public class GetAutoGenKeyByJDBC {
+
+ @Configuration
+ @ComponentScan(basePackages = { "com.baeldung.jdbc.autogenkey" })
+ public static class SpringConfig {
+
+ }
+
+ @Autowired
+ MessageRepositorySimpleJDBCInsert messageRepositorySimpleJDBCInsert;
+
+ @Autowired
+ MessageRepositoryJDBCTemplate messageRepositoryJDBCTemplate;
+
+ final String MESSAGE_CONTENT = "Test";
+
+ @Test
+ public void insertJDBC_whenLoadMessageByKey_thenGetTheSameMessage() {
+ long key = messageRepositoryJDBCTemplate.insert(MESSAGE_CONTENT);
+ String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
+
+ assertEquals(MESSAGE_CONTENT, loadedMessage);
+
+ }
+
+ @Test
+ public void insertSimpleInsert_whenLoadMessageKey_thenGetTheSameMessage() {
+ long key = messageRepositorySimpleJDBCInsert.insert(MESSAGE_CONTENT);
+ String loadedMessage = messageRepositoryJDBCTemplate.getMessageById(key);
+
+ assertEquals(MESSAGE_CONTENT, loadedMessage);
+ }
+
+}
diff --git a/pom.xml b/pom.xml
index 64744eb2da..f0cb72e4d0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -64,6 +64,7 @@
core-java
core-java-io
core-java-8
+
core-groovy
core-java-concurrency
diff --git a/resteasy/bin/pom.xml b/resteasy/bin/pom.xml
index 2e1f839a55..f275bc814f 100644
--- a/resteasy/bin/pom.xml
+++ b/resteasy/bin/pom.xml
@@ -13,6 +13,12 @@
2.5
1.6.1
+
+
+ com.baeldung
+ resteasy-tutorial
+ 1.0
+
RestEasyTutorial
@@ -73,66 +79,5 @@
commons-io
${commons-io.version}
-
-
-
-
- live
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- integration-test
-
- test
-
-
-
- **/*IntegrationTest.java
-
-
- **/*LiveTest.java
-
-
-
-
-
-
- json
-
-
-
-
- org.codehaus.cargo
- cargo-maven2-plugin
- ${cargo-maven2-plugin.version}
-
- false
-
-
-
- start-server
- pre-integration-test
-
- start
-
-
-
- stop-server
- post-integration-test
-
- stop
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/spring-5/src/main/java/com/baeldung/assertions/Car.java b/spring-5/src/main/java/com/baeldung/assertions/Car.java
index 4e210dfaab..abff27f0b0 100644
--- a/spring-5/src/main/java/com/baeldung/assertions/Car.java
+++ b/spring-5/src/main/java/com/baeldung/assertions/Car.java
@@ -39,8 +39,8 @@ public class Car {
// ...
}
- public void сhangeOilWithIsNull(String oil) {
- Assert.isNull(oil, "oil must be null");
+ public void replaceBattery(CarBattery carBattery) {
+ Assert.isNull(carBattery.getCharge(), "to replace battery the charge must be null");
// ...
}
@@ -99,7 +99,9 @@ public class Car {
car.fuel();
car.сhangeOil("oil");
- car.сhangeOilWithIsNull(null);
+
+ CarBattery carBattery = new CarBattery();
+ car.replaceBattery(carBattery);
car.сhangeEngine(new ToyotaEngine());
diff --git a/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java
new file mode 100644
index 0000000000..a75457a7ec
--- /dev/null
+++ b/spring-5/src/main/java/com/baeldung/assertions/CarBattery.java
@@ -0,0 +1,13 @@
+package com.baeldung.assertions;
+
+public class CarBattery {
+ private String charge;
+
+ public String getCharge() {
+ return charge;
+ }
+
+ public void setCharge(String charge) {
+ this.charge = charge;
+ }
+}
diff --git a/spring-boot-bootstrap/pom.xml b/spring-boot-bootstrap/pom.xml
index eb97d6d426..07466c76f2 100644
--- a/spring-boot-bootstrap/pom.xml
+++ b/spring-boot-bootstrap/pom.xml
@@ -5,7 +5,6 @@
org.baeldung
spring-boot-bootstrap
- 0.0.1-SNAPSHOT
jar
spring-boot-bootstrap
@@ -87,15 +86,6 @@
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
integration
diff --git a/spring-boot/README.MD b/spring-boot/README.MD
index e78756cf08..028fde5056 100644
--- a/spring-boot/README.MD
+++ b/spring-boot/README.MD
@@ -32,3 +32,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Spring Data Java 8 Support](http://www.baeldung.com/spring-data-java-8)
- [A Quick Guide to Maven Wrapper](http://www.baeldung.com/maven-wrapper)
- [An Introduction to Kong](http://www.baeldung.com/kong)
+- [Spring Boot Customize Whitelabel Error Page](http://www.baeldung.com/spring-boot-custom-error-page)
+
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java
new file mode 100644
index 0000000000..c4653932c0
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java
@@ -0,0 +1,17 @@
+package com.baeldung.bootcustomfilters;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+/**
+ * Boot application
+ * @author hemant
+ *
+ */
+@SpringBootApplication
+public class SpringBootFiltersApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootFiltersApplication.class, args);
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java
new file mode 100644
index 0000000000..9dfab1192d
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java
@@ -0,0 +1,34 @@
+package com.baeldung.bootcustomfilters.controller;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.baeldung.bootcustomfilters.model.User;
+
+/**
+ * Rest controller for User
+ * @author hemant
+ *
+ */
+@RestController
+@RequestMapping("/users")
+public class UserController {
+
+ private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
+
+ @RequestMapping("")
+ public List getAllUsers() {
+ LOG.info("Fetching all the users");
+ return Arrays.asList(
+ new User(UUID.randomUUID().toString(), "User1", "user1@test.com"),
+ new User(UUID.randomUUID().toString(), "User1", "user1@test.com"),
+ new User(UUID.randomUUID().toString(), "User1", "user1@test.com"));
+ }
+
+}
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java
new file mode 100644
index 0000000000..e42ea7d2dd
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java
@@ -0,0 +1,50 @@
+package com.baeldung.bootcustomfilters.filters;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * A servlet filter to log request and response
+ * The logging implementation is pretty native and for demonstration only
+ * @author hemant
+ *
+ */
+@Component
+@Order(2)
+public class RequestResponseLoggingFilter implements Filter {
+
+ private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class);
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ LOG.info("Initializing filter :{}", this);
+ }
+
+ @Override
+ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
+ throws IOException, ServletException {
+ HttpServletRequest req = (HttpServletRequest) request;
+ HttpServletResponse res = (HttpServletResponse) response;
+ LOG.info("Logging Request {} : {}", req.getMethod(), req.getRequestURI());
+ chain.doFilter(request, response);
+ LOG.info("Logging Response :{}", res.getContentType());
+ }
+
+ @Override
+ public void destroy() {
+ LOG.warn("Destructing filter :{}", this);
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java
new file mode 100644
index 0000000000..d92b723e73
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java
@@ -0,0 +1,47 @@
+package com.baeldung.bootcustomfilters.filters;
+
+import java.io.IOException;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+/**
+ * A filter to create transaction before and commit it once request completes
+ * The current implemenatation is just for demo
+ * @author hemant
+ *
+ */
+@Component
+@Order(1)
+public class TransactionFilter implements Filter {
+
+ private final static Logger LOG = LoggerFactory.getLogger(TransactionFilter.class);
+
+ @Override
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ LOG.info("Initializing filter :{}", this);
+ }
+
+ @Override
+ public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
+ HttpServletRequest req = (HttpServletRequest) request;
+ LOG.info("Starting Transaction for req :{}", req.getRequestURI());
+ chain.doFilter(request, response);
+ LOG.info("Committing Transaction for req :{}", req.getRequestURI());
+ }
+
+ @Override
+ public void destroy() {
+ LOG.warn("Destructing filter :{}", this);
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java
new file mode 100644
index 0000000000..ab8e6c8206
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java
@@ -0,0 +1,45 @@
+package com.baeldung.bootcustomfilters.model;
+
+/**
+ * User model
+ * @author hemant
+ *
+ */
+public class User {
+
+ private String id;
+ private String name;
+ private String email;
+
+ public User(String id, String name, String email) {
+ super();
+ this.id = id;
+ this.name = name;
+ this.email = email;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+}
diff --git a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
index d0c548e7bb..caa335ed23 100644
--- a/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
+++ b/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java
@@ -15,19 +15,21 @@ public class MyErrorController implements ErrorController {
@RequestMapping(value = "/error")
public String handleError(HttpServletRequest request) {
+
+ Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE);
- Integer statusCode =
- Integer.valueOf(request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE).toString());
+ if (status != null) {
+
+ Integer statusCode = Integer.valueOf(status.toString());
- if(statusCode == HttpStatus.NOT_FOUND.value()) {
- return "error-404";
- }
- else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
- return "error-500";
- }
- else {
- return "error";
+ if(statusCode == HttpStatus.NOT_FOUND.value()) {
+ return "error-404";
+ }
+ else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) {
+ return "error-500";
+ }
}
+ return "error";
}
@Override
diff --git a/spring-boot/src/main/resources/templates/error-404.html b/spring-boot/src/main/resources/templates/error-404.html
index 3d3adaefa6..cf68032596 100644
--- a/spring-boot/src/main/resources/templates/error-404.html
+++ b/spring-boot/src/main/resources/templates/error-404.html
@@ -1,7 +1,14 @@
+
+
+
+
-Sorry we couldn't find the resource you are looking for
-Go Home
+
+
+
Sorry, we couldn't find the page you were looking for.
+
Go Home
+
-
+