merge upstream
This commit is contained in:
commit
96adba789d
|
@ -41,7 +41,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<akka.http.version>10.0.11</akka.http.version>
|
<akka.http.version>10.0.11</akka.http.version>
|
||||||
<akka.stream.version>2.5.11</akka.stream.version>
|
<akka.stream.version>2.5.11</akka.stream.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -54,7 +54,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<io.jenetics.version>3.7.0</io.jenetics.version>
|
<io.jenetics.version>3.7.0</io.jenetics.version>
|
||||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||||
|
|
|
@ -74,7 +74,6 @@
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||||
<commons-codec.version>1.11</commons-codec.version>
|
<commons-codec.version>1.11</commons-codec.version>
|
||||||
|
|
|
@ -84,7 +84,6 @@
|
||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<tradukisto.version>1.0.1</tradukisto.version>
|
<tradukisto.version>1.0.1</tradukisto.version>
|
||||||
<org.jgrapht.core.version>1.0.1</org.jgrapht.core.version>
|
<org.jgrapht.core.version>1.0.1</org.jgrapht.core.version>
|
||||||
|
|
|
@ -49,7 +49,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||||
<commons-codec.version>1.11</commons-codec.version>
|
<commons-codec.version>1.11</commons-codec.version>
|
||||||
|
|
|
@ -82,7 +82,6 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<compiler-plugin.version>3.5</compiler-plugin.version>
|
<compiler-plugin.version>3.5</compiler-plugin.version>
|
||||||
<avro.version>1.8.2</avro.version>
|
<avro.version>1.8.2</avro.version>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<slf4j.version>1.7.25</slf4j.version>
|
<slf4j.version>1.7.25</slf4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson-databind.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -59,7 +59,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<curator.version>4.0.1</curator.version>
|
<curator.version>4.0.1</curator.version>
|
||||||
<zookeeper.version>3.4.11</zookeeper.version>
|
<zookeeper.version>3.4.11</zookeeper.version>
|
||||||
<jackson-databind.version>2.9.7</jackson-databind.version>
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
|
@ -32,8 +32,8 @@
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${java.version}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
@ -41,7 +41,5 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<geode.core>1.6.0</geode.core>
|
<geode.core>1.6.0</geode.core>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
|
@ -56,8 +56,8 @@
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${java.version}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -85,8 +85,6 @@
|
||||||
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
|
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
|
||||||
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
|
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
|
||||||
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
|
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,6 @@
|
||||||
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
||||||
<docker-maven-plugin.version>1.1.0</docker-maven-plugin.version>
|
<docker-maven-plugin.version>1.1.0</docker-maven-plugin.version>
|
||||||
<azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version>
|
<azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -66,7 +66,6 @@
|
||||||
<aspectjweaver.version>1.9.2</aspectjweaver.version>
|
<aspectjweaver.version>1.9.2</aspectjweaver.version>
|
||||||
<hamcrest-core.version>1.3</hamcrest-core.version>
|
<hamcrest-core.version>1.3</hamcrest-core.version>
|
||||||
<assertj-core.version>3.10.0</assertj-core.version>
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<spring.version>5.1.2.RELEASE</spring.version>
|
<spring.version>5.1.2.RELEASE</spring.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -23,6 +23,12 @@
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
<artifactId>groovy-all</artifactId>
|
<artifactId>groovy-all</artifactId>
|
||||||
<version>${groovy-all.version}</version>
|
<version>${groovy-all.version}</version>
|
||||||
|
<type>pom</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy-dateutil</artifactId>
|
||||||
|
<version>${groovy.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
@ -103,9 +109,12 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<junit.platform.version>1.0.0</junit.platform.version>
|
<junit.platform.version>1.0.0</junit.platform.version>
|
||||||
<groovy.version>2.4.13</groovy.version>
|
<!-- <groovy.version>2.4.13</groovy.version> -->
|
||||||
<groovy-all.version>2.4.13</groovy-all.version>
|
<!-- <groovy-all.version>2.4.13</groovy-all.version> -->
|
||||||
<groovy-sql.version>2.4.13</groovy-sql.version>
|
<!-- <groovy-sql.version>2.4.13</groovy-sql.version> -->
|
||||||
|
<groovy.version>2.5.6</groovy.version>
|
||||||
|
<groovy-all.version>2.5.6</groovy-all.version>
|
||||||
|
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||||
<hsqldb.version>2.4.0</hsqldb.version>
|
<hsqldb.version>2.4.0</hsqldb.version>
|
||||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.baeldung.groovy.sql
|
||||||
|
|
||||||
|
import static org.junit.Assert.*
|
||||||
|
import java.util.Calendar.*
|
||||||
|
import java.time.LocalDate
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import org.junit.Test
|
||||||
|
|
||||||
|
|
||||||
|
class DateTest {
|
||||||
|
|
||||||
|
def dateStr = "2019-02-28"
|
||||||
|
def pattern = "yyyy-MM-dd"
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGetStringRepresentation_thenCorrectlyConvertIntoDate() {
|
||||||
|
def dateFormat = new SimpleDateFormat(pattern)
|
||||||
|
def date = dateFormat.parse(dateStr)
|
||||||
|
|
||||||
|
println(" String to Date with DateFormatter : " + date)
|
||||||
|
|
||||||
|
def cal = new GregorianCalendar();
|
||||||
|
cal.setTime(date);
|
||||||
|
|
||||||
|
assertEquals(cal.get(Calendar.YEAR),2019)
|
||||||
|
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
|
||||||
|
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGetStringRepresentation_thenCorrectlyConvertWithDateUtilsExtension() {
|
||||||
|
|
||||||
|
def date = Date.parse(pattern, dateStr)
|
||||||
|
|
||||||
|
println(" String to Date with Date.parse : " + date)
|
||||||
|
|
||||||
|
def cal = new GregorianCalendar();
|
||||||
|
cal.setTime(date);
|
||||||
|
|
||||||
|
assertEquals(cal.get(Calendar.YEAR),2019)
|
||||||
|
assertEquals(cal.get(Calendar.DAY_OF_MONTH),28)
|
||||||
|
assertEquals(cal.get(Calendar.MONTH),java.util.Calendar.FEBRUARY)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGetStringRepresentation_thenCorrectlyConvertIntoDateWithLocalDate() {
|
||||||
|
def date = LocalDate.parse(dateStr, pattern)
|
||||||
|
|
||||||
|
println(" String to Date with LocalDate : " + date)
|
||||||
|
|
||||||
|
assertEquals(date.getYear(),2019)
|
||||||
|
assertEquals(date.getMonth(),java.time.Month.FEBRUARY)
|
||||||
|
assertEquals(date.getDayOfMonth(),28)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package com.baeldung.epsilongc;
|
||||||
|
|
||||||
|
public class MemoryPolluter {
|
||||||
|
|
||||||
|
private static final int MEGABYTE_IN_BYTES = 1024 * 1024;
|
||||||
|
private static final int ITERATION_COUNT = 1024 * 10;
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Starting pollution");
|
||||||
|
|
||||||
|
for (int i = 0; i < ITERATION_COUNT; i++) {
|
||||||
|
byte[] array = new byte[MEGABYTE_IN_BYTES];
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Terminating");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -180,7 +180,6 @@
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<joda.version>2.10</joda.version>
|
<joda.version>2.10</joda.version>
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
package com.baeldung.streamreduce.application;
|
||||||
|
|
||||||
|
import com.baeldung.streamreduce.entities.User;
|
||||||
|
import com.baeldung.streamreduce.utilities.NumberUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
int result1 = numbers.stream().reduce(0, (a, b) -> a + b);
|
||||||
|
System.out.println(result1);
|
||||||
|
|
||||||
|
int result2 = numbers.stream().reduce(0, Integer::sum);
|
||||||
|
System.out.println(result2);
|
||||||
|
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result3 = letters.stream().reduce("", (a, b) -> a + b);
|
||||||
|
System.out.println(result3);
|
||||||
|
|
||||||
|
String result4 = letters.stream().reduce("", String::concat);
|
||||||
|
System.out.println(result4);
|
||||||
|
|
||||||
|
String result5 = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
|
||||||
|
System.out.println(result5);
|
||||||
|
|
||||||
|
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||||
|
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
System.out.println(result6);
|
||||||
|
|
||||||
|
String result7 = letters.parallelStream().reduce("", String::concat);
|
||||||
|
System.out.println(result7);
|
||||||
|
|
||||||
|
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
System.out.println(result8);
|
||||||
|
|
||||||
|
List<User> userList = new ArrayList<>();
|
||||||
|
for (int i = 0; i <= 1000000; i++) {
|
||||||
|
userList.add(new User("John" + i, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
long t1 = System.currentTimeMillis();
|
||||||
|
int result9 = userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
long t2 = System.currentTimeMillis();
|
||||||
|
System.out.println(result9);
|
||||||
|
System.out.println("Sequential stream time: " + (t2 - t1) + "ms");
|
||||||
|
|
||||||
|
long t3 = System.currentTimeMillis();
|
||||||
|
int result10 = userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
long t4 = System.currentTimeMillis();
|
||||||
|
System.out.println(result10);
|
||||||
|
System.out.println("Parallel stream time: " + (t4 - t3) + "ms");
|
||||||
|
|
||||||
|
int result11 = NumberUtils.divideListElements(numbers, 1);
|
||||||
|
System.out.println(result11);
|
||||||
|
|
||||||
|
int result12 = NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0);
|
||||||
|
System.out.println(result12);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.baeldung.streamreduce.entities;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int age;
|
||||||
|
|
||||||
|
public User(String name, int age) {
|
||||||
|
this.name = name;
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" + "name=" + name + ", age=" + age + '}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.baeldung.streamreduce.utilities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public abstract class NumberUtils {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
|
||||||
|
|
||||||
|
public static int divideListElements(List<Integer> values, Integer divider) {
|
||||||
|
return values.stream()
|
||||||
|
.reduce(0, (a, b) -> {
|
||||||
|
try {
|
||||||
|
return a / divider + b / divider;
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
|
||||||
|
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
|
||||||
|
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
|
||||||
|
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int divide(int value, int factor) {
|
||||||
|
int result = 0;
|
||||||
|
try {
|
||||||
|
result = value / factor;
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
|
||||||
|
try {
|
||||||
|
return function.apply(a, b);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
LOGGER.log(Level.INFO, "Exception occurred!");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.baeldung.streamreduce.tests;
|
||||||
|
|
||||||
|
import com.baeldung.streamreduce.entities.User;
|
||||||
|
import com.baeldung.streamreduce.utilities.NumberUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class StreamReduceManualTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
int result = numbers.stream().reduce(0, (a, b) -> a + b);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
int result = numbers.stream().reduce(0, Integer::sum);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
|
||||||
|
String result = letters.stream().reduce("", (a, b) -> a + b);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
|
||||||
|
String result = letters.stream().reduce("", String::concat);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
|
||||||
|
String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("ABCDE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
|
||||||
|
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||||
|
|
||||||
|
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo(65);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
|
||||||
|
String result = letters.parallelStream().reduce("", String::concat);
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndListContainsZero_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(0, 1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlockAndDividerIsZero_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 0)).isEqualTo(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
|
||||||
|
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTwoStreams_whenCalledReduceOnParallelizedStream_thenFasterExecutionTime() {
|
||||||
|
List<User> userList = new ArrayList<>();
|
||||||
|
for (int i = 0; i <= 1000000; i++) {
|
||||||
|
userList.add(new User("John" + i, i));
|
||||||
|
}
|
||||||
|
long currentTime1 = System.currentTimeMillis();
|
||||||
|
userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
long sequentialExecutionTime = System.currentTimeMillis() -currentTime1;
|
||||||
|
long currentTime2 = System.currentTimeMillis();
|
||||||
|
userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
long parallelizedExecutionTime = System.currentTimeMillis() - currentTime2;
|
||||||
|
|
||||||
|
assertThat(parallelizedExecutionTime).isLessThan(sequentialExecutionTime);
|
||||||
|
}
|
||||||
|
}
|
|
@ -390,7 +390,6 @@
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
|
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
<jmh-core.version>1.19</jmh-core.version>
|
||||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||||
|
|
|
@ -27,3 +27,4 @@
|
||||||
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
|
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
|
||||||
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
|
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
|
||||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||||
|
- [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal)
|
||||||
|
|
|
@ -70,7 +70,6 @@
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<trove4j.version>3.0.2</trove4j.version>
|
<trove4j.version>3.0.2</trove4j.version>
|
||||||
<fastutil.version>8.1.0</fastutil.version>
|
<fastutil.version>8.1.0</fastutil.version>
|
||||||
<colt.version>1.2.0</colt.version>
|
<colt.version>1.2.0</colt.version>
|
||||||
|
|
|
@ -73,7 +73,6 @@
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<eclipse.collections.version>7.1.0</eclipse.collections.version>
|
<eclipse.collections.version>7.1.0</eclipse.collections.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<commons-exec.version>1.3</commons-exec.version>
|
<commons-exec.version>1.3</commons-exec.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -246,8 +246,6 @@
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- marshalling -->
|
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
|
@ -259,7 +257,6 @@
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
<grep4j.version>1.8.7</grep4j.version>
|
<grep4j.version>1.8.7</grep4j.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<fscontext.version>4.6-b01</fscontext.version>
|
<fscontext.version>4.6-b01</fscontext.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
|
|
@ -82,7 +82,6 @@
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj-core.version>3.10.0</assertj-core.version>
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
<equalsverifier.version>3.0.3</equalsverifier.version>
|
<equalsverifier.version>3.0.3</equalsverifier.version>
|
||||||
|
|
|
@ -74,14 +74,10 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<!-- marshalling -->
|
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
|
|
||||||
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
||||||
|
|
||||||
|
|
|
@ -13,4 +13,5 @@
|
||||||
- [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces)
|
- [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces)
|
||||||
- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets)
|
- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets)
|
||||||
- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding)
|
- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding)
|
||||||
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
||||||
|
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
|
||||||
|
|
|
@ -261,8 +261,6 @@
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- marshalling -->
|
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>23.0</guava.version>
|
<guava.version>23.0</guava.version>
|
||||||
|
@ -275,7 +273,6 @@
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
<grep4j.version>1.8.7</grep4j.version>
|
<grep4j.version>1.8.7</grep4j.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<fscontext.version>4.6-b01</fscontext.version>
|
<fscontext.version>4.6-b01</fscontext.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
- [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)
|
||||||
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
|
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
|
||||||
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
|
|
||||||
- [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 Java Stack](http://www.baeldung.com/java-stack)
|
- [Quick Guide to Java Stack](http://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)
|
||||||
|
|
|
@ -451,7 +451,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
|
@ -461,7 +460,6 @@
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
<grep4j.version>1.8.7</grep4j.version>
|
<grep4j.version>1.8.7</grep4j.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<fscontext.version>4.6-b01</fscontext.version>
|
<fscontext.version>4.6-b01</fscontext.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.baeldung.urlconnection;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class PostJSONWithHttpURLConnection {
|
||||||
|
|
||||||
|
public static void main (String []args) throws IOException{
|
||||||
|
//Change the URL with any other publicly accessible POST resource, which accepts JSON request body
|
||||||
|
URL url = new URL ("https://reqres.in/api/users");
|
||||||
|
|
||||||
|
HttpURLConnection con = (HttpURLConnection)url.openConnection();
|
||||||
|
con.setRequestMethod("POST");
|
||||||
|
|
||||||
|
con.setRequestProperty("Content-Type", "application/json; utf-8");
|
||||||
|
con.setRequestProperty("Accept", "application/json");
|
||||||
|
|
||||||
|
con.setDoOutput(true);
|
||||||
|
|
||||||
|
//JSON String need to be constructed for the specific resource.
|
||||||
|
//We may construct complex JSON using any third-party JSON libraries such as jackson or org.json
|
||||||
|
String jsonInputString = "{\"name\": \"Upendra\", \"job\": \"Programmer\"}";
|
||||||
|
|
||||||
|
try(OutputStream os = con.getOutputStream()){
|
||||||
|
byte[] input = jsonInputString.getBytes("utf-8");
|
||||||
|
os.write(input, 0, input.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
int code = con.getResponseCode();
|
||||||
|
System.out.println(code);
|
||||||
|
|
||||||
|
try(BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream(), "utf-8"))){
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String responseLine = null;
|
||||||
|
while ((responseLine = br.readLine()) != null) {
|
||||||
|
response.append(responseLine.trim());
|
||||||
|
}
|
||||||
|
System.out.println(response.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1 +1,3 @@
|
||||||
## Relevant articles:
|
## Relevant articles:
|
||||||
|
|
||||||
|
- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type)
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
package stringcomparison
|
||||||
|
|
||||||
|
import org.junit.Test
|
||||||
|
import kotlin.test.assertFalse
|
||||||
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
class StringComparisonUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `compare using equals operator`() {
|
||||||
|
val first = "kotlin"
|
||||||
|
val second = "kotlin"
|
||||||
|
val firstCapitalized = "KOTLIN"
|
||||||
|
assertTrue { first == second }
|
||||||
|
assertFalse { first == firstCapitalized }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `compare using referential equals operator`() {
|
||||||
|
val first = "kotlin"
|
||||||
|
val second = "kotlin"
|
||||||
|
val copyOfFirst = buildString { "kotlin" }
|
||||||
|
assertTrue { first === second }
|
||||||
|
assertFalse { first === copyOfFirst }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `compare using equals method`() {
|
||||||
|
val first = "kotlin"
|
||||||
|
val second = "kotlin"
|
||||||
|
val firstCapitalized = "KOTLIN"
|
||||||
|
assertTrue { first.equals(second) }
|
||||||
|
assertFalse { first.equals(firstCapitalized) }
|
||||||
|
assertTrue { first.equals(firstCapitalized, true) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `compare using compare method`() {
|
||||||
|
val first = "kotlin"
|
||||||
|
val second = "kotlin"
|
||||||
|
val firstCapitalized = "KOTLIN"
|
||||||
|
assertTrue { first.compareTo(second) == 0 }
|
||||||
|
assertTrue { first.compareTo(firstCapitalized) == 32 }
|
||||||
|
assertTrue { firstCapitalized.compareTo(first) == -32 }
|
||||||
|
assertTrue { first.compareTo(firstCapitalized, true) == 0 }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,114 @@
|
||||||
|
package com.baeldung.kotlin.dsl
|
||||||
|
|
||||||
|
abstract class Condition {
|
||||||
|
|
||||||
|
fun and(initializer: Condition.() -> Unit) {
|
||||||
|
addCondition(And().apply(initializer))
|
||||||
|
}
|
||||||
|
|
||||||
|
fun or(initializer: Condition.() -> Unit) {
|
||||||
|
addCondition(Or().apply(initializer))
|
||||||
|
}
|
||||||
|
|
||||||
|
infix fun String.eq(value: Any?) {
|
||||||
|
addCondition(Eq(this, value))
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract fun addCondition(condition: Condition)
|
||||||
|
}
|
||||||
|
|
||||||
|
open class CompositeCondition(private val sqlOperator: String) : Condition() {
|
||||||
|
private val conditions = mutableListOf<Condition>()
|
||||||
|
|
||||||
|
override fun addCondition(condition: Condition) {
|
||||||
|
conditions += condition
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return if (conditions.size == 1) {
|
||||||
|
conditions.first().toString()
|
||||||
|
} else {
|
||||||
|
conditions.joinToString(prefix = "(", postfix = ")", separator = " $sqlOperator ") {
|
||||||
|
"$it"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class And : CompositeCondition("and")
|
||||||
|
|
||||||
|
class Or : CompositeCondition("or")
|
||||||
|
|
||||||
|
class Eq(private val column: String, private val value: Any?) : Condition() {
|
||||||
|
|
||||||
|
init {
|
||||||
|
if (value != null && value !is Number && value !is String) {
|
||||||
|
throw IllegalArgumentException("Only <null>, numbers and strings values can be used in the 'where' clause")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun addCondition(condition: Condition) {
|
||||||
|
throw IllegalStateException("Can't add a nested condition to the sql 'eq'")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
return when (value) {
|
||||||
|
null -> "$column is null"
|
||||||
|
is String -> "$column = '$value'"
|
||||||
|
else -> "$column = $value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SqlSelectBuilder {
|
||||||
|
|
||||||
|
private val columns = mutableListOf<String>()
|
||||||
|
private lateinit var table: String
|
||||||
|
private var condition: Condition? = null
|
||||||
|
|
||||||
|
fun select(vararg columns: String) {
|
||||||
|
if (columns.isEmpty()) {
|
||||||
|
throw IllegalArgumentException("At least one column should be defined")
|
||||||
|
}
|
||||||
|
if (this.columns.isNotEmpty()) {
|
||||||
|
throw IllegalStateException("Detected an attempt to re-define columns to fetch. Current columns list: "
|
||||||
|
+ "${this.columns}, new columns list: $columns")
|
||||||
|
}
|
||||||
|
this.columns.addAll(columns)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun from(table: String) {
|
||||||
|
this.table = table
|
||||||
|
}
|
||||||
|
|
||||||
|
fun where(initializer: Condition.() -> Unit) {
|
||||||
|
condition = And().apply(initializer)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun build(): String {
|
||||||
|
if (!::table.isInitialized) {
|
||||||
|
throw IllegalStateException("Failed to build an sql select - target table is undefined")
|
||||||
|
}
|
||||||
|
return toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun toString(): String {
|
||||||
|
val columnsToFetch =
|
||||||
|
if (columns.isEmpty()) {
|
||||||
|
"*"
|
||||||
|
} else {
|
||||||
|
columns.joinToString(", ")
|
||||||
|
}
|
||||||
|
val conditionString =
|
||||||
|
if (condition == null) {
|
||||||
|
""
|
||||||
|
} else {
|
||||||
|
" where $condition"
|
||||||
|
}
|
||||||
|
return "select $columnsToFetch from $table$conditionString"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun query(initializer: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
|
||||||
|
return SqlSelectBuilder().apply(initializer)
|
||||||
|
}
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.baeldung.kotlin.dsl
|
||||||
|
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.junit.Test
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
class SqlDslTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when no columns are specified then star is used`() {
|
||||||
|
doTest("select * from table1") {
|
||||||
|
from ("table1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when no condition is specified then correct query is built`() {
|
||||||
|
doTest("select column1, column2 from table1") {
|
||||||
|
select("column1", "column2")
|
||||||
|
from ("table1")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = Exception::class)
|
||||||
|
fun `when no table is specified then an exception is thrown`() {
|
||||||
|
query {
|
||||||
|
select("column1")
|
||||||
|
}.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when a list of conditions is specified then it's respected`() {
|
||||||
|
doTest("select * from table1 where (column3 = 4 and column4 is null)") {
|
||||||
|
from ("table1")
|
||||||
|
where {
|
||||||
|
"column3" eq 4
|
||||||
|
"column4" eq null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when 'or' conditions are specified then they are respected`() {
|
||||||
|
doTest("select * from table1 where (column3 = 4 or column4 is null)") {
|
||||||
|
from ("table1")
|
||||||
|
where {
|
||||||
|
or {
|
||||||
|
"column3" eq 4
|
||||||
|
"column4" eq null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `when either 'and' or 'or' conditions are specified then they are respected`() {
|
||||||
|
doTest("select * from table1 where ((column3 = 4 or column4 is null) and column5 = 42)") {
|
||||||
|
from ("table1")
|
||||||
|
where {
|
||||||
|
and {
|
||||||
|
or {
|
||||||
|
"column3" eq 4
|
||||||
|
"column4" eq null
|
||||||
|
}
|
||||||
|
"column5" eq 42
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doTest(expected: String, sql: SqlSelectBuilder.() -> Unit) {
|
||||||
|
assertThat(query(sql).build()).isEqualTo(expected)
|
||||||
|
}
|
||||||
|
}
|
|
@ -25,7 +25,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson-version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- Spring Context for Dependency Injection -->
|
<!-- Spring Context for Dependency Injection -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -70,7 +70,6 @@
|
||||||
<couchbase.client.version>2.5.0</couchbase.client.version>
|
<couchbase.client.version>2.5.0</couchbase.client.version>
|
||||||
<spring-framework.version>4.3.5.RELEASE</spring-framework.version>
|
<spring-framework.version>4.3.5.RELEASE</spring-framework.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<jackson-version>2.9.7</jackson-version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
<description>DDD series examples</description>
|
<description>DDD series examples</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<groupId>com.baeldung</groupId>
|
||||||
<version>2.0.6.RELEASE</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath /> <!-- lookup parent from repository -->
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -86,6 +86,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<joda-money.version>1.0.1</joda-money.version>
|
<joda-money.version>1.0.1</joda-money.version>
|
||||||
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.22.0</maven-surefire-plugin.version>
|
||||||
|
<spring-boot.version>2.0.6.RELEASE</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -11,7 +11,7 @@ import org.joda.money.Money;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
class OrderTest {
|
class OrderUnitTest {
|
||||||
@DisplayName("given order with two items, when calculate total cost, then sum is returned")
|
@DisplayName("given order with two items, when calculate total cost, then sum is returned")
|
||||||
@Test
|
@Test
|
||||||
void test0() throws Exception {
|
void test0() throws Exception {
|
|
@ -7,7 +7,7 @@ import java.math.BigDecimal;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class ViolateOrderBusinessRulesTest {
|
public class ViolateOrderBusinessRulesUnitTest {
|
||||||
@DisplayName("given two non-zero order line items, when create an order with them, it's possible to set total cost to zero")
|
@DisplayName("given two non-zero order line items, when create an order with them, it's possible to set total cost to zero")
|
||||||
@Test
|
@Test
|
||||||
void test() throws Exception {
|
void test() throws Exception {
|
|
@ -208,15 +208,12 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<tomcat.version>8.5.4</tomcat.version>
|
<tomcat.version>8.5.4</tomcat.version>
|
||||||
<ethereumj-core.version>1.5.0-RELEASE</ethereumj-core.version>
|
<ethereumj-core.version>1.5.0-RELEASE</ethereumj-core.version>
|
||||||
<web3j.core.version>3.3.1</web3j.core.version>
|
<web3j.core.version>3.3.1</web3j.core.version>
|
||||||
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
|
<spring.boot.version>1.5.6.RELEASE</spring.boot.version>
|
||||||
<mockito.version>2.21.0</mockito.version>
|
<mockito.version>2.21.0</mockito.version>
|
||||||
<jackson-databind.version>2.9.7</jackson-databind.version>
|
|
||||||
<hamcrest.version>1.3</hamcrest.version>
|
<hamcrest.version>1.3</hamcrest.version>
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
<javax-jsp.version>2.3.1</javax-jsp.version>
|
<javax-jsp.version>2.3.1</javax-jsp.version>
|
||||||
<javax-servlet.version>3.1.0</javax-servlet.version>
|
<javax-servlet.version>3.1.0</javax-servlet.version>
|
||||||
<jsonpath.version>2.4.0</jsonpath.version>
|
<jsonpath.version>2.4.0</jsonpath.version>
|
||||||
|
|
|
@ -56,7 +56,6 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<feign.version>9.4.0</feign.version>
|
<feign.version>9.4.0</feign.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
<spring-boot-maven-plugin.version>1.4.2.RELEASE</spring-boot-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -33,24 +33,11 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>maven2-repository.dev.java.net</id>
|
|
||||||
<name>Java.net repository</name>
|
|
||||||
<url>http://download.java.net/maven/2</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>osgeo</id>
|
<id>osgeo</id>
|
||||||
<name>Open Source Geospatial Foundation Repository</name>
|
<name>Open Source Geospatial Foundation Repository</name>
|
||||||
<url>http://download.osgeo.org/webdav/geotools/</url>
|
<url>http://download.osgeo.org/webdav/geotools/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<snapshots>
|
|
||||||
<enabled>true</enabled>
|
|
||||||
</snapshots>
|
|
||||||
<id>opengeo</id>
|
|
||||||
<name>OpenGeo Maven Repository</name>
|
|
||||||
<url>http://repo.opengeo.org</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
package org.baeldung.gson.conversion;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class JsonObjectConversionsUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingJsonParser_thenConvertToJsonObject() throws Exception {
|
||||||
|
// Example 1: Using JsonParser
|
||||||
|
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||||
|
|
||||||
|
JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();
|
||||||
|
|
||||||
|
Assert.assertTrue(jsonObject.isJsonObject());
|
||||||
|
Assert.assertTrue(jsonObject.get("name").getAsString().equals("Baeldung"));
|
||||||
|
Assert.assertTrue(jsonObject.get("java").getAsBoolean() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenUsingGsonInstanceFromJson_thenConvertToJsonObject() throws Exception {
|
||||||
|
// Example 2: Using fromJson
|
||||||
|
String json = "{ \"name\": \"Baeldung\", \"java\": true }";
|
||||||
|
|
||||||
|
JsonObject convertedObject = new Gson().fromJson(json, JsonObject.class);
|
||||||
|
|
||||||
|
Assert.assertTrue(convertedObject.isJsonObject());
|
||||||
|
Assert.assertTrue(convertedObject.get("name").getAsString().equals("Baeldung"));
|
||||||
|
Assert.assertTrue(convertedObject.get("java").getAsBoolean() == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -21,7 +21,7 @@ import com.stackify.Application;
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
public class EmployeeControllerTest {
|
public class EmployeeControllerUnitTest {
|
||||||
|
|
||||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||||
|
|
|
@ -117,8 +117,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- marshalling -->
|
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.8</commons-lang3.version>
|
<commons-lang3.version>3.8</commons-lang3.version>
|
||||||
<joda-time.version>2.10</joda-time.version>
|
<joda-time.version>2.10</joda-time.version>
|
||||||
|
|
|
@ -1,16 +1,9 @@
|
||||||
package com.baeldung.jackson.dtos;
|
package com.baeldung.jackson.dtos;
|
||||||
|
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
|
|
||||||
|
|
||||||
public class Address {
|
public class Address {
|
||||||
|
|
||||||
@JacksonXmlProperty(localName = "street_number")
|
|
||||||
String streetNumber;
|
String streetNumber;
|
||||||
|
|
||||||
@JacksonXmlProperty(localName = "street_name")
|
|
||||||
String streetName;
|
String streetName;
|
||||||
|
|
||||||
@JacksonXmlProperty(localName = "city")
|
|
||||||
String city;
|
String city;
|
||||||
|
|
||||||
public String getStreetNumber() {
|
public String getStreetNumber() {
|
||||||
|
|
|
@ -3,16 +3,13 @@ package com.baeldung.jackson.dtos;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
|
|
||||||
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
|
||||||
|
|
||||||
@JacksonXmlRootElement(localName = "person")
|
@JacksonXmlRootElement(localName = "person")
|
||||||
public final class Person {
|
public final class Person {
|
||||||
private String firstName;
|
private String firstName;
|
||||||
private String lastName;
|
private String lastName;
|
||||||
@JacksonXmlElementWrapper(useWrapping = false)
|
|
||||||
private List<String> phoneNumbers = new ArrayList<>();
|
private List<String> phoneNumbers = new ArrayList<>();
|
||||||
@JacksonXmlElementWrapper(localName = "addresses")
|
|
||||||
private List<Address> address = new ArrayList<>();
|
private List<Address> address = new ArrayList<>();
|
||||||
|
|
||||||
public List<Address> getAddress() {
|
public List<Address> getAddress() {
|
||||||
|
@ -38,6 +35,7 @@ public final class Person {
|
||||||
public void setLastName(String lastName) {
|
public void setLastName(String lastName) {
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getPhoneNumbers() {
|
public List<String> getPhoneNumbers() {
|
||||||
return phoneNumbers;
|
return phoneNumbers;
|
||||||
}
|
}
|
||||||
|
@ -46,6 +44,4 @@ public final class Person {
|
||||||
this.phoneNumbers = phoneNumbers;
|
this.phoneNumbers = phoneNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -2,8 +2,10 @@ package com.baeldung.jackson.xml;
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -56,17 +58,14 @@ public class XMLSerializeDeserializeUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
|
public void whenJavaGotFromXmlStrWithCapitalElem_thenCorrect() throws IOException {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
SimpleBeanForCapitalizedFields value = xmlMapper.
|
SimpleBeanForCapitalizedFields value = xmlMapper.readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>", SimpleBeanForCapitalizedFields.class);
|
||||||
readValue("<SimpleBeanForCapitalizedFields><X>1</X><y>2</y></SimpleBeanForCapitalizedFields>",
|
|
||||||
SimpleBeanForCapitalizedFields.class);
|
|
||||||
assertTrue(value.getX() == 1 && value.getY() == 2);
|
assertTrue(value.getX() == 1 && value.getY() == 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException {
|
public void whenJavaSerializedToXmlFileWithCapitalizedField_thenCorrect() throws IOException {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"),
|
xmlMapper.writeValue(new File("target/simple_bean_capitalized.xml"), new SimpleBeanForCapitalizedFields());
|
||||||
new SimpleBeanForCapitalizedFields());
|
|
||||||
File file = new File("target/simple_bean_capitalized.xml");
|
File file = new File("target/simple_bean_capitalized.xml");
|
||||||
assertNotNull(file);
|
assertNotNull(file);
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,9 @@ public class XMLSerializeDeserializeUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
|
public void whenJavaDeserializedFromXmlFile_thenCorrect() throws IOException {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
Person value = xmlMapper.readValue(new File("src/test/resources/person.xml"), Person.class);
|
|
||||||
|
String xml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
|
||||||
|
Person value = xmlMapper.readValue(xml, Person.class);
|
||||||
|
|
||||||
assertTrue(value.getAddress()
|
assertTrue(value.getAddress()
|
||||||
.get(0)
|
.get(0)
|
||||||
|
@ -90,33 +91,38 @@ public class XMLSerializeDeserializeUnitTest {
|
||||||
public void whenJavaSerializedToXmlFile_thenSuccess() throws IOException {
|
public void whenJavaSerializedToXmlFile_thenSuccess() throws IOException {
|
||||||
XmlMapper xmlMapper = new XmlMapper();
|
XmlMapper xmlMapper = new XmlMapper();
|
||||||
|
|
||||||
|
String expectedXml = "<person><firstName>Rohan</firstName><lastName>Daye</lastName><phoneNumbers><phoneNumbers>9911034731</phoneNumbers><phoneNumbers>9911033478</phoneNumbers></phoneNumbers><address><address><streetNumber>1</streetNumber><streetName>Name1</streetName><city>City1</city></address><address><streetNumber>2</streetNumber><streetName>Name2</streetName><city>City2</city></address></address></person>";
|
||||||
|
|
||||||
Person person = new Person();
|
Person person = new Person();
|
||||||
|
|
||||||
person.setFirstName("Rohan");
|
person.setFirstName("Rohan");
|
||||||
person.setLastName("Daye");
|
person.setLastName("Daye");
|
||||||
|
|
||||||
List<String> ph = new ArrayList<>();
|
List<String> ph = new ArrayList<>();
|
||||||
ph.add("9911778981");
|
ph.add("9911034731");
|
||||||
ph.add("9991111111");
|
ph.add("9911033478");
|
||||||
person.setPhoneNumbers(ph);
|
person.setPhoneNumbers(ph);
|
||||||
|
|
||||||
List<Address> addresses = new ArrayList<>();
|
List<Address> addresses = new ArrayList<>();
|
||||||
|
|
||||||
Address address1 = new Address();
|
Address address1 = new Address();
|
||||||
address1.setStreetNumber("1");
|
address1.setStreetNumber("1");
|
||||||
address1.setStreetName("streetname1");
|
address1.setStreetName("Name1");
|
||||||
address1.setCity("city1");
|
address1.setCity("City1");
|
||||||
|
|
||||||
Address address2 = new Address();
|
Address address2 = new Address();
|
||||||
address2.setStreetNumber("2");
|
address2.setStreetNumber("2");
|
||||||
address2.setStreetName("streetname2");
|
address2.setStreetName("Name2");
|
||||||
address2.setCity("city2");
|
address2.setCity("City2");
|
||||||
|
|
||||||
addresses.add(address1);
|
addresses.add(address1);
|
||||||
addresses.add(address2);
|
addresses.add(address2);
|
||||||
|
|
||||||
person.setAddress(addresses);
|
person.setAddress(addresses);
|
||||||
|
|
||||||
xmlMapper.writeValue(new File("src/test/resources/PersonGenerated.xml"), person);
|
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
||||||
|
xmlMapper.writeValue(byteArrayOutputStream, person);
|
||||||
|
assertEquals(expectedXml, byteArrayOutputStream.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String inputStreamToString(InputStream is) throws IOException {
|
private static String inputStreamToString(InputStream is) throws IOException {
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
<person>
|
|
||||||
<firstName></firstName>
|
|
||||||
<lastName></lastName>
|
|
||||||
<phoneNumbers>9911778981</phoneNumbers>
|
|
||||||
<phoneNumbers>9991111111</phoneNumbers>
|
|
||||||
<addresses>
|
|
||||||
<address>
|
|
||||||
<street_number>1</street_number>
|
|
||||||
<street_name>streetname1</street_name>
|
|
||||||
<city>city1</city>
|
|
||||||
</address>
|
|
||||||
<address>
|
|
||||||
<street_number>2</street_number>
|
|
||||||
<street_name>streetname2</street_name>
|
|
||||||
<city>city2</city>
|
|
||||||
</address>
|
|
||||||
</addresses>
|
|
||||||
</person>
|
|
|
@ -1,19 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<person>
|
|
||||||
<firstName>Rohan</firstName>
|
|
||||||
<lastName>Daye</lastName>
|
|
||||||
<phoneNumbers>9911034731</phoneNumbers>
|
|
||||||
<phoneNumbers>9911033478</phoneNumbers>
|
|
||||||
<addresses>
|
|
||||||
<address>
|
|
||||||
<street_number>1</street_number>
|
|
||||||
<street_name>Name1</street_name>
|
|
||||||
<city>City1</city>
|
|
||||||
</address>
|
|
||||||
<address>
|
|
||||||
<street_number>2</street_number>
|
|
||||||
<street_name>Name2</street_name>
|
|
||||||
<city>City2</city>
|
|
||||||
</address>
|
|
||||||
</addresses>
|
|
||||||
</person>
|
|
|
@ -76,7 +76,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<joda-time.version>2.10</joda-time.version>
|
<joda-time.version>2.10</joda-time.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
|
|
@ -58,6 +58,13 @@
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>app-auth-basic-store-db</module>
|
||||||
|
<module>app-auth-form-store-ldap</module>
|
||||||
|
<module>app-auth-custom-form-store-custom</module>
|
||||||
|
<module>app-auth-custom-no-store</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<defaultHttpPort>9080</defaultHttpPort>
|
<defaultHttpPort>9080</defaultHttpPort>
|
||||||
<defaultHttpsPort>9443</defaultHttpsPort>
|
<defaultHttpsPort>9443</defaultHttpsPort>
|
||||||
|
@ -70,11 +77,4 @@
|
||||||
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>app-auth-basic-store-db</module>
|
|
||||||
<module>app-auth-form-store-ldap</module>
|
|
||||||
<module>app-auth-custom-form-store-custom</module>
|
|
||||||
<module>app-auth-custom-no-store</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -95,7 +95,6 @@
|
||||||
<activeweb.version>1.15</activeweb.version>
|
<activeweb.version>1.15</activeweb.version>
|
||||||
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
|
<mysql.connector.java.version>5.1.45</mysql.connector.java.version>
|
||||||
<sun.tools.version>1.7.0</sun.tools.version>
|
<sun.tools.version>1.7.0</sun.tools.version>
|
||||||
<jackson.version>2.9.7</jackson.version>
|
|
||||||
<activeweb-testing.version>1.15</activeweb-testing.version>
|
<activeweb-testing.version>1.15</activeweb-testing.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,6 @@
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<jmh.version>1.21</jmh.version>
|
<jmh.version>1.21</jmh.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
|
||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
<protonpack.version>1.15</protonpack.version>
|
<protonpack.version>1.15</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package com.baeldung.reduce.application;
|
||||||
|
|
||||||
|
import com.baeldung.reduce.entities.User;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import org.openjdk.jmh.annotations.Benchmark;
|
||||||
|
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||||
|
import org.openjdk.jmh.annotations.Fork;
|
||||||
|
import org.openjdk.jmh.annotations.Mode;
|
||||||
|
import org.openjdk.jmh.annotations.Warmup;
|
||||||
|
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
|
||||||
|
System.out.println(result1);
|
||||||
|
|
||||||
|
int result2 = numbers.stream().reduce(0, Integer::sum);
|
||||||
|
System.out.println(result2);
|
||||||
|
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element);
|
||||||
|
System.out.println(result3);
|
||||||
|
|
||||||
|
String result4 = letters.stream().reduce("", String::concat);
|
||||||
|
System.out.println(result4);
|
||||||
|
|
||||||
|
String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
|
||||||
|
System.out.println(result5);
|
||||||
|
|
||||||
|
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||||
|
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
System.out.println(result6);
|
||||||
|
|
||||||
|
String result7 = letters.parallelStream().reduce("", String::concat);
|
||||||
|
System.out.println(result7);
|
||||||
|
|
||||||
|
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
System.out.println(result8);
|
||||||
|
|
||||||
|
org.openjdk.jmh.Main.main(args);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@Fork(value = 1, warmups = 2)
|
||||||
|
@Warmup(iterations = 2)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public void executeReduceOnParallelizedStream() {
|
||||||
|
List<User> userList = new ArrayList<>();
|
||||||
|
for (int i = 0; i <= 1000000; i++) {
|
||||||
|
userList.add(new User("John" + i, i));
|
||||||
|
}
|
||||||
|
userList.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Benchmark
|
||||||
|
@Fork(value = 1, warmups = 2)
|
||||||
|
@Warmup(iterations = 2)
|
||||||
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
|
public void executeReduceOnSequentialStream() {
|
||||||
|
List<User> userList = new ArrayList<>();
|
||||||
|
for (int i = 0; i <= 1000000; i++) {
|
||||||
|
userList.add(new User("John" + i, i));
|
||||||
|
}
|
||||||
|
userList.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.baeldung.reduce.entities;
|
||||||
|
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
private final String name;
|
||||||
|
private final int age;
|
||||||
|
|
||||||
|
public User(String name, int age) {
|
||||||
|
this.name = name;
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "User{" + "name=" + name + ", age=" + age + '}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package com.baeldung.reduce.utilities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public abstract class NumberUtils {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
|
||||||
|
|
||||||
|
public static int divideListElements(List<Integer> values, Integer divider) {
|
||||||
|
return values.stream()
|
||||||
|
.reduce(0, (a, b) -> {
|
||||||
|
try {
|
||||||
|
return a / divider + b / divider;
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
|
||||||
|
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
|
||||||
|
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
|
||||||
|
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int divide(int value, int factor) {
|
||||||
|
int result = 0;
|
||||||
|
try {
|
||||||
|
result = value / factor;
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
|
||||||
|
try {
|
||||||
|
return function.apply(a, b);
|
||||||
|
}
|
||||||
|
catch(Exception e) {
|
||||||
|
LOGGER.log(Level.INFO, "Exception occurred!");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.baeldung.reduce.tests;
|
||||||
|
|
||||||
|
import com.baeldung.reduce.entities.User;
|
||||||
|
import com.baeldung.reduce.utilities.NumberUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class StreamReduceUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
int result = numbers.stream().reduce(0, (a, b) -> a + b);
|
||||||
|
assertThat(result).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
int result = numbers.stream().reduce(0, Integer::sum);
|
||||||
|
assertThat(result).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result = letters.stream().reduce("", (a, b) -> a + b);
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result = letters.stream().reduce("", String::concat);
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result = letters.stream().reduce("", (a, b) -> a.toUpperCase() + b.toUpperCase());
|
||||||
|
assertThat(result).isEqualTo("ABCDE");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
|
||||||
|
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||||
|
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||||
|
assertThat(result).isEqualTo(65);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
|
||||||
|
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||||
|
String result = letters.parallelStream().reduce("", String::concat);
|
||||||
|
assertThat(result).isEqualTo("abcde");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
|
||||||
|
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||||
|
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
|
||||||
|
}
|
||||||
|
}
|
|
@ -55,8 +55,7 @@
|
||||||
<validation-api.version>2.0.1.Final</validation-api.version>
|
<validation-api.version>2.0.1.Final</validation-api.version>
|
||||||
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
|
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
|
||||||
<javax.el.version>3.0.0</javax.el.version>
|
<javax.el.version>3.0.0</javax.el.version>
|
||||||
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
|
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -7,6 +7,8 @@ public final class AuthoritiesConstants {
|
||||||
|
|
||||||
public static final String ADMIN = "ROLE_ADMIN";
|
public static final String ADMIN = "ROLE_ADMIN";
|
||||||
|
|
||||||
|
public static final String MANAGER = "ROLE_MANAGER";
|
||||||
|
|
||||||
public static final String USER = "ROLE_USER";
|
public static final String USER = "ROLE_USER";
|
||||||
|
|
||||||
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
|
public static final String ANONYMOUS = "ROLE_ANONYMOUS";
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
name
|
name
|
||||||
ROLE_ADMIN
|
ROLE_ADMIN
|
||||||
|
ROLE_MANAGER
|
||||||
ROLE_USER
|
ROLE_USER
|
||||||
|
|
|
|
@ -2,9 +2,8 @@
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.jhipster</groupId>
|
<artifactId>jhipster-uaa</artifactId>
|
||||||
<artifactId>jhipster-microservice-uaa</artifactId>
|
<name>jhipster-uaa</name>
|
||||||
<name>JHipster Microservice with UAA</name>
|
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -39,7 +39,6 @@
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<jib-maven-plugin.version>0.9.10</jib-maven-plugin.version>
|
<jib-maven-plugin.version>0.9.10</jib-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
11
json/pom.xml
11
json/pom.xml
|
@ -42,7 +42,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson-databind.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.json.bind</groupId>
|
<groupId>javax.json.bind</groupId>
|
||||||
|
@ -73,6 +73,12 @@
|
||||||
<version>${commons-collections4.version}</version>
|
<version>${commons-collections4.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj-core.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -83,9 +89,8 @@
|
||||||
<yasson.version>1.0.1</yasson.version>
|
<yasson.version>1.0.1</yasson.version>
|
||||||
<json.version>20171018</json.version>
|
<json.version>20171018</json.version>
|
||||||
<gson.version>2.8.5</gson.version>
|
<gson.version>2.8.5</gson.version>
|
||||||
<jackson-databind.version>2.9.7</jackson-databind.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<javax.version>1.1.2</javax.version>
|
<javax.version>1.1.2</javax.version>
|
||||||
|
<assertj-core.version>3.11.1</assertj-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.baeldung.jsonobject.iterate;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
public class JSONObjectIterator {
|
||||||
|
|
||||||
|
private Map<String, Object> keyValuePairs;
|
||||||
|
|
||||||
|
public JSONObjectIterator() {
|
||||||
|
keyValuePairs = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleValue(String key, Object value) {
|
||||||
|
if (value instanceof JSONArray) {
|
||||||
|
handleJSONArray(key, (JSONArray) value);
|
||||||
|
} else if (value instanceof JSONObject) {
|
||||||
|
handleJSONObject((JSONObject) value);
|
||||||
|
}
|
||||||
|
keyValuePairs.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleJSONObject(JSONObject jsonObject) {
|
||||||
|
Iterator<String> jsonObjectIterator = jsonObject.keys();
|
||||||
|
jsonObjectIterator.forEachRemaining(key -> {
|
||||||
|
Object value = jsonObject.get(key);
|
||||||
|
handleValue(key, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleJSONArray(String key, JSONArray jsonArray) {
|
||||||
|
Iterator<Object> jsonArrayIterator = jsonArray.iterator();
|
||||||
|
jsonArrayIterator.forEachRemaining(element -> {
|
||||||
|
handleValue(key, element);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getKeyValuePairs() {
|
||||||
|
return keyValuePairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyValuePairs(Map<String, Object> keyValuePairs) {
|
||||||
|
this.keyValuePairs = keyValuePairs;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,79 @@
|
||||||
|
package com.baeldung.jsonobject.iterate;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class JSONObjectIteratorUnitTest {
|
||||||
|
|
||||||
|
private JSONObjectIterator jsonObjectIterator = new JSONObjectIterator();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJSONObject_whenIterating_thenGetKeyValuePairs() {
|
||||||
|
JSONObject jsonObject = getJsonObject();
|
||||||
|
|
||||||
|
jsonObjectIterator.handleJSONObject(jsonObject);
|
||||||
|
|
||||||
|
Map<String, Object> keyValuePairs = jsonObjectIterator.getKeyValuePairs();
|
||||||
|
assertThat(keyValuePairs.get("rType")).isEqualTo("Regular");
|
||||||
|
assertThat(keyValuePairs.get("rId")).isEqualTo("1001");
|
||||||
|
assertThat(keyValuePairs.get("cType")).isEqualTo("Chocolate");
|
||||||
|
assertThat(keyValuePairs.get("cId")).isEqualTo("1002");
|
||||||
|
assertThat(keyValuePairs.get("bType")).isEqualTo("BlueBerry");
|
||||||
|
assertThat(keyValuePairs.get("bId")).isEqualTo("1003");
|
||||||
|
assertThat(keyValuePairs.get("name")).isEqualTo("Cake");
|
||||||
|
assertThat(keyValuePairs.get("cakeId")).isEqualTo("0001");
|
||||||
|
assertThat(keyValuePairs.get("type")).isEqualTo("donut");
|
||||||
|
assertThat(keyValuePairs.get("Type")).isEqualTo("Maple");
|
||||||
|
assertThat(keyValuePairs.get("tId")).isEqualTo("5001");
|
||||||
|
assertThat(keyValuePairs.get("batters")
|
||||||
|
.toString()).isEqualTo("[{\"rType\":\"Regular\",\"rId\":\"1001\"},{\"cType\":\"Chocolate\",\"cId\":\"1002\"},{\"bType\":\"BlueBerry\",\"bId\":\"1003\"}]");
|
||||||
|
assertThat(keyValuePairs.get("cakeShapes")
|
||||||
|
.toString()).isEqualTo("[\"square\",\"circle\",\"heart\"]");
|
||||||
|
assertThat(keyValuePairs.get("topping")
|
||||||
|
.toString()).isEqualTo("{\"Type\":\"Maple\",\"tId\":\"5001\"}");
|
||||||
|
}
|
||||||
|
|
||||||
|
private JSONObject getJsonObject() {
|
||||||
|
JSONObject cake = new JSONObject();
|
||||||
|
cake.put("cakeId", "0001");
|
||||||
|
cake.put("type", "donut");
|
||||||
|
cake.put("name", "Cake");
|
||||||
|
|
||||||
|
JSONArray batters = new JSONArray();
|
||||||
|
JSONObject regular = new JSONObject();
|
||||||
|
regular.put("rId", "1001");
|
||||||
|
regular.put("rType", "Regular");
|
||||||
|
batters.put(regular);
|
||||||
|
JSONObject chocolate = new JSONObject();
|
||||||
|
chocolate.put("cId", "1002");
|
||||||
|
chocolate.put("cType", "Chocolate");
|
||||||
|
batters.put(chocolate);
|
||||||
|
JSONObject blueberry = new JSONObject();
|
||||||
|
blueberry.put("bId", "1003");
|
||||||
|
blueberry.put("bType", "BlueBerry");
|
||||||
|
batters.put(blueberry);
|
||||||
|
|
||||||
|
JSONArray cakeShapes = new JSONArray();
|
||||||
|
cakeShapes.put("square");
|
||||||
|
cakeShapes.put("circle");
|
||||||
|
cakeShapes.put("heart");
|
||||||
|
|
||||||
|
cake.put("cakeShapes", cakeShapes);
|
||||||
|
|
||||||
|
cake.put("batters", batters);
|
||||||
|
|
||||||
|
JSONObject topping = new JSONObject();
|
||||||
|
topping.put("tId", "5001");
|
||||||
|
topping.put("Type", "Maple");
|
||||||
|
|
||||||
|
cake.put("topping", topping);
|
||||||
|
|
||||||
|
return cake;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -10,10 +10,10 @@
|
||||||
<description>JEE JTA demo</description>
|
<description>JEE JTA demo</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<groupId>com.baeldung</groupId>
|
||||||
<version>2.0.4.RELEASE</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath/>
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -85,5 +85,6 @@
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<hsqldb.version>2.4.1</hsqldb.version>
|
<hsqldb.version>2.4.1</hsqldb.version>
|
||||||
|
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -434,7 +434,6 @@
|
||||||
<kryo.version>4.0.1</kryo.version>
|
<kryo.version>4.0.1</kryo.version>
|
||||||
<h2.version>1.4.196</h2.version>
|
<h2.version>1.4.196</h2.version>
|
||||||
<reladomo.version>16.5.1</reladomo.version>
|
<reladomo.version>16.5.1</reladomo.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
<ormlite.version>5.0</ormlite.version>
|
<ormlite.version>5.0</ormlite.version>
|
||||||
<kafka.version>1.0.0</kafka.version>
|
<kafka.version>1.0.0</kafka.version>
|
||||||
|
|
|
@ -51,7 +51,6 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
||||||
<scribejava.version>5.6.0</scribejava.version>
|
<scribejava.version>5.6.0</scribejava.version>
|
||||||
<spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>
|
<spring-security-oauth2.version>2.3.3.RELEASE</spring-security-oauth2.version>
|
||||||
|
|
|
@ -105,7 +105,6 @@
|
||||||
<jetty.version>9.4.8.v20171121</jetty.version>
|
<jetty.version>9.4.8.v20171121</jetty.version>
|
||||||
<netty.version>4.1.20.Final</netty.version>
|
<netty.version>4.1.20.Final</netty.version>
|
||||||
<commons.collections.version>4.1</commons.collections.version>
|
<commons.collections.version>4.1</commons.collections.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<tomcat.version>8.5.24</tomcat.version>
|
<tomcat.version>8.5.24</tomcat.version>
|
||||||
<smack.version>4.3.1</smack.version>
|
<smack.version>4.3.1</smack.version>
|
||||||
<eclipse.paho.client.mqttv3.version>1.2.0</eclipse.paho.client.mqttv3.version>
|
<eclipse.paho.client.mqttv3.version>1.2.0</eclipse.paho.client.mqttv3.version>
|
||||||
|
|
|
@ -223,6 +223,12 @@
|
||||||
<artifactId>serenity-spring</artifactId>
|
<artifactId>serenity-spring</artifactId>
|
||||||
<version>${serenity.version}</version>
|
<version>${serenity.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.serenity-bdd</groupId>
|
<groupId>net.serenity-bdd</groupId>
|
||||||
|
@ -318,6 +324,12 @@
|
||||||
<artifactId>pact-jvm-consumer-junit_2.11</artifactId>
|
<artifactId>pact-jvm-consumer-junit_2.11</artifactId>
|
||||||
<version>${pact.version}</version>
|
<version>${pact.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
|
<exclusions>
|
||||||
|
<exclusion>
|
||||||
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
<artifactId>groovy-all</artifactId>
|
||||||
|
</exclusion>
|
||||||
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.groovy</groupId>
|
<groupId>org.codehaus.groovy</groupId>
|
||||||
|
@ -675,6 +687,17 @@
|
||||||
<version>${mockftpserver.version}</version>
|
<version>${mockftpserver.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.asciidoctor</groupId>
|
||||||
|
<artifactId>asciidoctor-maven-plugin</artifactId>
|
||||||
|
<version>1.5.7.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- Reflections -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.reflections</groupId>
|
||||||
|
<artifactId>reflections</artifactId>
|
||||||
|
<version>${reflections.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -687,10 +710,6 @@
|
||||||
<name>bintray</name>
|
<name>bintray</name>
|
||||||
<url>http://dl.bintray.com/cuba-platform/main</url>
|
<url>http://dl.bintray.com/cuba-platform/main</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>Apache Staging</id>
|
|
||||||
<url>https://repository.apache.org/content/groups/staging</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>nm-repo</id>
|
<id>nm-repo</id>
|
||||||
<name>Numerical Method's Maven Repository</name>
|
<name>Numerical Method's Maven Repository</name>
|
||||||
|
@ -734,7 +753,7 @@
|
||||||
<api>JDO</api>
|
<api>JDO</api>
|
||||||
<props>${basedir}/datanucleus.properties</props>
|
<props>${basedir}/datanucleus.properties</props>
|
||||||
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
|
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
|
||||||
<verbose>true</verbose>
|
<verbose>false</verbose>
|
||||||
<fork>false</fork>
|
<fork>false</fork>
|
||||||
<!-- Solve windows line too long error -->
|
<!-- Solve windows line too long error -->
|
||||||
</configuration>
|
</configuration>
|
||||||
|
@ -826,7 +845,6 @@
|
||||||
<serenity.jira.version>1.9.0</serenity.jira.version>
|
<serenity.jira.version>1.9.0</serenity.jira.version>
|
||||||
<serenity.plugin.version>1.9.27</serenity.plugin.version>
|
<serenity.plugin.version>1.9.27</serenity.plugin.version>
|
||||||
<jUnitParams.version>1.1.0</jUnitParams.version>
|
<jUnitParams.version>1.1.0</jUnitParams.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<java-lsh.version>0.10</java-lsh.version>
|
<java-lsh.version>0.10</java-lsh.version>
|
||||||
<pact.version>3.5.0</pact.version>
|
<pact.version>3.5.0</pact.version>
|
||||||
<awaitility.version>3.0.0</awaitility.version>
|
<awaitility.version>3.0.0</awaitility.version>
|
||||||
|
@ -897,6 +915,8 @@
|
||||||
<derive4j.version>1.1.0</derive4j.version>
|
<derive4j.version>1.1.0</derive4j.version>
|
||||||
<mockftpserver.version>2.7.1</mockftpserver.version>
|
<mockftpserver.version>2.7.1</mockftpserver.version>
|
||||||
<commons-net.version>3.6</commons-net.version>
|
<commons-net.version>3.6</commons-net.version>
|
||||||
|
<reflections.version>0.9.11</reflections.version>
|
||||||
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -6,7 +6,7 @@ import org.derive4j.Make;
|
||||||
|
|
||||||
@Data(value = @Derive(
|
@Data(value = @Derive(
|
||||||
inClass = "{ClassName}Impl",
|
inClass = "{ClassName}Impl",
|
||||||
make = {Make.lazyConstructor, Make.constructors}
|
make = {Make.lazyConstructor, Make.constructors, Make.getters}
|
||||||
))
|
))
|
||||||
public interface LazyRequest {
|
public interface LazyRequest {
|
||||||
interface Cases<R>{
|
interface Cases<R>{
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
package com.baeldung.reflections;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import org.reflections.scanners.MethodAnnotationsScanner;
|
||||||
|
import org.reflections.scanners.MethodParameterScanner;
|
||||||
|
import org.reflections.scanners.ResourcesScanner;
|
||||||
|
import org.reflections.scanners.Scanner;
|
||||||
|
import org.reflections.scanners.SubTypesScanner;
|
||||||
|
import org.reflections.util.ClasspathHelper;
|
||||||
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
|
public class ReflectionsApp {
|
||||||
|
|
||||||
|
public Set<Class<? extends Scanner>> getReflectionsSubTypes() {
|
||||||
|
Reflections reflections = new Reflections("org.reflections");
|
||||||
|
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
|
||||||
|
return scannersSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Class<?>> getJDKFunctinalInterfaces() {
|
||||||
|
Reflections reflections = new Reflections("java.util.function");
|
||||||
|
Set<Class<?>> typesSet = reflections.getTypesAnnotatedWith(FunctionalInterface.class);
|
||||||
|
return typesSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Method> getDateDeprecatedMethods() {
|
||||||
|
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
|
||||||
|
Set<Method> deprecatedMethodsSet = reflections.getMethodsAnnotatedWith(Deprecated.class);
|
||||||
|
return deprecatedMethodsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public Set<Constructor> getDateDeprecatedConstructors() {
|
||||||
|
Reflections reflections = new Reflections(java.util.Date.class, new MethodAnnotationsScanner());
|
||||||
|
Set<Constructor> constructorsSet = reflections.getConstructorsAnnotatedWith(Deprecated.class);
|
||||||
|
return constructorsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Method> getMethodsWithDateParam() {
|
||||||
|
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
|
||||||
|
Set<Method> methodsSet = reflections.getMethodsMatchParams(Date.class);
|
||||||
|
return methodsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Method> getMethodsWithVoidReturn() {
|
||||||
|
Reflections reflections = new Reflections(java.text.SimpleDateFormat.class, new MethodParameterScanner());
|
||||||
|
Set<Method> methodsSet = reflections.getMethodsReturn(void.class);
|
||||||
|
return methodsSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<String> getPomXmlPaths() {
|
||||||
|
Reflections reflections = new Reflections(new ResourcesScanner());
|
||||||
|
Set<String> resourcesSet = reflections.getResources(Pattern.compile(".*pom\\.xml"));
|
||||||
|
return resourcesSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Class<? extends Scanner>> getReflectionsSubTypesUsingBuilder() {
|
||||||
|
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.reflections"))
|
||||||
|
.setScanners(new SubTypesScanner()));
|
||||||
|
|
||||||
|
Set<Class<? extends Scanner>> scannersSet = reflections.getSubTypesOf(Scanner.class);
|
||||||
|
return scannersSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,7 +26,7 @@ import com.google.api.services.sheets.v4.model.ValueRange;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.*;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
public class GoogleSheetsIntegrationTest {
|
public class GoogleSheetsLiveTest {
|
||||||
|
|
||||||
private static Sheets sheetsService;
|
private static Sheets sheetsService;
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package com.baeldung.reflections;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class ReflectionsUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTypeThenGetAllSubTypes() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getReflectionsSubTypes()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenTypeAndUsingBuilderThenGetAllSubTypes() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getReflectionsSubTypesUsingBuilder()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnnotationThenGetAllAnnotatedMethods() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getDateDeprecatedMethods()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnnotationThenGetAllAnnotatedConstructors() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getDateDeprecatedConstructors()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenParamTypeThenGetAllMethods() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getMethodsWithDateParam()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenReturnTypeThenGetAllMethods() {
|
||||||
|
ReflectionsApp reflectionsApp = new ReflectionsApp();
|
||||||
|
assertFalse(reflectionsApp.getMethodsWithVoidReturn()
|
||||||
|
.isEmpty());
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,9 +12,10 @@ import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SmooksIntegrationTest {
|
public class SmooksIntegrationTest {
|
||||||
|
|
||||||
private static final String EDIFACT_MESSAGE = "UNA:+.? '\r\n" + "UNH+771+IN_PROGRESS+2018-01-14'\r\n" + "CTA+CompanyX+1234567'\r\n" + "LIN+1+PX1234+9.99'\r\n" + "LIN+2+RX990+120.32'\r\n";
|
private static final String EDIFACT_MESSAGE = "UNA:+.? '" + System.lineSeparator() + "UNH+771+IN_PROGRESS+2018-01-14'" + System.lineSeparator() + "CTA+CompanyX+1234567'" + System.lineSeparator() + "LIN+1+PX1234+9.99'" + System.lineSeparator()
|
||||||
private static final String EMAIL_MESSAGE = "Hi,\r\n" + "Order number #771 created on 2018-01-14 is currently in IN_PROGRESS status.\r\n" + "Consider contact supplier \"CompanyX\" with phone number: \"1234567\".\r\n" + "Order items:\r\n"
|
+ "LIN+2+RX990+120.32'" + System.lineSeparator();
|
||||||
+ "1 X PX1234 (total price 9.99)\r\n" + "2 X RX990 (total price 240.64)\r\n";
|
private static final String EMAIL_MESSAGE = "Hi," + System.lineSeparator() + "Order number #771 created on 2018-01-14 is currently in IN_PROGRESS status." + System.lineSeparator() + "Consider contact supplier \"CompanyX\" with phone number: \"1234567\"."
|
||||||
|
+ System.lineSeparator() + "Order items:" + System.lineSeparator() + "1 X PX1234 (total price 9.99)" + System.lineSeparator() + "2 X RX990 (total price 240.64)" + System.lineSeparator();
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenOrderXML_whenConvert_thenPOJOsConstructedCorrectly() throws Exception {
|
public void givenOrderXML_whenConvert_thenPOJOsConstructedCorrectly() throws Exception {
|
||||||
|
@ -37,7 +38,10 @@ public class SmooksIntegrationTest {
|
||||||
|
|
||||||
assertThat(validationResult.getErrors(), hasSize(1));
|
assertThat(validationResult.getErrors(), hasSize(1));
|
||||||
// 1234567 didn't match ^[0-9\\-\\+]{9,15}$
|
// 1234567 didn't match ^[0-9\\-\\+]{9,15}$
|
||||||
assertThat(validationResult.getErrors().get(0).getFailRuleResult().getRuleName(), is("supplierPhone"));
|
assertThat(validationResult.getErrors()
|
||||||
|
.get(0)
|
||||||
|
.getFailRuleResult()
|
||||||
|
.getRuleName(), is("supplierPhone"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>lombok-custom</artifactId>
|
<artifactId>lombok-custom</artifactId>
|
||||||
|
<name>lombok-custom</name>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
/output-resources
|
/output-resources
|
||||||
|
/.idea/
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
<?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">
|
||||||
|
<parent>
|
||||||
|
<artifactId>maven</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>custom-rule</artifactId>
|
||||||
|
<name>custom-rule</name>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<api.version>3.0.0-M2</api.version>
|
||||||
|
<maven.version>2.0.9</maven.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- dependencies for maven plugin-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.enforcer</groupId>
|
||||||
|
<artifactId>enforcer-api</artifactId>
|
||||||
|
<version>${api.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-project</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-core</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-artifact</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
|
<version>${maven.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-container-default</artifactId>
|
||||||
|
<version>1.0-alpha-9</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-verifier-plugin</artifactId>
|
||||||
|
<version>${maven.verifier.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<verificationFile>../input-resources/verifications.xml</verificationFile>
|
||||||
|
<failOnError>false</failOnError>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 PloyRef
|
||||||
|
* Created by Seun Matt <smatt382@gmail.com>
|
||||||
|
* on 19 - 2 - 2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.baeldung.enforcer;
|
||||||
|
|
||||||
|
import org.apache.maven.enforcer.rule.api.EnforcerRule;
|
||||||
|
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
|
||||||
|
import org.apache.maven.enforcer.rule.api.EnforcerRuleHelper;
|
||||||
|
import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException;
|
||||||
|
|
||||||
|
public class MyCustomRule implements EnforcerRule {
|
||||||
|
|
||||||
|
public void execute(EnforcerRuleHelper enforcerRuleHelper) throws EnforcerRuleException {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
String groupId = (String) enforcerRuleHelper.evaluate("${project.groupId}");
|
||||||
|
|
||||||
|
if (groupId == null || !groupId.startsWith("org.baeldung")) {
|
||||||
|
throw new EnforcerRuleException("Project group id does not start with org.baeldung");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (ExpressionEvaluationException ex ) {
|
||||||
|
throw new EnforcerRuleException( "Unable to lookup an expression " + ex.getLocalizedMessage(), ex );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCacheable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResultValid(EnforcerRule enforcerRule) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCacheId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
<?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">
|
||||||
|
<parent>
|
||||||
|
<artifactId>maven</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>maven-enforcer</artifactId>
|
||||||
|
<name>maven-enforcer</name>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-enforcer-plugin</artifactId>
|
||||||
|
<version>3.0.0-M2</version>
|
||||||
|
<!--<dependencies>-->
|
||||||
|
<!--<dependency>-->
|
||||||
|
<!--<groupId>com.baeldung</groupId>-->
|
||||||
|
<!--<artifactId>custom-rule</artifactId>-->
|
||||||
|
<!--<version>1.0</version>-->
|
||||||
|
<!--</dependency>-->
|
||||||
|
<!--</dependencies>-->
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>enforce</id>
|
||||||
|
<goals>
|
||||||
|
<goal>enforce</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<rules>
|
||||||
|
<banDuplicatePomDependencyVersions/>
|
||||||
|
<requireMavenVersion>
|
||||||
|
<version>3.0</version>
|
||||||
|
<message>Invalid Maven version. It should, at least, be 3.0</message>
|
||||||
|
</requireMavenVersion>
|
||||||
|
<requireJavaVersion>
|
||||||
|
<version>1.8</version>
|
||||||
|
</requireJavaVersion>
|
||||||
|
<requireEnvironmentVariable>
|
||||||
|
<variableName>ui</variableName>
|
||||||
|
<level>WARN</level>
|
||||||
|
</requireEnvironmentVariable>
|
||||||
|
<requireEnvironmentVariable>
|
||||||
|
<variableName>cook</variableName>
|
||||||
|
<level>WARN</level>
|
||||||
|
</requireEnvironmentVariable>
|
||||||
|
<requireActiveProfile>
|
||||||
|
<profiles>local,base</profiles>
|
||||||
|
<message>Missing active profiles</message>
|
||||||
|
<level>WARN</level>
|
||||||
|
</requireActiveProfile>
|
||||||
|
<!--other rules -->
|
||||||
|
<!--<myCustomRule implementation="com.baeldung.enforcer.MyCustomRule"/>-->
|
||||||
|
</rules>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-verifier-plugin</artifactId>
|
||||||
|
<version>${maven.verifier.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<verificationFile>../input-resources/verifications.xml</verificationFile>
|
||||||
|
<failOnError>false</failOnError>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
|
||||||
|
</project>
|
|
@ -4,8 +4,12 @@
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>maven</artifactId>
|
<artifactId>maven</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>maven</name>
|
<modules>
|
||||||
<packaging>war</packaging>
|
<module>custom-rule</module>
|
||||||
|
<module>maven-enforcer</module>
|
||||||
|
</modules>
|
||||||
|
<name>maven</name>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>osgi-intro-sample-activator</artifactId>
|
<artifactId>osgi-intro-sample-activator</artifactId>
|
||||||
|
<name>osgi-intro-sample-activator</name>
|
||||||
<!-- Please, note this is not the usual 'jar'. -->
|
<!-- Please, note this is not the usual 'jar'. -->
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<!-- mvn:com.baeldung/osgi-intro-sample-client/1.0-SNAPSHOT -->
|
<!-- mvn:com.baeldung/osgi-intro-sample-client/1.0-SNAPSHOT -->
|
||||||
<artifactId>osgi-intro-sample-client</artifactId>
|
<artifactId>osgi-intro-sample-client</artifactId>
|
||||||
|
<name>osgi-intro-sample-client</name>
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>osgi-intro-sample-service</artifactId>
|
<artifactId>osgi-intro-sample-service</artifactId>
|
||||||
|
<name>osgi-intro-sample-service</name>
|
||||||
<!-- Please, note this is not the usual 'jar'. -->
|
<!-- Please, note this is not the usual 'jar'. -->
|
||||||
<packaging>bundle</packaging>
|
<packaging>bundle</packaging>
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<rest-assured.version>3.1.0</rest-assured.version>
|
<rest-assured.version>3.1.0</rest-assured.version>
|
||||||
<spring-boot.version>1.5.16.RELEASE</spring-boot.version>
|
<spring-boot.version>1.5.19.RELEASE</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -77,9 +77,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<rest-assured.version>3.1.0</rest-assured.version>
|
<rest-assured.version>3.1.0</rest-assured.version>
|
||||||
<!-- plugins -->
|
<!-- plugins -->
|
||||||
<thin.version>1.0.11.RELEASE</thin.version>
|
<thin.version>1.0.21.RELEASE</thin.version>
|
||||||
<spring-boot.version>2.1.1.RELEASE</spring-boot.version>
|
<spring-boot.version>2.1.3.RELEASE</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring.version>4.3.20.RELEASE</spring.version>
|
<spring.version>4.3.22.RELEASE</spring.version>
|
||||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
<properties>
|
<properties>
|
||||||
<spring.version>5.1.2.RELEASE</spring.version>
|
<spring.version>5.1.2.RELEASE</spring.version>
|
||||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||||
<jackson-databind.version>2.9.6</jackson-databind.version>
|
|
||||||
<jackson.version>2.9.6</jackson.version>
|
<jackson.version>2.9.6</jackson.version>
|
||||||
<spring-security.version>5.1.2.RELEASE</spring-security.version>
|
<spring-security.version>5.1.2.RELEASE</spring-security.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
|
@ -18,3 +18,4 @@
|
||||||
- [Chain of Responsibility Design Pattern in Java](http://www.baeldung.com/chain-of-responsibility-pattern)
|
- [Chain of Responsibility Design Pattern in Java](http://www.baeldung.com/chain-of-responsibility-pattern)
|
||||||
- [The Command Pattern in Java](http://www.baeldung.com/java-command-pattern)
|
- [The Command Pattern in Java](http://www.baeldung.com/java-command-pattern)
|
||||||
- [Java Constructors vs Static Factory Methods](https://www.baeldung.com/java-constructors-vs-static-factory-methods)
|
- [Java Constructors vs Static Factory Methods](https://www.baeldung.com/java-constructors-vs-static-factory-methods)
|
||||||
|
- [The Adapter Pattern in Java](https://www.baeldung.com/java-adapter-pattern)
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>solid</artifactId>
|
<artifactId>solid</artifactId>
|
||||||
|
<name>solid</name>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
|
|
|
@ -11,10 +11,10 @@
|
||||||
<description>Demo Spring Boot applications that starts H2 in memory database</description>
|
<description>Demo Spring Boot applications that starts H2 in memory database</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<groupId>com.baeldung</groupId>
|
||||||
<version>2.0.4.RELEASE</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath>../../../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -48,6 +48,7 @@
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<!-- The main class to start by executing java -jar -->
|
<!-- The main class to start by executing java -jar -->
|
||||||
<start-class>com.baeldung.h2db.demo.server.SpringBootApp</start-class>
|
<start-class>com.baeldung.h2db.demo.server.SpringBootApp</start-class>
|
||||||
|
<spring-boot.version>2.0.4.RELEASE</spring-boot.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -12,7 +12,7 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
|
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
|
||||||
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
||||||
public class SpringContextIntegrationTest {
|
public class SpringContextLiveTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
|
|
@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class PersonRepositoryServiceIntegrationTest extends PersonServiceIntegrationTest {
|
public class PersonRepositoryServiceLiveTest extends PersonServiceLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("PersonRepositoryService")
|
@Qualifier("PersonRepositoryService")
|
|
@ -20,7 +20,7 @@ import com.couchbase.client.java.CouchbaseCluster;
|
||||||
import com.couchbase.client.java.document.JsonDocument;
|
import com.couchbase.client.java.document.JsonDocument;
|
||||||
import com.couchbase.client.java.document.json.JsonObject;
|
import com.couchbase.client.java.document.json.JsonObject;
|
||||||
|
|
||||||
public abstract class PersonServiceIntegrationTest extends IntegrationTest {
|
public abstract class PersonServiceLiveTest extends IntegrationTest {
|
||||||
|
|
||||||
static final String typeField = "_class";
|
static final String typeField = "_class";
|
||||||
static final String john = "John";
|
static final String john = "John";
|
|
@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class PersonTemplateServiceIntegrationTest extends PersonServiceIntegrationTest {
|
public class PersonTemplateServiceLiveTest extends PersonServiceLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("PersonTemplateService")
|
@Qualifier("PersonTemplateService")
|
|
@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class StudentRepositoryServiceIntegrationTest extends StudentServiceIntegrationTest {
|
public class StudentRepositoryServiceLiveTest extends StudentServiceLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("StudentRepositoryService")
|
@Qualifier("StudentRepositoryService")
|
|
@ -22,7 +22,7 @@ import com.couchbase.client.java.CouchbaseCluster;
|
||||||
import com.couchbase.client.java.document.JsonDocument;
|
import com.couchbase.client.java.document.JsonDocument;
|
||||||
import com.couchbase.client.java.document.json.JsonObject;
|
import com.couchbase.client.java.document.json.JsonObject;
|
||||||
|
|
||||||
public abstract class StudentServiceIntegrationTest extends IntegrationTest {
|
public abstract class StudentServiceLiveTest extends IntegrationTest {
|
||||||
|
|
||||||
static final String typeField = "_class";
|
static final String typeField = "_class";
|
||||||
static final String joe = "Joe";
|
static final String joe = "Joe";
|
|
@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
|
||||||
public class StudentTemplateServiceIntegrationTest extends StudentServiceIntegrationTest {
|
public class StudentTemplateServiceLiveTest extends StudentServiceLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("StudentTemplateService")
|
@Qualifier("StudentTemplateService")
|
|
@ -9,6 +9,6 @@ import org.springframework.test.context.support.DependencyInjectionTestExecution
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
|
@ContextConfiguration(classes = { MultiBucketCouchbaseConfig.class, MultiBucketIntegrationTestConfig.class })
|
||||||
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
@TestExecutionListeners(listeners = { DependencyInjectionTestExecutionListener.class })
|
||||||
public abstract class MultiBucketIntegrationTest {
|
public abstract class MultiBucketLiveTest {
|
||||||
|
|
||||||
}
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue