-
Notifications
You must be signed in to change notification settings - Fork 3
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 #41 from axonivy-market/bugfix/APS-156
APS-156 added test but found no problem
- Loading branch information
Showing
6 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
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
42 changes: 42 additions & 0 deletions
42
persistence-utils-demo-test/src/com/axonivy/utils/persistence/daos/InvoiceDAO.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,42 @@ | ||
package com.axonivy.utils.persistence.daos; | ||
|
||
import javax.persistence.criteria.Expression; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.apache.logging.log4j.message.MessageFormatMessageFactory; | ||
|
||
import com.axonivy.utils.persistence.dao.CriteriaQueryContext; | ||
import com.axonivy.utils.persistence.dao.GenericIdEntityDAO; | ||
import com.axonivy.utils.persistence.entities.Invoice; | ||
import com.axonivy.utils.persistence.entities.Invoice_; | ||
|
||
public class InvoiceDAO extends GenericIdEntityDAO<Invoice_, Invoice> implements BaseDAO{ | ||
private static final Logger LOG = LogManager.getLogger(new MessageFormatMessageFactory()); | ||
private static final InvoiceDAO INSTANCE = new InvoiceDAO(); | ||
|
||
public static InvoiceDAO get() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
protected Class<Invoice> getType() { | ||
return Invoice.class; | ||
} | ||
|
||
public int countPositions(String invoiceId) { | ||
int result = 0; | ||
|
||
Invoice invoice = null; | ||
try (CriteriaQueryContext<Invoice> ctx = initializeQuery()) { | ||
Expression<String> idExpr = getExpression(null, ctx.r, Invoice_.id); | ||
ctx.whereEq(idExpr, invoiceId); | ||
invoice = forceSingleResult(findByCriteria(ctx)); | ||
// Do we have a session here? | ||
LOG.info("Found invoice position: {0}", invoice.getPositions().get(0).getDescription()); | ||
result = invoice.getPositions().size(); | ||
} | ||
return result; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
persistence-utils-demo-test/src/com/axonivy/utils/persistence/entities/Invoice.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,41 @@ | ||
package com.axonivy.utils.persistence.entities; | ||
|
||
import java.util.List; | ||
|
||
import javax.persistence.CascadeType; | ||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.OneToMany; | ||
|
||
import com.axonivy.utils.persistence.beans.GenericIdEntity; | ||
|
||
@Entity | ||
public class Invoice extends GenericIdEntity { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Column | ||
private String name; | ||
|
||
@OneToMany(mappedBy = "invoice", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) | ||
private List<InvoicePosition> positions; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public List<InvoicePosition> getPositions() { | ||
return positions; | ||
} | ||
|
||
public void setPositions(List<InvoicePosition> positions) { | ||
this.positions = positions; | ||
} | ||
|
||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
persistence-utils-demo-test/src/com/axonivy/utils/persistence/entities/InvoicePosition.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,31 @@ | ||
package com.axonivy.utils.persistence.entities; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.ManyToOne; | ||
|
||
import com.axonivy.utils.persistence.beans.GenericIdEntity; | ||
|
||
@Entity | ||
public class InvoicePosition extends GenericIdEntity { | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Column | ||
private String description; | ||
|
||
@ManyToOne | ||
private Invoice invoice; | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
public Invoice getInvoice() { | ||
return invoice; | ||
} | ||
public void setInvoice(Invoice invoice) { | ||
this.invoice = invoice; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
persistence-utils-demo-test/src_test/com/axonivy/utils/persistence/test/dao/Aps156Test.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,47 @@ | ||
package com.axonivy.utils.persistence.test.dao; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.axonivy.utils.persistence.daos.InvoiceDAO; | ||
import com.axonivy.utils.persistence.entities.Invoice; | ||
import com.axonivy.utils.persistence.entities.InvoicePosition; | ||
|
||
import ch.ivyteam.ivy.environment.IvyTest; | ||
|
||
@IvyTest | ||
public class Aps156Test { | ||
|
||
private Invoice invoice; | ||
|
||
@BeforeEach | ||
public void prepare() { | ||
invoice = new Invoice(); | ||
invoice.setName("Invoice 1"); | ||
|
||
ArrayList<InvoicePosition> positions = new ArrayList<>(); | ||
|
||
InvoicePosition ip1 = new InvoicePosition(); | ||
ip1.setDescription("Invoice Position 1"); | ||
ip1.setInvoice(invoice); | ||
positions.add(ip1); | ||
|
||
invoice.setPositions(positions); | ||
|
||
invoice = InvoiceDAO.get().save(invoice); | ||
} | ||
|
||
@Test | ||
public void test1() { | ||
assertThat(invoice).as("Prepared test").isNotNull(); | ||
|
||
int count = InvoiceDAO.get().countPositions(invoice.getId()); | ||
|
||
assertThat(count).as("Found one").isEqualTo(1); | ||
} | ||
} | ||
|
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