Merge remote-tracking branch 'baeldung/master' into BAEL-4288#flyway-repair

This commit is contained in:
Adrian Maghear
2020-07-17 15:28:06 +02:00
62 changed files with 1229 additions and 86 deletions
+1 -1
View File
@@ -13,4 +13,4 @@ This module contains articles about core Java input and output (IO)
- [How to Copy a File with Java](https://www.baeldung.com/java-copy-file)
- [Create a Directory in Java](https://www.baeldung.com/java-create-directory)
- [Java IO vs NIO](https://www.baeldung.com/java-io-vs-nio)
- [[<-- Prev]](/core-java-modules/core-java-io)
- [[<-- Prev]](/core-java-modules/core-java-io)[[More -->]](/core-java-modules/core-java-io-3)
@@ -0,0 +1,7 @@
## Core Java IO
This module contains articles about core Java input and output (IO)
### Relevant Articles:
- [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file)
- [[<-- Prev]](/core-java-modules/core-java-io-2)
+86
View File
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-io-3</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-io-3</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung.core-java-modules</groupId>
<artifactId>core-java-modules</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<!-- utils -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<!-- logging -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.tomakehurst/wiremock -->
<dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${wiremock.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>core-java-io-3</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven-javadoc-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<assertj.version>3.6.1</assertj.version>
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
<wiremock.version>2.26.3</wiremock.version>
</properties>
</project>
@@ -0,0 +1,50 @@
package com.baeldung.createfile;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CreateFileUnitTest {
private final String FILE_NAME = "src/test/resources/fileToCreate.txt";
@AfterEach
@BeforeEach
public void cleanUpFiles() {
File targetFile = new File(FILE_NAME);
targetFile.delete();
}
@Test
public void givenUsingNio_whenCreatingFile_thenCorrect() throws IOException {
Path newFilePath = Paths.get(FILE_NAME);
Files.createFile(newFilePath);
}
@Test
public void givenUsingFile_whenCreatingFile_thenCorrect() throws IOException {
File newFile = new File(FILE_NAME);
boolean success = newFile.createNewFile();
assertTrue(success);
}
@Test
public void givenUsingGuava_whenCreatingFile_thenCorrect() throws IOException {
com.google.common.io.Files.touch(new File(FILE_NAME));
}
@Test
public void givenUsingCommonsIo_whenCreatingFile_thenCorrect() throws IOException {
FileUtils.touch(new File(FILE_NAME));
}
}
+1 -1
View File
@@ -39,4 +39,4 @@
<assertj.version>3.12.2</assertj.version>
</properties>
</project>
</project>
@@ -0,0 +1,23 @@
package com.baeldung.staticvariables;
public class StaticVariableDemo {
public static int i;
public static int j = 20;
public static int z;
static {
z = 30;
a = 40;
}
public static int a = 50;
public static final int b = 100;
public StaticVariableDemo() {
}
static class Nested {
public static String nestedClassStaticVariable = "test";
}
}
@@ -0,0 +1,113 @@
package com.baeldung.staticvariables;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Field;
import org.junit.jupiter.api.Test;
public class StaticVariableUnitTest {
@Test
public void initializeStaticVariable_checkAssignedValues() {
try {
Class<?> staticVariableDemo = this.getClass()
.getClassLoader()
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
Field field1 = staticVariableDemo.getField("i");
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(0);
Field field2 = staticVariableDemo.getField("j");
assertThat(field2.getInt(staticVariableDemo)).isEqualTo(20);
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Test
public void initializeStaticVariable_checkStaticBlock() {
try {
Class<?> staticVariableDemo = this.getClass()
.getClassLoader()
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
Field field1 = staticVariableDemo.getField("z");
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(30);
Field field2 = staticVariableDemo.getField("a");
assertThat(field2.getInt(staticVariableDemo)).isEqualTo(50);
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Test
public void initializeStaticVariable_checkFinalValues() {
try {
Class<?> staticVariableDemo = this.getClass()
.getClassLoader()
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
Field field1 = staticVariableDemo.getField("b");
assertThat(field1.getInt(staticVariableDemo)).isEqualTo(100);
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
@Test
public void initializeStaticVariable_checkInnerClassValues() {
try {
Class<?> staticVariableDemo = this.getClass()
.getClassLoader()
.loadClass("com.baeldung.staticvariables.StaticVariableDemo");
Class<?>[] nestedClasses = staticVariableDemo.getClasses();
for (Class<?> nestedClass : nestedClasses) {
if (nestedClass.getName()
.equals("Nested")) {
Field field1 = nestedClass.getField("nestedClassStaticVariable");
assertThat(field1.get(nestedClass)).isEqualTo("test");
}
}
} catch (ClassNotFoundException | NoSuchFieldException | SecurityException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
+1
View File
@@ -72,6 +72,7 @@
<module>core-java-io</module>
<module>core-java-io-2</module>
<module>core-java-io-3</module>
<module>core-java-io-apis</module>
<module>core-java-io-conversions</module>
<module>core-java-io-conversions-2</module>
@@ -0,0 +1,46 @@
package com.baeldung.ddd.order.config;
import org.bson.Document;
import org.joda.money.CurrencyUnit;
import org.joda.money.Money;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import java.math.BigDecimal;
import java.util.Collections;
@Configuration
public class CustomMongoConfiguration {
@Bean
public MongoCustomConversions customConversions() {
return new MongoCustomConversions(Collections.singletonList(DocumentToMoneyConverter.INSTANCE));
}
@ReadingConverter
enum DocumentToMoneyConverter implements Converter<Document, Money> {
INSTANCE;
@Override
public Money convert(Document source) {
Document money = source.get("money", Document.class);
return Money.of(getCurrency(money), getAmount(money));
}
private CurrencyUnit getCurrency(Document money) {
Document currency = money.get("currency", Document.class);
String currencyCode = currency.getString("code");
return CurrencyUnit.of(currencyCode);
}
private BigDecimal getAmount(Document money) {
String amount = money.getString("amount");
return BigDecimal.valueOf(Double.parseDouble(amount));
}
}
}
@@ -1,19 +1,24 @@
package com.baeldung.ddd.order.jpa;
import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.util.Arrays;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import java.math.BigDecimal;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
public class PersistOrderIntegrationTest {
public class PersistOrderLiveTest {
@Autowired
private JpaOrderRepository repository;
@@ -17,9 +17,14 @@ import com.baeldung.ddd.order.Order;
import com.baeldung.ddd.order.OrderLine;
import com.baeldung.ddd.order.Product;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
public class OrderMongoIntegrationTest {
public class OrderMongoLiveTest {
@Autowired
private OrderMongoRepository repo;
@@ -18,10 +18,15 @@ import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class CassandraDbOrderRepositoryIntegrationTest {
class CassandraDbOrderRepositoryLiveTest {
@Autowired
private SpringDataCassandraOrderRepository cassandraOrderRepository;
@@ -18,10 +18,15 @@ import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository;
/*
To run this test we need to run the databases first.
A dedicated docker-compose.yml file is located under the resources directory.
We can run it by simple executing `docker-compose up`.
*/
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class MongoDbOrderRepositoryIntegrationTest {
class MongoDbOrderRepositoryLiveTest {
@Autowired
private SpringDataMongoOrderRepository mongoOrderRepository;
+1
View File
@@ -15,4 +15,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m
- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library)
- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once)
- [Introduction to Protonpack](https://www.baeldung.com/java-protonpack)
- [Java-R Integration](https://www.baeldung.com/java-r-integration)
- More articles [[<-- prev]](/libraries-5)
+45
View File
@@ -92,8 +92,50 @@
<version>${commonsio.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>Rserve</artifactId>
<version>${rserve.version}</version>
</dependency>
<dependency>
<groupId>com.github.jbytecode</groupId>
<artifactId>RCaller</artifactId>
<version>${rcaller.version}</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>${renjin.version}</version>
</dependency>
</dependencies>
<repositories>
<!-- Needed for Renjin -->
<repository>
<id>bedatadriven</id>
<name>bedatadriven public repo</name>
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- Excludes FastR classes from compilations since they require GraalVM -->
<excludes>
<exclude>com/baeldung/r/FastRMean.java</exclude>
</excludes>
<testExcludes>
<exclude>com/baeldung/r/FastRMeanUnitTest.java</exclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<kafka.version>2.0.0</kafka.version>
<javapoet.version>1.10.0</javapoet.version>
@@ -105,6 +147,9 @@
<commons-net.version>3.6</commons-net.version>
<assertj.version>3.6.2</assertj.version>
<commonsio.version>2.6</commonsio.version>
<renjin.version>RELEASE</renjin.version>
<rcaller.version>3.0</rcaller.version>
<rserve.version>1.8.1</rserve.version>
</properties>
@@ -1,8 +1,5 @@
package com.baeldung.r;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* FastR showcase.
*
@@ -1,12 +1,12 @@
package com.baeldung.r;
import java.io.IOException;
import java.net.URISyntaxException;
import com.github.rcaller.rstuff.RCaller;
import com.github.rcaller.rstuff.RCallerOptions;
import com.github.rcaller.rstuff.RCode;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* RCaller showcase.
*
@@ -1,13 +1,12 @@
package com.baeldung.r;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.script.ScriptException;
import org.renjin.script.RenjinScriptEngine;
import org.renjin.sexp.DoubleArrayVector;
import javax.script.ScriptException;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* Renjin showcase.
*
@@ -1,14 +1,13 @@
package com.baeldung.r;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.script.ScriptException;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import javax.script.ScriptException;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* Test for {@link RCallerMean}.
*
@@ -1,13 +1,11 @@
package com.baeldung.r;
import java.io.IOException;
import java.net.URISyntaxException;
import javax.script.ScriptException;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Assert;
import javax.script.ScriptException;
import java.io.IOException;
import java.net.URISyntaxException;
/**
* Test for {@link RenjinMean}.
-2
View File
@@ -8,10 +8,8 @@ This module contains articles about libraries for data processing in Java.
- [Introduction to Conflict-Free Replicated Data Types](https://www.baeldung.com/java-conflict-free-replicated-data-types)
- [Introduction to javax.measure](https://www.baeldung.com/javax-measure)
- [A Guide to Infinispan in Java](https://www.baeldung.com/infinispan)
- [Guide to JMapper](https://www.baeldung.com/jmapper)
- [An Introduction to SuanShu](https://www.baeldung.com/suanshu)
- [Intro to Derive4J](https://www.baeldung.com/derive4j)
- [Java-R Integration](https://www.baeldung.com/java-r-integration)
- [Univocity Parsers](https://www.baeldung.com/java-univocity-parsers)
- [Using Kafka MockConsumer](https://www.baeldung.com/kafka-mockconsumer)
- [Using Kafka MockProducer](https://www.baeldung.com/kafka-mockproducer)
+6 -49
View File
@@ -86,11 +86,6 @@
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.jmapper-framework</groupId>
<artifactId>jmapper-core</artifactId>
<version>${jmapper.version}</version>
</dependency>
<dependency>
<groupId>com.numericalmethod</groupId>
<artifactId>suanshu</artifactId>
@@ -126,6 +121,11 @@
<artifactId>kafka-clients</artifactId>
<version>${kafka.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
@@ -138,21 +138,6 @@
<version>${awaitility.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.rosuda.REngine</groupId>
<artifactId>Rserve</artifactId>
<version>${rserve.version}</version>
</dependency>
<dependency>
<groupId>com.github.jbytecode</groupId>
<artifactId>RCaller</artifactId>
<version>${rcaller.version}</version>
</dependency>
<dependency>
<groupId>org.renjin</groupId>
<artifactId>renjin-script-engine</artifactId>
<version>${renjin.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
@@ -175,33 +160,8 @@
<url>http://repo.numericalmethod.com/maven/</url>
<layout>default</layout>
</repository>
<!-- Needed for Renjin -->
<repository>
<id>bedatadriven</id>
<name>bedatadriven public repo</name>
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- Excludes FastR classes from compilations since they require GraalVM -->
<excludes>
<exclude>com/baeldung/r/FastRMean.java</exclude>
</excludes>
<testExcludes>
<exclude>com/baeldung/r/FastRMeanUnitTest.java</exclude>
</testExcludes>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<flink.version>1.5.0</flink.version>
<hll.version>1.6.0</hll.version>
@@ -210,17 +170,14 @@
<infinispan.version>9.1.5.Final</infinispan.version>
<jackson.version>2.9.8</jackson.version>
<spring.version>4.3.8.RELEASE</spring.version>
<jmapper.version>1.6.0.1</jmapper.version>
<suanshu.version>4.0.0</suanshu.version>
<derive4j.version>1.1.0</derive4j.version>
<assertj.version>3.6.2</assertj.version>
<slf4j.version>1.7.25</slf4j.version>
<awaitility.version>3.0.0</awaitility.version>
<univocity.version>2.8.4</univocity.version>
<renjin.version>RELEASE</renjin.version>
<rcaller.version>3.0</rcaller.version>
<rserve.version>1.8.1</rserve.version>
<kafka.version>2.5.0</kafka.version>
<guava.version>29.0-jre</guava.version>
</properties>
</project>
+1
View File
@@ -12,4 +12,5 @@ This module contains articles about libraries for data processing in Java.
- [Introduction to Kafka Connectors](https://www.baeldung.com/kafka-connectors-guide)
- [Kafka Connect Example with MQTT and MongoDB](https://www.baeldung.com/kafka-connect-mqtt-mongodb)
- [Building a Data Pipeline with Flink and Kafka](https://www.baeldung.com/kafka-flink-data-pipeline)
- [Guide to JMapper](https://www.baeldung.com/jmapper)
More articles: [[next -->]](/../libraries-data-2)
+6
View File
@@ -126,6 +126,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.googlecode.jmapper-framework</groupId>
<artifactId>jmapper-core</artifactId>
<version>${jmapper.version}</version>
</dependency>
</dependencies>
<build>
@@ -172,6 +177,7 @@
<org.apache.crunch.crunch-core.version>0.15.0</org.apache.crunch.crunch-core.version>
<org.apache.hadoop.hadoop-client>2.2.0</org.apache.hadoop.hadoop-client>
<slf4j.version>1.7.25</slf4j.version>
<jmapper.version>1.6.0.1</jmapper.version>
</properties>
</project>

Some files were not shown because too many files have changed in this diff Show More