From 674db8bd0ebd9dc23d6641c179f69013ac0c1fcd Mon Sep 17 00:00:00 2001 From: catalin-burcea Date: Wed, 31 Jul 2019 22:29:31 +0300 Subject: [PATCH 01/13] added StreamTokenizer examples --- .../streamtokenizer/StreamTokenizerDemo.java | 76 +++++++++++++++++++ .../resources/stream-tokenizer-example.txt | 3 + .../StreamTokenizerDemoUnitTest.java | 34 +++++++++ 3 files changed, 113 insertions(+) create mode 100644 java-strings-2/src/main/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemo.java create mode 100644 java-strings-2/src/main/resources/stream-tokenizer-example.txt create mode 100644 java-strings-2/src/test/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemoUnitTest.java diff --git a/java-strings-2/src/main/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemo.java b/java-strings-2/src/main/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemo.java new file mode 100644 index 0000000000..3bb0ff5b77 --- /dev/null +++ b/java-strings-2/src/main/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemo.java @@ -0,0 +1,76 @@ +package com.baeldung.string.streamtokenizer; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +public class StreamTokenizerDemo { + + private static final String INPUT_FILE = "/stream-tokenizer-example.txt"; + private static final int QUOTE_CHARACTER = '\''; + private static final int DOUBLE_QUOTE_CHARACTER = '"'; + + public static List streamTokenizerWithDefaultConfiguration(Reader reader) throws IOException { + StreamTokenizer streamTokenizer = new StreamTokenizer(reader); + List tokens = new ArrayList<>(); + + int currentToken = streamTokenizer.nextToken(); + while (currentToken != StreamTokenizer.TT_EOF) { + + if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) { + tokens.add(streamTokenizer.nval); + } else if (streamTokenizer.ttype == StreamTokenizer.TT_WORD + || streamTokenizer.ttype == QUOTE_CHARACTER + || streamTokenizer.ttype == DOUBLE_QUOTE_CHARACTER) { + tokens.add(streamTokenizer.sval); + } else { + tokens.add((char) currentToken); + } + + currentToken = streamTokenizer.nextToken(); + } + + return tokens; + } + + public static List streamTokenizerWithCustomConfiguration(Reader reader) throws IOException { + StreamTokenizer streamTokenizer = new StreamTokenizer(reader); + List tokens = new ArrayList<>(); + + streamTokenizer.wordChars('!', '-'); + streamTokenizer.ordinaryChar('/'); + streamTokenizer.commentChar('#'); + streamTokenizer.eolIsSignificant(true); + + int currentToken = streamTokenizer.nextToken(); + while (currentToken != StreamTokenizer.TT_EOF) { + + if (streamTokenizer.ttype == StreamTokenizer.TT_NUMBER) { + tokens.add(streamTokenizer.nval); + } else if (streamTokenizer.ttype == StreamTokenizer.TT_WORD + || streamTokenizer.ttype == QUOTE_CHARACTER + || streamTokenizer.ttype == DOUBLE_QUOTE_CHARACTER) { + tokens.add(streamTokenizer.sval); + } else { + tokens.add((char) currentToken); + } + currentToken = streamTokenizer.nextToken(); + } + + return tokens; + } + + public static Reader createReaderFromFile() throws FileNotFoundException { + String inputFile = StreamTokenizerDemo.class.getResource(INPUT_FILE).getFile(); + return new FileReader(inputFile); + } + + public static void main(String[] args) throws IOException { + List tokens1 = streamTokenizerWithDefaultConfiguration(createReaderFromFile()); + List tokens2 = streamTokenizerWithCustomConfiguration(createReaderFromFile()); + + System.out.println(tokens1); + System.out.println(tokens2); + } + +} \ No newline at end of file diff --git a/java-strings-2/src/main/resources/stream-tokenizer-example.txt b/java-strings-2/src/main/resources/stream-tokenizer-example.txt new file mode 100644 index 0000000000..6efe4fdc81 --- /dev/null +++ b/java-strings-2/src/main/resources/stream-tokenizer-example.txt @@ -0,0 +1,3 @@ +3 quick brown foxes jump over the "lazy" dog! +#test1 +//test2 \ No newline at end of file diff --git a/java-strings-2/src/test/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemoUnitTest.java b/java-strings-2/src/test/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemoUnitTest.java new file mode 100644 index 0000000000..01091ec629 --- /dev/null +++ b/java-strings-2/src/test/java/com/baeldung/string/streamtokenizer/StreamTokenizerDemoUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung.string.streamtokenizer; + +import org.junit.Test; + +import java.io.IOException; +import java.io.Reader; +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertArrayEquals; + +public class StreamTokenizerDemoUnitTest { + + @Test + public void whenStreamTokenizerWithDefaultConfigurationIsCalled_ThenCorrectTokensAreReturned() throws IOException { + Reader reader = StreamTokenizerDemo.createReaderFromFile(); + List expectedTokens = Arrays.asList(3.0, "quick", "brown", "foxes", "jump", "over", "the", "lazy", "dog", '!', '#', "test1"); + + List actualTokens = StreamTokenizerDemo.streamTokenizerWithDefaultConfiguration(reader); + + assertArrayEquals(expectedTokens.toArray(), actualTokens.toArray()); + } + + @Test + public void whenStreamTokenizerWithCustomConfigurationIsCalled_ThenCorrectTokensAreReturned() throws IOException { + Reader reader = StreamTokenizerDemo.createReaderFromFile(); + List expectedTokens = Arrays.asList(3.0, "quick", "brown", "foxes", "jump", "over", "the", "\"lazy\"", "dog!", '\n', '\n', '/', '/', "test2"); + + List actualTokens = StreamTokenizerDemo.streamTokenizerWithCustomConfiguration(reader); + + assertArrayEquals(expectedTokens.toArray(), actualTokens.toArray()); + } + +} From 0630b2dffcb9c2a49c68d7df025dfc7b07308daa Mon Sep 17 00:00:00 2001 From: Gang Date: Tue, 20 Aug 2019 22:53:05 -0600 Subject: [PATCH 02/13] BAEL-3146 Source code for article: Checked and Unchecked Exceptions in Java --- .../CheckedUncheckedExceptions.java | 43 +++++++++++++++ .../IncorrectFileNameException.java | 13 +++++ .../exceptions/NullOrEmptyException.java | 14 +++++ .../CheckedUncheckedExceptionsUnitTest.java | 54 +++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/CheckedUncheckedExceptions.java create mode 100644 core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/IncorrectFileNameException.java create mode 100644 core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/NullOrEmptyException.java create mode 100644 core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/CheckedUncheckedExceptions.java b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/CheckedUncheckedExceptions.java new file mode 100644 index 0000000000..780189b654 --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/CheckedUncheckedExceptions.java @@ -0,0 +1,43 @@ +package com.baeldung.exceptions; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +public class CheckedUncheckedExceptions { + public static void checkedExceptionWithThrows() throws FileNotFoundException { + File file = new File("not_existing_file.txt"); + FileInputStream stream = new FileInputStream(file); + } + + public static void checkedExceptionWithTryCatch() { + File file = new File("not_existing_file.txt"); + try { + FileInputStream stream = new FileInputStream(file); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + public static int divideByZero() { + int numerator = 1; + int denominator = 0; + return numerator / denominator; + } + + public static void checkFile(String fileName) throws IncorrectFileNameException { + if (fileName == null || fileName.isEmpty()) { + throw new NullOrEmptyException("The filename is null."); + } + if (!isCorrectFileName(fileName)) { + throw new IncorrectFileNameException("Incorrect filename : " + fileName); + } + } + + private static boolean isCorrectFileName(String fileName) { + if (fileName.equals("wrongFileName.txt")) + return false; + else + return true; + } +} diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/IncorrectFileNameException.java b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/IncorrectFileNameException.java new file mode 100644 index 0000000000..9877fe25ca --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/IncorrectFileNameException.java @@ -0,0 +1,13 @@ +package com.baeldung.exceptions; + +public class IncorrectFileNameException extends Exception { + private static final long serialVersionUID = 1L; + + public IncorrectFileNameException(String errorMessage) { + super(errorMessage); + } + + public IncorrectFileNameException(String errorMessage, Throwable thr) { + super(errorMessage, thr); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/NullOrEmptyException.java b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/NullOrEmptyException.java new file mode 100644 index 0000000000..d4ee9c0d6f --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/main/java/com/baeldung/exceptions/NullOrEmptyException.java @@ -0,0 +1,14 @@ +package com.baeldung.exceptions; + +public class NullOrEmptyException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public NullOrEmptyException(String errorMessage) { + super(errorMessage); + } + + public NullOrEmptyException(String errorMessage, Throwable thr) { + super(errorMessage, thr); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java new file mode 100644 index 0000000000..05a01ba97d --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.exceptions; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import java.io.FileNotFoundException; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +/** + * Tests the {@link CheckedUncheckedExceptions}. + */ +public class CheckedUncheckedExceptionsUnitTest { + + @Test + public void whenFileNotExist_thenThrowException() { + assertThrows(FileNotFoundException.class, () -> { + CheckedUncheckedExceptions.checkedExceptionWithThrows(); + }); + } + + public void whenTryCatchExcetpion_thenSuccess() { + try { + CheckedUncheckedExceptions.checkedExceptionWithTryCatch(); + } catch (Exception e) { + Assertions.fail(e.getMessage()); + } + } + + @Test + public void whenDivideByZero_thenThrowException() { + assertThrows(ArithmeticException.class, () -> { + CheckedUncheckedExceptions.divideByZero(); + }); + } + + @Test + public void whenInvalidFile_thenThrowException() { + + assertThrows(IncorrectFileNameException.class, () -> { + CheckedUncheckedExceptions.checkFile("wrongFileName.txt"); + }); + } + + @Test + public void whenNullOrEmptyFile_thenThrowException() { + assertThrows(NullOrEmptyException.class, () -> { + CheckedUncheckedExceptions.checkFile(null); + }); + assertThrows(NullOrEmptyException.class, () -> { + CheckedUncheckedExceptions.checkFile(""); + }); + } +} From 7e1ee8740e8ea464aaef2a9d04e0e231232c5e3d Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sat, 24 Aug 2019 20:29:21 +0530 Subject: [PATCH 03/13] [BAEL-16733] - Update package name and tests in spring-security-core --- .../{org => com}/baeldung/SpringContextIntegrationTest.java | 2 +- .../test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- .../methodsecurity/TestClassLevelSecurityUnitTest.java} | 4 ++-- .../baeldung/methodsecurity/TestMethodSecurityUnitTest.java} | 4 ++-- .../methodsecurity/TestWithMockUserAtClassLevelUnitTest.java} | 4 ++-- .../baeldung/methodsecurity/TestWithUserDetailsUnitTest.java} | 4 ++-- .../baeldung/methodsecurity/WithMockJohnViewer.java | 2 +- .../src/test/java/{org => com}/baeldung/test/LiveTest.java | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) rename spring-security-core/src/test/java/{org => com}/baeldung/SpringContextIntegrationTest.java (94%) rename spring-security-core/src/test/java/{org => com}/baeldung/SpringContextTest.java (94%) rename spring-security-core/src/test/java/{org/baeldung/methodsecurity/TestClassLevelSecurity.java => com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java} (92%) rename spring-security-core/src/test/java/{org/baeldung/methodsecurity/TestMethodSecurity.java => com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java} (96%) rename spring-security-core/src/test/java/{org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java => com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java} (89%) rename spring-security-core/src/test/java/{org/baeldung/methodsecurity/TestWithUserDetails.java => com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java} (93%) rename spring-security-core/src/test/java/{org => com}/baeldung/methodsecurity/WithMockJohnViewer.java (85%) rename spring-security-core/src/test/java/{org => com}/baeldung/test/LiveTest.java (99%) diff --git a/spring-security-core/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 94% rename from spring-security-core/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java index 5698afa417..73f735e93a 100644 --- a/spring-security-core/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.baeldung.app.App; import org.junit.Test; diff --git a/spring-security-core/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java similarity index 94% rename from spring-security-core/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-core/src/test/java/com/baeldung/SpringContextTest.java index 1707c706ae..4a76ea35b5 100644 --- a/spring-security-core/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.baeldung.app.App; import org.junit.Test; diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java similarity index 92% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java index 502fd50c46..b1d83c162b 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity; +package com.baeldung.methodsecurity; import static org.junit.Assert.*; @@ -15,7 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration -public class TestClassLevelSecurity { +public class TestClassLevelSecurityUnitTest { @Autowired SystemService systemService; diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java similarity index 96% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java index 009d9af9fc..b320e06a24 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity; +package com.baeldung.methodsecurity; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -21,7 +21,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration -public class TestMethodSecurity { +public class TestMethodSecurityUnitTest { @Autowired UserRoleService userRoleService; diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java similarity index 89% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java index 4df1af8ca9..47a9ddb985 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity; +package com.baeldung.methodsecurity; import static org.junit.Assert.assertEquals; @@ -15,7 +15,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration @WithMockUser(username = "john", roles = { "VIEWER" }) -public class TestWithMockUserAtClassLevel { +public class TestWithMockUserAtClassLevelUnitTest { @Test public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() { diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java similarity index 93% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java index 3ef5996554..3130e99ddf 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity; +package com.baeldung.methodsecurity; import static org.junit.Assert.assertEquals; @@ -16,7 +16,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @ContextConfiguration -public class TestWithUserDetails { +public class TestWithUserDetailsUnitTest { @Autowired UserRoleService userService; diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/WithMockJohnViewer.java similarity index 85% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/WithMockJohnViewer.java index 5e1e882f3d..f05a6bc20e 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/WithMockJohnViewer.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/WithMockJohnViewer.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity; +package com.baeldung.methodsecurity; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; diff --git a/spring-security-core/src/test/java/org/baeldung/test/LiveTest.java b/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java similarity index 99% rename from spring-security-core/src/test/java/org/baeldung/test/LiveTest.java rename to spring-security-core/src/test/java/com/baeldung/test/LiveTest.java index 7243d3efd5..32d3a9ed74 100644 --- a/spring-security-core/src/test/java/org/baeldung/test/LiveTest.java +++ b/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.test; +package com.baeldung.test; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; From 6a483e6eab472cbfbf6ceea9dfd4fd9814ab1d25 Mon Sep 17 00:00:00 2001 From: eric-martin Date: Sat, 24 Aug 2019 12:16:34 -0500 Subject: [PATCH 04/13] BAEL-2774: Remove gradle-5/.gitignore --- gradle-5/.gitignore | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 gradle-5/.gitignore diff --git a/gradle-5/.gitignore b/gradle-5/.gitignore deleted file mode 100644 index 7dd8895f4b..0000000000 --- a/gradle-5/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -/build/ -/bin/ -.settings -.gradle -.project -.classpath \ No newline at end of file From 50ca18c4ce7487c273ad9eb90edb547515ec6ebe Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Aug 2019 10:14:33 +0530 Subject: [PATCH 05/13] [BAEL-12749] - Moved the Hibernate specific articles out of persistence-modules/spring-jpa module --- .../_6.fdt | Bin 160 -> 0 bytes .../_6.fdx | Bin 84 -> 0 bytes .../_6.fnm | Bin 532 -> 0 bytes .../_6.nvd | Bin 65 -> 0 bytes .../_6.nvm | Bin 88 -> 0 bytes .../_6.si | Bin 503 -> 0 bytes .../_6.tvd | Bin 392 -> 0 bytes .../_6.tvx | Bin 79 -> 0 bytes .../_6_Lucene50_0.doc | Bin 190 -> 0 bytes .../_6_Lucene50_0.pos | Bin 162 -> 0 bytes .../_6_Lucene50_0.tim | Bin 914 -> 0 bytes .../_6_Lucene50_0.tip | Bin 195 -> 0 bytes .../_7.cfe | Bin 341 -> 0 bytes .../_7.cfs | Bin 2119 -> 0 bytes .../_7.si | Bin 360 -> 0 bytes .../segments_9 | Bin 198 -> 0 bytes .../write.lock | 0 17 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdt delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdx delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fnm delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvd delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvm delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.si delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvd delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvx delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.doc delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.pos delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tim delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tip delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfe delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfs delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.si delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/segments_9 delete mode 100644 persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/write.lock diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdt b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdt deleted file mode 100644 index c44ea80ed4835cac6d7c02e0283250eba151a13b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 160 zcmcD&o+B>fQ<|KbmuhMdT#{dun&Ot3nv+uOmRMZkl30?+z`($$U=u!Hth|RWNNSI7 zaZmMPhK2@4CI%h`CI_I diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdx b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdx deleted file mode 100644 index 77b3c43c2118eeeb99c5a92ce5c2798d92150eb2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 84 zcmcD&o+B>nQ<|KbmuhMdT#{dun&Ot3nv+uOmRMZknU|7U!N9=4s9+O5U#z@`FGy;S hZ*focVg@EgpeTbC5Hs{K9?+Ql0;mcMR=Nh=0042_7#jcp diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fnm b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fnm deleted file mode 100644 index 6a5f78d0a0d7f5dd416efcf7902a150f90c4a666..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 532 zcmcD&o+B>gQ<|KbmuhO@mYJH9;+dD0U(CS3z^GsoK3}Z7hc8HKk8g2L^ovau*ckr<5j__$B71GBHx$+1x3q#mPmP1tppJdCW90pDi~vH@~Qo Wg^7{sA$~w(@(W;ugTd$P_VWNA*U|t0 diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvd b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvd deleted file mode 100644 index 7644ffa79bd8bfde66f6115cfd602d89ab62c4f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 65 zcmcD&o+B>kQ<|KbmuhP4mtT}y?2=fL$N&TiHsSNd%6s^Nr1tn0_f#)tC@C$eC@(*t PG5G~Z8UzCG{Fn&<$0Zf# diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvm b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvm deleted file mode 100644 index b2eb2c7a525bc3f5ed0c4376a456f7d110a846d2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 88 zcmcD&o+B>mQ<|KbmuhP4mtT}y?3-GWn37nM$N&TiHsSNd%6s^Nr1tn0_f#)tU;>GP bKshrbgu$Tw9|-slXiR z{OL_&hV^F^zAI~77Kb6jd@7rr@*_$RNQiF5_O(DkM4D$@Ot?TQAQ3!Rh+?ZlJh)$}|ab0L1wYzqw?NqjW z*Uz8MZvo7M6+{dFA(Mjd0+r0tGQuh?ETLJ)vZ4~a;ASh@373o0*wP{yn)~_Xo{mj$ kKO_;BeJ&_cfO1Sqr#(I$Rz@`5}>6FQ#L))tdz6ZV^&iM}C^`D|t+RP$S6s~?CBeyAX z+SnF41b|?EZRhk!|8TlJ_kGJAemsY<;XF)0?%CzV8Nm3}r>n5jc~B_$+n3(YdbI#@ zL&&%6>y0<(ZQQBVmctj14|jt^UBZ~j_CzO7d3;VSEjOmdVwGTQ2%YeMm9tqJe%O%VK8 PJpSc7yPv;ri#PuP$%24n diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvx b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvx deleted file mode 100644 index 6b97c002b30e9a9274e680c4086f3dd8af04cd54..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 79 zcmcD&o+B>dQ<|KbmuhMdl3J7-mYQ6WUsUXwmy%k+z`($$U=u!Hth|RWNNSI7aZmMP c1|~+JD1!+QGkjw@pfULcP!$-6FJJKz0N;le*Z=?k diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.doc b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.doc deleted file mode 100644 index f86ebad3d109a32f4d3ec9d144cfb7cd5fb20bf3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 190 zcmcD&o+B>lQ<|KbmuhMdkY8MqnU`K1UX)pqTI7lQ<|KbmuhMdkY8MqnU`K1UX)pqS_I@V0D*!{_~)r+}c zs^bkn(hLkdOl)i{JdBLY%plCm!OF_a$i&3Q$-&6U!NtbL&cedP%*4dS%F4|O(ZCD_ iOiWBbE+Y#VFoFOB0}}%i(*cdiFCgj|7)qF>mjM7hq8XY1 diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tim b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tim deleted file mode 100644 index 3f8b1e4ab0ec3c81c17d458acde3b0b03e775bb1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 914 zcmb7Dy>HYo6!)_e-%*uT6bUFu2NOb6I$f{5qXVc27(uE~rEY*PaTBXf9NCWUDh5#J zPIO>oU_@eIX5g=&I};Q93p^*ij!5-K-nXCM?>XD2`ufTfZIXjsE9I`Vg?pwFPY9uR z9`1d*Ha%W?dGq@Vcl`GA!t*+jr5p`j56Cu#-I~ig#(7m{ZqF(&ZF2_3lmEoO2ex-V zF-3nOq)zKH>*s1BZ7IBTQrIN#7bcauzhg~WC!TUbUp?A5rIFCibVQk2qtaMZm6qKk z7dFH6og|l{l9uDSjaXYNOV4DPM*AX>(Y`fBoLMP+l&dVKD&?xmO)0q!d3~f+DI;yX z-R%C@niyX0;Y}!4<;#CSt+WRb_0bx-(T}YNoC`RaR>09G@zmt8xeg2*XX! z=UfVwc2cCg@d@&F`jikrFUHV7&j(|uYa}GiLN{EfBEWg;i{j-~Scf5Oz$T1fyf{x1 z=+z@AF#=ii#?vAK@s)(X>4rYF;kTAm41!a z)_D6M&pHmAep?DTu?ypol#`#F9a5B<8j@O+TkM&al3KyQz`&$n6Fy(8yoWDHYL9PmPxWFhpVH*i zyi`+zcmsQ&HfFcr5TG(v21aJ)M@$S1j0|X^tn09e@@>K<%Kr|VsL&*^sJU-)Wj`a( UE)ZCHKx6U?2$O*!D{M+F0FU1)Jpcdz diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfe b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfe deleted file mode 100644 index d1359e482e2d258c59d493f06401eda9938089fe..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 341 zcmcD&o+B>qQ<|KbmuhO@oS$2eUz(TVnpaYknOe*M1PV6c^To=0_=2SN_!jq6FJ<87 zkB2FbH_$7|EC8tj0zC-DaF|6euPhhJ`3R*WSoBKDQXm{gPpIG&7QM7Qs7l7W5J4sp zpkPV~gu@Ke-iTsnK|a`J3=AwqP?I7-##cZ%ET^G@{vd}y?PQgL3RRFVm`o;4IA n&!h;l9%>SM8B|j+il&tOWQaKXNvM3@0gcHoplk+ipdYA3`(b{p_!w) zLg!&GDc)S>pw2}2YeIB#3bu&|3&JKr2-{$;RdIE{Ro}+GtK0jn2A1sAzA<^>8Rq;U zme)I<|IXba^rkZOjdQ8ZQ|lgQpkRzzl2S@BAm(CD*tz=$QQ^j=E3dwA+Z(P2Ex6aE+Dy6BxG*zF~SX@m}Q{KGj_JDj2_O(~;#f|(#>FCDRRCaK1$ zp-UE>kyDasA|fCzl?Q2^poWbw!AuK?nNcX6WQ7y<#qT63wav^V66!pT5LLk^02@pj zOv%XBxTH~nkDqo>p{8u8X-j3ga02*VjcUwT@DP0L6?gZ<->1uQ-V-g(aZN&pQpG-3 zGb))@$!5)FF+qe}+GI|2$TV_WSZwaH>3 zc7($L@xt^q6rA+s4aW-y3zO~5c~04`>G<-lQ-+~ZxlhIPbzZuiuOQ++8*mr}E_(0z zfoi3g^uWcF1`8GDG4fyt|1=i?5$qvdy#lxxnT?CKj|Fy&tRToQ<|KbmuhMdoSL4SnpfhPmzK}Kz`&?r6Fy(8yoWDHYL9PmPxVru7y~O3 zW@O}I$}i>&&&*57FE3Uw=gvwjOVle%1#*jo{EHHkb5a$Y^NR}dixNvR^YeJ1(nZBU z4yU1>g`PpYp_w5+L^v0y5iG-HWU2=g)=e@r;>!U$3?{>Bst1JZ`NevPMadbgiMc6e zCL&irw;yauZARa`RJC cxtv^sL*j!2TwPrbXiRG*@ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/write.lock b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/write.lock deleted file mode 100644 index e69de29bb2..0000000000 From b172804fe187593f28e2ef2d235852c03e15fe01 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Aug 2019 10:30:00 +0530 Subject: [PATCH 06/13] [BAEL-16733] - Update package name and tests in spring-security-core --- .../src/main/java/{org => com}/baeldung/app/App.java | 8 ++++---- .../ExposeAttemptedPathAuthorizationAuditListener.java | 2 +- .../baeldung/auditing/LoginAttemptsLogger.java | 2 +- .../{org => com}/baeldung/config/DatabaseLoader.java | 7 ++++--- .../{org => com}/baeldung/config/WebSecurityConfig.java | 2 +- .../{org => com}/baeldung/controller/TaskController.java | 7 ++++--- .../src/main/java/{org => com}/baeldung/entity/Task.java | 2 +- .../java/{org => com}/baeldung/filter/CustomFilter.java | 2 +- .../baeldung/methodsecurity/annotation/IsViewer.java | 2 +- .../methodsecurity/config/MethodSecurityConfig.java | 2 +- .../baeldung/methodsecurity/entity/CustomUser.java | 2 +- .../methodsecurity/repository/UserRoleRepository.java | 5 +++-- .../methodsecurity/service/CustomUserDetailsService.java | 5 +++-- .../baeldung/methodsecurity/service/SystemService.java | 2 +- .../baeldung/methodsecurity/service/UserRoleService.java | 9 +++++---- .../{org => com}/baeldung/repository/TaskRepository.java | 5 +++-- .../java/{org => com}/baeldung/service/TaskService.java | 7 ++++--- .../java/com/baeldung/SpringContextIntegrationTest.java | 3 ++- .../src/test/java/com/baeldung/SpringContextTest.java | 3 ++- ...tTest.java => ClassLevelSecurityIntegrationTest.java} | 7 ++++--- ...yUnitTest.java => MethodSecurityIntegrationTest.java} | 7 ++++--- ...est.java => MockUserAtClassLevelIntegrationTest.java} | 7 ++++--- ...ailsUnitTest.java => UserDetailsIntegrationTest.java} | 9 +++++---- .../src/test/java/com/baeldung/test/LiveTest.java | 3 ++- 24 files changed, 62 insertions(+), 48 deletions(-) rename spring-security-core/src/main/java/{org => com}/baeldung/app/App.java (92%) rename spring-security-core/src/main/java/{org => com}/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java (98%) rename spring-security-core/src/main/java/{org => com}/baeldung/auditing/LoginAttemptsLogger.java (97%) rename spring-security-core/src/main/java/{org => com}/baeldung/config/DatabaseLoader.java (86%) rename spring-security-core/src/main/java/{org => com}/baeldung/config/WebSecurityConfig.java (98%) rename spring-security-core/src/main/java/{org => com}/baeldung/controller/TaskController.java (90%) rename spring-security-core/src/main/java/{org => com}/baeldung/entity/Task.java (96%) rename spring-security-core/src/main/java/{org => com}/baeldung/filter/CustomFilter.java (97%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/annotation/IsViewer.java (85%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/config/MethodSecurityConfig.java (91%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/entity/CustomUser.java (91%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/repository/UserRoleRepository.java (92%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/service/CustomUserDetailsService.java (81%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/service/SystemService.java (84%) rename spring-security-core/src/main/java/{org => com}/baeldung/methodsecurity/service/UserRoleService.java (92%) rename spring-security-core/src/main/java/{org => com}/baeldung/repository/TaskRepository.java (66%) rename spring-security-core/src/main/java/{org => com}/baeldung/service/TaskService.java (86%) rename spring-security-core/src/test/java/com/baeldung/methodsecurity/{TestClassLevelSecurityUnitTest.java => ClassLevelSecurityIntegrationTest.java} (87%) rename spring-security-core/src/test/java/com/baeldung/methodsecurity/{TestMethodSecurityUnitTest.java => MethodSecurityIntegrationTest.java} (95%) rename spring-security-core/src/test/java/com/baeldung/methodsecurity/{TestWithMockUserAtClassLevelUnitTest.java => MockUserAtClassLevelIntegrationTest.java} (82%) rename spring-security-core/src/test/java/com/baeldung/methodsecurity/{TestWithUserDetailsUnitTest.java => UserDetailsIntegrationTest.java} (87%) diff --git a/spring-security-core/src/main/java/org/baeldung/app/App.java b/spring-security-core/src/main/java/com/baeldung/app/App.java similarity index 92% rename from spring-security-core/src/main/java/org/baeldung/app/App.java rename to spring-security-core/src/main/java/com/baeldung/app/App.java index bf719b3b12..d23df9adef 100644 --- a/spring-security-core/src/main/java/org/baeldung/app/App.java +++ b/spring-security-core/src/main/java/com/baeldung/app/App.java @@ -1,4 +1,4 @@ -package org.baeldung.app; +package com.baeldung.app; import javax.servlet.Filter; @@ -12,9 +12,9 @@ import org.springframework.web.filter.DelegatingFilterProxy; import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; @SpringBootApplication -@EnableJpaRepositories("org.baeldung.repository") -@ComponentScan("org.baeldung") -@EntityScan("org.baeldung.entity") +@EnableJpaRepositories("com.baeldung.repository") +@ComponentScan("com.baeldung") +@EntityScan("com.baeldung.entity") public class App extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(App.class, args); diff --git a/spring-security-core/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java b/spring-security-core/src/main/java/com/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java similarity index 98% rename from spring-security-core/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java rename to spring-security-core/src/main/java/com/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java index bc36ac08b3..615d14584f 100644 --- a/spring-security-core/src/main/java/org/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java +++ b/spring-security-core/src/main/java/com/baeldung/auditing/ExposeAttemptedPathAuthorizationAuditListener.java @@ -1,4 +1,4 @@ -package org.baeldung.auditing; +package com.baeldung.auditing; import org.springframework.boot.actuate.audit.AuditEvent; import org.springframework.boot.actuate.security.AbstractAuthorizationAuditListener; diff --git a/spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java b/spring-security-core/src/main/java/com/baeldung/auditing/LoginAttemptsLogger.java similarity index 97% rename from spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java rename to spring-security-core/src/main/java/com/baeldung/auditing/LoginAttemptsLogger.java index bf0781bced..d06c3e24e1 100644 --- a/spring-security-core/src/main/java/org/baeldung/auditing/LoginAttemptsLogger.java +++ b/spring-security-core/src/main/java/com/baeldung/auditing/LoginAttemptsLogger.java @@ -1,4 +1,4 @@ -package org.baeldung.auditing; +package com.baeldung.auditing; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-security-core/src/main/java/org/baeldung/config/DatabaseLoader.java b/spring-security-core/src/main/java/com/baeldung/config/DatabaseLoader.java similarity index 86% rename from spring-security-core/src/main/java/org/baeldung/config/DatabaseLoader.java rename to spring-security-core/src/main/java/com/baeldung/config/DatabaseLoader.java index e311f62fff..7f22c3ec99 100644 --- a/spring-security-core/src/main/java/org/baeldung/config/DatabaseLoader.java +++ b/spring-security-core/src/main/java/com/baeldung/config/DatabaseLoader.java @@ -1,11 +1,12 @@ -package org.baeldung.config; +package com.baeldung.config; -import org.baeldung.entity.Task; -import org.baeldung.repository.TaskRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; +import com.baeldung.entity.Task; +import com.baeldung.repository.TaskRepository; + @Component public class DatabaseLoader implements CommandLineRunner { diff --git a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-core/src/main/java/com/baeldung/config/WebSecurityConfig.java similarity index 98% rename from spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java rename to spring-security-core/src/main/java/com/baeldung/config/WebSecurityConfig.java index df7c7d1611..be11a0fde5 100644 --- a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java +++ b/spring-security-core/src/main/java/com/baeldung/config/WebSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/spring-security-core/src/main/java/org/baeldung/controller/TaskController.java b/spring-security-core/src/main/java/com/baeldung/controller/TaskController.java similarity index 90% rename from spring-security-core/src/main/java/org/baeldung/controller/TaskController.java rename to spring-security-core/src/main/java/com/baeldung/controller/TaskController.java index d99109c543..91156354b1 100644 --- a/spring-security-core/src/main/java/org/baeldung/controller/TaskController.java +++ b/spring-security-core/src/main/java/com/baeldung/controller/TaskController.java @@ -1,7 +1,5 @@ -package org.baeldung.controller; +package com.baeldung.controller; -import org.baeldung.entity.Task; -import org.baeldung.service.TaskService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; @@ -9,6 +7,9 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import com.baeldung.entity.Task; +import com.baeldung.service.TaskService; + @Controller @RequestMapping("api/tasks") public class TaskController { diff --git a/spring-security-core/src/main/java/org/baeldung/entity/Task.java b/spring-security-core/src/main/java/com/baeldung/entity/Task.java similarity index 96% rename from spring-security-core/src/main/java/org/baeldung/entity/Task.java rename to spring-security-core/src/main/java/com/baeldung/entity/Task.java index 5d3321ef2e..9103c342cc 100644 --- a/spring-security-core/src/main/java/org/baeldung/entity/Task.java +++ b/spring-security-core/src/main/java/com/baeldung/entity/Task.java @@ -1,4 +1,4 @@ -package org.baeldung.entity; +package com.baeldung.entity; import javax.persistence.Entity; import javax.persistence.GeneratedValue; diff --git a/spring-security-core/src/main/java/org/baeldung/filter/CustomFilter.java b/spring-security-core/src/main/java/com/baeldung/filter/CustomFilter.java similarity index 97% rename from spring-security-core/src/main/java/org/baeldung/filter/CustomFilter.java rename to spring-security-core/src/main/java/com/baeldung/filter/CustomFilter.java index 35596eae16..e748b373b7 100644 --- a/spring-security-core/src/main/java/org/baeldung/filter/CustomFilter.java +++ b/spring-security-core/src/main/java/com/baeldung/filter/CustomFilter.java @@ -1,4 +1,4 @@ -package org.baeldung.filter; +package com.baeldung.filter; import java.io.IOException; diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/annotation/IsViewer.java similarity index 85% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/annotation/IsViewer.java index 711784adbb..bde4456f8e 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/annotation/IsViewer.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/annotation/IsViewer.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity.annotation; +package com.baeldung.methodsecurity.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/config/MethodSecurityConfig.java similarity index 91% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/config/MethodSecurityConfig.java index 4749c730dc..239f7067a4 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/config/MethodSecurityConfig.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/config/MethodSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity.config; +package com.baeldung.methodsecurity.config; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/entity/CustomUser.java similarity index 91% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/entity/CustomUser.java index fb9174befa..7daaef5984 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/entity/CustomUser.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/entity/CustomUser.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity.entity; +package com.baeldung.methodsecurity.entity; import java.util.Collection; diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/repository/UserRoleRepository.java similarity index 92% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/repository/UserRoleRepository.java index fc1a32289d..eef39189a7 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/repository/UserRoleRepository.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/repository/UserRoleRepository.java @@ -1,16 +1,17 @@ -package org.baeldung.methodsecurity.repository; +package com.baeldung.methodsecurity.repository; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.baeldung.methodsecurity.entity.CustomUser; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; +import com.baeldung.methodsecurity.entity.CustomUser; + @Service public class UserRoleRepository { diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/CustomUserDetailsService.java similarity index 81% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/service/CustomUserDetailsService.java index 91171468bb..685621b55f 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/CustomUserDetailsService.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/CustomUserDetailsService.java @@ -1,11 +1,12 @@ -package org.baeldung.methodsecurity.service; +package com.baeldung.methodsecurity.service; -import org.baeldung.methodsecurity.repository.UserRoleRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.stereotype.Service; +import com.baeldung.methodsecurity.repository.UserRoleRepository; + @Service("userDetailService") public class CustomUserDetailsService implements UserDetailsService { diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/SystemService.java similarity index 84% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/service/SystemService.java index 5f29d7dee6..623d51d34f 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/SystemService.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/SystemService.java @@ -1,4 +1,4 @@ -package org.baeldung.methodsecurity.service; +package com.baeldung.methodsecurity.service; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.stereotype.Service; diff --git a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/UserRoleService.java similarity index 92% rename from spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java rename to spring-security-core/src/main/java/com/baeldung/methodsecurity/service/UserRoleService.java index 30bbdbc10f..4d090fd90c 100644 --- a/spring-security-core/src/main/java/org/baeldung/methodsecurity/service/UserRoleService.java +++ b/spring-security-core/src/main/java/com/baeldung/methodsecurity/service/UserRoleService.java @@ -1,13 +1,10 @@ -package org.baeldung.methodsecurity.service; +package com.baeldung.methodsecurity.service; import java.util.List; import java.util.stream.Collectors; import javax.annotation.security.RolesAllowed; -import org.baeldung.methodsecurity.annotation.IsViewer; -import org.baeldung.methodsecurity.entity.CustomUser; -import org.baeldung.methodsecurity.repository.UserRoleRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.prepost.PostAuthorize; @@ -18,6 +15,10 @@ import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; +import com.baeldung.methodsecurity.annotation.IsViewer; +import com.baeldung.methodsecurity.entity.CustomUser; +import com.baeldung.methodsecurity.repository.UserRoleRepository; + @Service public class UserRoleService { diff --git a/spring-security-core/src/main/java/org/baeldung/repository/TaskRepository.java b/spring-security-core/src/main/java/com/baeldung/repository/TaskRepository.java similarity index 66% rename from spring-security-core/src/main/java/org/baeldung/repository/TaskRepository.java rename to spring-security-core/src/main/java/com/baeldung/repository/TaskRepository.java index 651b11684f..afb999719c 100644 --- a/spring-security-core/src/main/java/org/baeldung/repository/TaskRepository.java +++ b/spring-security-core/src/main/java/com/baeldung/repository/TaskRepository.java @@ -1,8 +1,9 @@ -package org.baeldung.repository; +package com.baeldung.repository; -import org.baeldung.entity.Task; import org.springframework.data.repository.CrudRepository; +import com.baeldung.entity.Task; + public interface TaskRepository extends CrudRepository { } diff --git a/spring-security-core/src/main/java/org/baeldung/service/TaskService.java b/spring-security-core/src/main/java/com/baeldung/service/TaskService.java similarity index 86% rename from spring-security-core/src/main/java/org/baeldung/service/TaskService.java rename to spring-security-core/src/main/java/com/baeldung/service/TaskService.java index 4efa3b0294..1269eb4fd0 100644 --- a/spring-security-core/src/main/java/org/baeldung/service/TaskService.java +++ b/spring-security-core/src/main/java/com/baeldung/service/TaskService.java @@ -1,12 +1,13 @@ -package org.baeldung.service; +package com.baeldung.service; -import org.baeldung.entity.Task; -import org.baeldung.repository.TaskRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PostFilter; import org.springframework.security.access.prepost.PreFilter; import org.springframework.stereotype.Service; +import com.baeldung.entity.Task; +import com.baeldung.repository.TaskRepository; + @Service public class TaskService { diff --git a/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java index 73f735e93a..1cdff1342c 100644 --- a/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -1,11 +1,12 @@ package com.baeldung; -import org.baeldung.app.App; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.app.App; + @RunWith(SpringRunner.class) @SpringBootTest(classes = App.class) public class SpringContextIntegrationTest { diff --git a/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java index 4a76ea35b5..bca6450fb1 100644 --- a/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java @@ -1,11 +1,12 @@ package com.baeldung; -import org.baeldung.app.App; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.app.App; + @RunWith(SpringRunner.class) @SpringBootTest(classes = App.class) public class SpringContextTest { diff --git a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java similarity index 87% rename from spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java index b1d83c162b..943bfda72c 100644 --- a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestClassLevelSecurityUnitTest.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java @@ -2,7 +2,6 @@ package com.baeldung.methodsecurity; import static org.junit.Assert.*; -import org.baeldung.methodsecurity.service.SystemService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -13,15 +12,17 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.methodsecurity.service.SystemService; + @RunWith(SpringRunner.class) @ContextConfiguration -public class TestClassLevelSecurityUnitTest { +public class ClassLevelSecurityIntegrationTest { @Autowired SystemService systemService; @Configuration - @ComponentScan("org.baeldung.methodsecurity.*") + @ComponentScan("com.baeldung.methodsecurity.*") public static class SpringConfig { } diff --git a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.java similarity index 95% rename from spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.java index b320e06a24..81b150f43e 100644 --- a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestMethodSecurityUnitTest.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.java @@ -6,7 +6,6 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; -import org.baeldung.methodsecurity.service.UserRoleService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -19,15 +18,17 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.methodsecurity.service.UserRoleService; + @RunWith(SpringRunner.class) @ContextConfiguration -public class TestMethodSecurityUnitTest { +public class MethodSecurityIntegrationTest { @Autowired UserRoleService userRoleService; @Configuration - @ComponentScan("org.baeldung.methodsecurity.*") + @ComponentScan("com.baeldung.methodsecurity.*") public static class SpringConfig { } diff --git a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java similarity index 82% rename from spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java index 47a9ddb985..fead89f75a 100644 --- a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithMockUserAtClassLevelUnitTest.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java @@ -2,7 +2,6 @@ package com.baeldung.methodsecurity; import static org.junit.Assert.assertEquals; -import org.baeldung.methodsecurity.service.UserRoleService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -12,10 +11,12 @@ import org.springframework.security.test.context.support.WithMockUser; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.methodsecurity.service.UserRoleService; + @RunWith(SpringRunner.class) @ContextConfiguration @WithMockUser(username = "john", roles = { "VIEWER" }) -public class TestWithMockUserAtClassLevelUnitTest { +public class MockUserAtClassLevelIntegrationTest { @Test public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() { @@ -27,7 +28,7 @@ public class TestWithMockUserAtClassLevelUnitTest { UserRoleService userService; @Configuration - @ComponentScan("org.baeldung.methodsecurity.*") + @ComponentScan("com.baeldung.methodsecurity.*") public static class SpringConfig { } diff --git a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java similarity index 87% rename from spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java index 3130e99ddf..d43a26a5ff 100644 --- a/spring-security-core/src/test/java/com/baeldung/methodsecurity/TestWithUserDetailsUnitTest.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java @@ -2,8 +2,6 @@ package com.baeldung.methodsecurity; import static org.junit.Assert.assertEquals; -import org.baeldung.methodsecurity.entity.CustomUser; -import org.baeldung.methodsecurity.service.UserRoleService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -14,15 +12,18 @@ import org.springframework.security.test.context.support.WithUserDetails; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; +import com.baeldung.methodsecurity.entity.CustomUser; +import com.baeldung.methodsecurity.service.UserRoleService; + @RunWith(SpringRunner.class) @ContextConfiguration -public class TestWithUserDetailsUnitTest { +public class UserDetailsIntegrationTest { @Autowired UserRoleService userService; @Configuration - @ComponentScan("org.baeldung.methodsecurity.*") + @ComponentScan("com.baeldung.methodsecurity.*") public static class SpringConfig { } diff --git a/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java b/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java index 32d3a9ed74..6bcb2e8f0f 100644 --- a/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java +++ b/spring-security-core/src/test/java/com/baeldung/test/LiveTest.java @@ -5,7 +5,6 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.baeldung.app.App; import org.junit.Before; import org.junit.FixMethodOrder; import org.junit.Test; @@ -20,6 +19,8 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import com.baeldung.app.App; + @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @FixMethodOrder(MethodSorters.NAME_ASCENDING) From 2796491d849765cef65fc4384b9e421e3926227c Mon Sep 17 00:00:00 2001 From: Gang Date: Sun, 25 Aug 2019 11:13:21 -0600 Subject: [PATCH 07/13] Add @Test annotation --- .../baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java index 05a01ba97d..d82b1349d8 100644 --- a/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java +++ b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java @@ -19,6 +19,7 @@ public class CheckedUncheckedExceptionsUnitTest { }); } + @Test public void whenTryCatchExcetpion_thenSuccess() { try { CheckedUncheckedExceptions.checkedExceptionWithTryCatch(); From 67d82a7e6d551de08d429bce5780a62f449c7f2c Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Aug 2019 23:29:19 +0530 Subject: [PATCH 08/13] [BAEL-7387] - Fix integration tests for spring-5-mvc module --- spring-5-mvc/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-5-mvc/pom.xml b/spring-5-mvc/pom.xml index 9569d52abf..be21db481a 100644 --- a/spring-5-mvc/pom.xml +++ b/spring-5-mvc/pom.xml @@ -86,6 +86,11 @@ javafaker 0.18 + + org.apache.httpcomponents + httpclient + ${httpclient.version} + @@ -167,5 +172,6 @@ 2.9.0 1.1.2 com.baeldung.Spring5Application + 4.5.8 From bcbff2712968204ec347ebbe9fbf2a81b87e7ed1 Mon Sep 17 00:00:00 2001 From: Anshul Bansal Date: Sun, 25 Aug 2019 21:22:38 +0300 Subject: [PATCH 09/13] BAEL-2846 - JDIExample renamed to JDIExampleDebuggee (#7636) --- .../baeldung/jdi/{JDIExample.java => JDIExampleDebuggee.java} | 2 +- java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebugger.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename java-jdi/src/main/java/com/baeldung/jdi/{JDIExample.java => JDIExampleDebuggee.java} (92%) diff --git a/java-jdi/src/main/java/com/baeldung/jdi/JDIExample.java b/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebuggee.java similarity index 92% rename from java-jdi/src/main/java/com/baeldung/jdi/JDIExample.java rename to java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebuggee.java index f8f20553b8..4fb49024fb 100644 --- a/java-jdi/src/main/java/com/baeldung/jdi/JDIExample.java +++ b/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebuggee.java @@ -1,6 +1,6 @@ package com.baeldung.jdi; -public class JDIExample { +public class JDIExampleDebuggee { public static void main(String[] args) { String jpda = "Java Platform Debugger Architecture"; diff --git a/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebugger.java b/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebugger.java index 1d9de57ddb..41a568e55f 100644 --- a/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebugger.java +++ b/java-jdi/src/main/java/com/baeldung/jdi/JDIExampleDebugger.java @@ -123,7 +123,7 @@ public class JDIExampleDebugger { public static void main(String[] args) throws Exception { JDIExampleDebugger debuggerInstance = new JDIExampleDebugger(); - debuggerInstance.setDebugClass(JDIExample.class); + debuggerInstance.setDebugClass(JDIExampleDebuggee.class); int[] breakPoints = {6, 9}; debuggerInstance.setBreakPointLines(breakPoints); VirtualMachine vm = null; From 7e18a82d1b09bc11962333ccf5f7d078434d4658 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Tue, 27 Aug 2019 06:43:00 +0530 Subject: [PATCH 10/13] BAEL-16906 Slice 6 | The top 100 articles should have their own package in the module (#7652) -Moved packages --- .../ExamplePostController.java | 5 ++--- .../{transfer => requestresponsebody}/LoginForm.java | 2 +- .../{transfer => requestresponsebody}/ResponseTransfer.java | 2 +- .../src/main/java/com/baeldung/services/ExampleService.java | 3 ++- .../ExamplePostControllerRequestIntegrationTest.java | 4 ++-- .../ExamplePostControllerResponseIntegrationTest.java | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) rename spring-boot-rest/src/main/java/com/baeldung/{web/controller => requestresponsebody}/ExamplePostController.java (91%) rename spring-boot-rest/src/main/java/com/baeldung/{transfer => requestresponsebody}/LoginForm.java (93%) rename spring-boot-rest/src/main/java/com/baeldung/{transfer => requestresponsebody}/ResponseTransfer.java (86%) diff --git a/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ExamplePostController.java similarity index 91% rename from spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java rename to spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ExamplePostController.java index 1519d95d4d..90211b11a3 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/web/controller/ExamplePostController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ExamplePostController.java @@ -1,7 +1,7 @@ -package com.baeldung.web.controller; +package com.baeldung.requestresponsebody; import com.baeldung.services.ExampleService; -import com.baeldung.transfer.ResponseTransfer; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -10,7 +10,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import com.baeldung.transfer.LoginForm; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/LoginForm.java similarity index 93% rename from spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java rename to spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/LoginForm.java index caafcdb500..36c7946918 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/transfer/LoginForm.java +++ b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/LoginForm.java @@ -1,4 +1,4 @@ -package com.baeldung.transfer; +package com.baeldung.requestresponsebody; public class LoginForm { private String username; diff --git a/spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ResponseTransfer.java similarity index 86% rename from spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java rename to spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ResponseTransfer.java index d4fb282c1b..60fc698792 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/transfer/ResponseTransfer.java +++ b/spring-boot-rest/src/main/java/com/baeldung/requestresponsebody/ResponseTransfer.java @@ -1,4 +1,4 @@ -package com.baeldung.transfer; +package com.baeldung.requestresponsebody; public class ResponseTransfer { diff --git a/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java b/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java index 48d98b41db..f2734ffa39 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/ExampleService.java @@ -1,8 +1,9 @@ package com.baeldung.services; -import com.baeldung.transfer.LoginForm; import org.springframework.stereotype.Service; +import com.baeldung.requestresponsebody.LoginForm; + @Service public class ExampleService { diff --git a/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java index fc533072c8..a277d5a685 100644 --- a/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerRequestIntegrationTest.java @@ -17,9 +17,9 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import com.baeldung.SpringBootRestApplication; +import com.baeldung.requestresponsebody.ExamplePostController; +import com.baeldung.requestresponsebody.LoginForm; import com.baeldung.services.ExampleService; -import com.baeldung.transfer.LoginForm; -import com.baeldung.web.controller.ExamplePostController; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringBootRestApplication.class) diff --git a/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java index cbe21b1d90..f8c70b0f4a 100644 --- a/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java +++ b/spring-boot-rest/src/test/java/com/baeldung/controllers/ExamplePostControllerResponseIntegrationTest.java @@ -18,9 +18,9 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import com.baeldung.SpringBootRestApplication; +import com.baeldung.requestresponsebody.ExamplePostController; +import com.baeldung.requestresponsebody.LoginForm; import com.baeldung.services.ExampleService; -import com.baeldung.transfer.LoginForm; -import com.baeldung.web.controller.ExamplePostController; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringBootRestApplication.class) From bfba59a42f97aa5b34eb0eedbd2a7b57f390bbba Mon Sep 17 00:00:00 2001 From: Sam Millington Date: Tue, 27 Aug 2019 02:16:44 +0100 Subject: [PATCH 11/13] =?UTF-8?q?Moved=20the=20benchmarks=20class,=20updat?= =?UTF-8?q?ed=20README=20with=20instructions,=20updated=E2=80=A6=20(#7650)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Moved the benchmarks class, updated README with instructions, updated pom with build instructions for easy benchmark running * updated README, changed wrong benchmarks.java to *.jar --- performance-tests/README.md | 7 + performance-tests/pom.xml | 171 ++++++++++++++---- .../MappingFrameworksPerformance.java | 0 3 files changed, 146 insertions(+), 32 deletions(-) rename performance-tests/src/{test/java/com/baeldung/performancetests/benchmark => main/java/com/baeldung/performancetests}/MappingFrameworksPerformance.java (100%) diff --git a/performance-tests/README.md b/performance-tests/README.md index 5af735b708..0064157966 100644 --- a/performance-tests/README.md +++ b/performance-tests/README.md @@ -1,3 +1,10 @@ ### Relevant Articles: - [Performance of Java Mapping Frameworks](http://www.baeldung.com/java-performance-mapping-frameworks) + +### Running + + To run the performance benchmarks: + +1: `mvn clean install` +2: `java -jar target/benchmarks.jar` \ No newline at end of file diff --git a/performance-tests/pom.xml b/performance-tests/pom.xml index d7738780bf..956c0ccfa8 100644 --- a/performance-tests/pom.xml +++ b/performance-tests/pom.xml @@ -1,17 +1,20 @@ - - 4.0.0 + + com.baeldung performance-tests - performance-tests - + 1.0 + jar + parent-modules com.baeldung 1.0.0-SNAPSHOT + performance-tests + ma.glasnost.orika @@ -32,7 +35,16 @@ org.mapstruct mapstruct-jdk8 ${mapstruct-jdk8.version} + true + + + org.mapstruct + mapstruct-processor + 1.2.0.Final + provided + + org.modelmapper modelmapper @@ -46,46 +58,141 @@ org.openjdk.jmh jmh-core - ${jmh-core.version} + ${jmh.version} org.openjdk.jmh jmh-generator-annprocess - ${jmh-generator.version} + ${jmh.version} + provided - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - ${java.version} - ${java.version} - - - org.mapstruct - mapstruct-processor - ${mapstruct-processor.version} - - - - - - - - + + UTF-8 + + + 1.21 1.5.2 5.5.1 1.0.2 1.2.0.Final 1.1.0 1.6.0.1 + 1.8 1.2.0.Final + 1.21 + 1.21 + 3.7.0 + + + 1.8 + + + benchmarks - \ No newline at end of file + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + ${javac.target} + ${javac.target} + ${javac.target} + + + org.mapstruct + mapstruct-processor + ${mapstruct-processor.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + 2.2 + + + package + + shade + + + ${uberjar.name} + + + org.openjdk.jmh.Main + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + + + + + maven-clean-plugin + 2.5 + + + maven-deploy-plugin + 2.8.1 + + + maven-install-plugin + 2.5.1 + + + maven-jar-plugin + 2.4 + + + maven-javadoc-plugin + 2.9.1 + + + maven-resources-plugin + 2.6 + + + maven-site-plugin + 3.3 + + + maven-source-plugin + 2.2.1 + + + maven-surefire-plugin + 2.17 + + + + + + diff --git a/performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java b/performance-tests/src/main/java/com/baeldung/performancetests/MappingFrameworksPerformance.java similarity index 100% rename from performance-tests/src/test/java/com/baeldung/performancetests/benchmark/MappingFrameworksPerformance.java rename to performance-tests/src/main/java/com/baeldung/performancetests/MappingFrameworksPerformance.java From 0216c364b0bddb717c054ab7d0ff61b1aaf032e9 Mon Sep 17 00:00:00 2001 From: Fabio Silva Date: Tue, 27 Aug 2019 12:33:06 -0300 Subject: [PATCH 12/13] Add a Header to a Jersey SSE Client Request (#7662) * Add a Header to a Jersey SSE Client Request (cherry picked from commit ee70714e7885cf8713e9c2698a8a8d93fb6a53c8) * Class and Methods rename --- jersey/pom.xml | 17 +- .../jersey/client/JerseyClientHeaders.java | 189 +++++++++++++++++ .../filter/AddHeaderOnRequestFilter.java | 16 ++ .../baeldung/jersey/server/EchoHeaders.java | 72 +++++++ .../jersey/server/EchoHeadersUnitTest.java | 197 ++++++++++++++++++ 5 files changed, 490 insertions(+), 1 deletion(-) create mode 100644 jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java create mode 100644 jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java create mode 100644 jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java create mode 100644 jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java diff --git a/jersey/pom.xml b/jersey/pom.xml index 708b36ce41..0b4d469e3a 100644 --- a/jersey/pom.xml +++ b/jersey/pom.xml @@ -32,7 +32,7 @@ org.glassfish.jersey.containers jersey-container-grizzly2-servlet - ${jersey.version} + ${jersey.version} org.glassfish.jersey.ext @@ -44,6 +44,21 @@ jersey-bean-validation ${jersey.version} + + org.glassfish.jersey.security + oauth1-client + ${jersey.version} + + + org.glassfish.jersey.security + oauth2-client + ${jersey.version} + + + org.glassfish.jersey.media + jersey-media-sse + ${jersey.version} + org.glassfish.jersey.test-framework jersey-test-framework-core diff --git a/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java new file mode 100644 index 0000000000..ebcbe1d4ab --- /dev/null +++ b/jersey/src/main/java/com/baeldung/jersey/client/JerseyClientHeaders.java @@ -0,0 +1,189 @@ +package com.baeldung.jersey.client; + +import com.baeldung.jersey.client.filter.AddHeaderOnRequestFilter; +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; +import org.glassfish.jersey.client.oauth1.AccessToken; +import org.glassfish.jersey.client.oauth1.ConsumerCredentials; +import org.glassfish.jersey.client.oauth1.OAuth1ClientSupport; +import org.glassfish.jersey.client.oauth2.OAuth2ClientSupport; + +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Feature; +import javax.ws.rs.core.Response; +import javax.ws.rs.sse.InboundSseEvent; +import javax.ws.rs.sse.SseEventSource; + +import static org.glassfish.jersey.client.authentication.HttpAuthenticationFeature.*; + +public class JerseyClientHeaders { + + private static final String BEARER_CONSUMER_SECRET = "my-consumer-secret"; + private static final String BEARER_ACCESS_TOKEN_SECRET = "my-access-token-secret"; + private static final String TARGET = "http://localhost:9998/"; + private static final String MAIN_RESOURCE = "echo-headers"; + private static final String RESOURCE_AUTH_DIGEST = "digest"; + + private static String sseHeaderValue; + + public static Response simpleHeader(String headerKey, String headerValue) { + Client client = ClientBuilder.newClient(); + WebTarget webTarget = client.target(TARGET); + WebTarget resourceWebTarget = webTarget.path(MAIN_RESOURCE); + Invocation.Builder invocationBuilder = resourceWebTarget.request(); + invocationBuilder.header(headerKey, headerValue); + return invocationBuilder.get(); + } + + public static Response simpleHeaderFluently(String headerKey, String headerValue) { + Client client = ClientBuilder.newClient(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .header(headerKey, headerValue) + .get(); + } + + public static Response basicAuthenticationAtClientLevel(String username, String password) { + //To simplify we removed de SSL/TLS protection, but it's required to have an encryption + // when using basic authentication schema as it's send only on Base64 encoding + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic(username, password); + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .get(); + } + + public static Response basicAuthenticationAtRequestLevel(String username, String password) { + //To simplify we removed de SSL/TLS protection, but it's required to have an encryption + // when using basic authentication schema as it's send only on Base64 encoding + HttpAuthenticationFeature feature = HttpAuthenticationFeature.basicBuilder().build(); + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .property(HTTP_AUTHENTICATION_BASIC_USERNAME, username) + .property(HTTP_AUTHENTICATION_BASIC_PASSWORD, password) + .get(); + } + + public static Response digestAuthenticationAtClientLevel(String username, String password) { + HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest(username, password); + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .path(RESOURCE_AUTH_DIGEST) + .request() + .get(); + } + + public static Response digestAuthenticationAtRequestLevel(String username, String password) { + HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest(); + + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .path(RESOURCE_AUTH_DIGEST) + .request() + .property(HTTP_AUTHENTICATION_DIGEST_USERNAME, username) + .property(HTTP_AUTHENTICATION_DIGEST_PASSWORD, password) + .get(); + } + + public static Response bearerAuthenticationWithOAuth1AtClientLevel(String token, String consumerKey) { + ConsumerCredentials consumerCredential = new ConsumerCredentials(consumerKey, BEARER_CONSUMER_SECRET); + AccessToken accessToken = new AccessToken(token, BEARER_ACCESS_TOKEN_SECRET); + Feature feature = OAuth1ClientSupport + .builder(consumerCredential) + .feature() + .accessToken(accessToken) + .build(); + + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .get(); + } + + public static Response bearerAuthenticationWithOAuth1AtRequestLevel(String token, String consumerKey) { + ConsumerCredentials consumerCredential = new ConsumerCredentials(consumerKey, BEARER_CONSUMER_SECRET); + AccessToken accessToken = new AccessToken(token, BEARER_ACCESS_TOKEN_SECRET); + Feature feature = OAuth1ClientSupport + .builder(consumerCredential) + .feature() + .build(); + + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .property(OAuth1ClientSupport.OAUTH_PROPERTY_ACCESS_TOKEN, accessToken) + .get(); + } + + public static Response bearerAuthenticationWithOAuth2AtClientLevel(String token) { + Feature feature = OAuth2ClientSupport.feature(token); + + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .get(); + } + + public static Response bearerAuthenticationWithOAuth2AtRequestLevel(String token, String otherToken) { + Feature feature = OAuth2ClientSupport.feature(token); + + Client client = ClientBuilder.newBuilder().register(feature).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .property(OAuth2ClientSupport.OAUTH2_PROPERTY_ACCESS_TOKEN, otherToken) + .get(); + } + + public static Response filter() { + Client client = ClientBuilder.newBuilder().register(AddHeaderOnRequestFilter.class).build(); + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .get(); + } + + public static Response sendRestrictedHeaderThroughDefaultTransportConnector(String headerKey, String headerValue) { + Client client = ClientBuilder.newClient(); + System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + + return client.target(TARGET) + .path(MAIN_RESOURCE) + .request() + .header(headerKey, headerValue) + .get(); + } + + public static String simpleSSEHeader() throws InterruptedException { + Client client = ClientBuilder.newBuilder() + .register(AddHeaderOnRequestFilter.class) + .build(); + + WebTarget webTarget = client.target(TARGET) + .path(MAIN_RESOURCE) + .path("events"); + + SseEventSource sseEventSource = SseEventSource.target(webTarget).build(); + sseEventSource.register(JerseyClientHeaders::receiveEvent); + sseEventSource.open(); + Thread.sleep(3_000); + sseEventSource.close(); + + return sseHeaderValue; + } + + private static void receiveEvent(InboundSseEvent event) { + sseHeaderValue = event.readData(); + } +} diff --git a/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java b/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java new file mode 100644 index 0000000000..a874928c16 --- /dev/null +++ b/jersey/src/main/java/com/baeldung/jersey/client/filter/AddHeaderOnRequestFilter.java @@ -0,0 +1,16 @@ +package com.baeldung.jersey.client.filter; + +import javax.ws.rs.client.ClientRequestContext; +import javax.ws.rs.client.ClientRequestFilter; +import java.io.IOException; + +public class AddHeaderOnRequestFilter implements ClientRequestFilter { + + public static final String FILTER_HEADER_VALUE = "filter-header-value"; + public static final String FILTER_HEADER_KEY = "x-filter-header"; + + @Override + public void filter(ClientRequestContext requestContext) throws IOException { + requestContext.getHeaders().add(FILTER_HEADER_KEY, FILTER_HEADER_VALUE); + } +} diff --git a/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java b/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java new file mode 100644 index 0000000000..a8df3c10a8 --- /dev/null +++ b/jersey/src/main/java/com/baeldung/jersey/server/EchoHeaders.java @@ -0,0 +1,72 @@ +package com.baeldung.jersey.server; + +import com.baeldung.jersey.client.filter.AddHeaderOnRequestFilter; + +import javax.annotation.security.RolesAllowed; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.*; +import javax.ws.rs.sse.OutboundSseEvent; +import javax.ws.rs.sse.Sse; +import javax.ws.rs.sse.SseEventSink; + +@Path("/echo-headers") +public class EchoHeaders { + + static final String REALM_KEY = "realm"; + static final String REALM_VALUE = "Baeldung"; + static final String QOP_KEY = "qop"; + static final String QOP_VALUE = "auth"; + static final String NONCE_KEY = "nonce"; + static final String NONCE_VALUE = "dcd98b7102dd2f0e8b11d0f600bfb0c093"; + static final String OPAQUE_KEY = "opaque"; + static final String OPAQUE_VALUE = "5ccc069c403ebaf9f0171e9517f40e41"; + static final String SSE_HEADER_KEY = "x-sse-header-key"; + + @Context + HttpHeaders headers; + + @GET + public Response getHeadersBack() { + return echoHeaders(); + } + + @RolesAllowed("ADMIN") + @GET + @Path("/digest") + public Response getHeadersBackFromDigestAuthentication() { + // As the Digest authentication require some complex steps to work we'll simulate the process + // https://en.wikipedia.org/wiki/Digest_access_authentication#Example_with_explanation + if (headers.getHeaderString("authorization") == null) { + String authenticationRequired = "Digest " + REALM_KEY + "=\"" + REALM_VALUE + "\", " + QOP_KEY + "=\"" + QOP_VALUE + "\", " + NONCE_KEY + "=\"" + NONCE_VALUE + "\", " + OPAQUE_KEY + "=\"" + OPAQUE_VALUE + "\""; + return Response.status(Response.Status.UNAUTHORIZED) + .header("WWW-Authenticate", authenticationRequired) + .build(); + } else { + return echoHeaders(); + } + } + + @GET + @Path("/events") + @Produces(MediaType.SERVER_SENT_EVENTS) + public void getServerSentEvents(@Context SseEventSink eventSink, @Context Sse sse) { + OutboundSseEvent event = sse.newEventBuilder() + .name("echo-headers") + .data(String.class, headers.getHeaderString(AddHeaderOnRequestFilter.FILTER_HEADER_KEY)) + .build(); + eventSink.send(event); + } + + private Response echoHeaders() { + Response.ResponseBuilder responseBuilder = Response.noContent(); + + headers.getRequestHeaders() + .forEach((k, v) -> { + v.forEach(value -> responseBuilder.header(k, value)); + }); + + return responseBuilder.build(); + } +} diff --git a/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java b/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java new file mode 100644 index 0000000000..ac2cc2c4eb --- /dev/null +++ b/jersey/src/test/java/com/baeldung/jersey/server/EchoHeadersUnitTest.java @@ -0,0 +1,197 @@ +package com.baeldung.jersey.server; + +import com.baeldung.jersey.client.JerseyClientHeaders; +import com.baeldung.jersey.client.filter.AddHeaderOnRequestFilter; +import org.glassfish.jersey.media.sse.SseFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.junit.Test; + +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import java.util.Base64; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +public class EchoHeadersUnitTest extends JerseyTest { + + private static final String SIMPLE_HEADER_KEY = "my-header-key"; + private static final String SIMPLE_HEADER_VALUE = "my-header-value"; + private static final String USERNAME = "baeldung"; + private static final String PASSWORD = "super-secret"; + private static final String AUTHORIZATION_HEADER_KEY = "authorization"; + private static final String BEARER_TOKEN_VALUE = "my-token"; + private static final String BEARER_CONSUMER_KEY_VALUE = "my-consumer-key"; + private static final String BEARER_REQUEST_TOKEN_VALUE = "my-request-token"; + + @Test + public void whenCallingSimpleHeader_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.simpleHeader(SIMPLE_HEADER_KEY, SIMPLE_HEADER_VALUE); + + assertEquals(response.getHeaderString(SIMPLE_HEADER_KEY), SIMPLE_HEADER_VALUE); + } + + @Test + public void whenCallingSimpleHeaderFluently_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.simpleHeaderFluently(SIMPLE_HEADER_KEY, SIMPLE_HEADER_VALUE); + + assertEquals(response.getHeaderString(SIMPLE_HEADER_KEY), SIMPLE_HEADER_VALUE); + } + + @Test + public void whenCallingBasicAuthenticationAtClientLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.basicAuthenticationAtClientLevel(USERNAME, PASSWORD); + + assertBasicAuthenticationHeaders(response); + } + + @Test + public void whenCallingBasicAuthenticationAtRequestLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.basicAuthenticationAtRequestLevel(USERNAME, PASSWORD); + + assertBasicAuthenticationHeaders(response); + } + + @Test + public void whenCallingDigestAuthenticationAtClientLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.digestAuthenticationAtClientLevel(USERNAME, PASSWORD); + + Map subHeadersMap = parseAuthenticationSubHeader(response, 7); + + assertDigestAuthenticationHeaders(subHeadersMap); + } + + @Test + public void whenCallingDigestAuthenticationAtRequestLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.digestAuthenticationAtRequestLevel(USERNAME, PASSWORD); + + Map subHeadersMap = parseAuthenticationSubHeader(response, 7); + + assertDigestAuthenticationHeaders(subHeadersMap); + } + + @Test + public void whenCallingBearerAuthenticationWithOAuth1AtClientLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.bearerAuthenticationWithOAuth1AtClientLevel(BEARER_TOKEN_VALUE, BEARER_CONSUMER_KEY_VALUE); + + Map subHeadersMap = parseAuthenticationSubHeader(response, 6); + + assertBearerAuthenticationHeaders(subHeadersMap); + } + + @Test + public void whenCallingBearerAuthenticationWithOAuth1AtRequestLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.bearerAuthenticationWithOAuth1AtRequestLevel(BEARER_TOKEN_VALUE, BEARER_CONSUMER_KEY_VALUE); + + Map subHeadersMap = parseAuthenticationSubHeader(response, 6); + + assertBearerAuthenticationHeaders(subHeadersMap); + } + + @Test + public void whenCallingBearerAuthenticationWithOAuth2AtClientLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.bearerAuthenticationWithOAuth2AtClientLevel(BEARER_TOKEN_VALUE); + + assertEquals("Bearer " + BEARER_TOKEN_VALUE, response.getHeaderString(AUTHORIZATION_HEADER_KEY)); + } + + @Test + public void whenCallingBearerAuthenticationWithOAuth2AtRequestLevel_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.bearerAuthenticationWithOAuth2AtRequestLevel(BEARER_TOKEN_VALUE, BEARER_REQUEST_TOKEN_VALUE); + + assertEquals("Bearer " + BEARER_REQUEST_TOKEN_VALUE, response.getHeaderString(AUTHORIZATION_HEADER_KEY)); + } + + @Test + public void whenCallingFilter_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.filter(); + + assertEquals(AddHeaderOnRequestFilter.FILTER_HEADER_VALUE, response.getHeaderString(AddHeaderOnRequestFilter.FILTER_HEADER_KEY)); + } + + @Test + public void whenCallingSendRestrictedHeaderThroughDefaultTransportConnector_thenHeadersReturnedBack() { + Response response = JerseyClientHeaders.sendRestrictedHeaderThroughDefaultTransportConnector("keep-alive", "keep-alive-value"); + + assertEquals("keep-alive-value", response.getHeaderString("keep-alive")); + } + + @Test + public void whenCallingSimpleSSEHeader_thenHeadersReturnedBack() throws InterruptedException { + String sseHeaderBackValue = JerseyClientHeaders.simpleSSEHeader(); + + assertEquals(AddHeaderOnRequestFilter.FILTER_HEADER_VALUE, sseHeaderBackValue); + } + + private void assertBearerAuthenticationHeaders(Map subHeadersMap) { + + assertEquals(BEARER_TOKEN_VALUE, subHeadersMap.get("oauth_token")); + assertEquals(BEARER_CONSUMER_KEY_VALUE, subHeadersMap.get("oauth_consumer_key")); + assertNotNull(subHeadersMap.get("oauth_nonce")); + assertNotNull(subHeadersMap.get("oauth_signature")); + assertNotNull(subHeadersMap.get("oauth_callback")); + assertNotNull(subHeadersMap.get("oauth_signature_method")); + assertNotNull(subHeadersMap.get("oauth_version")); + assertNotNull(subHeadersMap.get("oauth_timestamp")); + } + + private void assertDigestAuthenticationHeaders(Map subHeadersMap) { + assertEquals(EchoHeaders.NONCE_VALUE, subHeadersMap.get(EchoHeaders.NONCE_KEY)); + assertEquals(EchoHeaders.OPAQUE_VALUE, subHeadersMap.get(EchoHeaders.OPAQUE_KEY)); + assertEquals(EchoHeaders.QOP_VALUE, subHeadersMap.get(EchoHeaders.QOP_KEY)); + assertEquals(EchoHeaders.REALM_VALUE, subHeadersMap.get(EchoHeaders.REALM_KEY)); + + assertEquals(USERNAME, subHeadersMap.get("username")); + assertEquals("/echo-headers/digest", subHeadersMap.get("uri")); + assertNotNull(subHeadersMap.get("cnonce")); + assertEquals("00000001", subHeadersMap.get("nc")); + assertNotNull(subHeadersMap.get("response")); + } + + private Map parseAuthenticationSubHeader(Response response, int startAt) { + String authorizationHeader = response.getHeaderString(AUTHORIZATION_HEADER_KEY); + // The substring(startAt) is used to cut off the authentication schema part from the value returned. + String[] subHeadersKeyValue = authorizationHeader.substring(startAt).split(","); + Map subHeadersMap = new HashMap<>(); + + for (String subHeader : subHeadersKeyValue) { + String[] keyValue = subHeader.split("="); + + if (keyValue[1].startsWith("\"")) { + keyValue[1] = keyValue[1].substring(1, keyValue[1].length() - 1); + } + + subHeadersMap.put(keyValue[0].trim(), keyValue[1].trim()); + } + return subHeadersMap; + } + + private void assertBasicAuthenticationHeaders(Response response) { + String base64Credentials = response.getHeaderString(AUTHORIZATION_HEADER_KEY); + // The substring(6) is used to cut the "Basic " part of the value returned, + // as it's used to indicates the authentication schema and does not belong to the credentials + byte[] credentials = Base64.getDecoder().decode(base64Credentials.substring(6)); + String[] credentialsParsed = new String(credentials).split(":"); + + assertEquals(credentialsParsed[0], USERNAME); + assertEquals(credentialsParsed[1], PASSWORD); + } + + @Override + protected Application configure() { + return new ResourceConfig() + .register(EchoHeaders.class); + } + + @Override + public void setUp() throws Exception { + super.setUp(); + // We need this definition here, because if you are running + // the complete suit test the sendingRestrictedHeaderThroughDefaultTransportConnector_shouldReturnThanBack + // will fail if only defined on the client method, since the JerseyTest is created once. + System.setProperty("sun.net.http.allowRestrictedHeaders", "true"); + } +} \ No newline at end of file From 9d825c429e462ad15182910b20a7a705c6c86007 Mon Sep 17 00:00:00 2001 From: Kumar Chandrakant Date: Wed, 28 Aug 2019 10:25:04 +0530 Subject: [PATCH 13/13] Adding source code for the article tracked under BAEL-3232. (#7657) --- java-blockchain/.gitignore | 26 +++++++ java-blockchain/README.md | 6 ++ java-blockchain/pom.xml | 40 +++++++++++ .../java/com/baeldung/blockchain/Block.java | 65 ++++++++++++++++++ .../src/main/resources/logback.xml | 13 ++++ .../blockchain/BlockchainUnitTest.java | 67 +++++++++++++++++++ java-blockchain/src/test/resources/.gitignore | 13 ++++ pom.xml | 2 + 8 files changed, 232 insertions(+) create mode 100644 java-blockchain/.gitignore create mode 100644 java-blockchain/README.md create mode 100644 java-blockchain/pom.xml create mode 100644 java-blockchain/src/main/java/com/baeldung/blockchain/Block.java create mode 100644 java-blockchain/src/main/resources/logback.xml create mode 100644 java-blockchain/src/test/java/com/baeldung/blockchain/BlockchainUnitTest.java create mode 100644 java-blockchain/src/test/resources/.gitignore diff --git a/java-blockchain/.gitignore b/java-blockchain/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/java-blockchain/.gitignore @@ -0,0 +1,26 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/java-blockchain/README.md b/java-blockchain/README.md new file mode 100644 index 0000000000..600f4dd610 --- /dev/null +++ b/java-blockchain/README.md @@ -0,0 +1,6 @@ +========= + +## Basic Implementation of Blockchian in Java + +### Relevant Articles: +- []() diff --git a/java-blockchain/pom.xml b/java-blockchain/pom.xml new file mode 100644 index 0000000000..2f9e011aa7 --- /dev/null +++ b/java-blockchain/pom.xml @@ -0,0 +1,40 @@ + + 4.0.0 + com.baeldung.blockchain + java-blockchain + 0.1.0-SNAPSHOT + java-blockchain + jar + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + java-blockchain + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + 1.8 + 1.8 + + \ No newline at end of file diff --git a/java-blockchain/src/main/java/com/baeldung/blockchain/Block.java b/java-blockchain/src/main/java/com/baeldung/blockchain/Block.java new file mode 100644 index 0000000000..264e3c4b69 --- /dev/null +++ b/java-blockchain/src/main/java/com/baeldung/blockchain/Block.java @@ -0,0 +1,65 @@ +package com.baeldung.blockchain; + +import java.io.UnsupportedEncodingException; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.logging.Level; +import java.util.logging.Logger; + +public class Block { + + private static Logger logger = Logger.getLogger(Block.class.getName()); + + private String hash; + private String previousHash; + private String data; + private long timeStamp; + private int nonce; + + public Block(String data, String previousHash) { + this.data = data; + this.previousHash = previousHash; + this.timeStamp = new Date().getTime(); + this.hash = calculateBlockHash(); + } + + public String mineBlock(int prefix) { + String prefixString = new String(new char[prefix]).replace('\0', '0'); + while (!hash.substring(0, prefix) + .equals(prefixString)) { + nonce++; + hash = calculateBlockHash(); + } + return hash; + } + + public String calculateBlockHash() { + String dataToHash = previousHash + Long.toString(timeStamp) + Integer.toString(nonce) + data; + MessageDigest digest = null; + byte[] bytes = null; + try { + digest = MessageDigest.getInstance("SHA-256"); + bytes = digest.digest(dataToHash.getBytes("UTF-8")); + } catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) { + logger.log(Level.SEVERE, ex.getMessage()); + } + StringBuffer buffer = new StringBuffer(); + for (byte b : bytes) { + buffer.append(String.format("%02x", b)); + } + return buffer.toString(); + } + + public String getHash() { + return this.hash; + } + + public String getPreviousHash() { + return this.previousHash; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/java-blockchain/src/main/resources/logback.xml b/java-blockchain/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/java-blockchain/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/java-blockchain/src/test/java/com/baeldung/blockchain/BlockchainUnitTest.java b/java-blockchain/src/test/java/com/baeldung/blockchain/BlockchainUnitTest.java new file mode 100644 index 0000000000..acbf651e78 --- /dev/null +++ b/java-blockchain/src/test/java/com/baeldung/blockchain/BlockchainUnitTest.java @@ -0,0 +1,67 @@ +package com.baeldung.blockchain; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class BlockchainUnitTest { + + public static List blockchain = new ArrayList(); + public static int prefix = 4; + public static String prefixString = new String(new char[prefix]).replace('\0', '0'); + + @BeforeClass + public static void setUp() { + Block genesisBlock = new Block("The is the Genesis Block.", "0"); + genesisBlock.mineBlock(prefix); + blockchain.add(genesisBlock); + Block firstBlock = new Block("The is the First Block.", genesisBlock.getHash()); + firstBlock.mineBlock(prefix); + blockchain.add(firstBlock); + } + + @Test + public void givenBlockchain_whenNewBlockAdded_thenSuccess() { + Block newBlock = new Block("The is a New Block.", blockchain.get(blockchain.size() - 1) + .getHash()); + newBlock.mineBlock(prefix); + assertTrue(newBlock.getHash() + .substring(0, prefix) + .equals(prefixString)); + blockchain.add(newBlock); + } + + @Test + public void givenBlockchain_whenValidated_thenSuccess() { + boolean flag = true; + for (int i = 0; i < blockchain.size(); i++) { + String previousHash = i == 0 ? "0" + : blockchain.get(i - 1) + .getHash(); + flag = blockchain.get(i) + .getHash() + .equals(blockchain.get(i) + .calculateBlockHash()) + && previousHash.equals(blockchain.get(i) + .getPreviousHash()) + && blockchain.get(i) + .getHash() + .substring(0, prefix) + .equals(prefixString); + if (!flag) + break; + } + assertTrue(flag); + } + + @AfterClass + public static void tearDown() { + blockchain.clear(); + } + +} diff --git a/java-blockchain/src/test/resources/.gitignore b/java-blockchain/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/java-blockchain/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/pom.xml b/pom.xml index a4f2a13c28..1dbc3647b5 100644 --- a/pom.xml +++ b/pom.xml @@ -566,6 +566,7 @@ oauth2-framework-impl spring-boot-nashorn + java-blockchain @@ -802,6 +803,7 @@ spring-security-kerberos spring-boot-nashorn + java-blockchain