-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from peruzzo/master
unit tests for #70
- Loading branch information
Showing
6 changed files
with
258 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
...rnate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/InfiniteRecursionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.fasterxml.jackson.datatype.hibernate4; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.EntityManagerFactory; | ||
import javax.persistence.Persistence; | ||
|
||
import org.hibernate.Hibernate; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.datatype.hibernate4.data.Contrato; | ||
|
||
public class InfiniteRecursionTest extends BaseTest { | ||
|
||
// [Issue#70] | ||
@Test | ||
public void testInfinite() throws Exception { | ||
|
||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit"); | ||
String expected = "{\"id\":1,\"numeroContrato\":\"100001-9\",\"parcelas\":[{\"id\":1,\"numeroParcela\":1}],\"liquidacoes\":[{\"id\":1,\"valorTotal\":10000,\"parcela\":{\"id\":1,\"numeroParcela\":1}}]}"; | ||
|
||
try { | ||
EntityManager em = emf.createEntityManager(); | ||
ObjectMapper mapper = mapperWithModule(true); | ||
|
||
final Contrato contrato1 = em.find(Contrato.class, 1L); | ||
Hibernate.initialize(contrato1.getParcelas()); | ||
Hibernate.initialize(contrato1.getLiquidacoes()); | ||
assertEquals(expected, mapper.writer().writeValueAsString(contrato1)); | ||
|
||
em.clear(); | ||
|
||
final Contrato contrato2 = em.find(Contrato.class, 1L); | ||
Hibernate.initialize(contrato2.getLiquidacoes()); | ||
Hibernate.initialize(contrato2.getParcelas()); | ||
assertEquals(expected, mapper.writer().writeValueAsString(contrato2)); | ||
|
||
|
||
} finally { | ||
emf.close(); | ||
} | ||
|
||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/data/Contrato.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.fasterxml.jackson.datatype.hibernate4.data; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
import javax.persistence.Table; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@Entity @Table(name="Contrato", catalog="classicmodels") | ||
public class Contrato { | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(name="numero_contrato") | ||
private String numeroContrato; | ||
|
||
@OneToMany(mappedBy="contrato") @JsonIgnoreProperties("contrato") | ||
private List<Parcela> parcelas; | ||
|
||
@OneToMany(mappedBy="contrato") @JsonIgnoreProperties("contrato") | ||
private List<Liquidacao> liquidacoes; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getNumeroContrato() { | ||
return numeroContrato; | ||
} | ||
|
||
public void setNumeroContrato(String numeroContrato) { | ||
this.numeroContrato = numeroContrato; | ||
} | ||
|
||
public List<Parcela> getParcelas() { | ||
return parcelas; | ||
} | ||
|
||
public void setParcelas(List<Parcela> parcelas) { | ||
this.parcelas = parcelas; | ||
} | ||
|
||
public List<Liquidacao> getLiquidacoes() { | ||
return liquidacoes; | ||
} | ||
|
||
public void setLiquidacoes(List<Liquidacao> liquidacoes) { | ||
this.liquidacoes = liquidacoes; | ||
} | ||
|
||
|
||
|
||
} |
64 changes: 64 additions & 0 deletions
64
hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/data/Liquidacao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.fasterxml.jackson.datatype.hibernate4.data; | ||
|
||
import java.math.BigDecimal; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
|
||
@Entity @Table(name="Liquidacao", catalog="classicmodels") | ||
public class Liquidacao { | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(name="valor_total") | ||
private BigDecimal valorTotal; | ||
|
||
@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="contrato_id") | ||
private Contrato contrato; | ||
|
||
@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="parcela_id") @JsonIgnoreProperties("contrato") | ||
private Parcela parcela; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public BigDecimal getValorTotal() { | ||
return valorTotal; | ||
} | ||
|
||
public void setValorTotal(BigDecimal valorTotal) { | ||
this.valorTotal = valorTotal; | ||
} | ||
|
||
public Contrato getContrato() { | ||
return contrato; | ||
} | ||
|
||
public void setContrato(Contrato contrato) { | ||
this.contrato = contrato; | ||
} | ||
|
||
public Parcela getParcela() { | ||
return parcela; | ||
} | ||
|
||
public void setParcela(Parcela parcela) { | ||
this.parcela = parcela; | ||
} | ||
|
||
|
||
|
||
} |
50 changes: 50 additions & 0 deletions
50
hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/data/Parcela.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.fasterxml.jackson.datatype.hibernate4.data; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import javax.persistence.Table; | ||
|
||
@Entity @Table(name="Parcela", catalog="classicmodels") | ||
public class Parcela { | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(name="numero_parcela") | ||
private Integer numeroParcela; | ||
|
||
@ManyToOne(fetch=FetchType.LAZY) @JoinColumn(name="contrato_id") | ||
private Contrato contrato; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Integer getNumeroParcela() { | ||
return numeroParcela; | ||
} | ||
|
||
public void setNumeroParcela(Integer numeroParcela) { | ||
this.numeroParcela = numeroParcela; | ||
} | ||
|
||
public Contrato getContrato() { | ||
return contrato; | ||
} | ||
|
||
public void setContrato(Contrato contrato) { | ||
this.contrato = contrato; | ||
} | ||
|
||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters