Merge branch 'eugenp:master' into master
This commit is contained in:
commit
c3141107b9
@ -43,19 +43,19 @@
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.ws</groupId>
|
||||
<artifactId>jaxws-ri</artifactId>
|
||||
<version>2.3.3</version>
|
||||
<version>${jaxws-ri.version}</version>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>4.0.1</version>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>${jstl.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@ -117,7 +117,9 @@
|
||||
<properties>
|
||||
<spring.version>5.3.25</spring.version>
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||
<jaxws-ri.version>2.3.3</jaxws-ri.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -241,8 +241,6 @@
|
||||
<httpcore.version>4.4.16</httpcore.version>
|
||||
<httpclient.version>4.5.14</httpclient.version>
|
||||
<mockserver.version>5.11.2</mockserver.version>
|
||||
<!-- maven plugins -->
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -21,7 +21,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<javax.validation.validation-api.version>2.0.1.Final</javax.validation.validation-api.version>
|
||||
</properties>
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.baeldung.xsltProcessing;
|
||||
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.File;
|
||||
|
||||
public class XSLTProcessorWithParametersAndOption {
|
||||
public static void transformXMLWithParametersAndOption(
|
||||
String inputXMLPath,
|
||||
String xsltPath,
|
||||
String outputHTMLPath,
|
||||
String companyName,
|
||||
boolean enableIndentation
|
||||
) throws TransformerException {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Source xsltSource = new StreamSource(new File(xsltPath));
|
||||
Transformer transformer = transformerFactory.newTransformer(xsltSource);
|
||||
|
||||
transformer.setParameter("companyName", companyName);
|
||||
|
||||
if (enableIndentation) {
|
||||
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
|
||||
}
|
||||
|
||||
Source xmlSource = new StreamSource(new File(inputXMLPath));
|
||||
Result outputResult = new StreamResult(new File(outputHTMLPath));
|
||||
|
||||
transformer.transform(xmlSource, outputResult);
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.xsltProcessing;
|
||||
|
||||
import javax.xml.transform.*;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
import java.io.File;
|
||||
|
||||
public class XSLTProcessorWithTemplate {
|
||||
public static void transformXMLUsingTemplate(String inputXMLPath, String xsltPath, String outputHTMLPath) throws TransformerException {
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Source xsltSource = new StreamSource(new File(xsltPath));
|
||||
Templates templates = transformerFactory.newTemplates(xsltSource);
|
||||
|
||||
Transformer transformer = templates.newTransformer();
|
||||
|
||||
Source xmlSource = new StreamSource(new File(inputXMLPath));
|
||||
Result outputResult = new StreamResult(new File(outputHTMLPath));
|
||||
|
||||
transformer.transform(xmlSource, outputResult);
|
||||
}
|
||||
}
|
@ -63,7 +63,6 @@
|
||||
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
|
||||
<velocity-version>1.7</velocity-version>
|
||||
<velocity-tools-version>2.0</velocity-tools-version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -49,7 +49,6 @@
|
||||
|
||||
<properties>
|
||||
<asm.version>5.2</asm.version>
|
||||
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,6 +1,7 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aws-s3-update-object</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
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>aws-s3</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
|
@ -122,7 +122,6 @@
|
||||
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
||||
<docker-maven-plugin.version>1.1.0</docker-maven-plugin.version>
|
||||
<azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -27,6 +27,7 @@
|
||||
<hsqldb.version>2.7.1</hsqldb.version>
|
||||
<spock-core.version>2.3-groovy-3.0</spock-core.version>
|
||||
<gmavenplus-plugin.version>2.1.0</gmavenplus-plugin.version>
|
||||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -48,7 +48,6 @@
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>14</maven.compiler.release>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
|
@ -53,7 +53,6 @@
|
||||
|
||||
<properties>
|
||||
<maven.compiler.release>15</maven.compiler.release>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
|
@ -152,7 +152,6 @@
|
||||
<awaitility.version>4.0.2</awaitility.version>
|
||||
<maven.compiler.source>1.9</maven.compiler.source>
|
||||
<maven.compiler.target>1.9</maven.compiler.target>
|
||||
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,65 @@
|
||||
package com.baeldung.arraymiddle;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
|
||||
public class MiddleOfArray {
|
||||
int[] middleOfArray(int[] array) {
|
||||
if (ObjectUtils.isEmpty(array) || array.length < 3)
|
||||
return array;
|
||||
int n = array.length;
|
||||
int mid = n / 2;
|
||||
if (n % 2 == 0) {
|
||||
int mid2 = mid - 1;
|
||||
return new int[] { array[mid2], array[mid] };
|
||||
} else {
|
||||
return new int[] { array[mid] };
|
||||
}
|
||||
}
|
||||
|
||||
int[] middleOfArrayWithStartEndNaive(int[] array, int start, int end) {
|
||||
int mid = (start + end) / 2;
|
||||
int n = end - start;
|
||||
if (n % 2 == 0) {
|
||||
int mid2 = mid - 1;
|
||||
return new int[] { array[mid2], array[mid] };
|
||||
} else {
|
||||
return new int[] { array[mid] };
|
||||
}
|
||||
}
|
||||
|
||||
int[] middleOfArrayWithStartEnd(int[] array, int start, int end) {
|
||||
int mid = start + (end - start) / 2;
|
||||
int n = end - start;
|
||||
if (n % 2 == 0) {
|
||||
int mid2 = mid - 1;
|
||||
return new int[] { array[mid2], array[mid] };
|
||||
} else {
|
||||
return new int[] { array[mid] };
|
||||
}
|
||||
}
|
||||
|
||||
int[] middleOfArrayWithStartEndBitwise(int[] array, int start, int end) {
|
||||
int mid = (start + end) >>> 1;
|
||||
int n = end - start;
|
||||
if (n % 2 == 0) {
|
||||
int mid2 = mid - 1;
|
||||
return new int[] { array[mid2], array[mid] };
|
||||
} else {
|
||||
return new int[] { array[mid] };
|
||||
}
|
||||
}
|
||||
|
||||
int medianOfArray(int[] array, int start, int end) {
|
||||
Arrays.sort(array); // for safety. This can be ignored
|
||||
int mid = (start + end) >>> 1;
|
||||
int n = end - start;
|
||||
if (n % 2 == 0) {
|
||||
int mid2 = mid - 1;
|
||||
return (array[mid2] + array[mid]) / 2;
|
||||
} else {
|
||||
return array[mid];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
package com.baeldung.arraymiddle;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class MiddleOfArrayUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenArrayOfEvenLength_whenMiddleOfArray_thenReturn2Values() {
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int[] expectedMidArray = { 50, 51 };
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayOfEdgeCaseLength_whenMiddleOfArray_thenReturn2Values() {
|
||||
int[] array = new int[0];
|
||||
int[] expectedMidArray = new int[0];
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array));
|
||||
|
||||
array = new int[] { 1, 2 };
|
||||
expectedMidArray = new int[] { 1, 2 };
|
||||
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayOfOddLength_whenMiddleOfArray_thenReturnMid() {
|
||||
int[] array = new int[99];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int[] expectedMidArray = { 50 };
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArray(array));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayWithStartAndEnd_whenMiddleOfArray_thenReturnMid() {
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int[] expectedMidArray = { 58 };
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndNaive(array, 55, 60));
|
||||
|
||||
expectedMidArray = new int[] { 58, 59 };
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndNaive(array, 56, 60));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayWithStartAndEndOptimized_whenMiddleOfArray_thenReturnMid() {
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int[] expectedMidArray = { 78 };
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEnd(array, 55, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayWithStartAndEndBitwise_whenMiddleOfArray_thenReturnMid() {
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int[] expectedMidArray = { 78 };
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertArrayEquals(expectedMidArray, middleOfArray.middleOfArrayWithStartEndBitwise(array, 55, 100));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenArrayWithStartAndEnd_whenMedianOfArray_thenReturnMid() {
|
||||
int[] array = new int[100];
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = i + 1;
|
||||
}
|
||||
int expectMedian = 50;
|
||||
MiddleOfArray middleOfArray = new MiddleOfArray();
|
||||
Assert.assertEquals(expectMedian, middleOfArray.medianOfArray(array, 0, 100));
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
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-collections-list-5</artifactId>
|
||||
<name>core-java-collections-list-5</name>
|
||||
|
@ -58,4 +58,8 @@ public class DataQueue {
|
||||
return queue.poll();
|
||||
}
|
||||
}
|
||||
|
||||
public Integer getSize() {
|
||||
return queue.size();
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.baeldung.producerconsumer;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class Producer implements Runnable {
|
||||
private static final Logger log = Logger.getLogger(Producer.class.getCanonicalName());
|
||||
private final DataQueue dataQueue;
|
||||
|
||||
private static int idSequence = 0;
|
||||
final ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
public Producer(DataQueue dataQueue) {
|
||||
this.dataQueue = dataQueue;
|
||||
@ -19,22 +20,38 @@ public class Producer implements Runnable {
|
||||
|
||||
public void produce() {
|
||||
while (dataQueue.runFlag) {
|
||||
while (dataQueue.isFull() && dataQueue.runFlag) {
|
||||
try {
|
||||
dataQueue.waitOnFull();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
try {
|
||||
lock.lock();
|
||||
|
||||
while (dataQueue.isFull() && dataQueue.runFlag) {
|
||||
try {
|
||||
dataQueue.waitOnFull();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dataQueue.runFlag) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!dataQueue.runFlag) {
|
||||
break;
|
||||
}
|
||||
Message message = generateMessage();
|
||||
dataQueue.add(message);
|
||||
dataQueue.notifyAllForEmpty();
|
||||
|
||||
Message message = generateMessage();
|
||||
dataQueue.add(message);
|
||||
dataQueue.notifyAllForEmpty();
|
||||
|
||||
log.info("Size of the queue is: " + dataQueue.getSize());
|
||||
|
||||
}
|
||||
finally{
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
//Sleeping on random time to make it realistic
|
||||
ThreadUtil.sleep((long) (Math.random() * 100));
|
||||
}
|
||||
|
||||
log.info("Producer Stopped");
|
||||
}
|
||||
|
||||
@ -43,9 +60,6 @@ public class Producer implements Runnable {
|
||||
log.info(String.format("[%s] Generated Message. Id: %d, Data: %f%n",
|
||||
Thread.currentThread().getName(), message.getId(), message.getData()));
|
||||
|
||||
//Sleeping on random time to make it realistic
|
||||
ThreadUtil.sleep((long) (message.getData() * 100));
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,8 @@ public class ProducerConsumerDemonstrator {
|
||||
|
||||
public static void demoMultipleProducersAndMultipleConsumers() {
|
||||
DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY);
|
||||
int producerCount = 3;
|
||||
int consumerCount = 3;
|
||||
int producerCount = 5;
|
||||
int consumerCount = 5;
|
||||
List<Thread> threads = new ArrayList<>();
|
||||
Producer producer = new Producer(dataQueue);
|
||||
for(int i = 0; i < producerCount; i++) {
|
||||
@ -45,6 +45,7 @@ public class ProducerConsumerDemonstrator {
|
||||
producerThread.start();
|
||||
threads.add(producerThread);
|
||||
}
|
||||
|
||||
Consumer consumer = new Consumer(dataQueue);
|
||||
for(int i = 0; i < consumerCount; i++) {
|
||||
Thread consumerThread = new Thread(consumer);
|
||||
@ -52,8 +53,8 @@ public class ProducerConsumerDemonstrator {
|
||||
threads.add(consumerThread);
|
||||
}
|
||||
|
||||
// let threads run for two seconds
|
||||
sleep(2000);
|
||||
// let threads run for ten seconds
|
||||
sleep(10000);
|
||||
|
||||
// Stop threads
|
||||
producer.stop();
|
||||
|
@ -37,20 +37,19 @@
|
||||
<compilerArgs>--enable-preview</compilerArgs>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<argLine>--enable-preview</argLine>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source.version>14</maven.compiler.source.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<maven.compiler.target.version>14</maven.compiler.target.version>
|
||||
<surefire.plugin.version>3.0.0-M3</surefire.plugin.version>
|
||||
</properties>
|
||||
|
@ -12,7 +12,7 @@
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
@ -25,7 +25,7 @@
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<joda-time.version>2.12.5</joda-time.version>
|
||||
<commons-lang3.version>3.12.0</commons-lang3.version>
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.baeldung.epochconversion;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class EpochToLocalDate {
|
||||
|
||||
public static void main(String[] args) {
|
||||
long millisSinceEpoch = 2131242L;
|
||||
ZoneId zoneId = ZoneId.of("Europe/Amsterdam"); // or: ZoneId.systemDefault();
|
||||
// to get All Zone Ids available, we can use the function below
|
||||
// Set<String> allZoneIds = ZoneId.getAvailableZoneIds();
|
||||
LocalDate date =
|
||||
Instant.ofEpochMilli(millisSinceEpoch)
|
||||
.atZone(zoneId)
|
||||
.toLocalDate();
|
||||
LocalDateTime time =
|
||||
Instant.ofEpochMilli(millisSinceEpoch)
|
||||
.atZone(zoneId)
|
||||
.toLocalDateTime();
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.epochconversion;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
public class LocalDateToEpoch {
|
||||
|
||||
public static void main(String[] args) {
|
||||
ZoneId zoneId = ZoneId.of("Europe/Amsterdam"); // or: ZoneId.systemDefault()
|
||||
LocalDate date = LocalDate.now();
|
||||
long epochMilliSecondsAtDate = date.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
||||
|
||||
// epoch for time
|
||||
LocalDateTime time = LocalDateTime.parse("2019-11-15T13:15:30");
|
||||
long epochMilliSecondsAtTime = time.atZone(zoneId).toInstant().toEpochMilli();
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.baeldung.epochconversion;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class EpochToLocalDateUnitTest {
|
||||
|
||||
@Test
|
||||
void givenEpoch_thenComputeLocalDateCorrectly() {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
LocalDate expectedDate = LocalDate.of(1995, 4, 15);
|
||||
long date = expectedDate.atStartOfDay(zoneId).toInstant().toEpochMilli();
|
||||
|
||||
LocalDate actualDate =
|
||||
Instant.ofEpochMilli(date)
|
||||
.atZone(zoneId)
|
||||
.toLocalDate();
|
||||
assertEquals(expectedDate, actualDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenEpoch_thenComputeLocalDateTimeCorrectly() {
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
LocalDateTime expectedTime = LocalDateTime.parse("2019-11-15T13:15:30");
|
||||
long time = expectedTime.atZone(zoneId).toInstant().toEpochMilli();
|
||||
|
||||
LocalDateTime actualTime =
|
||||
Instant.ofEpochMilli(time)
|
||||
.atZone(zoneId)
|
||||
.toLocalDateTime();
|
||||
assertEquals(expectedTime, actualTime);
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.baeldung.epochconversion;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class LocalDateTimeToEpochUnitTest {
|
||||
|
||||
@Test
|
||||
void givenDate_thenComputeEpochCorrectly() {
|
||||
ZoneId zoneId = ZoneId.of("Europe/Tallinn");
|
||||
long expectedEpoch = LocalDate.now().toEpochDay();
|
||||
LocalDateTime givenDate = Instant.ofEpochMilli(expectedEpoch)
|
||||
.atZone(zoneId)
|
||||
.toLocalDateTime();
|
||||
|
||||
long actualEpoch = givenDate.atZone(zoneId).toInstant().toEpochMilli();
|
||||
assertEquals(expectedEpoch, actualEpoch);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTime_thenComputeEpochCorrectly() {
|
||||
ZoneId zoneId = ZoneId.of("Europe/Amsterdam");
|
||||
long expectedEpoch = Instant.now().toEpochMilli();
|
||||
LocalDateTime givenTime = Instant.ofEpochMilli(expectedEpoch)
|
||||
.atZone(zoneId)
|
||||
.toLocalDateTime();
|
||||
|
||||
long actualEpoch = givenTime.atZone(zoneId).toInstant().toEpochMilli();
|
||||
assertEquals(expectedEpoch, actualEpoch);
|
||||
}
|
||||
}
|
@ -132,7 +132,6 @@
|
||||
<!-- Mime Type Libraries -->
|
||||
<tika.version>2.8.0</tika.version>
|
||||
<jmime-magic.version>0.1.5</jmime-magic.version>
|
||||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
||||
<fscontext.version>4.4.2</fscontext.version>
|
||||
<jakarta-activation-api.version>2.1.2</jakarta-activation-api.version>
|
||||
<angus-activation.version>2.0.1</angus-activation.version>
|
||||
|
@ -275,7 +275,6 @@
|
||||
<!-- maven plugins -->
|
||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
||||
<maven-assembly-plugin.version>3.3.0</maven-assembly-plugin.version>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
|
@ -0,0 +1,13 @@
|
||||
package com.baeldung.stopexecution;
|
||||
|
||||
public class InterruptThread extends Thread {
|
||||
@Override
|
||||
public void run() {
|
||||
while (!isInterrupted()) {
|
||||
if (isInterrupted()) {
|
||||
break;
|
||||
}
|
||||
// business logic
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
package com.baeldung.stopexecution;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Locale;
|
||||
|
||||
public class StopExecutionFurtherCode {
|
||||
|
||||
boolean shouldContinue = true;
|
||||
|
||||
int performTask(int a, int b) {
|
||||
if (!shouldContinue) {
|
||||
System.exit(0);
|
||||
}
|
||||
return a + b;
|
||||
}
|
||||
|
||||
void stop() {
|
||||
this.shouldContinue = false;
|
||||
}
|
||||
|
||||
int calculateFactorial(int n) {
|
||||
if (n <= 1) {
|
||||
return 1; // base case
|
||||
}
|
||||
|
||||
return n * calculateFactorial(n - 1);
|
||||
}
|
||||
|
||||
int calculateSum(int[] x) {
|
||||
int sum = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
if (x[i] < 0) {
|
||||
break;
|
||||
}
|
||||
sum += x[i];
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
<T> T stopExecutionUsingException(T object) {
|
||||
if (object instanceof Number) {
|
||||
throw new IllegalArgumentException("Parameter can not be number.");
|
||||
}
|
||||
T upperCase = (T) String.valueOf(object)
|
||||
.toUpperCase(Locale.ENGLISH);
|
||||
return upperCase;
|
||||
}
|
||||
|
||||
int processLines(String[] lines) {
|
||||
int statusCode = 0;
|
||||
parser:
|
||||
for (String line : lines) {
|
||||
System.out.println("Processing line: " + line);
|
||||
if (line.equals("stop")) {
|
||||
System.out.println("Stopping parsing...");
|
||||
statusCode = -1;
|
||||
break parser; // Stop parsing and exit the loop
|
||||
}
|
||||
System.out.println("Line processed.");
|
||||
}
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
void download(String fileUrl, String destinationPath) throws MalformedURLException {
|
||||
if (fileUrl == null || fileUrl.isEmpty() || destinationPath == null || destinationPath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// execute downloading
|
||||
URL url = new URL(fileUrl);
|
||||
try (InputStream in = url.openStream(); FileOutputStream out = new FileOutputStream(destinationPath)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
out.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.baeldung.stopexecution;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class StopExecutionFurtherCodeUnitTest {
|
||||
|
||||
|
||||
@Test
|
||||
void givenExecution_whenStopIsNotCalled_thenTaskIsPerformed() {
|
||||
StopExecutionFurtherCode stopExecution = new StopExecutionFurtherCode();
|
||||
int performedTask = stopExecution.performTask(10, 20);
|
||||
Assert.assertEquals(30, performedTask);
|
||||
}
|
||||
|
||||
// This test case have been commented because, otherwise, the program will exit since System.exit(statusCode) is being used.
|
||||
/*@Test
|
||||
void givenExecution_whenStopIsCalled_thenTaskNotPerformed() {
|
||||
StopExecutionFurtherCode stopExecution = new StopExecutionFurtherCode();
|
||||
stopExecution.stop();
|
||||
int performedTask = stopExecution.performTask(10, 20);
|
||||
Assert.assertEquals(30, performedTask);
|
||||
}*/
|
||||
|
||||
@Test
|
||||
void givenWrongUrlAndPath_whenDownloadCalled_thenExecutionIsStopped() throws MalformedURLException {
|
||||
StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode();
|
||||
stopExecutionFurtherCode.download("", "");
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenName_whenStopExecutionUsingExceptionCalled_thenNameIsConvertedToUpper() {
|
||||
StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode();
|
||||
String name = "John";
|
||||
String result1 = stopExecutionFurtherCode.stopExecutionUsingException(name);
|
||||
Assert.assertEquals("JOHN", result1);
|
||||
try {
|
||||
Integer number1 = 10;
|
||||
Assert.assertThrows(IllegalArgumentException.class, () -> {
|
||||
int result = stopExecutionFurtherCode.stopExecutionUsingException(number1);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Assert.fail("Unexpected exception thrown: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenBaseCase_whenStopExecutionWhenBaseCaseKnownCalled_thenFactorialIsCalculated() throws MalformedURLException {
|
||||
StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode();
|
||||
int factorial = stopExecutionFurtherCode.calculateFactorial(1);
|
||||
Assert.assertEquals(1, factorial);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenArrayWithNegative_whenStopExecutionInLoopCalled_thenSumIsCalculatedIgnoringNegatives() {
|
||||
StopExecutionFurtherCode stopExecutionFurtherCode = new StopExecutionFurtherCode();
|
||||
int[] nums = { 1, 2, 3, -1, 1, 2, 3 };
|
||||
int sum = stopExecutionFurtherCode.calculateSum(nums);
|
||||
Assert.assertEquals(6, sum);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenThreadRunning_whenInterrupted_thenThreadExecutionIsStopped() throws InterruptedException {
|
||||
InterruptThread stopExecution = new InterruptThread();
|
||||
stopExecution.start();
|
||||
Thread.sleep(2000);
|
||||
stopExecution.interrupt();
|
||||
stopExecution.join();
|
||||
Assert.assertTrue(!stopExecution.isAlive());
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenLinesWithStopLabel_whenStopExecutionLabeledLoopCalled_thenLoopExecutionIsStopped() {
|
||||
StopExecutionFurtherCode furtherCode = new StopExecutionFurtherCode();
|
||||
final String[] lines = { "Line 1", "Line 2", "Line 3", "stop", "Line 4", "Line 5" };
|
||||
int statusCode = furtherCode.processLines(lines);
|
||||
Assert.assertEquals(-1, statusCode);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.baeldung.clampfunction;
|
||||
|
||||
public class Clamp {
|
||||
|
||||
public int clamp(int value, int min, int max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
public double clamp(double value, double min, double max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
public static <T extends Comparable<T>> T clamp(T value, T min, T max) {
|
||||
if (value.compareTo(min) < 0) {
|
||||
return min;
|
||||
} else if (value.compareTo(max) > 0) {
|
||||
return max;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.baeldung.clampfunction;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ClampFunctionUnitTest {
|
||||
|
||||
Clamp clampValue = new Clamp();
|
||||
|
||||
@Test
|
||||
public void givenValueOutsideRange_whenClamp_thenReturnLowerValue() {
|
||||
assertEquals(15, clampValue.clamp(10, 15, 35));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValueWithinRange_whenClamp_thenReturnValue() {
|
||||
assertEquals(20, clampValue.clamp(20, 15, 35));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenValueOutsideRange_whenClamp_thenReturnMaximumValue() {
|
||||
assertEquals(35, clampValue.clamp(50, 15, 35));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDoubleValueOutsideRange_whenClamp_thenReturnMaximumValue() {
|
||||
assertEquals(60.5, clampValue.clamp(75.6, 25.5, 60.5));
|
||||
}
|
||||
|
||||
/*
|
||||
* This method uses the clamp() method introduced in Java 21
|
||||
@Test
|
||||
public void givenValueWithinRange_whenClamp_thenReturnValue() {
|
||||
assertEquals(20, Math.clamp(20, 67,98));
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.interfaces.namingconventions;
|
||||
|
||||
public interface Identifiable {
|
||||
void identify();
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.baeldung.interfaces.namingconventions;
|
||||
|
||||
public class RegularUser implements User {
|
||||
@Override
|
||||
public void identify() {
|
||||
// some implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorize() {
|
||||
// some implementation
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.baeldung.interfaces.namingconventions;
|
||||
|
||||
public class RootUser implements User {
|
||||
@Override
|
||||
public void identify() {
|
||||
// some implementation
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authorize() {
|
||||
// some implementation
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package com.baeldung.interfaces.namingconventions;
|
||||
|
||||
public interface User extends Identifiable {
|
||||
void authorize();
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.baeldung.inttolong;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class IntToLongUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingTheAutoboxing_thenGetTheExpectedLong() {
|
||||
int intTen = 10;
|
||||
Long longTen = (long) intTen;
|
||||
assertEquals(intTen, longTen);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingTheValueOf_thenGetTheExpectedLong() {
|
||||
int intTen = 10;
|
||||
Long longTen = Long.valueOf(intTen);
|
||||
assertEquals(intTen, longTen);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingTheConstructor_thenGetTheExpectedLong() {
|
||||
int intTen = 10;
|
||||
Long longTen = new Long(intTen);
|
||||
assertEquals(intTen, longTen);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingTheParseLong_thenGetTheExpectedLong() {
|
||||
int intTen = 10;
|
||||
Long longTen = Long.parseLong(String.valueOf(intTen));
|
||||
assertEquals(intTen, longTen);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>core-java-scanner</artifactId>
|
||||
<name>core-java-scanner</name>
|
||||
|
7
core-java-modules/core-java-security-4/README.md
Normal file
7
core-java-modules/core-java-security-4/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## Core Java Security
|
||||
|
||||
This module contains articles about core Java Security
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-security-3)
|
16
core-java-modules/core-java-security-4/pom.xml
Normal file
16
core-java-modules/core-java-security-4/pom.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?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-security-4</artifactId>
|
||||
<name>core-java-security-4</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung.core-java-modules</groupId>
|
||||
<artifactId>core-java-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
</project>
|
@ -0,0 +1,51 @@
|
||||
package com.baeldung.certificate;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.KeyStoreException;
|
||||
import java.security.cert.Certificate;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Enumeration;
|
||||
|
||||
public class RootCertificateUtil {
|
||||
|
||||
private RootCertificateUtil() {
|
||||
}
|
||||
|
||||
public static X509Certificate getRootCertificate(X509Certificate endEntityCertificate, KeyStore trustStore)
|
||||
throws Exception {
|
||||
X509Certificate issuerCertificate = findIssuerCertificate(endEntityCertificate, trustStore);
|
||||
if (issuerCertificate != null) {
|
||||
if (isRoot(issuerCertificate)) {
|
||||
return issuerCertificate;
|
||||
} else {
|
||||
return getRootCertificate(issuerCertificate, trustStore);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static X509Certificate findIssuerCertificate(X509Certificate certificate, KeyStore trustStore)
|
||||
throws KeyStoreException {
|
||||
Enumeration<String> aliases = trustStore.aliases();
|
||||
while (aliases.hasMoreElements()) {
|
||||
String alias = aliases.nextElement();
|
||||
Certificate cert = trustStore.getCertificate(alias);
|
||||
if (cert instanceof X509Certificate) {
|
||||
X509Certificate x509Cert = (X509Certificate) cert;
|
||||
if (x509Cert.getSubjectX500Principal().equals(certificate.getIssuerX500Principal())) {
|
||||
return x509Cert;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isRoot(X509Certificate certificate) {
|
||||
try {
|
||||
certificate.verify(certificate.getPublicKey());
|
||||
return certificate.getKeyUsage() != null && certificate.getKeyUsage()[5];
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,76 @@
|
||||
package com.baeldung.certificate;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.security.KeyStore;
|
||||
import java.security.SignatureException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import static com.baeldung.certificate.RootCertificateUtil.getRootCertificate;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class SignedCertificateUnitTest {
|
||||
|
||||
private KeyStore keyStore;
|
||||
|
||||
private KeyStore trustStore;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
char[] passwd = "changeit".toCharArray();
|
||||
keyStore = KeyStore.getInstance("JKS");
|
||||
keyStore.load(this.getClass().getClassLoader().getResourceAsStream("keystore.jks"), passwd);
|
||||
trustStore = KeyStore.getInstance("JKS");
|
||||
trustStore.load(this.getClass().getClassLoader().getResourceAsStream("truststore.jks"), passwd);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsSelfSigned_thenSubjectIsEqualToIssuer() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned");
|
||||
assertEquals(certificate.getSubjectDN(), certificate.getIssuerDN());
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsSelfSigned_thenItCanBeVerifiedWithItsOwnPublicKey() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned");
|
||||
assertDoesNotThrow(() -> certificate.verify(certificate.getPublicKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsCASigned_thenItCantBeVerifiedWithItsOwnPublicKey() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("baeldung");
|
||||
assertThrows(SignatureException.class, () -> certificate.verify(certificate.getPublicKey()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsCASigned_thenRootCanBeFoundInTruststore() throws Exception {
|
||||
X509Certificate endEntityCertificate = (X509Certificate) keyStore.getCertificate("baeldung");
|
||||
X509Certificate rootCertificate = getRootCertificate(endEntityCertificate, trustStore);
|
||||
assertNotNull(rootCertificate);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsCA_thenItCanBeUsedToSignOtherCertificates() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("cloudflare");
|
||||
assertTrue(certificate.getKeyUsage()[5]);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsCA_thenBasicConstrainsReturnsZeroOrGreaterThanZero() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("cloudflare");
|
||||
assertNotEquals(-1, certificate.getBasicConstraints());
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCertificateIsSelfSigned_thenItCantBeUsedToSignOtherCertificates() throws Exception {
|
||||
X509Certificate certificate = (X509Certificate) keyStore.getCertificate("selfsigned");
|
||||
assertNull(certificate.getKeyUsage());
|
||||
}
|
||||
}
|
@ -115,7 +115,6 @@
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<assertj.version>3.23.1</assertj.version>
|
||||
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
|
||||
<maven.compiler.source>12</maven.compiler.source>
|
||||
<maven.compiler.target>12</maven.compiler.target>
|
||||
<rx.java.version>1.2.5</rx.java.version>
|
||||
|
@ -38,6 +38,11 @@
|
||||
<version>3.12.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.vavr</groupId>
|
||||
<artifactId>vavr</artifactId>
|
||||
<version>${vavr.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -64,9 +69,9 @@
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
|
||||
<maven.compiler.source>12</maven.compiler.source>
|
||||
<maven.compiler.target>12</maven.compiler.target>
|
||||
<vavr.version>0.10.2</vavr.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,38 @@
|
||||
package com.baeldung.aggregateexception;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
public class CustomCollector<T, R> {
|
||||
private final List<R> results = new ArrayList<>();
|
||||
private final List<Throwable> exceptions = new ArrayList<>();
|
||||
|
||||
public static <T, R> Collector<T, ?, CustomCollector<T, R>> of(Function<T, R> mapper) {
|
||||
return Collector.of(
|
||||
CustomCollector::new,
|
||||
(collector, item) -> {
|
||||
try {
|
||||
R result = mapper.apply(item);
|
||||
collector.results.add(result);
|
||||
} catch (Exception e) {
|
||||
collector.exceptions.add(e);
|
||||
}
|
||||
},
|
||||
(left, right) -> {
|
||||
left.results.addAll(right.results);
|
||||
left.exceptions.addAll(right.exceptions);
|
||||
return left;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public List<R> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<Throwable> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.baeldung.aggregateexception;
|
||||
|
||||
import com.baeldung.aggregateexception.entity.Result;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
public class CustomMapper {
|
||||
public static <T, R> Function<T, Result<R, Throwable>> mapper(Function<T, R> func) {
|
||||
return arg -> {
|
||||
try {
|
||||
return new Result(func.apply(arg));
|
||||
} catch (Exception e) {
|
||||
return new Result(e);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.baeldung.aggregateexception.entity;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class Result<R, E extends Throwable> {
|
||||
private Optional<R> result;
|
||||
private Optional<E> exception;
|
||||
|
||||
public Result(R result) {
|
||||
this.result = Optional.of(result);
|
||||
this.exception = Optional.empty();
|
||||
}
|
||||
|
||||
public Result(E exception) {
|
||||
this.exception = Optional.of(exception);
|
||||
this.result = Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<R> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public Optional<E> getException() {
|
||||
return exception;
|
||||
}
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package com.baeldung.aggregateexception;
|
||||
|
||||
import com.baeldung.aggregateexception.entity.Result;
|
||||
import io.vavr.control.Either;
|
||||
import io.vavr.control.Try;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class AggregateExceptionHandlerUnitTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(AggregateExceptionHandlerUnitTest.class);
|
||||
|
||||
@Test
|
||||
public void givenExtractedMethod_whenFoundEx_thenSuppressExIntoRuntimeEx() {
|
||||
String[] strings = {"1", "2", "3", "a", "b", "c"};
|
||||
RuntimeException runEx = Arrays.stream(strings)
|
||||
.map(str -> callProcessThrowsExAndNoOutput(str))
|
||||
.filter(Objects::nonNull)
|
||||
.reduce(new RuntimeException("Errors Occurred"), (o1, o2) -> {
|
||||
o1.addSuppressed(o2);
|
||||
return o1;
|
||||
});
|
||||
processExceptions(runEx);
|
||||
assertEquals("Errors Occurred", runEx.getMessage());
|
||||
assertEquals(3, runEx.getSuppressed().length);
|
||||
}
|
||||
@Test
|
||||
public void givenTryCatchInPipeline_whenFoundEx_thenSuppressExIntoRuntimeEx() {
|
||||
String[] strings = {"1", "2", "3", "a", "b", "c"};
|
||||
RuntimeException runEx = Arrays.stream(strings).map(str -> {
|
||||
try {
|
||||
processThrowsExAndNoOutput(str);
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
return e;
|
||||
}
|
||||
}).filter(Objects::nonNull)
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(), list -> {
|
||||
RuntimeException runtimeException = new RuntimeException("Errors Occurred");
|
||||
list.forEach(runtimeException::addSuppressed);
|
||||
return runtimeException;
|
||||
}));
|
||||
processExceptions(runEx);
|
||||
assertEquals("Errors Occurred", runEx.getMessage());
|
||||
assertEquals(3, runEx.getSuppressed().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessMethod_whenStreamResultHasExAndOutput_thenHandleExceptionListAndOutputList() {
|
||||
List<String> strings = List.of("1", "2", "3", "a", "b", "c");
|
||||
Map map = strings.stream()
|
||||
.map(s -> processReturnsExAndOutput(s))
|
||||
.collect(Collectors.partitioningBy(o -> o instanceof RuntimeException, Collectors.toList()));
|
||||
|
||||
List<RuntimeException> exceptions = (List<RuntimeException>)map.getOrDefault(Boolean.TRUE, List.of());
|
||||
List<Integer> results = (List<Integer>)map.getOrDefault(Boolean.FALSE, List.of());
|
||||
handleExceptionsAndOutputs(exceptions, results);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCustomMapper_whenStreamResultHasExAndSuccess_thenHandleExceptionListAndOutputList() {
|
||||
List<String> strings = List.of("1", "2", "3", "a", "b", "c");
|
||||
strings.stream()
|
||||
.map(CustomMapper.mapper(Integer::parseInt))
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(), list -> handleErrorsAndOutputForResult(list)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenCustomCollector_whenStreamResultHasExAndSuccess_thenHandleAggrExceptionAndResults() {
|
||||
String[] strings = {"1", "2", "3", "a", "b", "c"};
|
||||
Arrays.stream(strings)
|
||||
.collect(Collectors.collectingAndThen(CustomCollector.of(Integer::parseInt),
|
||||
col -> handleExAndResults(col.getExceptions(), col.getResults())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenVavrEitherAndTry_whenStreamResultHasExAndSuccess_thenHandleExceptionListAndOutputList() {
|
||||
List<String> strings = List.of("1", "2", "3", "a", "b", "c");
|
||||
strings.stream()
|
||||
.map(str -> Try.of(() -> Integer.parseInt(str)).toEither())
|
||||
.collect(Collectors.collectingAndThen(Collectors.partitioningBy(Either::isLeft, Collectors.toList()),
|
||||
map -> handleErrorsAndOutputForEither(map)));
|
||||
}
|
||||
|
||||
private static void processThrowsExAndNoOutput(String input) {
|
||||
//throw exception when input is "a", "b", "c"
|
||||
if (input.matches("[a-c]")) {
|
||||
throw new RuntimeException("Downstream method throws exception for " + input);
|
||||
}
|
||||
}
|
||||
private static RuntimeException callProcessThrowsExAndNoOutput(String input) {
|
||||
try {
|
||||
processThrowsExAndNoOutput(input);
|
||||
return null;
|
||||
} catch (RuntimeException e) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
|
||||
private static Object processReturnsExAndOutput(String input) {
|
||||
logger.info("call a downstream method that returns an Integer");
|
||||
try {
|
||||
return Integer.parseInt(input);
|
||||
} catch (Exception e) {
|
||||
return new RuntimeException("Exception in processWithReturnOutput for " + input, e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void processExceptions(Throwable throwable) {
|
||||
logger.error("Process Exception" + throwable.getMessage());
|
||||
}
|
||||
|
||||
private static void handleExceptionsAndOutputs(List<RuntimeException> exs, List<Integer> output) {
|
||||
logger.info("number of exceptions " + exs.size() + " number of outputs " + output.size());
|
||||
}
|
||||
|
||||
private static String handleExAndResults(List<Throwable> ex, List<Integer> results ) {
|
||||
logger.info("handle aggregated exceptions and results" + ex.size() + " " + results.size());
|
||||
return "Exceptions and Results Handled";
|
||||
}
|
||||
|
||||
private static String handleErrorsAndOutputForEither(Map<Boolean, List<Either<Throwable, Integer>>> map) {
|
||||
logger.info("handle errors and output");
|
||||
map.getOrDefault(Boolean.TRUE, List.of()).forEach(either -> logger.error("Process Exception " + either.getLeft()));
|
||||
|
||||
map.getOrDefault(Boolean.FALSE, List.of()).forEach(either -> logger.info("Process Result " + either.get()));
|
||||
return "Errors and Output Handled";
|
||||
}
|
||||
|
||||
private static String handleErrorsAndOutputForResult(List<Result<Integer, Throwable>> successAndErrors) {
|
||||
logger.info("handle errors and output");
|
||||
successAndErrors.forEach(result -> {
|
||||
if (result.getException().isPresent()) {
|
||||
logger.error("Process Exception " + result.getException().get());
|
||||
} else {
|
||||
logger.info("Process Result" + result.getResult().get());
|
||||
}
|
||||
});
|
||||
return "Errors and Output Handled";
|
||||
}
|
||||
}
|
@ -58,7 +58,6 @@
|
||||
|
||||
<properties>
|
||||
<!-- testing -->
|
||||
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.replace;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ReplaceStringUnitTest {
|
||||
private final String ORIGINAL_STRING = "This is 'Baeldung' tutorial.";
|
||||
private final String EXPECTED_STRING = "This is \\'Baeldung\\' tutorial.";
|
||||
|
||||
@Test
|
||||
public void givenString_thenReplaceUsinReplaceAllMethod() {
|
||||
String modifiedString = ORIGINAL_STRING.replaceAll("'", "\\\\'");
|
||||
assertEquals(EXPECTED_STRING, modifiedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenReplaceUsinReplaceMethod() {
|
||||
String modifiedString = ORIGINAL_STRING.replace("'", "\\'");
|
||||
assertEquals(EXPECTED_STRING, modifiedString);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
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-string-operations-6</artifactId>
|
||||
<name>core-java-string-operations-6</name>
|
||||
|
@ -15,30 +15,20 @@
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.4.0-b180725.0427</version>
|
||||
<groupId>jakarta.xml.bind</groupId>
|
||||
<artifactId>jakarta.xml.bind-api</artifactId>
|
||||
<version>${jakarta.xml.bind-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
@ -57,7 +47,8 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<commons-codec.version>1.15</commons-codec.version>
|
||||
<commons-codec.version>1.16.0</commons-codec.version>
|
||||
<jakarta.xml.bind-api.version>4.0.0</jakarta.xml.bind-api.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -2,7 +2,7 @@ package com.baeldung.base64encodinganddecoding;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import jakarta.xml.bind.DatatypeConverter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
@ -127,6 +127,7 @@
|
||||
<module>core-java-scanner</module>
|
||||
<module>core-java-security-2</module>
|
||||
<module>core-java-security-3</module>
|
||||
<module>core-java-security-4</module>
|
||||
<module>core-java-security-algorithms</module>
|
||||
<module>core-java-streams</module>
|
||||
<module>core-java-streams-3</module>
|
||||
|
@ -1,37 +1,37 @@
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>inject-intro</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>avaje-inject-intro</name>
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<avaje.inject.version>9.5</avaje.inject.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
</dependency>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>inject-intro</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>avaje-inject-intro</name>
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<avaje.inject.version>9.5</avaje.inject.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject-test</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject-test</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- Annotation processors -->
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject-generator</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<!-- Annotation processors -->
|
||||
<dependency>
|
||||
<groupId>io.avaje</groupId>
|
||||
<artifactId>avaje-inject-generator</artifactId>
|
||||
<version>${avaje.inject.version}</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -119,7 +119,6 @@
|
||||
<disruptor.version>3.3.6</disruptor.version>
|
||||
<!-- testing -->
|
||||
<maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||
</properties>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
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>jackson-polymorphic-deserialization</artifactId>
|
||||
<name>jackson-polymorphic-deserialization</name>
|
||||
|
@ -30,7 +30,6 @@
|
||||
<properties>
|
||||
<javax.websocket-api.version>1.1</javax.websocket-api.version>
|
||||
<gson.version>2.8.0</gson.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -100,7 +100,6 @@
|
||||
|
||||
<properties>
|
||||
<jersey.version>3.1.1</jersey.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,5 +1,7 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@ -45,8 +47,8 @@
|
||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||
<node.version>v6.10.0</node.version>
|
||||
<!-- These remain empty unless the corresponding profile is active -->
|
||||
<profile.no-liquibase />
|
||||
<profile.swagger />
|
||||
<profile.no-liquibase/>
|
||||
<profile.swagger/>
|
||||
<!-- Sonar properties -->
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||
@ -440,7 +442,7 @@
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
<ignore/>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
@ -634,9 +636,9 @@
|
||||
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
|
||||
<driver>org.h2.Driver</driver>
|
||||
<url>jdbc:h2:file:./target/h2db/db/carapp</url>
|
||||
<defaultSchemaName />
|
||||
<defaultSchemaName/>
|
||||
<username>carapp</username>
|
||||
<password />
|
||||
<password/>
|
||||
<referenceUrl>hibernate:spring:com.car.app.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
|
||||
<verbose>true</verbose>
|
||||
<logging>debug</logging>
|
||||
@ -683,7 +685,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration />
|
||||
<configuration/>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@ -722,7 +724,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration />
|
||||
<configuration/>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@ -44,8 +46,8 @@
|
||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||
<node.version>v6.10.0</node.version>
|
||||
<!-- These remain empty unless the corresponding profile is active -->
|
||||
<profile.no-liquibase />
|
||||
<profile.swagger />
|
||||
<profile.no-liquibase/>
|
||||
<profile.swagger/>
|
||||
<!-- Sonar properties -->
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||
@ -439,7 +441,7 @@
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
<ignore/>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
@ -633,9 +635,9 @@
|
||||
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
|
||||
<driver>org.h2.Driver</driver>
|
||||
<url>jdbc:h2:file:./target/h2db/db/dealerapp</url>
|
||||
<defaultSchemaName />
|
||||
<defaultSchemaName/>
|
||||
<username>dealerapp</username>
|
||||
<password />
|
||||
<password/>
|
||||
<referenceUrl>hibernate:spring:com.dealer.app.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
|
||||
<verbose>true</verbose>
|
||||
<logging>debug</logging>
|
||||
@ -682,7 +684,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration />
|
||||
<configuration/>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
@ -721,7 +723,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration />
|
||||
<configuration/>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
@ -48,8 +50,8 @@
|
||||
<metrics-spring.version>3.1.3</metrics-spring.version>
|
||||
<node.version>v6.10.0</node.version>
|
||||
<!-- These remain empty unless the corresponding profile is active -->
|
||||
<profile.no-liquibase />
|
||||
<profile.swagger />
|
||||
<profile.no-liquibase/>
|
||||
<profile.swagger/>
|
||||
<!-- Sonar properties -->
|
||||
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
|
||||
<prometheus-simpleclient.version>0.0.20</prometheus-simpleclient.version>
|
||||
@ -481,7 +483,7 @@
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
<ignore/>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
@ -497,7 +499,7 @@
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore />
|
||||
<ignore/>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
@ -691,9 +693,9 @@
|
||||
<diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
|
||||
<driver>org.h2.Driver</driver>
|
||||
<url>jdbc:h2:file:./target/h2db/db/gateway</url>
|
||||
<defaultSchemaName />
|
||||
<defaultSchemaName/>
|
||||
<username>gateway</username>
|
||||
<password />
|
||||
<password/>
|
||||
<referenceUrl>hibernate:spring:com.gateway.domain?dialect=org.hibernate.dialect.H2Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
|
||||
<verbose>true</verbose>
|
||||
<logging>debug</logging>
|
||||
|
@ -83,10 +83,8 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
||||
<jol-core.version>0.17</jol-core.version>
|
||||
<maven-assembly-plugin.version>3.5.0</maven-assembly-plugin.version>
|
||||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -76,8 +76,6 @@
|
||||
<!-- JSF -->
|
||||
<com.sun.faces.version>2.2.14</com.sun.faces.version>
|
||||
<javax.el.version>3.0.0</javax.el.version>
|
||||
<!-- Maven War plugin -->
|
||||
<maven-war-plugin.version>3.3.1</maven-war-plugin.version>
|
||||
<!-- Other -->
|
||||
<javax.annotation-api.version>1.3.1</javax.annotation-api.version>
|
||||
</properties>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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">
|
||||
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>org.baeldung</groupId>
|
||||
<artifactId>json-conversion</artifactId>
|
||||
@ -29,11 +29,17 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<json.version>20211205</json.version>
|
||||
<gson.version>2.10.1</gson.version>
|
||||
<guava.version>32.1.2-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -0,0 +1,36 @@
|
||||
package com.baeldung.jsontomap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class FlattenUtils {
|
||||
public static Map<String, Object> flatten(Map<String, Object> map) {
|
||||
return flatten(map, null);
|
||||
}
|
||||
|
||||
private static Map<String, Object> flatten(Map<String, Object> map, String prefix) {
|
||||
Map<String, Object> flatMap = new HashMap<>();
|
||||
map.forEach((key, value) -> {
|
||||
String newKey = prefix != null ? prefix + "." + key : key;
|
||||
if (value instanceof Map) {
|
||||
flatMap.putAll(flatten((Map<String, Object>) value, newKey));
|
||||
} else if (value instanceof List) {
|
||||
// check for list of primitives
|
||||
Object element = ((List<?>) value).get(0);
|
||||
if (element instanceof String || element instanceof Number || element instanceof Boolean) {
|
||||
flatMap.put(newKey, value);
|
||||
} else {
|
||||
// check for list of objects
|
||||
List<Map<String, Object>> list = (List<Map<String, Object>>) value;
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
flatMap.putAll(flatten(list.get(i), newKey + "[" + i + "]"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
flatMap.put(newKey, value);
|
||||
}
|
||||
});
|
||||
return flatMap;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.baeldung.jsontomap;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
public class JsonUtils {
|
||||
public static Map<String, Object> jsonFileToMap(String path) throws IOException {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
return mapper.readValue(new File(path), new TypeReference<Map<String, Object>>() {});
|
||||
}
|
||||
|
||||
public static Map<String, Object> jsonFileToMapGson(String path) throws IOException {
|
||||
Gson gson = new Gson();
|
||||
return gson.fromJson(new FileReader(path), new TypeToken<Map<String, Object>>() {}.getType());
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
package com.baeldung.jsontomap;
|
||||
|
||||
import com.google.common.collect.MapDifference;
|
||||
import com.google.common.collect.Maps;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class JSONComparisonUnitTest {
|
||||
|
||||
@Test
|
||||
void givenTwoJsonFiles_whenCompared_thenTheyAreDifferent() throws IOException {
|
||||
Map<String, Object> firstMap = JsonUtils.jsonFileToMap("src/test/resources/first.json");
|
||||
Map<String, Object> secondMap = JsonUtils.jsonFileToMap("src/test/resources/second.json");
|
||||
|
||||
MapDifference<String, Object> difference = Maps.difference(firstMap, secondMap);
|
||||
difference.entriesDiffering().forEach((key, value) -> {
|
||||
System.out.println(key + ": " + value.leftValue() + " - " + value.rightValue());
|
||||
});
|
||||
assertThat(difference.areEqual()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTwoJsonFiles_whenFlattenedAndCompared_thenTheyAreDifferent() throws IOException {
|
||||
Map<String, Object> firstFlatMap = FlattenUtils.flatten(JsonUtils.jsonFileToMap("src/test/resources/first.json"));
|
||||
Map<String, Object> secondFlatMap = FlattenUtils.flatten(JsonUtils.jsonFileToMap("src/test/resources/second.json"));
|
||||
|
||||
MapDifference<String, Object> difference = Maps.difference(firstFlatMap, secondFlatMap);
|
||||
difference.entriesDiffering().forEach((key, value) -> {
|
||||
System.out.println(key + ": " + value.leftValue() + " - " + value.rightValue());
|
||||
});
|
||||
assertThat(difference.areEqual()).isFalse();
|
||||
}
|
||||
}
|
22
json-modules/json-conversion/src/test/resources/first.json
Normal file
22
json-modules/json-conversion/src/test/resources/first.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "John",
|
||||
"age": 30,
|
||||
"cars": [
|
||||
"Ford",
|
||||
"BMW"
|
||||
],
|
||||
"address": {
|
||||
"street": "Second Street",
|
||||
"city": "New York"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "Sara",
|
||||
"age": 5
|
||||
},
|
||||
{
|
||||
"name": "Alex",
|
||||
"age": 3
|
||||
}
|
||||
]
|
||||
}
|
22
json-modules/json-conversion/src/test/resources/second.json
Normal file
22
json-modules/json-conversion/src/test/resources/second.json
Normal file
@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "John",
|
||||
"age": 30,
|
||||
"cars": [
|
||||
"Ford",
|
||||
"Audi"
|
||||
],
|
||||
"address": {
|
||||
"street": "Main Street",
|
||||
"city": "New York"
|
||||
},
|
||||
"children": [
|
||||
{
|
||||
"name": "Peter",
|
||||
"age": 5
|
||||
},
|
||||
{
|
||||
"name": "Cathy",
|
||||
"age": 10
|
||||
}
|
||||
]
|
||||
}
|
@ -61,8 +61,4 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
@ -92,7 +92,7 @@
|
||||
<artifactId>suanshu</artifactId>
|
||||
<version>${suanshu.version}</version>
|
||||
</dependency>
|
||||
-->
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.derive4j</groupId>
|
||||
<artifactId>derive4j</artifactId>
|
||||
@ -162,7 +162,7 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
<!-- JAVA-24004
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -73,7 +73,6 @@
|
||||
<properties>
|
||||
<jetty.version>9.4.27.v20200227</jetty.version>
|
||||
<alpn.version>8.1.11.v20170118</alpn.version>
|
||||
<maven-war-plugin.version>3.2.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -291,7 +291,6 @@
|
||||
<quartz.version>2.3.0</quartz.version>
|
||||
<javaassist.version>3.29.2-GA</javaassist.version>
|
||||
<jool.version>0.9.12</jool.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<commons-net.version>3.6</commons-net.version>
|
||||
<commonsio.version>2.6</commonsio.version>
|
||||
</properties>
|
||||
|
@ -71,11 +71,11 @@
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>provided</scope>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
|
@ -7,8 +7,8 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>maven-build-optimization</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>maven-modules</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
@ -53,10 +53,10 @@
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
|
||||
<properties>
|
||||
<failsafe.version>3.1.2</failsafe.version>
|
||||
<profiler.version>1.7</profiler.version>
|
||||
</properties>
|
||||
<profiler.version>1.7</profiler.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>business</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
@ -24,5 +24,4 @@
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
</project>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>resume-from</artifactId>
|
||||
|
@ -22,7 +22,7 @@
|
||||
<module>spring-amqp</module>
|
||||
<module>spring-apache-camel</module>
|
||||
<module>spring-jms</module>
|
||||
<module>postgres-notify</module>
|
||||
<module>postgres-notify</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
@ -42,37 +42,36 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>instance1</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<jvmArguments>-Dserver.port=8081</jvmArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>instance1</id>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<jvmArguments>-Dserver.port=8081</jvmArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
</profiles>
|
||||
</project>
|
@ -22,8 +22,4 @@
|
||||
<module>rest-express</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -144,7 +144,6 @@
|
||||
<Syntaxe.version>1.0</Syntaxe.version>
|
||||
<repoexpress-mongodb.version>0.4.8</repoexpress-mongodb.version>
|
||||
<junit4.version>4.11</junit4.version>
|
||||
<exec-maven-plugin.version>1.2.1</exec-maven-plugin.version>
|
||||
<maven-shade-plugin.version>2.4.1</maven-shade-plugin.version>
|
||||
<versions-maven-plugin.version>2.0</versions-maven-plugin.version>
|
||||
</properties>
|
||||
|
@ -217,6 +217,8 @@
|
||||
<munit.version>1.3.6</munit.version>
|
||||
<build-helper-maven-plugin.version>1.10</build-helper-maven-plugin.version>
|
||||
<mule-maven-plugin.version>2.2.1</mule-maven-plugin.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -166,7 +166,6 @@
|
||||
<javassist.version>3.27.0-GA</javassist.version>
|
||||
<jaxb.version>2.3.1</jaxb.version>
|
||||
<log4jdbc.version>2.0.0</log4jdbc.version>
|
||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||
<maven.compiler.version>3.8.1</maven.compiler.version>
|
||||
<maven.version>3.8.1</maven.version>
|
||||
<mysql.version>8.0.19</mysql.version>
|
||||
|
@ -156,7 +156,6 @@
|
||||
<properties>
|
||||
<eclipselink.version>4.0.1</eclipselink.version>
|
||||
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
||||
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
||||
<querydsl.version>5.0.0</querydsl.version>
|
||||
|
@ -88,7 +88,6 @@
|
||||
<eclipselink.version>2.7.4</eclipselink.version>
|
||||
<mysql.version>8.0.21</mysql.version>
|
||||
<javax.persistence-api.version>2.2</javax.persistence-api.version>
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-processor-plugin.version>3.3.3</maven-processor-plugin.version>
|
||||
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
|
||||
<h2.version>2.1.214</h2.version>
|
||||
|
@ -85,7 +85,7 @@
|
||||
<module>spring-data-jpa-query-3</module>
|
||||
<module>spring-data-jpa-repo</module>
|
||||
<module>spring-data-jpa-repo-2</module>
|
||||
<module>spring-data-jpa-repo-4</module>
|
||||
<module>spring-data-jpa-repo-4</module>
|
||||
<module>spring-data-jdbc</module>
|
||||
<module>spring-data-keyvalue</module>
|
||||
<module>spring-data-mongodb</module>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.boot.persistence</groupId>
|
||||
<artifactId>spring-boot-persistence-4</artifactId>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-shardingsphere</artifactId>
|
||||
<version>1.0</version>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>spring-data-yugabytedb</artifactId>
|
||||
<version>1.0</version>
|
||||
|
26
pom.xml
26
pom.xml
@ -474,7 +474,6 @@
|
||||
<module>apache-spark</module>
|
||||
|
||||
<module>jenkins-modules</module>
|
||||
<module>jhipster-6</module>
|
||||
<module>jhipster-modules</module>
|
||||
</modules>
|
||||
</profile>
|
||||
@ -633,7 +632,6 @@
|
||||
<module>apache-spark</module>
|
||||
|
||||
<module>jenkins-modules</module>
|
||||
<module>jhipster-6</module>
|
||||
<module>jhipster-modules</module>
|
||||
</modules>
|
||||
|
||||
@ -788,6 +786,7 @@
|
||||
<module>guava-modules</module>
|
||||
<module>kubernetes-modules</module>
|
||||
<module>libraries-concurrency</module>
|
||||
<module>jhipster-6</module>
|
||||
<module>libraries-testing</module>
|
||||
<module>maven-modules</module>
|
||||
<module>optaplanner</module>
|
||||
@ -869,7 +868,7 @@
|
||||
<module>libraries-apache-commons-2</module>
|
||||
<module>libraries-apache-commons-collections</module>
|
||||
<module>libraries-apache-commons-io</module>
|
||||
<!--<module>libraries-data-2</module>--> <!-- Fixing in JAVA-24007 -->
|
||||
<module>libraries-data-2</module> <!-- Fixing in JAVA-24007 -->
|
||||
<module>libraries-data-io</module>
|
||||
<module>libraries-files</module>
|
||||
<module>libraries-http</module>
|
||||
@ -1059,6 +1058,7 @@
|
||||
<module>guava-modules</module>
|
||||
<module>kubernetes-modules</module>
|
||||
<module>libraries-concurrency</module>
|
||||
<module>jhipster-6</module>
|
||||
<module>libraries-testing</module>
|
||||
<module>maven-modules</module>
|
||||
<module>optaplanner</module>
|
||||
@ -1140,7 +1140,7 @@
|
||||
<module>libraries-apache-commons-2</module>
|
||||
<module>libraries-apache-commons-collections</module>
|
||||
<module>libraries-apache-commons-io</module>
|
||||
<!--<module>libraries-data-2</module>--> <!-- Fixing in JAVA-24007 -->
|
||||
<module>libraries-data-2</module> <!-- Fixing in JAVA-24007 -->
|
||||
<module>libraries-data-io</module>
|
||||
<module>libraries-files</module>
|
||||
<module>libraries-http</module>
|
||||
@ -1270,19 +1270,19 @@
|
||||
|
||||
<!-- plugins -->
|
||||
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
|
||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
||||
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
|
||||
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
|
||||
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
|
||||
<java.version>1.8</java.version>
|
||||
<log4j.version>1.2.17</log4j.version>
|
||||
<jmh-core.version>1.36</jmh-core.version>
|
||||
<jmh-generator.version>1.36</jmh-generator.version>
|
||||
<maven-failsafe-plugin.version>2.21.0</maven-failsafe-plugin.version>
|
||||
<maven-failsafe-plugin.version>3.1.2</maven-failsafe-plugin.version>
|
||||
<commons-collections4.version>4.4</commons-collections4.version>
|
||||
<commons-io.version>2.13.0</commons-io.version>
|
||||
<commons-lang.version>2.6</commons-lang.version>
|
||||
<commons-lang3.version>3.13.0</commons-lang3.version>
|
||||
<commons-cli.version>1.5.0</commons-cli.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
<maven-war-plugin.version>3.4.0</maven-war-plugin.version>
|
||||
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
|
||||
<jstl-api.version>1.2</jstl-api.version>
|
||||
<javax.servlet.jsp-api.version>2.3.3</javax.servlet.jsp-api.version>
|
||||
@ -1292,16 +1292,16 @@
|
||||
<junit-platform.version>1.9.2</junit-platform.version>
|
||||
<junit-jupiter.version>5.9.2</junit-jupiter.version>
|
||||
<junit-platform-surefire-provider.version>1.3.2</junit-platform-surefire-provider.version>
|
||||
<directory-maven-plugin.version>0.3.1</directory-maven-plugin.version>
|
||||
<maven-install-plugin.version>2.5.2</maven-install-plugin.version>
|
||||
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
|
||||
<maven-install-plugin.version>3.1.1</maven-install-plugin.version>
|
||||
<custom-pmd.version>0.0.1</custom-pmd.version>
|
||||
<gitflow-incremental-builder.version>3.12.2</gitflow-incremental-builder.version>
|
||||
<maven-jxr-plugin.version>3.0.0</maven-jxr-plugin.version>
|
||||
<maven-pmd-plugin.version>3.19.0</maven-pmd-plugin.version>
|
||||
<maven-jxr-plugin.version>3.3.0</maven-jxr-plugin.version>
|
||||
<maven-pmd-plugin.version>3.21.0</maven-pmd-plugin.version>
|
||||
<lombok.version>1.18.28</lombok.version>
|
||||
<h2.version>2.1.214</h2.version>
|
||||
<guava.version>32.1.2-jre</guava.version>
|
||||
<maven-jar-plugin.version>3.2.2</maven-jar-plugin.version>
|
||||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -255,7 +255,6 @@
|
||||
<testcontainers-bom.version>1.17.2</testcontainers-bom.version>
|
||||
<java.version>11</java.version>
|
||||
<spring-native.version>0.12.1</spring-native.version>
|
||||
<maven-compiler-plugin.version>3.10.1</maven-compiler-plugin.version>
|
||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||
<maven-surefire-plugin.version>3.1.0</maven-surefire-plugin.version>
|
||||
|
@ -46,6 +46,5 @@
|
||||
<properties>
|
||||
<sentry.version>6.11.0</sentry.version>
|
||||
<cargo-maven3-plugin.version>1.10.4</cargo-maven3-plugin.version>
|
||||
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
|
||||
</properties>
|
||||
</project>
|
@ -55,7 +55,6 @@
|
||||
|
||||
<properties>
|
||||
<slack.version>1.4</slack.version>
|
||||
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@ -97,13 +98,14 @@ public class Auth0JsonWebTokenUnitTest {
|
||||
assertEquals(DATA, claim.asString());
|
||||
}
|
||||
|
||||
@Test
|
||||
//Need to fix with JAVA-24552
|
||||
@Ignore
|
||||
public void givenJWT_whenCreatedWithNotBefore_thenThrowException() {
|
||||
|
||||
jwtToken = JWT.create()
|
||||
.withIssuer(ISSUER)
|
||||
.withClaim(DATA_CLAIM, DATA)
|
||||
.withNotBefore(new Date(System.currentTimeMillis() + 1000L))
|
||||
.withNotBefore(new Date(System.currentTimeMillis() + 10000L))
|
||||
.sign(algorithm);
|
||||
|
||||
assertThrows(IncorrectClaimException.class, () -> {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user