Date: Sat, 28 Mar 2020 16:48:04 +0530
Subject: [PATCH 28/59] JAVA-623: Moved 3 articles from core-java-security to
security-2
---
.../core-java-security/README.md | 5 +-
core-java-modules/core-java-security/pom.xml | 15 --
.../baeldung/hashing/DigestAlgorithms.java | 9 --
.../baeldung/hashing/Keccak256Hashing.java | 30 ----
.../com/baeldung/hashing/SHA256Hashing.java | 39 -----
.../com/baeldung/hashing/SHA3Hashing.java | 45 ------
.../com/baeldung/hashing/SHACommonUtils.java | 16 --
.../passwordhashing/PBKDF2Hasher.java | 149 ------------------
.../passwordhashing/SHA512Hasher.java | 35 ----
.../passwordhashing/SimplePBKDF2Hasher.java | 18 ---
.../hashing/Keccak256HashingUnitTest.java | 22 ---
.../hashing/SHA256HashingUnitTest.java | 35 ----
.../baeldung/hashing/SHA3HashingUnitTest.java | 38 -----
.../baeldung/java/md5/JavaMD5UnitTest.java | 75 ---------
.../passwordhashing/PBKDF2HasherUnitTest.java | 41 -----
.../passwordhashing/SHA512HasherUnitTest.java | 70 --------
.../src/test/resources/test_md5.txt | 1 -
17 files changed, 2 insertions(+), 641 deletions(-)
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
delete mode 100644 core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
delete mode 100644 core-java-modules/core-java-security/src/test/resources/test_md5.txt
diff --git a/core-java-modules/core-java-security/README.md b/core-java-modules/core-java-security/README.md
index ff9b1eef14..83b12793b5 100644
--- a/core-java-modules/core-java-security/README.md
+++ b/core-java-modules/core-java-security/README.md
@@ -3,17 +3,16 @@
This module contains articles about core Java Security
### Relevant Articles:
-- [MD5 Hashing in Java](http://www.baeldung.com/java-md5)
+
- [Guide to the Cipher Class](http://www.baeldung.com/java-cipher-class)
- [Introduction to SSL in Java](http://www.baeldung.com/java-ssl)
- [Java KeyStore API](http://www.baeldung.com/java-keystore)
- [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream)
-- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
- [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures)
-- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
- [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12)
- [The Java SecureRandom Class](https://www.baeldung.com/java-secure-random)
- [An Introduction to Java SASL](https://www.baeldung.com/java-sasl)
- [A Guide to Java GSS API](https://www.baeldung.com/java-gss)
- [Intro to the Java SecurityManager](https://www.baeldung.com/java-security-manager)
+- More articles: [[next -->]](/core-java-modules/core-java-security-2)
diff --git a/core-java-modules/core-java-security/pom.xml b/core-java-modules/core-java-security/pom.xml
index a46c2e2d40..96024a73a1 100644
--- a/core-java-modules/core-java-security/pom.xml
+++ b/core-java-modules/core-java-security/pom.xml
@@ -24,24 +24,9 @@
${assertj-core.version}
test
-
-
- commons-codec
- commons-codec
- ${commons-codec.version}
-
-
- org.bouncycastle
- bcprov-jdk15on
- ${bouncycastle.version}
-
-
- 1.60
- 1.11
-
3.10.0
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
deleted file mode 100644
index 94dd22ff4b..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.baeldung.hashing;
-
-public class DigestAlgorithms {
-
- public static final String SHA3_256 = "SHA3-256";
- public static final String SHA_256 = "SHA-256";
- public static final String KECCAK_256 = "Keccak-256";
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
deleted file mode 100644
index 19fc4cf059..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.hashing;
-
-import org.bouncycastle.jcajce.provider.digest.Keccak;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.bouncycastle.util.encoders.Hex;
-
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.Security;
-
-import static com.baeldung.hashing.DigestAlgorithms.KECCAK_256;
-import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
-
-public class Keccak256Hashing {
-
- public static String hashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
- Security.addProvider(new BouncyCastleProvider());
- final MessageDigest digest = MessageDigest.getInstance(KECCAK_256);
- final byte[] encodedhash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return bytesToHex(encodedhash);
- }
-
- public static String hashWithBouncyCastle(final String originalString) {
- Keccak.Digest256 digest256 = new Keccak.Digest256();
- byte[] hashbytes = digest256.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return new String(Hex.encode(hashbytes));
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java
deleted file mode 100644
index ec008cebab..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA256Hashing.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.baeldung.hashing;
-
-import com.google.common.hash.Hashing;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.bouncycastle.util.encoders.Hex;
-
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import static com.baeldung.hashing.DigestAlgorithms.SHA_256;
-import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
-
-public class SHA256Hashing {
-
- public static String HashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
- final MessageDigest digest = MessageDigest.getInstance(SHA_256);
- final byte[] encodedhash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return bytesToHex(encodedhash);
- }
-
- public static String hashWithGuava(final String originalString) {
- final String sha256hex = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
- return sha256hex;
- }
-
- public static String HashWithApacheCommons(final String originalString) {
- final String sha256hex = DigestUtils.sha256Hex(originalString);
- return sha256hex;
- }
-
- public static String HashWithBouncyCastle(final String originalString) throws NoSuchAlgorithmException {
- final MessageDigest digest = MessageDigest.getInstance(SHA_256);
- final byte[] hash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
- final String sha256hex = new String(Hex.encode(hash));
- return sha256hex;
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java
deleted file mode 100644
index eb363205b1..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHA3Hashing.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.baeldung.hashing;
-
-import com.google.common.hash.Hashing;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.bouncycastle.crypto.digests.SHA3Digest;
-import org.bouncycastle.jcajce.provider.digest.SHA3;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.bouncycastle.util.encoders.Hex;
-
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-import java.security.Security;
-
-import static com.baeldung.hashing.DigestAlgorithms.SHA3_256;
-import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
-
-public class SHA3Hashing {
-
- /* works with JDK9+ only */
- public static String hashWithJavaMessageDigestJDK9(final String originalString) throws NoSuchAlgorithmException {
- final MessageDigest digest = MessageDigest.getInstance(SHA3_256);
- final byte[] hashbytes = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return bytesToHex(hashbytes);
- }
-
- public static String hashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
- Security.addProvider(new BouncyCastleProvider());
- final MessageDigest digest = MessageDigest.getInstance(SHA3_256);
- final byte[] hashbytes = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return bytesToHex(hashbytes);
- }
-
- /* works with JDK9+ only */
- public static String hashWithApacheCommonsJDK9(final String originalString) {
- return new DigestUtils(SHA3_256).digestAsHex(originalString);
- }
-
- public static String hashWithBouncyCastle(final String originalString) {
- SHA3.Digest256 digest256 = new SHA3.Digest256();
- byte[] hashbytes = digest256.digest(originalString.getBytes(StandardCharsets.UTF_8));
- return new String(Hex.encode(hashbytes));
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java
deleted file mode 100644
index 0f28408083..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/hashing/SHACommonUtils.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.baeldung.hashing;
-
-class SHACommonUtils {
-
- public static String bytesToHex(byte[] hash) {
- StringBuffer hexString = new StringBuffer();
- for (byte h : hash) {
- String hex = Integer.toHexString(0xff & h);
- if (hex.length() == 1)
- hexString.append('0');
- hexString.append(hex);
- }
- return hexString.toString();
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
deleted file mode 100644
index e2259e4249..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
+++ /dev/null
@@ -1,149 +0,0 @@
-package com.baeldung.passwordhashing;
-
-import java.security.NoSuchAlgorithmException;
-import java.security.SecureRandom;
-import java.security.spec.InvalidKeySpecException;
-import java.security.spec.KeySpec;
-import java.util.Arrays;
-import java.util.Base64;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-
-/**
- * Hash passwords for storage, and test passwords against password tokens.
- *
- * Instances of this class can be used concurrently by multiple threads.
- *
- * @author erickson
- * @see StackOverflow
- */
-public final class PBKDF2Hasher
-{
-
- /**
- * Each token produced by this class uses this identifier as a prefix.
- */
- public static final String ID = "$31$";
-
- /**
- * The minimum recommended cost, used by default
- */
- public static final int DEFAULT_COST = 16;
-
- private static final String ALGORITHM = "PBKDF2WithHmacSHA1";
-
- private static final int SIZE = 128;
-
- private static final Pattern layout = Pattern.compile("\\$31\\$(\\d\\d?)\\$(.{43})");
-
- private final SecureRandom random;
-
- private final int cost;
-
- public PBKDF2Hasher()
- {
- this(DEFAULT_COST);
- }
-
- /**
- * Create a password manager with a specified cost
- *
- * @param cost the exponential computational cost of hashing a password, 0 to 30
- */
- public PBKDF2Hasher(int cost)
- {
- iterations(cost); /* Validate cost */
- this.cost = cost;
- this.random = new SecureRandom();
- }
-
- private static int iterations(int cost)
- {
- if ((cost < 0) || (cost > 30))
- throw new IllegalArgumentException("cost: " + cost);
- return 1 << cost;
- }
-
- /**
- * Hash a password for storage.
- *
- * @return a secure authentication token to be stored for later authentication
- */
- public String hash(char[] password)
- {
- byte[] salt = new byte[SIZE / 8];
- random.nextBytes(salt);
- byte[] dk = pbkdf2(password, salt, 1 << cost);
- byte[] hash = new byte[salt.length + dk.length];
- System.arraycopy(salt, 0, hash, 0, salt.length);
- System.arraycopy(dk, 0, hash, salt.length, dk.length);
- Base64.Encoder enc = Base64.getUrlEncoder().withoutPadding();
- return ID + cost + '$' + enc.encodeToString(hash);
- }
-
- /**
- * Authenticate with a password and a stored password token.
- *
- * @return true if the password and token match
- */
- public boolean checkPassword(char[] password, String token)
- {
- Matcher m = layout.matcher(token);
- if (!m.matches())
- throw new IllegalArgumentException("Invalid token format");
- int iterations = iterations(Integer.parseInt(m.group(1)));
- byte[] hash = Base64.getUrlDecoder().decode(m.group(2));
- byte[] salt = Arrays.copyOfRange(hash, 0, SIZE / 8);
- byte[] check = pbkdf2(password, salt, iterations);
- int zero = 0;
- for (int idx = 0; idx < check.length; ++idx)
- zero |= hash[salt.length + idx] ^ check[idx];
- return zero == 0;
- }
-
- private static byte[] pbkdf2(char[] password, byte[] salt, int iterations)
- {
- KeySpec spec = new PBEKeySpec(password, salt, iterations, SIZE);
- try {
- SecretKeyFactory f = SecretKeyFactory.getInstance(ALGORITHM);
- return f.generateSecret(spec).getEncoded();
- }
- catch (NoSuchAlgorithmException ex) {
- throw new IllegalStateException("Missing algorithm: " + ALGORITHM, ex);
- }
- catch (InvalidKeySpecException ex) {
- throw new IllegalStateException("Invalid SecretKeyFactory", ex);
- }
- }
-
- /**
- * Hash a password in an immutable {@code String}.
- *
- * Passwords should be stored in a {@code char[]} so that it can be filled
- * with zeros after use instead of lingering on the heap and elsewhere.
- *
- * @deprecated Use {@link #hash(char[])} instead
- */
- @Deprecated
- public String hash(String password)
- {
- return hash(password.toCharArray());
- }
-
- /**
- * Authenticate with a password in an immutable {@code String} and a stored
- * password token.
- *
- * @deprecated Use {@link #checkPassword(char[],String)} instead.
- * @see #hash(String)
- */
- @Deprecated
- public boolean checkPassword(String password, String token)
- {
- return checkPassword(password.toCharArray(), token);
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
deleted file mode 100644
index 4f5337f963..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.baeldung.passwordhashing;
-
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-
-/** A really simple SHA_512 Encryption example.
- *
- */
-public class SHA512Hasher {
-
- public String hash(String passwordToHash, byte[] salt){
- String generatedPassword = null;
- try {
- MessageDigest md = MessageDigest.getInstance("SHA-512");
- md.update(salt);
- byte[] bytes = md.digest(passwordToHash.getBytes(StandardCharsets.UTF_8));
- StringBuilder sb = new StringBuilder();
- for(int i=0; i< bytes.length ;i++){
- sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
- }
- generatedPassword = sb.toString();
- }
- catch (NoSuchAlgorithmException e){
- e.printStackTrace();
- }
- return generatedPassword;
- }
-
- public boolean checkPassword(String hash, String attempt, byte[] salt){
- String generatedHash = hash(attempt, salt);
- return hash.equals(generatedHash);
- }
-}
diff --git a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java b/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
deleted file mode 100644
index 36c9b65070..0000000000
--- a/core-java-modules/core-java-security/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.baeldung.passwordhashing;
-
-import javax.crypto.SecretKeyFactory;
-import javax.crypto.spec.PBEKeySpec;
-import java.security.spec.KeySpec;
-
-/** A really simple SimplePBKDF2 Encryption example.
- *
- */
-public class SimplePBKDF2Hasher {
-
- public static String hashSimple(String password, byte[] salt) throws Exception{
- KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 128);
- SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
- byte[] hash = f.generateSecret(spec).getEncoded();
- return String.valueOf(hash);
- }
-}
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
deleted file mode 100644
index 9ed35c8834..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.baeldung.hashing;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class Keccak256HashingUnitTest {
-
- private static String originalValue = "abc123";
- private static String hashedValue = "719accc61a9cc126830e5906f9d672d06eab6f8597287095a2c55a8b775e7016";
-
- @Test public void testHashWithJavaMessageDigest() throws Exception {
- final String currentHashedValue = Keccak256Hashing.hashWithJavaMessageDigest(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test public void testHashWithBouncyCastle() {
- final String currentHashedValue = Keccak256Hashing.hashWithBouncyCastle(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
deleted file mode 100644
index 6bc9ad2cc6..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.baeldung.hashing;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class SHA256HashingUnitTest {
-
- private static String originalValue = "abc123";
- private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
-
- @Test
- public void testHashWithJavaMessageDigest() throws Exception {
- final String currentHashedValue = SHA256Hashing.HashWithJavaMessageDigest(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test
- public void testHashWithGuava() throws Exception {
- final String currentHashedValue = SHA256Hashing.hashWithGuava(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test
- public void testHashWithApacheCommans() throws Exception {
- final String currentHashedValue = SHA256Hashing.HashWithApacheCommons(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test
- public void testHashWithBouncyCastle() throws Exception {
- final String currentHashedValue = SHA256Hashing.HashWithBouncyCastle(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
deleted file mode 100644
index fffab96405..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung.hashing;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class SHA3HashingUnitTest {
-
- private static String originalValue = "abc123";
- private static String hashedValue = "f58fa3df820114f56e1544354379820cff464c9c41cb3ca0ad0b0843c9bb67ee";
-
- /* works with JDK9+ only */
- //@Test
- public void testHashWithJavaMessageDigestJDK9() throws Exception {
- final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigestJDK9(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test
- public void testHashWithJavaMessageDigest() throws Exception {
- final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigest(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- /* works with JDK9+ only */
- //@Test
- public void testHashWithApacheCommonsJDK9() {
- final String currentHashedValue = SHA3Hashing.hashWithApacheCommonsJDK9(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
- @Test
- public void testHashWithBouncyCastle() {
- final String currentHashedValue = SHA3Hashing.hashWithBouncyCastle(originalValue);
- assertEquals(hashedValue, currentHashedValue);
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
deleted file mode 100644
index 67d6918c09..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.baeldung.java.md5;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import javax.xml.bind.DatatypeConverter;
-
-import org.apache.commons.codec.digest.DigestUtils;
-import org.junit.Test;
-
-import com.google.common.hash.HashCode;
-import com.google.common.hash.Hashing;
-
-public class JavaMD5UnitTest {
-
- String filename = "src/test/resources/test_md5.txt";
- String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
-
- String hash = "35454B055CC325EA1AF2126E27707052";
- String password = "ILoveJava";
-
- @Test
- public void givenPassword_whenHashing_thenVerifying() throws NoSuchAlgorithmException {
- String hash = "35454B055CC325EA1AF2126E27707052";
- String password = "ILoveJava";
-
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(password.getBytes());
- byte[] digest = md.digest();
- String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase();
-
- assertThat(myHash.equals(hash)).isTrue();
- }
-
- @Test
- public void givenFile_generatingChecksum_thenVerifying() throws NoSuchAlgorithmException, IOException {
- String filename = "src/test/resources/test_md5.txt";
- String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
-
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.update(Files.readAllBytes(Paths.get(filename)));
- byte[] digest = md.digest();
- String myChecksum = DatatypeConverter.printHexBinary(digest).toUpperCase();
-
- assertThat(myChecksum.equals(checksum)).isTrue();
- }
-
- @Test
- public void givenPassword_whenHashingUsingCommons_thenVerifying() {
- String hash = "35454B055CC325EA1AF2126E27707052";
- String password = "ILoveJava";
-
- String md5Hex = DigestUtils.md5Hex(password).toUpperCase();
-
- assertThat(md5Hex.equals(hash)).isTrue();
- }
-
- @Test
- public void givenFile_whenChecksumUsingGuava_thenVerifying() throws IOException {
- String filename = "src/test/resources/test_md5.txt";
- String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
-
- HashCode hash = com.google.common.io.Files.hash(new File(filename), Hashing.md5());
- String myChecksum = hash.toString().toUpperCase();
-
- assertThat(myChecksum.equals(checksum)).isTrue();
- }
-
-}
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
deleted file mode 100644
index 8e90725c77..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.baeldung.passwordhashing;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.*;
-
-
-public class PBKDF2HasherUnitTest {
-
- private PBKDF2Hasher mPBKDF2Hasher;
-
- @Before
- public void setUp() throws Exception {
- mPBKDF2Hasher = new PBKDF2Hasher();
- }
-
- @Test
- public void givenCorrectMessageAndHash_whenAuthenticated_checkAuthenticationSucceeds() throws Exception {
- String message1 = "password123";
-
- String hash1 = mPBKDF2Hasher.hash(message1.toCharArray());
-
- assertTrue(mPBKDF2Hasher.checkPassword(message1.toCharArray(), hash1));
-
- }
-
- @Test
- public void givenWrongMessage_whenAuthenticated_checkAuthenticationFails() throws Exception {
- String message1 = "password123";
-
- String hash1 = mPBKDF2Hasher.hash(message1.toCharArray());
-
- String wrongPasswordAttempt = "IamWrong";
-
- assertFalse(mPBKDF2Hasher.checkPassword(wrongPasswordAttempt.toCharArray(), hash1));
-
- }
-
-
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java b/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
deleted file mode 100644
index 3acfb0ba9d..0000000000
--- a/core-java-modules/core-java-security/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package com.baeldung.passwordhashing;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import java.security.SecureRandom;
-
-import static org.junit.Assert.*;
-
-/**
- * Created by PhysicsSam on 06-Sep-18.
- */
-public class SHA512HasherUnitTest {
-
- private SHA512Hasher hasher;
- private SecureRandom secureRandom;
-
- @Before
- public void setUp() throws Exception {
- hasher = new SHA512Hasher();
- secureRandom = new SecureRandom();
- }
-
- @Test
- public void givenSamePasswordAndSalt_whenHashed_checkResultingHashesAreEqual() throws Exception {
-
- byte[] salt = new byte[16];
- secureRandom.nextBytes(salt);
-
- String hash1 = hasher.hash("password", salt);
- String hash2 = hasher.hash("password", salt);
-
- assertEquals(hash1, hash2);
-
- }
-
- @Test
- public void givenSamePasswordAndDifferentSalt_whenHashed_checkResultingHashesNotEqual() throws Exception {
-
- byte[] salt = new byte[16];
- secureRandom.nextBytes(salt);
- String hash1 = hasher.hash("password", salt);
- //generate a second salt
- byte[] secondSalt = new byte[16];
- String hash2 = hasher.hash("password", secondSalt);
-
- assertNotEquals(hash1, hash2);
-
- }
-
- @Test
- public void givenPredefinedHash_whenCorrectAttemptGiven_checkAuthenticationSucceeds() throws Exception {
- byte[] salt = new byte[16];
- secureRandom.nextBytes(salt);
-
- String originalHash = hasher.hash("password123", salt);
-
- assertTrue(hasher.checkPassword(originalHash, "password123", salt));
- }
-
- @Test
- public void givenPredefinedHash_whenIncorrectAttemptGiven_checkAuthenticationFails() throws Exception {
- byte[] salt = new byte[16];
- secureRandom.nextBytes(salt);
-
- String originalHash = hasher.hash("password123", salt);
-
- assertFalse(hasher.checkPassword(originalHash, "password124", salt));
- }
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security/src/test/resources/test_md5.txt b/core-java-modules/core-java-security/src/test/resources/test_md5.txt
deleted file mode 100644
index 95d09f2b10..0000000000
--- a/core-java-modules/core-java-security/src/test/resources/test_md5.txt
+++ /dev/null
@@ -1 +0,0 @@
-hello world
\ No newline at end of file
From e2b6b4bc924f860cd2ab7d77ed17ad8e2d969b15 Mon Sep 17 00:00:00 2001
From: sampadawagde
Date: Sat, 28 Mar 2020 16:48:43 +0530
Subject: [PATCH 29/59] JAVA-623: Moved 3 articles to core-java-security-2
---
.../core-java-security-2/README.md | 8 +
.../core-java-security-2/pom.xml | 30 ++++
.../baeldung/hashing/DigestAlgorithms.java | 9 ++
.../baeldung/hashing/Keccak256Hashing.java | 30 ++++
.../com/baeldung/hashing/SHA256Hashing.java | 39 +++++
.../com/baeldung/hashing/SHA3Hashing.java | 45 ++++++
.../com/baeldung/hashing/SHACommonUtils.java | 16 ++
.../passwordhashing/PBKDF2Hasher.java | 149 ++++++++++++++++++
.../passwordhashing/SHA512Hasher.java | 35 ++++
.../passwordhashing/SimplePBKDF2Hasher.java | 18 +++
.../hashing/Keccak256HashingUnitTest.java | 22 +++
.../hashing/SHA256HashingUnitTest.java | 35 ++++
.../baeldung/hashing/SHA3HashingUnitTest.java | 38 +++++
.../baeldung/java/md5/JavaMD5UnitTest.java | 75 +++++++++
.../passwordhashing/PBKDF2HasherUnitTest.java | 41 +++++
.../passwordhashing/SHA512HasherUnitTest.java | 70 ++++++++
.../src/test/resources/test_md5.txt | 1 +
17 files changed, 661 insertions(+)
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA256Hashing.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA3Hashing.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
create mode 100644 core-java-modules/core-java-security-2/src/test/resources/test_md5.txt
diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md
index c250e24078..2eb21fb77e 100644
--- a/core-java-modules/core-java-security-2/README.md
+++ b/core-java-modules/core-java-security-2/README.md
@@ -1,3 +1,11 @@
+## Core Java Security
+
+This module contains articles about core Java Security
+
### Relevant Articles:
- [Guide To The Java Authentication And Authorization Service (JAAS)](https://www.baeldung.com/java-authentication-authorization-service)
+- [MD5 Hashing in Java](http://www.baeldung.com/java-md5)
+- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
+- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
+- More articles: [[<-- prev]](/core-java-modules/core-java-security)
diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml
index 23f0c5aab9..9315ab4af2 100644
--- a/core-java-modules/core-java-security-2/pom.xml
+++ b/core-java-modules/core-java-security-2/pom.xml
@@ -16,4 +16,34 @@
../../parent-java
+
+
+ commons-codec
+ commons-codec
+ ${commons-codec.version}
+
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+ ${bouncycastle.version}
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj-core.version}
+ test
+
+
+
+
+
+ 1.60
+ 1.11
+
+
+ 3.10.0
+
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/DigestAlgorithms.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
new file mode 100644
index 0000000000..94dd22ff4b
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/DigestAlgorithms.java
@@ -0,0 +1,9 @@
+package com.baeldung.hashing;
+
+public class DigestAlgorithms {
+
+ public static final String SHA3_256 = "SHA3-256";
+ public static final String SHA_256 = "SHA-256";
+ public static final String KECCAK_256 = "Keccak-256";
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/Keccak256Hashing.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
new file mode 100644
index 0000000000..19fc4cf059
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/Keccak256Hashing.java
@@ -0,0 +1,30 @@
+package com.baeldung.hashing;
+
+import org.bouncycastle.jcajce.provider.digest.Keccak;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.util.encoders.Hex;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.Security;
+
+import static com.baeldung.hashing.DigestAlgorithms.KECCAK_256;
+import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
+
+public class Keccak256Hashing {
+
+ public static String hashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
+ Security.addProvider(new BouncyCastleProvider());
+ final MessageDigest digest = MessageDigest.getInstance(KECCAK_256);
+ final byte[] encodedhash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return bytesToHex(encodedhash);
+ }
+
+ public static String hashWithBouncyCastle(final String originalString) {
+ Keccak.Digest256 digest256 = new Keccak.Digest256();
+ byte[] hashbytes = digest256.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return new String(Hex.encode(hashbytes));
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA256Hashing.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA256Hashing.java
new file mode 100644
index 0000000000..ec008cebab
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA256Hashing.java
@@ -0,0 +1,39 @@
+package com.baeldung.hashing;
+
+import com.google.common.hash.Hashing;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.bouncycastle.util.encoders.Hex;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import static com.baeldung.hashing.DigestAlgorithms.SHA_256;
+import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
+
+public class SHA256Hashing {
+
+ public static String HashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
+ final MessageDigest digest = MessageDigest.getInstance(SHA_256);
+ final byte[] encodedhash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return bytesToHex(encodedhash);
+ }
+
+ public static String hashWithGuava(final String originalString) {
+ final String sha256hex = Hashing.sha256().hashString(originalString, StandardCharsets.UTF_8).toString();
+ return sha256hex;
+ }
+
+ public static String HashWithApacheCommons(final String originalString) {
+ final String sha256hex = DigestUtils.sha256Hex(originalString);
+ return sha256hex;
+ }
+
+ public static String HashWithBouncyCastle(final String originalString) throws NoSuchAlgorithmException {
+ final MessageDigest digest = MessageDigest.getInstance(SHA_256);
+ final byte[] hash = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ final String sha256hex = new String(Hex.encode(hash));
+ return sha256hex;
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA3Hashing.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA3Hashing.java
new file mode 100644
index 0000000000..eb363205b1
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHA3Hashing.java
@@ -0,0 +1,45 @@
+package com.baeldung.hashing;
+
+import com.google.common.hash.Hashing;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.bouncycastle.crypto.digests.SHA3Digest;
+import org.bouncycastle.jcajce.provider.digest.SHA3;
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+import org.bouncycastle.util.encoders.Hex;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.Security;
+
+import static com.baeldung.hashing.DigestAlgorithms.SHA3_256;
+import static com.baeldung.hashing.SHACommonUtils.bytesToHex;
+
+public class SHA3Hashing {
+
+ /* works with JDK9+ only */
+ public static String hashWithJavaMessageDigestJDK9(final String originalString) throws NoSuchAlgorithmException {
+ final MessageDigest digest = MessageDigest.getInstance(SHA3_256);
+ final byte[] hashbytes = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return bytesToHex(hashbytes);
+ }
+
+ public static String hashWithJavaMessageDigest(final String originalString) throws NoSuchAlgorithmException {
+ Security.addProvider(new BouncyCastleProvider());
+ final MessageDigest digest = MessageDigest.getInstance(SHA3_256);
+ final byte[] hashbytes = digest.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return bytesToHex(hashbytes);
+ }
+
+ /* works with JDK9+ only */
+ public static String hashWithApacheCommonsJDK9(final String originalString) {
+ return new DigestUtils(SHA3_256).digestAsHex(originalString);
+ }
+
+ public static String hashWithBouncyCastle(final String originalString) {
+ SHA3.Digest256 digest256 = new SHA3.Digest256();
+ byte[] hashbytes = digest256.digest(originalString.getBytes(StandardCharsets.UTF_8));
+ return new String(Hex.encode(hashbytes));
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
new file mode 100644
index 0000000000..0f28408083
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
@@ -0,0 +1,16 @@
+package com.baeldung.hashing;
+
+class SHACommonUtils {
+
+ public static String bytesToHex(byte[] hash) {
+ StringBuffer hexString = new StringBuffer();
+ for (byte h : hash) {
+ String hex = Integer.toHexString(0xff & h);
+ if (hex.length() == 1)
+ hexString.append('0');
+ hexString.append(hex);
+ }
+ return hexString.toString();
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
new file mode 100644
index 0000000000..e2259e4249
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/PBKDF2Hasher.java
@@ -0,0 +1,149 @@
+package com.baeldung.passwordhashing;
+
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+
+/**
+ * Hash passwords for storage, and test passwords against password tokens.
+ *
+ * Instances of this class can be used concurrently by multiple threads.
+ *
+ * @author erickson
+ * @see StackOverflow
+ */
+public final class PBKDF2Hasher
+{
+
+ /**
+ * Each token produced by this class uses this identifier as a prefix.
+ */
+ public static final String ID = "$31$";
+
+ /**
+ * The minimum recommended cost, used by default
+ */
+ public static final int DEFAULT_COST = 16;
+
+ private static final String ALGORITHM = "PBKDF2WithHmacSHA1";
+
+ private static final int SIZE = 128;
+
+ private static final Pattern layout = Pattern.compile("\\$31\\$(\\d\\d?)\\$(.{43})");
+
+ private final SecureRandom random;
+
+ private final int cost;
+
+ public PBKDF2Hasher()
+ {
+ this(DEFAULT_COST);
+ }
+
+ /**
+ * Create a password manager with a specified cost
+ *
+ * @param cost the exponential computational cost of hashing a password, 0 to 30
+ */
+ public PBKDF2Hasher(int cost)
+ {
+ iterations(cost); /* Validate cost */
+ this.cost = cost;
+ this.random = new SecureRandom();
+ }
+
+ private static int iterations(int cost)
+ {
+ if ((cost < 0) || (cost > 30))
+ throw new IllegalArgumentException("cost: " + cost);
+ return 1 << cost;
+ }
+
+ /**
+ * Hash a password for storage.
+ *
+ * @return a secure authentication token to be stored for later authentication
+ */
+ public String hash(char[] password)
+ {
+ byte[] salt = new byte[SIZE / 8];
+ random.nextBytes(salt);
+ byte[] dk = pbkdf2(password, salt, 1 << cost);
+ byte[] hash = new byte[salt.length + dk.length];
+ System.arraycopy(salt, 0, hash, 0, salt.length);
+ System.arraycopy(dk, 0, hash, salt.length, dk.length);
+ Base64.Encoder enc = Base64.getUrlEncoder().withoutPadding();
+ return ID + cost + '$' + enc.encodeToString(hash);
+ }
+
+ /**
+ * Authenticate with a password and a stored password token.
+ *
+ * @return true if the password and token match
+ */
+ public boolean checkPassword(char[] password, String token)
+ {
+ Matcher m = layout.matcher(token);
+ if (!m.matches())
+ throw new IllegalArgumentException("Invalid token format");
+ int iterations = iterations(Integer.parseInt(m.group(1)));
+ byte[] hash = Base64.getUrlDecoder().decode(m.group(2));
+ byte[] salt = Arrays.copyOfRange(hash, 0, SIZE / 8);
+ byte[] check = pbkdf2(password, salt, iterations);
+ int zero = 0;
+ for (int idx = 0; idx < check.length; ++idx)
+ zero |= hash[salt.length + idx] ^ check[idx];
+ return zero == 0;
+ }
+
+ private static byte[] pbkdf2(char[] password, byte[] salt, int iterations)
+ {
+ KeySpec spec = new PBEKeySpec(password, salt, iterations, SIZE);
+ try {
+ SecretKeyFactory f = SecretKeyFactory.getInstance(ALGORITHM);
+ return f.generateSecret(spec).getEncoded();
+ }
+ catch (NoSuchAlgorithmException ex) {
+ throw new IllegalStateException("Missing algorithm: " + ALGORITHM, ex);
+ }
+ catch (InvalidKeySpecException ex) {
+ throw new IllegalStateException("Invalid SecretKeyFactory", ex);
+ }
+ }
+
+ /**
+ * Hash a password in an immutable {@code String}.
+ *
+ * Passwords should be stored in a {@code char[]} so that it can be filled
+ * with zeros after use instead of lingering on the heap and elsewhere.
+ *
+ * @deprecated Use {@link #hash(char[])} instead
+ */
+ @Deprecated
+ public String hash(String password)
+ {
+ return hash(password.toCharArray());
+ }
+
+ /**
+ * Authenticate with a password in an immutable {@code String} and a stored
+ * password token.
+ *
+ * @deprecated Use {@link #checkPassword(char[],String)} instead.
+ * @see #hash(String)
+ */
+ @Deprecated
+ public boolean checkPassword(String password, String token)
+ {
+ return checkPassword(password.toCharArray(), token);
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
new file mode 100644
index 0000000000..4f5337f963
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SHA512Hasher.java
@@ -0,0 +1,35 @@
+package com.baeldung.passwordhashing;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+
+/** A really simple SHA_512 Encryption example.
+ *
+ */
+public class SHA512Hasher {
+
+ public String hash(String passwordToHash, byte[] salt){
+ String generatedPassword = null;
+ try {
+ MessageDigest md = MessageDigest.getInstance("SHA-512");
+ md.update(salt);
+ byte[] bytes = md.digest(passwordToHash.getBytes(StandardCharsets.UTF_8));
+ StringBuilder sb = new StringBuilder();
+ for(int i=0; i< bytes.length ;i++){
+ sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
+ }
+ generatedPassword = sb.toString();
+ }
+ catch (NoSuchAlgorithmException e){
+ e.printStackTrace();
+ }
+ return generatedPassword;
+ }
+
+ public boolean checkPassword(String hash, String attempt, byte[] salt){
+ String generatedHash = hash(attempt, salt);
+ return hash.equals(generatedHash);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
new file mode 100644
index 0000000000..36c9b65070
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/passwordhashing/SimplePBKDF2Hasher.java
@@ -0,0 +1,18 @@
+package com.baeldung.passwordhashing;
+
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.PBEKeySpec;
+import java.security.spec.KeySpec;
+
+/** A really simple SimplePBKDF2 Encryption example.
+ *
+ */
+public class SimplePBKDF2Hasher {
+
+ public static String hashSimple(String password, byte[] salt) throws Exception{
+ KeySpec spec = new PBEKeySpec(password.toCharArray(), salt, 65536, 128);
+ SecretKeyFactory f = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
+ byte[] hash = f.generateSecret(spec).getEncoded();
+ return String.valueOf(hash);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
new file mode 100644
index 0000000000..9ed35c8834
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/Keccak256HashingUnitTest.java
@@ -0,0 +1,22 @@
+package com.baeldung.hashing;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class Keccak256HashingUnitTest {
+
+ private static String originalValue = "abc123";
+ private static String hashedValue = "719accc61a9cc126830e5906f9d672d06eab6f8597287095a2c55a8b775e7016";
+
+ @Test public void testHashWithJavaMessageDigest() throws Exception {
+ final String currentHashedValue = Keccak256Hashing.hashWithJavaMessageDigest(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test public void testHashWithBouncyCastle() {
+ final String currentHashedValue = Keccak256Hashing.hashWithBouncyCastle(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
new file mode 100644
index 0000000000..6bc9ad2cc6
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA256HashingUnitTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.hashing;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SHA256HashingUnitTest {
+
+ private static String originalValue = "abc123";
+ private static String hashedValue = "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090";
+
+ @Test
+ public void testHashWithJavaMessageDigest() throws Exception {
+ final String currentHashedValue = SHA256Hashing.HashWithJavaMessageDigest(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test
+ public void testHashWithGuava() throws Exception {
+ final String currentHashedValue = SHA256Hashing.hashWithGuava(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test
+ public void testHashWithApacheCommans() throws Exception {
+ final String currentHashedValue = SHA256Hashing.HashWithApacheCommons(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test
+ public void testHashWithBouncyCastle() throws Exception {
+ final String currentHashedValue = SHA256Hashing.HashWithBouncyCastle(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
new file mode 100644
index 0000000000..fffab96405
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/hashing/SHA3HashingUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.hashing;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class SHA3HashingUnitTest {
+
+ private static String originalValue = "abc123";
+ private static String hashedValue = "f58fa3df820114f56e1544354379820cff464c9c41cb3ca0ad0b0843c9bb67ee";
+
+ /* works with JDK9+ only */
+ //@Test
+ public void testHashWithJavaMessageDigestJDK9() throws Exception {
+ final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigestJDK9(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test
+ public void testHashWithJavaMessageDigest() throws Exception {
+ final String currentHashedValue = SHA3Hashing.hashWithJavaMessageDigest(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ /* works with JDK9+ only */
+ //@Test
+ public void testHashWithApacheCommonsJDK9() {
+ final String currentHashedValue = SHA3Hashing.hashWithApacheCommonsJDK9(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+ @Test
+ public void testHashWithBouncyCastle() {
+ final String currentHashedValue = SHA3Hashing.hashWithBouncyCastle(originalValue);
+ assertEquals(hashedValue, currentHashedValue);
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
new file mode 100644
index 0000000000..67d6918c09
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/java/md5/JavaMD5UnitTest.java
@@ -0,0 +1,75 @@
+package com.baeldung.java.md5;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import javax.xml.bind.DatatypeConverter;
+
+import org.apache.commons.codec.digest.DigestUtils;
+import org.junit.Test;
+
+import com.google.common.hash.HashCode;
+import com.google.common.hash.Hashing;
+
+public class JavaMD5UnitTest {
+
+ String filename = "src/test/resources/test_md5.txt";
+ String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
+
+ String hash = "35454B055CC325EA1AF2126E27707052";
+ String password = "ILoveJava";
+
+ @Test
+ public void givenPassword_whenHashing_thenVerifying() throws NoSuchAlgorithmException {
+ String hash = "35454B055CC325EA1AF2126E27707052";
+ String password = "ILoveJava";
+
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(password.getBytes());
+ byte[] digest = md.digest();
+ String myHash = DatatypeConverter.printHexBinary(digest).toUpperCase();
+
+ assertThat(myHash.equals(hash)).isTrue();
+ }
+
+ @Test
+ public void givenFile_generatingChecksum_thenVerifying() throws NoSuchAlgorithmException, IOException {
+ String filename = "src/test/resources/test_md5.txt";
+ String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
+
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(Files.readAllBytes(Paths.get(filename)));
+ byte[] digest = md.digest();
+ String myChecksum = DatatypeConverter.printHexBinary(digest).toUpperCase();
+
+ assertThat(myChecksum.equals(checksum)).isTrue();
+ }
+
+ @Test
+ public void givenPassword_whenHashingUsingCommons_thenVerifying() {
+ String hash = "35454B055CC325EA1AF2126E27707052";
+ String password = "ILoveJava";
+
+ String md5Hex = DigestUtils.md5Hex(password).toUpperCase();
+
+ assertThat(md5Hex.equals(hash)).isTrue();
+ }
+
+ @Test
+ public void givenFile_whenChecksumUsingGuava_thenVerifying() throws IOException {
+ String filename = "src/test/resources/test_md5.txt";
+ String checksum = "5EB63BBBE01EEED093CB22BB8F5ACDC3";
+
+ HashCode hash = com.google.common.io.Files.hash(new File(filename), Hashing.md5());
+ String myChecksum = hash.toString().toUpperCase();
+
+ assertThat(myChecksum.equals(checksum)).isTrue();
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
new file mode 100644
index 0000000000..8e90725c77
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/PBKDF2HasherUnitTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.passwordhashing;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+public class PBKDF2HasherUnitTest {
+
+ private PBKDF2Hasher mPBKDF2Hasher;
+
+ @Before
+ public void setUp() throws Exception {
+ mPBKDF2Hasher = new PBKDF2Hasher();
+ }
+
+ @Test
+ public void givenCorrectMessageAndHash_whenAuthenticated_checkAuthenticationSucceeds() throws Exception {
+ String message1 = "password123";
+
+ String hash1 = mPBKDF2Hasher.hash(message1.toCharArray());
+
+ assertTrue(mPBKDF2Hasher.checkPassword(message1.toCharArray(), hash1));
+
+ }
+
+ @Test
+ public void givenWrongMessage_whenAuthenticated_checkAuthenticationFails() throws Exception {
+ String message1 = "password123";
+
+ String hash1 = mPBKDF2Hasher.hash(message1.toCharArray());
+
+ String wrongPasswordAttempt = "IamWrong";
+
+ assertFalse(mPBKDF2Hasher.checkPassword(wrongPasswordAttempt.toCharArray(), hash1));
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
new file mode 100644
index 0000000000..3acfb0ba9d
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/passwordhashing/SHA512HasherUnitTest.java
@@ -0,0 +1,70 @@
+package com.baeldung.passwordhashing;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.security.SecureRandom;
+
+import static org.junit.Assert.*;
+
+/**
+ * Created by PhysicsSam on 06-Sep-18.
+ */
+public class SHA512HasherUnitTest {
+
+ private SHA512Hasher hasher;
+ private SecureRandom secureRandom;
+
+ @Before
+ public void setUp() throws Exception {
+ hasher = new SHA512Hasher();
+ secureRandom = new SecureRandom();
+ }
+
+ @Test
+ public void givenSamePasswordAndSalt_whenHashed_checkResultingHashesAreEqual() throws Exception {
+
+ byte[] salt = new byte[16];
+ secureRandom.nextBytes(salt);
+
+ String hash1 = hasher.hash("password", salt);
+ String hash2 = hasher.hash("password", salt);
+
+ assertEquals(hash1, hash2);
+
+ }
+
+ @Test
+ public void givenSamePasswordAndDifferentSalt_whenHashed_checkResultingHashesNotEqual() throws Exception {
+
+ byte[] salt = new byte[16];
+ secureRandom.nextBytes(salt);
+ String hash1 = hasher.hash("password", salt);
+ //generate a second salt
+ byte[] secondSalt = new byte[16];
+ String hash2 = hasher.hash("password", secondSalt);
+
+ assertNotEquals(hash1, hash2);
+
+ }
+
+ @Test
+ public void givenPredefinedHash_whenCorrectAttemptGiven_checkAuthenticationSucceeds() throws Exception {
+ byte[] salt = new byte[16];
+ secureRandom.nextBytes(salt);
+
+ String originalHash = hasher.hash("password123", salt);
+
+ assertTrue(hasher.checkPassword(originalHash, "password123", salt));
+ }
+
+ @Test
+ public void givenPredefinedHash_whenIncorrectAttemptGiven_checkAuthenticationFails() throws Exception {
+ byte[] salt = new byte[16];
+ secureRandom.nextBytes(salt);
+
+ String originalHash = hasher.hash("password123", salt);
+
+ assertFalse(hasher.checkPassword(originalHash, "password124", salt));
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-security-2/src/test/resources/test_md5.txt b/core-java-modules/core-java-security-2/src/test/resources/test_md5.txt
new file mode 100644
index 0000000000..95d09f2b10
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/resources/test_md5.txt
@@ -0,0 +1 @@
+hello world
\ No newline at end of file
From 4382852a1731d9d06f838219ec176ddf89c04d3d Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Sun, 29 Mar 2020 19:00:40 +0200
Subject: [PATCH 30/59] JAVA-43: Upgrade spring-security-modules to Spring Boot
2
---
spring-security-modules/spring-security-acl/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spring-security-modules/spring-security-acl/pom.xml b/spring-security-modules/spring-security-acl/pom.xml
index 3c613f9d92..5c04aaa9ca 100644
--- a/spring-security-modules/spring-security-acl/pom.xml
+++ b/spring-security-modules/spring-security-acl/pom.xml
@@ -10,9 +10,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
From 35bbf9c8845c7c6091afdefb5fb49e8f54035f1c Mon Sep 17 00:00:00 2001
From: Ali Dehghani
Date: Mon, 30 Mar 2020 01:29:02 +0430
Subject: [PATCH 31/59] Borrowing one Example from JCIP
---
.../volatilekeyword/TaskRunner.java | 25 +++++++++++++++++++
1 file changed, 25 insertions(+)
create mode 100644 core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/TaskRunner.java
diff --git a/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/TaskRunner.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/TaskRunner.java
new file mode 100644
index 0000000000..f0493d4911
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/concurrent/volatilekeyword/TaskRunner.java
@@ -0,0 +1,25 @@
+package com.baeldung.concurrent.volatilekeyword;
+
+public class TaskRunner {
+
+ private static int number;
+ private volatile static boolean ready;
+
+ private static class Reader extends Thread {
+
+ @Override
+ public void run() {
+ while (!ready) {
+ Thread.yield();
+ }
+
+ System.out.println(number);
+ }
+ }
+
+ public static void main(String[] args) {
+ new Reader().start();
+ number = 42;
+ ready = true;
+ }
+}
From ee95317ad9dd8af56a885bcac40b9b11d04dca56 Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Sun, 29 Mar 2020 23:54:31 +0200
Subject: [PATCH 32/59] JAVA-42: Upgrade spring-security-ldap to Spring Boot 2
---
.../spring-security-ldap/pom.xml | 8 +++++--
.../com/baeldung/SampleLDAPApplication.java | 13 +-----------
.../{security => config}/SecurityConfig.java | 21 +++++++++++++++----
.../java/com/baeldung/config/WebConfig.java | 16 ++++++++++++++
.../src/main/resources/application.properties | 1 +
.../src/main/resources/webSecurityConfig.xml | 1 +
6 files changed, 42 insertions(+), 18 deletions(-)
rename spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/{security => config}/SecurityConfig.java (53%)
create mode 100644 spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/WebConfig.java
create mode 100644 spring-security-modules/spring-security-ldap/src/main/resources/application.properties
diff --git a/spring-security-modules/spring-security-ldap/pom.xml b/spring-security-modules/spring-security-ldap/pom.xml
index f5e8856648..baed682186 100644
--- a/spring-security-modules/spring-security-ldap/pom.xml
+++ b/spring-security-modules/spring-security-ldap/pom.xml
@@ -9,9 +9,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
@@ -21,6 +21,10 @@
org.springframework.boot
spring-boot-starter-security
+
+ org.springframework.boot
+ spring-boot-starter-web
+
org.springframework.boot
spring-boot-starter-thymeleaf
diff --git a/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java
index ec585f2387..2d619cccfa 100644
--- a/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java
+++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java
@@ -2,7 +2,7 @@ package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.support.SpringBootServletInitializer;
+import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@@ -19,15 +19,4 @@ public class SampleLDAPApplication extends SpringBootServletInitializer {
SpringApplication.run(SampleLDAPApplication.class, args);
}
- @Bean
- public WebMvcConfigurerAdapter adapter() {
- return new WebMvcConfigurerAdapter() {
- @Override
- public void addViewControllers(ViewControllerRegistry registry) {
- registry.addViewController("/login")
- .setViewName("login");
- }
- };
- }
-
}
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/SecurityConfig.java
similarity index 53%
rename from spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java
rename to spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/SecurityConfig.java
index a00cb02459..69f90d9de9 100644
--- a/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java
+++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/SecurityConfig.java
@@ -1,4 +1,4 @@
-package com.baeldung.security;
+package com.baeldung.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -14,13 +14,26 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.ldapAuthentication().userSearchBase("ou=people").userSearchFilter("(uid={0})").groupSearchBase("ou=groups").groupSearchFilter("(member={0})").contextSource().root("dc=baeldung,dc=com").ldif("classpath:users.ldif");
+ auth.ldapAuthentication()
+ .userSearchBase("ou=people")
+ .userSearchFilter("(uid={0})")
+ .groupSearchBase("ou=groups")
+ .groupSearchFilter("(member={0})")
+ .contextSource()
+ .root("dc=baeldung,dc=com")
+ .ldif("classpath:users.ldif");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
- http.authorizeRequests().antMatchers("/", "/home").permitAll().anyRequest().authenticated();
- http.formLogin().loginPage("/login").permitAll().and().logout().logoutSuccessUrl("/");
+ http
+ .authorizeRequests()
+ .antMatchers("/", "/home", "/css/**")
+ .permitAll()
+ .anyRequest()
+ .authenticated()
+ .and().formLogin().loginPage("/login").permitAll()
+ .and().logout().logoutSuccessUrl("/");
}
}
diff --git a/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/WebConfig.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/WebConfig.java
new file mode 100644
index 0000000000..9809be1844
--- /dev/null
+++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/config/WebConfig.java
@@ -0,0 +1,16 @@
+package com.baeldung.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+@Configuration
+public class WebConfig implements WebMvcConfigurer {
+
+ @Override
+ public void addViewControllers(ViewControllerRegistry registry) {
+ registry.addViewController("/login")
+ .setViewName("login");
+ }
+}
diff --git a/spring-security-modules/spring-security-ldap/src/main/resources/application.properties b/spring-security-modules/spring-security-ldap/src/main/resources/application.properties
new file mode 100644
index 0000000000..3d0221bb7b
--- /dev/null
+++ b/spring-security-modules/spring-security-ldap/src/main/resources/application.properties
@@ -0,0 +1 @@
+management.health.ldap.enabled=false
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-ldap/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-ldap/src/main/resources/webSecurityConfig.xml
index c13f65de5e..adfd603e54 100644
--- a/spring-security-modules/spring-security-ldap/src/main/resources/webSecurityConfig.xml
+++ b/spring-security-modules/spring-security-ldap/src/main/resources/webSecurityConfig.xml
@@ -10,6 +10,7 @@
+
From 0628c8dd423c2c46932b474b5f2d0d51e6b26369 Mon Sep 17 00:00:00 2001
From: Ali Dehghani
Date: Mon, 30 Mar 2020 17:55:33 +0430
Subject: [PATCH 33/59] Introducing nullsFirst and nullsLast
---
.../com/baeldung/java8/Java8SortUnitTest.java | 63 ++++++++++++++++---
1 file changed, 53 insertions(+), 10 deletions(-)
diff --git a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
index 57d9d8347b..9e510575fc 100644
--- a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
+++ b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
@@ -1,18 +1,17 @@
package com.baeldung.java8;
-import static org.hamcrest.Matchers.equalTo;
+import com.baeldung.java8.entity.Human;
+import com.google.common.collect.Lists;
+import com.google.common.primitives.Ints;
+import org.junit.Assert;
+import org.junit.Test;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.baeldung.java8.entity.Human;
-import com.google.common.collect.Lists;
-import com.google.common.primitives.Ints;
+import static org.hamcrest.Matchers.equalTo;
public class Java8SortUnitTest {
@@ -113,11 +112,11 @@ public class Java8SortUnitTest {
humans.sort(Comparator.comparing(Human::getName));
Assert.assertThat(humans.get(0), equalTo(new Human("Jack", 12)));
}
-
+
@Test
public final void givenStreamNaturalOrdering_whenSortingEntitiesByName_thenCorrectlySorted() {
final List letters = Lists.newArrayList("B", "A", "C");
-
+
final List sortedLetters = letters.stream().sorted().collect(Collectors.toList());
Assert.assertThat(sortedLetters.get(0), equalTo("A"));
}
@@ -126,7 +125,7 @@ public class Java8SortUnitTest {
public final void givenStreamCustomOrdering_whenSortingEntitiesByName_thenCorrectlySorted() {
final List humans = Lists.newArrayList(new Human("Sarah", 10), new Human("Jack", 12));
final Comparator nameComparator = (h1, h2) -> h1.getName().compareTo(h2.getName());
-
+
final List sortedHumans = humans.stream().sorted(nameComparator).collect(Collectors.toList());
Assert.assertThat(sortedHumans.get(0), equalTo(new Human("Jack", 12)));
}
@@ -164,4 +163,48 @@ public class Java8SortUnitTest {
Assert.assertThat(reverseSortedHumans.get(0), equalTo(new Human("Sarah", 10)));
}
+ @Test(expected = NullPointerException.class)
+ public final void givenANullElement_whenSortingEntitiesByName_thenThrowsNPE() {
+ final List humans = Lists.newArrayList(null, new Human("Jack", 12));
+
+ humans.sort((h1, h2) -> h1.getName().compareTo(h2.getName()));
+ }
+
+ @Test
+ public final void givenANullElement_whenSortingEntitiesByNameManually_thenMovesTheNullToLast() {
+ final List humans = Lists.newArrayList(null, new Human("Jack", 12), null);
+
+ humans.sort((h1, h2) -> {
+ if (h1 == null) return h2 == null ? 0 : 1;
+ else if (h2 == null) return -1;
+
+ return h1.getName().compareTo(h2.getName());
+ });
+
+ Assert.assertNotNull(humans.get(0));
+ Assert.assertNull(humans.get(1));
+ Assert.assertNull(humans.get(2));
+ }
+
+ @Test
+ public final void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToLast() {
+ final List humans = Lists.newArrayList(null, new Human("Jack", 12), null);
+
+ humans.sort(Comparator.nullsLast(Comparator.comparing(Human::getName)));
+
+ Assert.assertNotNull(humans.get(0));
+ Assert.assertNull(humans.get(1));
+ Assert.assertNull(humans.get(2));
+ }
+
+ @Test
+ public final void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToStart() {
+ final List humans = Lists.newArrayList(null, new Human("Jack", 12), null);
+
+ humans.sort(Comparator.nullsFirst(Comparator.comparing(Human::getName)));
+
+ Assert.assertNull(humans.get(0));
+ Assert.assertNull(humans.get(1));
+ Assert.assertNotNull(humans.get(2));
+ }
}
From 3f83ed67d3511a057bbf5b0db8e56f214ffd88a7 Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Mon, 30 Mar 2020 23:27:11 +0200
Subject: [PATCH 34/59] JAVA-42: Upgrade spring-security-kerberos to Spring
Boot 2
---
spring-security-modules/spring-security-kerberos/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/spring-security-modules/spring-security-kerberos/pom.xml b/spring-security-modules/spring-security-kerberos/pom.xml
index 6846bdf063..51a48a78c6 100644
--- a/spring-security-modules/spring-security-kerberos/pom.xml
+++ b/spring-security-modules/spring-security-kerberos/pom.xml
@@ -10,9 +10,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
From 3f2d436db4e93cf57428c75758376b8e2d17b3c2 Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Mon, 30 Mar 2020 23:45:37 +0200
Subject: [PATCH 35/59] JAVA-42: Upgrade spring-security-cache-control to
Spring Boot 2
---
.../spring-security-cache-control/pom.xml | 38 +++----------------
.../ResourceEndpointIntegrationTest.java | 2 +-
2 files changed, 7 insertions(+), 33 deletions(-)
diff --git a/spring-security-modules/spring-security-cache-control/pom.xml b/spring-security-modules/spring-security-cache-control/pom.xml
index acc37b41ef..743b3c291d 100644
--- a/spring-security-modules/spring-security-cache-control/pom.xml
+++ b/spring-security-modules/spring-security-cache-control/pom.xml
@@ -8,9 +8,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
@@ -23,41 +23,15 @@
spring-boot-starter-web
- org.springframework.security
- spring-security-core
-
-
- org.springframework.security
- spring-security-config
-
-
- org.springframework.security
- spring-security-web
-
-
- javax.servlet
- javax.servlet-api
- ${javax.servlet-api.version}
+ org.springframework.boot
+ spring-boot-starter-security
- org.hamcrest
- hamcrest
- ${hamcrest.version}
+ org.springframework.boot
+ spring-boot-starter-test
test
-
-
- org.mockito
- mockito-core
- test
-
-
-
- org.springframework
- spring-test
-
-
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java b/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java
index d6a1a97773..d4d24a4986 100644
--- a/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java
+++ b/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/cachecontrol/ResourceEndpointIntegrationTest.java
@@ -4,8 +4,8 @@ import static io.restassured.RestAssured.given;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import io.restassured.http.ContentType;
From a0478a7832e003ac3748ae5b574504b12e64dc1a Mon Sep 17 00:00:00 2001
From: ramkumarvenkat
Date: Tue, 31 Mar 2020 12:09:13 +0530
Subject: [PATCH 36/59] Fix code after article changes
---
.../com/baeldung/guava/entity/Profile.java | 20 ++++++++
.../com/baeldung/guava/entity/Session.java | 13 ++++++
.../java/com/baeldung/guava/entity/User.java | 20 ++++++++
.../guava/mapmaker/GuavaMapMakerUnitTest.java | 46 +++++++++++++------
4 files changed, 84 insertions(+), 15 deletions(-)
create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java
create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java
create mode 100644 guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java
new file mode 100644
index 0000000000..17a6502f39
--- /dev/null
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java
@@ -0,0 +1,20 @@
+package com.baeldung.guava.entity;
+
+public class Profile {
+ private long id;
+ private String type;
+
+ public Profile(long id, String type) {
+ this.id = id;
+ this.type = type;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return type;
+ }
+
+}
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java
new file mode 100644
index 0000000000..b834c23df1
--- /dev/null
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java
@@ -0,0 +1,13 @@
+package com.baeldung.guava.entity;
+
+public class Session {
+ private long id;
+
+ public Session(long id) {
+ this.id = id;
+ }
+
+ public long getId() {
+ return id;
+ }
+}
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java b/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java
new file mode 100644
index 0000000000..613045ec23
--- /dev/null
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java
@@ -0,0 +1,20 @@
+package com.baeldung.guava.entity;
+
+public class User {
+ private long id;
+ private String name;
+
+ public User(long id, String name) {
+ this.id = id;
+ this.name = name;
+ }
+
+ public long getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+}
diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
index 8da459f22e..e2bc1349c6 100644
--- a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
+++ b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
@@ -1,40 +1,56 @@
package com.baeldung.guava.mapmaker;
+import com.baeldung.guava.entity.Profile;
+import com.baeldung.guava.entity.Session;
+import com.baeldung.guava.entity.User;
import com.google.common.collect.MapMaker;
+import org.junit.Assert;
import org.junit.Test;
import java.util.concurrent.ConcurrentMap;
+import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertNotNull;
public class GuavaMapMakerUnitTest {
@Test
- public void whenMakeMap_thenCreated() {
- ConcurrentMap concurrentMap = new MapMaker().makeMap();
- assertNotNull(concurrentMap);
+ public void whenCreateCaches_thenCreated() {
+ ConcurrentMap sessionCache = new MapMaker().makeMap();
+ assertNotNull(sessionCache);
+
+ ConcurrentMap profileCache = new MapMaker().makeMap();
+ assertNotNull(profileCache);
+
+ User userA = new User(1, "UserA");
+
+ sessionCache.put(userA, new Session(100));
+ Assert.assertThat(sessionCache.size(), equalTo(1));
+
+ profileCache.put(userA, new Profile(1000, "Personal"));
+ Assert.assertThat(profileCache.size(), equalTo(1));
}
@Test
- public void whenMakeMapWithWeakKeys_thenCreated() {
- ConcurrentMap concurrentMap = new MapMaker().weakKeys().makeMap();
- assertNotNull(concurrentMap);
+ public void whenCreateCacheWithInitialCapacity_thenCreated() {
+ ConcurrentMap profileCache = new MapMaker().initialCapacity(100).makeMap();
+ assertNotNull(profileCache);
}
@Test
- public void whenMakeMapWithWeakValues_thenCreated() {
- ConcurrentMap concurrentMap = new MapMaker().weakValues().makeMap();
- assertNotNull(concurrentMap);
+ public void whenCreateCacheWithConcurrencyLevel_thenCreated() {
+ ConcurrentMap sessionCache = new MapMaker().concurrencyLevel(10).makeMap();
+ assertNotNull(sessionCache);
}
@Test
- public void whenMakeMapWithInitialCapacity_thenCreated() {
- ConcurrentMap concurrentMap = new MapMaker().initialCapacity(10).makeMap();
- assertNotNull(concurrentMap);
+ public void whenCreateCacheWithWeakKeys_thenCreated() {
+ ConcurrentMap sessionCache = new MapMaker().weakKeys().makeMap();
+ assertNotNull(sessionCache);
}
@Test
- public void whenMakeMapWithConcurrencyLevel_thenCreated() {
- ConcurrentMap concurrentMap = new MapMaker().concurrencyLevel(10).makeMap();
- assertNotNull(concurrentMap);
+ public void whenCreateCacheWithWeakValues_thenCreated() {
+ ConcurrentMap profileCache = new MapMaker().weakValues().makeMap();
+ assertNotNull(profileCache);
}
}
From d1b40a0c026a07b5780e85bd8170f3a397967189 Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Tue, 31 Mar 2020 22:55:19 +0200
Subject: [PATCH 37/59] JAVA-42: Upgrade spring-security-x509 to Spring Boot 2
---
spring-security-modules/spring-security-x509/pom.xml | 4 ++--
.../src/main/resources/application.properties | 6 +++---
.../src/main/resources/application.properties | 4 ++--
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/spring-security-modules/spring-security-x509/pom.xml b/spring-security-modules/spring-security-x509/pom.xml
index a4ff908eed..d4132f058d 100644
--- a/spring-security-modules/spring-security-x509/pom.xml
+++ b/spring-security-modules/spring-security-x509/pom.xml
@@ -9,9 +9,9 @@
com.baeldung
- parent-boot-1
+ parent-boot-2
0.0.1-SNAPSHOT
- ../../parent-boot-1
+ ../../parent-boot-2
diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
index f293d6712d..53dfe9976a 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
@@ -1,8 +1,8 @@
-server.ssl.key-store=../keystore/keystore.jks
+server.ssl.key-store=keystore/keystore.jks
server.ssl.key-store-password=changeit
server.ssl.key-alias=localhost
server.ssl.key-password=changeit
server.ssl.enabled=true
server.port=8443
-security.user.name=Admin
-security.user.password=admin
\ No newline at end of file
+spring.security.user.name=Admin
+spring.security.user.password=admin
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
index 174eba9f98..743c9c4582 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
@@ -4,8 +4,8 @@ server.ssl.key-alias=localhost
server.ssl.key-password=changeit
server.ssl.enabled=true
server.port=8443
-security.user.name=Admin
-security.user.password=admin
+spring.security.user.name=Admin
+spring.security.user.password=admin
server.ssl.trust-store=../keystore/truststore.jks
server.ssl.trust-store-password=changeit
server.ssl.client-auth=need
\ No newline at end of file
From 3d6c7359fa3522e9985d2126509238624a667e04 Mon Sep 17 00:00:00 2001
From: Krzysztof Woyke
Date: Wed, 1 Apr 2020 14:35:03 +0200
Subject: [PATCH 38/59] JAVA-995: Upgrade Spring Boot to the latest 2.2.6
version
---
parent-boot-2/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml
index 6e9e90a6d3..c7bb11b1d5 100644
--- a/parent-boot-2/pom.xml
+++ b/parent-boot-2/pom.xml
@@ -81,7 +81,7 @@
3.3.0
1.0.22.RELEASE
- 2.2.2.RELEASE
+ 2.2.6.RELEASE
From 37ed8f63271c225427a172d8b95224f5be09f626 Mon Sep 17 00:00:00 2001
From: Waldemar
Date: Wed, 1 Apr 2020 20:29:34 +0200
Subject: [PATCH 39/59] BAEL-2398 rename package
---
coroutines-java/pom.xml | 4 ++--
.../main/java/com/baeldung/{introduction => quasar}/App.java | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
rename coroutines-java/src/main/java/com/baeldung/{introduction => quasar}/App.java (86%)
diff --git a/coroutines-java/pom.xml b/coroutines-java/pom.xml
index 3546aa5673..caee769a78 100644
--- a/coroutines-java/pom.xml
+++ b/coroutines-java/pom.xml
@@ -53,7 +53,7 @@
exec-maven-plugin
1.6.0
- com.baeldung.introduction.App
+ com.baeldung.quasar.App
target/classes
java
@@ -68,7 +68,7 @@
- com.baeldung.introduction.App
+ com.baeldung.quasar.App
diff --git a/coroutines-java/src/main/java/com/baeldung/introduction/App.java b/coroutines-java/src/main/java/com/baeldung/quasar/App.java
similarity index 86%
rename from coroutines-java/src/main/java/com/baeldung/introduction/App.java
rename to coroutines-java/src/main/java/com/baeldung/quasar/App.java
index f915464973..510877d1be 100644
--- a/coroutines-java/src/main/java/com/baeldung/introduction/App.java
+++ b/coroutines-java/src/main/java/com/baeldung/quasar/App.java
@@ -1,4 +1,4 @@
-package com.baeldung.introduction;
+package com.baeldung.quasar;
import co.paralleluniverse.fibers.Fiber;
From 7187cb0dfbd3487877248742309519bed0f55d49 Mon Sep 17 00:00:00 2001
From: ramkumarvenkat
Date: Thu, 2 Apr 2020 07:13:19 +0530
Subject: [PATCH 40/59] Change package name
---
.../java/com/baeldung/guava/{entity => mapmaker}/Profile.java | 2 +-
.../java/com/baeldung/guava/{entity => mapmaker}/Session.java | 2 +-
.../java/com/baeldung/guava/{entity => mapmaker}/User.java | 2 +-
.../com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java | 3 ---
4 files changed, 3 insertions(+), 6 deletions(-)
rename guava-collections-map/src/main/java/com/baeldung/guava/{entity => mapmaker}/Profile.java (88%)
rename guava-collections-map/src/main/java/com/baeldung/guava/{entity => mapmaker}/Session.java (81%)
rename guava-collections-map/src/main/java/com/baeldung/guava/{entity => mapmaker}/User.java (88%)
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java
similarity index 88%
rename from guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java
rename to guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java
index 17a6502f39..165c5a9f8f 100644
--- a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Profile.java
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Profile.java
@@ -1,4 +1,4 @@
-package com.baeldung.guava.entity;
+package com.baeldung.guava.mapmaker;
public class Profile {
private long id;
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java
similarity index 81%
rename from guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java
rename to guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java
index b834c23df1..a614f431f8 100644
--- a/guava-collections-map/src/main/java/com/baeldung/guava/entity/Session.java
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/Session.java
@@ -1,4 +1,4 @@
-package com.baeldung.guava.entity;
+package com.baeldung.guava.mapmaker;
public class Session {
private long id;
diff --git a/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java
similarity index 88%
rename from guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java
rename to guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java
index 613045ec23..a7f0435049 100644
--- a/guava-collections-map/src/main/java/com/baeldung/guava/entity/User.java
+++ b/guava-collections-map/src/main/java/com/baeldung/guava/mapmaker/User.java
@@ -1,4 +1,4 @@
-package com.baeldung.guava.entity;
+package com.baeldung.guava.mapmaker;
public class User {
private long id;
diff --git a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
index e2bc1349c6..754e3ac099 100644
--- a/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
+++ b/guava-collections-map/src/test/java/com/baeldung/guava/mapmaker/GuavaMapMakerUnitTest.java
@@ -1,8 +1,5 @@
package com.baeldung.guava.mapmaker;
-import com.baeldung.guava.entity.Profile;
-import com.baeldung.guava.entity.Session;
-import com.baeldung.guava.entity.User;
import com.google.common.collect.MapMaker;
import org.junit.Assert;
import org.junit.Test;
From 509423ba5714718292b4b08782afe7f73dbcd80f Mon Sep 17 00:00:00 2001
From: Krzysztof Woyke
Date: Thu, 2 Apr 2020 16:10:53 +0200
Subject: [PATCH 41/59] JAVA-997: Upgrade Spring Core & Security to the latest
versions
---
parent-spring-5/pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml
index 27f355bfad..c75655ebc8 100644
--- a/parent-spring-5/pom.xml
+++ b/parent-spring-5/pom.xml
@@ -31,8 +31,8 @@
- 5.2.2.RELEASE
- 5.2.1.RELEASE
+ 5.2.5.RELEASE
+ 5.2.3.RELEASE
\ No newline at end of file
From 55d1d12216712635a005ab6d7629ebeb2fc97f40 Mon Sep 17 00:00:00 2001
From: sampadawagde
Date: Sat, 4 Apr 2020 12:55:27 +0530
Subject: [PATCH 42/59] JAVA-624: Updated READMEs for prev links
---
java-collections-maps-2/README.md | 2 +-
java-collections-maps-3/README.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/java-collections-maps-2/README.md b/java-collections-maps-2/README.md
index 71c6a3f32b..2188960543 100644
--- a/java-collections-maps-2/README.md
+++ b/java-collections-maps-2/README.md
@@ -13,4 +13,4 @@ This module contains articles about Map data structures in Java.
- [Sort a HashMap in Java](https://www.baeldung.com/java-hashmap-sort)
- [Finding the Highest Value in a Java Map](https://www.baeldung.com/java-find-map-max)
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
-- More articles: [[<-- prev>]](/java-collections-maps) [[next -->]](/java-collections-maps-3)
+- More articles: [[<-- prev]](/java-collections-maps) [[next -->]](/java-collections-maps-3)
diff --git a/java-collections-maps-3/README.md b/java-collections-maps-3/README.md
index 8f185f6ad4..886461a35c 100644
--- a/java-collections-maps-3/README.md
+++ b/java-collections-maps-3/README.md
@@ -5,4 +5,4 @@ This module contains articles about Map data structures in Java.
### Relevant Articles:
- [Java TreeMap vs HashMap](https://www.baeldung.com/java-treemap-vs-hashmap)
- [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps)
-- More articles: [[<-- prev>]](/java-collections-maps-2)
+- More articles: [[<-- prev]](/java-collections-maps-2)
From ffc854e2f0d92d531aae9d576c387bfb3ee078d5 Mon Sep 17 00:00:00 2001
From: Waldemar
Date: Sat, 4 Apr 2020 11:38:24 +0200
Subject: [PATCH 43/59] BAEL-2398: add libraries-concurrency module
---
libraries-concurrency/pom.xml | 15 +++++++++++++++
pom.xml | 1 +
2 files changed, 16 insertions(+)
create mode 100644 libraries-concurrency/pom.xml
diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml
new file mode 100644
index 0000000000..0dc546e63a
--- /dev/null
+++ b/libraries-concurrency/pom.xml
@@ -0,0 +1,15 @@
+
+
+
+ parent-modules
+ com.baeldung
+ 1.0.0-SNAPSHOT
+
+ 4.0.0
+
+ libraries-concurrency
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a295439951..9694941645 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1259,6 +1259,7 @@
wildfly
xml
xstream
+ libraries-concurrency
From 0cb40ad2665b4ed854938cc57d126a73ba6b4a1a Mon Sep 17 00:00:00 2001
From: Waldemar
Date: Sat, 4 Apr 2020 11:48:18 +0200
Subject: [PATCH 44/59] BAEL-2398: move coroutines-java module into
libraries-concurrency module
---
.../coroutines-java}/pom.xml | 15 +++++----------
.../src/main/java/com/baeldung/quasar/App.java | 0
libraries-concurrency/pom.xml | 11 ++++++++---
3 files changed, 13 insertions(+), 13 deletions(-)
rename {coroutines-java => libraries-concurrency/coroutines-java}/pom.xml (89%)
rename {coroutines-java => libraries-concurrency/coroutines-java}/src/main/java/com/baeldung/quasar/App.java (100%)
diff --git a/coroutines-java/pom.xml b/libraries-concurrency/coroutines-java/pom.xml
similarity index 89%
rename from coroutines-java/pom.xml
rename to libraries-concurrency/coroutines-java/pom.xml
index caee769a78..72356738d4 100644
--- a/coroutines-java/pom.xml
+++ b/libraries-concurrency/coroutines-java/pom.xml
@@ -2,19 +2,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
-
- com.baeldung
coroutines-java
- 1.0-SNAPSHOT
-
coroutines-java
- http://baeldung.com
-
- UTF-8
- 1.8
- 1.8
-
+
+ com.baeldung
+ libraries-concurrency
+ 1.0.0-SNAPSHOT
+
diff --git a/coroutines-java/src/main/java/com/baeldung/quasar/App.java b/libraries-concurrency/coroutines-java/src/main/java/com/baeldung/quasar/App.java
similarity index 100%
rename from coroutines-java/src/main/java/com/baeldung/quasar/App.java
rename to libraries-concurrency/coroutines-java/src/main/java/com/baeldung/quasar/App.java
diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml
index 0dc546e63a..5ba722ae2e 100644
--- a/libraries-concurrency/pom.xml
+++ b/libraries-concurrency/pom.xml
@@ -2,14 +2,19 @@
+ 4.0.0
+ libraries-concurrency
+ libraries-concurrency
+ pom
+
parent-modules
com.baeldung
1.0.0-SNAPSHOT
- 4.0.0
-
- libraries-concurrency
+
+ coroutines-java
+
\ No newline at end of file
From 585ed13442a50a8471d5df66d831d4b069e27c2a Mon Sep 17 00:00:00 2001
From: Waldemar
Date: Sat, 4 Apr 2020 11:50:20 +0200
Subject: [PATCH 45/59] BAEL-2398: rename coroutines-java to
coroutines-with-quasar
---
.../{coroutines-java => coroutines-with-quasar}/pom.xml | 4 ++--
.../src/main/java/com/baeldung/quasar/App.java | 0
libraries-concurrency/pom.xml | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
rename libraries-concurrency/{coroutines-java => coroutines-with-quasar}/pom.xml (97%)
rename libraries-concurrency/{coroutines-java => coroutines-with-quasar}/src/main/java/com/baeldung/quasar/App.java (100%)
diff --git a/libraries-concurrency/coroutines-java/pom.xml b/libraries-concurrency/coroutines-with-quasar/pom.xml
similarity index 97%
rename from libraries-concurrency/coroutines-java/pom.xml
rename to libraries-concurrency/coroutines-with-quasar/pom.xml
index 72356738d4..59241272e7 100644
--- a/libraries-concurrency/coroutines-java/pom.xml
+++ b/libraries-concurrency/coroutines-with-quasar/pom.xml
@@ -2,8 +2,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- coroutines-java
- coroutines-java
+ coroutines-with-quasar
+ coroutines-with-quasar
com.baeldung
diff --git a/libraries-concurrency/coroutines-java/src/main/java/com/baeldung/quasar/App.java b/libraries-concurrency/coroutines-with-quasar/src/main/java/com/baeldung/quasar/App.java
similarity index 100%
rename from libraries-concurrency/coroutines-java/src/main/java/com/baeldung/quasar/App.java
rename to libraries-concurrency/coroutines-with-quasar/src/main/java/com/baeldung/quasar/App.java
diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml
index 5ba722ae2e..7ae834025f 100644
--- a/libraries-concurrency/pom.xml
+++ b/libraries-concurrency/pom.xml
@@ -14,7 +14,7 @@
- coroutines-java
+ coroutines-with-quasar
\ No newline at end of file
From 1acadab18b1fec5fe1422faf7c01d6b4c5b45ffd Mon Sep 17 00:00:00 2001
From: Fabricio Pautasso
Date: Sat, 4 Apr 2020 11:55:13 -0300
Subject: [PATCH 46/59] BAEL-3918 - Adding BigDecimal numbers using the Stream
API (#8900)
* BAEL-3918 - Adding BigDecimal numbers using the Stream API
* BAEL-3918 - Adding BigDecimal numbers using the Stream API
* BAEL-3918 - Adding BigDecimal numbers using the Stream API
* BAEL-3918 - Updating test methods names to be compliant with Baeldung standards
* Minor name change
Co-authored-by: ashleyfrieze
---
.../bigdecimals/AddNumbersUnitTest.java | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/bigdecimals/AddNumbersUnitTest.java
diff --git a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/bigdecimals/AddNumbersUnitTest.java b/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/bigdecimals/AddNumbersUnitTest.java
new file mode 100644
index 0000000000..9399908b30
--- /dev/null
+++ b/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/bigdecimals/AddNumbersUnitTest.java
@@ -0,0 +1,42 @@
+package com.baeldung.streams.bigdecimals;
+
+import static org.junit.Assert.assertEquals;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.junit.Test;
+
+public class AddNumbersUnitTest {
+
+ @Test
+ public void givenIntStream_whenSum_thenResultIsCorrect() {
+ IntStream intNumbers = IntStream.range(0, 3);
+ assertEquals(3, intNumbers.sum());
+ }
+
+ @Test
+ public void givenCollectionOfDouble_whenUsingMapToDoubleToSum_thenResultIsCorrect() {
+ List doubleNumbers = Arrays.asList(23.48, 52.26, 13.5);
+ double result = doubleNumbers.stream()
+ .mapToDouble(Double::doubleValue)
+ .sum();
+ assertEquals(89.24, result, .1);
+ }
+
+ public void givenStreamOfIntegers_whenUsingReduceToSum_thenResultIsCorrect() {
+ Stream intNumbers = Stream.of(0, 1, 2);
+ int result = intNumbers.reduce(0, Integer::sum);
+ assertEquals(106, result);
+ }
+
+ public void givenStreamOfBigDecimals_whenUsingReduceToSum_thenResultIsCorrect() {
+ Stream bigDecimalNumber = Stream.of(BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN);
+ BigDecimal result = bigDecimalNumber.reduce(BigDecimal.ZERO, BigDecimal::add);
+ assertEquals(11, result);
+ }
+
+}
From 487d6b38fc3ac13af3dd026745c83e56b0716f13 Mon Sep 17 00:00:00 2001
From: mikr
Date: Sat, 4 Apr 2020 20:24:48 +0200
Subject: [PATCH 47/59] JAVA-117 Standardize spring-boot-modules/spring-boot
---
.../java/{org => com}/baeldung/boot/Application.java | 2 +-
.../baeldung/boot/config/H2JpaConfig.java | 6 +++---
.../{org => com}/baeldung/boot/config/WebConfig.java | 8 ++++----
.../boot/controller/servlet/HelloWorldServlet.java | 2 +-
.../controller/servlet/SpringHelloWorldServlet.java | 2 +-
.../boot/converter/GenericBigDecimalConverter.java | 2 +-
.../boot/converter/StringToEmployeeConverter.java | 2 +-
.../boot/converter/StringToEnumConverterFactory.java | 2 +-
.../StringToEmployeeConverterController.java | 2 +-
.../{org => com}/baeldung/boot/domain/Modes.java | 2 +-
.../common/error/MyCustomErrorController.java | 2 +-
.../error/SpringHelloServletRegistrationBean.java | 2 +-
.../common/error/controller/ErrorController.java | 2 +-
.../MyServletContainerCustomizationBean.java | 2 +-
.../resources/ExecutorServiceExitCodeGenerator.java | 2 +-
.../{org => com}/baeldung/demo/DemoApplication.java | 2 +-
.../baeldung/demo/boottest/Employee.java | 2 +-
.../baeldung/demo/boottest/EmployeeRepository.java | 2 +-
.../demo/boottest/EmployeeRestController.java | 2 +-
.../baeldung/demo/boottest/EmployeeService.java | 2 +-
.../baeldung/demo/boottest/EmployeeServiceImpl.java | 2 +-
.../baeldung/demo/components/FooService.java | 6 +++---
.../baeldung/demo/exceptions/CommonException.java | 2 +-
.../demo/exceptions/FooNotFoundException.java | 2 +-
.../java/{org => com}/baeldung/demo/model/Foo.java | 2 +-
.../baeldung/demo/repository/FooRepository.java | 4 ++--
.../baeldung/demo/service/FooController.java | 6 +++---
.../endpoints/info/TotalUsersInfoContributor.java | 4 ++--
.../baeldung/main/SpringBootApplication.java | 12 ++++++------
.../main/java/{org => com}/baeldung/model/User.java | 2 +-
.../baeldung/repository/UserRepository.java | 4 ++--
.../baeldung/session/exception/Application.java | 4 ++--
.../session/exception/repository/FooRepository.java | 4 ++--
.../exception/repository/FooRepositoryImpl.java | 4 ++--
.../baeldung/startup/AppStartupRunner.java | 2 +-
.../startup/CommandLineAppStartupRunner.java | 2 +-
.../baeldung/boot/ApplicationIntegrationTest.java | 4 ++--
.../boot/DemoApplicationIntegrationTest.java | 4 ++--
.../repository/FooRepositoryIntegrationTest.java | 8 ++++----
.../repository/HibernateSessionIntegrationTest.java | 8 ++++----
.../NoHibernateSessionIntegrationTest.java | 8 ++++----
.../converter/CustomConverterIntegrationTest.java | 6 +++---
...ToEmployeeConverterControllerIntegrationTest.java | 4 ++--
.../boottest/EmployeeControllerIntegrationTest.java | 5 +----
.../boottest/EmployeeRepositoryIntegrationTest.java | 6 +++---
.../EmployeeRestControllerIntegrationTest.java | 4 ++--
.../boottest/EmployeeServiceImplIntegrationTest.java | 6 +++++-
.../baeldung/demo/boottest/JsonUtil.java | 2 +-
.../repository/UserRepositoryIntegrationTest.java | 7 ++++---
49 files changed, 93 insertions(+), 91 deletions(-)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/Application.java (93%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/config/H2JpaConfig.java (89%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/config/WebConfig.java (71%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/controller/servlet/HelloWorldServlet.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/converter/GenericBigDecimalConverter.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/converter/StringToEmployeeConverter.java (90%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/converter/StringToEnumConverterFactory.java (95%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/converter/controller/StringToEmployeeConverterController.java (91%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/boot/domain/Modes.java (54%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/common/error/MyCustomErrorController.java (93%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/common/error/SpringHelloServletRegistrationBean.java (91%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/common/error/controller/ErrorController.java (90%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/common/properties/MyServletContainerCustomizationBean.java (95%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java (94%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/DemoApplication.java (94%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/boottest/Employee.java (95%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/boottest/EmployeeRepository.java (91%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/boottest/EmployeeRestController.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/boottest/EmployeeService.java (89%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/boottest/EmployeeServiceImpl.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/components/FooService.java (77%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/exceptions/CommonException.java (85%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/exceptions/FooNotFoundException.java (86%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/model/Foo.java (95%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/repository/FooRepository.java (70%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/demo/service/FooController.java (85%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/endpoints/info/TotalUsersInfoContributor.java (89%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/main/SpringBootApplication.java (78%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/model/User.java (96%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/repository/UserRepository.java (98%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/session/exception/Application.java (87%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/session/exception/repository/FooRepository.java (50%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/session/exception/repository/FooRepositoryImpl.java (88%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/startup/AppStartupRunner.java (95%)
rename spring-boot-modules/spring-boot/src/main/java/{org => com}/baeldung/startup/CommandLineAppStartupRunner.java (94%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/boot/ApplicationIntegrationTest.java (85%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/boot/DemoApplicationIntegrationTest.java (87%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/boot/repository/FooRepositoryIntegrationTest.java (82%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/boot/repository/HibernateSessionIntegrationTest.java (81%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java (78%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/converter/CustomConverterIntegrationTest.java (94%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java (94%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java (93%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java (94%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java (97%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java (94%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/demo/boottest/JsonUtil.java (91%)
rename spring-boot-modules/spring-boot/src/test/java/{org => com}/baeldung/repository/UserRepositoryIntegrationTest.java (92%)
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/Application.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java
similarity index 93%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/Application.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java
index c1b6558b26..cb0d0c1532 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/Application.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/Application.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot;
+package com.baeldung.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
similarity index 89%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
index 92a6ed7ab0..928928c9a5 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/H2JpaConfig.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/H2JpaConfig.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.config;
+package com.baeldung.boot.config;
import java.util.Properties;
@@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
-@EnableJpaRepositories(basePackages = { "org.baeldung.boot.repository", "org.baeldung.boot.boottest", "org.baeldung.repository" })
+@EnableJpaRepositories(basePackages = { "com.baeldung.boot.repository", "com.baeldung.boot.boottest", "com.baeldung.repository" })
@PropertySource("classpath:persistence-generic-entity.properties")
@EnableTransactionManagement
public class H2JpaConfig {
@@ -41,7 +41,7 @@ public class H2JpaConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] { "org.baeldung.boot.domain", "org.baeldung.boot.model", "org.baeldung.boot.boottest", "org.baeldung.model" });
+ em.setPackagesToScan(new String[] { "com.baeldung.boot.domain", "com.baeldung.boot.model", "com.baeldung.boot.boottest", "com.baeldung.model" });
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(additionalProperties());
return em;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java
similarity index 71%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java
index 9554facb12..b23c910a04 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/config/WebConfig.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/config/WebConfig.java
@@ -1,8 +1,8 @@
-package org.baeldung.boot.config;
+package com.baeldung.boot.config;
-import org.baeldung.boot.converter.StringToEmployeeConverter;
-import org.baeldung.boot.converter.StringToEnumConverterFactory;
-import org.baeldung.boot.converter.GenericBigDecimalConverter;
+import com.baeldung.boot.converter.StringToEmployeeConverter;
+import com.baeldung.boot.converter.StringToEnumConverterFactory;
+import com.baeldung.boot.converter.GenericBigDecimalConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java
index 34ad11254c..80c75aa8b5 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/HelloWorldServlet.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/HelloWorldServlet.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.controller.servlet;
+package com.baeldung.boot.controller.servlet;
import java.io.IOException;
import java.io.PrintWriter;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java
index 91547683c6..f276f94b7c 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/controller/servlet/SpringHelloWorldServlet.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.controller.servlet;
+package com.baeldung.boot.controller.servlet;
import java.io.IOException;
import java.io.PrintWriter;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java
index 8add28fc2d..fc73cfee5f 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/GenericBigDecimalConverter.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/GenericBigDecimalConverter.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.converter;
+package com.baeldung.boot.converter;
import com.google.common.collect.ImmutableSet;
import org.springframework.core.convert.TypeDescriptor;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java
similarity index 90%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java
index 1bf75b38f0..ac635532ea 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEmployeeConverter.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEmployeeConverter.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.converter;
+package com.baeldung.boot.converter;
import org.springframework.core.convert.converter.Converter;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java
similarity index 95%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java
index ddb2cd2b08..a2dce11a6a 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/StringToEnumConverterFactory.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/StringToEnumConverterFactory.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.converter;
+package com.baeldung.boot.converter;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java
similarity index 91%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java
index 27bad4c387..260b1c734b 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/converter/controller/StringToEmployeeConverterController.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/converter/controller/StringToEmployeeConverterController.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.converter.controller;
+package com.baeldung.boot.converter.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java
similarity index 54%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java
index dcba064e8c..7717294996 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/boot/domain/Modes.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/boot/domain/Modes.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.domain;
+package com.baeldung.boot.domain;
public enum Modes {
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/MyCustomErrorController.java
similarity index 93%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/MyCustomErrorController.java
index df0e3ec0b2..373ae8f745 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/MyCustomErrorController.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/MyCustomErrorController.java
@@ -1,4 +1,4 @@
-package org.baeldung.common.error;
+package com.baeldung.common.error;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.GetMapping;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/SpringHelloServletRegistrationBean.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java
similarity index 91%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/SpringHelloServletRegistrationBean.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java
index 774cf1b970..3f51a4ab69 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/SpringHelloServletRegistrationBean.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/SpringHelloServletRegistrationBean.java
@@ -1,4 +1,4 @@
-package org.baeldung.common.error;
+package com.baeldung.common.error;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/controller/ErrorController.java
similarity index 90%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/controller/ErrorController.java
index ac5f92e9c9..1e5fbf3ac4 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/error/controller/ErrorController.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/error/controller/ErrorController.java
@@ -1,4 +1,4 @@
-package org.baeldung.common.error.controller;
+package com.baeldung.common.error.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java
similarity index 95%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java
index d553d44769..be503b1b6c 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/properties/MyServletContainerCustomizationBean.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/properties/MyServletContainerCustomizationBean.java
@@ -1,4 +1,4 @@
-package org.baeldung.common.properties;
+package com.baeldung.common.properties;
import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java
index 64853a9941..1db7054f85 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/common/resources/ExecutorServiceExitCodeGenerator.java
@@ -1,4 +1,4 @@
-package org.baeldung.common.resources;
+package com.baeldung.common.resources;
import org.springframework.boot.ExitCodeGenerator;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/DemoApplication.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/DemoApplication.java
index 4a88fcea07..eb091b4695 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/DemoApplication.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/DemoApplication.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo;
+package com.baeldung.demo;
import com.baeldung.graphql.GraphqlConfiguration;
import org.springframework.boot.SpringApplication;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/Employee.java
similarity index 95%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/Employee.java
index 645ce2838a..fa3c1dc809 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/Employee.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/Employee.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRepository.java
similarity index 91%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRepository.java
index 00fdbfaae4..b6850d587e 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRepository.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRepository.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import java.util.List;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRestController.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRestController.java
index 516bff0e8c..7d2e06d4a0 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeRestController.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeRestController.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import java.util.List;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeService.java
similarity index 89%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeService.java
index 07765a511c..ff1976cad1 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeService.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeService.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import java.util.List;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeServiceImpl.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeServiceImpl.java
index a1639b29cc..156fc571f3 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/boottest/EmployeeServiceImpl.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/boottest/EmployeeServiceImpl.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import java.util.List;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/components/FooService.java
similarity index 77%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/components/FooService.java
index 66943f6461..98a0db67ef 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/components/FooService.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/components/FooService.java
@@ -1,7 +1,7 @@
-package org.baeldung.demo.components;
+package com.baeldung.demo.components;
-import org.baeldung.demo.model.Foo;
-import org.baeldung.demo.repository.FooRepository;
+import com.baeldung.demo.model.Foo;
+import com.baeldung.demo.repository.FooRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/CommonException.java
similarity index 85%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/CommonException.java
index 51dd7bbd44..276802d0b9 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/CommonException.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/CommonException.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.exceptions;
+package com.baeldung.demo.exceptions;
public class CommonException extends RuntimeException {
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java
similarity index 86%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java
index 59796c58f0..8c425d078e 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/exceptions/FooNotFoundException.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/exceptions/FooNotFoundException.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.exceptions;
+package com.baeldung.demo.exceptions;
public class FooNotFoundException extends RuntimeException {
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/model/Foo.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/model/Foo.java
similarity index 95%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/model/Foo.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/model/Foo.java
index e5638cfd3d..796bcca11b 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/model/Foo.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/model/Foo.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.model;
+package com.baeldung.demo.model;
import java.io.Serializable;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/repository/FooRepository.java
similarity index 70%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/repository/FooRepository.java
index c04e0c7438..ed27ac23bc 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/repository/FooRepository.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/repository/FooRepository.java
@@ -1,6 +1,6 @@
-package org.baeldung.demo.repository;
+package com.baeldung.demo.repository;
-import org.baeldung.demo.model.Foo;
+import com.baeldung.demo.model.Foo;
import org.springframework.data.jpa.repository.JpaRepository;
public interface FooRepository extends JpaRepository {
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/service/FooController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/service/FooController.java
similarity index 85%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/service/FooController.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/service/FooController.java
index c28dcde1a7..c72c52fa3e 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/demo/service/FooController.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/demo/service/FooController.java
@@ -1,7 +1,7 @@
-package org.baeldung.demo.service;
+package com.baeldung.demo.service;
-import org.baeldung.demo.components.FooService;
-import org.baeldung.demo.model.Foo;
+import com.baeldung.demo.model.Foo;
+import com.baeldung.demo.components.FooService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/endpoints/info/TotalUsersInfoContributor.java
similarity index 89%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/endpoints/info/TotalUsersInfoContributor.java
index 34b50a2c0a..c316cabda5 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/endpoints/info/TotalUsersInfoContributor.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/endpoints/info/TotalUsersInfoContributor.java
@@ -1,9 +1,9 @@
-package org.baeldung.endpoints.info;
+package com.baeldung.endpoints.info;
import java.util.HashMap;
import java.util.Map;
-import org.baeldung.repository.UserRepository;
+import com.baeldung.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
similarity index 78%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
index a203659d63..c8cfb50f1c 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/main/SpringBootApplication.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
@@ -1,9 +1,9 @@
-package org.baeldung.main;
+package com.baeldung.main;
-import org.baeldung.boot.controller.servlet.HelloWorldServlet;
-import org.baeldung.boot.controller.servlet.SpringHelloWorldServlet;
-import org.baeldung.common.error.SpringHelloServletRegistrationBean;
-import org.baeldung.common.resources.ExecutorServiceExitCodeGenerator;
+import com.baeldung.boot.controller.servlet.HelloWorldServlet;
+import com.baeldung.boot.controller.servlet.SpringHelloWorldServlet;
+import com.baeldung.common.error.SpringHelloServletRegistrationBean;
+import com.baeldung.common.resources.ExecutorServiceExitCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
@@ -18,7 +18,7 @@ import java.util.concurrent.Executors;
@RestController
@EnableAutoConfiguration
-@ComponentScan({ "org.baeldung.common.error", "org.baeldung.common.error.controller", "org.baeldung.common.properties", "org.baeldung.common.resources", "org.baeldung.endpoints", "org.baeldung.service", "org.baeldung.monitor.jmx", "org.baeldung.boot.config" })
+@ComponentScan({ "org.baeldung.common.error", "com.baeldung.common.error.controller", "com.baeldung.common.properties", "com.baeldung.common.resources", "com.baeldung.endpoints", "com.baeldung.service", "com.baeldung.monitor.jmx", "com.baeldung.boot.config" })
public class SpringBootApplication {
private static ApplicationContext applicationContext;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/model/User.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java
similarity index 96%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/model/User.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java
index eb886338a0..cc5f27f38c 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/model/User.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/model/User.java
@@ -1,4 +1,4 @@
-package org.baeldung.model;
+package com.baeldung.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/repository/UserRepository.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java
similarity index 98%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/repository/UserRepository.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java
index 752664cd5d..4dd863fb17 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/repository/UserRepository.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/repository/UserRepository.java
@@ -1,6 +1,6 @@
-package org.baeldung.repository;
+package com.baeldung.repository;
-import org.baeldung.model.User;
+import com.baeldung.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/Application.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/Application.java
similarity index 87%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/Application.java
index 354c64c258..de4ca5998e 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/Application.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/Application.java
@@ -1,6 +1,6 @@
-package org.baeldung.session.exception;
+package com.baeldung.session.exception;
-import org.baeldung.demo.model.Foo;
+import com.baeldung.demo.model.Foo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepository.java
similarity index 50%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepository.java
index ce7bbfe57b..5e748973ed 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepository.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepository.java
@@ -1,6 +1,6 @@
-package org.baeldung.session.exception.repository;
+package com.baeldung.session.exception.repository;
-import org.baeldung.demo.model.Foo;
+import com.baeldung.demo.model.Foo;
public interface FooRepository {
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java
similarity index 88%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java
index 607bae83ba..a304373d6c 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/session/exception/repository/FooRepositoryImpl.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/session/exception/repository/FooRepositoryImpl.java
@@ -1,8 +1,8 @@
-package org.baeldung.session.exception.repository;
+package com.baeldung.session.exception.repository;
import javax.persistence.EntityManagerFactory;
-import org.baeldung.demo.model.Foo;
+import com.baeldung.demo.model.Foo;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/AppStartupRunner.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java
similarity index 95%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/AppStartupRunner.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java
index d491bdb42c..0495473704 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/AppStartupRunner.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/AppStartupRunner.java
@@ -1,4 +1,4 @@
-package org.baeldung.startup;
+package com.baeldung.startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/CommandLineAppStartupRunner.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/CommandLineAppStartupRunner.java
rename to spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java
index 6a7be59c21..48c5225cf1 100644
--- a/spring-boot-modules/spring-boot/src/main/java/org/baeldung/startup/CommandLineAppStartupRunner.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/startup/CommandLineAppStartupRunner.java
@@ -1,4 +1,4 @@
-package org.baeldung.startup;
+package com.baeldung.startup;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/ApplicationIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java
similarity index 85%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/ApplicationIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java
index 5e351157c8..462291e0ac 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/ApplicationIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/ApplicationIntegrationTest.java
@@ -1,6 +1,6 @@
-package org.baeldung.boot;
+package com.baeldung.boot;
-import org.baeldung.session.exception.Application;
+import com.baeldung.session.exception.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java
similarity index 87%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java
index 0541da3199..aaf4f1f780 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/DemoApplicationIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/DemoApplicationIntegrationTest.java
@@ -1,6 +1,6 @@
-package org.baeldung.boot;
+package com.baeldung.boot;
-import org.baeldung.demo.DemoApplication;
+import com.baeldung.demo.DemoApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java
similarity index 82%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java
index c32e36d7e3..1772739d20 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/FooRepositoryIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/FooRepositoryIntegrationTest.java
@@ -1,8 +1,8 @@
-package org.baeldung.boot.repository;
+package com.baeldung.boot.repository;
-import org.baeldung.boot.DemoApplicationIntegrationTest;
-import org.baeldung.demo.model.Foo;
-import org.baeldung.demo.repository.FooRepository;
+import com.baeldung.boot.DemoApplicationIntegrationTest;
+import com.baeldung.demo.model.Foo;
+import com.baeldung.demo.repository.FooRepository;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java
similarity index 81%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java
index b22282e896..2fe072bb67 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/HibernateSessionIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/HibernateSessionIntegrationTest.java
@@ -1,8 +1,8 @@
-package org.baeldung.boot.repository;
+package com.baeldung.boot.repository;
-import org.baeldung.boot.DemoApplicationIntegrationTest;
-import org.baeldung.demo.model.Foo;
-import org.baeldung.demo.repository.FooRepository;
+import com.baeldung.boot.DemoApplicationIntegrationTest;
+import com.baeldung.demo.model.Foo;
+import com.baeldung.demo.repository.FooRepository;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java
similarity index 78%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java
index 5c8d10223b..2e3326e6b1 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/boot/repository/NoHibernateSessionIntegrationTest.java
@@ -1,8 +1,8 @@
-package org.baeldung.boot.repository;
+package com.baeldung.boot.repository;
-import org.baeldung.boot.ApplicationIntegrationTest;
-import org.baeldung.demo.model.Foo;
-import org.baeldung.session.exception.repository.FooRepository;
+import com.baeldung.boot.ApplicationIntegrationTest;
+import com.baeldung.demo.model.Foo;
+import com.baeldung.session.exception.repository.FooRepository;
import org.hibernate.HibernateException;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/CustomConverterIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/CustomConverterIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java
index bd1ae2c8fa..4619964783 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/CustomConverterIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/CustomConverterIntegrationTest.java
@@ -1,9 +1,9 @@
-package org.baeldung.converter;
+package com.baeldung.converter;
import com.baeldung.toggle.Employee;
-import org.baeldung.boot.Application;
-import org.baeldung.boot.domain.Modes;
+import com.baeldung.boot.Application;
+import com.baeldung.boot.domain.Modes;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java
index 2afda7565a..52dc542ebf 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/converter/controller/StringToEmployeeConverterControllerIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung.converter.controller;
+package com.baeldung.converter.controller;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -14,7 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-import org.baeldung.boot.Application;
+import com.baeldung.boot.Application;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = Application.class)
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java
similarity index 93%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java
index 2d70583a54..962abf0fa3 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeControllerIntegrationTest.java
@@ -1,8 +1,5 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
-import org.baeldung.demo.boottest.Employee;
-import org.baeldung.demo.boottest.EmployeeRestController;
-import org.baeldung.demo.boottest.EmployeeService;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
index 3042f95a46..164887886b 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRepositoryIntegrationTest.java
@@ -1,7 +1,7 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
-import org.baeldung.demo.boottest.Employee;
-import org.baeldung.demo.boottest.EmployeeRepository;
+import com.baeldung.demo.boottest.Employee;
+import com.baeldung.demo.boottest.EmployeeRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java
similarity index 97%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java
index a4b35889d6..327e9f9d56 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeRestControllerIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.is;
@@ -14,7 +14,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
import java.io.IOException;
import java.util.List;
-import org.baeldung.demo.DemoApplication;
+import com.baeldung.demo.DemoApplication;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
similarity index 94%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
index df28111a57..88f2830a2b 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/EmployeeServiceImplIntegrationTest.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import static org.assertj.core.api.Assertions.assertThat;
@@ -6,6 +6,10 @@ import java.util.Arrays;
import java.util.List;
import java.util.Optional;
+import com.baeldung.demo.boottest.Employee;
+import com.baeldung.demo.boottest.EmployeeRepository;
+import com.baeldung.demo.boottest.EmployeeService;
+import com.baeldung.demo.boottest.EmployeeServiceImpl;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/JsonUtil.java
similarity index 91%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/JsonUtil.java
index 7e04f47696..3fcd709f7c 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/demo/boottest/JsonUtil.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/demo/boottest/JsonUtil.java
@@ -1,4 +1,4 @@
-package org.baeldung.demo.boottest;
+package com.baeldung.demo.boottest;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
diff --git a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java
similarity index 92%
rename from spring-boot-modules/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java
rename to spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java
index ea7f118967..a1318949f3 100644
--- a/spring-boot-modules/spring-boot/src/test/java/org/baeldung/repository/UserRepositoryIntegrationTest.java
+++ b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/repository/UserRepositoryIntegrationTest.java
@@ -1,7 +1,8 @@
-package org.baeldung.repository;
+package com.baeldung.repository;
-import org.baeldung.boot.config.H2JpaConfig;
-import org.baeldung.model.User;
+import com.baeldung.boot.config.H2JpaConfig;
+import com.baeldung.model.User;
+import com.baeldung.repository.UserRepository;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
From 2d0f2c171bba3b8d970de9e8e76c9e78ea07d124 Mon Sep 17 00:00:00 2001
From: mikr
Date: Sat, 4 Apr 2020 20:40:09 +0200
Subject: [PATCH 48/59] JAVA-117 Standardize
spring-boot-modules/spring-boot-client
---
.../main/java/{org => com}/baeldung/boot/Application.java | 2 +-
.../java/{org => com}/baeldung/boot/client/Details.java | 2 +-
.../baeldung/boot/client/DetailsServiceClient.java | 2 +-
.../{org => com}/baeldung/websocket/client/Message.java | 2 +-
.../baeldung/websocket/client/MyStompSessionHandler.java | 2 +-
.../{org => com}/baeldung/websocket/client/StompClient.java | 2 +-
.../test/java/{org => com}/baeldung/SpringContextTest.java | 4 ++--
.../boot/client/DetailsServiceClientIntegrationTest.java | 6 ++++--
.../client/MyStompSessionHandlerIntegrationTest.java | 1 -
9 files changed, 12 insertions(+), 11 deletions(-)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/boot/Application.java (93%)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/boot/client/Details.java (93%)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/boot/client/DetailsServiceClient.java (93%)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/websocket/client/Message.java (89%)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/websocket/client/MyStompSessionHandler.java (98%)
rename spring-boot-modules/spring-boot-client/src/main/java/{org => com}/baeldung/websocket/client/StompClient.java (96%)
rename spring-boot-modules/spring-boot-client/src/test/java/{org => com}/baeldung/SpringContextTest.java (86%)
rename spring-boot-modules/spring-boot-client/src/test/java/{org => com}/baeldung/boot/client/DetailsServiceClientIntegrationTest.java (90%)
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/Application.java
similarity index 93%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/Application.java
index c1b6558b26..cb0d0c1532 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/Application.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot;
+package com.baeldung.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/Details.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/Details.java
similarity index 93%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/Details.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/Details.java
index 1e3ddf7b21..c806476634 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/Details.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/Details.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.client;
+package com.baeldung.boot.client;
public class Details {
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/DetailsServiceClient.java
similarity index 93%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/DetailsServiceClient.java
index f2b9d6d030..a9f1b08c97 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/client/DetailsServiceClient.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/boot/client/DetailsServiceClient.java
@@ -1,4 +1,4 @@
-package org.baeldung.boot.client;
+package com.baeldung.boot.client;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.stereotype.Service;
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/Message.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/Message.java
similarity index 89%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/Message.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/Message.java
index 2744c49f62..19140f76a2 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/Message.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/Message.java
@@ -1,4 +1,4 @@
-package org.baeldung.websocket.client;
+package com.baeldung.websocket.client;
public class Message {
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/MyStompSessionHandler.java
similarity index 98%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/MyStompSessionHandler.java
index 92beab9430..8ccc42c58a 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/MyStompSessionHandler.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/MyStompSessionHandler.java
@@ -1,4 +1,4 @@
-package org.baeldung.websocket.client;
+package com.baeldung.websocket.client;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/StompClient.java b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/StompClient.java
similarity index 96%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/StompClient.java
rename to spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/StompClient.java
index 2bff07186d..04d87dd2ed 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/websocket/client/StompClient.java
+++ b/spring-boot-modules/spring-boot-client/src/main/java/com/baeldung/websocket/client/StompClient.java
@@ -1,4 +1,4 @@
-package org.baeldung.websocket.client;
+package com.baeldung.websocket.client;
import java.util.Scanner;
diff --git a/spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/SpringContextTest.java
similarity index 86%
rename from spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/SpringContextTest.java
rename to spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/SpringContextTest.java
index 9c3b83ea79..1341f17eac 100644
--- a/spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/SpringContextTest.java
@@ -1,6 +1,6 @@
-package org.baeldung;
+package com.baeldung;
-import org.baeldung.boot.Application;
+import com.baeldung.boot.Application;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
diff --git a/spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/boot/client/DetailsServiceClientIntegrationTest.java
similarity index 90%
rename from spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java
rename to spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/boot/client/DetailsServiceClientIntegrationTest.java
index d423300b85..4af5370950 100644
--- a/spring-boot-modules/spring-boot-client/src/test/java/org/baeldung/boot/client/DetailsServiceClientIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/boot/client/DetailsServiceClientIntegrationTest.java
@@ -1,10 +1,12 @@
-package org.baeldung.boot.client;
+package com.baeldung.boot.client;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
-import org.baeldung.boot.Application;
+import com.baeldung.boot.Application;
+import com.baeldung.boot.client.Details;
+import com.baeldung.boot.client.DetailsServiceClient;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/websocket/client/MyStompSessionHandlerIntegrationTest.java b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/websocket/client/MyStompSessionHandlerIntegrationTest.java
index bb1b5e254e..57eec935f6 100644
--- a/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/websocket/client/MyStompSessionHandlerIntegrationTest.java
+++ b/spring-boot-modules/spring-boot-client/src/test/java/com/baeldung/websocket/client/MyStompSessionHandlerIntegrationTest.java
@@ -1,6 +1,5 @@
package com.baeldung.websocket.client;
-import org.baeldung.websocket.client.MyStompSessionHandler;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.messaging.simp.stomp.StompHeaders;
From 641956f87db3f02e3291cc684e868b9d19b808ad Mon Sep 17 00:00:00 2001
From: mikr
Date: Sat, 4 Apr 2020 21:16:51 +0200
Subject: [PATCH 49/59] JAVA-117 Standardize
spring-boot-modules/spring-boot-gradle
---
spring-boot-modules/spring-boot-gradle/build.gradle | 8 ++++----
.../main/java/{org => com}/baeldung/DemoApplication.java | 2 +-
.../java/{org => com}/baeldung/DemoApplicationTests.java | 2 +-
3 files changed, 6 insertions(+), 6 deletions(-)
rename spring-boot-modules/spring-boot-gradle/src/main/java/{org => com}/baeldung/DemoApplication.java (92%)
rename spring-boot-modules/spring-boot-gradle/src/test/java/{org => com}/baeldung/DemoApplicationTests.java (93%)
diff --git a/spring-boot-modules/spring-boot-gradle/build.gradle b/spring-boot-modules/spring-boot-gradle/build.gradle
index 96055536c3..faae01a1a5 100644
--- a/spring-boot-modules/spring-boot-gradle/build.gradle
+++ b/spring-boot-modules/spring-boot-gradle/build.gradle
@@ -21,7 +21,7 @@ apply plugin: 'io.spring.dependency-management'
//add tasks thinJar and thinResolve for thin JAR deployments
apply plugin: 'org.springframework.boot.experimental.thin-launcher'
-group = 'org.baeldung'
+group = 'com.baeldung'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
@@ -35,16 +35,16 @@ dependencies {
}
springBoot {
- mainClassName = 'org.baeldung.DemoApplication'
+ mainClassName = 'com.baeldung.DemoApplication'
}
bootJar {
// This is overridden by the mainClassName in springBoot{} and added here for reference purposes.
- mainClassName = 'org.baeldung.DemoApplication'
+ mainClassName = 'com.baeldung.DemoApplication'
// This block serves the same purpose as the above thus commented out. Added here for reference purposes
// manifest {
-// attributes 'Start-Class': 'org.baeldung.DemoApplication'
+// attributes 'Start-Class': 'com.baeldung.DemoApplication'
// }
}
diff --git a/spring-boot-modules/spring-boot-gradle/src/main/java/org/baeldung/DemoApplication.java b/spring-boot-modules/spring-boot-gradle/src/main/java/com/baeldung/DemoApplication.java
similarity index 92%
rename from spring-boot-modules/spring-boot-gradle/src/main/java/org/baeldung/DemoApplication.java
rename to spring-boot-modules/spring-boot-gradle/src/main/java/com/baeldung/DemoApplication.java
index f8df823f25..64bac6936b 100644
--- a/spring-boot-modules/spring-boot-gradle/src/main/java/org/baeldung/DemoApplication.java
+++ b/spring-boot-modules/spring-boot-gradle/src/main/java/com/baeldung/DemoApplication.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
diff --git a/spring-boot-modules/spring-boot-gradle/src/test/java/org/baeldung/DemoApplicationTests.java b/spring-boot-modules/spring-boot-gradle/src/test/java/com/baeldung/DemoApplicationTests.java
similarity index 93%
rename from spring-boot-modules/spring-boot-gradle/src/test/java/org/baeldung/DemoApplicationTests.java
rename to spring-boot-modules/spring-boot-gradle/src/test/java/com/baeldung/DemoApplicationTests.java
index b24bfb2cb6..65395582cb 100644
--- a/spring-boot-modules/spring-boot-gradle/src/test/java/org/baeldung/DemoApplicationTests.java
+++ b/spring-boot-modules/spring-boot-gradle/src/test/java/com/baeldung/DemoApplicationTests.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
From ad889f6bcd2c597f86434b731141ccb4f0321ca1 Mon Sep 17 00:00:00 2001
From: mikr
Date: Sat, 4 Apr 2020 21:47:45 +0200
Subject: [PATCH 50/59] JAVA-117 Standardize spring-boot-modules
---
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
spring-boot-modules/spring-boot-artifacts/pom.xml | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
spring-boot-modules/spring-boot-deployment/pom.xml | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextLiveTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../properties/external/ExternalPropertiesWithJavaConfig.java | 2 +-
.../properties/external/ExternalPropertiesWithXmlConfig.java | 2 +-
.../properties/external/ExternalPropertiesWithXmlConfigOne.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/test/java/org/baeldung/SpringContextTest.java | 2 +-
.../src/main/java/com/baeldung/main/SpringBootApplication.java | 2 +-
21 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java
index 834f26dacf..78a1ab7a54 100644
--- a/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-admin/spring-boot-admin-client/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java
index c185456019..3322193134 100644
--- a/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-admin/spring-boot-admin-server/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java
index 961d756a68..0f4fa757d6 100644
--- a/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-angular/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-artifacts/pom.xml b/spring-boot-modules/spring-boot-artifacts/pom.xml
index f7c8636593..de9f6ab635 100644
--- a/spring-boot-modules/spring-boot-artifacts/pom.xml
+++ b/spring-boot-modules/spring-boot-artifacts/pom.xml
@@ -208,7 +208,7 @@
- org.baeldung.boot.Application
+ com.baeldung.boot.Application
3.1.1
3.3.7-1
2.2
diff --git a/spring-boot-modules/spring-boot-camel/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-camel/src/test/java/org/baeldung/SpringContextTest.java
index 8324fabfca..ce743e0f77 100644
--- a/spring-boot-modules/spring-boot-camel/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-camel/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java
index ff3e795778..ca8989724b 100644
--- a/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-ctx-fluent/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
diff --git a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/test/java/org/baeldung/SpringContextTest.java
index e6ce83fab5..b4668e7d2b 100644
--- a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-autoconfigure/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/org/baeldung/SpringContextTest.java
index b82b67df68..7103da97f3 100644
--- a/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-custom-starter/greeter-spring-boot-sample-app/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-deployment/pom.xml b/spring-boot-modules/spring-boot-deployment/pom.xml
index 64c0e698f6..b3fc3eabd1 100644
--- a/spring-boot-modules/spring-boot-deployment/pom.xml
+++ b/spring-boot-modules/spring-boot-deployment/pom.xml
@@ -190,7 +190,7 @@
- org.baeldung.boot.Application
+ com.baeldung.boot.Application
3.1.1
3.3.7-1
2.2
diff --git a/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java
index ab6e4557d5..97810cf590 100644
--- a/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-jasypt/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java
index 4effccc083..3f3ecd87d0 100644
--- a/spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-keycloak/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java
index 9817522e68..d2660ad84e 100644
--- a/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-logging-log4j2/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextLiveTest.java
index 069dd41b8d..209a93d94c 100644
--- a/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextLiveTest.java
+++ b/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextLiveTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextTest.java
index 16e0708fc9..e73f4e79f7 100644
--- a/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-mvc/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithJavaConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithJavaConfig.java
index d43f18f6a7..5b954f8941 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithJavaConfig.java
+++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithJavaConfig.java
@@ -7,7 +7,7 @@ import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
@Configuration
-@ComponentScan("org.baeldung.properties.core")
+@ComponentScan("com.baeldung.properties.core")
@PropertySource("classpath:foo.properties")
public class ExternalPropertiesWithJavaConfig {
diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java
index 6d105428d9..9080e3d0ba 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java
+++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfig.java
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource("classpath:configForProperties.xml")
-@ComponentScan("org.baeldung.core")
+@ComponentScan("com.baeldung.core")
public class ExternalPropertiesWithXmlConfig {
public ExternalPropertiesWithXmlConfig() {
diff --git a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java
index 6f1e4c8490..f45f5b6a03 100644
--- a/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java
+++ b/spring-boot-modules/spring-boot-properties/src/main/java/com/baeldung/properties/external/ExternalPropertiesWithXmlConfigOne.java
@@ -6,7 +6,7 @@ import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource("classpath:configForPropertiesOne.xml")
-@ComponentScan("org.baeldung.core")
+@ComponentScan("com.baeldung.core")
public class ExternalPropertiesWithXmlConfigOne {
public ExternalPropertiesWithXmlConfigOne() {
diff --git a/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/src/test/java/org/baeldung/SpringContextTest.java
index 874c4f582f..2e1a17199d 100644
--- a/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-property-exp/property-exp-custom-config/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-property-exp/property-exp-default-config/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-property-exp/property-exp-default-config/src/test/java/org/baeldung/SpringContextTest.java
index 874c4f582f..2e1a17199d 100644
--- a/spring-boot-modules/spring-boot-property-exp/property-exp-default-config/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-property-exp/property-exp-default-config/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java b/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java
index 16e0708fc9..e73f4e79f7 100644
--- a/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-boot-modules/spring-boot-vue/src/test/java/org/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
index c8cfb50f1c..383932524f 100644
--- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
+++ b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/main/SpringBootApplication.java
@@ -18,7 +18,7 @@ import java.util.concurrent.Executors;
@RestController
@EnableAutoConfiguration
-@ComponentScan({ "org.baeldung.common.error", "com.baeldung.common.error.controller", "com.baeldung.common.properties", "com.baeldung.common.resources", "com.baeldung.endpoints", "com.baeldung.service", "com.baeldung.monitor.jmx", "com.baeldung.boot.config" })
+@ComponentScan({ "com.baeldung.common.error", "com.baeldung.common.error.controller", "com.baeldung.common.properties", "com.baeldung.common.resources", "com.baeldung.endpoints", "com.baeldung.service", "com.baeldung.monitor.jmx", "com.baeldung.boot.config" })
public class SpringBootApplication {
private static ApplicationContext applicationContext;
From 8c5dfc6f173c01ff21b6392393152fad6154bdea Mon Sep 17 00:00:00 2001
From: kwoyke
Date: Sun, 5 Apr 2020 07:52:47 +0200
Subject: [PATCH 51/59] BAEL-3978: Add code samples for Objects.equals()
(#9033)
---
.../comparelong/CompareLongUnitTest.java | 31 +++++++++++++++++++
1 file changed, 31 insertions(+)
diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java
index ab4ea2b657..a26b0a74b0 100644
--- a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java
+++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java
@@ -1,8 +1,12 @@
package com.baeldung.comparelong;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatCode;
+
import org.junit.Test;
+import java.util.Objects;
+
public class CompareLongUnitTest {
@Test
@@ -32,6 +36,33 @@ public class CompareLongUnitTest {
assertThat(l1.equals(l2)).isTrue();
}
+ @Test
+ public void givenLongValuesLessThan128_whenUsingObjectsEquals_thenSuccess() {
+
+ Long l1 = 127L;
+ Long l2 = 127L;
+
+ assertThat(Objects.equals(l1, l2)).isTrue();
+ }
+
+ @Test
+ public void givenLongValuesGreaterOrEqualsThan128_whenUsingObjectsEquals_thenSuccess() {
+
+ Long l1 = 128L;
+ Long l2 = 128L;
+
+ assertThat(Objects.equals(l1, l2)).isTrue();
+ }
+
+ @Test
+ public void givenNullReference_whenUsingObjectsEquals_thenNoException() {
+
+ Long l1 = null;
+ Long l2 = 128L;
+
+ assertThatCode(() -> Objects.equals(l1, l2)).doesNotThrowAnyException();
+ }
+
@Test
public void givenLongValuesGreaterOrEqualsThan128_whenUsingComparisonOperator_andLongValue_thenSuccess() {
From b30ee628059d55773e18420d9ed8df9f079678eb Mon Sep 17 00:00:00 2001
From: Belma Jakupovic
Date: Mon, 6 Apr 2020 20:22:28 +0200
Subject: [PATCH 52/59] Belma Jakupovic - Mockito additional answers (#9041)
---
.../mockito/additionalanswers/Book.java | 58 ++++++++++++++++
.../additionalanswers/BookRepository.java | 17 +++++
.../additionalanswers/BookService.java | 22 ++++++
.../BookServiceUnitTest.java | 68 +++++++++++++++++++
4 files changed, 165 insertions(+)
create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java
create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java
create mode 100644 testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java
create mode 100644 testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java
new file mode 100644
index 0000000000..fa021f8cba
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java
@@ -0,0 +1,58 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class Book {
+
+ private Long bookId;
+
+ private String title;
+
+ private String author;
+
+ private int numberOfPages;
+
+ public Book(String title, String author, int numberOfPages) {
+ this.title = title;
+ this.author = author;
+ this.numberOfPages = numberOfPages;
+ }
+
+ public Book(Long bookId, String title, String author, int numberOfPages) {
+ this.bookId = bookId;
+ this.title = title;
+ this.author = author;
+ this.numberOfPages = numberOfPages;
+ }
+
+ public Long getBookId() {
+ return bookId;
+ }
+
+ public void setBookId(Long bookId) {
+ this.bookId = bookId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public int getNumberOfPages() {
+ return numberOfPages;
+ }
+
+ public void setNumberOfPages(int numberOfPages) {
+ this.numberOfPages = numberOfPages;
+ }
+}
+
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java
new file mode 100644
index 0000000000..78187e3f01
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java
@@ -0,0 +1,17 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class BookRepository {
+ public Book getByBookId(Long bookId) {
+ return new Book(bookId, "To Kill a Mocking Bird", "Harper Lee", 256);
+ }
+
+ public Book save(Book book) {
+ return new Book(book.getBookId(), book.getTitle(), book.getAuthor(), book.getNumberOfPages());
+ }
+
+ public Book checkIfEquals(Book bookOne, Book bookTwo, Book bookThree) {
+ if (bookOne.equals(bookTwo) && bookTwo.equals(bookThree) && bookThree.equals(bookOne)) {
+ return bookOne;
+ } else return bookTwo;
+ }
+}
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java
new file mode 100644
index 0000000000..92c01f8a70
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java
@@ -0,0 +1,22 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class BookService {
+ private final BookRepository bookRepository;
+
+ public BookService(BookRepository bookRepository) {
+ this.bookRepository = bookRepository;
+ }
+
+ public Book getByBookId(Long id) {
+ return bookRepository.getByBookId(id);
+ }
+
+ public Book save(Book book) {
+ return bookRepository.save(book);
+ }
+
+ public Book checkifEquals(Book book1, Book book2, Book book3) {
+ return bookRepository.checkIfEquals(book1, book2, book3);
+ }
+}
+
diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java
new file mode 100644
index 0000000000..c9527ec0ec
--- /dev/null
+++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java
@@ -0,0 +1,68 @@
+package com.baeldung.mockito.additionalanswers;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.AdditionalAnswers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+
+@RunWith(MockitoJUnitRunner.class)
+public class BookServiceUnitTest {
+ @InjectMocks
+ private BookService bookService;
+
+ @Mock
+ private BookRepository bookRepository;
+
+ @Test
+ public void givenSaveMethodMocked_whenSaveInvoked_ThenReturnFirstArgument_UnitTest() {
+ Book book = new Book("To Kill a Mocking Bird", "Harper Lee", 256);
+ Mockito.when(bookRepository.save(any(Book.class))).then(AdditionalAnswers.returnsFirstArg());
+
+ Book savedBook = bookService.save(book);
+
+ assertEquals(savedBook, book);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnSecondArgument_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsSecondArg());
+
+ Book secondBook = bookService.checkifEquals(book1, book2, book3);
+
+ assertEquals(secondBook, book2);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnLastArgument_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsLastArg());
+
+ Book lastBook = bookService.checkifEquals(book1, book2, book3);
+ assertEquals(lastBook, book3);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnArgumentAtIndex_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsArgAt(1));
+
+ Book bookOnIndex = bookService.checkifEquals(book1, book2, book3);
+
+ assertEquals(bookOnIndex, book2);
+ }
+}
From ab6fee6012ba5ab83ab4263ea3a53a771b4f7ecf Mon Sep 17 00:00:00 2001
From: Jonathan Cook
Date: Mon, 6 Apr 2020 22:21:24 +0200
Subject: [PATCH 53/59] BAEL-3868 - Fix the integrations tests in mocks (#9039)
* BAEL-3491 - Check for null before calling parse in the
Double.parseDouble
* BAEL-3491 - Check for null before calling parse in the
Double.parseDouble
- Return to indentation with spaces.
* BAEL-3854 - Pattern Matching for instanceof in Java 14
* BAEL-3854 - Pattern Matching for instanceof in Java 14 - add unit test
* BAEL-3868 - Fix the integrations tests in mocks
Co-authored-by: Jonathan Cook
---
.../jmockit/ExpectationsCollaborator.java | 2 +-
.../jmockit/ExpectationsIntegrationTest.java | 35 ++++++++++---------
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java b/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
index 799e7721e0..1aafa28a6a 100644
--- a/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
+++ b/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
@@ -15,5 +15,5 @@ public interface ExpectationsCollaborator {
void methodForArgThat(Object o);
String methodReturnsString();
int methodReturnsInt();
- Object methodForDelegate(int i);
+ int methodForDelegate(int i);
}
diff --git a/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java b/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
index 8b0c3ab4ec..1ff90111d1 100644
--- a/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
+++ b/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
@@ -1,21 +1,21 @@
package com.baeldung.jmockit;
-import com.baeldung.jmockit.ExpectationsCollaborator;
-import com.baeldung.jmockit.Model;
-import mockit.Delegate;
-import mockit.Expectations;
-import mockit.Mocked;
-import mockit.Verifications;
-import mockit.integration.junit4.JMockit;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
+import mockit.Delegate;
+import mockit.Expectations;
+import mockit.Mocked;
+import mockit.Verifications;
+import mockit.integration.junit4.JMockit;
@RunWith(JMockit.class)
@SuppressWarnings("unchecked")
@@ -112,17 +112,16 @@ public class ExpectationsIntegrationTest {
result = "foo";
result = new Exception();
result = "bar";
- mock.methodReturnsInt();
- result = new int[]{1, 2, 3};
- mock.methodReturnsString();
returns("foo", "bar");
mock.methodReturnsInt();
+ result = new int[]{1, 2, 3};
result = 1;
}};
assertEquals("Should return foo", "foo", mock.methodReturnsString());
try {
mock.methodReturnsString();
+ fail("Shouldn't reach here");
} catch (Exception e) {
// NOOP
}
@@ -134,13 +133,14 @@ public class ExpectationsIntegrationTest {
assertEquals("Should return bar", "bar", mock.methodReturnsString());
assertEquals("Should return 1", 1, mock.methodReturnsInt());
}
-
+
@Test
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
new Expectations() {{
mock.methodForDelegate(anyInt);
- result = new Delegate() {
- public int delegate(int i) throws Exception {
+
+ result = new Delegate() {
+ int delegate(int i) throws Exception {
if (i < 3) {
return 5;
} else {
@@ -153,6 +153,7 @@ public class ExpectationsIntegrationTest {
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
try {
mock.methodForDelegate(3);
+ fail("Shouldn't reach here");
} catch (Exception e) {
}
}
From ad669c87a4c4de7df98f6dddf5db813cd76b254d Mon Sep 17 00:00:00 2001
From: Krzysiek
Date: Mon, 6 Apr 2020 22:28:19 +0200
Subject: [PATCH 54/59] JAVA-1201: Disable libraries-concurrency in the main
pom.xml
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index e21c13efc2..bc9b820766 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1263,7 +1263,7 @@
wildfly
xml
xstream
- libraries-concurrency
+
From 7f010f0f98ee07b1fc42237bc864a30ea622596a Mon Sep 17 00:00:00 2001
From: Krzysztof Woyke
Date: Tue, 7 Apr 2020 08:50:55 +0200
Subject: [PATCH 55/59] Revert "JAVA-1201: Disable libraries-concurrency in the
main pom.xml"
This reverts commit ad669c87a4c4de7df98f6dddf5db813cd76b254d.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index bc9b820766..e21c13efc2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1263,7 +1263,7 @@
wildfly
xml
xstream
-
+ libraries-concurrency
From 5bd296e8d0470a9eea32f8b7c42e56b992e222f7 Mon Sep 17 00:00:00 2001
From: Krzysztof Woyke
Date: Tue, 7 Apr 2020 08:52:00 +0200
Subject: [PATCH 56/59] JAVA-1201: Disable coroutines-with-quasar as it needs
Java 12
---
libraries-concurrency/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libraries-concurrency/pom.xml b/libraries-concurrency/pom.xml
index 7ae834025f..cb59b17674 100644
--- a/libraries-concurrency/pom.xml
+++ b/libraries-concurrency/pom.xml
@@ -14,7 +14,7 @@
- coroutines-with-quasar
+
\ No newline at end of file
From 8e107d118090a1704ae096aecf101c6dd3c37858 Mon Sep 17 00:00:00 2001
From: Sampada <46674082+sampada07@users.noreply.github.com>
Date: Wed, 8 Apr 2020 02:26:53 +0530
Subject: [PATCH 57/59] BAEL-3895: HTTP/2 in Netty (#9036)
* BAEL-3895 : HTTP/2 in Netty
* BAEL-3895: Added Live Test in place of java client
* BAEL-3895: Commented out netty module from main pom as it needs Java 13
---
netty/README.md | 6 +
netty/pom.xml | 34 +++++
.../com/baeldung/netty/http2/Http2Util.java | 135 ++++++++++++++++++
.../http2/client/Http2ClientInitializer.java | 46 ++++++
.../client/Http2ClientResponseHandler.java | 128 +++++++++++++++++
.../http2/client/Http2SettingsHandler.java | 30 ++++
.../netty/http2/server/Http2Server.java | 59 ++++++++
.../server/Http2ServerResponseHandler.java | 52 +++++++
netty/src/main/resources/logback.xml | 13 ++
.../baeldung/netty/Http2ClientLiveTest.java | 91 ++++++++++++
pom.xml | 2 +
11 files changed, 596 insertions(+)
create mode 100644 netty/README.md
create mode 100644 netty/pom.xml
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/Http2Util.java
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientInitializer.java
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientResponseHandler.java
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/client/Http2SettingsHandler.java
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/server/Http2Server.java
create mode 100644 netty/src/main/java/com/baeldung/netty/http2/server/Http2ServerResponseHandler.java
create mode 100644 netty/src/main/resources/logback.xml
create mode 100644 netty/src/test/java/com/baeldung/netty/Http2ClientLiveTest.java
diff --git a/netty/README.md b/netty/README.md
new file mode 100644
index 0000000000..b006c1c686
--- /dev/null
+++ b/netty/README.md
@@ -0,0 +1,6 @@
+## Netty
+
+This module contains articles about Netty.
+
+### Relevant Articles:
+
diff --git a/netty/pom.xml b/netty/pom.xml
new file mode 100644
index 0000000000..1a33eef92e
--- /dev/null
+++ b/netty/pom.xml
@@ -0,0 +1,34 @@
+
+
+ 4.0.0
+ netty
+ 0.0.1-SNAPSHOT
+ netty
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ io.netty
+ netty-all
+ ${netty.version}
+
+
+
+ org.conscrypt
+ conscrypt-openjdk-uber
+ 2.4.0
+
+
+
+
+
+ 4.1.48.Final
+
+
+
\ No newline at end of file
diff --git a/netty/src/main/java/com/baeldung/netty/http2/Http2Util.java b/netty/src/main/java/com/baeldung/netty/http2/Http2Util.java
new file mode 100644
index 0000000000..62b6d4c4ed
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/Http2Util.java
@@ -0,0 +1,135 @@
+package com.baeldung.netty.http2;
+
+import static io.netty.handler.logging.LogLevel.INFO;
+
+import java.security.cert.CertificateException;
+
+import javax.net.ssl.SSLException;
+
+import com.baeldung.netty.http2.client.Http2ClientResponseHandler;
+import com.baeldung.netty.http2.client.Http2SettingsHandler;
+import com.baeldung.netty.http2.server.Http2ServerResponseHandler;
+
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPipeline;
+import io.netty.handler.codec.http.DefaultFullHttpRequest;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.codec.http.HttpHeaderNames;
+import io.netty.handler.codec.http.HttpHeaderValues;
+import io.netty.handler.codec.http.HttpMethod;
+import io.netty.handler.codec.http.HttpScheme;
+import io.netty.handler.codec.http.HttpVersion;
+import io.netty.handler.codec.http2.DefaultHttp2Connection;
+import io.netty.handler.codec.http2.DelegatingDecompressorFrameListener;
+import io.netty.handler.codec.http2.Http2Connection;
+import io.netty.handler.codec.http2.Http2FrameCodecBuilder;
+import io.netty.handler.codec.http2.Http2FrameLogger;
+import io.netty.handler.codec.http2.Http2SecurityUtil;
+import io.netty.handler.codec.http2.HttpConversionUtil;
+import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandler;
+import io.netty.handler.codec.http2.HttpToHttp2ConnectionHandlerBuilder;
+import io.netty.handler.codec.http2.InboundHttp2ToHttpAdapterBuilder;
+import io.netty.handler.ssl.ApplicationProtocolConfig;
+import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol;
+import io.netty.handler.ssl.ApplicationProtocolConfig.SelectedListenerFailureBehavior;
+import io.netty.handler.ssl.ApplicationProtocolConfig.SelectorFailureBehavior;
+import io.netty.handler.ssl.ApplicationProtocolNames;
+import io.netty.handler.ssl.ApplicationProtocolNegotiationHandler;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.ssl.SslProvider;
+import io.netty.handler.ssl.SupportedCipherSuiteFilter;
+import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import io.netty.handler.ssl.util.SelfSignedCertificate;
+
+public class Http2Util {
+ public static SslContext createSSLContext(boolean isServer) throws SSLException, CertificateException {
+
+ SslContext sslCtx;
+
+ SelfSignedCertificate ssc = new SelfSignedCertificate();
+
+ if (isServer) {
+ sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey())
+ .sslProvider(SslProvider.JDK)
+ .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
+ .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN,
+ SelectorFailureBehavior.NO_ADVERTISE,
+ SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1))
+ .build();
+ } else {
+ sslCtx = SslContextBuilder.forClient()
+ .sslProvider(SslProvider.JDK)
+ .ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE)
+ .trustManager(InsecureTrustManagerFactory.INSTANCE)
+ .applicationProtocolConfig(new ApplicationProtocolConfig(Protocol.ALPN,
+ SelectorFailureBehavior.NO_ADVERTISE,
+ SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2))
+ .build();
+ }
+ return sslCtx;
+
+ }
+
+ public static ApplicationProtocolNegotiationHandler getServerAPNHandler() {
+ ApplicationProtocolNegotiationHandler serverAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) {
+
+ @Override
+ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
+ if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
+ ctx.pipeline()
+ .addLast(Http2FrameCodecBuilder.forServer()
+ .build(), new Http2ServerResponseHandler());
+ return;
+ }
+ throw new IllegalStateException("Protocol: " + protocol + " not supported");
+ }
+ };
+ return serverAPNHandler;
+
+ }
+
+ public static ApplicationProtocolNegotiationHandler getClientAPNHandler(int maxContentLength, Http2SettingsHandler settingsHandler, Http2ClientResponseHandler responseHandler) {
+ final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2Util.class);
+ final Http2Connection connection = new DefaultHttp2Connection(false);
+
+ HttpToHttp2ConnectionHandler connectionHandler = new HttpToHttp2ConnectionHandlerBuilder()
+ .frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength)
+ .propagateSettings(true)
+ .build()))
+ .frameLogger(logger)
+ .connection(connection)
+ .build();
+
+ ApplicationProtocolNegotiationHandler clientAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) {
+ @Override
+ protected void configurePipeline(ChannelHandlerContext ctx, String protocol) {
+ if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
+ ChannelPipeline p = ctx.pipeline();
+ p.addLast(connectionHandler);
+ p.addLast(settingsHandler, responseHandler);
+ return;
+ }
+ ctx.close();
+ throw new IllegalStateException("Protocol: " + protocol + " not supported");
+ }
+ };
+
+ return clientAPNHandler;
+
+ }
+
+ public static FullHttpRequest createGetRequest(String host, int port) {
+ FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.valueOf("HTTP/2.0"), HttpMethod.GET, "/", Unpooled.EMPTY_BUFFER);
+ request.headers()
+ .add(HttpHeaderNames.HOST, new String(host + ":" + port));
+ request.headers()
+ .add(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), HttpScheme.HTTPS);
+ request.headers()
+ .add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP);
+ request.headers()
+ .add(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.DEFLATE);
+ return request;
+ }
+}
diff --git a/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientInitializer.java b/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientInitializer.java
new file mode 100644
index 0000000000..d50240fcb2
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientInitializer.java
@@ -0,0 +1,46 @@
+package com.baeldung.netty.http2.client;
+
+import com.baeldung.netty.http2.Http2Util;
+
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelPipeline;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.ssl.SslContext;
+
+public class Http2ClientInitializer extends ChannelInitializer {
+
+ private final SslContext sslCtx;
+ private final int maxContentLength;
+ private Http2SettingsHandler settingsHandler;
+ private Http2ClientResponseHandler responseHandler;
+ private String host;
+ private int port;
+
+ public Http2ClientInitializer(SslContext sslCtx, int maxContentLength, String host, int port) {
+ this.sslCtx = sslCtx;
+ this.maxContentLength = maxContentLength;
+ this.host = host;
+ this.port = port;
+ }
+
+ @Override
+ public void initChannel(SocketChannel ch) throws Exception {
+
+ settingsHandler = new Http2SettingsHandler(ch.newPromise());
+ responseHandler = new Http2ClientResponseHandler();
+
+ if (sslCtx != null) {
+ ChannelPipeline pipeline = ch.pipeline();
+ pipeline.addLast(sslCtx.newHandler(ch.alloc(), host, port));
+ pipeline.addLast(Http2Util.getClientAPNHandler(maxContentLength, settingsHandler, responseHandler));
+ }
+ }
+
+ public Http2SettingsHandler getSettingsHandler() {
+ return settingsHandler;
+ }
+
+ public Http2ClientResponseHandler getResponseHandler() {
+ return responseHandler;
+ }
+}
diff --git a/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientResponseHandler.java b/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientResponseHandler.java
new file mode 100644
index 0000000000..4e17155bbc
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/client/Http2ClientResponseHandler.java
@@ -0,0 +1,128 @@
+package com.baeldung.netty.http2.client;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.channel.ChannelFuture;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http2.HttpConversionUtil;
+import io.netty.util.CharsetUtil;
+
+public class Http2ClientResponseHandler extends SimpleChannelInboundHandler {
+
+ private final Logger logger = LoggerFactory.getLogger(Http2ClientResponseHandler.class);
+ private final Map streamidMap;
+
+ public Http2ClientResponseHandler() {
+ streamidMap = new HashMap();
+ }
+
+ public MapValues put(int streamId, ChannelFuture writeFuture, ChannelPromise promise) {
+ return streamidMap.put(streamId, new MapValues(writeFuture, promise));
+ }
+
+ public String awaitResponses(long timeout, TimeUnit unit) {
+
+ Iterator> itr = streamidMap.entrySet()
+ .iterator();
+
+ String response = null;
+
+ while (itr.hasNext()) {
+ Entry entry = itr.next();
+ ChannelFuture writeFuture = entry.getValue()
+ .getWriteFuture();
+
+ if (!writeFuture.awaitUninterruptibly(timeout, unit)) {
+ throw new IllegalStateException("Timed out waiting to write for stream id " + entry.getKey());
+ }
+ if (!writeFuture.isSuccess()) {
+ throw new RuntimeException(writeFuture.cause());
+ }
+ ChannelPromise promise = entry.getValue()
+ .getPromise();
+
+ if (!promise.awaitUninterruptibly(timeout, unit)) {
+ throw new IllegalStateException("Timed out waiting for response on stream id " + entry.getKey());
+ }
+ if (!promise.isSuccess()) {
+ throw new RuntimeException(promise.cause());
+ }
+ logger.info("---Stream id: " + entry.getKey() + " received---");
+ response = entry.getValue().getResponse();
+
+ itr.remove();
+ }
+
+ return response;
+
+ }
+
+ @Override
+ protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
+ Integer streamId = msg.headers()
+ .getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
+ if (streamId == null) {
+ logger.error("HttpResponseHandler unexpected message received: " + msg);
+ return;
+ }
+
+ MapValues value = streamidMap.get(streamId);
+
+ if (value == null) {
+ logger.error("Message received for unknown stream id " + streamId);
+ ctx.close();
+ } else {
+ ByteBuf content = msg.content();
+ if (content.isReadable()) {
+ int contentLength = content.readableBytes();
+ byte[] arr = new byte[contentLength];
+ content.readBytes(arr);
+ String response = new String(arr, 0, contentLength, CharsetUtil.UTF_8);
+ logger.info("Response from Server: "+ (response));
+ value.setResponse(response);
+ }
+
+ value.getPromise()
+ .setSuccess();
+ }
+ }
+
+ public static class MapValues {
+ ChannelFuture writeFuture;
+ ChannelPromise promise;
+ String response;
+
+ public String getResponse() {
+ return response;
+ }
+
+ public void setResponse(String response) {
+ this.response = response;
+ }
+
+ public MapValues(ChannelFuture writeFuture2, ChannelPromise promise2) {
+ this.writeFuture = writeFuture2;
+ this.promise = promise2;
+ }
+
+ public ChannelFuture getWriteFuture() {
+ return writeFuture;
+ }
+
+ public ChannelPromise getPromise() {
+ return promise;
+ }
+
+ }
+}
diff --git a/netty/src/main/java/com/baeldung/netty/http2/client/Http2SettingsHandler.java b/netty/src/main/java/com/baeldung/netty/http2/client/Http2SettingsHandler.java
new file mode 100644
index 0000000000..93841187c7
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/client/Http2SettingsHandler.java
@@ -0,0 +1,30 @@
+package com.baeldung.netty.http2.client;
+
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.SimpleChannelInboundHandler;
+import io.netty.handler.codec.http2.Http2Settings;
+
+import java.util.concurrent.TimeUnit;
+
+public class Http2SettingsHandler extends SimpleChannelInboundHandler {
+ private final ChannelPromise promise;
+
+ public Http2SettingsHandler(ChannelPromise promise) {
+ this.promise = promise;
+ }
+
+ public void awaitSettings(long timeout, TimeUnit unit) throws Exception {
+ if (!promise.awaitUninterruptibly(timeout, unit)) {
+ throw new IllegalStateException("Timed out waiting for settings");
+ }
+ }
+
+ @Override
+ protected void channelRead0(ChannelHandlerContext ctx, Http2Settings msg) throws Exception {
+ promise.setSuccess();
+
+ ctx.pipeline()
+ .remove(this);
+ }
+}
diff --git a/netty/src/main/java/com/baeldung/netty/http2/server/Http2Server.java b/netty/src/main/java/com/baeldung/netty/http2/server/Http2Server.java
new file mode 100644
index 0000000000..a8e9e59953
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/server/Http2Server.java
@@ -0,0 +1,59 @@
+package com.baeldung.netty.http2.server;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.baeldung.netty.http2.Http2Util;
+
+import io.netty.bootstrap.ServerBootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelInitializer;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.channel.socket.nio.NioServerSocketChannel;
+import io.netty.handler.logging.LogLevel;
+import io.netty.handler.logging.LoggingHandler;
+import io.netty.handler.ssl.SslContext;
+
+public final class Http2Server {
+
+ private static final int PORT = 8443;
+ private static final Logger logger = LoggerFactory.getLogger(Http2Server.class);
+
+ public static void main(String[] args) throws Exception {
+ SslContext sslCtx = Http2Util.createSSLContext(true);
+
+ EventLoopGroup group = new NioEventLoopGroup();
+ try {
+ ServerBootstrap b = new ServerBootstrap();
+ b.option(ChannelOption.SO_BACKLOG, 1024);
+ b.group(group)
+ .channel(NioServerSocketChannel.class)
+ .handler(new LoggingHandler(LogLevel.INFO))
+ .childHandler(new ChannelInitializer() {
+ @Override
+ protected void initChannel(SocketChannel ch) throws Exception {
+ if (sslCtx != null) {
+ ch.pipeline()
+ .addLast(sslCtx.newHandler(ch.alloc()), Http2Util.getServerAPNHandler());
+ }
+ }
+
+ });
+
+ Channel ch = b.bind(PORT)
+ .sync()
+ .channel();
+
+ logger.info("HTTP/2 Server is listening on https://127.0.0.1:" + PORT + '/');
+
+ ch.closeFuture()
+ .sync();
+ } finally {
+ group.shutdownGracefully();
+ }
+ }
+
+}
diff --git a/netty/src/main/java/com/baeldung/netty/http2/server/Http2ServerResponseHandler.java b/netty/src/main/java/com/baeldung/netty/http2/server/Http2ServerResponseHandler.java
new file mode 100644
index 0000000000..24c66f15bb
--- /dev/null
+++ b/netty/src/main/java/com/baeldung/netty/http2/server/Http2ServerResponseHandler.java
@@ -0,0 +1,52 @@
+package com.baeldung.netty.http2.server;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandler.Sharable;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.handler.codec.http.HttpResponseStatus;
+import io.netty.handler.codec.http2.DefaultHttp2DataFrame;
+import io.netty.handler.codec.http2.DefaultHttp2Headers;
+import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame;
+import io.netty.handler.codec.http2.Http2Headers;
+import io.netty.handler.codec.http2.Http2HeadersFrame;
+import io.netty.util.CharsetUtil;
+
+@Sharable
+public class Http2ServerResponseHandler extends ChannelDuplexHandler {
+
+ static final ByteBuf RESPONSE_BYTES = Unpooled.unreleasableBuffer(Unpooled.copiedBuffer("Hello World", CharsetUtil.UTF_8));
+
+ @Override
+ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
+ super.exceptionCaught(ctx, cause);
+ cause.printStackTrace();
+ ctx.close();
+ }
+
+ @Override
+ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+ if (msg instanceof Http2HeadersFrame) {
+ Http2HeadersFrame msgHeader = (Http2HeadersFrame) msg;
+ if (msgHeader.isEndStream()) {
+ ByteBuf content = ctx.alloc()
+ .buffer();
+ content.writeBytes(RESPONSE_BYTES.duplicate());
+
+ Http2Headers headers = new DefaultHttp2Headers().status(HttpResponseStatus.OK.codeAsText());
+ ctx.write(new DefaultHttp2HeadersFrame(headers).stream(msgHeader.stream()));
+ ctx.write(new DefaultHttp2DataFrame(content, true).stream(msgHeader.stream()));
+ }
+
+ } else {
+ super.channelRead(ctx, msg);
+ }
+ }
+
+ @Override
+ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
+ ctx.flush();
+ }
+
+}
diff --git a/netty/src/main/resources/logback.xml b/netty/src/main/resources/logback.xml
new file mode 100644
index 0000000000..7d900d8ea8
--- /dev/null
+++ b/netty/src/main/resources/logback.xml
@@ -0,0 +1,13 @@
+
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/netty/src/test/java/com/baeldung/netty/Http2ClientLiveTest.java b/netty/src/test/java/com/baeldung/netty/Http2ClientLiveTest.java
new file mode 100644
index 0000000000..6b9a53a1b3
--- /dev/null
+++ b/netty/src/test/java/com/baeldung/netty/Http2ClientLiveTest.java
@@ -0,0 +1,91 @@
+package com.baeldung.netty;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.concurrent.TimeUnit;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.baeldung.netty.http2.Http2Util;
+import com.baeldung.netty.http2.client.Http2ClientInitializer;
+import com.baeldung.netty.http2.client.Http2ClientResponseHandler;
+import com.baeldung.netty.http2.client.Http2SettingsHandler;
+
+import io.netty.bootstrap.Bootstrap;
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelOption;
+import io.netty.channel.EventLoopGroup;
+import io.netty.channel.nio.NioEventLoopGroup;
+import io.netty.channel.socket.nio.NioSocketChannel;
+import io.netty.handler.codec.http.FullHttpRequest;
+import io.netty.handler.ssl.SslContext;
+
+//Ensure the server class - Http2Server.java is already started before running this test
+public class Http2ClientLiveTest {
+
+ private static final Logger logger = LoggerFactory.getLogger(Http2ClientLiveTest.class);
+
+ private static final String HOST = "127.0.0.1";
+ private static final int PORT = 8443;
+ private SslContext sslCtx;
+ private Channel channel;
+
+ @Before
+ public void setup() throws Exception {
+ sslCtx = Http2Util.createSSLContext(false);
+ }
+
+ @Test
+ public void whenRequestSent_thenHelloWorldReceived() throws Exception {
+
+ EventLoopGroup workerGroup = new NioEventLoopGroup();
+ Http2ClientInitializer initializer = new Http2ClientInitializer(sslCtx, Integer.MAX_VALUE, HOST, PORT);
+
+ try {
+ Bootstrap b = new Bootstrap();
+ b.group(workerGroup);
+ b.channel(NioSocketChannel.class);
+ b.option(ChannelOption.SO_KEEPALIVE, true);
+ b.remoteAddress(HOST, PORT);
+ b.handler(initializer);
+
+ channel = b.connect()
+ .syncUninterruptibly()
+ .channel();
+
+ logger.info("Connected to [" + HOST + ':' + PORT + ']');
+
+ Http2SettingsHandler http2SettingsHandler = initializer.getSettingsHandler();
+ http2SettingsHandler.awaitSettings(60, TimeUnit.SECONDS);
+
+ logger.info("Sending request(s)...");
+
+ FullHttpRequest request = Http2Util.createGetRequest(HOST, PORT);
+
+ Http2ClientResponseHandler responseHandler = initializer.getResponseHandler();
+ int streamId = 3;
+
+ responseHandler.put(streamId, channel.write(request), channel.newPromise());
+ channel.flush();
+ String response = responseHandler.awaitResponses(60, TimeUnit.SECONDS);
+
+ assertEquals("Hello World", response);
+
+ logger.info("Finished HTTP/2 request(s)");
+
+ } finally {
+ workerGroup.shutdownGracefully();
+ }
+
+ }
+
+ @After
+ public void cleanup() {
+ channel.close()
+ .syncUninterruptibly();
+ }
+}
diff --git a/pom.xml b/pom.xml
index e21c13efc2..5602e807b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -536,6 +536,7 @@
mybatis
netflix-modules
+
ninja
open-liberty
@@ -1047,6 +1048,7 @@
mybatis
netflix-modules
+
ninja
open-liberty
From f9ac384b8567a06c65e7b1e47c3ec2c3026a8dda Mon Sep 17 00:00:00 2001
From: Sam Millington
Date: Wed, 8 Apr 2020 18:40:34 +0100
Subject: [PATCH 58/59] Added BAEL-3604 code (#9020)
* Added BAEL-3604 code
---
.../core-java-security-2/pom.xml | 11 ++++
.../com/baeldung/checksums/ChecksumUtils.java | 23 +++++++++
.../checksums/ChecksumUtilsUnitTest.java | 51 +++++++++++++++++++
3 files changed, 85 insertions(+)
create mode 100644 core-java-modules/core-java-security-2/src/main/java/com/baeldung/checksums/ChecksumUtils.java
create mode 100644 core-java-modules/core-java-security-2/src/test/java/com/baeldung/checksums/ChecksumUtilsUnitTest.java
diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml
index 9315ab4af2..5db3b67c04 100644
--- a/core-java-modules/core-java-security-2/pom.xml
+++ b/core-java-modules/core-java-security-2/pom.xml
@@ -17,6 +17,7 @@
+
commons-codec
commons-codec
@@ -36,6 +37,15 @@
${assertj-core.version}
test
+
+
+
+ javax.xml.bind
+ jaxb-api
+ 2.3.1
+
+
+
@@ -46,4 +56,5 @@
3.10.0
+
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/checksums/ChecksumUtils.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/checksums/ChecksumUtils.java
new file mode 100644
index 0000000000..d214a0f757
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/checksums/ChecksumUtils.java
@@ -0,0 +1,23 @@
+package com.baeldung.checksums;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.zip.CRC32;
+import java.util.zip.CheckedInputStream;
+import java.util.zip.Checksum;
+
+public class ChecksumUtils {
+
+ public static long getChecksumCRC32(byte[] bytes) {
+ Checksum crc32 = new CRC32();
+ crc32.update(bytes, 0, bytes.length);
+ return crc32.getValue();
+ }
+
+ public static long getChecksumCRC32(InputStream stream, int bufferSize) throws IOException {
+ CheckedInputStream checkedInputStream = new CheckedInputStream(stream, new CRC32());
+ byte[] buffer = new byte[bufferSize];
+ while (checkedInputStream.read(buffer, 0, buffer.length) >= 0) {}
+ return checkedInputStream.getChecksum().getValue();
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/checksums/ChecksumUtilsUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/checksums/ChecksumUtilsUnitTest.java
new file mode 100644
index 0000000000..f5366917f6
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/checksums/ChecksumUtilsUnitTest.java
@@ -0,0 +1,51 @@
+package com.baeldung.checksums;
+
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ChecksumUtilsUnitTest {
+
+ byte[] arr;
+
+ @Before
+ void setUp() {
+ arr = new byte[]{0,10,21,20,35,40,120,56,72,22};
+ }
+
+ @Test
+ void givenByteArray_whenChecksumCreated_checkCorrect() {
+
+ long checksum = ChecksumUtils.getChecksumCRC32(arr);
+
+ assertEquals(3915397664L, checksum);
+ }
+
+ @Test
+ void givenTwoDifferentStrings_whenChecksumCreated_checkCollision() {
+
+ String plumless = "plumless";
+ String buckeroo = "buckeroo";
+
+ long plumlessChecksum = ChecksumUtils.getChecksumCRC32(plumless.getBytes());
+ long buckerooChecksum = ChecksumUtils.getChecksumCRC32(buckeroo.getBytes());
+
+ assertEquals(plumlessChecksum, buckerooChecksum);
+ }
+
+ @Test
+ void givenInputString_whenChecksumCreated_checkCorrect() throws IOException {
+
+ InputStream inputStream = new ByteArrayInputStream(arr);
+ long checksum = ChecksumUtils.getChecksumCRC32(inputStream, 10);
+
+ assertEquals(3915397664L, checksum);
+
+ }
+}
\ No newline at end of file
From 88cc732dc7bfffba9f086bd0d77f0487b56bd0bb Mon Sep 17 00:00:00 2001
From: Catalin Burcea
Date: Thu, 9 Apr 2020 10:30:04 +0300
Subject: [PATCH 59/59] BAEL-3649 Quick Guide to Spring Cloud Circuit Breaker
(#8819)
---
.../spring-cloud-circuit-breaker/README.md | 5 ++
.../spring-cloud-circuit-breaker/pom.xml | 55 ++++++++++++++
.../baeldung/circuitbreaker/AlbumService.java | 40 +++++++++++
.../baeldung/circuitbreaker/Controller.java | 18 +++++
.../baeldung/circuitbreaker/SpringApp.java | 71 +++++++++++++++++++
.../main/resources/fallback-album-list.json | 12 ++++
6 files changed, 201 insertions(+)
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/README.md
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/pom.xml
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/AlbumService.java
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/Controller.java
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/SpringApp.java
create mode 100644 spring-cloud/spring-cloud-circuit-breaker/src/main/resources/fallback-album-list.json
diff --git a/spring-cloud/spring-cloud-circuit-breaker/README.md b/spring-cloud/spring-cloud-circuit-breaker/README.md
new file mode 100644
index 0000000000..040eb0ccee
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/README.md
@@ -0,0 +1,5 @@
+## Spring Cloud Circuit Breaker
+
+This module contains articles about Spring Cloud Circuit Breaker
+
+### Relevant Articles:
diff --git a/spring-cloud/spring-cloud-circuit-breaker/pom.xml b/spring-cloud/spring-cloud-circuit-breaker/pom.xml
new file mode 100644
index 0000000000..188fc4bf8e
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/pom.xml
@@ -0,0 +1,55 @@
+
+
+ 4.0.0
+ spring-cloud-circuit-breaker
+ spring-cloud-gateway
+ jar
+
+
+ com.baeldung.spring.cloud
+ spring-cloud
+ 1.0.0-SNAPSHOT
+ ..
+
+
+
+
+ spring-snapshots
+ Spring Snapshots
+ https://repo.spring.io/libs-snapshot
+
+ true
+
+
+ false
+
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-dependencies
+ 2.2.4.RELEASE
+ pom
+ import
+
+
+
+
+
+
+ org.springframework.cloud
+ spring-cloud-starter-circuitbreaker-resilience4j
+ 1.0.2.RELEASE
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+
+
diff --git a/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/AlbumService.java b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/AlbumService.java
new file mode 100644
index 0000000000..67163c8c9a
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/AlbumService.java
@@ -0,0 +1,40 @@
+package com.baeldung.circuitbreaker;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.client.circuitbreaker.CircuitBreaker;
+import org.springframework.cloud.client.circuitbreaker.CircuitBreakerFactory;
+import org.springframework.stereotype.Service;
+import org.springframework.web.client.RestTemplate;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+@Service
+public class AlbumService {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(AlbumService.class);
+
+ @Autowired
+ private CircuitBreakerFactory circuitBreakerFactory;
+
+ private RestTemplate restTemplate = new RestTemplate();
+
+ public String getAlbumList() {
+ CircuitBreaker circuitBreaker = circuitBreakerFactory.create("circuitbreaker");
+ String url = "https://jsonplaceholder.typicode.com/albums";
+
+ return circuitBreaker.run(() -> restTemplate.getForObject(url, String.class), throwable -> getDefaultAlbumList());
+ }
+
+ private String getDefaultAlbumList() {
+ try {
+ return new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource("fallback-album-list.json").toURI())));
+ } catch (Exception e) {
+ LOGGER.error("error occurred while reading the file", e);
+ }
+ return null;
+ }
+
+}
diff --git a/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/Controller.java b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/Controller.java
new file mode 100644
index 0000000000..10f7c57a7a
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/Controller.java
@@ -0,0 +1,18 @@
+package com.baeldung.circuitbreaker;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class Controller {
+
+ @Autowired
+ private AlbumService service;
+
+ @GetMapping("/albums")
+ public String albums() {
+ return service.getAlbumList();
+ }
+
+}
\ No newline at end of file
diff --git a/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/SpringApp.java b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/SpringApp.java
new file mode 100644
index 0000000000..f891e7693f
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/src/main/java/com/baeldung/circuitbreaker/SpringApp.java
@@ -0,0 +1,71 @@
+package com.baeldung.circuitbreaker;
+
+import io.github.resilience4j.circuitbreaker.CircuitBreakerConfig;
+import io.github.resilience4j.timelimiter.TimeLimiterConfig;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JCircuitBreakerFactory;
+import org.springframework.cloud.circuitbreaker.resilience4j.Resilience4JConfigBuilder;
+import org.springframework.cloud.client.circuitbreaker.Customizer;
+import org.springframework.context.annotation.Bean;
+
+import java.time.Duration;
+
+@SpringBootApplication
+public class SpringApp {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringApp.class, args);
+ }
+
+ @Bean
+ public Customizer globalCustomConfiguration() {
+ TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
+ .timeoutDuration(Duration.ofSeconds(4))
+ .build();
+ CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
+ .failureRateThreshold(50)
+ .waitDurationInOpenState(Duration.ofMillis(1000))
+ .slidingWindowSize(2)
+ .build();
+
+ return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id)
+ .timeLimiterConfig(timeLimiterConfig)
+ .circuitBreakerConfig(circuitBreakerConfig)
+ .build());
+ }
+
+ @Bean
+ public Customizer specificCustomConfiguration1() {
+
+ TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
+ .timeoutDuration(Duration.ofSeconds(4))
+ .build();
+ CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
+ .failureRateThreshold(50)
+ .waitDurationInOpenState(Duration.ofMillis(1000))
+ .slidingWindowSize(2)
+ .build();
+
+ return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig)
+ .timeLimiterConfig(timeLimiterConfig).build(), "circuitBreaker");
+ }
+
+ @Bean
+ public Customizer specificCustomConfiguration2() {
+
+ TimeLimiterConfig timeLimiterConfig = TimeLimiterConfig.custom()
+ .timeoutDuration(Duration.ofSeconds(4))
+ .build();
+ CircuitBreakerConfig circuitBreakerConfig = CircuitBreakerConfig.custom()
+ .failureRateThreshold(50)
+ .waitDurationInOpenState(Duration.ofMillis(1000))
+ .slidingWindowSize(2)
+ .build();
+
+ return factory -> factory.configure(builder -> builder.circuitBreakerConfig(circuitBreakerConfig)
+ .timeLimiterConfig(timeLimiterConfig).build(),
+ "circuitBreaker1", "circuitBreaker2", "circuitBreaker3");
+ }
+
+}
diff --git a/spring-cloud/spring-cloud-circuit-breaker/src/main/resources/fallback-album-list.json b/spring-cloud/spring-cloud-circuit-breaker/src/main/resources/fallback-album-list.json
new file mode 100644
index 0000000000..001df7610a
--- /dev/null
+++ b/spring-cloud/spring-cloud-circuit-breaker/src/main/resources/fallback-album-list.json
@@ -0,0 +1,12 @@
+[
+ {
+ "userId": 1,
+ "id": 1,
+ "title": "quidem molestiae enim"
+ },
+ {
+ "userId": 1,
+ "id": 2,
+ "title": "sunt qui excepturi placeat culpa"
+ }
+]
\ No newline at end of file