Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
7da495a37a
|
@ -10,7 +10,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
|
||||||
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
|
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
|
||||||
- [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack)
|
- [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack)
|
||||||
- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
|
- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
|
||||||
- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher)
|
|
||||||
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
|
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
|
||||||
- [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm)
|
- [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm)
|
||||||
- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray)
|
- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
### Relevant Articles
|
|
||||||
|
|
||||||
- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
|
|
@ -1,5 +0,0 @@
|
||||||
## Apache FOP
|
|
||||||
|
|
||||||
This module contains articles about Apache FOP
|
|
||||||
|
|
||||||
### Relevant Articles:
|
|
|
@ -1,4 +1,3 @@
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
|
|
||||||
- [OData Protocol Guide](https://www.baeldung.com/odata)
|
|
||||||
- [Intro to OData with Olingo](https://www.baeldung.com/olingo)
|
- [Intro to OData with Olingo](https://www.baeldung.com/olingo)
|
||||||
|
|
|
@ -8,4 +8,4 @@ This module contains articles about Apache POI
|
||||||
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
||||||
- [Merge Cells in Excel Using Apache POI](https://www.baeldung.com/java-apache-poi-merge-cells)
|
- [Merge Cells in Excel Using Apache POI](https://www.baeldung.com/java-apache-poi-merge-cells)
|
||||||
- [Get String Value of Excel Cell with Apache POI](https://www.baeldung.com/java-apache-poi-cell-string-value)
|
- [Get String Value of Excel Cell with Apache POI](https://www.baeldung.com/java-apache-poi-cell-string-value)
|
||||||
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://github.com/eugenp/tutorials/tree/master/apache-poi)
|
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula)
|
||||||
|
|
|
@ -5,7 +5,7 @@ spring.jpa.hibernate.ddl-auto=create
|
||||||
logging.file=azure.log
|
logging.file=azure.log
|
||||||
logging.level.root=info
|
logging.level.root=info
|
||||||
|
|
||||||
spring.datasource.url=jdbc:h2:file:~/test
|
spring.datasource.url=jdbc:h2:mem:azure-test-db
|
||||||
spring.datasource.username=sa
|
spring.datasource.username=sa
|
||||||
spring.datasource.password=
|
spring.datasource.password=
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
This module contains articles about Java 8 core features
|
This module contains articles about Java 8 core features
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Anonymous Classes in Java](https://www.baeldung.com/java-anonymous-classes)
|
|
||||||
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
|
||||||
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
|
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
|
||||||
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
|
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
|
||||||
|
|
|
@ -48,25 +48,6 @@
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<version>${spring-boot-maven-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>spring-boot</classifier>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -74,8 +55,6 @@
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<!-- plugins -->
|
|
||||||
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
## Core Java Arrays (Part 3)
|
|
||||||
|
|
||||||
This module contains articles about Java arrays
|
|
||||||
|
|
||||||
## Relevant Articles
|
|
|
@ -66,101 +66,7 @@
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>${maven-jar-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>libs/</classpathPrefix>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>${maven-shade-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.jolira</groupId>
|
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
|
||||||
<version>${onejar-maven-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
<attachToBuild>true</attachToBuild>
|
|
||||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>one-jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<version>${spring-boot-maven-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>spring-boot</classifier>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
@ -250,110 +156,6 @@
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<!-- java instrumentation profiles to build jars -->
|
|
||||||
<profile>
|
|
||||||
<id>buildAgentLoader</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>agentLoader</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/application/AgentLoader.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/Launcher.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>buildApplication</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>application</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/application/MyAtm.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/MyAtmApplication.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/Launcher.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>buildAgent</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>agent</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/agent/AtmTransformer.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/agent/MyInstrumentationAgent.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -368,10 +170,6 @@
|
||||||
|
|
||||||
<!-- maven and spring plugins -->
|
<!-- maven and spring plugins -->
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
|
||||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
|
||||||
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
|
||||||
<spring-boot-maven-plugin.version>2.0.3.RELEASE</spring-boot-maven-plugin.version>
|
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<source.version>1.8</source.version>
|
<source.version>1.8</source.version>
|
||||||
<target.version>1.8</target.version>
|
<target.version>1.8</target.version>
|
||||||
|
|
|
@ -15,7 +15,7 @@ import java.util.logging.Logger;
|
||||||
|
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
public class PrimeNumbersUnitTest {
|
public class PrimeNumbersUnitManualTest {
|
||||||
|
|
||||||
private static Logger logger = Logger.getAnonymousLogger();
|
private static Logger logger = Logger.getAnonymousLogger();
|
||||||
|
|
|
@ -11,5 +11,4 @@ This module contains articles about Java operators
|
||||||
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)
|
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)
|
||||||
- [The XOR Operator in Java](https://www.baeldung.com/java-xor-operator)
|
- [The XOR Operator in Java](https://www.baeldung.com/java-xor-operator)
|
||||||
- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators)
|
- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators)
|
||||||
- [Bitwise & vs Logical && Operators](https://www.baeldung.com/bitwise-vs-logical-operators/)
|
- [Bitwise & vs Logical && Operators](https://www.baeldung.com/java-bitwise-vs-logical-and)
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,12 @@
|
||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
<version>${jmh-core.version}</version>
|
<version>${jmh-core.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>3.15.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
package com.baeldung.replacetokens;
|
||||||
|
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class ReplacingTokens {
|
||||||
|
public static final Pattern TITLE_CASE_PATTERN = Pattern.compile("(?<=^|[^A-Za-z])([A-Z][a-z]*)(?=[^A-Za-z]|$)");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate over the title case tokens in the input and replace them with lowercase
|
||||||
|
* @param original the original string
|
||||||
|
* @return a string with words replaced with their lowercase equivalents
|
||||||
|
*/
|
||||||
|
public static String replaceTitleCaseWithLowerCase(String original) {
|
||||||
|
int lastIndex = 0;
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
Matcher matcher = TITLE_CASE_PATTERN.matcher(original);
|
||||||
|
while (matcher.find()) {
|
||||||
|
output.append(original, lastIndex, matcher.start())
|
||||||
|
.append(convert(matcher.group(1)));
|
||||||
|
|
||||||
|
lastIndex = matcher.end();
|
||||||
|
}
|
||||||
|
if (lastIndex < original.length()) {
|
||||||
|
output.append(original, lastIndex, original.length());
|
||||||
|
}
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a token found into its desired lowercase
|
||||||
|
* @param token the token to convert
|
||||||
|
* @return the converted token
|
||||||
|
*/
|
||||||
|
private static String convert(String token) {
|
||||||
|
return token.toLowerCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replace all the tokens in an input using the algorithm provided for each
|
||||||
|
* @param original original string
|
||||||
|
* @param tokenPattern the pattern to match with
|
||||||
|
* @param converter the conversion to apply
|
||||||
|
* @return the substituted string
|
||||||
|
*/
|
||||||
|
public static String replaceTokens(String original, Pattern tokenPattern,
|
||||||
|
Function<Matcher, String> converter) {
|
||||||
|
int lastIndex = 0;
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
Matcher matcher = tokenPattern.matcher(original);
|
||||||
|
while (matcher.find()) {
|
||||||
|
output.append(original, lastIndex, matcher.start())
|
||||||
|
.append(converter.apply(matcher));
|
||||||
|
|
||||||
|
lastIndex = matcher.end();
|
||||||
|
}
|
||||||
|
if (lastIndex < original.length()) {
|
||||||
|
output.append(original, lastIndex, original.length());
|
||||||
|
}
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.baeldung.replacetokens;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static com.baeldung.replacetokens.ReplacingTokens.TITLE_CASE_PATTERN;
|
||||||
|
import static com.baeldung.replacetokens.ReplacingTokens.replaceTokens;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ReplacingTokensUnitTest {
|
||||||
|
private static final String EXAMPLE_INPUT = "First 3 Capital Words! then 10 TLAs, I Found";
|
||||||
|
private static final String EXAMPLE_INPUT_PROCESSED = "first 3 capital words! then 10 TLAs, i found";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenFindMatches_thenTitleWordsFound() {
|
||||||
|
Matcher matcher = TITLE_CASE_PATTERN.matcher(EXAMPLE_INPUT);
|
||||||
|
List<String> matches = new ArrayList<>();
|
||||||
|
while (matcher.find()) {
|
||||||
|
matches.add(matcher.group(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(matches)
|
||||||
|
.containsExactly("First", "Capital", "Words", "I", "Found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void exploreMatches() {
|
||||||
|
Matcher matcher = TITLE_CASE_PATTERN.matcher(EXAMPLE_INPUT);
|
||||||
|
while (matcher.find()) {
|
||||||
|
System.out.println("Match: " + matcher.group(0));
|
||||||
|
System.out.println("Start: " + matcher.start());
|
||||||
|
System.out.println("End: " + matcher.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReplaceTokensWithLowerCase() {
|
||||||
|
assertThat(ReplacingTokens.replaceTitleCaseWithLowerCase(EXAMPLE_INPUT))
|
||||||
|
.isEqualTo(EXAMPLE_INPUT_PROCESSED);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReplaceTokensWithLowerCaseUsingGeneralPurpose() {
|
||||||
|
assertThat(replaceTokens("First 3 Capital Words! then 10 TLAs, I Found",
|
||||||
|
TITLE_CASE_PATTERN,
|
||||||
|
match -> match.group(1).toLowerCase()))
|
||||||
|
.isEqualTo("first 3 capital words! then 10 TLAs, i found");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void escapeRegexCharacters() {
|
||||||
|
Pattern regexCharacters = Pattern.compile("[<(\\[{\\\\^\\-=$!|\\]})?*+.>]");
|
||||||
|
|
||||||
|
assertThat(replaceTokens("A regex character like [",
|
||||||
|
regexCharacters,
|
||||||
|
match -> "\\" + match.group()))
|
||||||
|
.isEqualTo("A regex character like \\[");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void replacePlaceholders() {
|
||||||
|
Pattern placeholderPattern = Pattern.compile("\\$\\{(?<placeholder>[A-Za-z0-9-_]+)}");
|
||||||
|
|
||||||
|
Map<String, String> placeholderValues = new HashMap<>();
|
||||||
|
placeholderValues.put("name", "Bill");
|
||||||
|
placeholderValues.put("company", "Baeldung");
|
||||||
|
|
||||||
|
assertThat(replaceTokens("Hi ${name} at ${company}",
|
||||||
|
placeholderPattern,
|
||||||
|
match -> placeholderValues.get(match.group("placeholder"))))
|
||||||
|
.isEqualTo("Hi Bill at Baeldung");
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,8 +28,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -44,8 +44,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
|
@ -48,8 +48,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -40,20 +40,6 @@
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>${maven-jar-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>libs/</classpathPrefix>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
@ -115,7 +101,6 @@
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<sun-tools.version>1.8.0</sun-tools.version>
|
<sun-tools.version>1.8.0</sun-tools.version>
|
||||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -11,7 +11,7 @@
|
||||||
- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
|
- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
|
||||||
- [Guide to UUID in Java](http://www.baeldung.com/java-uuid)
|
- [Guide to UUID in Java](http://www.baeldung.com/java-uuid)
|
||||||
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
||||||
- [Quick Guide to the Java Stack](http://www.baeldung.com/java-stack)
|
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
|
||||||
- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
|
- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
|
||||||
- [Introduction to Javadoc](http://www.baeldung.com/javadoc)
|
- [Introduction to Javadoc](http://www.baeldung.com/javadoc)
|
||||||
- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable)
|
- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable)
|
||||||
|
|
|
@ -90,101 +90,6 @@
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<version>${maven-jar-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>libs/</classpathPrefix>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<version>${maven-shade-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.jolira</groupId>
|
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
|
||||||
<version>${onejar-maven-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
<attachToBuild>true</attachToBuild>
|
|
||||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>one-jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<version>${spring-boot-maven-plugin.version}</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>spring-boot</classifier>
|
|
||||||
<mainClass>com.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
@ -273,111 +178,6 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<!-- java instrumentation profiles to build jars -->
|
|
||||||
<profile>
|
|
||||||
<id>buildAgentLoader</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>agentLoader</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/application/AgentLoader.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/Launcher.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>buildApplication</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>application</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/application/MyAtm.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/MyAtmApplication.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/application/Launcher.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
<profile>
|
|
||||||
<id>buildAgent</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>jar</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>agent</classifier>
|
|
||||||
<classesDirectory>target/classes</classesDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
</manifest>
|
|
||||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
|
||||||
</archive>
|
|
||||||
|
|
||||||
<includes>
|
|
||||||
<include>com/baeldung/instrumentation/agent/AtmTransformer.class</include>
|
|
||||||
<include>com/baeldung/instrumentation/agent/MyInstrumentationAgent.class</include>
|
|
||||||
</includes>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</profile>
|
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -392,10 +192,6 @@
|
||||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||||
|
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
|
||||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
|
||||||
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
|
||||||
<spring-boot-maven-plugin.version>2.0.3.RELEASE</spring-boot-maven-plugin.version>
|
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<source.version>1.8</source.version>
|
<source.version>1.8</source.version>
|
||||||
<target.version>1.8</target.version>
|
<target.version>1.8</target.version>
|
||||||
|
|
|
@ -1,123 +1,153 @@
|
||||||
package com.baeldung.stack;
|
package com.baeldung.stack;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.equalTo;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
public class StackUnitTest {
|
public class StackUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenStackIsCreated_thenItHasSize0() {
|
public void whenStackIsCreated_thenItHasSizeZero() {
|
||||||
Stack intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
|
|
||||||
assertEquals(0, intStack.size());
|
assertEquals(0, intStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmptyStack_whenElementIsPushed_thenStackSizeisIncreased() {
|
public void whenElementIsPushed_thenStackSizeIsIncreased() {
|
||||||
Stack intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(1);
|
intStack.push(1);
|
||||||
|
|
||||||
assertEquals(1, intStack.size());
|
assertEquals(1, intStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmptyStack_whenMultipleElementsArePushed_thenStackSizeisIncreased() {
|
public void whenMultipleElementsArePushed_thenStackSizeIsIncreased() {
|
||||||
Stack intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||||
|
|
||||||
boolean result = intStack.addAll(intList);
|
boolean result = intStack.addAll(intList);
|
||||||
|
|
||||||
assertTrue(result);
|
assertTrue(result);
|
||||||
assertEquals(7, intList.size());
|
assertEquals(7, intList.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenElementIsPoppedFromStack_thenElementIsRemovedAndSizeChanges() {
|
public void whenElementIsPoppedFromStack_thenElementIsRemovedAndSizeChanges() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.pop();
|
|
||||||
|
Integer element = intStack.pop();
|
||||||
|
|
||||||
|
assertEquals(Integer.valueOf(5), element);
|
||||||
assertTrue(intStack.isEmpty());
|
assertTrue(intStack.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenElementIsPeeked_thenElementIsNotRemovedAndSizeDoesNotChange() {
|
public void whenElementIsPeeked_thenElementIsNotRemovedAndSizeDoesNotChange() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.peek();
|
|
||||||
|
Integer element = intStack.peek();
|
||||||
|
|
||||||
|
assertEquals(Integer.valueOf(5), element);
|
||||||
assertEquals(1, intStack.search(5));
|
assertEquals(1, intStack.search(5));
|
||||||
assertEquals(1, intStack.size());
|
assertEquals(1, intStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenElementIsOnStack_thenSearchReturnsItsDistanceFromTheTop() {
|
public void whenElementIsOnStack_thenSearchReturnsItsDistanceFromTheTop() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
assertEquals(1, intStack.search(5));
|
intStack.push(8);
|
||||||
|
|
||||||
|
assertEquals(2, intStack.search(5));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenElementIsOnStack_thenIndexOfReturnsItsIndex() {
|
public void whenElementIsOnStack_thenIndexOfReturnsItsIndex() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
|
|
||||||
int indexOf = intStack.indexOf(5);
|
int indexOf = intStack.indexOf(5);
|
||||||
|
|
||||||
assertEquals(0, indexOf);
|
assertEquals(0, indexOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMultipleElementsAreOnStack_thenIndexOfReturnsLastElementIndex() {
|
public void whenMultipleElementsAreOnStack_thenIndexOfReturnsLastElementIndex() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
|
|
||||||
int lastIndexOf = intStack.lastIndexOf(5);
|
int lastIndexOf = intStack.lastIndexOf(5);
|
||||||
|
|
||||||
assertEquals(2, lastIndexOf);
|
assertEquals(2, lastIndexOf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenElementOnStack_whenRemoveElementIsInvoked_thenElementIsRemoved() {
|
public void whenRemoveElementIsInvoked_thenElementIsRemoved() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
|
|
||||||
intStack.removeElement(5);
|
intStack.removeElement(5);
|
||||||
|
|
||||||
assertEquals(1, intStack.size());
|
assertEquals(1, intStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenElementOnStack_whenRemoveElementAtIsInvoked_thenElementIsRemoved() {
|
public void whenRemoveElementAtIsInvoked_thenElementIsRemoved() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.push(7);
|
intStack.push(7);
|
||||||
|
|
||||||
intStack.removeElementAt(1);
|
intStack.removeElementAt(1);
|
||||||
|
|
||||||
assertEquals(-1, intStack.search(7));
|
assertEquals(-1, intStack.search(7));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenElementsOnStack_whenRemoveAllElementsIsInvoked_thenAllElementsAreRemoved() {
|
public void whenRemoveAllElementsIsInvoked_thenAllElementsAreRemoved() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
intStack.push(5);
|
intStack.push(5);
|
||||||
intStack.push(7);
|
intStack.push(7);
|
||||||
|
|
||||||
intStack.removeAllElements();
|
intStack.removeAllElements();
|
||||||
|
|
||||||
assertTrue(intStack.isEmpty());
|
assertTrue(intStack.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenElementsOnStack_whenRemoveAllIsInvoked_thenAllElementsFromCollectionAreRemoved() {
|
public void givenElementsOnStack_whenRemoveAllIsInvoked_thenAllElementsFromCollectionAreRemoved() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||||
intStack.addAll(intList);
|
intStack.addAll(intList);
|
||||||
intStack.add(500);
|
intStack.add(500);
|
||||||
|
|
||||||
intStack.removeAll(intList);
|
intStack.removeAll(intList);
|
||||||
|
|
||||||
assertEquals(1, intStack.size());
|
assertEquals(1, intStack.size());
|
||||||
|
assertEquals(1, intStack.search(500));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenElementsOnStack_whenRemoveIfIsInvoked_thenAllElementsSatysfyingConditionAreRemoved() {
|
public void whenRemoveIfIsInvoked_thenAllElementsSatysfyingConditionAreRemoved() {
|
||||||
Stack<Integer> intStack = new Stack();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||||
intStack.addAll(intList);
|
intStack.addAll(intList);
|
||||||
|
|
||||||
intStack.removeIf(element -> element < 6);
|
intStack.removeIf(element -> element < 6);
|
||||||
|
|
||||||
assertEquals(2, intStack.size());
|
assertEquals(2, intStack.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,12 +156,28 @@ public class StackUnitTest {
|
||||||
Stack<Integer> intStack = new Stack<>();
|
Stack<Integer> intStack = new Stack<>();
|
||||||
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
List<Integer> intList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||||
intStack.addAll(intList);
|
intStack.addAll(intList);
|
||||||
|
|
||||||
ListIterator<Integer> it = intStack.listIterator();
|
ListIterator<Integer> it = intStack.listIterator();
|
||||||
Stack<Integer> result = new Stack();
|
|
||||||
|
Stack<Integer> result = new Stack<>();
|
||||||
while(it.hasNext()) {
|
while(it.hasNext()) {
|
||||||
result.push(it.next());
|
result.push(it.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertThat(result, equalTo(intStack));
|
assertThat(result, equalTo(intStack));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenStackIsFiltered_allElementsNotSatisfyingFilterConditionAreDiscarded() {
|
||||||
|
Stack<Integer> intStack = new Stack<>();
|
||||||
|
List<Integer> inputIntList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 9, 10);
|
||||||
|
intStack.addAll(inputIntList);
|
||||||
|
|
||||||
|
List<Integer> filtered = intStack
|
||||||
|
.stream()
|
||||||
|
.filter(element -> element <= 3)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertEquals(3, filtered.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
## Core Kotlin
|
|
||||||
|
|
||||||
This module contains articles about core Kotlin.
|
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.algorithms.balancedbinarytree;
|
package com.baeldung.avltree;
|
||||||
|
|
||||||
public class AVLTree {
|
public class AVLTree {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package com.baeldung.algorithms.balancedbinarytree;
|
package com.baeldung.avltree;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
|
@ -159,8 +159,8 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
package com.baeldung.gson.jsoncompare;
|
||||||
|
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import org.junit.Test;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class JsonCompareUnitTest {
|
||||||
|
@Test
|
||||||
|
public void givenJsonStrings_whenCompared_thenNotEqual() {
|
||||||
|
String string1 = "{\"fullName\": \"Emily Jenkins\", \"age\": 27 }";
|
||||||
|
String string2 = "{\"fullName\": \"Emily Jenkins\", \"age\": 27}";
|
||||||
|
|
||||||
|
assertNotEquals(string1, string2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIdenticalSimpleObjects_whenCompared_thenEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27 }}";
|
||||||
|
String string2 = "{\"customer\": {\"id\": \"44521\", \"fullName\": \"Emily Jenkins\",\"age\": 27}}";
|
||||||
|
|
||||||
|
assertTrue(parser.parse(string1)
|
||||||
|
.isJsonObject());
|
||||||
|
assertEquals(parser.parse(string1), parser.parse(string2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSameObjectsInDifferentOrder_whenCompared_thenEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27 }}";
|
||||||
|
String string2 = "{\"customer\": {\"id\": \"44521\",\"age\": 27, \"fullName\": \"Emily Jenkins\" }}";
|
||||||
|
|
||||||
|
JsonElement json1 = parser.parse(string1);
|
||||||
|
JsonElement json2 = parser.parse(string2);
|
||||||
|
|
||||||
|
assertEquals(json1, json2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIdenticalArrays_whenCompared_thenEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "[10, 20, 30]";
|
||||||
|
String string2 = "[10, 20, 30]";
|
||||||
|
|
||||||
|
assertTrue(parser.parse(string1)
|
||||||
|
.isJsonArray());
|
||||||
|
assertEquals(parser.parse(string1), parser.parse(string2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenArraysInDifferentOrder_whenCompared_thenNotEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "[20, 10, 30]";
|
||||||
|
String string2 = "[10, 20, 30]";
|
||||||
|
|
||||||
|
assertNotEquals(parser.parse(string1), parser.parse(string2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIdenticalNestedObjects_whenCompared_thenEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"fav_product\": \"Coke\", \"last_buy\": \"2012-04-23\"}}}";
|
||||||
|
String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"fav_product\": \"Coke\"}}}";
|
||||||
|
|
||||||
|
JsonElement json1 = parser.parse(string1);
|
||||||
|
JsonElement json2 = parser.parse(string2);
|
||||||
|
|
||||||
|
assertEquals(json1, json2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIdenticalNestedObjectsWithArray_whenCompared_thenEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}";
|
||||||
|
String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}";
|
||||||
|
|
||||||
|
JsonElement json1 = parser.parse(string1);
|
||||||
|
JsonElement json2 = parser.parse(string2);
|
||||||
|
|
||||||
|
assertEquals(json1, json2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNestedObjectsDifferentArrayOrder_whenCompared_thenNotEqual() {
|
||||||
|
JsonParser parser = new JsonParser();
|
||||||
|
String string1 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"banana\", \"eggs\"]}}}";
|
||||||
|
String string2 = "{\"customer\": {\"id\": \"44521\",\"fullName\": \"Emily Jenkins\", \"age\": 27, \"consumption_info\" : {\"last_buy\": \"2012-04-23\", \"prouducts\": [\"eggs\", \"banana\"]}}}";
|
||||||
|
|
||||||
|
JsonElement json1 = parser.parse(string1);
|
||||||
|
JsonElement json2 = parser.parse(string2);
|
||||||
|
|
||||||
|
assertNotEquals(json1, json2);
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ This module contains articles about numbers in Java.
|
||||||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||||
- [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple)
|
- [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple)
|
||||||
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
- [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers)
|
||||||
- [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers)
|
- [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers-in-range)
|
||||||
- [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range)
|
- [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range)
|
||||||
- [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci)
|
- [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci)
|
||||||
- More articles: [[<-- prev]](/../java-numbers)
|
- More articles: [[<-- prev]](/../java-numbers)
|
||||||
|
|
|
@ -14,6 +14,7 @@ node_modules/
|
||||||
npm-debug.log.*
|
npm-debug.log.*
|
||||||
/.awcache/*
|
/.awcache/*
|
||||||
/.cache-loader/*
|
/.cache-loader/*
|
||||||
|
package-lock.json
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# SASS
|
# SASS
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,11 +20,11 @@ import static java.lang.String.format;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for the UTC Hibernate configuration.
|
* Tests for the UTC Hibernate configuration.
|
||||||
*/
|
*/
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = BookstoreApp.class)
|
@SpringBootTest(classes = BookstoreApp.class)
|
||||||
public class HibernateTimeZoneTest {
|
public class HibernateTimeZoneIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DateTimeWrapperRepository dateTimeWrapperRepository;
|
private DateTimeWrapperRepository dateTimeWrapperRepository;
|
|
@ -435,7 +435,23 @@
|
||||||
<artifactId>reflections</artifactId>
|
<artifactId>reflections</artifactId>
|
||||||
<version>${reflections.version}</version>
|
<version>${reflections.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.uber.nullaway</groupId>
|
||||||
|
<artifactId>nullaway</artifactId>
|
||||||
|
<version>0.3.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-compiler-javac-errorprone</artifactId>
|
||||||
|
<version>2.8</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- override plexus-compiler-javac-errorprone's dependency on
|
||||||
|
Error Prone with the latest version -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.errorprone</groupId>
|
||||||
|
<artifactId>error_prone_core</artifactId>
|
||||||
|
<version>2.1.3</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -552,6 +568,47 @@
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.5</version>
|
||||||
|
<configuration>
|
||||||
|
<compilerId>javac-with-errorprone</compilerId>
|
||||||
|
<forceJavacCompilerUse>true</forceJavacCompilerUse>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
<showWarnings>true</showWarnings>
|
||||||
|
<annotationProcessorPaths>
|
||||||
|
<path>
|
||||||
|
<groupId>com.uber.nullaway</groupId>
|
||||||
|
<artifactId>nullaway</artifactId>
|
||||||
|
<version>0.3.0</version>
|
||||||
|
</path>
|
||||||
|
</annotationProcessorPaths>
|
||||||
|
<compilerArgs>
|
||||||
|
<!-- NullAway will warn by default, uncomment the next line to make the build fail -->
|
||||||
|
<!-- <arg>-Xep:NullAway:ERROR</arg> -->
|
||||||
|
<arg>-XepExcludedPaths:(.*)/test/.*|(.*)/streamex/.*</arg>
|
||||||
|
<arg>-XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway</arg>
|
||||||
|
</compilerArgs>
|
||||||
|
</configuration>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-compiler-javac-errorprone</artifactId>
|
||||||
|
<version>2.8</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- override plexus-compiler-javac-errorprone's dependency on
|
||||||
|
Error Prone with the latest version -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.errorprone</groupId>
|
||||||
|
<artifactId>error_prone_core</artifactId>
|
||||||
|
<version>2.1.3</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.baeldung.nullaway;
|
||||||
|
|
||||||
|
import com.baeldung.distinct.Person;
|
||||||
|
|
||||||
|
public class NullAwayExample {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 1- NullAway will warn about yearsToRetirement method
|
||||||
|
* 2- Uncomment @Nullable in printAge and NullAway will warn about this method
|
||||||
|
* 3- Add a standard null check to be NullAway compliant
|
||||||
|
* 4- Build will be SUCCESS
|
||||||
|
*/
|
||||||
|
|
||||||
|
static Integer getAge(/*@Nullable*/ Person person) {
|
||||||
|
return person.getAge();
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer yearsToRetirement() {
|
||||||
|
Person p = null;
|
||||||
|
// ... p never gets set correctly...
|
||||||
|
return 65 - getAge(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,3 +1,3 @@
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
|
|
||||||
- [Linux Commands – Remove All Text After X](https://www.baeldung.com/linux/remove-text-after-x-in-file)
|
- [Linux Commands – Remove All Text After X](https://www.baeldung.com/linux/tr-manipulate-strings)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
### Relevant Articles
|
### Relevant Articles
|
||||||
|
|
||||||
- [Maven Compiler Plugin](http://www.baeldung.com/maven-compiler-plugin)
|
- [Maven Compiler Plugin](https://www.baeldung.com/maven-compiler-plugin)
|
||||||
|
|
|
@ -4,4 +4,3 @@ This module contains articles about Maven with Java 11+.
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
|
|
||||||
- [Multi-Module Maven Application with Java Modules](https://www.baeldung.com/maven-multi-module-project-java-jpms)
|
|
||||||
|
|
|
@ -83,7 +83,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mulesoft.munit</groupId>
|
<groupId>com.mulesoft.munit</groupId>
|
||||||
<artifactId>mule-munit-support</artifactId>
|
<artifactId>mule-munit-support</artifactId>
|
||||||
<version>${mule.munit.support.version}</version>
|
<version>${mule.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -106,18 +106,19 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.mule.tools</groupId>
|
<groupId>org.mule.tools.maven</groupId>
|
||||||
<artifactId>muleesb-maven-plugin</artifactId>
|
<artifactId>mule-maven-plugin</artifactId>
|
||||||
<version>${muleesb-maven-plugin.version}</version>
|
<version>2.2.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
|
<deploymentType>standalone</deploymentType>
|
||||||
<muleVersion>${mule.version}</muleVersion>
|
<muleVersion>${mule.version}</muleVersion>
|
||||||
<applications>/home/abir/AnypointStudio/workspace/variablescopetest</applications>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>deploy</id>
|
<id>deploy</id>
|
||||||
|
<phase>deploy</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>start</goal>
|
<goal>deploy</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
|
@ -210,11 +211,9 @@
|
||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<mule.version>3.8.1</mule.version>
|
<mule.version>3.9.0</mule.version>
|
||||||
<mule.tools.version>1.2</mule.tools.version>
|
<mule.tools.version>1.2</mule.tools.version>
|
||||||
<munit.version>1.3.6</munit.version>
|
<munit.version>1.3.6</munit.version>
|
||||||
<mule.munit.support.version>3.9.0</mule.munit.support.version>
|
|
||||||
<muleesb-maven-plugin.version>1.0</muleesb-maven-plugin.version>
|
|
||||||
<build-helper-maven-plugin.version>1.7</build-helper-maven-plugin.version>
|
<build-helper-maven-plugin.version>1.7</build-helper-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,4 @@ This module contains articles about Netflix.
|
||||||
|
|
||||||
### Relevant articles
|
### Relevant articles
|
||||||
|
|
||||||
- [Introduction to Netflix Genie](https://github.com/eugenp/tutorials/tree/master/netflix/genie)
|
- [Introduction to Netflix Genie](https://www.baeldung.com/netflix-genie-intro)
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
### Relevant Articles:
|
|
||||||
|
|
||||||
- [Implementing The OAuth 2.0 Authorization Framework Using Jakarta EE](https://www.baeldung.com/java-ee-oauth2-implementation)
|
|
|
@ -5,7 +5,7 @@ This module contains articles about the Java Persistence API (JPA) in Java.
|
||||||
### Relevant Articles
|
### Relevant Articles
|
||||||
|
|
||||||
- [JPA Query Parameters Usage](https://www.baeldung.com/jpa-query-parameters)
|
- [JPA Query Parameters Usage](https://www.baeldung.com/jpa-query-parameters)
|
||||||
- [Mapping Entitiy Class Names to SQL Table Names with JPA](https://www.baeldung.com/jpa-entity-table-names)
|
- [Mapping Entity Class Names to SQL Table Names with JPA](https://www.baeldung.com/jpa-entity-table-names)
|
||||||
- [Default Column Values in JPA](https://www.baeldung.com/jpa-default-column-values)
|
- [Default Column Values in JPA](https://www.baeldung.com/jpa-default-column-values)
|
||||||
- [Types of JPA Queries](https://www.baeldung.com/jpa-queries)
|
- [Types of JPA Queries](https://www.baeldung.com/jpa-queries)
|
||||||
- [JPA/Hibernate Projections](https://www.baeldung.com/jpa-hibernate-projections)
|
- [JPA/Hibernate Projections](https://www.baeldung.com/jpa-hibernate-projections)
|
||||||
|
|
|
@ -3,7 +3,7 @@ server.port=8082
|
||||||
|
|
||||||
#spring boot mongodb
|
#spring boot mongodb
|
||||||
spring.data.mongodb.host=localhost
|
spring.data.mongodb.host=localhost
|
||||||
spring.data.mongodb.port=27017
|
spring.data.mongodb.port=0
|
||||||
spring.data.mongodb.database=springboot-mongo
|
spring.data.mongodb.database=springboot-mongo
|
||||||
|
|
||||||
spring.thymeleaf.cache=false
|
spring.thymeleaf.cache=false
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package com.baeldung.spring.data.redis.config;
|
package com.baeldung.spring.data.redis.config;
|
||||||
|
|
||||||
import com.baeldung.spring.data.redis.queue.MessagePublisher;
|
|
||||||
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
|
||||||
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.annotation.PropertySource;
|
import org.springframework.context.annotation.PropertySource;
|
||||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.data.redis.listener.ChannelTopic;
|
import org.springframework.data.redis.listener.ChannelTopic;
|
||||||
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
|
||||||
|
@ -15,6 +13,10 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
|
||||||
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
import org.springframework.data.redis.repository.configuration.EnableRedisRepositories;
|
||||||
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
import org.springframework.data.redis.serializer.GenericToStringSerializer;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.queue.MessagePublisher;
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
|
||||||
|
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan("com.baeldung.spring.data.redis")
|
@ComponentScan("com.baeldung.spring.data.redis")
|
||||||
@EnableRedisRepositories(basePackages = "com.baeldung.spring.data.redis.repo")
|
@EnableRedisRepositories(basePackages = "com.baeldung.spring.data.redis.repo")
|
||||||
|
@ -33,6 +35,18 @@ public class RedisConfig {
|
||||||
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
|
template.setValueSerializer(new GenericToStringSerializer<Object>(Object.class));
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public LettuceConnectionFactory lettuceConnectionFactory() {
|
||||||
|
return new LettuceConnectionFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "flushRedisTemplate")
|
||||||
|
public RedisTemplate<String, String> flushRedisTemplate() {
|
||||||
|
RedisTemplate<String, String> template = new RedisTemplate<>();
|
||||||
|
template.setConnectionFactory(lettuceConnectionFactory());
|
||||||
|
return template;
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
MessageListenerAdapter messageListener() {
|
MessageListenerAdapter messageListener() {
|
||||||
|
|
|
@ -0,0 +1,92 @@
|
||||||
|
package com.baeldung.spring.data.redis.delete;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
|
import org.springframework.data.redis.core.RedisCallback;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.core.ValueOperations;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import com.baeldung.spring.data.redis.config.RedisConfig;
|
||||||
|
|
||||||
|
import redis.embedded.RedisServer;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = { RedisConfig.class })
|
||||||
|
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
|
||||||
|
public class RedisFlushDatabaseIntegrationTest {
|
||||||
|
|
||||||
|
private RedisServer redisServer;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("flushRedisTemplate")
|
||||||
|
private RedisTemplate<String, String> flushRedisTemplate;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws IOException {
|
||||||
|
redisServer = new RedisServer(6390);
|
||||||
|
redisServer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
redisServer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenFlushDB_thenAllKeysInDatabaseAreCleared() {
|
||||||
|
|
||||||
|
ValueOperations<String, String> simpleValues = flushRedisTemplate.opsForValue();
|
||||||
|
String key = "key";
|
||||||
|
String value = "value";
|
||||||
|
simpleValues.set(key, value);
|
||||||
|
assertThat(simpleValues.get(key)).isEqualTo(value);
|
||||||
|
|
||||||
|
flushRedisTemplate.execute(new RedisCallback<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInRedis(RedisConnection connection) throws DataAccessException {
|
||||||
|
connection.flushDb();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThat(simpleValues.get(key)).isNull();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenFlushAll_thenAllKeysInDatabasesAreCleared() {
|
||||||
|
|
||||||
|
ValueOperations<String, String> simpleValues = flushRedisTemplate.opsForValue();
|
||||||
|
String key = "key";
|
||||||
|
String value = "value";
|
||||||
|
simpleValues.set(key, value);
|
||||||
|
assertThat(simpleValues.get(key)).isEqualTo(value);
|
||||||
|
|
||||||
|
flushRedisTemplate.execute(new RedisCallback<Void>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Void doInRedis(RedisConnection connection) throws DataAccessException {
|
||||||
|
connection.flushAll();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertThat(simpleValues.get(key)).isNull();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [A Guide to JPA with Spring](https://www.baeldung.com/the-persistence-layer-with-spring-and-jpa)
|
- [A Guide to JPA with Spring](https://www.baeldung.com/the-persistence-layer-with-spring-and-jpa)
|
||||||
- [Bootstrapping Hibernate 5 with Spring](http://www.baeldung.com/hibernate-5-spring)
|
- [Bootstrapping Hibernate 5 with Spring](http://www.baeldung.com/hibernate-5-spring)
|
||||||
- [The DAO with Spring and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
|
- [The DAO with Spring and Hibernate](https://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
|
||||||
- [Simplify the DAO with Spring and Java Generics](https://www.baeldung.com/simplifying-the-data-access-layer-with-spring-and-java-generics)
|
- [Simplify the DAO with Spring and Java Generics](https://www.baeldung.com/simplifying-the-data-access-layer-with-spring-and-java-generics)
|
||||||
- [Transactions with Spring and JPA](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
|
- [Transactions with Spring and JPA](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
|
||||||
- [Introduction to Spring Data JPA](http://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
|
- [Introduction to Spring Data JPA](http://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
|
||||||
|
|
20
pom.xml
20
pom.xml
|
@ -59,20 +59,14 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-all</artifactId>
|
<artifactId>hamcrest-all</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${hamcrest-all.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1334,7 +1328,8 @@
|
||||||
<gib.enabled>false</gib.enabled>
|
<gib.enabled>false</gib.enabled>
|
||||||
|
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
<hamcrest.version>2.2</hamcrest.version>
|
||||||
|
<hamcrest-all.version>1.3</hamcrest-all.version>
|
||||||
<mockito.version>2.21.0</mockito.version>
|
<mockito.version>2.21.0</mockito.version>
|
||||||
|
|
||||||
<!-- logging -->
|
<!-- logging -->
|
||||||
|
@ -1344,7 +1339,7 @@
|
||||||
<!-- plugins -->
|
<!-- plugins -->
|
||||||
<!-- can't upgrade the plugin yet; as there is an issue with 2.22 no longer running all the tests-->
|
<!-- can't upgrade the plugin yet; as there is an issue with 2.22 no longer running all the tests-->
|
||||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
<log4j.version>1.2.17</log4j.version>
|
||||||
|
@ -1352,7 +1347,6 @@
|
||||||
<esapi.version>2.1.0.1</esapi.version>
|
<esapi.version>2.1.0.1</esapi.version>
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
<jmh-core.version>1.19</jmh-core.version>
|
||||||
<jmh-generator.version>1.19</jmh-generator.version>
|
<jmh-generator.version>1.19</jmh-generator.version>
|
||||||
<hamcrest-all.version>1.3</hamcrest-all.version>
|
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
||||||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
<commons-io.version>2.5</commons-io.version>
|
||||||
|
@ -1370,7 +1364,7 @@
|
||||||
<junit-platform.version>1.2.0</junit-platform.version>
|
<junit-platform.version>1.2.0</junit-platform.version>
|
||||||
<junit-jupiter.version>5.2.0</junit-jupiter.version>
|
<junit-jupiter.version>5.2.0</junit-jupiter.version>
|
||||||
<directory-maven-plugin.version>0.3.1</directory-maven-plugin.version>
|
<directory-maven-plugin.version>0.3.1</directory-maven-plugin.version>
|
||||||
<maven-install-plugin.version>2.5.1</maven-install-plugin.version>
|
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
|
||||||
<custom-pmd.version>0.0.1</custom-pmd.version>
|
<custom-pmd.version>0.0.1</custom-pmd.version>
|
||||||
<gitflow-incremental-builder.version>3.8</gitflow-incremental-builder.version>
|
<gitflow-incremental-builder.version>3.8</gitflow-incremental-builder.version>
|
||||||
<maven-jxr-plugin.version>2.3</maven-jxr-plugin.version>
|
<maven-jxr-plugin.version>2.3</maven-jxr-plugin.version>
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.baeldung.spring.serverconfig;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/timeout")
|
||||||
|
public class TimeoutController {
|
||||||
|
|
||||||
|
@GetMapping("/{timeout}")
|
||||||
|
private Mono<String> timeout(@PathVariable int timeout) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(timeout * 1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
return Mono.just("OK");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.baeldung.spring.serverconfig;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.net.ssl.SSLException;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.ExpectedException;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||||
|
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
|
||||||
|
import org.springframework.test.annotation.DirtiesContext;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||||
|
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.handler.ssl.SslContext;
|
||||||
|
import io.netty.handler.ssl.SslContextBuilder;
|
||||||
|
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||||
|
import io.netty.handler.timeout.ReadTimeoutException;
|
||||||
|
import io.netty.handler.timeout.ReadTimeoutHandler;
|
||||||
|
import io.netty.handler.timeout.WriteTimeoutHandler;
|
||||||
|
import reactor.netty.http.client.HttpClient;
|
||||||
|
import reactor.netty.tcp.TcpClient;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
|
||||||
|
@DirtiesContext
|
||||||
|
public class TimeoutLiveTest {
|
||||||
|
|
||||||
|
private static final String BASE_URL = "https://localhost:8443";
|
||||||
|
private static final int TIMEOUT_MILLIS = 2000;
|
||||||
|
|
||||||
|
private WebTestClient webTestClient;
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public ExpectedException exception = ExpectedException.none();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws SSLException {
|
||||||
|
webTestClient = WebTestClient.bindToServer(getConnector())
|
||||||
|
.baseUrl(BASE_URL)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldTimeout() {
|
||||||
|
exception.expect(ReadTimeoutException.class);
|
||||||
|
webTestClient.get()
|
||||||
|
.uri("/timeout/{timeout}", 3)
|
||||||
|
.exchange();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldNotTimeout() {
|
||||||
|
WebTestClient.ResponseSpec response = webTestClient.get()
|
||||||
|
.uri("/timeout/{timeout}", 1)
|
||||||
|
.exchange();
|
||||||
|
response.expectStatus()
|
||||||
|
.isOk()
|
||||||
|
.expectBody(String.class)
|
||||||
|
.isEqualTo("OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReactorClientHttpConnector getConnector() throws SSLException {
|
||||||
|
SslContext sslContext = SslContextBuilder
|
||||||
|
.forClient()
|
||||||
|
.trustManager(InsecureTrustManagerFactory.INSTANCE)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
TcpClient tcpClient = TcpClient
|
||||||
|
.create()
|
||||||
|
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, TIMEOUT_MILLIS)
|
||||||
|
.doOnConnected(connection -> {
|
||||||
|
connection.addHandlerLast(new ReadTimeoutHandler(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
|
||||||
|
connection.addHandlerLast(new WriteTimeoutHandler(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS));
|
||||||
|
});
|
||||||
|
|
||||||
|
HttpClient httpClient = HttpClient.from(tcpClient).secure(t -> t.sslContext(sslContext));
|
||||||
|
return new ReactorClientHttpConnector(httpClient);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,10 @@
|
||||||
package org.baeldung.batch.model;
|
package org.baeldung.batch.model;
|
||||||
|
|
||||||
import java.util.Date;
|
import org.baeldung.batch.service.adapter.LocalDateTimeAdapter;
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
@SuppressWarnings("restriction")
|
@SuppressWarnings("restriction")
|
||||||
@XmlRootElement(name = "transactionRecord")
|
@XmlRootElement(name = "transactionRecord")
|
||||||
|
@ -11,7 +13,7 @@ public class Transaction {
|
||||||
private int userId;
|
private int userId;
|
||||||
private int age;
|
private int age;
|
||||||
private String postCode;
|
private String postCode;
|
||||||
private Date transactionDate;
|
private LocalDateTime transactionDate;
|
||||||
private double amount;
|
private double amount;
|
||||||
|
|
||||||
/* getters and setters for the attributes */
|
/* getters and setters for the attributes */
|
||||||
|
@ -32,11 +34,12 @@ public class Transaction {
|
||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getTransactionDate() {
|
@XmlJavaTypeAdapter(LocalDateTimeAdapter.class)
|
||||||
|
public LocalDateTime getTransactionDate() {
|
||||||
return transactionDate;
|
return transactionDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransactionDate(Date transactionDate) {
|
public void setTransactionDate(LocalDateTime transactionDate) {
|
||||||
this.transactionDate = transactionDate;
|
this.transactionDate = transactionDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,19 @@
|
||||||
package org.baeldung.batch.service;
|
package org.baeldung.batch.service;
|
||||||
|
|
||||||
import java.text.ParseException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
|
|
||||||
import org.baeldung.batch.model.Transaction;
|
import org.baeldung.batch.model.Transaction;
|
||||||
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
import org.springframework.batch.item.file.mapping.FieldSetMapper;
|
||||||
import org.springframework.batch.item.file.transform.FieldSet;
|
import org.springframework.batch.item.file.transform.FieldSet;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
public class RecordFieldSetMapper implements FieldSetMapper<Transaction> {
|
public class RecordFieldSetMapper implements FieldSetMapper<Transaction> {
|
||||||
|
|
||||||
public Transaction mapFieldSet(FieldSet fieldSet) throws BindException {
|
public Transaction mapFieldSet(FieldSet fieldSet) throws BindException {
|
||||||
|
|
||||||
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/M/yyy");
|
||||||
|
|
||||||
Transaction transaction = new Transaction();
|
Transaction transaction = new Transaction();
|
||||||
// you can either use the indices or custom names
|
// you can either use the indices or custom names
|
||||||
// I personally prefer the custom names easy for debugging and
|
// I personally prefer the custom names easy for debugging and
|
||||||
|
@ -20,13 +21,10 @@ public class RecordFieldSetMapper implements FieldSetMapper<Transaction> {
|
||||||
transaction.setUsername(fieldSet.readString("username"));
|
transaction.setUsername(fieldSet.readString("username"));
|
||||||
transaction.setUserId(fieldSet.readInt("userid"));
|
transaction.setUserId(fieldSet.readInt("userid"));
|
||||||
transaction.setAmount(fieldSet.readDouble(3));
|
transaction.setAmount(fieldSet.readDouble(3));
|
||||||
|
|
||||||
// Converting the date
|
// Converting the date
|
||||||
String dateString = fieldSet.readString(2);
|
String dateString = fieldSet.readString(2);
|
||||||
try {
|
transaction.setTransactionDate(LocalDate.parse(dateString, formatter).atStartOfDay());
|
||||||
transaction.setTransactionDate(dateFormat.parse(dateString));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return transaction;
|
return transaction;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package org.baeldung.batch.service.adapter;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
|
public class LocalDateTimeAdapter extends XmlAdapter<String, LocalDateTime> {
|
||||||
|
|
||||||
|
private static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
private static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_FORMAT);
|
||||||
|
|
||||||
|
public LocalDateTime unmarshal(String v) throws Exception {
|
||||||
|
return LocalDateTime.parse(v, DATE_TIME_FORMATTER);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String marshal(LocalDateTime v) throws Exception {
|
||||||
|
return DATE_TIME_FORMATTER.format(v);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,19 +2,19 @@
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>10000.0</amount>
|
<amount>10000.0</amount>
|
||||||
<transactionDate>2015-10-31T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-10-31 00:00:00</transactionDate>
|
||||||
<userId>1234</userId>
|
<userId>1234</userId>
|
||||||
<username>devendra</username>
|
<username>devendra</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>12321.0</amount>
|
<amount>12321.0</amount>
|
||||||
<transactionDate>2015-12-03T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-12-03 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>john</username>
|
<username>john</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>23411.0</amount>
|
<amount>23411.0</amount>
|
||||||
<transactionDate>2015-02-02T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-02-02 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>robin</username>
|
<username>robin</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>10000.0</amount>
|
<amount>10000.0</amount>
|
||||||
<transactionDate>2015-10-31T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-10-31 00:00:00</transactionDate>
|
||||||
<userId>1234</userId>
|
<userId>1234</userId>
|
||||||
<username>devendra</username>
|
<username>devendra</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>12321.0</amount>
|
<amount>12321.0</amount>
|
||||||
<transactionDate>2015-12-03T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-12-03 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>john</username>
|
<username>john</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>23411.0</amount>
|
<amount>23411.0</amount>
|
||||||
<transactionDate>2015-02-02T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-02-02 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>robin</username>
|
<username>robin</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>10000.0</amount>
|
<amount>10000.0</amount>
|
||||||
<transactionDate>2015-10-31T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-10-31 00:00:00</transactionDate>
|
||||||
<userId>1234</userId>
|
<userId>1234</userId>
|
||||||
<username>devendra</username>
|
<username>devendra</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>12321.0</amount>
|
<amount>12321.0</amount>
|
||||||
<transactionDate>2015-12-03T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-12-03 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>john</username>
|
<username>john</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>23411.0</amount>
|
<amount>23411.0</amount>
|
||||||
<transactionDate>2015-02-02T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-02-02 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>robin</username>
|
<username>robin</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>10000.0</amount>
|
<amount>10000.0</amount>
|
||||||
<transactionDate>2015-10-31T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-10-31 00:00:00</transactionDate>
|
||||||
<userId>1234</userId>
|
<userId>1234</userId>
|
||||||
<username>devendra</username>
|
<username>devendra</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>12321.0</amount>
|
<amount>12321.0</amount>
|
||||||
<transactionDate>2015-12-03T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-12-03 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>john</username>
|
<username>john</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>23411.0</amount>
|
<amount>23411.0</amount>
|
||||||
<transactionDate>2015-02-02T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-02-02 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>robin</username>
|
<username>robin</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
|
|
|
@ -2,19 +2,19 @@
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>10000.0</amount>
|
<amount>10000.0</amount>
|
||||||
<transactionDate>2015-10-31T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-10-31 00:00:00</transactionDate>
|
||||||
<userId>1234</userId>
|
<userId>1234</userId>
|
||||||
<username>devendra</username>
|
<username>devendra</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>12321.0</amount>
|
<amount>12321.0</amount>
|
||||||
<transactionDate>2015-12-03T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-12-03 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>john</username>
|
<username>john</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
<transactionRecord>
|
<transactionRecord>
|
||||||
<amount>23411.0</amount>
|
<amount>23411.0</amount>
|
||||||
<transactionDate>2015-02-02T00:00:00+05:30</transactionDate>
|
<transactionDate>2015-02-02 00:00:00</transactionDate>
|
||||||
<userId>2134</userId>
|
<userId>2134</userId>
|
||||||
<username>robin</username>
|
<username>robin</username>
|
||||||
</transactionRecord>
|
</transactionRecord>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><age>10</age><amount>10000.0</amount><postCode>430222</postCode><transactionDate>2015-10-31T00:00:00+05:30</transactionDate><userId>1234</userId><username>sammy</username></transactionRecord><transactionRecord><age>10</age><amount>12321.0</amount><postCode>430222</postCode><transactionDate>2015-12-03T00:00:00+05:30</transactionDate><userId>9999</userId><username>john</username></transactionRecord></transactionRecord>
|
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><age>10</age><amount>10000.0</amount><postCode>430222</postCode><transactionDate>2015-10-31 00:00:00</transactionDate><userId>1234</userId><username>sammy</username></transactionRecord><transactionRecord><age>10</age><amount>12321.0</amount><postCode>430222</postCode><transactionDate>2015-12-03 00:00:00</transactionDate><userId>9999</userId><username>john</username></transactionRecord></transactionRecord>
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><amount>10000.0</amount><transactionDate>2015-10-31T00:00:00+05:30</transactionDate><userId>1234</userId><username>devendra</username></transactionRecord><transactionRecord><amount>12321.0</amount><transactionDate>2015-12-03T00:00:00+05:30</transactionDate><userId>2134</userId><username>john</username></transactionRecord><transactionRecord><amount>23411.0</amount><transactionDate>2015-02-02T00:00:00+05:30</transactionDate><userId>2134</userId><username>robin</username></transactionRecord></transactionRecord>
|
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><amount>10000.0</amount><transactionDate>2015-10-31 00:00:00</transactionDate><userId>1234</userId><username>devendra</username></transactionRecord><transactionRecord><amount>12321.0</amount><transactionDate>2015-12-03 00:00:00</transactionDate><userId>2134</userId><username>john</username></transactionRecord><transactionRecord><amount>23411.0</amount><transactionDate>2015-02-02 00:00:00</transactionDate><userId>2134</userId><username>robin</username></transactionRecord></transactionRecord>
|
|
@ -1 +1 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><age>10</age><amount>10000.0</amount><postCode>430222</postCode><transactionDate>2015-10-31T00:00:00+05:30</transactionDate><userId>1234</userId><username>sammy</username></transactionRecord><transactionRecord><age>10</age><amount>12321.0</amount><postCode>430222</postCode><transactionDate>2015-12-03T00:00:00+05:30</transactionDate><userId>9999</userId><username>john</username></transactionRecord></transactionRecord>
|
<?xml version="1.0" encoding="UTF-8"?><transactionRecord><transactionRecord><age>10</age><amount>10000.0</amount><postCode>430222</postCode><transactionDate>2015-10-31 00:00:00</transactionDate><userId>1234</userId><username>sammy</username></transactionRecord><transactionRecord><age>10</age><amount>12321.0</amount><postCode>430222</postCode><transactionDate>2015-12-03 00:00:00</transactionDate><userId>9999</userId><username>john</username></transactionRecord></transactionRecord>
|
|
@ -1,3 +0,0 @@
|
||||||
## Spring Boot Modules
|
|
||||||
|
|
||||||
This module contains various modules of Spring Boot
|
|
|
@ -32,6 +32,7 @@
|
||||||
<module>spring-boot-crud</module>
|
<module>spring-boot-crud</module>
|
||||||
<module>spring-boot-data</module>
|
<module>spring-boot-data</module>
|
||||||
<module>spring-boot-environment</module>
|
<module>spring-boot-environment</module>
|
||||||
|
<module>spring-boot-exceptions</module>
|
||||||
<module>spring-boot-flowable</module>
|
<module>spring-boot-flowable</module>
|
||||||
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
|
<!-- <module>spring-boot-gradle</module> --> <!-- Not a maven project -->
|
||||||
<module>spring-boot-jasypt</module>
|
<module>spring-boot-jasypt</module>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
## Spring Boot
|
||||||
|
|
||||||
|
This module contains articles about Spring Boot Exceptions
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
|
@ -0,0 +1,96 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>spring-boot-exceptions</artifactId>
|
||||||
|
<name>spring-boot-exceptions</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<description>Demo project for working with Spring Boot exceptions</description>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-boot-2</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-boot-2</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
|
<version>2.2.3.RELEASE</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>spring-boot-exceptions</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
|
<plugins>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<delimiters>
|
||||||
|
<delimiter>@</delimiter>
|
||||||
|
</delimiters>
|
||||||
|
<useDefaultDelimiters>false</useDefaultDelimiters>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>autoconfiguration</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>integration-test</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>test</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
|
<exclude>**/*IntegrationTest.java</exclude>
|
||||||
|
<exclude>**/*IntTest.java</exclude>
|
||||||
|
</excludes>
|
||||||
|
<includes>
|
||||||
|
<include>**/AutoconfigurationTest.java</include>
|
||||||
|
</includes>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<test.mime>json</test.mime>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<!-- The main class to start by executing java -jar -->
|
||||||
|
<start-class>com.baeldung.intro.App</start-class>
|
||||||
|
</properties>
|
||||||
|
</project>
|
|
@ -0,0 +1,13 @@
|
||||||
|
<configuration>
|
||||||
|
<include resource="/org/springframework/boot/logging/logback/base.xml"/>
|
||||||
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||||
|
</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
<root level="error">
|
||||||
|
<appender-ref ref="STDOUT"/>
|
||||||
|
</root>
|
||||||
|
<logger name="com.baeldung.testloglevel" level="debug"/>
|
||||||
|
</configuration>
|
|
@ -43,6 +43,12 @@
|
||||||
<artifactId>httpcore</artifactId>
|
<artifactId>httpcore</artifactId>
|
||||||
<version>${httpcore.version}</version>
|
<version>${httpcore.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||||
|
<version>${configuration-processor.version}</version>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<dependencyManagement>
|
<dependencyManagement>
|
||||||
|
@ -121,6 +127,7 @@
|
||||||
<guava.version>20.0</guava.version>
|
<guava.version>20.0</guava.version>
|
||||||
<httpcore.version>4.4.11</httpcore.version>
|
<httpcore.version>4.4.11</httpcore.version>
|
||||||
<resource.delimiter>@</resource.delimiter>
|
<resource.delimiter>@</resource.delimiter>
|
||||||
|
<configuration-processor.version>2.2.4.RELEASE</configuration-processor.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.boot.context.properties.*;
|
||||||
|
import org.springframework.context.annotation.*;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@ConfigurationProperties(prefix = "com.baeldung")
|
||||||
|
public class CustomProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The url to connect to.
|
||||||
|
*/
|
||||||
|
String url;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time to wait for the connection.
|
||||||
|
*/
|
||||||
|
private int timeoutInMilliSeconds = 1000;
|
||||||
|
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimeoutInMilliSeconds() {
|
||||||
|
return timeoutInMilliSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeoutInMilliSeconds(int timeoutInMilliSeconds) {
|
||||||
|
this.timeoutInMilliSeconds = timeoutInMilliSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.boot.*;
|
||||||
|
import org.springframework.boot.autoconfigure.*;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class DemoApplication {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.*;
|
||||||
|
import org.springframework.stereotype.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PropertyBeanInjection {
|
||||||
|
|
||||||
|
private final CustomProperties customProperties;
|
||||||
|
|
||||||
|
PropertyBeanInjection(@Autowired CustomProperties customProperties) {
|
||||||
|
this.customProperties = customProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getUrl() {
|
||||||
|
return customProperties.getUrl();
|
||||||
|
}
|
||||||
|
|
||||||
|
int getTimeoutInMilliseconds() {
|
||||||
|
return customProperties.getTimeoutInMilliSeconds();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.baeldung.configuration.processor;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.runner.*;
|
||||||
|
import org.springframework.beans.factory.annotation.*;
|
||||||
|
import org.springframework.boot.test.context.*;
|
||||||
|
import org.springframework.test.context.*;
|
||||||
|
import org.springframework.test.context.junit4.*;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@TestPropertySource("/configuration-processor.properties")
|
||||||
|
@SpringBootTest(classes = DemoApplication.class)
|
||||||
|
class PropertyBeanInjectionUnitTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PropertyBeanInjection propertyBeanInjection;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void checkThatCustomPropertiesHaveTheCorrectValueFromPropertiesFile() {
|
||||||
|
Assertions.assertEquals("www.abc.test.com", propertyBeanInjection.getUrl());
|
||||||
|
Assertions.assertEquals(2000, propertyBeanInjection.getTimeoutInMilliseconds());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
com.baeldung.url=www.abc.test.com
|
||||||
|
com.baeldung.timeout-in-milli-seconds=2000
|
|
@ -1,3 +0,0 @@
|
||||||
### Relevant Articles:
|
|
||||||
|
|
||||||
- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging)
|
|
|
@ -17,8 +17,8 @@
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- <spring-boot.version>2.1.9.RELEASE</spring-boot.version>-->
|
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
|
<springdoc.version>1.2.32</springdoc.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -26,6 +26,14 @@
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.h2database</groupId>
|
||||||
|
<artifactId>h2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -36,24 +44,13 @@
|
||||||
<!-- SpringDoc -->
|
<!-- SpringDoc -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-core</artifactId>
|
<artifactId>springdoc-openapi-ui</artifactId>
|
||||||
<version>1.1.49</version>
|
<version>${springdoc.version}</version>
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>io.github.classgraph</groupId>
|
|
||||||
<artifactId>classgraph</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springdoc</groupId>
|
<groupId>org.springdoc</groupId>
|
||||||
<artifactId>springdoc-openapi-ui</artifactId>
|
<artifactId>springdoc-openapi-data-rest</artifactId>
|
||||||
<version>1.1.49</version>
|
<version>${springdoc.version}</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.classgraph</groupId>
|
|
||||||
<artifactId>classgraph</artifactId>
|
|
||||||
<version>4.8.44</version>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import javax.validation.Valid;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -41,6 +43,11 @@ public class BookController {
|
||||||
return repository.getBooks();
|
return repository.getBooks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/filter")
|
||||||
|
public Page<Book> filterBooks(Pageable pageable) {
|
||||||
|
return repository.getBooks(pageable);
|
||||||
|
}
|
||||||
|
|
||||||
@PutMapping("/{id}")
|
@PutMapping("/{id}")
|
||||||
@ResponseStatus(HttpStatus.OK)
|
@ResponseStatus(HttpStatus.OK)
|
||||||
public Book updateBook(@PathVariable("id") final String id, @RequestBody final Book book) {
|
public Book updateBook(@PathVariable("id") final String id, @RequestBody final Book book) {
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
package com.baeldung.springdoc.repository;
|
package com.baeldung.springdoc.repository;
|
||||||
|
|
||||||
import java.util.Collection;
|
import com.baeldung.springdoc.model.Book;
|
||||||
import java.util.HashMap;
|
import org.springframework.data.domain.Page;
|
||||||
import java.util.Map;
|
import org.springframework.data.domain.PageImpl;
|
||||||
import java.util.Optional;
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
import com.baeldung.springdoc.model.Book;
|
import java.util.*;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public class BookRepository {
|
public class BookRepository {
|
||||||
|
@ -25,4 +26,11 @@ public class BookRepository {
|
||||||
public Collection<Book> getBooks() {
|
public Collection<Book> getBooks() {
|
||||||
return books.values();
|
return books.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Page<Book> getBooks(Pageable pageable) {
|
||||||
|
int toSkip = pageable.getPageSize() * pageable.getPageNumber();
|
||||||
|
List<Book> result = books.values().stream().skip(toSkip).limit(pageable.getPageSize()).collect(toList());
|
||||||
|
|
||||||
|
return new PageImpl<>(result, pageable, books.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,3 +3,6 @@ springdoc.swagger-ui.path=/swagger-ui-custom.html
|
||||||
|
|
||||||
# custom path for api docs
|
# custom path for api docs
|
||||||
springdoc.api-docs.path=/api-docs
|
springdoc.api-docs.path=/api-docs
|
||||||
|
|
||||||
|
# H2 Related Configurations
|
||||||
|
spring.datasource.url=jdbc:h2:mem:springdoc
|
|
@ -31,4 +31,3 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
||||||
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
|
- [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks)
|
||||||
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
|
- [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot)
|
||||||
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
|
- [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation)
|
||||||
- [The BeanDefinitionOverrideException in Spring Boot](https://www.baeldung.com/spring-boot-bean-definition-override-exception)
|
|
||||||
|
|
|
@ -65,14 +65,14 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
<version>${hamcrest.version}</version>
|
<version>${hamcrest-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring-cloud-starter-feign.version>1.2.5.RELEASE</spring-cloud-starter-feign.version>
|
<spring-cloud-starter-feign.version>1.2.5.RELEASE</spring-cloud-starter-feign.version>
|
||||||
<hamcrest.version>1.3</hamcrest.version>
|
<hamcrest-core.version>1.3</hamcrest-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -24,12 +24,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -135,12 +135,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -206,15 +206,9 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- <dependency> -->
|
|
||||||
<!-- <groupId>org.hamcrest</groupId> -->
|
|
||||||
<!-- <artifactId>hamcrest-core</artifactId> -->
|
|
||||||
<!-- <scope>test</scope> -->
|
|
||||||
<!-- </dependency> -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -139,12 +139,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -177,14 +177,9 @@
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- <dependency> -->
|
|
||||||
<!-- <groupId>org.hamcrest</groupId> -->
|
|
||||||
<!-- <artifactId>hamcrest-core</artifactId> -->
|
|
||||||
<!-- <scope>test</scope> -->
|
|
||||||
<!-- </dependency> -->
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -130,12 +130,7 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
### Relevant articles:
|
### Relevant articles:
|
||||||
- [A Guide to the Spring Task Scheduler](http://www.baeldung.com/spring-task-scheduler)
|
- [A Guide to the Spring Task Scheduler](https://www.baeldung.com/spring-task-scheduler)
|
||||||
- [The @Scheduled Annotation in Spring](https://www.baeldung.com/spring-scheduled-tasks)
|
- [The @Scheduled Annotation in Spring](https://www.baeldung.com/spring-scheduled-tasks)
|
||||||
- [Guide to Spring Retry](http://www.baeldung.com/spring-retry)
|
- [Guide to Spring Retry](https://www.baeldung.com/spring-retry)
|
||||||
- [How To Do @Async in Spring](http://www.baeldung.com/spring-async)
|
- [How To Do @Async in Spring](https://www.baeldung.com/spring-async)
|
||||||
- [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally)
|
- [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally)
|
||||||
|
|
||||||
|
|
|
@ -42,12 +42,8 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
<version>${hamcrest.version}</version>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -61,12 +61,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class CustomUserDetailsServiceIntegrationTest {
|
||||||
@WithAnonymousUser
|
@WithAnonymousUser
|
||||||
public void givenAnonymous_whenRequestFoo_thenRetrieveUnauthorized() throws Exception {
|
public void givenAnonymous_whenRequestFoo_thenRetrieveUnauthorized() throws Exception {
|
||||||
this.mvc.perform(get("/foos/1").with(csrf()))
|
this.mvc.perform(get("/foos/1").with(csrf()))
|
||||||
.andExpect(status().isUnauthorized());
|
.andExpect(status().isFound());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -61,12 +61,7 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -136,12 +136,7 @@
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest</artifactId>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com
|
||||||
- [Intro to Spring Security Expressions](https://www.baeldung.com/spring-security-expressions)
|
- [Intro to Spring Security Expressions](https://www.baeldung.com/spring-security-expressions)
|
||||||
- [Spring Security for a REST API](https://www.baeldung.com/securing-a-restful-web-service-with-spring-security)
|
- [Spring Security for a REST API](https://www.baeldung.com/securing-a-restful-web-service-with-spring-security)
|
||||||
- [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic)
|
- [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic)
|
||||||
|
- [Error Handling for REST with Spring](https://www.baeldung.com/exception-handling-for-rest-with-spring)
|
||||||
|
|
|
@ -18,13 +18,13 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>java-hamcrest</artifactId>
|
<artifactId>java-hamcrest</artifactId>
|
||||||
<version>${hamcrest.version}</version>
|
<version>${java-hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<hamcrest.version>2.0.0.0</hamcrest.version>
|
<java-hamcrest.version>2.0.0.0</java-hamcrest.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -90,7 +90,6 @@
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<powermock.version>2.0.2</powermock.version>
|
<powermock.version>2.0.2</powermock.version>
|
||||||
<hamcrest.version>2.0.0.0</hamcrest.version>
|
|
||||||
<javax.persistence.version>2.1.1</javax.persistence.version>
|
<javax.persistence.version>2.1.1</javax.persistence.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -17,8 +17,7 @@ import static io.restassured.RestAssured.with;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
|
||||||
public class RestAssured2IntegrationTest {
|
public class RestAssured2IntegrationTest {
|
||||||
private static final int PORT = 8084;
|
private static WireMockServer wireMockServer;
|
||||||
private static WireMockServer wireMockServer = new WireMockServer(PORT);
|
|
||||||
|
|
||||||
private static final String EVENTS_PATH = "/odds";
|
private static final String EVENTS_PATH = "/odds";
|
||||||
private static final String APPLICATION_JSON = "application/json";
|
private static final String APPLICATION_JSON = "application/json";
|
||||||
|
@ -27,9 +26,11 @@ public class RestAssured2IntegrationTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void before() throws Exception {
|
public static void before() throws Exception {
|
||||||
System.out.println("Setting up!");
|
System.out.println("Setting up!");
|
||||||
|
final int port = Util.getAvailablePort();
|
||||||
|
wireMockServer = new WireMockServer(port);
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
configureFor("localhost", PORT);
|
configureFor("localhost", port);
|
||||||
RestAssured.port = PORT;
|
RestAssured.port = port;
|
||||||
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
||||||
aResponse().withStatus(200)
|
aResponse().withStatus(200)
|
||||||
.withHeader("Content-Type", APPLICATION_JSON)
|
.withHeader("Content-Type", APPLICATION_JSON)
|
||||||
|
|
|
@ -21,8 +21,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
|
||||||
public class RestAssuredIntegrationTest {
|
public class RestAssuredIntegrationTest {
|
||||||
private static final int PORT = 8083;
|
private static WireMockServer wireMockServer;
|
||||||
private static WireMockServer wireMockServer = new WireMockServer(PORT);
|
|
||||||
|
|
||||||
private static final String EVENTS_PATH = "/events?id=390";
|
private static final String EVENTS_PATH = "/events?id=390";
|
||||||
private static final String APPLICATION_JSON = "application/json";
|
private static final String APPLICATION_JSON = "application/json";
|
||||||
|
@ -31,9 +30,11 @@ public class RestAssuredIntegrationTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void before() throws Exception {
|
public static void before() throws Exception {
|
||||||
System.out.println("Setting up!");
|
System.out.println("Setting up!");
|
||||||
|
final int port = Util.getAvailablePort();
|
||||||
|
wireMockServer = new WireMockServer(port);
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
RestAssured.port = PORT;
|
RestAssured.port = port;
|
||||||
configureFor("localhost", PORT);
|
configureFor("localhost", port);
|
||||||
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
||||||
aResponse().withStatus(200)
|
aResponse().withStatus(200)
|
||||||
.withHeader("Content-Type", APPLICATION_JSON)
|
.withHeader("Content-Type", APPLICATION_JSON)
|
||||||
|
|
|
@ -12,11 +12,11 @@ import static com.github.tomakehurst.wiremock.client.WireMock.get;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
|
||||||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
|
||||||
import static io.restassured.RestAssured.get;
|
import static io.restassured.RestAssured.get;
|
||||||
|
import static io.restassured.RestAssured.port;
|
||||||
import static org.hamcrest.Matchers.hasItems;
|
import static org.hamcrest.Matchers.hasItems;
|
||||||
|
|
||||||
public class RestAssuredXML2IntegrationTest {
|
public class RestAssuredXML2IntegrationTest {
|
||||||
private static final int PORT = 8082;
|
private static WireMockServer wireMockServer;
|
||||||
private static WireMockServer wireMockServer = new WireMockServer(PORT);
|
|
||||||
|
|
||||||
private static final String EVENTS_PATH = "/teachers";
|
private static final String EVENTS_PATH = "/teachers";
|
||||||
private static final String APPLICATION_XML = "application/xml";
|
private static final String APPLICATION_XML = "application/xml";
|
||||||
|
@ -25,9 +25,11 @@ public class RestAssuredXML2IntegrationTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void before() throws Exception {
|
public static void before() throws Exception {
|
||||||
System.out.println("Setting up!");
|
System.out.println("Setting up!");
|
||||||
|
final int port = Util.getAvailablePort();
|
||||||
|
wireMockServer = new WireMockServer(port);
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
RestAssured.port = PORT;
|
RestAssured.port = port;
|
||||||
configureFor("localhost", PORT);
|
configureFor("localhost", port);
|
||||||
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn(
|
||||||
aResponse().withStatus(200)
|
aResponse().withStatus(200)
|
||||||
.withHeader("Content-Type", APPLICATION_XML)
|
.withHeader("Content-Type", APPLICATION_XML)
|
||||||
|
|
|
@ -17,8 +17,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.xml.HasXPath.hasXPath;
|
import static org.hamcrest.xml.HasXPath.hasXPath;
|
||||||
|
|
||||||
public class RestAssuredXMLIntegrationTest {
|
public class RestAssuredXMLIntegrationTest {
|
||||||
private static final int PORT = 8081;
|
private static WireMockServer wireMockServer;
|
||||||
private static WireMockServer wireMockServer = new WireMockServer(PORT);
|
|
||||||
|
|
||||||
private static final String EVENTS_PATH = "/employees";
|
private static final String EVENTS_PATH = "/employees";
|
||||||
private static final String APPLICATION_XML = "application/xml";
|
private static final String APPLICATION_XML = "application/xml";
|
||||||
|
@ -27,9 +26,11 @@ public class RestAssuredXMLIntegrationTest {
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void before() throws Exception {
|
public static void before() throws Exception {
|
||||||
System.out.println("Setting up!");
|
System.out.println("Setting up!");
|
||||||
|
final int port = Util.getAvailablePort();
|
||||||
|
wireMockServer = new WireMockServer(port);
|
||||||
wireMockServer.start();
|
wireMockServer.start();
|
||||||
configureFor("localhost", PORT);
|
configureFor("localhost", port);
|
||||||
RestAssured.port = PORT;
|
RestAssured.port = port;
|
||||||
stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn(
|
stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn(
|
||||||
aResponse().withStatus(200)
|
aResponse().withStatus(200)
|
||||||
.withHeader("Content-Type", APPLICATION_XML)
|
.withHeader("Content-Type", APPLICATION_XML)
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue