cleanup work
This commit is contained in:
parent
e83b4b8523
commit
81da6c5c63
|
@ -1,59 +1,58 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>dozer-tutorial</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>Dozer</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>dozer-tutorial</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<name>dozer</name>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>7</source>
|
||||
<target>7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.2.1</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.7.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>net.sf.dozer</groupId>
|
||||
<artifactId>dozer</artifactId>
|
||||
<version>5.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.2.1</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>net.sf.dozer</groupId>
|
||||
<artifactId>dozer</artifactId>
|
||||
<version>5.5.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -1,33 +1,33 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Dest {
|
||||
private String name;
|
||||
private int age;
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Dest() {
|
||||
public Dest() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dest(String name, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
public Dest(String name, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Dest2 {
|
||||
private int id;
|
||||
private int points;
|
||||
private int id;
|
||||
private int points;
|
||||
|
||||
public Dest2() {
|
||||
public Dest2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Dest2(int id, int points) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.points = points;
|
||||
}
|
||||
public Dest2(int id, int points) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
public int getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(int points) {
|
||||
this.points = points;
|
||||
}
|
||||
public void setPoints(int points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dest2 [id=" + id + ", points=" + points + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dest2 [id=" + id + ", points=" + points + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,39 +10,35 @@ import org.dozer.MappingException;
|
|||
|
||||
public class MyCustomConvertor implements CustomConverter {
|
||||
|
||||
@Override
|
||||
public Object convert(Object dest, Object source, Class<?> arg2,
|
||||
Class<?> arg3) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
if (source instanceof Personne3) {
|
||||
Personne3 person = (Personne3) source;
|
||||
Date date = new Date(person.getDtob());
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
String isoDate = format.format(date);
|
||||
return new Person3(person.getName(), isoDate);
|
||||
@Override
|
||||
public Object convert(Object dest, Object source, Class<?> arg2, Class<?> arg3) {
|
||||
if (source == null) {
|
||||
return null;
|
||||
}
|
||||
if (source instanceof Personne3) {
|
||||
Personne3 person = (Personne3) source;
|
||||
Date date = new Date(person.getDtob());
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
String isoDate = format.format(date);
|
||||
return new Person3(person.getName(), isoDate);
|
||||
|
||||
} else if (source instanceof Person3) {
|
||||
Person3 person = (Person3) source;
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
Date date = null;
|
||||
try {
|
||||
date = format.parse(person.getDtob());
|
||||
} else if (source instanceof Person3) {
|
||||
Person3 person = (Person3) source;
|
||||
DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
|
||||
Date date = null;
|
||||
try {
|
||||
date = format.parse(person.getDtob());
|
||||
|
||||
} catch (ParseException e) {
|
||||
throw new MappingException("Converter MyCustomConvertor "
|
||||
+ "used incorrectly:" + e.getMessage());
|
||||
}
|
||||
long timestamp = date.getTime();
|
||||
return new Personne3(person.getName(), timestamp);
|
||||
} catch (ParseException e) {
|
||||
throw new MappingException("Converter MyCustomConvertor " + "used incorrectly:" + e.getMessage());
|
||||
}
|
||||
long timestamp = date.getTime();
|
||||
return new Personne3(person.getName(), timestamp);
|
||||
|
||||
} else {
|
||||
throw new MappingException("Converter MyCustomConvertor "
|
||||
+ "used incorrectly. Arguments passed in were:" + dest
|
||||
+ " and " + source);
|
||||
} else {
|
||||
throw new MappingException("Converter MyCustomConvertor " + "used incorrectly. Arguments passed in were:" + dest + " and " + source);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private String nickname;
|
||||
private int age;
|
||||
private String name;
|
||||
private String nickname;
|
||||
private int age;
|
||||
|
||||
public Person() {
|
||||
public Person() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Person(String name, String nickname, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.nickname = nickname;
|
||||
this.age = age;
|
||||
}
|
||||
public Person(String name, String nickname, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.nickname = nickname;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Person2 {
|
||||
private String name;
|
||||
private String nickname;
|
||||
private int age;
|
||||
private String name;
|
||||
private String nickname;
|
||||
private int age;
|
||||
|
||||
public Person2() {
|
||||
public Person2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Person2(String name, String nickname, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.nickname = nickname;
|
||||
this.age = age;
|
||||
}
|
||||
public Person2(String name, String nickname, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.nickname = nickname;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
public String getNickname() {
|
||||
return nickname;
|
||||
}
|
||||
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
public void setNickname(String nickname) {
|
||||
this.nickname = nickname;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,39 +1,38 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Person3 {
|
||||
private String name;
|
||||
private String dtob;
|
||||
private String name;
|
||||
private String dtob;
|
||||
|
||||
public Person3() {
|
||||
public Person3() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Person3(String name, String dtob) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.dtob = dtob;
|
||||
}
|
||||
public Person3(String name, String dtob) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.dtob = dtob;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDtob() {
|
||||
return dtob;
|
||||
}
|
||||
public String getDtob() {
|
||||
return dtob;
|
||||
}
|
||||
|
||||
public void setDtob(String dtob) {
|
||||
this.dtob = dtob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person3 [name=" + name + ", dtob=" + dtob + "]";
|
||||
}
|
||||
public void setDtob(String dtob) {
|
||||
this.dtob = dtob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person3 [name=" + name + ", dtob=" + dtob + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,43 +1,43 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Personne {
|
||||
private String nom;
|
||||
private String surnom;
|
||||
private int age;
|
||||
private String nom;
|
||||
private String surnom;
|
||||
private int age;
|
||||
|
||||
public Personne() {
|
||||
public Personne() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Personne(String nom, String surnom, int age) {
|
||||
super();
|
||||
this.nom = nom;
|
||||
this.surnom = surnom;
|
||||
this.age = age;
|
||||
}
|
||||
public Personne(String nom, String surnom, int age) {
|
||||
super();
|
||||
this.nom = nom;
|
||||
this.surnom = surnom;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public String getSurnom() {
|
||||
return surnom;
|
||||
}
|
||||
public String getSurnom() {
|
||||
return surnom;
|
||||
}
|
||||
|
||||
public void setSurnom(String surnom) {
|
||||
this.surnom = surnom;
|
||||
}
|
||||
public void setSurnom(String surnom) {
|
||||
this.surnom = surnom;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,45 +3,45 @@ package com.baeldung.dozer;
|
|||
import org.dozer.Mapping;
|
||||
|
||||
public class Personne2 {
|
||||
private String nom;
|
||||
private String surnom;
|
||||
private int age;
|
||||
private String nom;
|
||||
private String surnom;
|
||||
private int age;
|
||||
|
||||
public Personne2() {
|
||||
public Personne2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Personne2(String nom, String surnom, int age) {
|
||||
super();
|
||||
this.nom = nom;
|
||||
this.surnom = surnom;
|
||||
this.age = age;
|
||||
}
|
||||
public Personne2(String nom, String surnom, int age) {
|
||||
super();
|
||||
this.nom = nom;
|
||||
this.surnom = surnom;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
@Mapping("name")
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
@Mapping("name")
|
||||
public String getNom() {
|
||||
return nom;
|
||||
}
|
||||
|
||||
@Mapping("nickname")
|
||||
public String getSurnom() {
|
||||
return surnom;
|
||||
}
|
||||
@Mapping("nickname")
|
||||
public String getSurnom() {
|
||||
return surnom;
|
||||
}
|
||||
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
public void setNom(String nom) {
|
||||
this.nom = nom;
|
||||
}
|
||||
|
||||
public void setSurnom(String surnom) {
|
||||
this.surnom = surnom;
|
||||
}
|
||||
public void setSurnom(String surnom) {
|
||||
this.surnom = surnom;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Personne3 {
|
||||
private String name;
|
||||
private long dtob;
|
||||
private String name;
|
||||
private long dtob;
|
||||
|
||||
public Personne3() {
|
||||
public Personne3() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Personne3(String name, long dtob) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.dtob = dtob;
|
||||
}
|
||||
public Personne3(String name, long dtob) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.dtob = dtob;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getDtob() {
|
||||
return dtob;
|
||||
}
|
||||
public long getDtob() {
|
||||
return dtob;
|
||||
}
|
||||
|
||||
public void setDtob(long dtob) {
|
||||
this.dtob = dtob;
|
||||
}
|
||||
public void setDtob(long dtob) {
|
||||
this.dtob = dtob;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Personne3 [name=" + name + ", dtob=" + dtob + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Personne3 [name=" + name + ", dtob=" + dtob + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,32 +1,32 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Source {
|
||||
private String name;
|
||||
private int age;
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Source() {
|
||||
}
|
||||
public Source() {
|
||||
}
|
||||
|
||||
public Source(String name, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
public Source(String name, int age) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,38 +1,38 @@
|
|||
package com.baeldung.dozer;
|
||||
|
||||
public class Source2 {
|
||||
private String id;
|
||||
private double points;
|
||||
private String id;
|
||||
private double points;
|
||||
|
||||
public Source2() {
|
||||
public Source2() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Source2(String id, double points) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.points = points;
|
||||
}
|
||||
public Source2(String id, double points) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public double getPoints() {
|
||||
return points;
|
||||
}
|
||||
public double getPoints() {
|
||||
return points;
|
||||
}
|
||||
|
||||
public void setPoints(double points) {
|
||||
this.points = points;
|
||||
}
|
||||
public void setPoints(double points) {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Source2 [id=" + id + ", points=" + points + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Source2 [id=" + id + ", points=" + points + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,208 +12,188 @@ import org.junit.Ignore;
|
|||
import org.junit.Test;
|
||||
|
||||
public class DozerTest {
|
||||
private final long GMT_DIFFERENCE = 46800000;
|
||||
private final long GMT_DIFFERENCE = 46800000;
|
||||
|
||||
DozerBeanMapper mapper;
|
||||
DozerBeanMapper mapper;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
mapper = new DozerBeanMapper();
|
||||
}
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
mapper = new DozerBeanMapper();
|
||||
}
|
||||
|
||||
BeanMappingBuilder builder = new BeanMappingBuilder() {
|
||||
BeanMappingBuilder builder = new BeanMappingBuilder() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
mapping(Person.class, Personne.class).fields("name", "nom").fields(
|
||||
"nickname", "surnom");
|
||||
@Override
|
||||
protected void configure() {
|
||||
mapping(Person.class, Personne.class).fields("name", "nom").fields("nickname", "surnom");
|
||||
|
||||
}
|
||||
};
|
||||
BeanMappingBuilder builderMinusAge = new BeanMappingBuilder() {
|
||||
}
|
||||
};
|
||||
BeanMappingBuilder builderMinusAge = new BeanMappingBuilder() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
mapping(Person.class, Personne.class).fields("name", "nom")
|
||||
.fields("nickname", "surnom").exclude("age");
|
||||
@Override
|
||||
protected void configure() {
|
||||
mapping(Person.class, Personne.class).fields("name", "nom").fields("nickname", "surnom").exclude("age");
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@Test
|
||||
public void givenApiMapper_whenMaps_thenCorrect() {
|
||||
mapper.addMapping(builder);
|
||||
@Test
|
||||
public void givenApiMapper_whenMaps_thenCorrect() {
|
||||
mapper.addMapping(builder);
|
||||
|
||||
Personne frenchAppPerson = new Personne("Sylvester Stallone", "Rambo",
|
||||
70);
|
||||
Person englishAppPerson = mapper.map(frenchAppPerson, Person.class);
|
||||
Personne frenchAppPerson = new Personne("Sylvester Stallone", "Rambo", 70);
|
||||
Person englishAppPerson = mapper.map(frenchAppPerson, Person.class);
|
||||
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(),
|
||||
frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(), frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenApiMapper_whenMapsOnlySpecifiedFields_thenCorrect() {
|
||||
mapper.addMapping(builderMinusAge);
|
||||
@Test
|
||||
public void givenApiMapper_whenMapsOnlySpecifiedFields_thenCorrect() {
|
||||
mapper.addMapping(builderMinusAge);
|
||||
|
||||
Person englishAppPerson = new Person("Sylvester Stallone", "Rambo", 70);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
Person englishAppPerson = new Person("Sylvester Stallone", "Rambo", 70);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), 0);
|
||||
}
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenApiMapper_whenMapsBidirectionally_thenCorrect() {
|
||||
mapper.addMapping(builder);
|
||||
@Test
|
||||
public void givenApiMapper_whenMapsBidirectionally_thenCorrect() {
|
||||
mapper.addMapping(builder);
|
||||
|
||||
Person englishAppPerson = new Person("Sylvester Stallone", "Rambo", 70);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
Person englishAppPerson = new Person("Sylvester Stallone", "Rambo", 70);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSourceObjectAndDestClass_whenMapsSameNameFieldsCorrectly_thenCorrect() {
|
||||
Source source = new Source("Baeldung", 10);
|
||||
Dest dest = mapper.map(source, Dest.class);
|
||||
assertEquals(dest.getName(), "Baeldung");
|
||||
assertEquals(dest.getAge(), 10);
|
||||
}
|
||||
@Test
|
||||
public void givenSourceObjectAndDestClass_whenMapsSameNameFieldsCorrectly_thenCorrect() {
|
||||
Source source = new Source("Baeldung", 10);
|
||||
Dest dest = mapper.map(source, Dest.class);
|
||||
assertEquals(dest.getName(), "Baeldung");
|
||||
assertEquals(dest.getAge(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSourceObjectAndDestObject_whenMapsSameNameFieldsCorrectly_thenCorrect() {
|
||||
Source source = new Source("Baeldung", 10);
|
||||
Dest dest = new Dest();
|
||||
mapper.map(source, dest);
|
||||
assertEquals(dest.getName(), "Baeldung");
|
||||
assertEquals(dest.getAge(), 10);
|
||||
}
|
||||
@Test
|
||||
public void givenSourceObjectAndDestObject_whenMapsSameNameFieldsCorrectly_thenCorrect() {
|
||||
Source source = new Source("Baeldung", 10);
|
||||
Dest dest = new Dest();
|
||||
mapper.map(source, dest);
|
||||
assertEquals(dest.getName(), "Baeldung");
|
||||
assertEquals(dest.getAge(), 10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSourceAndDestWithDifferentFieldTypes_whenMapsAndAutoConverts_thenCorrect() {
|
||||
Source2 source = new Source2("320", 15.2);
|
||||
Dest2 dest = mapper.map(source, Dest2.class);
|
||||
assertEquals(dest.getId(), 320);
|
||||
assertEquals(dest.getPoints(), 15);
|
||||
}
|
||||
@Test
|
||||
public void givenSourceAndDestWithDifferentFieldTypes_whenMapsAndAutoConverts_thenCorrect() {
|
||||
Source2 source = new Source2("320", 15.2);
|
||||
Dest2 dest = mapper.map(source, Dest2.class);
|
||||
assertEquals(dest.getId(), 320);
|
||||
assertEquals(dest.getPoints(), 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldNamesWithCustomMapper_whenMaps_thenCorrect() {
|
||||
configureMapper("dozer_mapping.xml");
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldNamesWithCustomMapper_whenMaps_thenCorrect() {
|
||||
configureMapper("dozer_mapping.xml");
|
||||
|
||||
Personne frenchAppPerson = new Personne("Sylvester Stallone", "Rambo",
|
||||
70);
|
||||
Person englishAppPerson = mapper.map(frenchAppPerson, Person.class);
|
||||
Personne frenchAppPerson = new Personne("Sylvester Stallone", "Rambo", 70);
|
||||
Person englishAppPerson = mapper.map(frenchAppPerson, Person.class);
|
||||
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(),
|
||||
frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(), frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldNamesWithCustomMapper_whenMapsBidirectionally_thenCorrect() {
|
||||
configureMapper("dozer_mapping.xml");
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldNamesWithCustomMapper_whenMapsBidirectionally_thenCorrect() {
|
||||
configureMapper("dozer_mapping.xml");
|
||||
|
||||
Person englishAppPerson = new Person("Dwayne Johnson", "The Rock", 44);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
Person englishAppPerson = new Person("Dwayne Johnson", "The Rock", 44);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Ignore("place dozer_mapping.xml at a location of your choice and copy/paste the path after file: in configureMapper method")
|
||||
@Test
|
||||
public void givenMappingFileOutsideClasspath_whenMaps_thenCorrect() {
|
||||
configureMapper("file:e:/dozer_mapping.xml");
|
||||
@Ignore("place dozer_mapping.xml at a location of your choice and copy/paste the path after file: in configureMapper method")
|
||||
@Test
|
||||
public void givenMappingFileOutsideClasspath_whenMaps_thenCorrect() {
|
||||
configureMapper("file:e:/dozer_mapping.xml");
|
||||
|
||||
Person englishAppPerson = new Person("Marshall Bruce Mathers III",
|
||||
"Eminem", 43);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
Person englishAppPerson = new Person("Marshall Bruce Mathers III", "Eminem", 43);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSrcAndDest_whenMapsOnlySpecifiedFields_thenCorrect() {
|
||||
configureMapper("dozer_mapping2.xml");
|
||||
@Test
|
||||
public void givenSrcAndDest_whenMapsOnlySpecifiedFields_thenCorrect() {
|
||||
configureMapper("dozer_mapping2.xml");
|
||||
|
||||
Person englishAppPerson = new Person("Shawn Corey Carter", "Jay Z", 46);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
Person englishAppPerson = new Person("Shawn Corey Carter", "Jay Z", 46);
|
||||
Personne frenchAppPerson = mapper.map(englishAppPerson, Personne.class);
|
||||
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), 0);
|
||||
}
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnnotatedSrcFields_whenMapsToRightDestField_thenCorrect() {
|
||||
Person2 englishAppPerson = new Person2("Jean-Claude Van Damme", "JCVD",
|
||||
55);
|
||||
Personne2 frenchAppPerson = mapper.map(englishAppPerson,
|
||||
Personne2.class);
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(),
|
||||
englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
@Test
|
||||
public void givenAnnotatedSrcFields_whenMapsToRightDestField_thenCorrect() {
|
||||
Person2 englishAppPerson = new Person2("Jean-Claude Van Damme", "JCVD", 55);
|
||||
Personne2 frenchAppPerson = mapper.map(englishAppPerson, Personne2.class);
|
||||
assertEquals(frenchAppPerson.getNom(), englishAppPerson.getName());
|
||||
assertEquals(frenchAppPerson.getSurnom(), englishAppPerson.getNickname());
|
||||
assertEquals(frenchAppPerson.getAge(), englishAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAnnotatedSrcFields_whenMapsToRightDestFieldBidirectionally_thenCorrect() {
|
||||
Personne2 frenchAppPerson = new Personne2("Jason Statham",
|
||||
"transporter", 49);
|
||||
Person2 englishAppPerson = mapper.map(frenchAppPerson, Person2.class);
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(),
|
||||
frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
@Test
|
||||
public void givenAnnotatedSrcFields_whenMapsToRightDestFieldBidirectionally_thenCorrect() {
|
||||
Personne2 frenchAppPerson = new Personne2("Jason Statham", "transporter", 49);
|
||||
Person2 englishAppPerson = mapper.map(frenchAppPerson, Person2.class);
|
||||
assertEquals(englishAppPerson.getName(), frenchAppPerson.getNom());
|
||||
assertEquals(englishAppPerson.getNickname(), frenchAppPerson.getSurnom());
|
||||
assertEquals(englishAppPerson.getAge(), frenchAppPerson.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvert_thenCorrect() {
|
||||
configureMapper("dozer_custom_convertor.xml");
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvert_thenCorrect() {
|
||||
configureMapper("dozer_custom_convertor.xml");
|
||||
|
||||
String dateTime = "2007-06-26T21:22:39Z";
|
||||
long timestamp = new Long("1182882159000");
|
||||
String dateTime = "2007-06-26T21:22:39Z";
|
||||
long timestamp = new Long("1182882159000");
|
||||
|
||||
Person3 person = new Person3("Rich", dateTime);
|
||||
Personne3 person0 = mapper.map(person, Personne3.class);
|
||||
Person3 person = new Person3("Rich", dateTime);
|
||||
Personne3 person0 = mapper.map(person, Personne3.class);
|
||||
|
||||
long timestampToTest = person0.getDtob();
|
||||
assertTrue(timestampToTest == timestamp
|
||||
|| timestampToTest >= timestamp - GMT_DIFFERENCE
|
||||
|| timestampToTest <= timestamp + GMT_DIFFERENCE);
|
||||
}
|
||||
long timestampToTest = person0.getDtob();
|
||||
assertTrue(timestampToTest == timestamp || timestampToTest >= timestamp - GMT_DIFFERENCE || timestampToTest <= timestamp + GMT_DIFFERENCE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvertBidirectionally_thenCorrect() {
|
||||
long timestamp = new Long("1182882159000");
|
||||
Personne3 person = new Personne3("Rich", timestamp);
|
||||
configureMapper("dozer_custom_convertor.xml");
|
||||
@Test
|
||||
public void givenSrcAndDestWithDifferentFieldTypes_whenAbleToCustomConvertBidirectionally_thenCorrect() {
|
||||
long timestamp = new Long("1182882159000");
|
||||
Personne3 person = new Personne3("Rich", timestamp);
|
||||
configureMapper("dozer_custom_convertor.xml");
|
||||
|
||||
Person3 person0 = mapper.map(person, Person3.class);
|
||||
String timestampTest = person0.getDtob();
|
||||
Person3 person0 = mapper.map(person, Person3.class);
|
||||
String timestampTest = person0.getDtob();
|
||||
|
||||
assertTrue(timestampTest.charAt(10) == 'T'
|
||||
&& timestampTest.charAt(19) == 'Z');
|
||||
}
|
||||
assertTrue(timestampTest.charAt(10) == 'T' && timestampTest.charAt(19) == 'Z');
|
||||
}
|
||||
|
||||
public void configureMapper(String... mappingFileUrls) {
|
||||
mapper.setMappingFiles(Arrays.asList(mappingFileUrls));
|
||||
}
|
||||
public void configureMapper(String... mappingFileUrls) {
|
||||
mapper.setMappingFiles(Arrays.asList(mappingFileUrls));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,13 +4,11 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.boot.test.IntegrationTest;
|
||||
import org.springframework.boot.test.SpringApplicationContextLoader;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.client.ClientHttpResponse;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.web.client.ResponseErrorHandler;
|
||||
import org.springframework.web.client.ResponseExtractor;
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package com.baeldung;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import cucumber.api.java.en.And;
|
||||
import cucumber.api.java.en.Then;
|
||||
import cucumber.api.java.en.When;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class StepDefs extends SpringIntegrationTest {
|
||||
|
||||
|
|
Loading…
Reference in New Issue