mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-14 06:45:21 +00:00
Refactor tests, move internal type tests to ebean-core
This commit is contained in:
1 parent
e3e5414157
commit
426d314e63
75 files changed
+485
-159
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-2
@@ -5,9 +5,9 @@ import io.ebean.config.dbplatform.postgres.PostgresPlatform;
|
|||||||
import io.ebean.core.type.ScalarType;
|
import io.ebean.core.type.ScalarType;
|
||||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.array.IntEnum;
|
|
||||||
import org.tests.model.array.VarcharEnum;
|
|
||||||
import org.tests.model.basic.Car;
|
import org.tests.model.basic.Car;
|
||||||
|
import org.tests.model.basic.IntEnum;
|
||||||
|
import org.tests.model.basic.VarcharEnum;
|
||||||
|
|
||||||
import javax.persistence.EnumType;
|
import javax.persistence.EnumType;
|
||||||
import java.time.DayOfWeek;
|
import java.time.DayOfWeek;
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+3
-2
@@ -3,6 +3,7 @@ package io.ebeaninternal.server.type;
|
|||||||
|
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
import io.ebean.text.json.JsonContext;
|
import io.ebean.text.json.JsonContext;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.TOne;
|
import org.tests.model.basic.TOne;
|
||||||
|
|
||||||
@@ -25,7 +26,7 @@ public class ScalarTypeBooleanTest {
|
|||||||
String json = jsonContext.toJson(bean);
|
String json = jsonContext.toJson(bean);
|
||||||
TOne tOne = jsonContext.toBean(TOne.class, json);
|
TOne tOne = jsonContext.toBean(TOne.class, json);
|
||||||
|
|
||||||
assertTrue(tOne.isActive());
|
Assertions.assertTrue(tOne.isActive());
|
||||||
assertEquals(json, "{\"id\":42,\"active\":true}");
|
assertEquals(json, "{\"id\":42,\"active\":true}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,7 +40,7 @@ public class ScalarTypeBooleanTest {
|
|||||||
String json = jsonContext.toJson(bean);
|
String json = jsonContext.toJson(bean);
|
||||||
TOne tOne = jsonContext.toBean(TOne.class, json);
|
TOne tOne = jsonContext.toBean(TOne.class, json);
|
||||||
|
|
||||||
assertFalse(tOne.isActive());
|
Assertions.assertFalse(tOne.isActive());
|
||||||
assertEquals(json, "{\"id\":42,\"active\":false}");
|
assertEquals(json, "{\"id\":42,\"active\":false}");
|
||||||
}
|
}
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+2
-1
@@ -4,6 +4,7 @@ import io.ebean.DB;
|
|||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
import org.joda.time.LocalDateTime;
|
import org.joda.time.LocalDateTime;
|
||||||
import org.joda.time.LocalTime;
|
import org.joda.time.LocalTime;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.TJodaEntity;
|
import org.tests.model.basic.TJodaEntity;
|
||||||
|
|
||||||
@@ -58,6 +59,6 @@ public class ScalarTypeJodaLocalTimeTest {
|
|||||||
String json = DB.json().toJson(bean);
|
String json = DB.json().toJson(bean);
|
||||||
TJodaEntity bean1 = DB.json().toBean(TJodaEntity.class, json);
|
TJodaEntity bean1 = DB.json().toBean(TJodaEntity.class, json);
|
||||||
|
|
||||||
assertEquals(bean1.getLocalTime(), now);
|
Assertions.assertEquals(bean1.getLocalTime(), now);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+17
-3
@@ -1,9 +1,8 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebeaninternal.server.type;
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.config.EncryptKey;
|
import io.ebean.config.EncryptKey;
|
||||||
|
import io.ebeaninternal.server.deploy.BaseTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.basic.encrypt.BasicEncryptKey;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -11,7 +10,7 @@ import java.sql.Timestamp;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
public class TestSimpleEncryptor extends BaseTestCase {
|
public class TestSimpleEncryptor extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
@@ -35,4 +34,19 @@ public class TestSimpleEncryptor extends BaseTestCase {
|
|||||||
Timestamp t1 = Timestamp.valueOf(tsFormat);
|
Timestamp t1 = Timestamp.valueOf(tsFormat);
|
||||||
assertEquals(t, t1);
|
assertEquals(t, t1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class BasicEncryptKey implements EncryptKey {
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
public BasicEncryptKey(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStringValue() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+5
-5
@@ -1,15 +1,15 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebeaninternal.server.type;
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.config.DatabaseConfig;
|
import io.ebean.config.DatabaseConfig;
|
||||||
import io.ebean.config.dbplatform.h2.H2Platform;
|
import io.ebean.config.dbplatform.h2.H2Platform;
|
||||||
import io.ebean.core.type.DataReader;
|
import io.ebean.core.type.DataReader;
|
||||||
import io.ebean.core.type.ScalarType;
|
import io.ebean.core.type.ScalarType;
|
||||||
import io.ebean.xtest.MyDayOfWeek;
|
|
||||||
import io.ebean.xtest.MyEnum;
|
|
||||||
import io.ebean.xtest.MySex;
|
|
||||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||||
|
import io.ebeaninternal.server.deploy.BaseTest;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.tests.model.basic.enums.MyDayOfWeek;
|
||||||
|
import org.tests.model.basic.enums.MyEnum;
|
||||||
|
import org.tests.model.basic.enums.MySex;
|
||||||
import org.tests.model.ivo.Money;
|
import org.tests.model.ivo.Money;
|
||||||
import org.tests.model.ivo.converter.MoneyTypeConverter;
|
import org.tests.model.ivo.converter.MoneyTypeConverter;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
|
|||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
class TestTypeManager extends BaseTestCase {
|
class TestTypeManager extends BaseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testEnumWithSubclasses() throws SQLException {
|
void testEnumWithSubclasses() throws SQLException {
|
||||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,13 @@
|
|||||||
|
package org.tests.model.basic;
|
||||||
|
|
||||||
|
import io.ebean.annotation.DbEnumType;
|
||||||
|
import io.ebean.annotation.DbEnumValue;
|
||||||
|
|
||||||
|
public enum IntEnum {
|
||||||
|
ZERO, ONE, TWO;
|
||||||
|
|
||||||
|
@DbEnumValue(storage = DbEnumType.INTEGER)
|
||||||
|
public int dbValue() {
|
||||||
|
return 100 + ordinal();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package org.tests.model.basic;
|
||||||
|
|
||||||
|
import org.joda.time.LocalTime;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class TJodaEntity {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
Integer id;
|
||||||
|
|
||||||
|
LocalTime localTime;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalTime getLocalTime() {
|
||||||
|
return localTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocalTime(LocalTime localTime) {
|
||||||
|
this.localTime = localTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package org.tests.model.basic;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A basic entity to test simple things.
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "t_oneb")
|
||||||
|
public class TOne {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
Integer id;
|
||||||
|
|
||||||
|
String name;
|
||||||
|
|
||||||
|
String description;
|
||||||
|
|
||||||
|
boolean active;
|
||||||
|
|
||||||
|
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 String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive() {
|
||||||
|
return active;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActive(boolean active) {
|
||||||
|
this.active = active;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package org.tests.model.basic;
|
||||||
|
|
||||||
|
import io.ebean.annotation.DbEnumType;
|
||||||
|
import io.ebean.annotation.DbEnumValue;
|
||||||
|
|
||||||
|
public enum VarcharEnum {
|
||||||
|
ZERO, ONE, TWO;
|
||||||
|
|
||||||
|
@DbEnumValue(storage = DbEnumType.VARCHAR, withConstraint = false)
|
||||||
|
public String dbValue() {
|
||||||
|
return "xXx" + name();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package org.tests.model.basic.enums;
|
||||||
|
|
||||||
|
import io.ebean.annotation.EnumValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum test when DB CHAR column used with spaces.
|
||||||
|
*/
|
||||||
|
public enum MyDayOfWeek {
|
||||||
|
|
||||||
|
@EnumValue("MONDAY ")MONDAY,
|
||||||
|
@EnumValue("TUESDAY ")TUESDAY,
|
||||||
|
@EnumValue("WEDNESDAY")WEDNESDAY,
|
||||||
|
@EnumValue("THURSDAY ")THURSDAY,
|
||||||
|
@EnumValue("FRIDAY ")FRIDAY,
|
||||||
|
@EnumValue("SATURDAY ")SATURDAY,
|
||||||
|
@EnumValue("SUNDAY ")SUNDAY
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.tests.model.basic.enums;
|
||||||
|
|
||||||
|
import io.ebean.annotation.EnumValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum with method overrides (and hence multiple actual classes).
|
||||||
|
*/
|
||||||
|
public enum MyEnum {
|
||||||
|
|
||||||
|
@EnumValue("A")Aval {
|
||||||
|
@Override
|
||||||
|
public String doSomething() {
|
||||||
|
return "bar";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
@EnumValue("B")Bval,
|
||||||
|
|
||||||
|
@EnumValue("C")Cval {
|
||||||
|
@Override
|
||||||
|
public String doSomething() {
|
||||||
|
return "baz";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public String doSomething() {
|
||||||
|
return "foo";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package org.tests.model.basic.enums;
|
||||||
|
|
||||||
|
public enum MySex {
|
||||||
|
MALE, FEMALE
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
package org.tests.model.ivo;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.MathContext;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A representation of Money effectively wrapping BigDecimal.
|
||||||
|
* <p>
|
||||||
|
* <p>
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author rbygrave
|
||||||
|
*/
|
||||||
|
public final class Money implements Comparable<Money>, Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final Money ZERO = new Money(BigDecimal.ZERO);
|
||||||
|
|
||||||
|
private final BigDecimal amount;
|
||||||
|
|
||||||
|
public Money(BigDecimal amount) {
|
||||||
|
if (amount == null) {
|
||||||
|
throw new NullPointerException("amount can not be null");
|
||||||
|
}
|
||||||
|
this.amount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money(double val) {
|
||||||
|
this(BigDecimal.valueOf(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money(String val) {
|
||||||
|
this(new BigDecimal(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return amount.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return amount.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof Money) {
|
||||||
|
// use BigDecimal.compareTo to handle scale differences
|
||||||
|
return amount.compareTo(((Money) obj).getAmount()) == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Money o) {
|
||||||
|
return amount.compareTo(o.amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getAmount() {
|
||||||
|
return amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money subtract(Money amt) {
|
||||||
|
BigDecimal b = amount.subtract(amt.amount);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money subtract(Money amt, MathContext ctx) {
|
||||||
|
BigDecimal b = amount.subtract(amt.amount, ctx);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money add(Money amt) {
|
||||||
|
BigDecimal b = amount.add(amt.amount);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money add(Money amt, MathContext ctx) {
|
||||||
|
BigDecimal b = amount.add(amt.amount, ctx);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money multiply(Money m) {
|
||||||
|
return multiply(m.amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money multiply(int val) {
|
||||||
|
return multiply(BigDecimal.valueOf(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money multiply(float val) {
|
||||||
|
return multiply(BigDecimal.valueOf(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money multiply(double val) {
|
||||||
|
return multiply(BigDecimal.valueOf(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money multiply(BigDecimal m) {
|
||||||
|
BigDecimal b = amount.multiply(m);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money divide(BigDecimal divisor) {
|
||||||
|
BigDecimal b = amount.divide(divisor);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Money divide(BigDecimal divisor, MathContext ctx) {
|
||||||
|
BigDecimal b = amount.divide(divisor, ctx);
|
||||||
|
return new Money(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Money sum(Money... m) {
|
||||||
|
BigDecimal t = BigDecimal.ZERO;
|
||||||
|
for (Money money : m) {
|
||||||
|
t = t.add(money.amount);
|
||||||
|
}
|
||||||
|
return new Money(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Money sum(Iterator<Money> it) {
|
||||||
|
BigDecimal t = BigDecimal.ZERO;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
t = t.add(it.next().amount);
|
||||||
|
}
|
||||||
|
return new Money(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Money sum(Iterator<Money> it, MathContext ctx) {
|
||||||
|
BigDecimal t = BigDecimal.ZERO;
|
||||||
|
while (it.hasNext()) {
|
||||||
|
t = t.add(it.next().amount, ctx);
|
||||||
|
}
|
||||||
|
return new Money(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.tests.model.ivo;
|
||||||
|
|
||||||
|
|
||||||
|
public class Oid<T> {
|
||||||
|
|
||||||
|
private final long value;
|
||||||
|
|
||||||
|
public Oid(long value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return (int) (value ^ (value >>> 32));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (o instanceof Oid<?>) {
|
||||||
|
return ((Oid<?>) o).value == value;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Oid<?> valueOf(String s) {
|
||||||
|
return new Oid<>(Integer.valueOf(s));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Oid<?> valueOf(long i) {
|
||||||
|
return new Oid<>(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Oid<T> valueOf(Class<T> cls, String s) {
|
||||||
|
Integer v = Integer.valueOf(s);
|
||||||
|
return new Oid<>(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package org.tests.model.ivo;
|
||||||
|
|
||||||
|
public class SysTime {
|
||||||
|
|
||||||
|
private final long millis;
|
||||||
|
|
||||||
|
public SysTime(long millis) {
|
||||||
|
this.millis = millis;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMillis() {
|
||||||
|
return millis;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package org.tests.model.ivo.converter;
|
||||||
|
|
||||||
|
import org.tests.model.ivo.Money;
|
||||||
|
|
||||||
|
import javax.persistence.AttributeConverter;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts between Money and BigDecimal.
|
||||||
|
*/
|
||||||
|
public class MoneyTypeConverter implements AttributeConverter<Money,BigDecimal> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BigDecimal convertToDatabaseColumn(Money beanType) {
|
||||||
|
return beanType.getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Money convertToEntityAttribute(BigDecimal scalarType) {
|
||||||
|
return new Money(scalarType);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package org.tests.model.ivo.converter;
|
||||||
|
|
||||||
|
import io.ebean.config.ScalarTypeConverter;
|
||||||
|
import org.tests.model.ivo.Oid;
|
||||||
|
|
||||||
|
public class OidTypeConverter implements ScalarTypeConverter<Oid<?>,Long> {
|
||||||
|
|
||||||
|
public static final Oid<?> NULL_VALUE = new Oid<>(0);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Oid<?> getNullValue() {
|
||||||
|
return NULL_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Oid<?> wrapValue(Long scalarType) {
|
||||||
|
return new Oid<>(scalarType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Long unwrapValue(Oid<?> beanType) {
|
||||||
|
if (NULL_VALUE.equals(beanType)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return beanType.getValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package org.tests.model.ivo.converter;
|
||||||
|
|
||||||
|
import io.ebean.config.ScalarTypeConverter;
|
||||||
|
import org.tests.model.ivo.SysTime;
|
||||||
|
|
||||||
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
public class SysTimeConverter implements ScalarTypeConverter<SysTime, Timestamp> {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTime getNullValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Timestamp unwrapValue(SysTime beanType) {
|
||||||
|
return new Timestamp(beanType.getMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SysTime wrapValue(Timestamp scalarType) {
|
||||||
|
return new SysTime(scalarType.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,3 +11,5 @@ datasource.h2other.url=jdbc:h2:mem:testCoreOther;DB_CLOSE_ON_EXIT=FALSE;NON_KEYW
|
|||||||
ebean.h2.ddl.generate=true
|
ebean.h2.ddl.generate=true
|
||||||
ebean.h2.ddl.run=true
|
ebean.h2.ddl.run=true
|
||||||
ebean.h2.ddl.initSql=h2-init.sql
|
ebean.h2.ddl.initSql=h2-init.sql
|
||||||
|
|
||||||
|
ebean.jodaLocalTimeMode=normal
|
||||||
+9
-10
@@ -1,18 +1,17 @@
|
|||||||
package io.ebeaninternal.server.type;
|
package io.ebean.xtest.core;
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.DB;
|
import io.ebean.DB;
|
||||||
import io.ebean.SqlRow;
|
import io.ebean.SqlRow;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.tests.model.basic.UUOne;
|
import org.tests.model.basic.UUOne;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
public class TestBinaryUUID extends BaseTestCase {
|
public class TestBinaryUUID {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void test() {
|
||||||
@@ -31,11 +30,11 @@ public class TestBinaryUUID extends BaseTestCase {
|
|||||||
UUOne fetch0 = DB.find(UUOne.class, one0.getId());
|
UUOne fetch0 = DB.find(UUOne.class, one0.getId());
|
||||||
UUOne fetch1 = DB.find(UUOne.class, one1.getId());
|
UUOne fetch1 = DB.find(UUOne.class, one1.getId());
|
||||||
|
|
||||||
assertEquals(one0.getId(), fetch0.getId());
|
Assertions.assertEquals(one0.getId(), fetch0.getId());
|
||||||
assertEquals(one0.getName(), fetch0.getName());
|
Assertions.assertEquals(one0.getName(), fetch0.getName());
|
||||||
|
|
||||||
assertEquals(one1.getId(), fetch1.getId());
|
Assertions.assertEquals(one1.getId(), fetch1.getId());
|
||||||
assertEquals(one1.getName(), fetch1.getName());
|
Assertions.assertEquals(one1.getName(), fetch1.getName());
|
||||||
|
|
||||||
String sql = "select id, name from uuone";
|
String sql = "select id, name from uuone";
|
||||||
List<SqlRow> list = DB.sqlQuery(sql).findList();
|
List<SqlRow> list = DB.sqlQuery(sql).findList();
|
||||||
@@ -50,8 +49,8 @@ public class TestBinaryUUID extends BaseTestCase {
|
|||||||
String asJson = DB.json().toJson(fetch0);
|
String asJson = DB.json().toJson(fetch0);
|
||||||
UUOne bean = DB.json().toBean(UUOne.class, asJson);
|
UUOne bean = DB.json().toBean(UUOne.class, asJson);
|
||||||
|
|
||||||
assertEquals(fetch0.getId(), bean.getId());
|
Assertions.assertEquals(fetch0.getId(), bean.getId());
|
||||||
assertEquals(fetch0.getName(), bean.getName());
|
Assertions.assertEquals(fetch0.getName(), bean.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package io.ebeaninternal.server.core;
|
|
||||||
|
|
||||||
import io.ebean.Database;
|
|
||||||
import io.ebean.Query;
|
|
||||||
import io.ebean.Transaction;
|
|
||||||
import io.ebeaninternal.api.SpiQuery;
|
|
||||||
|
|
||||||
public class HelpCreateQueryRequest {
|
|
||||||
|
|
||||||
public static <T> OrmQueryRequest<T> create(Database server, SpiQuery.Type type, Query<T> query, Transaction t) {
|
|
||||||
DefaultServer defaultServer = (DefaultServer) server;
|
|
||||||
return (OrmQueryRequest<T>)defaultServer.createQueryRequest(type, query, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package io.ebeaninternal.server.core;
|
|
||||||
|
|
||||||
import io.ebean.DB;
|
|
||||||
import io.ebean.Query;
|
|
||||||
import io.ebeaninternal.api.SpiQuery;
|
|
||||||
|
|
||||||
public class OrmQueryRequestTestHelper {
|
|
||||||
|
|
||||||
static DefaultServer defaultServer = (DefaultServer) DB.getDefault();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create and return a OrmQueryRequest for the given query.
|
|
||||||
*/
|
|
||||||
public static <T> OrmQueryRequest<T> queryRequest(Query<T> query) {
|
|
||||||
return (OrmQueryRequest<T>) defaultServer.createQueryRequest(SpiQuery.Type.LIST, query, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
package io.ebeaninternal.server.loadcontext;
|
|
||||||
|
|
||||||
import io.ebean.xtest.BaseTestCase;
|
|
||||||
import io.ebean.FetchConfig;
|
|
||||||
import io.ebean.Query;
|
|
||||||
import io.ebeaninternal.server.core.OrmQueryRequest;
|
|
||||||
import io.ebeaninternal.server.core.OrmQueryRequestTestHelper;
|
|
||||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.tests.model.basic.Order;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class DLoadContextTest extends BaseTestCase {
|
|
||||||
|
|
||||||
private OrmQueryRequest<Order> queryRequest(Query<Order> query) {
|
|
||||||
return OrmQueryRequestTestHelper.queryRequest(query);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Query<Order> query() {
|
|
||||||
return server().find(Order.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_defaults_expect_defaultLazyBatchSizeServerDefaults() {
|
|
||||||
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query());
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadBeanContext customer = graphContext.getBeanContext("customer");
|
|
||||||
|
|
||||||
assertThat(customer.batchSize).isEqualTo(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_fetchQuery_expect_100_batchSize() {
|
|
||||||
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetch("customer", FetchConfig.ofQuery()));
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadBeanContext customer = graphContext.getBeanContext("customer");
|
|
||||||
|
|
||||||
assertThat(customer.batchSize).isEqualTo(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_fetchQuery_expect_100_batchSize_viaFetchQuery() {
|
|
||||||
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetchQuery("customer"));
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadBeanContext customer = graphContext.getBeanContext("customer");
|
|
||||||
|
|
||||||
assertThat(customer.batchSize).isEqualTo(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_fetchQuery50_expect_50_batchSize() {
|
|
||||||
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetch("customer", FetchConfig.ofQuery(50)));
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadBeanContext customer = graphContext.getBeanContext("customer");
|
|
||||||
|
|
||||||
assertThat(customer.batchSize).isEqualTo(50);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_fetchQueryFirst20Lazy5_expect_20_5_batchSize() {
|
|
||||||
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetchQuery("customer"));
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadBeanContext customer = graphContext.getBeanContext("customer");
|
|
||||||
|
|
||||||
assertThat(customer.batchSize).isEqualTo(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void construct_when_fetch_expect_100_100_batchSize() {
|
|
||||||
|
|
||||||
BeanPropertyAssocMany<?> many = (BeanPropertyAssocMany<?>)getBeanDescriptor(Order.class).beanProperty("details");
|
|
||||||
// the fetch is converted to a query join due to the maxRows
|
|
||||||
OrmQueryRequest<Order> queryRequest = queryRequest(query().fetch("details").setMaxRows(50));
|
|
||||||
queryRequest.initTransIfRequired();
|
|
||||||
queryRequest.endTransIfRequired();
|
|
||||||
|
|
||||||
DLoadContext graphContext = (DLoadContext) queryRequest.loadContext();
|
|
||||||
DLoadManyContext details = graphContext.getManyContext("details", many);
|
|
||||||
|
|
||||||
assertThat(details.batchSize).isEqualTo(100);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user