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..d82b1349d8 --- /dev/null +++ b/core-java-modules/core-java-exceptions/src/test/java/com/baeldung/exceptions/CheckedUncheckedExceptionsUnitTest.java @@ -0,0 +1,55 @@ +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(); + }); + } + + @Test + 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(""); + }); + } +} 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 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/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; 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()); + } + +} 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 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 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 c44ea80ed4..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdt and /dev/null differ 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 77b3c43c21..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fdx and /dev/null differ 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 6a5f78d0a0..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.fnm and /dev/null differ 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 7644ffa79b..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvd and /dev/null differ 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 b2eb2c7a52..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.nvm and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.si b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.si deleted file mode 100644 index 67b02ea9fd..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.si and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvd b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvd deleted file mode 100644 index b43b83f86a..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvd and /dev/null differ 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 6b97c002b3..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6.tvx and /dev/null differ 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 f86ebad3d1..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.doc and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.pos b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.pos deleted file mode 100644 index 6299098895..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.pos and /dev/null differ 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 3f8b1e4ab0..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tim and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tip b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tip deleted file mode 100644 index 996b9bae87..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_6_Lucene50_0.tip and /dev/null differ 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 d1359e482e..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfe and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfs b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfs deleted file mode 100644 index 476949c900..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.cfs and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.si b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.si deleted file mode 100644 index f85f471dbd..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/_7.si and /dev/null differ diff --git a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/segments_9 b/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/segments_9 deleted file mode 100644 index 555f95a4ee..0000000000 Binary files a/persistence-modules/spring-hibernate-5/com.baeldung.hibernatesearch.model.Product/segments_9 and /dev/null differ 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 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 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 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) 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/org/baeldung/SpringContextIntegrationTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 87% 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..1cdff1342c 100644 --- a/spring-security-core/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -1,11 +1,12 @@ -package org.baeldung; +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/org/baeldung/SpringContextTest.java b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java similarity index 87% 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..bca6450fb1 100644 --- a/spring-security-core/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-core/src/test/java/com/baeldung/SpringContextTest.java @@ -1,11 +1,12 @@ -package org.baeldung; +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/org/baeldung/methodsecurity/TestClassLevelSecurity.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java similarity index 85% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java index 502fd50c46..943bfda72c 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestClassLevelSecurity.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/ClassLevelSecurityIntegrationTest.java @@ -1,8 +1,7 @@ -package org.baeldung.methodsecurity; +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 TestClassLevelSecurity { +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/org/baeldung/methodsecurity/TestMethodSecurity.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.java similarity index 94% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.java index 009d9af9fc..81b150f43e 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestMethodSecurity.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MethodSecurityIntegrationTest.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; @@ -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 TestMethodSecurity { +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/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java similarity index 79% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java index 4df1af8ca9..fead89f75a 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithMockUserAtClassLevel.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/MockUserAtClassLevelIntegrationTest.java @@ -1,8 +1,7 @@ -package org.baeldung.methodsecurity; +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 TestWithMockUserAtClassLevel { +public class MockUserAtClassLevelIntegrationTest { @Test public void givenRoleViewer_whenCallGetUsername_thenReturnUsername() { @@ -27,7 +28,7 @@ public class TestWithMockUserAtClassLevel { UserRoleService userService; @Configuration - @ComponentScan("org.baeldung.methodsecurity.*") + @ComponentScan("com.baeldung.methodsecurity.*") public static class SpringConfig { } diff --git a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java b/spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java similarity index 86% rename from spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java rename to spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java index 3ef5996554..d43a26a5ff 100644 --- a/spring-security-core/src/test/java/org/baeldung/methodsecurity/TestWithUserDetails.java +++ b/spring-security-core/src/test/java/com/baeldung/methodsecurity/UserDetailsIntegrationTest.java @@ -1,9 +1,7 @@ -package org.baeldung.methodsecurity; +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 TestWithUserDetails { +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/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 98% 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..6bcb2e8f0f 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,11 +1,10 @@ -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; 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)