From 88005dbe092f927312bd366b925dba1666ed3330 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Fri, 25 Mar 2022 18:44:24 +1300 Subject: [PATCH] Refactor tests, move changelog tests --- .../changelog/ChangeJsonBuilderTest.java | 5 +- .../DefaultChangeLogRegisterTest.java | 11 +- .../server/changelog/Helper.java | 0 .../inheritance/model/AbstractBaseClass.java | 16 ++ .../inheritance/model/CalculationResult.java | 51 ++++ .../inheritance/model/Configuration.java | 43 +++ .../inheritance/model/Configurations.java | 64 +++++ .../inheritance/model/GroupConfiguration.java | 40 +++ .../model/ProductConfiguration.java | 35 +++ .../java/org/tests/model/basic/Address.java | 147 ++++++++++ .../org/tests/model/basic/BasicDomain.java | 60 +++++ .../java/org/tests/model/basic/Contact.java | 151 +++++++++++ .../org/tests/model/basic/ContactGroup.java | 20 ++ .../org/tests/model/basic/ContactNote.java | 51 ++++ .../java/org/tests/model/basic/Country.java | 63 +++++ .../java/org/tests/model/basic/Customer.java | 209 ++++++++++++++- .../java/org/tests/model/basic/Order.java | 252 ++++++++++++++++++ .../org/tests/model/basic/OrderDetail.java | 157 +++++++++++ .../java/org/tests/model/basic/Product.java | 112 ++++++++ .../DefaultChangeLogListenerTest.java | 26 -- 20 files changed, 1476 insertions(+), 37 deletions(-) rename {ebean-test => ebean-core}/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java (87%) rename {ebean-test => ebean-core}/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java (92%) rename {ebean-test => ebean-core}/src/test/java/io/ebeaninternal/server/changelog/Helper.java (100%) create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/AbstractBaseClass.java create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/CalculationResult.java create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/Configuration.java create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/Configurations.java create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/GroupConfiguration.java create mode 100644 ebean-core/src/test/java/org/tests/inheritance/model/ProductConfiguration.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/Address.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/BasicDomain.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/ContactGroup.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/ContactNote.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/Country.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/Order.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/OrderDetail.java create mode 100644 ebean-core/src/test/java/org/tests/model/basic/Product.java delete mode 100644 ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogListenerTest.java diff --git a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java similarity index 87% rename from ebean-test/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java rename to ebean-core/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java index 88828f78b..5a8bf1537 100644 --- a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/changelog/ChangeJsonBuilderTest.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.changelog; -import io.ebean.xtest.BaseTestCase; import io.ebean.event.changelog.BeanChange; import io.ebean.event.changelog.ChangeSet; import org.junit.jupiter.api.Test; @@ -11,12 +10,12 @@ import java.util.List; import static org.assertj.core.api.Assertions.assertThat; -public class ChangeJsonBuilderTest extends BaseTestCase { +class ChangeJsonBuilderTest { Helper helper = new Helper(); @Test - public void testToJson() throws Exception { + void testToJson() throws Exception { ChangeJsonBuilder builder = new ChangeJsonBuilder(); diff --git a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java b/ebean-core/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java similarity index 92% rename from ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java rename to ebean-core/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java index c1b1536ad..8924ac803 100644 --- a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java +++ b/ebean-core/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogRegisterTest.java @@ -1,6 +1,5 @@ package io.ebeaninternal.server.changelog; -import io.ebean.xtest.BaseTestCase; import io.ebean.event.changelog.ChangeLogFilter; import org.junit.jupiter.api.Test; import org.tests.inheritance.model.ProductConfiguration; @@ -12,11 +11,10 @@ import org.tests.model.basic.Customer; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; -public class DefaultChangeLogRegisterTest extends BaseTestCase { - +class DefaultChangeLogRegisterTest { @Test - public void test_defaultInsertTrue() { + void test_defaultInsertTrue() { DefaultChangeLogRegister register = new DefaultChangeLogRegister(true); @@ -39,7 +37,7 @@ public class DefaultChangeLogRegisterTest extends BaseTestCase { } @Test - public void test_defaultInsertFalse() { + void test_defaultInsertFalse() { DefaultChangeLogRegister register = new DefaultChangeLogRegister(false); @@ -62,8 +60,7 @@ public class DefaultChangeLogRegisterTest extends BaseTestCase { } @Test - public void test_inheritance() { - + void test_inheritance() { DefaultChangeLogRegister register = new DefaultChangeLogRegister(true); ChangeLogFilter changeFilter = register.getChangeFilter(ProductConfiguration.class); assertNotNull(changeFilter); diff --git a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/Helper.java b/ebean-core/src/test/java/io/ebeaninternal/server/changelog/Helper.java similarity index 100% rename from ebean-test/src/test/java/io/ebeaninternal/server/changelog/Helper.java rename to ebean-core/src/test/java/io/ebeaninternal/server/changelog/Helper.java diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/AbstractBaseClass.java b/ebean-core/src/test/java/org/tests/inheritance/model/AbstractBaseClass.java new file mode 100644 index 000000000..ae914d0c7 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/AbstractBaseClass.java @@ -0,0 +1,16 @@ +package org.tests.inheritance.model; + +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class AbstractBaseClass { + private String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/CalculationResult.java b/ebean-core/src/test/java/org/tests/inheritance/model/CalculationResult.java new file mode 100644 index 000000000..6d315b65a --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/CalculationResult.java @@ -0,0 +1,51 @@ +package org.tests.inheritance.model; + +import javax.persistence.*; + +@Entity +public class CalculationResult { + + @Id + @Column(name = "id") + private Integer id; + + private double charge; + + @ManyToOne(cascade = CascadeType.PERSIST) + private ProductConfiguration productConfiguration; + + @ManyToOne(cascade = CascadeType.PERSIST) + private GroupConfiguration groupConfiguration; + + public double getCharge() { + return charge; + } + + public void setCharge(double charge) { + this.charge = charge; + } + + public ProductConfiguration getProductConfiguration() { + return productConfiguration; + } + + public void setProductConfiguration(ProductConfiguration productConfiguration) { + this.productConfiguration = productConfiguration; + } + + public GroupConfiguration getGroupConfiguration() { + return groupConfiguration; + } + + public void setGroupConfiguration(GroupConfiguration groupConfiguration) { + this.groupConfiguration = groupConfiguration; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } +} diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/Configuration.java b/ebean-core/src/test/java/org/tests/inheritance/model/Configuration.java new file mode 100644 index 000000000..c58afe6c1 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/Configuration.java @@ -0,0 +1,43 @@ +package org.tests.inheritance.model; + +import io.ebean.annotation.Cache; +import io.ebean.annotation.ChangeLog; + +import javax.persistence.*; + +@ChangeLog +@Entity +@Cache(enableQueryCache = true) +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING, columnDefinition = "varchar(21)") +public class Configuration extends AbstractBaseClass { + + @Id + @Column(name = "id") + private Integer id; + + + @ManyToOne + private Configurations configurations; + + + public Configuration() { + super(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Configurations getConfigurations() { + return configurations; + } + + public void setConfigurations(Configurations configurations) { + this.configurations = configurations; + } +} diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/Configurations.java b/ebean-core/src/test/java/org/tests/inheritance/model/Configurations.java new file mode 100644 index 000000000..7afed20a6 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/Configurations.java @@ -0,0 +1,64 @@ +package org.tests.inheritance.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.List; + +@Entity +public class Configurations { + @Id + @Column(name = "id") + private Integer id; + + private String name; + + @OneToMany + private List groupConfigurations; + + @OneToMany + private List productConfigurations; + + 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; + } + + public List getGroupConfigurations() { + return groupConfigurations; + } + + public void setGroupConfigurations(List groupConfigurations) { + this.groupConfigurations = groupConfigurations; + } + + public void addGroupConfiguration(GroupConfiguration groupConfiguration) { + groupConfiguration.setConfigurations(this); + groupConfigurations.add(groupConfiguration); + } + + public List getProductConfigurations() { + return productConfigurations; + } + + public void setProductConfigurations(List productConfigurations) { + this.productConfigurations = productConfigurations; + } + + public void addProductConfiguration(ProductConfiguration productConfiguration) { + productConfiguration.setConfigurations(this); + productConfigurations.add(productConfiguration); + } +} diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/GroupConfiguration.java b/ebean-core/src/test/java/org/tests/inheritance/model/GroupConfiguration.java new file mode 100644 index 000000000..e1b90aef4 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/GroupConfiguration.java @@ -0,0 +1,40 @@ +package org.tests.inheritance.model; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import java.util.List; + +@Entity +@DiscriminatorValue("2") +public class GroupConfiguration extends Configuration { + private String groupName; + + @OneToMany(mappedBy = "groupConfiguration") + private List results; + + public GroupConfiguration() { + super(); + } + + public GroupConfiguration(String name) { + super(); + this.groupName = name; + } + + public String getGroupName() { + return groupName; + } + + public void setGroupName(String groupName) { + this.groupName = groupName; + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/ebean-core/src/test/java/org/tests/inheritance/model/ProductConfiguration.java b/ebean-core/src/test/java/org/tests/inheritance/model/ProductConfiguration.java new file mode 100644 index 000000000..3ff22d7bb --- /dev/null +++ b/ebean-core/src/test/java/org/tests/inheritance/model/ProductConfiguration.java @@ -0,0 +1,35 @@ +package org.tests.inheritance.model; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; +import javax.persistence.OneToMany; +import java.util.List; + +@Entity +@DiscriminatorValue("1") +public class ProductConfiguration extends Configuration { + private String productName; + + @OneToMany(mappedBy = "productConfiguration") + private List results; + + public ProductConfiguration() { + super(); + } + + public String getProductName() { + return productName; + } + + public void setProductName(String productName) { + this.productName = productName; + } + + public List getResults() { + return results; + } + + public void setResults(List results) { + this.results = results; + } +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Address.java b/ebean-core/src/test/java/org/tests/model/basic/Address.java new file mode 100644 index 000000000..632cb4efc --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/Address.java @@ -0,0 +1,147 @@ +package org.tests.model.basic; + +import io.ebean.annotation.InvalidateQueryCache; + +import javax.persistence.*; +import javax.validation.constraints.Size; +import java.sql.Timestamp; + +/** + * Address entity bean. + */ +// Address is not L2 cached directly but it is joined to queries that are cached +// What InvalidateQueryCache means is that we propagate a table modification event +// when address is changed ... and cached queries that join to address will be +// invalidated accordingly. +@InvalidateQueryCache +@Entity +@Table(name = "o_address") +public class Address { + + @Id + Integer id; + + @Size(max = 100) + @Column(name = "line_1") + String line1; + + //@SizeMedium + @Column(name = "line_2") + String line2; + + //@SizeMedium + String city; + + Timestamp cretime; + + @Version + Timestamp updtime; + + @ManyToOne + Country country; + + + @Override + public String toString() { + return id + " " + line1 + " " + line2 + " " + city + " " + country; + } + + /** + * Return id. + */ + public Integer getId() { + return id; + } + + /** + * Set id. + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Return line 1. + */ + public String getLine1() { + return line1; + } + + /** + * Set line 1. + */ + public void setLine1(String line1) { + this.line1 = line1; + } + + /** + * Return line 2. + */ + public String getLine2() { + return line2; + } + + /** + * Set line 2. + */ + public void setLine2(String line2) { + this.line2 = line2; + } + + /** + * Return city. + */ + public String getCity() { + return city; + } + + /** + * Set city. + */ + public void setCity(String city) { + this.city = city; + } + + /** + * Return cretime. + */ + public Timestamp getCretime() { + return cretime; + } + + /** + * Set cretime. + */ + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + /** + * Return updtime. + */ + public Timestamp getUpdtime() { + return updtime; + } + + /** + * Set updtime. + */ + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + /** + * Return country. + */ + public Country getCountry() { + return country; + } + + /** + * Set country. + */ + public void setCountry(Country country) { + this.country = country; + } + +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/BasicDomain.java b/ebean-core/src/test/java/org/tests/model/basic/BasicDomain.java new file mode 100644 index 000000000..86c39f5b4 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/BasicDomain.java @@ -0,0 +1,60 @@ +package org.tests.model.basic; + +import io.ebean.annotation.WhenCreated; +import io.ebean.annotation.WhenModified; + +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; +import javax.persistence.Version; +import java.io.Serializable; +import java.sql.Timestamp; + +@MappedSuperclass +public class BasicDomain implements Serializable { + + private static final long serialVersionUID = 5569496199004449769L; + + @Id + Integer id; + + @WhenCreated + Timestamp cretime; + + @WhenModified + Timestamp updtime; + + @Version + Long version; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public Timestamp getUpdtime() { + return updtime; + } + + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + public Timestamp getCretime() { + return cretime; + } + + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + public Long getVersion() { + return version; + } + + public void setVersion(Long version) { + this.version = version; + } +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Contact.java b/ebean-core/src/test/java/org/tests/model/basic/Contact.java index 5c1e0cc8e..883d27d5c 100644 --- a/ebean-core/src/test/java/org/tests/model/basic/Contact.java +++ b/ebean-core/src/test/java/org/tests/model/basic/Contact.java @@ -1,4 +1,155 @@ package org.tests.model.basic; +import io.ebean.annotation.Index; +import io.ebean.annotation.*; + +import javax.persistence.*; +import javax.validation.constraints.Size; +import java.sql.Timestamp; +import java.util.List; + +@DocStore +@Index(columnNames = {"last_name", "first_name"}) +@ChangeLog +@Entity +@Cache(naturalKey = "email") public class Contact { + + @Id @GeneratedValue + int id; + + @Size(max=127) + String firstName; + + @Size(max=127) + String lastName; + + String phone; + String mobile; + String email; + + boolean isMember; + + @DocEmbedded(doc = "id,name") + @ManyToOne(optional = false) + Customer customer; + + @ManyToOne(optional = true) + ContactGroup group; + + @OneToMany(cascade = CascadeType.ALL) + List notes; + + @CreatedTimestamp + Timestamp cretime; + + @Version + Timestamp updtime; + + + public Contact(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public Contact() { + + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Timestamp getUpdtime() { + return updtime; + } + + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + public Timestamp getCretime() { + return cretime; + } + + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getPhone() { + return phone; + } + + public void setPhone(String phone) { + this.phone = phone; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public boolean isMember() { + return isMember; + } + + public void setMember(boolean member) { + isMember = member; + } + + public Customer getCustomer() { + return customer; + } + + public void setCustomer(Customer customer) { + this.customer = customer; + } + + public ContactGroup getGroup() { + return group; + } + + public void setGroup(ContactGroup group) { + this.group = group; + } + + public List getNotes() { + return notes; + } + + public void setNotes(List notes) { + this.notes = notes; + } + } diff --git a/ebean-core/src/test/java/org/tests/model/basic/ContactGroup.java b/ebean-core/src/test/java/org/tests/model/basic/ContactGroup.java new file mode 100644 index 000000000..1b2963624 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/ContactGroup.java @@ -0,0 +1,20 @@ +package org.tests.model.basic; + +import javax.persistence.Entity; + +@Entity +public class ContactGroup extends BasicDomain { + + private static final long serialVersionUID = -5447111032760796085L; + + String name; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/ContactNote.java b/ebean-core/src/test/java/org/tests/model/basic/ContactNote.java new file mode 100644 index 000000000..ffe0b2e56 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/ContactNote.java @@ -0,0 +1,51 @@ +package org.tests.model.basic; + +import javax.persistence.Entity; +import javax.persistence.Lob; +import javax.persistence.ManyToOne; +import javax.validation.constraints.Size; + +@Entity +public class ContactNote extends BasicDomain { + + private static final long serialVersionUID = 7949702621226333278L; + + @ManyToOne + Contact contact; + + String title; + + @Size(max = 2000) + @Lob + String note; + + public ContactNote(String title, String note) { + this.title = title; + this.note = note; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + + public Contact getContact() { + return contact; + } + + public void setContact(Contact contact) { + this.contact = contact; + } + +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Country.java b/ebean-core/src/test/java/org/tests/model/basic/Country.java new file mode 100644 index 000000000..bde38fc78 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/Country.java @@ -0,0 +1,63 @@ +package org.tests.model.basic; + +import io.ebean.annotation.*; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.validation.constraints.Size; + +/** + * Country entity bean. + */ +@DocStore +@ReadAudit +@ChangeLog(inserts = ChangeLogInsertMode.INCLUDE) +@Cache(readOnly = true, enableQueryCache = true) +@CacheBeanTuning(maxSize = 500) +@Entity +@Table(name = "o_country") +public class Country { + + @Id + @Size(max = 2) + String code; + + @Size(max = 60) + String name; + + @Override + public String toString() { + return code; + } + + /** + * Return code. + */ + public String getCode() { + return code; + } + + /** + * Set code. + */ + public void setCode(String code) { + this.code = code; + } + + /** + * Return name. + */ + public String getName() { + return name; + } + + /** + * Set name. + */ + public void setName(String name) { + this.name = name; + } + + +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Customer.java b/ebean-core/src/test/java/org/tests/model/basic/Customer.java index 0b0202301..8e209631e 100644 --- a/ebean-core/src/test/java/org/tests/model/basic/Customer.java +++ b/ebean-core/src/test/java/org/tests/model/basic/Customer.java @@ -1,4 +1,211 @@ package org.tests.model.basic; -public class Customer { +import io.ebean.annotation.*; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.sql.Date; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + +/** + * Customer entity bean. + */ +@NamedQueries( + value = { + @NamedQuery(name = "name", query = "select(name) order by name"), + @NamedQuery(name = "withStatus", query = "select(name,status) order by name") + } +) +@NamedQuery(name = "withContacts", query = "fetch contacts (firstName, lastName) where id = :id") +@Cache(enableQueryCache = true) +@DocStore +@ChangeLog(inserts = ChangeLogInsertMode.EXCLUDE, updatesThatInclude = {"name", "status"}) +@Entity +@Table(name = "o_customer") +@DbComment("Holds external customers") +public class Customer extends BasicDomain { + + private static final long serialVersionUID = 1L; + + //public static final CustomerFinder find = new CustomerFinder(); + + /** + * EnumValue is an Ebean specific mapping for enums. + */ + public enum Status { + NEW("N"), + ACTIVE("A"), + INACTIVE("I"); + + String dbValue; + + Status(String dbValue) { + this.dbValue = dbValue; + } + + @DbEnumValue + public String getValue() { + return dbValue; + } + } + + @Transient + Boolean selected; + + + @JsonIgnore + //@Expose(deserialize = false, serialize = false) + @Transient + ReentrantLock lock = new ReentrantLock(); + + @DbComment("status of the customer") + Status status; + + @NotNull + @Size(max = 40) + String name; + + @DbComment("Short notes regarding the customer") + @Size(max = 100) + String smallnote; + + @DbComment("Join date of the customer") + @NotNull//(groups = {ValidationGroupSomething.class}) + Date anniversary; + + @DocEmbedded(doc = "*,country(*)") + @ManyToOne(cascade = CascadeType.ALL) + Address billingAddress; + + @DocEmbedded(doc = "*,country(*)") + @ManyToOne(cascade = CascadeType.ALL) + Address shippingAddress; + + @OneToMany(mappedBy = "customer") + @Where(clause = "${ta}.order_date is not null") + List orders; + + @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL) + List contacts; + + @Override + public String toString() { + return id + " " + status + " " + name; + } + + /** + * Return name. + */ + public String getName() { + return name; + } + + /** + * Set name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Return billing address. + */ + public Address getBillingAddress() { + return billingAddress; + } + + /** + * Set billing address. + */ + public void setBillingAddress(Address billingAddress) { + this.billingAddress = billingAddress; + } + + /** + * Return status. + */ + public Status getStatus() { + return status; + } + + /** + * Set status. + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Return shipping address. + */ + public Address getShippingAddress() { + return shippingAddress; + } + + /** + * Set shipping address. + */ + public void setShippingAddress(Address shippingAddress) { + this.shippingAddress = shippingAddress; + } + + /** + * Return orders. + */ + public List getOrders() { + return orders; + } + + /** + * Set orders. + */ + public void setOrders(List orders) { + this.orders = orders; + } + + public Boolean getSelected() { + return selected; + } + + public void setSelected(Boolean selected) { + this.selected = selected; + } + + public ReentrantLock getLock() { + return lock; + } + + public String getSmallnote() { + return smallnote; + } + + public void setSmallnote(String smallnote) { + this.smallnote = smallnote; + } + + public Date getAnniversary() { + return anniversary; + } + + public void setAnniversary(Date anniversary) { + this.anniversary = anniversary; + } + + public List getContacts() { + return contacts; + } + + public void setContacts(List contacts) { + this.contacts = contacts; + } + + public void addContact(Contact contact) { + if (contacts == null) { + contacts = new ArrayList<>(); + } + contacts.add(contact); + } } diff --git a/ebean-core/src/test/java/org/tests/model/basic/Order.java b/ebean-core/src/test/java/org/tests/model/basic/Order.java new file mode 100644 index 000000000..537207935 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/Order.java @@ -0,0 +1,252 @@ +package org.tests.model.basic; + +import io.ebean.annotation.*; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; +import java.sql.Date; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; + +/** + * Order entity bean. + */ +@DocStore +@ChangeLog +@Entity +@Table(name = "o_order") +public class Order implements Serializable { + + private static final long serialVersionUID = 1L; + + public enum Status { + NEW, + APPROVED, + SHIPPED, + COMPLETE + } + + @Id + Integer id; + + /** + * Derived total amount from the order details. Needs to be explicitly included in query as Transient. + * Removing the Transient would mean by default it would be included in a order query. + *

+ * NOTE: The join clause for totalAmount and totalItems is the same. If your query includes both + * totalAmount and totalItems only the one join is added to the query. + *

+ */ + @Transient + @Formula( + select = "z_b${ta}.total_amount", + join = "join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") + Double totalAmount; + + /** + * Derived total item count from the order details. Needs to be explicitly included in query as Transient. + */ + @Transient + @Formula( + select = "z_b${ta}.total_items", + join = "join (select order_id, count(*) as total_items, sum(order_qty*unit_price) as total_amount from o_order_detail group by order_id) z_b${ta} on z_b${ta}.order_id = ${ta}.id") + Integer totalItems; + + @Enumerated(value = EnumType.ORDINAL) + Status status = Status.NEW; + + Date orderDate = new Date(System.currentTimeMillis()); + + Date shipDate; + + @NotNull + @ManyToOne(cascade = CascadeType.PERSIST) + @JoinColumn(name = "kcustomer_id") + @DocEmbedded(doc = "id,name") + Customer customer; + + @Column(name = "name", table = "o_customer") + String customerName; + + @WhenCreated + Timestamp cretime; + + @Version + Timestamp updtime; + + @Where(clause = "${ta}.id > 0") + @OneToMany(cascade = CascadeType.ALL, mappedBy = "order") + @OrderBy("id asc, orderQty asc, cretime desc") + @DocEmbedded + List details; + +// @OneToMany(cascade = CascadeType.ALL, mappedBy = "order", orphanRemoval = true) +// List shipments; + + @Override + public String toString() { + return id + " totalAmount:" + totalAmount + " totalItems:" + totalItems; + } + + /** + * Return id. + */ + public Integer getId() { + return id; + } + + /** + * Set id. + */ + public void setId(Integer id) { + this.id = id; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public Double getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Double totalAmount) { + this.totalAmount = totalAmount; + } + + public Integer getTotalItems() { + return totalItems; + } + + public void setTotalItems(Integer totalItems) { + this.totalItems = totalItems; + } + + /** + * Return order date. + */ + public Date getOrderDate() { + return orderDate; + } + + /** + * Set order date. + */ + public void setOrderDate(Date orderDate) { + this.orderDate = orderDate; + } + + /** + * Return ship date. + */ + public Date getShipDate() { + return shipDate; + } + + /** + * Set ship date. + */ + public void setShipDate(Date shipDate) { + this.shipDate = shipDate; + } + + /** + * Return cretime. + */ + public Timestamp getCretime() { + return cretime; + } + + /** + * Set cretime. + */ + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + /** + * Return updtime. + */ + public Timestamp getUpdtime() { + return updtime; + } + + /** + * Set updtime. + */ + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + /** + * Return status. + */ + public Status getStatus() { + return status; + } + + /** + * Set status. + */ + public void setStatus(Status status) { + this.status = status; + } + + /** + * Return customer. + */ + public Customer getCustomer() { + return customer; + } + + /** + * Set customer. + */ + public void setCustomer(Customer customer) { + this.customer = customer; + } + + /** + * Return details. + */ + public List getDetails() { + return details; + } + + /** + * Set details. + */ + public void setDetails(List details) { + this.details = details; + } + + public void addDetail(OrderDetail detail) { + + if (details == null) { + details = new ArrayList<>(); + } + details.add(detail); + } + +// public List getShipments() { +// return shipments; +// } +// +// public void setShipments(List shipments) { +// this.shipments = shipments; +// } +// +// public void addShipment(OrderShipment shipment) { +// +// if (shipments == null) { +// shipments = new ArrayList<>(); +// } +// shipments.add(shipment); +// } +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/OrderDetail.java b/ebean-core/src/test/java/org/tests/model/basic/OrderDetail.java new file mode 100644 index 000000000..393837296 --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/OrderDetail.java @@ -0,0 +1,157 @@ +package org.tests.model.basic; + +import io.ebean.annotation.Cache; +import io.ebean.annotation.DocEmbedded; + +import javax.persistence.*; +import java.io.Serializable; +import java.math.BigDecimal; +import java.sql.Timestamp; + +/** + * Order Detail entity bean. + */ +@Cache +@Entity +@Table(name = "o_order_detail") +public class OrderDetail implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + Integer id; + + @ManyToOne(optional = false) + Order order; + + Integer orderQty; + + Integer shipQty; + + BigDecimal unitPrice; + + @ManyToOne + @DocEmbedded(doc = "id,name,sku") + Product product; + + Timestamp cretime; + + @Version + Timestamp updtime; + + public OrderDetail() { + } + + public OrderDetail(Product product, Integer orderQty, BigDecimal unitPrice) { + this.product = product; + this.orderQty = orderQty; + this.unitPrice = unitPrice; + } + + /** + * Return id. + */ + public Integer getId() { + return id; + } + + /** + * Set id. + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Return order qty. + */ + public Integer getOrderQty() { + return orderQty; + } + + /** + * Set order qty. + */ + public void setOrderQty(Integer orderQty) { + this.orderQty = orderQty; + } + + /** + * Return ship qty. + */ + public Integer getShipQty() { + return shipQty; + } + + /** + * Set ship qty. + */ + public void setShipQty(Integer shipQty) { + this.shipQty = shipQty; + } + + public BigDecimal getUnitPrice() { + return unitPrice; + } + + public void setUnitPrice(BigDecimal unitPrice) { + this.unitPrice = unitPrice; + } + + /** + * Return cretime. + */ + public Timestamp getCretime() { + return cretime; + } + + /** + * Set cretime. + */ + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + /** + * Return updtime. + */ + public Timestamp getUpdtime() { + return updtime; + } + + /** + * Set updtime. + */ + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + + /** + * Return order. + */ + public Order getOrder() { + return order; + } + + /** + * Set order. + */ + public void setOrder(Order order) { + this.order = order; + } + + /** + * Return product. + */ + public Product getProduct() { + return product; + } + + /** + * Set product. + */ + public void setProduct(Product product) { + this.product = product; + } + +} diff --git a/ebean-core/src/test/java/org/tests/model/basic/Product.java b/ebean-core/src/test/java/org/tests/model/basic/Product.java new file mode 100644 index 000000000..60f73475c --- /dev/null +++ b/ebean-core/src/test/java/org/tests/model/basic/Product.java @@ -0,0 +1,112 @@ +package org.tests.model.basic; + +import io.ebean.annotation.*; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import javax.persistence.Version; +import javax.validation.constraints.Size; +import java.io.Serializable; +import java.sql.Timestamp; + +import static io.ebean.annotation.IdentityGenerated.BY_DEFAULT; + +/** + * Product entity bean. + */ +@Identity(generated = BY_DEFAULT) +@DocStore +@Cache +@CacheQueryTuning(maxSecsToLive = 15) +@Entity +@Table(name = "o_product") +public class Product implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + Integer id; + + @Size(max = 20) + String sku; + + String name; + + @CreatedTimestamp + Timestamp cretime; + + @Version + Timestamp updtime; + + /** + * Return id. + */ + public Integer getId() { + return id; + } + + /** + * Set id. + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * Return sku. + */ + public String getSku() { + return sku; + } + + /** + * Set sku. + */ + public void setSku(String sku) { + this.sku = sku; + } + + /** + * Return name. + */ + public String getName() { + return name; + } + + /** + * Set name. + */ + public void setName(String name) { + this.name = name; + } + + /** + * Return cretime. + */ + public Timestamp getCretime() { + return cretime; + } + + /** + * Set cretime. + */ + public void setCretime(Timestamp cretime) { + this.cretime = cretime; + } + + /** + * Return updtime. + */ + public Timestamp getUpdtime() { + return updtime; + } + + /** + * Set updtime. + */ + public void setUpdtime(Timestamp updtime) { + this.updtime = updtime; + } + +} diff --git a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogListenerTest.java b/ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogListenerTest.java deleted file mode 100644 index d45c249fc..000000000 --- a/ebean-test/src/test/java/io/ebeaninternal/server/changelog/DefaultChangeLogListenerTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.ebeaninternal.server.changelog; - -import io.ebean.xtest.BaseTestCase; -import io.ebean.DB; -import io.ebean.Database; -import io.ebean.event.changelog.ChangeSet; -import org.junit.jupiter.api.Test; - -public class DefaultChangeLogListenerTest extends BaseTestCase { - - Helper helper = new Helper(); - - @Test - public void test() { - - DefaultChangeLogListener changeLogListener = new DefaultChangeLogListener(); - - Database defaultServer = DB.getDefault(); - changeLogListener.configure(defaultServer.pluginApi()); - - ChangeSet changeSet = helper.createChangeSet("INT-001", 13); - - changeLogListener.log(changeSet); - } - -}