Merge remote-tracking branch 'upstream/master' into BAEL-1657

This commit is contained in:
Nikhil Khatwani 2018-05-09 18:04:30 +05:30
commit bf04c6bd27
271 changed files with 5179 additions and 1462 deletions

View File

@ -34,3 +34,9 @@ CI - Jenkins
================================
This tutorials project is being built **[>> HERE](https://rest-security.ci.cloudbees.com/job/tutorials-unit/)**
### Relevant Articles:
================================
- [Apache Maven Standard Directory Layout](http://www.baeldung.com/maven-directory-structure)
- [Apache Maven Tutorial](http://www.baeldung.com/maven)
- [Designing a User Friendly Java Library](http://www.baeldung.com/design-a-user-friendly-java-library)

View File

@ -20,4 +20,5 @@
- [A Maze Solver in Java](http://www.baeldung.com/java-solve-maze)
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum)

View File

@ -2,3 +2,4 @@
- [Introduction to Asciidoctor](http://www.baeldung.com/introduction-to-asciidoctor)
- [Generating a Book with Asciidoctor](http://www.baeldung.com/asciidoctor-book)
- [Introduction to Asciidoctor in Java](http://www.baeldung.com/asciidoctor)

View File

@ -8,4 +8,5 @@
- [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload)
- [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests)
- [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3)
- [Managing Amazon SQS Queues in Java](http://www.baeldung.com/aws-queues-java)

View File

@ -8,16 +8,12 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>

View File

@ -28,12 +28,6 @@
<artifactId>groovy-sql</artifactId>
<version>${groovy-sql.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.platform</groupId>
<artifactId>junit-platform-runner</artifactId>

View File

@ -0,0 +1,61 @@
package com.baeldung.java10;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Before;
import org.junit.Test;
public class Java10FeaturesUnitTest {
private List<Integer> someIntList;
@Before
public void setup() {
someIntList = new ArrayList<>();
someIntList.add(1);
someIntList.add(2);
someIntList.add(3);
}
@Test
public void whenVarInitWithString_thenGetStringTypeVar() {
var message = "Hello, Java 10";
assertTrue(message instanceof String);
}
@Test
public void whenVarInitWithAnonymous_thenGetAnonymousType() {
var obj = new Object() {};
assertFalse(obj.getClass().equals(Object.class));
}
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List<Integer> copyList = List.copyOf(someIntList);
copyList.add(4);
}
@Test(expected = UnsupportedOperationException.class)
public void whenModifyToUnmodifiableList_thenThrowsException() {
List<Integer> evenList = someIntList.stream()
.filter(i -> i % 2 == 0)
.collect(Collectors.toUnmodifiableList());
evenList.add(4);
}
@Test
public void whenListContainsInteger_OrElseThrowReturnsInteger() {
Integer firstEven = someIntList.stream()
.filter(i -> i % 2 == 0)
.findFirst()
.orElseThrow();
is(firstEven).equals(Integer.valueOf(2));
}
}

View File

@ -47,3 +47,7 @@
- [Overview of Java Built-in Annotations](http://www.baeldung.com/java-default-annotations)
- [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max)
- [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization)
- [Filtering Kotlin Collections](http://www.baeldung.com/kotlin-filter-collection)
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
- [Measure Elapsed Time in Java](http://www.baeldung.com/java-measure-elapsed-time)

View File

@ -9,17 +9,12 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>

View File

@ -8,10 +8,11 @@
<name>core-java-collections</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
@ -25,11 +26,6 @@
<artifactId>collections-generic</artifactId>
<version>${collections-generic.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
@ -55,7 +51,6 @@
</dependencies>
<properties>
<guava.version>22.0</guava.version>
<commons-lang3.version>3.5</commons-lang3.version>
<commons-collections4.version>4.1</commons-collections4.version>
<collections-generic.version>4.01</collections-generic.version>

View File

@ -9,17 +9,12 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>

View File

@ -9,8 +9,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
@ -20,11 +21,6 @@
<artifactId>collections-generic</artifactId>
<version>${collections-generic.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>

View File

@ -8,8 +8,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
@ -19,11 +20,6 @@
<artifactId>collections-generic</artifactId>
<version>${collections-generic.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>

View File

@ -140,3 +140,9 @@
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger)
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
- [Sending Emails with Java](http://www.baeldung.com/java-email)
- [Introduction to SSL in Java](http://www.baeldung.com/java-ssl)
- [Java KeyStore API](http://www.baeldung.com/java-keystore)
- [Double-Checked Locking with Singleton](http://www.baeldung.com/java-singleton-double-checked-locking)

View File

@ -9,17 +9,12 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
@ -438,7 +433,6 @@
<log4j.version>1.2.17</log4j.version>
<!-- util -->
<guava.version>22.0</guava.version>
<commons-lang3.version>3.5</commons-lang3.version>
<bouncycastle.version>1.55</bouncycastle.version>
<commons-codec.version>1.10</commons-codec.version>

View File

@ -0,0 +1,19 @@
package com.baeldung.designpatterns.composite;
/**
* Created by Gebruiker on 5/3/2018.
*/
public class CompositeDemo {
public static void main(String args[]) {
Department salesDepartment = new SalesDepartment(1, "Sales department");
Department financialDepartment = new FinancialDepartment(2, "Financial department");
HeadDepartment headDepartment = new HeadDepartment(3, "Head department");
headDepartment.addDepartMent(salesDepartment);
headDepartment.addDepartMent(financialDepartment);
headDepartment.printDepartmentName();
}
}

View File

@ -0,0 +1,9 @@
package com.baeldung.designpatterns.composite;
/**
* Created by Gebruiker on 5/1/2018.
*/
public interface Department {
void printDepartmentName();
}

View File

@ -0,0 +1,35 @@
package com.baeldung.designpatterns.composite;
/**
* Created by Gebruiker on 5/1/2018.
*/
public class FinancialDepartment implements Department {
private Integer id;
private String name;
public FinancialDepartment(Integer id, String name) {
this.id = id;
this.name = name;
}
public void printDepartmentName() {
System.out.println(getClass().getSimpleName());
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.designpatterns.composite;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Gebruiker on 5/1/2018.
*/
public class HeadDepartment implements Department {
private Integer id;
private String name;
private List<Department> childDepartments;
public HeadDepartment(Integer id, String name) {
this.id = id;
this.name = name;
this.childDepartments = new ArrayList<Department>();
}
public void printDepartmentName() {
childDepartments.forEach(Department::printDepartmentName);
}
public void addDepartMent(Department department) {
childDepartments.add(department);
}
public void removeDepartment(Department department) {
childDepartments.remove(department);
}
}

View File

@ -0,0 +1,35 @@
package com.baeldung.designpatterns.composite;
/**
* Created by Gebruiker on 5/1/2018.
*/
public class SalesDepartment implements Department {
private Integer id;
private String name;
public SalesDepartment(Integer id, String name) {
this.id = id;
this.name = name;
}
public void printDepartmentName() {
System.out.println(getClass().getSimpleName());
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

View File

@ -25,12 +25,6 @@
<artifactId>commons-math3</artifactId>
<version>${commons-math3.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.platform</groupId>
<artifactId>junit-platform-runner</artifactId>

View File

@ -0,0 +1,19 @@
package com.baeldung.filesystem
import java.io.File
class FileWriter {
fun writeFileUsingPrintWriter(fileName: String, fileContent: String) =
File(fileName).printWriter().use { out -> out.print(fileContent) }
fun writeFileUsingBufferedWriter(fileName: String, fileContent: String) =
File(fileName).bufferedWriter().use { out -> out.write(fileContent) }
fun writeFileDirectly(fileName: String, fileContent: String) =
File(fileName).writeText(fileContent)
fun writeFileDirectlyAsBytes(fileName: String, fileContent: String) =
File(fileName).writeBytes(fileContent.toByteArray())
}

View File

@ -0,0 +1,43 @@
package com.baeldung.filesystem
import org.junit.jupiter.api.Test
import java.io.File
import kotlin.test.assertEquals
internal class FileWriterTest {
private val fileName = "src/test/resources/Kotlin.out"
private val fileContent = "Kotlin\nConcise, Safe, Interoperable, Tool-friendly"
private val fileWriter = FileWriter()
@Test
fun whenWrittenWithPrintWriter_thenCorrect() {
fileWriter.writeFileUsingPrintWriter(fileName, fileContent)
assertEquals(fileContent, File(fileName).readText())
}
@Test
fun whenWrittenWithBufferedWriter_thenCorrect() {
fileWriter.writeFileUsingBufferedWriter(fileName, fileContent)
assertEquals(fileContent, File(fileName).readText())
}
@Test
fun whenWrittenDirectly_thenCorrect() {
fileWriter.writeFileDirectly(fileName, fileContent)
assertEquals(fileContent, File(fileName).readText())
}
@Test
fun whenWrittenDirectlyAsBytes_thenCorrect() {
fileWriter.writeFileDirectlyAsBytes(fileName, fileContent)
assertEquals(fileContent, File(fileName).readText())
}
}

View File

@ -5,10 +5,11 @@
<artifactId>drools</artifactId>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring</relativePath>
</parent>
<dependencies>
<dependency>
@ -47,18 +48,13 @@
<artifactId>poi-ooxml</artifactId>
<version>${apache-poi-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>
</dependencies>
<properties>
<http-component-version>4.4.6</http-component-version>
<drools-version>7.4.1.Final</drools-version>
<apache-poi-version>3.13</apache-poi-version>
<spring-core.version>4.3.6.RELEASE</spring-core.version>
<spring.version>4.3.6.RELEASE</spring.version>
</properties>
</project>

View File

@ -8,8 +8,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
@ -19,11 +20,6 @@
<artifactId>joda-time</artifactId>
<version>${joda-time.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>

View File

@ -8,19 +8,11 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<guava.version>18.0</guava.version>
</properties>

View File

@ -8,19 +8,11 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<guava.version>19.0</guava.version>
</properties>

View File

@ -7,18 +7,12 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jool</artifactId>

View File

@ -8,17 +8,13 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>

View File

@ -11,11 +11,6 @@
<relativePath>../../</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.0-M4</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
@ -62,4 +57,8 @@
</plugin>
</plugins>
</build>
<properties>
</properties>
</project>

View File

@ -10,8 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring</relativePath>
</parent>
<dependencies>

View File

@ -9,3 +9,4 @@
- [Hibernate Interceptors](http://www.baeldung.com/hibernate-interceptor)
- [JPA Attribute Converters](http://www.baeldung.com/jpa-attribute-converters)
- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob)
- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable)

View File

@ -8,17 +8,13 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>

View File

@ -8,18 +8,13 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>

View File

@ -10,8 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-java</relativePath>
</parent>
<dependencies>
@ -25,17 +26,6 @@
<artifactId>jmh-generator-annprocess</artifactId>
<version>${openjdk.jmh.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<build>

View File

@ -2,3 +2,4 @@
- [Introduction to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3)
- [Introduction to JSF EL 2](http://www.baeldung.com/intro-to-jsf-expression-language)
- [JavaServer Faces (JSF) with Spring](http://www.baeldung.com/spring-jsf)
- [Introduction to Primefaces](http://www.baeldung.com/jsf-primefaces)

View File

@ -34,12 +34,6 @@
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.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.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>

View File

@ -65,7 +65,7 @@
- [Creating and Configuring Jetty 9 Server in Java](http://www.baeldung.com/jetty-java-programmatic)
- [Introduction To OpenCSV](http://www.baeldung.com/opencsv)
- [Introduction to Akka Actors in Java](http://www.baeldung.com/akka-actors-java)
- [Asynchronous HTTP with async-http-client in Java](https://github.com/eugenp/tutorials/tree/master/libraries)
- [Asynchronous HTTP with async-http-client in Java](http://www.baeldung.com/async-http-client)
- [Introduction to Smooks](http://www.baeldung.com/smooks)
- [WebSockets with AsyncHttpClient](http://www.baeldung.com/async-http-client-websockets)
- [A Guide to Infinispan in Java](http://www.baeldung.com/infinispan)
@ -82,6 +82,8 @@
- [Publish and Receive Messages with Nats Java Client](http://www.baeldung.com/nats-java-client)
- [Java Concurrency Utility with JCTools](http://www.baeldung.com/java-concurrency-jc-tools)
- [Apache Commons Collections MapUtils](http://www.baeldung.com/apache-commons-map-utils)
- [Testing Netty with EmbeddedChannel](http://www.baeldung.com/testing-netty-embedded-channel)
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.

View File

@ -5,3 +5,4 @@
- [Creating a Custom Logback Appender](http://www.baeldung.com/custom-logback-appender)
- [Get Log Output in JSON Format](http://www.baeldung.com/java-log-json-output)
- [A Guide To Logback](http://www.baeldung.com/a-guide-to-logback)

View File

@ -9,28 +9,22 @@
<description>tutorial on logging with MDC and NDC</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../../</relativePath>
</parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-spring</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework.version}</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework.version}</version>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
@ -79,14 +73,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${springframework.version}</version>
<version>${spring.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<springframework.version>4.3.4.RELEASE</springframework.version>
<spring.version>4.3.4.RELEASE</spring.version>
<log4j.version>1.2.17</log4j.version>
<log4j2.version>2.7</log4j2.version>
<disruptor.version>3.3.6</disruptor.version>

View File

@ -0,0 +1,19 @@
<?xml version="1.0"?>
<project
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>modify-xml-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>modify-xml-configuration</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,29 @@
/**
This class demonstrates on modifying the loaded xml configuration by
extending XMLConfigurationFactory as defined in section 4.4 of
"Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.config;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Order;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory;
@Plugin(name = "CustomConfigurationFactory", category = ConfigurationFactory.CATEGORY)
@Order(50)
public class CustomXMLConfigurationFactory extends XmlConfigurationFactory {
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
return new MyXMLConfiguration(loggerContext, source);
}
@Override
public String[] getSupportedTypes() {
return new String[] { ".xml", "*" };
}
}

View File

@ -0,0 +1,35 @@
/**
This class demonstrates on overriding the configuration loaded through xml
as defined in section 4.4 of "Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.config;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.Layout;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.appender.FileAppender;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.apache.logging.log4j.core.config.xml.XmlConfiguration;
import org.apache.logging.log4j.core.layout.PatternLayout;
public class MyXMLConfiguration extends XmlConfiguration {
public MyXMLConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
super(loggerContext, source);
}
@Override
protected void doConfigure() {
super.doConfigure();
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig("com");
final Layout layout = PatternLayout.createLayout("[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n", null, config, null, null, false, false, null, null);
Appender appender = FileAppender.createAppender("target/test.log", "false", "false", "File", "true", "false", "false", "4000", layout, null, "false", null, config);
loggerConfig.addAppender(appender, Level.DEBUG, null);
addAppender(appender);
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration monitorInterval="60">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout
pattern="[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="com" additivity="false" level="info">
<AppenderRef ref="console" />
</Logger>
<Root>
<AppenderRef ref="console" />
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,23 @@
package com.baeldung.log4j2.logtest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.plugins.util.PluginManager;
import org.junit.Test;
public class LogTest {
static{
PluginManager.addPackage("com.baeldung.log4j2.config");
}
@Test
public void simpleProgrammaticConfiguration() {
Logger logger = LogManager.getLogger();
LoggerContext ctx = (LoggerContext) LogManager.getContext();
logger.debug("Debug log message");
logger.info("Info log message");
logger.error("Error log message");
}
}

View File

@ -0,0 +1,34 @@
<?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>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>simple-configuration</module>
<module>set-configuration-factory</module>
<module>simple-configurator</module>
<module>simple-configuration-xml</module>
<module>modify-xml-configuration</module>
</modules>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,10 @@
<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>
<parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>set-configuration-factory</artifactId>
</project>

View File

@ -0,0 +1,88 @@
/**
This class demonstrates how to build the components of
the configuration factory, as described in Section 3 of
"Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.config;
import java.io.IOException;
import java.net.URI;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
public class CustomConfigurationFactory extends ConfigurationFactory {
static Configuration createConfiguration(final String name, ConfigurationBuilder<BuiltConfiguration> builder) {
AppenderComponentBuilder console = builder.newAppender("Stdout", "Console");
LayoutComponentBuilder layout = builder.newLayout("PatternLayout")
.addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
console.add(layout);
FilterComponentBuilder filter = builder.newFilter("MarkerFilter", Filter.Result.ACCEPT, Filter.Result.DENY);
filter.addAttribute("marker", "FLOW");
console.add(filter);
builder.add(console);
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile = builder.newAppender("rolling", "RollingFile");
rollingFile.addAttribute("fileName", "target/rolling.log");
rollingFile.addAttribute("filePattern", "target/archive/rolling-%d{MM-dd-yy}.log.gz");
rollingFile.add(layout);
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
AppenderComponentBuilder file = builder.newAppender("FileSystem", "File");
file.addAttribute("fileName", "target/logging.log");
file.add(layout);
builder.add(file);
LoggerComponentBuilder logger = builder.newLogger("com", Level.DEBUG);
logger.add(builder.newAppenderRef("Stdout"));
logger.add(builder.newAppenderRef("rolling"));
logger.add(builder.newAppenderRef("FileSystem"));
logger.addAttribute("additivity", false);
builder.add(logger);
RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.ERROR);
rootLogger.add(builder.newAppenderRef("Stdout"));
rootLogger.add(builder.newAppenderRef("rolling"));
rootLogger.add(builder.newAppenderRef("FileSystem"));
rootLogger.addAttribute("additivity", false);
builder.add(rootLogger);
try {
builder.writeXmlConfiguration(System.out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.build();
}
public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) {
ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder();
return createConfiguration(name, builder);
}
@Override
protected String[] getSupportedTypes() {
return new String[] { "*" };
}
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
return getConfiguration(loggerContext, source.toString(), null);
}
}

View File

@ -0,0 +1,33 @@
/**
This class invokes the configuration factory with static initialization,
as defined in section 4.1 of the "Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.logtest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.baeldung.log4j2.config.CustomConfigurationFactory;
@RunWith(JUnit4.class)
public class LogTest {
static {
CustomConfigurationFactory customConfigurationFactory = new CustomConfigurationFactory();
ConfigurationFactory.setConfigurationFactory(customConfigurationFactory);
}
@Test
public void simpleProgrammaticConfiguration() {
Logger logger = LogManager.getLogger();
Marker markerContent = MarkerManager.getMarker("FLOW");
logger.debug(markerContent, "Debug log message");
logger.info(markerContent, "Info log message");
logger.error(markerContent, "Error log message");
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<project
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>simple-configuration-xml</artifactId>
<name>simple-configuration-xml</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -0,0 +1,32 @@
<?xml version="1.0" ?>
<Configuration>
<Appenders>
<Console name="Stdout">
<PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
<MarkerFilter onMatch="ACCEPT" onMismatch="DENY" marker="FLOW" />
</Console>
<RollingFile name="rolling" fileName="target/rolling.log"
filePattern="target/archive/rolling-%d{MM-dd-yy}.log.gz">
<PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
<Policies>
<CronTriggeringPolicy schedule="0 0 0 * * ?" />
<SizeBasedTriggeringPolicy size="100M" />
</Policies>
</RollingFile>
<File name="FileSystem" fileName="target/logging.log">
<PatternLayout pattern="%d [%t] %-5level: %msg%n%throwable" />
</File>
</Appenders>
<Loggers>
<Logger name="com" level="DEBUG" additivity="false">
<AppenderRef ref="Stdout" />
<AppenderRef ref="rolling" />
<AppenderRef ref="FileSystem" />
</Logger>
<Root level="ERROR" additivity="false">
<AppenderRef ref="Stdout" />
<AppenderRef ref="rolling" />
<AppenderRef ref="FileSystem" />
</Root>
</Loggers>
</Configuration>

View File

@ -0,0 +1,30 @@
/**
This class loads the logging configuration from the xml defined in
src/main/resources and uses the same configuration generated through
programmatic configuration as defined in simple-configuration example.
**/
package com.baeldung.log4j2.logtest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class LogTest {
@Test
public void simpleProgrammaticConfiguration(){
Logger logger = LogManager.getLogger();
Marker markerContent = MarkerManager.getMarker("FLOW");
logger.debug(markerContent, "Debug log message");
logger.info(markerContent, "Info log message");
logger.error(markerContent, "Error log message");
}
}

View File

@ -0,0 +1,10 @@
<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>
<parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>simple-configuration</artifactId>
</project>

View File

@ -0,0 +1,94 @@
/**
This class demonstrates how to build the components of
the configuration factory, as described in Section 3 of
"Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.config;
import java.io.IOException;
import java.net.URI;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.Filter;
import org.apache.logging.log4j.core.LoggerContext;
import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.ConfigurationFactory;
import org.apache.logging.log4j.core.config.ConfigurationSource;
import org.apache.logging.log4j.core.config.Order;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.FilterComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LayoutComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.LoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.RootLoggerComponentBuilder;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.apache.logging.log4j.core.config.plugins.Plugin;
@Plugin(name = "CustomConfigurationFactory", category = ConfigurationFactory.CATEGORY)
@Order(50)
public class CustomConfigurationFactory extends ConfigurationFactory {
static Configuration createConfiguration(final String name, ConfigurationBuilder<BuiltConfiguration> builder) {
AppenderComponentBuilder console = builder.newAppender("Stdout", "Console");
LayoutComponentBuilder layout = builder.newLayout("PatternLayout")
.addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable");
console.add(layout);
FilterComponentBuilder filter = builder.newFilter("MarkerFilter", Filter.Result.ACCEPT, Filter.Result.DENY);
filter.addAttribute("marker", "FLOW");
console.add(filter);
builder.add(console);
ComponentBuilder triggeringPolicies = builder.newComponent("Policies")
.addComponent(builder.newComponent("CronTriggeringPolicy")
.addAttribute("schedule", "0 0 0 * * ?"))
.addComponent(builder.newComponent("SizeBasedTriggeringPolicy")
.addAttribute("size", "100M"));
AppenderComponentBuilder rollingFile = builder.newAppender("rolling", "RollingFile");
rollingFile.addAttribute("fileName", "target/rolling.log");
rollingFile.addAttribute("filePattern", "target/archive/rolling-%d{MM-dd-yy}.log.gz");
rollingFile.add(layout);
rollingFile.addComponent(triggeringPolicies);
builder.add(rollingFile);
AppenderComponentBuilder file = builder.newAppender("FileSystem", "File");
file.addAttribute("fileName", "target/logging.log");
file.add(layout);
builder.add(file);
LoggerComponentBuilder logger = builder.newLogger("com", Level.DEBUG);
logger.add(builder.newAppenderRef("Stdout"));
logger.add(builder.newAppenderRef("rolling"));
logger.add(builder.newAppenderRef("FileSystem"));
logger.addAttribute("additivity", false);
builder.add(logger);
RootLoggerComponentBuilder rootLogger = builder.newRootLogger(Level.ERROR);
rootLogger.add(builder.newAppenderRef("Stdout"));
rootLogger.add(builder.newAppenderRef("rolling"));
// rootLogger.add(builder.newAppenderRef("syslogAppender"));
rootLogger.add(builder.newAppenderRef("FileSystem"));
rootLogger.addAttribute("additivity", false);
builder.add(rootLogger);
try {
builder.writeXmlConfiguration(System.out);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return builder.build();
}
@Override
public Configuration getConfiguration(LoggerContext loggerContext, ConfigurationSource source) {
return getConfiguration(loggerContext, source.toString(), null);
}
public Configuration getConfiguration(final LoggerContext loggerContext, final String name, final URI configLocation) {
ConfigurationBuilder<BuiltConfiguration> builder = newConfigurationBuilder();
return createConfiguration(name, builder);
}
@Override
protected String[] getSupportedTypes() {
return new String[] { "*" };
}
}

View File

@ -0,0 +1,22 @@
/**
This class invokes the configuration factory through the run time property,
as defined in section 4.2 of the "Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.logtest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
import org.apache.logging.log4j.MarkerManager;
import org.junit.Test;
public class LogTest {
@Test
public void simpleProgrammaticConfiguration() {
Logger logger = LogManager.getLogger();
Marker markerContent = MarkerManager.getMarker("FLOW");
logger.debug(markerContent, "Debug log message");
logger.info(markerContent, "Info log message");
logger.error(markerContent, "Error log message");
}
}

View File

@ -0,0 +1,10 @@
<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>
<parent>
<groupId>com.baeldung.log4j2</groupId>
<artifactId>log4j2-programmatic-configuration</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>simple-configurator</artifactId>
</project>

View File

@ -0,0 +1,40 @@
/**
This class demonstrates how to use ConfigurationBuilderFactory directly,
as described in Section 3 of "Programmatic Configuration with Log4j 2"
**/
package com.baeldung.log4j2.configure;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.appender.ConsoleAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.builder.api.AppenderComponentBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilder;
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory;
import org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import com.baeldung.log4j2.logtest.LogPrinter;
@RunWith(JUnit4.class)
public class LogTest {
@Test
public void simpleProgrammaticConfiguration() {
ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
AppenderComponentBuilder console = builder.newAppender("Stdout", "CONSOLE")
.addAttribute("target", ConsoleAppender.Target.SYSTEM_OUT);
console.add(builder.newLayout("PatternLayout")
.addAttribute("pattern", "%d [%t] %-5level: %msg%n%throwable"));
builder.add(console);
builder.add(builder.newLogger("com", Level.DEBUG)
.add(builder.newAppenderRef("Stdout"))
.addAttribute("additivity", false));
builder.add(builder.newRootLogger(Level.ERROR)
.add(builder.newAppenderRef("Stdout")));
Configurator.initialize(builder.build());
LogPrinter logPrinter = new LogPrinter();
logPrinter.printlog();
}
}

View File

@ -0,0 +1,15 @@
package com.baeldung.log4j2.logtest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class LogPrinter {
private Logger logger = LogManager.getLogger();
public void printlog() {
logger.debug("Debug log message");
logger.info("Info log message");
logger.error("Error log message");
}
}

View File

@ -0,0 +1,89 @@
package com.baeldung.logback;
import ch.qos.logback.classic.Level;
import org.junit.Test;
import ch.qos.logback.classic.Logger;
import org.slf4j.LoggerFactory;
public class LogbackTests {
@Test
public void givenLogHierarchy_MessagesFiltered() {
ch.qos.logback.classic.Logger parentLogger =
(ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback");
parentLogger.setLevel(Level.INFO);
Logger childlogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger("com.baeldung.logback.tests");
parentLogger.warn("This message is logged because WARN > INFO.");
// This request is disabled, because DEBUG < INFO.
parentLogger.debug("This message is not logged because DEBUG < INFO.");
childlogger.info("INFO == INFO");
childlogger.debug("DEBUG < INFO");
}
@Test
public void givenRootLevel_MessagesFiltered() {
ch.qos.logback.classic.Logger logger =
(ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback");
logger.debug("Hi there!");
Logger rootLogger = (ch.qos.logback.classic.Logger)LoggerFactory.getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
logger.debug("This message is logged because DEBUG == DEBUG.");
rootLogger.setLevel(Level.ERROR);
logger.warn("This message is not logged because WARN < ERROR.");
logger.error("This is logged.");
}
@Test
public void givenParameters_ValuesLogged() {
Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(LogbackTests.class);
String message = "This is a String";
Integer zero = 0;
try {
logger.debug("Logging message: {}", message);
logger.debug("Going to divide {} by {}", 42, zero);
int result = 42 / zero;
} catch (Exception e) {
logger.error("Error dividing {} by {} ", 42, zero, e);
}
}
@Test
public void givenConfig_MessageFiltered() {
Logger foobar = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.foobar");
Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback");
Logger testslogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.baeldung.logback.tests");
foobar.debug("This is logged from foobar");
logger.debug("This is not logged from logger");
logger.info("This is logged from logger");
testslogger.info("This is not logged from tests");
testslogger.warn("This is logged from tests");
}
}

View File

@ -0,0 +1,32 @@
<configuration debug="true">
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>tests.log</file>
<append>true</append>
<!-- set immediateFlush to false for much higher logging throughput -->
<immediateFlush>true</immediateFlush>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
<logger name="com.baeldung.logback" level="INFO" />
<logger name="com.baeldung.logback.tests" level="WARN">
<appender-ref ref="FILE" />
</logger>
</configuration>

1
parent-boot-2/README.md Normal file
View File

@ -0,0 +1 @@
## Relevant articles:

120
parent-boot-2/pom.xml Normal file
View File

@ -0,0 +1,120 @@
<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.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Parent Boot 2</name>
<description>Parent for all spring boot 2 modules</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>3</forkCount>
<reuseForks>true</reuseForks>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LongRunningUnitTest.java</exclude>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*ManualTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
<exclude>**/AutoconfigurationTest.java</exclude>
<exclude>**/*UnitTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
<include>*/EthControllerTestOne.java</include>
<include>**/*IntTest.java</include>
<include>**/*EntryPointsTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<rest-assured.version>3.1.0</rest-assured.version>
<!-- plugins -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>

1
parent-java/README.md Normal file
View File

@ -0,0 +1 @@
## Relevant articles:

30
parent-java/pom.xml Normal file
View File

@ -0,0 +1,30 @@
<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.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-java</name>
<description>Parent for all java modules</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<!-- utils -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<guava.version>22.0</guava.version>
</properties>
</project>

1
parent-spring/README.md Normal file
View File

@ -0,0 +1 @@
## Relevant articles:

36
parent-spring/pom.xml Normal file
View File

@ -0,0 +1,36 @@
<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.baeldung</groupId>
<artifactId>parent-spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-spring</name>
<description>Parent for all spring core modules</description>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<spring.version>4.3.6.RELEASE</spring.version>
<junit.jupiter.version>5.0.2</junit.jupiter.version>
</properties>
</project>

View File

@ -19,10 +19,22 @@
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</properties>
</project>

View File

@ -0,0 +1,19 @@
package com.baeldung.pattern.command.client;
import com.baeldung.pattern.command.command.OpenTextFileOperation;
import com.baeldung.pattern.command.command.SaveTextFileOperation;
import com.baeldung.pattern.command.command.TextFileOperation;
import com.baeldung.pattern.command.invoker.TextFileOperationExecutor;
import com.baeldung.pattern.command.receiver.TextFile;
public class TextFileApplication {
public static void main(String[] args) {
TextFileOperation openTextFileOperation = new OpenTextFileOperation(new TextFile("file1.txt"));
TextFileOperation saveTextFileOperation = new SaveTextFileOperation(new TextFile("file2.txt"));
TextFileOperationExecutor textFileOperationExecutor = new TextFileOperationExecutor();
System.out.println(textFileOperationExecutor.executeOperation(openTextFileOperation));
System.out.println(textFileOperationExecutor.executeOperation(saveTextFileOperation));
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.pattern.command.command;
import com.baeldung.pattern.command.receiver.TextFile;
public class OpenTextFileOperation implements TextFileOperation {
private final TextFile textFile;
public OpenTextFileOperation(TextFile textFile) {
this.textFile = textFile;
}
@Override
public String execute() {
return textFile.open();
}
}

View File

@ -0,0 +1,17 @@
package com.baeldung.pattern.command.command;
import com.baeldung.pattern.command.receiver.TextFile;
public class SaveTextFileOperation implements TextFileOperation {
private final TextFile textFile;
public SaveTextFileOperation(TextFile textFile) {
this.textFile = textFile;
}
@Override
public String execute() {
return textFile.save();
}
}

View File

@ -0,0 +1,8 @@
package com.baeldung.pattern.command.command;
@FunctionalInterface
public interface TextFileOperation {
String execute();
}

View File

@ -0,0 +1,15 @@
package com.baeldung.pattern.command.invoker;
import com.baeldung.pattern.command.command.TextFileOperation;
import java.util.ArrayList;
import java.util.List;
public class TextFileOperationExecutor {
private final List<TextFileOperation> textFileOperations = new ArrayList<>();
public String executeOperation(TextFileOperation textFileOperation) {
textFileOperations.add(textFileOperation);
return textFileOperation.execute();
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.pattern.command.receiver;
public class TextFile {
private final String name;
public TextFile(String name) {
this.name = name;
}
public String open() {
return "Opening file " + name;
}
public String read() {
return "Reading file " + name;
}
public String write() {
return "Writing to file " + name;
}
public String save() {
return "Saving file " + name;
}
public String copy() {
return "Copying file " + name;
}
public String paste() {
return "Pasting file " + name;
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.pattern.command.test;
import com.baeldung.pattern.command.command.OpenTextFileOperation;
import com.baeldung.pattern.command.command.TextFileOperation;
import com.baeldung.pattern.command.receiver.TextFile;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
public class OpenTextFileOperationUnitTest {
@Test
public void givenOpenTextFileOperationIntance_whenCalledExecuteMethod_thenOneAssertion() {
TextFileOperation openTextFileOperation = new OpenTextFileOperation(new TextFile("file1.txt"));
assertThat(openTextFileOperation.execute()).isEqualTo("Opening file file1.txt");
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.pattern.command.test;
import com.baeldung.pattern.command.command.SaveTextFileOperation;
import com.baeldung.pattern.command.command.TextFileOperation;
import com.baeldung.pattern.command.receiver.TextFile;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
public class SaveTextFileOperationUnitTest {
@Test
public void givenSaveTextFileOperationIntance_whenCalledExecuteMethod_thenOneAssertion() {
TextFileOperation openTextFileOperation = new SaveTextFileOperation(new TextFile("file1.txt"));
assertThat(openTextFileOperation.execute()).isEqualTo("Saving file file1.txt");
}
}

View File

@ -0,0 +1,68 @@
package com.baeldung.pattern.command.test;
import com.baeldung.pattern.command.command.OpenTextFileOperation;
import com.baeldung.pattern.command.command.SaveTextFileOperation;
import com.baeldung.pattern.command.command.TextFileOperation;
import com.baeldung.pattern.command.invoker.TextFileOperationExecutor;
import com.baeldung.pattern.command.receiver.TextFile;
import java.util.function.Function;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
import org.junit.BeforeClass;
public class TextFileOperationExecutorUnitTest {
private static TextFileOperationExecutor textFileOperationExecutor;
@BeforeClass
public static void setUpTextFileOperationExecutor() {
textFileOperationExecutor = new TextFileOperationExecutor();
}
@Test
public void givenTextFileOPerationExecutorInstance_whenCalledexecuteOperationWithOpenTextOperation_thenOneAssertion() {
TextFileOperation textFileOperation = new OpenTextFileOperation(new TextFile("file1.txt"));
assertThat(textFileOperationExecutor.executeOperation(textFileOperation)).isEqualTo("Opening file file1.txt");
}
@Test
public void givenTextFileOPerationExecutorInstance_whenCalledexecuteOperationWithSaveTextOperation_thenOneAssertion() {
TextFileOperation textFileOperation = new SaveTextFileOperation(new TextFile("file1.txt"));
assertThat(textFileOperationExecutor.executeOperation(textFileOperation)).isEqualTo("Saving file file1.txt");
}
@Test
public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileOpenLambda_thenOneAssertion() {
assertThat(textFileOperationExecutor.executeOperation(() -> {return "Opening file file1.txt";})).isEqualTo("Opening file file1.txt");
}
@Test
public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileSaveLambda_thenOneAssertion() {
assertThat(textFileOperationExecutor.executeOperation(() -> {return "Saving file file1.txt";})).isEqualTo("Saving file file1.txt");
}
@Test
public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileOpenMethodReferenceOfExistingObject_thenOneAssertion() {
TextFile textFile = new TextFile("file1.txt");
assertThat(textFileOperationExecutor.executeOperation(textFile::open)).isEqualTo("Opening file file1.txt");
}
@Test
public void givenTextFileOperationExecutorInstance_whenCalledexecuteOperationWithTextFileSaveMethodReferenceOfExistingObject_thenOneAssertion() {
TextFile textFile = new TextFile("file1.txt");
assertThat(textFileOperationExecutor.executeOperation(textFile::save)).isEqualTo("Saving file file1.txt");
}
@Test
public void givenOpenTextFileOperationExecuteMethodReference_whenCalledApplyMethod_thenOneAssertion() {
Function<OpenTextFileOperation, String> executeMethodReference = OpenTextFileOperation::execute;
assertThat(executeMethodReference.apply(new OpenTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Opening file file1.txt");
}
@Test
public void givenSaveTextFileOperationExecuteMethodReference_whenCalledApplyMethod_thenOneAssertion() {
Function<SaveTextFileOperation, String> executeMethodReference = SaveTextFileOperation::execute;
assertThat(executeMethodReference.apply(new SaveTextFileOperation(new TextFile("file1.txt")))).isEqualTo("Saving file file1.txt");
}
}

View File

@ -0,0 +1,42 @@
package com.baeldung.pattern.command.test;
import com.baeldung.pattern.command.receiver.TextFile;
import org.junit.Test;
import static org.assertj.core.api.Assertions.*;
import org.junit.BeforeClass;
public class TextFileUnitTest {
private static TextFile textFile;
@BeforeClass
public static void setUpTextFileInstance() {
textFile = new TextFile("file1.txt");
}
@Test
public void givenTextFileInstance_whenCalledopenMethod_thenOneAssertion() {
assertThat(textFile.open()).isEqualTo("Opening file file1.txt");
}
@Test
public void givenTextFileInstance_whenCalledwriteMethod_thenOneAssertion() {
assertThat(textFile.write()).isEqualTo("Writing to file file1.txt");
}
@Test
public void givenTextFileInstance_whenCalledsaveMethod_thenOneAssertion() {
assertThat(textFile.save()).isEqualTo("Saving file file1.txt");
}
@Test
public void givenTextFileInstance_whenCalledcopyMethod_thenOneAssertion() {
assertThat(textFile.copy()).isEqualTo("Copying file file1.txt");
}
@Test
public void givenTextFileInstance_whenCalledpasteMethod_thenOneAssertion() {
assertThat(textFile.paste()).isEqualTo("Pasting file file1.txt");
}
}

79
performance-tests/pom.xml Normal file
View File

@ -0,0 +1,79 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>performancetests</artifactId>
<dependencies>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>1.5.2</version>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>5.5.1</version>
</dependency>
<dependency>
<groupId>io.craftsman</groupId>
<artifactId>dozer-jdk8-support</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>1.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.googlecode.jmapper-framework</groupId>
<artifactId>jmapper-core</artifactId>
<version>1.6.0.1</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.20</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.20</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,11 @@
package com.baeldung.performancetests;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
public interface Converter {
Order convert(SourceOrder sourceOrder);
DestinationCode convert(SourceCode sourceCode);
}

View File

@ -0,0 +1,29 @@
package com.baeldung.performancetests.dozer;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
public class DozerConverter implements Converter {
private final Mapper mapper;
public DozerConverter() {
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.addMapping(DozerConverter.class.getResourceAsStream("/dozer-mapping.xml"));
this.mapper = mapper;
}
@Override
public Order convert(SourceOrder sourceOrder) {
return mapper.map(sourceOrder,Order.class);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return mapper.map(sourceCode, DestinationCode.class);
}
}

View File

@ -0,0 +1,30 @@
package com.baeldung.performancetests.jmapper;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import com.googlecode.jmapper.JMapper;
import com.googlecode.jmapper.api.JMapperAPI;
public class JMapperConverter implements Converter {
JMapper realLifeMapper;
JMapper simpleMapper;
public JMapperConverter() {
JMapperAPI api = new JMapperAPI().add(JMapperAPI.mappedClass(Order.class));
realLifeMapper = new JMapper(Order.class, SourceOrder.class, api);
JMapperAPI simpleApi = new JMapperAPI().add(JMapperAPI.mappedClass(DestinationCode.class));
simpleMapper = new JMapper(DestinationCode.class, SourceCode.class, simpleApi);
}
@Override
public Order convert(SourceOrder sourceOrder) {
return (Order) realLifeMapper.getDestination(sourceOrder);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return (DestinationCode) simpleMapper.getDestination(sourceCode);
}
}

View File

@ -0,0 +1,22 @@
package com.baeldung.performancetests.mapstruct;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface MapStructConverter extends Converter {
MapStructConverter MAPPER = Mappers.getMapper(MapStructConverter.class);
@Mapping(source = "status", target = "orderStatus")
@Override
Order convert(SourceOrder sourceOrder);
@Override
DestinationCode convert(SourceCode sourceCode);
}

View File

@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum AccountStatus {
ACTIVE, NOT_ACTIVE, BANNED
}

View File

@ -0,0 +1,83 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.util.Objects;
@JGlobalMap
public class Address {
private String street;
private String city;
private String postalCode;
public Address() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if(o.getClass() == com.baeldung.performancetests.model.source.Address.class) {
com.baeldung.performancetests.model.source.Address address =
(com.baeldung.performancetests.model.source.Address) o;
return Objects.equals(street, address.getStreet()) &&
Objects.equals(city, address.getCity()) &&
Objects.equals(postalCode, address.getPostalCode()) &&
Objects.equals(country, address.getCountry());
}
if(o.getClass() != getClass()) return false;
Address address = (Address) o;
return Objects.equals(street, address.street) &&
Objects.equals(city, address.city) &&
Objects.equals(postalCode, address.postalCode) &&
Objects.equals(country, address.country);
}
@Override
public int hashCode() {
return Objects.hash(street, city, postalCode, country);
}
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Address(String street, String city, String postalCode, String country) {
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.country = country;
}
}

View File

@ -0,0 +1,83 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
import java.util.Objects;
@JGlobalMap
public class DeliveryData {
private Address deliveryAddress;
@JMapAccessor(get = "isPrePaid", set = "setPrePaid")
private boolean isPrePaid;
private String trackingCode;
private int expectedDeliveryTimeInDays;
public DeliveryData() {
}
public Address getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(Address deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public boolean isPrePaid() {
return isPrePaid;
}
public void setPrePaid(boolean prePaid) {
isPrePaid = prePaid;
}
public String getTrackingCode() {
return trackingCode;
}
public void setTrackingCode(String trackingCode) {
this.trackingCode = trackingCode;
}
public int getExpectedDeliveryTimeInDays() {
return expectedDeliveryTimeInDays;
}
public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) {
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) {
this.deliveryAddress = deliveryAddress;
this.isPrePaid = isPrePaid;
this.trackingCode = trackingCode;
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if(o.getClass() == com.baeldung.performancetests.model.source.DeliveryData.class) {
com.baeldung.performancetests.model.source.DeliveryData deliveryData =
(com.baeldung.performancetests.model.source.DeliveryData) o;
return isPrePaid == deliveryData.isPrePaid() &&
expectedDeliveryTimeInDays == deliveryData.getExpectedDeliveryTimeInDays() &&
Objects.equals(deliveryAddress, deliveryData.getDeliveryAddress()) &&
Objects.equals(trackingCode, deliveryData.getTrackingCode());
}
if (o.getClass() != getClass()) return false;
DeliveryData that = (DeliveryData) o;
return isPrePaid == that.isPrePaid &&
expectedDeliveryTimeInDays == that.expectedDeliveryTimeInDays &&
Objects.equals(deliveryAddress, that.deliveryAddress) &&
Objects.equals(trackingCode, that.trackingCode);
}
@Override
public int hashCode() {
return Objects.hash(deliveryAddress, isPrePaid, trackingCode, expectedDeliveryTimeInDays);
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JMap;
public class DestinationCode {
@JMap
String code;
public DestinationCode(String code) {
this.code = code;
}
public DestinationCode() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

View File

@ -0,0 +1,70 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
@JGlobalMap
public class Discount {
private String startTime;
private String endTime;
private BigDecimal discountPrice;
public Discount() {
}
public String getStartTime() {
return startTime;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.Discount.class) {
com.baeldung.performancetests.model.source.Discount discount =
(com.baeldung.performancetests.model.source.Discount) o;
return Objects.equal(startTime, discount.getStartTime()) &&
Objects.equal(endTime, discount.getEndTime()) &&
Objects.equal(discountPrice, discount.getDiscountPrice());
}
if(o.getClass() != getClass()) return false;
Discount discount = (Discount) o;
return Objects.equal(startTime, discount.startTime) &&
Objects.equal(endTime, discount.endTime) &&
Objects.equal(discountPrice, discount.discountPrice);
}
@Override
public int hashCode() {
return Objects.hashCode(startTime, endTime, discountPrice);
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public BigDecimal getDiscountPrice() {
return discountPrice;
}
public void setDiscountPrice(BigDecimal discountPrice) {
this.discountPrice = discountPrice;
}
public Discount(String startTime, String endTime, BigDecimal discountPrice) {
this.startTime = startTime;
this.endTime = endTime;
this.discountPrice = discountPrice;
}
}

View File

@ -0,0 +1,210 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JMap;
import com.googlecode.jmapper.annotations.JMapConversion;
import java.util.List;
public class Order {
@JMap
private User orderingUser;
@JMap
private List<Product> orderedProducts;
@JMap("status")
private OrderStatus orderStatus;
@JMap
private String orderDate;
@JMap
private String orderFinishDate;
@JMap
private PaymentType paymentType;
@JMap
private Discount discount;
@JMap
private int orderId;
@JMap
private DeliveryData deliveryData;
@JMap
private Shop offeringShop;
public Order() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == SourceOrder.class) {
SourceOrder order =
(SourceOrder) o;
return Objects.equal(orderingUser, order.getOrderingUser()) &&
Objects.equal(orderedProducts, order.getOrderedProducts()) &&
orderStatus.ordinal() == order.getStatus().ordinal() &&
Objects.equal(orderDate, order.getOrderDate()) &&
Objects.equal(orderFinishDate, order.getOrderFinishDate()) &&
paymentType.ordinal() == order.getPaymentType().ordinal() &&
Objects.equal(discount, order.getDiscount()) &&
Objects.equal(deliveryData, order.getDeliveryData());
}
if (o.getClass() != getClass()) return false;
Order order = (Order) o;
return Objects.equal(orderingUser, order.orderingUser) &&
Objects.equal(orderedProducts, order.orderedProducts) &&
orderStatus == order.orderStatus &&
Objects.equal(orderDate, order.orderDate) &&
Objects.equal(orderFinishDate, order.orderFinishDate) &&
paymentType == order.paymentType &&
Objects.equal(discount, order.discount) &&
Objects.equal(deliveryData, order.deliveryData);
}
@Override
public int hashCode() {
return Objects.hashCode(orderingUser, orderedProducts, orderStatus, orderDate, orderFinishDate, paymentType, discount, deliveryData);
}
public User getOrderingUser() {
return orderingUser;
}
public void setOrderingUser(User orderingUser) {
this.orderingUser = orderingUser;
}
public List<Product> getOrderedProducts() {
return orderedProducts;
}
public void setOrderedProducts(List<Product> orderedProducts) {
this.orderedProducts = orderedProducts;
}
public OrderStatus getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(OrderStatus status) {
this.orderStatus = status;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getOrderFinishDate() {
return orderFinishDate;
}
public void setOrderFinishDate(String orderFinishDate) {
this.orderFinishDate = orderFinishDate;
}
public PaymentType getPaymentType() {
return paymentType;
}
public void setPaymentType(PaymentType paymentType) {
this.paymentType = paymentType;
}
public Discount getDiscount() {
return discount;
}
public void setDiscount(Discount discount) {
this.discount = discount;
}
public DeliveryData getDeliveryData() {
return deliveryData;
}
public void setDeliveryData(DeliveryData deliveryData) {
this.deliveryData = deliveryData;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public Order(User orderingUser, List<Product> orderedProducts, OrderStatus orderStatus, String orderDate, String orderFinishDate, PaymentType paymentType, Discount discount, int orderId, DeliveryData deliveryData, Shop offeringShop) {
this.orderingUser = orderingUser;
this.orderedProducts = orderedProducts;
this.orderStatus = orderStatus;
this.orderDate = orderDate;
this.orderFinishDate = orderFinishDate;
this.paymentType = paymentType;
this.discount = discount;
this.orderId = orderId;
this.deliveryData = deliveryData;
this.offeringShop = offeringShop;
}
public Shop getOfferingShop() {
return offeringShop;
}
public void setOfferingShop(Shop offeringShop) {
this.offeringShop = offeringShop;
}
@JMapConversion(from = "status", to = "orderStatus")
public OrderStatus conversion(com.baeldung.performancetests.model.source.OrderStatus status) {
OrderStatus orderStatus = null;
switch(status) {
case CREATED:
orderStatus = OrderStatus.CREATED;
break;
case FINISHED:
orderStatus = OrderStatus.FINISHED;
break;
case CONFIRMED:
orderStatus = OrderStatus.CONFIRMED;
break;
case COLLECTING:
orderStatus = OrderStatus.COLLECTING;
break;
case IN_TRANSPORT:
orderStatus = OrderStatus.IN_TRANSPORT;
break;
}
return orderStatus;
}
@JMapConversion(from = "paymentType", to = "paymentType")
public PaymentType conversion(com.baeldung.performancetests.model.source.PaymentType type) {
PaymentType paymentType = null;
switch(type) {
case CARD:
paymentType = PaymentType.CARD;
break;
case CASH:
paymentType = PaymentType.CASH;
break;
case TRANSFER:
paymentType = PaymentType.TRANSFER;
break;
}
return paymentType;
}
}

View File

@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum OrderStatus {
CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED
}

View File

@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum PaymentType {
CASH, CARD, TRANSFER
}

View File

@ -0,0 +1,107 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
@JGlobalMap
public class Product {
private BigDecimal price;
private int quantity;
public Product() {
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public RefundPolicy getRefundPolicy() {
return refundPolicy;
}
public void setRefundPolicy(RefundPolicy refundPolicy) {
this.refundPolicy = refundPolicy;
}
private String name;
public Product(BigDecimal price, int quantity, String name, String description, boolean available, RefundPolicy refundPolicy) {
this.price = price;
this.quantity = quantity;
this.name = name;
this.description = description;
this.available = available;
this.refundPolicy = refundPolicy;
}
String description;
boolean available;
private RefundPolicy refundPolicy;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.Product.class) {
com.baeldung.performancetests.model.source.Product product =
(com.baeldung.performancetests.model.source.Product) o;
return quantity == product.getQuantity() &&
available == product.isAvailable() &&
Objects.equal(price, product.getPrice()) &&
Objects.equal(name, product.getName()) &&
Objects.equal(description, product.getDescription()) &&
Objects.equal(refundPolicy, product.getRefundPolicy());
}
if(o.getClass() != getClass()) return false;
Product product = (Product) o;
return quantity == product.quantity &&
available == product.available &&
Objects.equal(price, product.price) &&
Objects.equal(name, product.name) &&
Objects.equal(description, product.description) &&
Objects.equal(refundPolicy, product.refundPolicy);
}
@Override
public int hashCode() {
return Objects.hashCode(price, quantity, name, description, available, refundPolicy);
}
}

View File

@ -0,0 +1,72 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
import java.util.List;
@JGlobalMap
public class RefundPolicy {
@JMapAccessor(get = "isRefundable", set = "setRefundable")
private boolean isRefundable;
private int refundTimeInDays;
public RefundPolicy() {
}
public boolean isRefundable() {
return isRefundable;
}
public void setRefundable(boolean refundable) {
isRefundable = refundable;
}
public int getRefundTimeInDays() {
return refundTimeInDays;
}
public void setRefundTimeInDays(int refundTimeInDays) {
this.refundTimeInDays = refundTimeInDays;
}
public List<String> getNotes() {
return notes;
}
public void setNotes(List<String> notes) {
this.notes = notes;
}
public RefundPolicy(boolean isRefundable, int refundTimeInDays, List<String> notes) {
this.isRefundable = isRefundable;
this.refundTimeInDays = refundTimeInDays;
this.notes = notes;
}
private List<String> notes;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.RefundPolicy.class) {
com.baeldung.performancetests.model.source.RefundPolicy that = (com.baeldung.performancetests.model.source.RefundPolicy) o;
return isRefundable == that.isRefundable() &&
refundTimeInDays == that.getRefundTimeInDays() &&
Objects.equal(notes, that.getNotes());
}
if (o.getClass() != getClass()) return false;
RefundPolicy that = (RefundPolicy) o;
return isRefundable == that.isRefundable &&
refundTimeInDays == that.refundTimeInDays &&
Objects.equal(notes, that.notes);
}
@Override
public int hashCode() {
return Objects.hashCode(isRefundable, refundTimeInDays, notes);
}
}

View File

@ -0,0 +1,67 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.User;
import com.googlecode.jmapper.annotations.JGlobalMap;
@JGlobalMap
public class Review {
int shippingGrade;
int pricingGrade;
int serviceGrade;
User reviewingUser;
String note;
public int getShippingGrade() {
return shippingGrade;
}
public void setShippingGrade(int shippingGrade) {
this.shippingGrade = shippingGrade;
}
public int getPricingGrade() {
return pricingGrade;
}
public void setPricingGrade(int pricingGrade) {
this.pricingGrade = pricingGrade;
}
public int getServiceGrade() {
return serviceGrade;
}
public void setServiceGrade(int serviceGrade) {
this.serviceGrade = serviceGrade;
}
public User getReviewingUser() {
return reviewingUser;
}
public void setReviewingUser(User reviewingUser) {
this.reviewingUser = reviewingUser;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Review() {
}
public Review(int shippingGrade, int pricingGrade, int serviceGrade, User reviewingUser, String note) {
this.shippingGrade = shippingGrade;
this.pricingGrade = pricingGrade;
this.serviceGrade = serviceGrade;
this.reviewingUser = reviewingUser;
this.note = note;
}
}

View File

@ -0,0 +1,57 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.Address;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.util.List;
@JGlobalMap
public class Shop {
private String shopName;
private Address shopAddres;
private String shopUrl;
private List<Review> reviews;
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public Address getShopAddres() {
return shopAddres;
}
public void setShopAddres(Address shopAddres) {
this.shopAddres = shopAddres;
}
public String getShopUrl() {
return shopUrl;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
public Shop() {
}
public List<Review> getReviews() {
return reviews;
}
public void setReviews(List<Review> reviews) {
this.reviews = reviews;
}
public Shop(String shopName, Address shopAddres, String shopUrl, List<Review> reviews) {
this.shopName = shopName;
this.shopAddres = shopAddres;
this.shopUrl = shopUrl;
this.reviews = reviews;
}
}

View File

@ -0,0 +1,87 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapConversion;
@JGlobalMap
public class User {
private String username;
private String email;
private AccountStatus userAccountStatus;
public User(String username, String email, AccountStatus userAccountStatus) {
this.username = username;
this.email = email;
this.userAccountStatus = userAccountStatus;
}
public User() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public AccountStatus getUserAccountStatus() {
return userAccountStatus;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.User.class) {
com.baeldung.performancetests.model.source.User user =
(com.baeldung.performancetests.model.source.User) o;
return Objects.equal(username, user.getUsername()) &&
Objects.equal(email, user.getEmail()) &&
userAccountStatus.ordinal() == user.getUserAccountStatus().ordinal();
}
if (o.getClass() != getClass()) return false;
User user = (User) o;
return Objects.equal(username, user.username) &&
Objects.equal(email, user.email) &&
userAccountStatus == user.userAccountStatus;
}
@Override
public int hashCode() {
return Objects.hashCode(username, email, userAccountStatus);
}
public void setUserAccountStatus(AccountStatus userAccountStatus) {
this.userAccountStatus = userAccountStatus;
}
@JMapConversion(from = "userAccountStatus", to = "userAccountStatus")
public AccountStatus conversion(com.baeldung.performancetests.model.source.AccountStatus status) {
AccountStatus accountStatus = null;
switch(status) {
case ACTIVE:
accountStatus = AccountStatus.ACTIVE;
break;
case NOT_ACTIVE:
accountStatus = AccountStatus.NOT_ACTIVE;
break;
case BANNED:
accountStatus = AccountStatus.BANNED;
break;
}
return accountStatus;
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public enum AccountStatus {
ACTIVE, NOT_ACTIVE, BANNED
}

View File

@ -0,0 +1,54 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public class Address {
private String street;
private String city;
private String postalCode;
public Address() {
}
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Address(String street, String city, String postalCode, String country) {
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.country = country;
}
}

View File

@ -0,0 +1,54 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
public class DeliveryData {
private Address deliveryAddress;
@JMapAccessor(get = "isPrePaid", set = "setPrePaid")
private boolean isPrePaid;
private String trackingCode;
private int expectedDeliveryTimeInDays;
public DeliveryData() {
}
public Address getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(Address deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public boolean isPrePaid() {
return isPrePaid;
}
public void setPrePaid(boolean prePaid) {
isPrePaid = prePaid;
}
public String getTrackingCode() {
return trackingCode;
}
public void setTrackingCode(String trackingCode) {
this.trackingCode = trackingCode;
}
public int getExpectedDeliveryTimeInDays() {
return expectedDeliveryTimeInDays;
}
public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) {
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) {
this.deliveryAddress = deliveryAddress;
this.isPrePaid = isPrePaid;
this.trackingCode = trackingCode;
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
}

View File

@ -0,0 +1,44 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
public class Discount {
private String startTime;
private String endTime;
private BigDecimal discountPrice;
public Discount() {
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public BigDecimal getDiscountPrice() {
return discountPrice;
}
public void setDiscountPrice(BigDecimal discountPrice) {
this.discountPrice = discountPrice;
}
public Discount(String startTime, String endTime, BigDecimal discountPrice) {
this.startTime = startTime;
this.endTime = endTime;
this.discountPrice = discountPrice;
}
}

View File

@ -0,0 +1,7 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public enum OrderStatus {
CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED
}

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