Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
cf7705caee
@ -38,8 +38,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<akka.http.version>10.0.11</akka.http.version>
|
||||
<akka.stream.version>2.5.11</akka.stream.version>
|
||||
</properties>
|
||||
|
@ -91,8 +91,6 @@
|
||||
<commons-collections4.version>4.3</commons-collections4.version>
|
||||
<guava.version>28.0-jre</guava.version>
|
||||
<retrofit.version>2.6.0</retrofit.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
<commons.lang3.version>3.8.1</commons.lang3.version>
|
||||
<JUnitParams.version>1.1.0</JUnitParams.version>
|
||||
</properties>
|
||||
|
@ -13,7 +13,7 @@ import java.util.Objects;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class AvroSerealizerDeSerealizerUnitTest {
|
||||
public class AvroSerealizerDeSerealizerIntegrationTest {
|
||||
|
||||
AvroSerealizer serealizer;
|
||||
AvroDeSerealizer deSerealizer;
|
@ -17,7 +17,7 @@ import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
@RunWith(MonoMeecrowave.Runner.class)
|
||||
public class ArticleEndpointsUnitTest {
|
||||
public class ArticleEndpointsIntegrationTest {
|
||||
|
||||
@ConfigurationInject
|
||||
private Meecrowave.Builder config;
|
@ -100,7 +100,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring.version>2.2.1.RELEASE</spring.version>
|
||||
<awssdk.version>2.10.27</awssdk.version>
|
||||
</properties>
|
||||
|
@ -115,7 +115,6 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
@ -186,7 +185,6 @@
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<groovy.version>2.5.7</groovy.version>
|
||||
<assembly.plugin.version>3.1.0</assembly.plugin.version>
|
||||
<surefire.plugin.version>2.20.1</surefire.plugin.version>
|
||||
<compiler.plugin.version>3.8.0</compiler.plugin.version>
|
||||
<groovy.compiler.version>3.3.0-01</groovy.compiler.version>
|
||||
</properties>
|
||||
|
@ -101,7 +101,6 @@
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
@ -128,7 +127,6 @@
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||
<surefire.plugin.version>2.20.1</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -32,12 +32,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -105,7 +105,6 @@
|
||||
<guava.version>27.1-jre</guava.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
<uberjar.name>benchmarks</uberjar.name>
|
||||
<jmh.version>1.22</jmh.version>
|
||||
<eclipse.collections.version>10.0.0</eclipse.collections.version>
|
||||
<shade.plugin.version>3.2.4</shade.plugin.version>
|
||||
</properties>
|
||||
|
@ -17,16 +17,18 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.19.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
</project>
|
@ -2,7 +2,6 @@ package com.baeldung.genericarrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -0,0 +1,77 @@
|
||||
package com.baeldung.genericarrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
public class StreamToArrayUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenAStream_thenCanGetArrayOfObject() {
|
||||
Object[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
|
||||
.filter(string -> string.startsWith("A"))
|
||||
.toArray();
|
||||
|
||||
assertThat(strings).containsExactly("A", "AAA", "AAB");
|
||||
assertThat(strings).isNotInstanceOf(String[].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAStream_thenCanGetArrayOfString() {
|
||||
String[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
|
||||
.filter(string -> string.startsWith("A"))
|
||||
.toArray(String[]::new);
|
||||
|
||||
assertThat(strings).containsExactly("A", "AAA", "AAB");
|
||||
assertThat(strings).isInstanceOf(String[].class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void givenAStream_whenConvertToOptional_thenCanGetArrayOfOptional() {
|
||||
Stream<Optional<String>> stream = Stream.of("A", "AAA", "B", "AAB", "C")
|
||||
.filter(string -> string.startsWith("A"))
|
||||
.map(Optional::of);
|
||||
Optional<String>[] strings = stream
|
||||
.toArray(Optional[]::new);
|
||||
|
||||
assertThat(strings).containsExactly(Optional.of("A"),
|
||||
Optional.of("AAA"),
|
||||
Optional.of("AAB"));
|
||||
assertThat(strings).isInstanceOf(Optional[].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAStream_whenConvertToOptional_thenCanGetArrayOfOptionalWithHelper() {
|
||||
Optional<String>[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
|
||||
.filter(string -> string.startsWith("A"))
|
||||
.map(Optional::of)
|
||||
.toArray(genericArray(Optional[]::new));
|
||||
|
||||
assertThat(strings).containsExactly(Optional.of("A"),
|
||||
Optional.of("AAA"),
|
||||
Optional.of("AAB"));
|
||||
assertThat(strings).isInstanceOf(Optional[].class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInvalidUseOfGenericArray_thenIllegalCast() {
|
||||
assertThatThrownBy(() -> {
|
||||
ArrayList<String>[] lists = Stream.of(singletonList("A"))
|
||||
.toArray(genericArray(List[]::new));
|
||||
}).isInstanceOf(ClassCastException.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static <T, R extends T> IntFunction<R[]> genericArray(IntFunction<T[]> arrayCreator) {
|
||||
return size -> (R[])arrayCreator.apply(size);
|
||||
}
|
||||
}
|
@ -24,12 +24,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -68,7 +68,6 @@
|
||||
|
||||
<properties>
|
||||
<shade.plugin.version>3.2.0</shade.plugin.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
</project>
|
@ -31,12 +31,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Testing -->
|
||||
@ -77,7 +77,6 @@
|
||||
<properties>
|
||||
<shade.plugin.version>3.2.0</shade.plugin.version>
|
||||
<guava.version>28.2-jre</guava.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
</project>
|
@ -25,17 +25,16 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<openjdk.jmh.version>1.19</openjdk.jmh.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
|
@ -24,7 +24,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
@ -40,7 +40,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<openjdk.jmh.version>1.19</openjdk.jmh.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
<jol-core.version>0.10</jol-core.version>
|
||||
</properties>
|
||||
|
@ -58,7 +58,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -25,17 +25,16 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<openjdk.jmh.version>1.19</openjdk.jmh.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
|
@ -29,7 +29,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -51,8 +51,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
|
@ -23,12 +23,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
@ -39,7 +39,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.21</jmh.version>
|
||||
<guava.version>28.2-jre</guava.version>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
|
@ -65,8 +65,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
<assertj.version>3.12.2</assertj.version>
|
||||
<commons.beanutils.version>1.9.4</commons.beanutils.version>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
|
@ -20,12 +20,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -40,8 +40,4 @@
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jmh.version>1.28</jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -58,7 +58,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -83,7 +83,6 @@
|
||||
<nd4j.version>1.0.0-beta4</nd4j.version>
|
||||
<colt.version>1.2.0</colt.version>
|
||||
<la4j.version>0.6.0</la4j.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -13,3 +13,4 @@ This module contains articles about types in Java
|
||||
- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums)
|
||||
- [Determine if an Object is of Primitive Type](https://www.baeldung.com/java-object-primitive-type)
|
||||
- [Extending Enums in Java](https://www.baeldung.com/java-extending-enums)
|
||||
- [Java Class File Naming Conventions](https://www.baeldung.com/java-class-file-naming)
|
||||
|
@ -47,6 +47,7 @@ public class Outer {
|
||||
// Anonymous Inner class extending a class
|
||||
public String greet() {
|
||||
Outer anonymous = new Outer() {
|
||||
@Override
|
||||
public String greet() {
|
||||
return "Running Anonymous Class...";
|
||||
}
|
||||
@ -58,6 +59,7 @@ public class Outer {
|
||||
public String greet(String name) {
|
||||
|
||||
HelloWorld helloWorld = new HelloWorld() {
|
||||
@Override
|
||||
public String greet(String name) {
|
||||
return "Welcome to " + name;
|
||||
}
|
||||
@ -70,6 +72,7 @@ public class Outer {
|
||||
public String greetSomeone(String name) {
|
||||
|
||||
HelloSomeone helloSomeOne = new HelloSomeone() {
|
||||
@Override
|
||||
public String greet(String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
@ -94,7 +97,8 @@ interface HelloWorld {
|
||||
public String greet(String name);
|
||||
|
||||
// Nested class within an interface
|
||||
class InnerClass {
|
||||
class InnerClass implements HelloWorld {
|
||||
@Override
|
||||
public String greet(String name) {
|
||||
return "Inner class within an interface";
|
||||
}
|
||||
|
@ -14,5 +14,4 @@ This module contains articles about networking in Java
|
||||
- [Handling java.net.ConnectException](https://www.baeldung.com/java-net-connectexception)
|
||||
- [Getting MAC addresses in Java](https://www.baeldung.com/java-mac-address)
|
||||
- [Sending Emails with Attachments in Java](https://www.baeldung.com/java-send-emails-attachments)
|
||||
- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking)
|
||||
|
@ -4,5 +4,5 @@ This module contains articles about networking in Java
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- TODO: add link once live
|
||||
- [Finding a Free Port in Java](https://www.baeldung.com/java-free-port)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-networking-2)
|
||||
|
@ -67,8 +67,6 @@
|
||||
|
||||
<properties>
|
||||
<hibernate.core.version>5.4.0.Final</hibernate.core.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
<guava.version>27.1-jre</guava.version>
|
||||
<assertj.version>3.10.0</assertj.version>
|
||||
<rest-assured.version>3.1.1</rest-assured.version>
|
||||
|
@ -0,0 +1,92 @@
|
||||
package com.baeldung.cipher;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileReader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.KeyPair;
|
||||
import java.security.KeyPairGenerator;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
|
||||
public class RsaUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception {
|
||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(2048);
|
||||
KeyPair pair = generator.generateKeyPair();
|
||||
PrivateKey privateKey = pair.getPrivate();
|
||||
PublicKey publicKey = pair.getPublic();
|
||||
|
||||
String secretMessage = "Baeldung secret message";
|
||||
Cipher encryptCipher = Cipher.getInstance("RSA");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8);
|
||||
byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes);
|
||||
|
||||
Cipher decryptCipher = Cipher.getInstance("RSA");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes);
|
||||
String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8);
|
||||
|
||||
Assertions.assertEquals(secretMessage, decryptedMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception {
|
||||
KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
|
||||
generator.initialize(2048);
|
||||
KeyPair pair = generator.generateKeyPair();
|
||||
PrivateKey privateKey = pair.getPrivate();
|
||||
PublicKey publicKey = pair.getPublic();
|
||||
|
||||
String originalContent = "some secret message";
|
||||
Path tempFile = Files.createTempFile("temp", "txt");
|
||||
writeString(tempFile, originalContent);
|
||||
|
||||
byte[] fileBytes = Files.readAllBytes(tempFile);
|
||||
Cipher encryptCipher = Cipher.getInstance("RSA");
|
||||
encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
|
||||
byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes);
|
||||
try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
|
||||
stream.write(encryptedFileBytes);
|
||||
}
|
||||
|
||||
encryptedFileBytes = Files.readAllBytes(tempFile);
|
||||
Cipher decryptCipher = Cipher.getInstance("RSA");
|
||||
decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||
byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes);
|
||||
try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
|
||||
stream.write(decryptedFileBytes);
|
||||
}
|
||||
|
||||
String fileContent = readString(tempFile);
|
||||
|
||||
Assertions.assertEquals(originalContent, fileContent);
|
||||
}
|
||||
|
||||
private void writeString(Path path, String content) throws Exception {
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(path)) {
|
||||
writer.write(content);
|
||||
}
|
||||
}
|
||||
|
||||
private String readString(Path path) throws Exception {
|
||||
StringBuilder resultStringBuilder = new StringBuilder();
|
||||
try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
resultStringBuilder.append(line);
|
||||
}
|
||||
}
|
||||
return resultStringBuilder.toString();
|
||||
}
|
||||
}
|
@ -47,7 +47,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.9</maven.compiler.source>
|
||||
<maven.compiler.target>1.9</maven.compiler.target>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
|
@ -10,4 +10,5 @@ This module contains articles about the Stream API in Java.
|
||||
- [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
|
||||
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
|
||||
- [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close)
|
||||
- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection)
|
||||
- More articles: [[<-- prev>]](/../core-java-streams-2)
|
||||
|
@ -49,8 +49,6 @@
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<!-- plugins -->
|
||||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,95 @@
|
||||
package com.baeldung.streams.streamvscollection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class StreamVsCollectionExample {
|
||||
|
||||
static ArrayList<String> userNameSource = new ArrayList<>();
|
||||
|
||||
static {
|
||||
userNameSource.add("john");
|
||||
userNameSource.add("smith");
|
||||
userNameSource.add("tom");
|
||||
userNameSource.add("rob");
|
||||
userNameSource.add("charlie");
|
||||
userNameSource.add("alfred");
|
||||
}
|
||||
|
||||
public static Stream<String> userNames() {
|
||||
return userNameSource.stream();
|
||||
}
|
||||
|
||||
public static List<String> userNameList() {
|
||||
return userNames().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public static Set<String> userNameSet() {
|
||||
return userNames().collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
public static Map<String, String> userNameMap() {
|
||||
return userNames().collect(Collectors.toMap(u1 -> u1.toString(), u1 -> u1.toString()));
|
||||
}
|
||||
|
||||
public static Stream<String> filterUserNames() {
|
||||
return userNames().filter(i -> i.length() >= 4);
|
||||
}
|
||||
|
||||
public static Stream<String> sortUserNames() {
|
||||
return userNames().sorted();
|
||||
}
|
||||
|
||||
public static Stream<String> limitUserNames() {
|
||||
return userNames().limit(3);
|
||||
}
|
||||
|
||||
public static Stream<String> sortFilterLimitUserNames() {
|
||||
return filterUserNames().sorted().limit(3);
|
||||
}
|
||||
|
||||
public static void printStream(Stream<String> stream) {
|
||||
stream.forEach(System.out::println);
|
||||
}
|
||||
|
||||
public static void modifyList() {
|
||||
userNameSource.remove(2);
|
||||
}
|
||||
|
||||
public static Map<String, String> modifyMap() {
|
||||
Map<String, String> userNameMap = userNameMap();
|
||||
userNameMap.put("bob", "bob");
|
||||
userNameMap.remove("alfred");
|
||||
|
||||
return userNameMap;
|
||||
}
|
||||
|
||||
public static void tryStreamTraversal() {
|
||||
Stream<String> userNameStream = userNames();
|
||||
userNameStream.forEach(System.out::println);
|
||||
|
||||
try {
|
||||
userNameStream.forEach(System.out::println);
|
||||
} catch(IllegalStateException e) {
|
||||
System.out.println("stream has already been operated upon or closed");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(userNameMap());
|
||||
System.out.println(modifyMap());
|
||||
tryStreamTraversal();
|
||||
|
||||
Set<String> set = userNames().collect(Collectors.toCollection(TreeSet::new));
|
||||
set.forEach(val -> System.out.println(val));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -34,7 +34,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
|
@ -39,7 +39,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vdurmont</groupId>
|
||||
|
@ -59,7 +59,6 @@
|
||||
<compiler.plugin.version>3.8.0</compiler.plugin.version>
|
||||
<source.version>1.9</source.version>
|
||||
<target.version>1.9</target.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<assertj-core.version>3.12.2</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
|
@ -100,6 +100,7 @@
|
||||
|
||||
<module>core-java-networking</module>
|
||||
<module>core-java-networking-2</module>
|
||||
<module>core-java-networking-3</module>
|
||||
<module>core-java-nio</module>
|
||||
<module>core-java-nio-2</module>
|
||||
|
||||
@ -148,18 +149,6 @@
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
|
@ -45,7 +45,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||
<pmdVersion>6.0.1</pmdVersion>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
|
@ -148,48 +148,46 @@ public class BinaryTree {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void traverseInOrderWithoutRecursion() {
|
||||
Stack<Node> stack = new Stack<Node>();
|
||||
Stack<Node> stack = new Stack<>();
|
||||
Node current = root;
|
||||
stack.push(root);
|
||||
while(! stack.isEmpty()) {
|
||||
while(current.left != null) {
|
||||
|
||||
while (current != null || !stack.isEmpty()) {
|
||||
while (current != null) {
|
||||
stack.push(current);
|
||||
current = current.left;
|
||||
stack.push(current);
|
||||
}
|
||||
current = stack.pop();
|
||||
visit(current.value);
|
||||
if(current.right != null) {
|
||||
current = current.right;
|
||||
stack.push(current);
|
||||
}
|
||||
|
||||
Node top = stack.pop();
|
||||
visit(top.value);
|
||||
current = top.right;
|
||||
}
|
||||
}
|
||||
|
||||
public void traversePreOrderWithoutRecursion() {
|
||||
Stack<Node> stack = new Stack<Node>();
|
||||
Stack<Node> stack = new Stack<>();
|
||||
Node current = root;
|
||||
stack.push(root);
|
||||
while(! stack.isEmpty()) {
|
||||
|
||||
while (current != null && !stack.isEmpty()) {
|
||||
current = stack.pop();
|
||||
visit(current.value);
|
||||
|
||||
if(current.right != null)
|
||||
if (current.right != null)
|
||||
stack.push(current.right);
|
||||
|
||||
if(current.left != null)
|
||||
if (current.left != null)
|
||||
stack.push(current.left);
|
||||
}
|
||||
}
|
||||
|
||||
public void traversePostOrderWithoutRecursion() {
|
||||
Stack<Node> stack = new Stack<Node>();
|
||||
Stack<Node> stack = new Stack<>();
|
||||
Node prev = root;
|
||||
Node current = root;
|
||||
stack.push(root);
|
||||
|
||||
while (!stack.isEmpty()) {
|
||||
while (current != null && !stack.isEmpty()) {
|
||||
current = stack.peek();
|
||||
boolean hasChild = (current.left != null || current.right != null);
|
||||
boolean isPrevLastChild = (prev == current.right || (prev == current.left && current.right == null));
|
||||
|
@ -13,7 +13,7 @@ public class BinaryTreeUnitTest {
|
||||
|
||||
BinaryTree bt = createBinaryTree();
|
||||
|
||||
assertTrue(!bt.isEmpty());
|
||||
assertFalse(bt.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -72,6 +72,7 @@ public class BinaryTreeUnitTest {
|
||||
|
||||
@Test
|
||||
public void it_deletes_the_root() {
|
||||
|
||||
int value = 12;
|
||||
BinaryTree bt = new BinaryTree();
|
||||
bt.add(value);
|
||||
@ -91,6 +92,14 @@ public class BinaryTreeUnitTest {
|
||||
bt.traverseInOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnEmptyBinaryTree_WhenTraversingInOrderWithoutRecursion_ThenNoException() {
|
||||
|
||||
BinaryTree empty = new BinaryTree();
|
||||
|
||||
empty.traverseInOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenABinaryTree_WhenTraversingPreOrder_ThenPrintValues() {
|
||||
|
||||
@ -101,6 +110,14 @@ public class BinaryTreeUnitTest {
|
||||
bt.traversePreOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnEmptyBinaryTree_WhenTraversingPreOrderWithoutRecursion_ThenNoException() {
|
||||
|
||||
BinaryTree empty = new BinaryTree();
|
||||
|
||||
empty.traversePreOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenABinaryTree_WhenTraversingPostOrder_ThenPrintValues() {
|
||||
|
||||
@ -111,6 +128,14 @@ public class BinaryTreeUnitTest {
|
||||
bt.traversePostOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnEmptyBinaryTree_WhenTraversingPostOrderWithoutRecursion_ThenNoException() {
|
||||
|
||||
BinaryTree empty = new BinaryTree();
|
||||
|
||||
empty.traversePostOrderWithoutRecursion();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenABinaryTree_WhenTraversingLevelOrder_ThenPrintValues() {
|
||||
|
||||
|
@ -29,7 +29,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.16</version>
|
||||
<configuration>
|
||||
<enableAssertions>true</enableAssertions>
|
||||
</configuration>
|
||||
|
@ -66,7 +66,6 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>0</forkCount>
|
||||
</configuration>
|
||||
@ -75,13 +74,10 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<source.version>9</source.version>
|
||||
<target.version>9</target.version>
|
||||
|
||||
<compiler.plugin.version>3.8.1</compiler.plugin.version>
|
||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
||||
|
||||
<appmodules.version>1.0</appmodules.version>
|
||||
|
||||
|
@ -99,15 +99,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<joda-money.version>1.0.1</joda-money.version>
|
||||
|
||||
|
@ -97,7 +97,6 @@
|
||||
<!-- Skip normal test execution, we use gwt:test instead -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
@ -113,12 +112,8 @@
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<!-- Don't let your Mac use a crazy non-standard encoding -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<gwt.version>2.8.2</gwt.version>
|
||||
<gwt.plugin.version>1.0-rc-8</gwt.plugin.version>
|
||||
<surefire.plugin.version>2.17</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -66,14 +66,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -38,14 +38,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -37,14 +37,6 @@
|
||||
|
||||
<build>
|
||||
<finalName>guava-collections-set</finalName>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -71,14 +71,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -40,14 +40,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
@ -52,14 +52,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -46,17 +46,8 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
</properties>
|
||||
|
@ -50,16 +50,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
</properties>
|
||||
|
@ -51,14 +51,6 @@
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -1,42 +1,42 @@
|
||||
package com.baeldung.rmi;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.rmi.NotBoundException;
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class JavaRMIIntegrationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void whenRunServer_thenServerStarts() {
|
||||
private MessengerServiceImpl messengerService;
|
||||
|
||||
try {
|
||||
MessengerServiceImpl server = new MessengerServiceImpl();
|
||||
server.createStubAndBind();
|
||||
} catch (RemoteException e) {
|
||||
fail("Exception Occurred: " + e);
|
||||
}
|
||||
}
|
||||
@Before
|
||||
public void init() {
|
||||
try {
|
||||
messengerService = new MessengerServiceImpl();
|
||||
messengerService.createStubAndBind();
|
||||
} catch (RemoteException e) {
|
||||
fail("Exception Occurred: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() {
|
||||
@Test
|
||||
public void whenClientSendsMessageToServer_thenServerSendsResponseMessage() {
|
||||
try {
|
||||
Registry registry = LocateRegistry.getRegistry();
|
||||
MessengerService server = (MessengerService) registry.lookup("MessengerService");
|
||||
String responseMessage = server.sendMessage("Client Message");
|
||||
|
||||
try {
|
||||
Registry registry = LocateRegistry.getRegistry();
|
||||
MessengerService server = (MessengerService) registry.lookup("MessengerService");
|
||||
String responseMessage = server.sendMessage("Client Message");
|
||||
|
||||
String expectedMessage = "Server Message";
|
||||
assertEquals(responseMessage, expectedMessage);
|
||||
} catch (RemoteException | NotBoundException e) {
|
||||
fail("Exception Occurred: " + e);
|
||||
};
|
||||
}
|
||||
String expectedMessage = "Server Message";
|
||||
assertEquals(responseMessage, expectedMessage);
|
||||
} catch (RemoteException | NotBoundException e) {
|
||||
fail("Exception Occurred: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -523,7 +523,6 @@
|
||||
<jersey.version>2.25</jersey.version>
|
||||
<arquillian-glassfish.version>1.0.0.Final</arquillian-glassfish.version>
|
||||
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
|
||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
||||
<taglibs.standard.version>1.1.2</taglibs.standard.version>
|
||||
<com.sun.faces.jsf.version>2.2.14</com.sun.faces.jsf.version>
|
||||
<httpclient.version>4.5</httpclient.version>
|
||||
|
@ -12,7 +12,7 @@ import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class CustomCheckPointUnitTest {
|
||||
class CustomCheckPointIntegrationTest {
|
||||
@Test
|
||||
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
@ -16,7 +16,7 @@ import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class JobSequenceUnitTest {
|
||||
class JobSequenceIntegrationTest {
|
||||
@Test
|
||||
public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
@ -11,7 +11,7 @@ import javax.batch.runtime.JobExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleBatchLetUnitTest {
|
||||
class SimpleBatchLetIntegrationTest {
|
||||
@Test
|
||||
public void givenBatchLet_thenBatch_CompleteWithSuccess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
@ -16,7 +16,7 @@ import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleChunkUnitTest {
|
||||
class SimpleChunkIntegrationTest {
|
||||
@Test
|
||||
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
|
||||
JobOperator jobOperator = BatchRuntime.getJobOperator();
|
@ -13,7 +13,7 @@ import javax.batch.runtime.StepExecution;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class SimpleErrorChunkUnitTest {
|
||||
class SimpleErrorChunkIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenChunkError_thenBatch_CompletesWithFailed() throws Exception {
|
@ -1099,8 +1099,6 @@
|
||||
<scala.version>2.12.6</scala.version>
|
||||
<node.version>v10.15.0</node.version>
|
||||
<npm.version>6.4.1</npm.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
|
@ -1020,8 +1020,6 @@
|
||||
<scala.version>2.12.6</scala.version>
|
||||
<node.version>v8.12.0</node.version>
|
||||
<npm.version>6.4.1</npm.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
|
@ -840,8 +840,6 @@
|
||||
<scala.version>2.12.6</scala.version>
|
||||
<node.version>v8.12.0</node.version>
|
||||
<npm.version>6.4.1</npm.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
|
@ -842,8 +842,6 @@
|
||||
<scala.version>2.12.6</scala.version>
|
||||
<node.version>v8.12.0</node.version>
|
||||
<npm.version>6.4.1</npm.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<maven.build.timestamp.format>yyyyMMddHHmmss</maven.build.timestamp.format>
|
||||
<maven.compiler.source>${java.version}</maven.compiler.source>
|
||||
|
@ -19,12 +19,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk.jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jol</groupId>
|
||||
@ -76,7 +76,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<openjdk.jmh.version>1.19</openjdk.jmh.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<jol-core.version>0.10</jol-core.version>
|
||||
<maven-assembly-plugin.version>3.2.0</maven-assembly-plugin.version>
|
||||
|
@ -11,3 +11,7 @@ An easy way to check that everything is working as expected is issuing any *kube
|
||||
$ kubectl get nodes
|
||||
```
|
||||
If you get a valid response, then you're good to go.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Paging and Async Calls with the Kubernetes API](https://www.baeldung.com/java-kubernetes-paging-async)
|
||||
|
@ -55,12 +55,12 @@
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy</artifactId>
|
||||
<version>${bytebuddy.version}</version>
|
||||
<version>${byte-buddy.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.bytebuddy</groupId>
|
||||
<artifactId>byte-buddy-agent</artifactId>
|
||||
<version>${bytebuddy.version}</version>
|
||||
<version>${byte-buddy.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--Java Docker API Client -->
|
||||
@ -115,7 +115,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -127,14 +127,12 @@
|
||||
<scala.version>2.11</scala.version>
|
||||
<typesafe-akka.version>2.5.11</typesafe-akka.version>
|
||||
<streamex.version>0.6.5</streamex.version>
|
||||
<bytebuddy.version>1.7.1</bytebuddy.version>
|
||||
<docker.version>3.0.14</docker.version>
|
||||
<caffeine.version>2.5.5</caffeine.version>
|
||||
<findbugs.version>3.0.2</findbugs.version>
|
||||
<fugue.version>4.5.1</fugue.version>
|
||||
<jnats.version>1.0</jnats.version>
|
||||
<jctools.version>2.1.2</jctools.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -26,13 +26,13 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- Eclipse Collections -->
|
||||
@ -46,10 +46,11 @@
|
||||
<properties>
|
||||
<fastutil.version>8.2.2</fastutil.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
<eclipse-collections.version>10.0.0</eclipse-collections.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<jmh-core.version>1.28</jmh-core.version>
|
||||
<jmh-generator.version>1.28</jmh-generator.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -202,7 +202,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
@ -395,7 +395,6 @@
|
||||
<spring-mock-mvc.version>3.0.3</spring-mock-mvc.version>
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
<jool.version>0.9.12</jool.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<commons-net.version>3.6</commons-net.version>
|
||||
<commonsio.version>2.6</commonsio.version>
|
||||
|
@ -95,14 +95,6 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
|
@ -14,23 +14,13 @@
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>flogger</module>
|
||||
<module>log4j</module>
|
||||
<module>log4j2</module>
|
||||
<module>logback</module>
|
||||
<module>log-mdc</module>
|
||||
<module>flogger</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<junit-jupiter.version>5.6.2</junit-jupiter.version>
|
||||
</properties>
|
||||
|
@ -20,14 +20,15 @@
|
||||
<module>maven-integration-test</module>
|
||||
<module>maven-multi-source</module>
|
||||
<module>maven-plugins</module>
|
||||
<module>maven-unused-dependencies</module>
|
||||
<module>maven-war-plugin</module>
|
||||
<module>maven-profiles</module>
|
||||
<module>maven-properties</module>
|
||||
<module>versions-maven-plugin</module>
|
||||
<module>version-collision</module>
|
||||
<!-- <module>maven-proxy</module> --> <!-- Not a maven project -->
|
||||
<module>maven-unused-dependencies</module>
|
||||
<module>maven-war-plugin</module>
|
||||
<module>optional-dependencies</module>
|
||||
<module>version-collision</module>
|
||||
<module>version-overriding-plugins</module>
|
||||
<module>versions-maven-plugin</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
@ -32,18 +32,17 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
<jmh.version>1.19</jmh.version>
|
||||
<modelmapper.version>2.3.7</modelmapper.version>
|
||||
<hamcrest.version>2.2</hamcrest.version>
|
||||
</properties>
|
||||
|
@ -15,10 +15,6 @@
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
|
@ -38,8 +38,8 @@ public class UsingOptional {
|
||||
.flatMap(list -> list.stream().findFirst());
|
||||
}
|
||||
|
||||
private Optional<List> getOptionalList() {
|
||||
return Optional.ofNullable(getList());
|
||||
private Optional<List<String>> getOptionalList() {
|
||||
return Optional.of(getList());
|
||||
}
|
||||
|
||||
private String doSomething(boolean processed) {
|
||||
|
@ -19,22 +19,22 @@ class UsingOptionalUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsFalse_thenReturnEmptyResponse() {
|
||||
void whenArgIsFalse_thenReturnEmptyResponse() {
|
||||
Optional<Object> result = dataObject.process(false);
|
||||
|
||||
assertFalse(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsTrue_thenReturnValidResponse() {
|
||||
void whenArgIsTrue_thenReturnValidResponse() {
|
||||
Optional<Object> result = dataObject.process(true);
|
||||
|
||||
assertTrue(result.isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenArgIsFalse_thenChainResponseAndThrowException() {
|
||||
assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(() -> new Exception()));
|
||||
void whenArgIsFalse_thenChainResponseAndThrowException() {
|
||||
assertThrows(Exception.class, () -> dataObject.process(false).orElseThrow(Exception::new));
|
||||
}
|
||||
|
||||
@Test()
|
||||
@ -51,7 +51,4 @@ class UsingOptionalUnitTest {
|
||||
void whenOptionalListFirst_returnsEmptyOptional() {
|
||||
assertFalse(dataObject.optionalListFirst().isPresent());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -15,10 +15,6 @@
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -42,12 +42,12 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@ -67,7 +67,7 @@
|
||||
<path>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</path>
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
@ -147,19 +147,11 @@
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>${source.plugin.version}</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<!--
|
||||
JMH version to use with this project.
|
||||
-->
|
||||
<jmh.version>1.23</jmh.version>
|
||||
<orika.version>1.5.4</orika.version>
|
||||
<dozer.version>6.5.0</dozer.version>
|
||||
<mapstruct.version>1.3.1.Final</mapstruct.version>
|
||||
@ -185,7 +177,6 @@
|
||||
<resources.plugin.version>3.1.0</resources.plugin.version>
|
||||
<site.plugin.version>3.9.1</site.plugin.version>
|
||||
<source.plugin.version>3.2.1</source.plugin.version>
|
||||
<surefire.plugin.version>2.17</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -31,7 +31,7 @@
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>testcontainers</artifactId>
|
||||
<version>1.14.3</version>
|
||||
<version>${testcontainers.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
|
||||
<properties>
|
||||
<org.apache.bookkeeper.version>4.10.0</org.apache.bookkeeper.version>
|
||||
<testcontainers.version>1.14.3</testcontainers.version>
|
||||
</properties>
|
||||
|
||||
|
||||
|
@ -2,3 +2,4 @@
|
||||
|
||||
- [Getting Database URL From JDBC Connection Object](https://www.baeldung.com/jdbc-get-url-from-connection)
|
||||
- [JDBC URL Format For Different Databases](https://www.baeldung.com/java-jdbc-url-format)
|
||||
- [How to Check if a Database Table Exists with JDBC](https://www.baeldung.com/jdbc-check-table-exists)
|
||||
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.tableexists;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
|
||||
class DatabaseConfig {
|
||||
static Connection connect() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("org.h2.Driver");
|
||||
String url = "jdbc:h2:mem:testdb";
|
||||
return DriverManager.getConnection(url, "user", "password");
|
||||
}
|
||||
|
||||
static void createTables(Connection connection) throws SQLException {
|
||||
connection.createStatement().executeUpdate("create table EMPLOYEE (id int primary key auto_increment, name VARCHAR(255))");
|
||||
}
|
||||
|
||||
static void dropTables(Connection connection) throws SQLException {
|
||||
connection.createStatement().executeUpdate("drop table EMPLOYEE");
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.baeldung.tableexists;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
class TableChecker {
|
||||
static void printAllTables(Connection connection, String tableName) throws SQLException {
|
||||
DatabaseMetaData databaseMetaData = connection.getMetaData();
|
||||
ResultSet resultSet = databaseMetaData.getTables(null, null, tableName, new String[] {"TABLE"});
|
||||
|
||||
while (resultSet.next()) {
|
||||
String name = resultSet.getString("TABLE_NAME");
|
||||
String schema = resultSet.getString("TABLE_SCHEM");
|
||||
System.out.println(name + " on schema " + schema);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean tableExists(Connection connection, String tableName) throws SQLException {
|
||||
DatabaseMetaData meta = connection.getMetaData();
|
||||
ResultSet resultSet = meta.getTables(null, null, tableName, new String[] {"TABLE"});
|
||||
|
||||
return resultSet.next();
|
||||
}
|
||||
|
||||
static boolean tableExistsSQL(Connection connection, String tableName) throws SQLException {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT count(*) " +
|
||||
"FROM information_schema.tables " +
|
||||
"WHERE table_name = ?" +
|
||||
"LIMIT 1;");
|
||||
preparedStatement.setString(1, tableName);
|
||||
|
||||
ResultSet resultSet = preparedStatement.executeQuery();
|
||||
resultSet.next();
|
||||
return resultSet.getInt(1) != 0;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.baeldung.tableexists;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class TableCheckerUnitTest {
|
||||
|
||||
@Test
|
||||
void givenCreatedTable_shouldFindTable() throws SQLException, ClassNotFoundException {
|
||||
// given
|
||||
Connection connection = DatabaseConfig.connect();
|
||||
DatabaseConfig.createTables(connection);
|
||||
|
||||
// when
|
||||
boolean tableExists = TableChecker.tableExists(connection, "EMPLOYEE");
|
||||
|
||||
// then
|
||||
TableChecker.printAllTables(connection, null);
|
||||
assertTrue(tableExists);
|
||||
|
||||
DatabaseConfig.dropTables(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenCreatedTable_shouldFindTableWithSQL() throws SQLException, ClassNotFoundException {
|
||||
// given
|
||||
Connection connection = DatabaseConfig.connect();
|
||||
DatabaseConfig.createTables(connection);
|
||||
|
||||
// when
|
||||
boolean tableExists = TableChecker.tableExistsSQL(connection, "EMPLOYEE");
|
||||
|
||||
// then
|
||||
TableChecker.printAllTables(connection, null);
|
||||
assertTrue(tableExists);
|
||||
|
||||
DatabaseConfig.dropTables(connection);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNoTable_shouldNotFindTable() throws SQLException, ClassNotFoundException {
|
||||
// given
|
||||
Connection connection = DatabaseConfig.connect();
|
||||
|
||||
// when
|
||||
boolean tableExists = TableChecker.tableExists(connection, "EMPLOYEE");
|
||||
|
||||
// then
|
||||
TableChecker.printAllTables(connection, null);
|
||||
assertFalse(tableExists);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNoTable_shouldNotFindTableWithSQL() throws SQLException, ClassNotFoundException {
|
||||
// given
|
||||
Connection connection = DatabaseConfig.connect();
|
||||
|
||||
// when
|
||||
boolean tableExists = TableChecker.tableExistsSQL(connection, "EMPLOYEE");
|
||||
|
||||
// then
|
||||
TableChecker.printAllTables(connection, null);
|
||||
assertFalse(tableExists);
|
||||
}
|
||||
}
|
@ -79,7 +79,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk-jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
@ -94,7 +94,6 @@
|
||||
<postgresql.version>42.2.11</postgresql.version>
|
||||
<mariaDB4j.version>2.2.3</mariaDB4j.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
<openjdk-jmh.version>1.21</openjdk-jmh.version>
|
||||
<spring-boot.version>2.1.7.RELEASE</spring-boot.version>
|
||||
</properties>
|
||||
|
||||
|
@ -175,7 +175,6 @@
|
||||
<log4jdbc.version>2.0.0</log4jdbc.version>
|
||||
<logback.version>1.2.3</logback.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<maven.surefire.version>2.22.2</maven.surefire.version>
|
||||
<maven.compiler.version>3.8.1</maven.compiler.version>
|
||||
<maven.version>3.8.1</maven.version>
|
||||
<mysql.version>8.0.19</mysql.version>
|
||||
|
@ -53,7 +53,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk-jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -61,7 +61,6 @@
|
||||
<mysql.version>6.0.6</mysql.version>
|
||||
<mariaDB4j.version>2.2.3</mariaDB4j.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
<openjdk-jmh.version>1.21</openjdk-jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -59,7 +59,7 @@
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${openjdk-jmh.version}</version>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -68,7 +68,6 @@
|
||||
<mysql.version>6.0.6</mysql.version>
|
||||
<mariaDB4j.version>2.2.3</mariaDB4j.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
<openjdk-jmh.version>1.21</openjdk-jmh.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -30,17 +30,17 @@
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>8.0.21</version>
|
||||
<version>${mysql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.3</version>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-hibernate5</artifactId>
|
||||
<version>2.9.8</version>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<!--Compile time JPA API -->
|
||||
<dependency>
|
||||
@ -87,6 +87,7 @@
|
||||
<hibernate.version>5.4.14.Final</hibernate.version>
|
||||
<eclipselink.version>2.7.4</eclipselink.version>
|
||||
<postgres.version>42.2.5</postgres.version>
|
||||
<mysql.version>8.0.21</mysql.version>
|
||||
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
|
@ -9,6 +9,7 @@ import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
public class HibernateConfig {
|
||||
|
||||
private static SessionFactory sessionFactory;
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
@ -16,12 +17,12 @@ public class HibernateConfig {
|
||||
Configuration configuration = new Configuration();
|
||||
|
||||
Properties settings = new Properties();
|
||||
settings.put(Environment.DRIVER, "com.mysql.cj.jdbc.Driver");
|
||||
settings.put(Environment.URL, "jdbc:mysql://localhost:3306/app_db?useSSL=false");
|
||||
settings.put(Environment.USER, "root");
|
||||
settings.put(Environment.PASS, "password");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.MySQL5Dialect");
|
||||
settings.put(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread");
|
||||
settings.put(Environment.DRIVER, "org.h2.Driver");
|
||||
settings.put(Environment.URL, "jdbc:h2:mem:test");
|
||||
settings.put(Environment.USER, "sa");
|
||||
settings.put(Environment.PASS, "");
|
||||
settings.put(Environment.DIALECT, "org.hibernate.dialect.H2Dialect");
|
||||
settings.put(Environment.HBM2DDL_AUTO, "create-drop");
|
||||
configuration.setProperties(settings);
|
||||
|
||||
configuration.addAnnotatedClass(User.class);
|
||||
|
@ -1,18 +1,24 @@
|
||||
package com.baeldung.ignorable.fields;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
public class TransientFieldUnitTest {
|
||||
|
||||
@ -34,18 +40,20 @@ public class TransientFieldUnitTest {
|
||||
@Test
|
||||
public void givenFieldWithTransientAnnotation_whenSerializingObject_thenFieldSerialized() throws IOException, ClassNotFoundException {
|
||||
|
||||
FileOutputStream fout = new FileOutputStream("test.obj");
|
||||
ObjectOutputStream out = new ObjectOutputStream(fout);
|
||||
out.writeObject(user);
|
||||
out.flush();
|
||||
out.close();
|
||||
try (FileOutputStream fout = new FileOutputStream("test.obj")) {
|
||||
ObjectOutputStream out = new ObjectOutputStream(fout);
|
||||
out.writeObject(user);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
FileInputStream fin = new FileInputStream("test.obj");
|
||||
ObjectInputStream in = new ObjectInputStream(fin);
|
||||
User savedUser = (User) in.readObject();
|
||||
in.close();
|
||||
try (FileInputStream fin = new FileInputStream("test.obj")) {
|
||||
ObjectInputStream in = new ObjectInputStream(fin);
|
||||
User savedUser = (User) in.readObject();
|
||||
|
||||
assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice());
|
||||
assertEquals(user.getCurrentDevice(), savedUser.getCurrentDevice());
|
||||
}
|
||||
|
||||
Files.deleteIfExists(Paths.get("test.obj"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -19,28 +19,34 @@
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq</artifactId>
|
||||
<version>3.13.4</version>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-meta</artifactId>
|
||||
<version>3.13.4</version>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jooq-codegen</artifactId>
|
||||
<version>3.13.4</version>
|
||||
<version>${jooq.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.16</version>
|
||||
<version>${postgresql.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.200</version>
|
||||
<version>${h2.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jooq.version>3.13.4</jooq.version>
|
||||
<postgresql.version>42.2.16</postgresql.version>
|
||||
<h2.version>1.4.200</h2.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -38,6 +38,7 @@
|
||||
<module>java-jdbi</module>
|
||||
<module>java-jpa</module> <!-- long running -->
|
||||
<module>java-jpa-2</module> <!-- long running -->
|
||||
<module>java-jpa-3</module>
|
||||
<module>java-mongodb</module> <!-- long running -->
|
||||
<module>jnosql</module> <!-- long running -->
|
||||
<module>jooq</module>
|
||||
|
@ -47,7 +47,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.release.version>11</maven.release.version>
|
||||
<sirix-core.version>0.9.3</sirix-core.version>
|
||||
<compiler.plugin.version>3.8.0</compiler.plugin.version>
|
||||
|
@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = {SpringBootJdbiApplication.class, JdbiConfiguration.class})
|
||||
@Slf4j
|
||||
public class SpringBootJdbiApplicationUnitTest {
|
||||
public class SpringBootJdbiApplicationIntegrationTest {
|
||||
|
||||
|
||||
@Autowired
|
@ -20,7 +20,7 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
public class CustomerControllerUnitTest {
|
||||
public class CustomerControllerIntegrationTest {
|
||||
|
||||
private static MediaType MEDIA_TYPE_JSON;
|
||||
|
@ -14,9 +14,7 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<cosmodb.version>2.3.0</cosmodb.version>
|
||||
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -61,7 +61,7 @@
|
||||
<plugin>
|
||||
<groupId>com.mysema.maven</groupId>
|
||||
<artifactId>maven-apt-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<version>${maven-apt-plugin.version}</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-sources</phase>
|
||||
@ -88,6 +88,7 @@
|
||||
<start-class>com.baeldung.springdatageode.app.ClientCacheApp</start-class>
|
||||
<spring-geode-starter-version>1.1.1.RELEASE</spring-geode-starter-version>
|
||||
<spring.boot.starter.version>2.1.9.RELEASE</spring.boot.starter.version>
|
||||
<maven-apt-plugin.version>1.0</maven-apt-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -78,7 +78,7 @@
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
@ -86,7 +86,7 @@
|
||||
<path>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct-processor</artifactId>
|
||||
<version>1.3.1.Final</version>
|
||||
<version>${mapstruct.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
@ -98,7 +98,6 @@
|
||||
<mapstruct.version>1.3.1.Final</mapstruct.version>
|
||||
<guava.version>21.0</guava.version>
|
||||
<testcontainers.version>1.12.2</testcontainers.version>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
@ -6,18 +6,15 @@ import com.baeldung.projection.repository.PersonRepository;
|
||||
import com.baeldung.projection.view.AddressView;
|
||||
import com.baeldung.projection.view.PersonDto;
|
||||
import com.baeldung.projection.view.PersonView;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.jdbc.Sql;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD;
|
||||
|
||||
@DataJpaTest
|
||||
@RunWith(SpringRunner.class)
|
||||
@Sql(scripts = "/projection-insert-data.sql")
|
||||
@Sql(scripts = "/projection-clean-up-data.sql", executionPhase = AFTER_TEST_METHOD)
|
||||
public class JpaProjectionIntegrationTest {
|
||||
|
@ -162,6 +162,25 @@ public class ApplicationView {
|
||||
return betweenItems;
|
||||
}
|
||||
|
||||
// To get records having itemName in 'Skate Board', 'Paint' and 'Glue'
|
||||
public String[] inCriteria() {
|
||||
final Session session = HibernateUtil.getHibernateSession();
|
||||
final CriteriaBuilder cb = session.getCriteriaBuilder();
|
||||
final CriteriaQuery<Item> cr = cb.createQuery(Item.class);
|
||||
final Root<Item> root = cr.from(Item.class);
|
||||
cr.select(root)
|
||||
.where(root.get("itemName").in("Skate Board", "Paint", "Glue"));
|
||||
Query<Item> query = session.createQuery(cr);
|
||||
final List<Item> inItemsList = query.getResultList();
|
||||
final String inItems[] = new String[inItemsList.size()];
|
||||
for (int i = 0; i < inItemsList.size(); i++) {
|
||||
inItems[i] = inItemsList.get(i)
|
||||
.getItemName();
|
||||
}
|
||||
session.close();
|
||||
return inItems;
|
||||
}
|
||||
|
||||
// To check if the given property is null
|
||||
public String[] nullCriteria() {
|
||||
final Session session = HibernateUtil.getHibernateSession();
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user