Merge branch 'eugenp:master' into master
This commit is contained in:
commit
377eeb7279
50
README.md
50
README.md
|
@ -18,27 +18,33 @@ Java and Spring Tutorials
|
|||
|
||||
This project is **a collection of small and focused tutorials** - each covering a single and well defined area of development in the Java ecosystem.
|
||||
A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security.
|
||||
In additional to Spring, the modules here are covering a number of aspects in Java.
|
||||
In addition to Spring, the modules here cover a number of aspects of Java.
|
||||
|
||||
Profile based segregation
|
||||
====================
|
||||
|
||||
We are using maven build profiles to segregate the huge list of individual projects we have in our repository.
|
||||
|
||||
The projects are broadly divided into 3 list: first, second and heavy.
|
||||
As for now, vast majority of the modules require JDK8 to build and run correctly.
|
||||
|
||||
Next, they are segregated further on the basis of tests that we want to execute.
|
||||
The projects are broadly divided into 3 lists: first, second and heavy.
|
||||
|
||||
Therefore, we have a total of 6 profiles:
|
||||
Next, they are segregated further on the basis of the tests that we want to execute.
|
||||
|
||||
| Profile | Includes | Type of test enabled |
|
||||
| ----------------------- | --------------------------- | -------------------- |
|
||||
| default-first | First set of projects | *UnitTest |
|
||||
| integration-lite-first | First set of projects | *IntegrationTest |
|
||||
| default-second | Second set of projects | *UnitTest |
|
||||
| integration-lite-second | Second set of projects | *IntegrationTest |
|
||||
| default-heavy | Heavy/long running projects | *UnitTest |
|
||||
| integration-heavy | Heavy/long running projects | *IntegrationTest |
|
||||
Additionally, there are 2 profiles dedicated for JDK9 and above builds.
|
||||
|
||||
Therefore, we have a total of 8 profiles:
|
||||
|
||||
| Profile | Includes | Type of test enabled |
|
||||
| -------------------------- | --------------------------- | -------------------- |
|
||||
| default-first | First set of projects | *UnitTest |
|
||||
| integration-lite-first | First set of projects | *IntegrationTest |
|
||||
| default-second | Second set of projects | *UnitTest |
|
||||
| integration-lite-second | Second set of projects | *IntegrationTest |
|
||||
| default-heavy | Heavy/long running projects | *UnitTest |
|
||||
| integration-heavy | Heavy/long running projects | *IntegrationTest |
|
||||
| default-jdk9-and-above | JDK9 and above projects | *UnitTest |
|
||||
| integration-jdk9-and-above | JDK9 and above projects | *IntegrationTest |
|
||||
|
||||
Building the project
|
||||
====================
|
||||
|
@ -53,15 +59,22 @@ or if we want to build the entire repository with Integration Tests enabled, we
|
|||
|
||||
`mvn clean install -Pintegration-lite-first,integration-lite-second,integration-heavy`
|
||||
|
||||
Analogously, for the JDK9 and above projects the commands are:
|
||||
|
||||
`mvn clean install -Pdefault-jdk9-and-above`
|
||||
|
||||
and
|
||||
|
||||
`mvn clean install -Pintegration-jdk9-and-above`
|
||||
|
||||
Building a single module
|
||||
====================
|
||||
To build a specific module run the command: `mvn clean install` in the module directory
|
||||
To build a specific module, run the command: `mvn clean install` in the module directory.
|
||||
|
||||
|
||||
Running a Spring Boot module
|
||||
====================
|
||||
To run a Spring Boot module run the command: `mvn spring-boot:run` in the module directory
|
||||
To run a Spring Boot module, run the command: `mvn spring-boot:run` in the module directory.
|
||||
|
||||
|
||||
Working with the IDE
|
||||
|
@ -81,11 +94,8 @@ To run the integration tests, use the command:
|
|||
|
||||
`mvn clean install -Pintegration-lite-second` or
|
||||
|
||||
`mvn clean install -Pintegration-heavy`
|
||||
`mvn clean install -Pintegration-heavy` or
|
||||
|
||||
`mvn clean install -Pintegration-jdk9-and-above`
|
||||
|
||||
depending on the list where our module exists
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -41,4 +41,4 @@
|
|||
<akka.stream.version>2.5.11</akka.stream.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
|
@ -35,18 +35,11 @@
|
|||
<artifactId>jenetics</artifactId>
|
||||
<version>${io.jenetics.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<io.jenetics.version>3.7.0</io.jenetics.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -18,15 +18,16 @@ public class Travel {
|
|||
}
|
||||
|
||||
public void generateInitialTravel() {
|
||||
if (travel.isEmpty())
|
||||
if (travel.isEmpty()) {
|
||||
new Travel(10);
|
||||
}
|
||||
Collections.shuffle(travel);
|
||||
}
|
||||
|
||||
public void swapCities() {
|
||||
int a = generateRandomIndex();
|
||||
int b = generateRandomIndex();
|
||||
previousTravel = travel;
|
||||
previousTravel = new ArrayList<>(travel);
|
||||
City x = travel.get(a);
|
||||
City y = travel.get(b);
|
||||
travel.set(a, y);
|
||||
|
|
|
@ -35,12 +35,6 @@
|
|||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.dpaukov</groupId>
|
||||
<artifactId>combinatoricslib3</artifactId>
|
||||
|
@ -70,9 +64,7 @@
|
|||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
<combinatoricslib3.version>3.3.0</combinatoricslib3.version>
|
||||
<cobertura.plugin.version>2.7</cobertura.plugin.version>
|
||||
</properties>
|
||||
|
|
|
@ -45,12 +45,6 @@
|
|||
<artifactId>tradukisto</artifactId>
|
||||
<version>${tradukisto.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<reporting>
|
||||
|
@ -78,7 +72,6 @@
|
|||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
<org.jgrapht.core.version>1.0.1</org.jgrapht.core.version>
|
||||
<org.jgrapht.ext.version>1.0.1</org.jgrapht.ext.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<cobertura-maven-plugin.version>2.7</cobertura-maven-plugin.version>
|
||||
</properties>
|
||||
|
|
|
@ -14,12 +14,6 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
|
@ -43,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons.lang3.version}</version>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pl.pragmatists</groupId>
|
||||
|
@ -69,11 +63,7 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-collections4.version>4.3</commons-collections4.version>
|
||||
<guava.version>28.0-jre</guava.version>
|
||||
<retrofit.version>2.6.0</retrofit.version>
|
||||
<commons.lang3.version>3.8.1</commons.lang3.version>
|
||||
<JUnitParams.version>1.1.0</JUnitParams.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -25,17 +25,6 @@
|
|||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -34,26 +34,12 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-commons</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<guava.version>28.1-jre</guava.version>
|
||||
<junit.platform.version>1.6.0</junit.platform.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -19,17 +19,6 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-commons</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -44,9 +33,6 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<guava.version>28.1-jre</guava.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<junit.platform.version>1.6.0</junit.platform.version>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
package com.baeldung.algorithms.caesarcipher;
|
||||
|
||||
import org.apache.commons.math3.stat.inference.ChiSquareTest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class CaesarCipher {
|
||||
|
||||
private final Logger log = LoggerFactory.getLogger(CaesarCipher.class);
|
||||
|
||||
private static final char LETTER_A = 'a';
|
||||
private static final char LETTER_Z = 'z';
|
||||
private static final int ALPHABET_SIZE = LETTER_Z - LETTER_A + 1;
|
||||
|
@ -72,7 +77,7 @@ public class CaesarCipher {
|
|||
private int probableOffset(double[] chiSquares) {
|
||||
int probableOffset = 0;
|
||||
for (int offset = 0; offset < chiSquares.length; offset++) {
|
||||
System.out.println(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset]));
|
||||
log.debug(String.format("Chi-Square for offset %d: %.2f", offset, chiSquares[offset]));
|
||||
if (chiSquares[offset] < chiSquares[probableOffset]) {
|
||||
probableOffset = offset;
|
||||
}
|
||||
|
|
|
@ -13,15 +13,6 @@
|
|||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>algorithms-searching</finalName>
|
||||
<resources>
|
||||
|
@ -32,8 +23,4 @@
|
|||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -16,7 +16,7 @@ public class BreadthFirstSearchAlgorithm {
|
|||
Tree<T> currentNode;
|
||||
while (!queue.isEmpty()) {
|
||||
currentNode = queue.remove();
|
||||
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||
LOGGER.debug("Visited node with value: {}", currentNode.getValue());
|
||||
|
||||
if (currentNode.getValue().equals(value)) {
|
||||
return Optional.of(currentNode);
|
||||
|
@ -37,7 +37,7 @@ public class BreadthFirstSearchAlgorithm {
|
|||
|
||||
while (!queue.isEmpty()) {
|
||||
currentNode = queue.remove();
|
||||
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||
LOGGER.debug("Visited node with value: {}", currentNode.getValue());
|
||||
|
||||
if (currentNode.getValue().equals(value)) {
|
||||
return Optional.of(currentNode);
|
||||
|
|
|
@ -35,6 +35,7 @@ public class QuadTreeSearchUnitTest {
|
|||
public void givenQuadTree_whenSearchingForRange_thenReturn1MatchingItem() {
|
||||
Region searchArea = new Region(200, 200, 250, 250);
|
||||
List<Point> result = quadTree.search(searchArea, null, "");
|
||||
|
||||
LOGGER.debug(result.toString());
|
||||
LOGGER.debug(quadTree.printSearchTraversePath());
|
||||
|
||||
|
@ -47,6 +48,7 @@ public class QuadTreeSearchUnitTest {
|
|||
public void givenQuadTree_whenSearchingForRange_thenReturn2MatchingItems() {
|
||||
Region searchArea = new Region(0, 0, 100, 100);
|
||||
List<Point> result = quadTree.search(searchArea, null, "");
|
||||
|
||||
LOGGER.debug(result.toString());
|
||||
LOGGER.debug(quadTree.printSearchTraversePath());
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForA_thenReturn6Matches() {
|
||||
List<String> matches = suffixTree.searchText("a");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] { "h[a]vanabanana", "hav[a]nabanana", "havan[a]banana", "havanab[a]nana", "havanaban[a]na", "havanabanan[a]" }, matches.toArray());
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForNab_thenReturn1Match() {
|
||||
List<String> matches = suffixTree.searchText("nab");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] { "hava[nab]anana" }, matches.toArray());
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForNag_thenReturnNoMatches() {
|
||||
List<String> matches = suffixTree.searchText("nag");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] {}, matches.toArray());
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForBanana_thenReturn2Matches() {
|
||||
List<String> matches = suffixTree.searchText("ana");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] { "hav[ana]banana", "havanab[ana]na", "havanaban[ana]" }, matches.toArray());
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForNa_thenReturn4Matches() {
|
||||
List<String> matches = suffixTree.searchText("na");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] { "hava[na]banana", "havanaba[na]na", "havanabana[na]" }, matches.toArray());
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,14 @@ public class SuffixTreeUnitTest {
|
|||
public void givenSuffixTree_whenSearchingForX_thenReturnNoMatches() {
|
||||
List<String> matches = suffixTree.searchText("x");
|
||||
matches.stream()
|
||||
.forEach(m -> LOGGER.info(m));
|
||||
.forEach(m -> LOGGER.debug(m));
|
||||
Assert.assertArrayEquals(new String[] {}, matches.toArray());
|
||||
}
|
||||
|
||||
private static void printTree() {
|
||||
suffixTree.printTree();
|
||||
|
||||
LOGGER.info("\n" + suffixTree.printTree());
|
||||
LOGGER.info("==============================================");
|
||||
LOGGER.debug("\n" + suffixTree.printTree());
|
||||
LOGGER.debug("==============================================");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,25 +29,11 @@
|
|||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter-api.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<junit-jupiter-api.version>5.3.1</junit-jupiter-api.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -30,25 +30,11 @@
|
|||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter-api.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<junit-jupiter-api.version>5.3.1</junit-jupiter-api.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -98,12 +98,6 @@
|
|||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>kafka</artifactId>
|
||||
|
@ -170,13 +164,11 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<kafka.version>2.8.0</kafka.version>
|
||||
<testcontainers-kafka.version>1.15.3</testcontainers-kafka.version>
|
||||
<testcontainers-jupiter.version>1.15.3</testcontainers-jupiter.version>
|
||||
<flink.version>1.5.0</flink.version>
|
||||
<awaitility.version>3.0.0</awaitility.version>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
<org.apache.spark.spark-core.version>2.4.8</org.apache.spark.spark-core.version>
|
||||
<graphframes.version>0.8.1-spark3.0-s_2.12</graphframes.version>
|
||||
<com.datastax.spark.spark-cassandra-connector.version>2.5.2</com.datastax.spark.spark-cassandra-connector.version>
|
||||
|
|
|
@ -156,13 +156,6 @@
|
|||
<artifactId>solr-solrj</artifactId>
|
||||
<version>${solr.solr-solrj.version}</version>
|
||||
</dependency>
|
||||
<!-- common -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -202,7 +195,6 @@
|
|||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<avro.version>1.8.2</avro.version>
|
||||
<beam.version>2.19.0</beam.version>
|
||||
<assertj.version>3.9.0</assertj.version>
|
||||
<bval.version>1.1.2</bval.version>
|
||||
<javax.validation.validation-api.version>1.1.0.Final</javax.validation.validation-api.version>
|
||||
<meecrowave-junit.version>1.2.0</meecrowave-junit.version>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
|
@ -0,0 +1,4 @@
|
|||
*.docx
|
||||
temp.xls
|
||||
temp.xlsx
|
||||
number_test.xlsx
|
|
@ -0,0 +1,12 @@
|
|||
## Apache POI
|
||||
|
||||
This module contains articles about Apache POI.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Adding a Column to an Excel Sheet Using Apache POI](https://www.baeldung.com/java-excel-add-column)
|
||||
- [Add an Image to a Cell in an Excel File With Java](https://www.baeldung.com/java-add-image-excel)
|
||||
- [Numeric Format Using POI](https://www.baeldung.com/apache-poi-numeric-format)
|
||||
- [Microsoft Word Processing in Java with Apache POI](https://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
||||
- More articles: [[<-- prev]](../apache-poi)
|
|
@ -1,28 +1,29 @@
|
|||
<?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"
|
||||
<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>
|
||||
<groupId>com.stackify</groupId>
|
||||
<artifactId>logback-example</artifactId>
|
||||
<artifactId>apache-poi-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>logback-example</name>
|
||||
<name>apache-poi-2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.janino</groupId>
|
||||
<artifactId>janino</artifactId>
|
||||
<version>${janino.version}</version>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi-ooxml</artifactId>
|
||||
<version>${poi.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<janino.version>3.0.7</janino.version>
|
||||
<poi.version>5.0.0</poi.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package com.baeldung.poi.excel.newcolumn;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
|
||||
public class ExcelColumn {
|
||||
|
||||
public void addColumn(Sheet sheet, CellType cellType) {
|
||||
for (Row currentRow : sheet) {
|
||||
currentRow.createCell(currentRow.getLastCellNum(), cellType);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.poi.excel.newcolumn.numeric;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
|
||||
public class ExcelNumericFormat {
|
||||
|
||||
public static void applyNumericFormat(Workbook outWorkbook, Row row, Cell cell, Double value, String styleFormat) {
|
||||
CellStyle style = outWorkbook.createCellStyle();
|
||||
DataFormat format = outWorkbook.createDataFormat();
|
||||
style.setDataFormat(format.getFormat(styleFormat));
|
||||
cell.setCellValue(value);
|
||||
cell.setCellStyle(style);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.baeldung.poi.excel.write.addimageincell;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
|
||||
import org.apache.poi.xssf.usermodel.XSSFDrawing;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* This Helper class Add an Image to a Cell of an Excel File With apache-poi api.
|
||||
*
|
||||
*/
|
||||
public class ExcelCellImageHelper {
|
||||
|
||||
public static void main(String[] args) throws IOException, InvalidFormatException {
|
||||
try (final Workbook workbook = new XSSFWorkbook();
|
||||
FileOutputStream saveExcel = new FileOutputStream("target/baeldung-apachepoi.xlsx");) {
|
||||
|
||||
Sheet sheet = workbook.createSheet("Avengers");
|
||||
|
||||
XSSFDrawing drawing = (XSSFDrawing) sheet.createDrawingPatriarch();
|
||||
XSSFClientAnchor ironManAnchor = new XSSFClientAnchor();
|
||||
XSSFClientAnchor spiderManAnchor = new XSSFClientAnchor();
|
||||
|
||||
// Fill row1 data
|
||||
Row row1 = sheet.createRow(0);
|
||||
row1.setHeight((short) 1000);
|
||||
row1.createCell(0)
|
||||
.setCellValue("IRON-MAN");
|
||||
updateCellWithImage(workbook, 1, drawing, ironManAnchor, "ironman.png");
|
||||
|
||||
// Fill row2 data
|
||||
Row row2 = sheet.createRow(1);
|
||||
row2.setHeight((short) 1000);
|
||||
row2.createCell(0)
|
||||
.setCellValue("SPIDER-MAN");
|
||||
updateCellWithImage(workbook, 2, drawing, spiderManAnchor, "spiderman.png");
|
||||
|
||||
// Resize all columns to fit the content size
|
||||
for (int i = 0; i < 2; i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
}
|
||||
workbook.write(saveExcel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This method position the anchor for a given rowNum and add the image correctly.
|
||||
* @param workbook
|
||||
* @param rowNum
|
||||
* @param drawing
|
||||
* @param inputImageAnchor
|
||||
* @throws IOException
|
||||
*/
|
||||
private static void updateCellWithImage(Workbook workbook, int rowNum, XSSFDrawing drawing, XSSFClientAnchor inputImageAnchor, String inputImageName) throws IOException {
|
||||
InputStream inputImageStream = ExcelCellImageHelper.class.getClassLoader()
|
||||
.getResourceAsStream(inputImageName);
|
||||
byte[] inputImageBytes = IOUtils.toByteArray(inputImageStream);
|
||||
int inputImagePictureID = workbook.addPicture(inputImageBytes, Workbook.PICTURE_TYPE_PNG);
|
||||
inputImageStream.close();
|
||||
inputImageAnchor.setCol1(1);
|
||||
inputImageAnchor.setRow1(rowNum - 1);
|
||||
inputImageAnchor.setCol2(2);
|
||||
inputImageAnchor.setRow2(rowNum);
|
||||
drawing.createPicture(inputImageAnchor, inputImagePictureID);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,22 @@ import org.apache.poi.sl.usermodel.PictureData;
|
|||
import org.apache.poi.sl.usermodel.TableCell;
|
||||
import org.apache.poi.sl.usermodel.TextParagraph;
|
||||
import org.apache.poi.util.IOUtils;
|
||||
import org.apache.poi.xslf.usermodel.*;
|
||||
import org.apache.poi.xslf.usermodel.SlideLayout;
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFAutoShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFHyperlink;
|
||||
import org.apache.poi.xslf.usermodel.XSLFPictureData;
|
||||
import org.apache.poi.xslf.usermodel.XSLFPictureShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlideLayout;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlideMaster;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTable;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTableCell;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTableRow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTextParagraph;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTextRun;
|
||||
import org.apache.poi.xslf.usermodel.XSLFTextShape;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -155,8 +170,8 @@ public class PowerPointHelper {
|
|||
|
||||
/**
|
||||
* Retrieve the placeholder inside a slide
|
||||
*
|
||||
* @param slide
|
||||
*
|
||||
* @param slide
|
||||
* The slide
|
||||
* @return List of placeholder inside a slide
|
||||
*/
|
|
@ -1,7 +1,11 @@
|
|||
package com.baeldung.poi.word;
|
||||
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
|
||||
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
Before Width: | Height: | Size: 782 B After Width: | Height: | Size: 782 B |
Binary file not shown.
After Width: | Height: | Size: 56 KiB |
|
@ -0,0 +1,40 @@
|
|||
package com.baeldung.poi.excel.newcolumn;
|
||||
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ExcelColumnUnitTest {
|
||||
private static final String FILE_NAME = "newColumnTest.xlsx";
|
||||
private String fileLocation;
|
||||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenExistingRows_whenAddNewColumn_thenRowColumnNumberIncreased() throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
Row row = sheet.getRow(0);
|
||||
assertEquals(5, row.getLastCellNum());
|
||||
|
||||
ExcelColumn excelColumn = new ExcelColumn();
|
||||
excelColumn.addColumn(sheet, CellType.STRING);
|
||||
assertEquals(6, row.getLastCellNum());
|
||||
|
||||
workbook.close();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,105 @@
|
|||
package com.baeldung.poi.excel.newcolumn.numeric;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class NumberCellValueUnitTest {
|
||||
|
||||
@Test
|
||||
public void decimalDisplay_whenAddedDouble_thenNumericCellCreated() throws IOException {
|
||||
File file = new File("number_test.xlsx");
|
||||
try (Workbook outWorkbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = outWorkbook.createSheet("Numeric Sheet");
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
ExcelNumericFormat.applyNumericFormat(outWorkbook, row, cell, 10.251, "0.00");
|
||||
FileOutputStream fileOut = new FileOutputStream(file);
|
||||
outWorkbook.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
try (Workbook inWorkbook = new XSSFWorkbook("number_test.xlsx")) {
|
||||
Sheet sheet = inWorkbook.cloneSheet(0);
|
||||
Row row = sheet.getRow(0);
|
||||
Assertions.assertEquals(10.251, row.getCell(0)
|
||||
.getNumericCellValue());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decimalRoundedDisplay_whenAddedDouble_thenNumericCellCreated() throws IOException {
|
||||
File file = new File("number_test.xlsx");
|
||||
try (Workbook outWorkbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = outWorkbook.createSheet("Numeric Sheet");
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
ExcelNumericFormat.applyNumericFormat(outWorkbook, row, cell, 10.251123, "#,##0.0000");
|
||||
FileOutputStream fileOut = new FileOutputStream(file);
|
||||
outWorkbook.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
try (Workbook inWorkbook = new XSSFWorkbook("number_test.xlsx")) {
|
||||
Sheet sheet = inWorkbook.cloneSheet(0);
|
||||
Row row = sheet.getRow(0);
|
||||
Assertions.assertEquals(10.251123, row.getCell(0)
|
||||
.getNumericCellValue());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decimalDisplayInXLS_whenAddedDouble_thenNumericCellCreated() throws IOException {
|
||||
File file = new File("number_test.xls");
|
||||
try (Workbook outWorkbook = new HSSFWorkbook()) {
|
||||
Sheet sheet = outWorkbook.createSheet("Numeric Sheet");
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
ExcelNumericFormat.applyNumericFormat(outWorkbook, row, cell, 10.251, "0.00");
|
||||
FileOutputStream fileOut = new FileOutputStream(file);
|
||||
outWorkbook.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
try (Workbook inWorkbook = new HSSFWorkbook(new FileInputStream(file))) {
|
||||
Sheet sheet = inWorkbook.cloneSheet(0);
|
||||
Row row = sheet.getRow(0);
|
||||
Assertions.assertEquals(10.251, row.getCell(0)
|
||||
.getNumericCellValue());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decimalValue_whenAddedDouble_thenNumericCellCreated() throws IOException {
|
||||
File file = new File("number_test.xlsx");
|
||||
try (Workbook outWorkbook = new XSSFWorkbook()) {
|
||||
Sheet sheet = outWorkbook.createSheet("Numeric Sheet");
|
||||
Row row = sheet.createRow(0);
|
||||
Cell cell = row.createCell(0);
|
||||
DecimalFormat df = new DecimalFormat("#,###.##");
|
||||
ExcelNumericFormat.applyNumericFormat(outWorkbook, row, cell, Double.valueOf(df.format(10.251)), "#,###.##");
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream(file);
|
||||
outWorkbook.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
try (Workbook inWorkbook = new XSSFWorkbook("number_test.xlsx")) {
|
||||
Sheet sheet = inWorkbook.cloneSheet(0);
|
||||
Row row = sheet.getRow(0);
|
||||
Assertions.assertEquals(10.25, row.getCell(0)
|
||||
.getNumericCellValue());
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package com.baeldung.poi.powerpoint;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.xslf.usermodel.XMLSlideShow;
|
||||
import org.apache.poi.xslf.usermodel.XSLFShape;
|
||||
import org.apache.poi.xslf.usermodel.XSLFSlide;
|
||||
|
@ -13,12 +10,15 @@ import org.junit.Rule;
|
|||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class PowerPointIntegrationTest {
|
||||
|
||||
private PowerPointHelper pph;
|
||||
private String fileLocation;
|
||||
private static final String FILE_NAME = "presentation.pptx";
|
||||
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
|
@ -1,19 +1,19 @@
|
|||
package com.baeldung.poi.word;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class WordIntegrationTest {
|
||||
static WordDocument wordDocument;
|
||||
|
Binary file not shown.
|
@ -1,14 +1,17 @@
|
|||
## Apache POI
|
||||
|
||||
This module contains articles about Apache POI
|
||||
This module contains articles about Apache POI.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Microsoft Word Processing in Java with Apache POI](https://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel)
|
||||
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
||||
- [Merge Cells in Excel Using Apache POI](https://www.baeldung.com/java-apache-poi-merge-cells)
|
||||
- [Get String Value of Excel Cell with Apache POI](https://www.baeldung.com/java-apache-poi-cell-string-value)
|
||||
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://www.baeldung.com/apache-poi-read-cell-value-formula)
|
||||
- [Setting Formulas in Excel with Apache POI](https://www.baeldung.com/java-apache-poi-set-formulas)
|
||||
- [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row)
|
||||
- [Multiline Text in Excel Cell Using Apache POI](https://www.baeldung.com/apache-poi-write-multiline-text)
|
||||
- [Set Background Color of a Cell with Apache POI](https://www.baeldung.com/apache-poi-background-color)
|
||||
- [Add Borders to Excel Cells With Apache POI](https://www.baeldung.com/apache-poi-add-borders)
|
||||
- [Reading Values From Excel in Java](https://www.baeldung.com/java-read-dates-excel)
|
||||
- More articles: [[next -->]](../apache-poi-2)
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package com.baeldung.poi.excel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class ExcelUtility {
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
|
||||
public static String readExcel(String filePath) throws IOException {
|
||||
File file = new File(filePath);
|
||||
FileInputStream inputStream = null;
|
||||
StringBuilder toReturn = new StringBuilder();
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
Workbook baeuldungWorkBook = new XSSFWorkbook(inputStream);
|
||||
for (Sheet sheet : baeuldungWorkBook) {
|
||||
toReturn.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
toReturn.append("Worksheet :")
|
||||
.append(sheet.getSheetName())
|
||||
.append(ENDLINE);
|
||||
toReturn.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
int firstRow = sheet.getFirstRowNum();
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int index = firstRow + 1; index <= lastRow; index++) {
|
||||
Row row = sheet.getRow(index);
|
||||
toReturn.append("|| ");
|
||||
for (int cellIndex = row.getFirstCellNum(); cellIndex < row.getLastCellNum(); cellIndex++) {
|
||||
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
printCellValue(cell, toReturn);
|
||||
}
|
||||
toReturn.append(" ||")
|
||||
.append(ENDLINE);
|
||||
}
|
||||
}
|
||||
inputStream.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
return toReturn.toString();
|
||||
}
|
||||
|
||||
public static void printCellValue(Cell cell, StringBuilder toReturn) {
|
||||
CellType cellType = cell.getCellType()
|
||||
.equals(CellType.FORMULA) ? cell.getCachedFormulaResultType() : cell.getCellType();
|
||||
if (cellType.equals(CellType.STRING)) {
|
||||
toReturn.append(cell.getStringCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
if (cellType.equals(CellType.NUMERIC)) {
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
toReturn.append(cell.getDateCellValue())
|
||||
.append(" | ");
|
||||
} else {
|
||||
toReturn.append(cell.getNumericCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
}
|
||||
if (cellType.equals(CellType.BOOLEAN)) {
|
||||
toReturn.append(cell.getBooleanCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
package com.baeldung.poi.excel;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellType;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class ExcelUtility {
|
||||
<<<<<<< HEAD
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
|
||||
public static String readExcel(String filePath) throws IOException {
|
||||
File file = new File(filePath);
|
||||
FileInputStream inputStream = null;
|
||||
StringBuilder toReturn = new StringBuilder();
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
Workbook baeuldungWorkBook = new XSSFWorkbook(inputStream);
|
||||
for (Sheet sheet : baeuldungWorkBook) {
|
||||
toReturn.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
toReturn.append("Worksheet :")
|
||||
.append(sheet.getSheetName())
|
||||
.append(ENDLINE);
|
||||
toReturn.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
int firstRow = sheet.getFirstRowNum();
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int index = firstRow + 1; index <= lastRow; index++) {
|
||||
Row row = sheet.getRow(index);
|
||||
toReturn.append("|| ");
|
||||
for (int cellIndex = row.getFirstCellNum(); cellIndex < row.getLastCellNum(); cellIndex++) {
|
||||
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
printCellValue(cell, toReturn);
|
||||
}
|
||||
toReturn.append(" ||")
|
||||
.append(ENDLINE);
|
||||
}
|
||||
}
|
||||
inputStream.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
return toReturn.toString();
|
||||
}
|
||||
|
||||
public static void printCellValue(Cell cell, StringBuilder toReturn) {
|
||||
CellType cellType = cell.getCellType()
|
||||
.equals(CellType.FORMULA) ? cell.getCachedFormulaResultType() : cell.getCellType();
|
||||
if (cellType.equals(CellType.STRING)) {
|
||||
toReturn.append(cell.getStringCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
if (cellType.equals(CellType.NUMERIC)) {
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
toReturn.append(cell.getDateCellValue())
|
||||
.append(" | ");
|
||||
} else {
|
||||
toReturn.append(cell.getNumericCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
}
|
||||
if (cellType.equals(CellType.BOOLEAN)) {
|
||||
toReturn.append(cell.getBooleanCellValue())
|
||||
.append(" | ");
|
||||
}
|
||||
}
|
||||
=======
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
|
||||
public static String readExcel(String filePath) throws IOException {
|
||||
File file = new File(filePath);
|
||||
FileInputStream inputStream = null;
|
||||
StringBuilder toReturn = new StringBuilder();
|
||||
try {
|
||||
inputStream = new FileInputStream(file);
|
||||
Workbook baeuldungWorkBook = new XSSFWorkbook(inputStream);
|
||||
for (Sheet sheet : baeuldungWorkBook) {
|
||||
toReturn.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
toReturn.append("Worksheet :").append(sheet.getSheetName()).append(ENDLINE);
|
||||
toReturn.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
int firstRow = sheet.getFirstRowNum();
|
||||
int lastRow = sheet.getLastRowNum();
|
||||
for (int index = firstRow + 1; index <= lastRow; index++) {
|
||||
Row row = sheet.getRow(index);
|
||||
toReturn.append("|| ");
|
||||
for (int cellIndex = row.getFirstCellNum(); cellIndex < row.getLastCellNum(); cellIndex++) {
|
||||
Cell cell = row.getCell(cellIndex, Row.MissingCellPolicy.CREATE_NULL_AS_BLANK);
|
||||
printCellValue(cell, toReturn);
|
||||
}
|
||||
toReturn.append(" ||").append(ENDLINE);
|
||||
}
|
||||
}
|
||||
inputStream.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
return toReturn.toString();
|
||||
}
|
||||
|
||||
public static void printCellValue(Cell cell, StringBuilder toReturn) {
|
||||
CellType cellType = cell.getCellType().equals(CellType.FORMULA) ? cell.getCachedFormulaResultType()
|
||||
: cell.getCellType();
|
||||
if (cellType.equals(CellType.STRING)) {
|
||||
toReturn.append(cell.getStringCellValue()).append(" | ");
|
||||
}
|
||||
if (cellType.equals(CellType.NUMERIC)) {
|
||||
if (DateUtil.isCellDateFormatted(cell)) {
|
||||
toReturn.append(cell.getDateCellValue()).append(" | ");
|
||||
} else {
|
||||
toReturn.append(cell.getNumericCellValue()).append(" | ");
|
||||
}
|
||||
}
|
||||
if (cellType.equals(CellType.BOOLEAN)) {
|
||||
toReturn.append(cell.getBooleanCellValue()).append(" | ");
|
||||
}
|
||||
}
|
||||
>>>>>>> master
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.baeldung.poi.excel.cellstyle;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.RegionUtil;
|
||||
|
||||
public class CellBordersHandler {
|
||||
|
||||
public void setRegionBorder(CellRangeAddress region, Sheet sheet, BorderStyle borderStyle) {
|
||||
RegionUtil.setBorderTop(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderBottom(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderLeft(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderRight(borderStyle, region, sheet);
|
||||
}
|
||||
|
||||
public void setRegionBorderWithColor(CellRangeAddress region, Sheet sheet, BorderStyle borderStyle, short color) {
|
||||
RegionUtil.setTopBorderColor(color, region, sheet);
|
||||
RegionUtil.setBottomBorderColor(color, region, sheet);
|
||||
RegionUtil.setLeftBorderColor(color, region, sheet);
|
||||
RegionUtil.setRightBorderColor(color, region, sheet);
|
||||
RegionUtil.setBorderTop(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderBottom(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderLeft(borderStyle, region, sheet);
|
||||
RegionUtil.setBorderRight(borderStyle, region, sheet);
|
||||
}
|
||||
|
||||
public void setCrazyBorder(CellRangeAddress region, Sheet sheet) {
|
||||
RegionUtil.setTopBorderColor(IndexedColors.RED.index, region, sheet);
|
||||
RegionUtil.setBottomBorderColor(IndexedColors.GREEN.index, region, sheet);
|
||||
RegionUtil.setLeftBorderColor(IndexedColors.BLUE.index, region, sheet);
|
||||
RegionUtil.setRightBorderColor(IndexedColors.VIOLET.index, region, sheet);
|
||||
RegionUtil.setBorderTop(BorderStyle.DASH_DOT, region, sheet);
|
||||
RegionUtil.setBorderBottom(BorderStyle.DOUBLE, region, sheet);
|
||||
RegionUtil.setBorderLeft(BorderStyle.DOTTED, region, sheet);
|
||||
RegionUtil.setBorderRight(BorderStyle.SLANTED_DASH_DOT, region, sheet);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.poi.excel.cellstyle;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.FillPatternType;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
|
||||
public class CellStyleHandler {
|
||||
|
||||
public void changeCellBackgroundColor(Cell cell) {
|
||||
CellStyle cellStyle = cell.getCellStyle();
|
||||
if(cellStyle == null) {
|
||||
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
|
||||
}
|
||||
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
|
||||
cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
|
||||
public void changeCellBackgroundColorWithPattern(Cell cell) {
|
||||
CellStyle cellStyle = cell.getCellStyle();
|
||||
if(cellStyle == null) {
|
||||
cellStyle = cell.getSheet().getWorkbook().createCellStyle();
|
||||
}
|
||||
cellStyle.setFillBackgroundColor(IndexedColors.BLACK.index);
|
||||
cellStyle.setFillPattern(FillPatternType.BIG_SPOTS);
|
||||
cellStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex());
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.poi.excel.multilinetext;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
|
||||
public class MultilineText {
|
||||
public void formatMultilineText(Cell cell, int cellNumber) {
|
||||
cell.getRow()
|
||||
.setHeightInPoints(cell.getSheet()
|
||||
.getDefaultRowHeightInPoints() * 2);
|
||||
CellStyle cellStyle = cell.getSheet()
|
||||
.getWorkbook()
|
||||
.createCellStyle();
|
||||
cellStyle.setWrapText(true);
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,72 @@
|
|||
package com.baeldung.poi.excel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExcelUtilityUnitTest {
|
||||
private static final String FILE_NAME = "baeldung.xlsx";
|
||||
private String fileLocation;
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
private StringBuilder output;
|
||||
|
||||
@Before
|
||||
public void setupUnitTest() throws IOException, URISyntaxException, ParseException {
|
||||
output = new StringBuilder();
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("Worksheet :Sheet1")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name1 | Surname1 | 3.55696564113E11 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021")
|
||||
.toString())
|
||||
.append(" | ‡ | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name2 | Surname2 | 5.646513512E9 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/12/2021")
|
||||
.toString())
|
||||
.append(" | false | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name3 | Surname3 | 3.55696564113E11 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021")
|
||||
.toString())
|
||||
.append(" | 7.17039641738E11 | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("Worksheet :Sheet2")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name4 | Surname4 | 3.55675623232E11 | 13/04/2021 | ||")
|
||||
.append(ENDLINE);
|
||||
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME)
|
||||
.toURI())
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenReturnStringValue() throws IOException {
|
||||
assertEquals(output.toString(), ExcelUtility.readExcel(fileLocation));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenThrowException() {
|
||||
assertThrows(IOException.class, () -> {
|
||||
ExcelUtility.readExcel("baeldung");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
package com.baeldung.poi.excel;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExcelUtilityUnitTest {
|
||||
<<<<<<< HEAD
|
||||
private static final String FILE_NAME = "baeldung.xlsx";
|
||||
private String fileLocation;
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
private StringBuilder output;
|
||||
|
||||
@Before
|
||||
public void setupUnitTest() throws IOException, URISyntaxException, ParseException {
|
||||
output = new StringBuilder();
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("Worksheet :Sheet1")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name1 | Surname1 | 3.55696564113E11 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021")
|
||||
.toString())
|
||||
.append(" | ‡ | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name2 | Surname2 | 5.646513512E9 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/12/2021")
|
||||
.toString())
|
||||
.append(" | false | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name3 | Surname3 | 3.55696564113E11 | ")
|
||||
.append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021")
|
||||
.toString())
|
||||
.append(" | 7.17039641738E11 | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("Worksheet :Sheet2")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name4 | Surname4 | 3.55675623232E11 | 13/04/2021 | ||")
|
||||
.append(ENDLINE);
|
||||
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME)
|
||||
.toURI())
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenReturnStringValue() throws IOException {
|
||||
assertEquals(output.toString(), ExcelUtility.readExcel(fileLocation));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenThrowException() {
|
||||
assertThrows(IOException.class, () -> {
|
||||
ExcelUtility.readExcel("baeldung");
|
||||
});
|
||||
}
|
||||
=======
|
||||
private static final String FILE_NAME = "baeldung.xlsx";
|
||||
private String fileLocation;
|
||||
private static final String ENDLINE = System.getProperty("line.separator");
|
||||
private StringBuilder output;
|
||||
|
||||
@Before
|
||||
public void setupUnitTest() throws IOException, URISyntaxException, ParseException {
|
||||
output = new StringBuilder();
|
||||
output.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
output.append("Worksheet :Sheet1").append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
output.append("|| Name1 | Surname1 | 3.55696564113E11 | ").append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021").toString()).append(" | ‡ | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name2 | Surname2 | 5.646513512E9 | ").append(new SimpleDateFormat("dd/MM/yyyy").parse("4/12/2021").toString()).append(" | false | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("|| Name3 | Surname3 | 3.55696564113E11 | ").append(new SimpleDateFormat("dd/MM/yyyy").parse("4/11/2021").toString()).append(" | 7.17039641738E11 | ||")
|
||||
.append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
output.append("Worksheet :Sheet2").append(ENDLINE);
|
||||
output.append("--------------------------------------------------------------------").append(ENDLINE);
|
||||
output.append("|| Name4 | Surname4 | 3.55675623232E11 | 13/04/2021 | ||").append(ENDLINE);
|
||||
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenReturnStringValue() throws IOException {
|
||||
assertEquals(output.toString(), ExcelUtility.readExcel(fileLocation));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringPath_whenReadExcel_thenThrowException() {
|
||||
assertThrows(IOException.class, () -> {
|
||||
ExcelUtility.readExcel("baeldung");
|
||||
});
|
||||
}
|
||||
>>>>>>> master
|
||||
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package com.baeldung.poi.excel.cellstyle;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CellBorderHandlerUnitTest {
|
||||
private static final String FILE_NAME = "cellstyle/CellStyleHandlerTest.xlsx";
|
||||
private static final int SHEET_INDEX = 0;
|
||||
|
||||
private static CellBordersHandler cellBordersHandler;
|
||||
private static Workbook workbook;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws URISyntaxException, IOException {
|
||||
String fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
|
||||
cellBordersHandler = new CellBordersHandler();
|
||||
workbook = new XSSFWorkbook(fileLocation);
|
||||
createRowsAndCells(workbook);
|
||||
}
|
||||
|
||||
private static void createRowsAndCells(Workbook workbook) {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
for (int rowIndex = 0; rowIndex < 10; rowIndex++) {
|
||||
Row row = sheet.getRow(rowIndex);
|
||||
if (row == null) {
|
||||
row = sheet.createRow(rowIndex);
|
||||
}
|
||||
for (int colIndex = 0; colIndex < 10; colIndex++) {
|
||||
Cell cell = row.getCell(colIndex);
|
||||
if (cell == null) {
|
||||
row.createCell(colIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookCell_whenSetRegionBorder() {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
|
||||
CellRangeAddress region = new CellRangeAddress(1, 1, 1, 1);
|
||||
cellBordersHandler.setRegionBorder(region, sheet, BorderStyle.THICK);
|
||||
|
||||
Row row = sheet.getRow(1);
|
||||
Cell cell = row.getCell(1);
|
||||
assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.THICK);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookCell_whenSetRegionBorderWithColor() {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
|
||||
CellRangeAddress region = new CellRangeAddress(1, 1, 3, 3);
|
||||
cellBordersHandler.setRegionBorderWithColor(region, sheet, BorderStyle.THICK, IndexedColors.MAROON.index);
|
||||
|
||||
Row row = sheet.getRow(1);
|
||||
Cell cell = row.getCell(1 + 2);
|
||||
assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.THICK);
|
||||
assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.MAROON.index);
|
||||
assertEquals(cell.getCellStyle().getBottomBorderColor(), IndexedColors.MAROON.index);
|
||||
assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.MAROON.index);
|
||||
assertEquals(cell.getCellStyle().getRightBorderColor(), IndexedColors.MAROON.index);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookCell_whenSetCrazyBorder() {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
|
||||
CellRangeAddress region = new CellRangeAddress(1, 1, 5, 5);
|
||||
cellBordersHandler.setCrazyBorder(region, sheet);
|
||||
|
||||
Row row = sheet.getRow(1);
|
||||
Cell cell = row.getCell(5);
|
||||
assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.DASH_DOT);
|
||||
assertEquals(cell.getCellStyle().getBorderBottom(), BorderStyle.DOUBLE);
|
||||
assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.DOTTED);
|
||||
assertEquals(cell.getCellStyle().getBorderRight(), BorderStyle.SLANTED_DASH_DOT);
|
||||
assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.RED.index);
|
||||
assertEquals(cell.getCellStyle().getBottomBorderColor(), IndexedColors.GREEN.index);
|
||||
assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.BLUE.index);
|
||||
assertEquals(cell.getCellStyle().getRightBorderColor(), IndexedColors.VIOLET.index);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookRegion_whenSetRegionBorder() {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
|
||||
CellRangeAddress region = new CellRangeAddress(3, 5, 1, 5);
|
||||
cellBordersHandler.setRegionBorder(region, sheet, BorderStyle.MEDIUM);
|
||||
|
||||
Row row = sheet.getRow(3);
|
||||
Cell cell = row.getCell(1);
|
||||
assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.MEDIUM);
|
||||
assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.MEDIUM);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookRegion_whenSetRegionBorderWithColor() {
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
|
||||
CellRangeAddress region = new CellRangeAddress(7, 8, 1, 5);
|
||||
cellBordersHandler.setRegionBorderWithColor(region, sheet, BorderStyle.MEDIUM, IndexedColors.ORANGE.index);
|
||||
|
||||
Row row = sheet.getRow(7);
|
||||
Cell cell = row.getCell(1);
|
||||
assertEquals(cell.getCellStyle().getBorderTop(), BorderStyle.MEDIUM);
|
||||
assertEquals(cell.getCellStyle().getBorderLeft(), BorderStyle.MEDIUM);
|
||||
assertEquals(cell.getCellStyle().getTopBorderColor(), IndexedColors.ORANGE.index);
|
||||
assertEquals(cell.getCellStyle().getLeftBorderColor(), IndexedColors.ORANGE.index);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() throws IOException {
|
||||
workbook.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.baeldung.poi.excel.cellstyle;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CellStyleHandlerUnitTest {
|
||||
private static final String FILE_NAME = "cellstyle/CellStyleHandlerTest.xlsx";
|
||||
private static final int SHEET_INDEX = 0;
|
||||
private static final int ROW_INDEX = 0;
|
||||
private static final int CELL_INDEX = 0;
|
||||
|
||||
private String fileLocation;
|
||||
private CellStyleHandler cellStyleHandler;
|
||||
|
||||
@Before
|
||||
public void setup() throws URISyntaxException {
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
|
||||
cellStyleHandler = new CellStyleHandler();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookCell_whenChangeCellBackgroundColor() throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
Row row = sheet.getRow(ROW_INDEX);
|
||||
Cell cell = row.getCell(CELL_INDEX);
|
||||
|
||||
cellStyleHandler.changeCellBackgroundColor(cell);
|
||||
|
||||
assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
|
||||
workbook.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenWorkbookCell_whenChangeCellBackgroundColorWithPattern() throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||
Sheet sheet = workbook.getSheetAt(SHEET_INDEX);
|
||||
Row row = sheet.getRow(ROW_INDEX);
|
||||
Cell cell = row.getCell(CELL_INDEX + 1);
|
||||
|
||||
cellStyleHandler.changeCellBackgroundColorWithPattern(cell);
|
||||
|
||||
assertEquals(IndexedColors.LIGHT_BLUE.index, cell.getCellStyle().getFillForegroundColor());
|
||||
workbook.close();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
package com.baeldung.poi.excel.multilinetext;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MultilineTextUnitTest {
|
||||
private static String FILE_NAME = "com/baeldung/poi/excel/multilinetext/MultilineTextTest.xlsx";
|
||||
private static final String NEW_FILE_NAME = "MultilineTextTest_output.xlsx";
|
||||
private static final int STRING_ROW_INDEX = 1;
|
||||
private static final int STRING_CELL_INDEX = 0;
|
||||
|
||||
private String fileLocation;
|
||||
|
||||
@Before
|
||||
public void setup() throws IOException, URISyntaxException {
|
||||
fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME)
|
||||
.toURI())
|
||||
.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultilineTextCell_whenFormated_thenMultilineTextVisible() throws IOException {
|
||||
Workbook workbook = new XSSFWorkbook(fileLocation);
|
||||
Sheet sheet = workbook.getSheetAt(0);
|
||||
sheet.createRow(STRING_ROW_INDEX);
|
||||
Row row = sheet.getRow(STRING_ROW_INDEX);
|
||||
Cell cell = row.createCell(STRING_CELL_INDEX);
|
||||
|
||||
cell.setCellValue("Hello \n world!");
|
||||
MultilineText multilineText = new MultilineText();
|
||||
multilineText.formatMultilineText(cell, STRING_CELL_INDEX);
|
||||
|
||||
FileOutputStream outputStream = new FileOutputStream(NEW_FILE_NAME);
|
||||
workbook.write(outputStream);
|
||||
outputStream.close();
|
||||
|
||||
File file = new File(NEW_FILE_NAME);
|
||||
FileInputStream fileInputStream = new FileInputStream(file);
|
||||
Workbook testWorkbook = new XSSFWorkbook(fileInputStream);
|
||||
assertTrue(row.getHeightInPoints() == testWorkbook.getSheetAt(0)
|
||||
.getRow(STRING_ROW_INDEX)
|
||||
.getHeightInPoints());
|
||||
DataFormatter formatter = new DataFormatter();
|
||||
assertEquals("Hello \n world!", formatter.formatCellValue(testWorkbook.getSheetAt(0)
|
||||
.getRow(STRING_ROW_INDEX)
|
||||
.getCell(STRING_CELL_INDEX)));
|
||||
testWorkbook.close();
|
||||
fileInputStream.close();
|
||||
file.delete();
|
||||
|
||||
workbook.close();
|
||||
}
|
||||
}
|
Binary file not shown.
|
@ -39,10 +39,6 @@
|
|||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- spring-sec -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration scan="true" scanPeriod="15 seconds" debug="false">
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
</configuration>
|
|
@ -71,12 +71,6 @@
|
|||
<artifactId>derby</artifactId>
|
||||
<version>${derby.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- the JTA API -->
|
||||
<dependency>
|
||||
<groupId>javax.transaction</groupId>
|
||||
|
|
|
@ -10,9 +10,8 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<artifactId>aws-lambda</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -62,6 +61,14 @@
|
|||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>${json-simple.version}</version>
|
||||
<exclusions>
|
||||
<!-- junit4 dependency is excluded as it should to be resolved from junit-vintage-engine
|
||||
included in parent-modules. -->
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -5,30 +5,24 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>ShippingFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>ShippingFunction</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.11.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
<version>${jackson-databind.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
|
@ -43,7 +37,7 @@
|
|||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<version>42.2.16</version>
|
||||
<version>${postgresql.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -71,6 +65,10 @@
|
|||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<hibernate.version>5.4.21.Final</hibernate.version>
|
||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||
<aws-lambda-java-events.version>3.1.0</aws-lambda-java-events.version>
|
||||
<jackson-databind.version>2.11.2</jackson-databind.version>
|
||||
<postgresql.version>42.2.16</postgresql.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -5,77 +5,77 @@
|
|||
<groupId>helloworld</groupId>
|
||||
<artifactId>ToDoFunction</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>ToDoFunction</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>1.2.1</version>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>3.6.0</version>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.org.webcompere</groupId>
|
||||
<artifactId>lightweight-config</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>${lightweight-config.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-log4j2</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>${aws-lambda-java-log4j2.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>2.13.2</version>
|
||||
<version>${log4j-slf4j-impl.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
<version>11.2</version>
|
||||
<version>${feign-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-slf4j</artifactId>
|
||||
<version>11.2</version>
|
||||
<version>${feign-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-gson</artifactId>
|
||||
<version>11.2</version>
|
||||
<version>${feign-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>5.0.1</version>
|
||||
<version>${guice.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<groupId>org.junit.vintage</groupId>
|
||||
<artifactId>junit-vintage-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>uk.org.webcompere</groupId>
|
||||
<artifactId>system-stubs-junit4</artifactId>
|
||||
<version>1.2.0</version>
|
||||
<version>${system-stubs-junit4.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<version>${mockito-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.19.0</version>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -103,6 +103,17 @@
|
|||
<properties>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<aws-lambda-java-core.version>1.2.1</aws-lambda-java-core.version>
|
||||
<aws-lambda-java-events.version>3.6.0</aws-lambda-java-events.version>
|
||||
<lightweight-config.version>1.1.0</lightweight-config.version>
|
||||
<aws-lambda-java-log4j2.version>1.2.0</aws-lambda-java-log4j2.version>
|
||||
<log4j-slf4j-impl.version>2.13.2</log4j-slf4j-impl.version>
|
||||
<feign-core.version>11.2</feign-core.version>
|
||||
<guice.version>5.0.1</guice.version>
|
||||
<system-stubs-junit4.version>1.2.0</system-stubs-junit4.version>
|
||||
<mockito-core.version>4.1.0</mockito-core.version>
|
||||
<assertj-core.version>3.19.0</assertj-core.version>
|
||||
<junit-jupiter.version>5.8.1</junit-jupiter.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
14
aws/pom.xml
14
aws/pom.xml
|
@ -20,18 +20,6 @@
|
|||
<artifactId>aws-java-sdk</artifactId>
|
||||
<version>${aws-java-sdk.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<version>${mockito-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
|
@ -117,8 +105,6 @@
|
|||
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<aws-java-sdk.version>1.11.290</aws-java-sdk.version>
|
||||
<mockito-core.version>2.21.0</mockito-core.version>
|
||||
<assertj-core.version>3.8.0</assertj-core.version>
|
||||
<dynamodblocal.version>1.11.86</dynamodblocal.version>
|
||||
<dynamodblocal.repository.url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</dynamodblocal.repository.url>
|
||||
<commons-codec-version>1.10.L001</commons-codec-version>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<dependency>
|
||||
<groupId>org.axonframework</groupId>
|
||||
<artifactId>axon-bom</artifactId>
|
||||
<version>4.5.0</version>
|
||||
<version>${axon.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
@ -56,4 +56,8 @@
|
|||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<axon.version>4.5.0</axon.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -36,12 +36,6 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
|
@ -70,6 +64,7 @@
|
|||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${maven-failsafe-plugin.version}</version>
|
||||
<configuration>
|
||||
<skipITs>true</skipITs>
|
||||
<includes>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
|
@ -118,7 +113,6 @@
|
|||
<httpclient.version>4.5.6</httpclient.version>
|
||||
<httpmime.version>4.5.6</httpmime.version>
|
||||
<httpcore.version>4.4.10</httpcore.version>
|
||||
<assertj-core.version>3.11.1</assertj-core.version>
|
||||
<maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version>
|
||||
<process-exec-maven-plugin.version>0.7</process-exec-maven-plugin.version>
|
||||
<assembly.plugin.version>3.1.0</assembly.plugin.version>
|
||||
|
|
|
@ -25,12 +25,6 @@
|
|||
<artifactId>weld-se-core</artifactId>
|
||||
<version>${weld-se-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.aspectj</groupId>
|
||||
<artifactId>aspectjweaver</artifactId>
|
||||
|
@ -53,7 +47,6 @@
|
|||
<cdi-api.version>2.0.SP1</cdi-api.version>
|
||||
<weld-se-core.version>3.0.5.Final</weld-se-core.version>
|
||||
<aspectjweaver.version>1.9.2</aspectjweaver.version>
|
||||
<assertj-core.version>3.10.0</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -10,9 +10,8 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>cloud-foundry-uaa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -10,9 +10,8 @@
|
|||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>cloud-foundry-uaa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
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>cloud-foundry-uaa</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>cloud-foundry-uaa</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform-surefire-provider.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
@ -165,7 +165,6 @@
|
|||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||
<commons-lang3.version>3.9</commons-lang3.version>
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -94,7 +94,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform-surefire-provider.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
@ -162,7 +162,6 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<hsqldb.version>2.4.0</hsqldb.version>
|
||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||
<groovy-wslite.version>1.1.3</groovy-wslite.version>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform-surefire-provider.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
@ -119,7 +119,6 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
<groovy-all.version>2.5.6</groovy-all.version>
|
||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform-surefire-provider.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
@ -109,7 +109,6 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
<groovy-all.version>2.5.6</groovy-all.version>
|
||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-runner</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -80,7 +80,7 @@
|
|||
<dependency>
|
||||
<groupId>org.junit.platform</groupId>
|
||||
<artifactId>junit-platform-surefire-provider</artifactId>
|
||||
<version>${junit.platform.version}</version>
|
||||
<version>${junit-platform-surefire-provider.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<executions>
|
||||
|
@ -109,7 +109,6 @@
|
|||
</repositories>
|
||||
|
||||
<properties>
|
||||
<junit.platform.version>1.0.0</junit.platform.version>
|
||||
<groovy.version>2.5.6</groovy.version>
|
||||
<groovy-all.version>2.5.6</groovy-all.version>
|
||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||
|
|
|
@ -12,7 +12,6 @@
|
|||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -40,7 +39,6 @@
|
|||
<properties>
|
||||
<maven.compiler.source.version>10</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>10</maven.compiler.target.version>
|
||||
<commons-collections4.version>4.1</commons-collections4.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -9,3 +9,5 @@ This module contains articles about Java 11 core features
|
|||
- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
|
||||
- [Getting the Java Version at Runtime](https://www.baeldung.com/get-java-version-runtime)
|
||||
- [Invoking a SOAP Web Service in Java](https://www.baeldung.com/java-soap-web-service)
|
||||
- [Java HTTPS Client Certificate Authentication](https://www.baeldung.com/java-https-client-certificate-authentication)
|
||||
- [Call Methods at Runtime Using Java Reflection](https://www.baeldung.com/java-method-reflection)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -21,35 +21,11 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mock-server</groupId>
|
||||
<artifactId>mockserver-junit-jupiter</artifactId>
|
||||
<version>${mockserver.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit.jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
|
@ -60,18 +36,6 @@
|
|||
<artifactId>jakarta.xml.ws-api</artifactId>
|
||||
<version>${jakarta.ws-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-rt</artifactId>
|
||||
<version>${jaxws-rt.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-ri</artifactId>
|
||||
<version>${jaxws-ri.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -105,15 +69,9 @@
|
|||
<properties>
|
||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||
<guava.version>29.0-jre</guava.version>
|
||||
<junit.jupiter.version>5.7.0</junit.jupiter.version>
|
||||
<assertj.version>3.17.2</assertj.version>
|
||||
<mockserver.version>5.11.1</mockserver.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
<jakarta.ws-api.version>3.0.0</jakarta.ws-api.version>
|
||||
<jaxws-rt.version>3.0.0</jaxws-rt.version>
|
||||
<jaxws-ri.version>2.3.1</jaxws-ri.version>
|
||||
<jaxws-maven-plugin.version>2.3.2</jaxws-maven-plugin.version>
|
||||
<jakarta.ws-api.version>3.0.1</jakarta.ws-api.version>
|
||||
<jaxws-maven-plugin.version>3.0.2</jaxws-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,41 @@
|
|||
package com.baeldung.httpsclientauthentication;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import javax.net.SocketFactory;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
public class SSLScocketClient {
|
||||
|
||||
static void startClient(String host, int port) throws IOException {
|
||||
|
||||
SocketFactory factory = SSLSocketFactory.getDefault();
|
||||
|
||||
try (SSLSocket socket = (SSLSocket) factory.createSocket(host, port)) {
|
||||
socket.setEnabledCipherSuites(new String[] { "TLS_AES_128_GCM_SHA256" });
|
||||
socket.setEnabledProtocols(new String[] { "TLSv1.3" });
|
||||
InputStream is = new BufferedInputStream(socket.getInputStream());
|
||||
String message = "Hello World Message";
|
||||
System.out.println("sending message: " + message);
|
||||
OutputStream os = new BufferedOutputStream(socket.getOutputStream());
|
||||
os.write(message.getBytes());
|
||||
os.flush();
|
||||
byte[] data = new byte[2048];
|
||||
int len = is.read(data);
|
||||
if (len <= 0) {
|
||||
throw new IOException("no data received");
|
||||
}
|
||||
System.out.printf("client received %d bytes: %s%n", len, new String(data, 0, len));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
startClient("localhost", 8443);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.baeldung.httpsclientauthentication;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
import javax.net.ServerSocketFactory;
|
||||
import javax.net.ssl.SSLServerSocket;
|
||||
import javax.net.ssl.SSLServerSocketFactory;
|
||||
|
||||
public class SSLSocketEchoServer {
|
||||
|
||||
static void startServer(int port) throws IOException {
|
||||
|
||||
ServerSocketFactory factory = SSLServerSocketFactory.getDefault();
|
||||
|
||||
try (SSLServerSocket listener = (SSLServerSocket) factory.createServerSocket(port)) {
|
||||
listener.setNeedClientAuth(true);
|
||||
listener.setEnabledCipherSuites(new String[] { "TLS_AES_128_GCM_SHA256" });
|
||||
listener.setEnabledProtocols(new String[] { "TLSv1.3" });
|
||||
System.out.println("listening for messages...");
|
||||
try (Socket socket = listener.accept()) {
|
||||
InputStream is = new BufferedInputStream(socket.getInputStream());
|
||||
OutputStream os = new BufferedOutputStream(socket.getOutputStream());
|
||||
byte[] data = new byte[2048];
|
||||
int len = is.read(data);
|
||||
if (len <= 0) {
|
||||
throw new IOException("no data received");
|
||||
}
|
||||
String message = new String(data, 0, len);
|
||||
System.out.printf("server received %d bytes: %s%n", len, message);
|
||||
String response = message + " processed by server";
|
||||
os.write(response.getBytes(), 0, response.getBytes().length);
|
||||
os.flush();
|
||||
}
|
||||
System.out.println("message processed, exiting");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
startServer(8443);
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlSchemaType;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.jws.WebMethod;
|
||||
import javax.jws.WebParam;
|
||||
import javax.jws.WebResult;
|
||||
import javax.jws.WebService;
|
||||
import javax.jws.soap.SOAPBinding;
|
||||
import javax.xml.bind.annotation.XmlSeeAlso;
|
||||
import javax.xml.ws.Action;
|
||||
import jakarta.jws.WebMethod;
|
||||
import jakarta.jws.WebParam;
|
||||
import jakarta.jws.WebResult;
|
||||
import jakarta.jws.WebService;
|
||||
import jakarta.jws.soap.SOAPBinding;
|
||||
import jakarta.xml.bind.annotation.XmlSeeAlso;
|
||||
import jakarta.xml.ws.Action;
|
||||
|
||||
|
||||
/**
|
||||
* This class was generated by the JAX-WS RI.
|
||||
* JAX-WS RI 2.3.2
|
||||
* Generated source version: 2.2
|
||||
* JAX-WS RI 3.0.2
|
||||
* Generated source version: 3.0
|
||||
*
|
||||
*/
|
||||
@WebService(name = "CountryService", targetNamespace = "http://server.ws.soap.baeldung.com/")
|
||||
|
|
|
@ -4,17 +4,17 @@ package com.baeldung.soap.ws.client.generated;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.Service;
|
||||
import javax.xml.ws.WebEndpoint;
|
||||
import javax.xml.ws.WebServiceClient;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import javax.xml.ws.WebServiceFeature;
|
||||
import jakarta.xml.ws.Service;
|
||||
import jakarta.xml.ws.WebEndpoint;
|
||||
import jakarta.xml.ws.WebServiceClient;
|
||||
import jakarta.xml.ws.WebServiceException;
|
||||
import jakarta.xml.ws.WebServiceFeature;
|
||||
|
||||
|
||||
/**
|
||||
* This class was generated by the JAX-WS RI.
|
||||
* JAX-WS RI 2.3.2
|
||||
* Generated source version: 2.2
|
||||
* JAX-WS RI 3.0.2
|
||||
* Generated source version: 3.0
|
||||
*
|
||||
*/
|
||||
@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "http://localhost:8888/ws/country?wsdl")
|
||||
|
@ -75,7 +75,7 @@ public class CountryServiceImplService
|
|||
/**
|
||||
*
|
||||
* @param features
|
||||
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
|
||||
* A list of {@link jakarta.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
|
||||
* @return
|
||||
* returns CountryService
|
||||
*/
|
||||
|
|
|
@ -1,15 +1,14 @@
|
|||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import jakarta.xml.bind.annotation.XmlEnum;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for currency.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p>
|
||||
* <pre>
|
||||
* <simpleType name="currency">
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}string">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
import jakarta.xml.bind.annotation.XmlRegistry;
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://server.ws.soap.baeldung.com/")
|
||||
@jakarta.xml.bind.annotation.XmlSchema(namespace = "http://server.ws.soap.baeldung.com/")
|
||||
package com.baeldung.soap.ws.client.generated;
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.baeldung.reflection;
|
|||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -34,6 +35,25 @@ public class OperationsUnitTest {
|
|||
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePrivateMethod_thenCheckAccess() throws Exception {
|
||||
Operations operationsInstance = new Operations();
|
||||
Method andPrivatedMethod = Operations.class.getDeclaredMethod("privateAnd", boolean.class, boolean.class);
|
||||
boolean isAccessEnabled = andPrivatedMethod.canAccess(operationsInstance);
|
||||
|
||||
assertFalse(isAccessEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePublicMethod_thenEnableAccess() throws Exception {
|
||||
Operations operationsInstance = new Operations();
|
||||
Method andPrivatedMethod = Operations.class.getDeclaredMethod("privateAnd", boolean.class, boolean.class);
|
||||
andPrivatedMethod.trySetAccessible();
|
||||
boolean isAccessEnabled = andPrivatedMethod.canAccess(operationsInstance);
|
||||
|
||||
assertTrue(isAccessEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePublicMethod_thenCorrect() throws Exception {
|
||||
|
|
|
@ -5,7 +5,8 @@ import org.assertj.core.api.Assertions;
|
|||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class VersionUnitTest {
|
||||
// manual test as the runtime JDK version can be different depending on where the test is run
|
||||
public class VersionManualTest {
|
||||
|
||||
@Test
|
||||
public void givenJava_whenUsingRuntime_thenGetVersion() {
|
|
@ -13,7 +13,7 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../..</relativePath>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
|
@ -22,12 +22,6 @@
|
|||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
|
@ -103,8 +97,6 @@
|
|||
<properties>
|
||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||
<guava.version>27.1-jre</guava.version>
|
||||
<assertj.version>3.11.1</assertj.version>
|
||||
<uberjar.name>benchmarks</uberjar.name>
|
||||
<eclipse.collections.version>10.0.0</eclipse.collections.version>
|
||||
<shade.plugin.version>3.2.4</shade.plugin.version>
|
||||
|
|
|
@ -13,20 +13,13 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.11.0</version>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -54,7 +47,6 @@
|
|||
<properties>
|
||||
<maven.compiler.source.version>12</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>12</maven.compiler.target.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -14,18 +14,8 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -53,7 +43,6 @@
|
|||
<properties>
|
||||
<maven.compiler.source.version>13</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>13</maven.compiler.target.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -12,30 +12,8 @@
|
|||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -62,7 +40,6 @@
|
|||
|
||||
<properties>
|
||||
<maven.compiler.release>14</maven.compiler.release>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
|
|
@ -22,22 +22,9 @@
|
|||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -67,7 +54,6 @@
|
|||
|
||||
<properties>
|
||||
<maven.compiler.release>15</maven.compiler.release>
|
||||
<assertj.version>3.17.2</assertj.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.hidden.classes;
|
||||
|
||||
public class HiddenClass {
|
||||
public String convertToUpperCase(String s) {
|
||||
return s.toUpperCase();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.baeldung.hidden.classes;
|
||||
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodHandles.Lookup.ClassOption;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HiddenClassUnitTest {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(HiddenClassUnitTest.class);
|
||||
|
||||
@Test
|
||||
void whenInvokeMethodOnHiddenClass_thenSuccess() {
|
||||
// Initiate lookup class
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
// Create a byte code of a class
|
||||
|
||||
Class<?> clazz = HiddenClass.class;
|
||||
String className = clazz.getName();
|
||||
String classAsPath = className.replace('.', '/') + ".class";
|
||||
InputStream stream = clazz.getClassLoader()
|
||||
.getResourceAsStream(classAsPath);
|
||||
|
||||
try {
|
||||
// Define hidden class with byte code
|
||||
Class<?> hiddenClass = lookup.defineHiddenClass(IOUtils.toByteArray(stream), true, ClassOption.NESTMATE)
|
||||
.lookupClass();
|
||||
Object hiddenClassObject = hiddenClass.getConstructor()
|
||||
.newInstance();
|
||||
|
||||
Method method = hiddenClassObject.getClass()
|
||||
.getDeclaredMethod("convertToUpperCase", String.class);
|
||||
|
||||
Assertions.assertEquals(true, hiddenClass.isHidden());
|
||||
|
||||
Assertions.assertEquals("HELLO", method.invoke(hiddenClassObject, "Hello"));
|
||||
|
||||
Assertions.assertEquals(this.getClass()
|
||||
.getClassLoader(), hiddenClass.getClassLoader());
|
||||
|
||||
Assertions.assertEquals(null, hiddenClass.getCanonicalName());
|
||||
|
||||
Assertions.assertThrows(ClassNotFoundException.class, () -> Class.forName(hiddenClass.getName()));
|
||||
|
||||
Assertions.assertThrows(ClassNotFoundException.class, () -> lookup.findClass(hiddenClass.getName()));
|
||||
|
||||
} catch (Exception e) {
|
||||
LOG.error("Couldn't instantiate hidden class" + e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,29 +17,11 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -50,37 +32,35 @@
|
|||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
<forkCount>1</forkCount>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-api</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
<forkCount>1</forkCount>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-api</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source.version>16</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>16</maven.compiler.target.version>
|
||||
<maven.compiler.release>16</maven.compiler.release>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
|
||||
<assertj.version>3.17.2</assertj.version>
|
||||
<maven.compiler.release>16</maven.compiler.release>
|
||||
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
### Relevant articles:
|
||||
|
||||
- [Pattern Matching for Switch](https://www.baeldung.com/java-switch-pattern-matching)
|
||||
- [Introduction to HexFormat in Java 17](https://www.baeldung.com/java-hexformat)
|
||||
- [New Features in Java 17](https://www.baeldung.com/java-17-new-features)
|
||||
- [Random Number Generators in Java 17](https://www.baeldung.com/java-17-random-number-generators)
|
|
@ -0,0 +1,80 @@
|
|||
<?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-17</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-17</name>
|
||||
<packaging>jar</packaging>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>../../</relativePath>
|
||||
</parent>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<release>${maven.compiler.release}</release>
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
<source>${maven.compiler.source.version}</source>
|
||||
<target>${maven.compiler.target.version}</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
<argLine>--enable-native-access=core.java</argLine>
|
||||
<forkCount>1</forkCount>
|
||||
</configuration>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-api</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source.version>17</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>17</maven.compiler.target.version>
|
||||
<maven.compiler.release>17</maven.compiler.release>
|
||||
<surefire.plugin.version>3.0.0-M5</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.features;
|
||||
|
||||
import java.util.random.RandomGeneratorFactory;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class JEP356 {
|
||||
|
||||
public Stream<String> getAllAlgorithms() {
|
||||
return RandomGeneratorFactory.all().map(RandomGeneratorFactory::name);
|
||||
}
|
||||
|
||||
public IntStream getPseudoInts(String algorithm, int streamSize) {
|
||||
// returns an IntStream with size @streamSize of random numbers generated using the @algorithm
|
||||
// where the lower bound is 0 and the upper is 100 (exclusive)
|
||||
return RandomGeneratorFactory.of(algorithm)
|
||||
.create()
|
||||
.ints(streamSize, 0,100);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.features;
|
||||
|
||||
import com.baeldung.features.JEP409.Circle;
|
||||
import com.baeldung.features.JEP409.Shape;
|
||||
import com.baeldung.features.JEP409.Triangle;
|
||||
|
||||
public class JEP406 {
|
||||
|
||||
static record Human (String name, int age, String profession) {}
|
||||
|
||||
public String checkObject(Object obj) {
|
||||
return switch (obj) {
|
||||
case Human h -> "Name: %s, age: %s and profession: %s".formatted(h.name(), h.age(), h.profession());
|
||||
case Circle c -> "This is a circle";
|
||||
case Shape s -> "It is just a shape";
|
||||
case null -> "It is null";
|
||||
default -> "It is an object";
|
||||
};
|
||||
}
|
||||
|
||||
public String checkShape(Shape shape) {
|
||||
return switch (shape) {
|
||||
case Triangle t && (t.getNumberOfSides() != 3) -> "This is a weird triangle";
|
||||
case Circle c && (c.getNumberOfSides() != 0) -> "This is a weird circle";
|
||||
default -> "Just a normal shape";
|
||||
};
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue