mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
@@ -0,0 +1,82 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class BeanCascadeInfoTest {
|
||||
|
||||
@Test
|
||||
public void setTypes_ALL() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setTypes(new CascadeType[]{CascadeType.ALL});
|
||||
assertTrue(info.isSave());
|
||||
assertTrue(info.isDelete());
|
||||
assertTrue(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTypes_PERSIST() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setTypes(new CascadeType[]{CascadeType.PERSIST});
|
||||
assertTrue(info.isSave());
|
||||
assertFalse(info.isDelete());
|
||||
assertFalse(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTypes_MERGE() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setTypes(new CascadeType[]{CascadeType.MERGE});
|
||||
assertTrue(info.isSave());
|
||||
assertFalse(info.isDelete());
|
||||
assertFalse(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTypes_REMOVE() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setTypes(new CascadeType[]{CascadeType.REMOVE});
|
||||
assertFalse(info.isSave());
|
||||
assertTrue(info.isDelete());
|
||||
assertFalse(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setTypes_REFRESH() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setTypes(new CascadeType[]{CascadeType.REFRESH});
|
||||
assertFalse(info.isSave());
|
||||
assertFalse(info.isDelete());
|
||||
assertTrue(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setDelete() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setDelete(true);
|
||||
assertFalse(info.isSave());
|
||||
assertTrue(info.isDelete());
|
||||
assertFalse(info.isRefresh());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setSaveDelete() throws Exception {
|
||||
|
||||
BeanCascadeInfo info = new BeanCascadeInfo();
|
||||
info.setSaveDelete(true, true);
|
||||
assertTrue(info.isSave());
|
||||
assertTrue(info.isDelete());
|
||||
assertFalse(info.isRefresh());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.plugin.Property;
|
||||
import io.ebeaninternal.server.core.CacheOptions;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployIdentityMode;
|
||||
import io.ebeanservice.docstore.api.DocStoreBeanAdapter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.*;
|
||||
import org.tests.model.bridge.BSite;
|
||||
import org.tests.model.bridge.BUser;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BeanDescriptorTest extends BaseTestCase {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = spiEbeanServer().descriptor(Customer.class);
|
||||
|
||||
@Test
|
||||
public void createReference() {
|
||||
|
||||
Customer bean = customerDesc.createReference(null, false, 42, null);
|
||||
assertThat(bean.getId()).isEqualTo(42);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_whenReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.TRUE, false, 42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_whenNotReadOnly() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, false, 42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
|
||||
bean = customerDesc.createReference(42, null);
|
||||
assertThat(server().beanState(bean).isReadOnly()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_when_disabledLazyLoad() {
|
||||
|
||||
Customer bean = customerDesc.createReference(Boolean.FALSE, true, 42, null);
|
||||
assertThat(server().beanState(bean).isDisableLazyLoad()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReference_with_inheritance() {
|
||||
Cat cat = new Cat();
|
||||
cat.setName("Puss");
|
||||
DB.save(cat);
|
||||
|
||||
Dog dog = new Dog();
|
||||
dog.setRegistrationNumber("DOGGIE");
|
||||
DB.save(dog);
|
||||
|
||||
AnimalShelter shelter = new AnimalShelter();
|
||||
shelter.setName("My Animal Shelter");
|
||||
shelter.getAnimals().add(cat);
|
||||
shelter.getAnimals().add(dog);
|
||||
|
||||
DB.save(shelter);
|
||||
|
||||
BeanDescriptor<Animal> animalDesc = spiEbeanServer().descriptor(Animal.class);
|
||||
|
||||
Animal bean = animalDesc.createReference(Boolean.FALSE, false, dog.getId(), null);
|
||||
assertThat(bean.getId()).isEqualTo(dog.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void allProperties() {
|
||||
|
||||
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
|
||||
Collection<? extends Property> props = desc.allProperties();
|
||||
|
||||
assertThat(props).extracting("name").contains("id", "status", "orderDate", "shipDate");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchBaseTable() {
|
||||
BeanDescriptor<Customer> desc = getBeanDescriptor(Customer.class);
|
||||
assertTrue(desc.matchBaseTable("o_customer"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchBaseTable_whenTableHasSchema_expect_matchRegardlessOfSchema() {
|
||||
|
||||
DeployBeanDescriptor<Customer> deploy = mockDeployCustomer();
|
||||
|
||||
when(deploy.getBaseTable()).thenReturn("foo.o_customer");
|
||||
BeanDescriptor<?> desc1 = new BeanDescriptor<>(mockOwner(), deploy);
|
||||
assertTrue(desc1.matchBaseTable("o_customer"));
|
||||
|
||||
when(deploy.getBaseTable()).thenReturn("bar.o_customer");
|
||||
BeanDescriptor<?> desc2 = new BeanDescriptor<>(mockOwner(), deploy);
|
||||
assertTrue(desc2.matchBaseTable("o_customer"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private DeployBeanDescriptor<Customer> mockDeployCustomer() {
|
||||
DeployBeanDescriptor<Customer> deploy = mock(DeployBeanDescriptor.class);
|
||||
when(deploy.getBeanType()).thenReturn(Customer.class);
|
||||
when(deploy.getIdentityMode()).thenReturn(DeployIdentityMode.auto());
|
||||
when(deploy.buildIdentityMode()).thenReturn(IdentityMode.NONE);
|
||||
when(deploy.getCacheOptions()).thenReturn(CacheOptions.NO_CACHING);
|
||||
return deploy;
|
||||
}
|
||||
|
||||
private BeanDescriptorMap mockOwner() {
|
||||
BeanDescriptorMap owner = mock(BeanDescriptorMap.class);
|
||||
when(owner.createDocStoreBeanAdapter(any(), any())).thenReturn(mock(DocStoreBeanAdapter.class));
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void merge_when_empty() {
|
||||
|
||||
Customer from = new Customer();
|
||||
from.setId(42);
|
||||
from.setName("rob");
|
||||
|
||||
Customer to = new Customer();
|
||||
customerDesc.merge((EntityBean) from, (EntityBean) to);
|
||||
|
||||
assertThat(to.getId()).isEqualTo(42);
|
||||
assertThat(to.getName()).isEqualTo("rob");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isIdTypeExternal_when_externalId() {
|
||||
|
||||
BeanDescriptor<Country> countryDesc = spiEbeanServer().descriptor(Country.class);
|
||||
assertThat(countryDesc.isIdGeneratedValue()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isIdTypeExternal_when_platformGenerator_noGeneratedValueAnnotation() {
|
||||
|
||||
assertThat(customerDesc.isIdGeneratedValue()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isIdTypeExternal_when_explicitGeneratedValue() {
|
||||
|
||||
BeanDescriptor<Contact> desc = spiEbeanServer().descriptor(Contact.class);
|
||||
assertThat(desc.isIdGeneratedValue()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isIdTypeExternal_when_uuidGenerator_and_generatedValue() {
|
||||
|
||||
BeanDescriptor<BSite> desc = spiEbeanServer().descriptor(BSite.class);
|
||||
assertThat(desc.isIdGeneratedValue()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isIdTypeExternal_when_uuidGenerator_and_noGeneratedValue() {
|
||||
|
||||
BeanDescriptor<BUser> desc = spiEbeanServer().descriptor(BUser.class);
|
||||
assertThat(desc.isIdGeneratedValue()).isFalse();
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyAdapter;
|
||||
import io.ebeanservice.docstore.api.mapping.DocPropertyMapping;
|
||||
import io.ebeanservice.docstore.api.mapping.DocumentMapping;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BeanDescriptor_documentMappingTest extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void docMapping() {
|
||||
|
||||
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
|
||||
|
||||
DocumentMapping documentMapping = desc.docMapping();
|
||||
|
||||
DocPropertyMapping properties = documentMapping.getProperties();
|
||||
|
||||
assertThat(properties).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void docMapping_visitor() {
|
||||
|
||||
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
|
||||
|
||||
DocumentMapping documentMapping = desc.docMapping();
|
||||
|
||||
DocPropertyMapping properties = documentMapping.getProperties();
|
||||
|
||||
assertThat(properties).isNotNull();
|
||||
|
||||
TDVisitor tdVisitor = new TDVisitor();
|
||||
documentMapping.visit(tdVisitor);
|
||||
|
||||
assertThat(tdVisitor.sb.toString()).isEqualTo("{status,orderDate,shipDate, object{customer:id,name,}customerName, nested{details: [id,orderQty,shipQty,unitPrice,cretime,updtime,]}cretime,updtime,}");
|
||||
}
|
||||
|
||||
class TDVisitor extends DocPropertyAdapter {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@Override
|
||||
public void visitProperty(DocPropertyMapping property) {
|
||||
sb.append(property.getName() + ",");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBegin() {
|
||||
|
||||
sb.append("{");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEnd() {
|
||||
sb.append("}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBeginObject(DocPropertyMapping property) {
|
||||
sb.append(" object{" + property.getName() + ":");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEndObject(DocPropertyMapping property) {
|
||||
sb.append("}");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitBeginList(DocPropertyMapping property) {
|
||||
sb.append(" nested{" + property.getName() + ": [");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitEndList(DocPropertyMapping property) {
|
||||
sb.append("]}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.DatabaseFactory;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.event.AbstractBeanPersistListener;
|
||||
import io.ebean.event.BeanPersistAdapter;
|
||||
import io.ebean.event.BeanPersistListener;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.EBasic;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class BeanDescriptor_registerTest {
|
||||
|
||||
@Test
|
||||
public void testRegisterDeregister() {
|
||||
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
|
||||
config.setName("h2other");
|
||||
config.loadFromProperties();
|
||||
config.setDdlExtra(false);
|
||||
config.setRegister(false);
|
||||
config.setDefaultServer(false);
|
||||
config.getClasses().add(EBasic.class);
|
||||
|
||||
SpiEbeanServer ebeanServer = (SpiEbeanServer)DatabaseFactory.create(config);
|
||||
try {
|
||||
BeanDescriptor<EBasic> desc = ebeanServer.descriptor(EBasic.class);
|
||||
persistListenerRegistrationTests(desc);
|
||||
persistControllerRegistrationTests(desc);
|
||||
} finally {
|
||||
ebeanServer.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
private void persistControllerRegistrationTests(BeanDescriptor<EBasic> desc) {
|
||||
|
||||
Controller1 controller1 = new Controller1();
|
||||
|
||||
assertNull(desc.persistController());
|
||||
desc.register(controller1);
|
||||
assertSame(controller1, desc.persistController());
|
||||
|
||||
Controller2 controller2 = new Controller2();
|
||||
desc.register(controller2);
|
||||
|
||||
assertEquals(2, ((ChainedBeanPersistController) desc.persistController()).size());
|
||||
|
||||
desc.deregister(controller1);
|
||||
assertEquals(1, ((ChainedBeanPersistController) desc.persistController()).size());
|
||||
|
||||
desc.deregister(controller2);
|
||||
assertEquals(0, ((ChainedBeanPersistController) desc.persistController()).size());
|
||||
}
|
||||
|
||||
private void persistListenerRegistrationTests(BeanDescriptor<EBasic> desc) {
|
||||
|
||||
Listener1 listener1 = new Listener1();
|
||||
|
||||
assertNull(desc.persistListener());
|
||||
desc.register(listener1);
|
||||
assertSame(listener1, desc.persistListener());
|
||||
|
||||
Listener2 listener2 = new Listener2();
|
||||
desc.register(listener2);
|
||||
|
||||
BeanPersistListener persistListener = desc.persistListener();
|
||||
assertTrue(persistListener instanceof ChainedBeanPersistListener);
|
||||
assertEquals(2, ((ChainedBeanPersistListener) persistListener).size());
|
||||
|
||||
desc.deregister(listener1);
|
||||
assertEquals(1, ((ChainedBeanPersistListener) desc.persistListener()).size());
|
||||
|
||||
desc.deregister(listener2);
|
||||
assertEquals(0, ((ChainedBeanPersistListener) desc.persistListener()).size());
|
||||
}
|
||||
|
||||
public static class Listener1 extends AbstractBeanPersistListener {
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasic.class.isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Listener2 extends AbstractBeanPersistListener {
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasic.class.isAssignableFrom(cls);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class Controller1 extends BeanPersistAdapter {
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasic.class.isAssignableFrom(cls);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Controller2 extends BeanPersistAdapter {
|
||||
|
||||
@Override
|
||||
public boolean isRegisterFor(Class<?> cls) {
|
||||
return EBasic.class.isAssignableFrom(cls);
|
||||
}
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasic;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
|
||||
public class BeanDescriptor_whenCreatedPropertyTest extends BaseTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) DB.getDefault();
|
||||
|
||||
BeanDescriptor<Customer> desc = server.descriptor(Customer.class);
|
||||
|
||||
BeanProperty whenCreatedProperty = desc.whenCreatedProperty();
|
||||
assertEquals("cretime", whenCreatedProperty.dbColumn());
|
||||
|
||||
BeanProperty whenModifiedProperty = desc.whenModifiedProperty();
|
||||
assertEquals("updtime", whenModifiedProperty.dbColumn());
|
||||
|
||||
|
||||
BeanDescriptor<EBasic> eBasicDesc = server.descriptor(EBasic.class);
|
||||
assertNull(eBasicDesc.whenCreatedProperty());
|
||||
assertNull(eBasicDesc.whenModifiedProperty());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.meta.BasicMetricVisitor;
|
||||
import io.ebean.meta.MetaTimedMetric;
|
||||
import io.ebeaninternal.server.core.PersistRequest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BeanIudMetricsTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void addBatch() {
|
||||
|
||||
BeanIudMetrics iudMetrics = new BeanIudMetrics("one");
|
||||
|
||||
final long startNanos = System.nanoTime() - 10000;
|
||||
iudMetrics.addBatch(PersistRequest.Type.INSERT, startNanos, 4);
|
||||
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
|
||||
List<MetaTimedMetric> timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(1);
|
||||
|
||||
assertThat(timed.get(0).count()).isEqualTo(4);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insertBatch");
|
||||
|
||||
iudMetrics.addBatch(PersistRequest.Type.UPDATE, startNanos, 1);
|
||||
iudMetrics.addBatch(PersistRequest.Type.DELETE_SOFT, startNanos, 2);
|
||||
iudMetrics.addBatch(PersistRequest.Type.DELETE, startNanos, 4);
|
||||
iudMetrics.addBatch(PersistRequest.Type.DELETE_PERMANENT, startNanos, 8);
|
||||
iudMetrics.addBatch(PersistRequest.Type.INSERT, startNanos, 16);
|
||||
|
||||
basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(3);
|
||||
|
||||
assertThat(timed.get(0).count()).isEqualTo(16);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insertBatch");
|
||||
assertThat(timed.get(1).count()).isEqualTo(3);
|
||||
assertThat(timed.get(1).name()).isEqualTo("iud.one.updateBatch");
|
||||
assertThat(timed.get(2).count()).isEqualTo(12);
|
||||
assertThat(timed.get(2).name()).isEqualTo("iud.one.deleteBatch");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addNoBatch() {
|
||||
|
||||
BeanIudMetrics iudMetrics = new BeanIudMetrics("one");
|
||||
|
||||
final long startNanos = System.nanoTime() - 10000;
|
||||
iudMetrics.addNoBatch(PersistRequest.Type.INSERT, startNanos);
|
||||
iudMetrics.addNoBatch(PersistRequest.Type.UPDATE, startNanos);
|
||||
iudMetrics.addNoBatch(PersistRequest.Type.DELETE_SOFT, startNanos);
|
||||
iudMetrics.addNoBatch(PersistRequest.Type.DELETE, startNanos);
|
||||
iudMetrics.addNoBatch(PersistRequest.Type.DELETE_PERMANENT, startNanos);
|
||||
|
||||
BasicMetricVisitor basic = new BasicMetricVisitor();
|
||||
iudMetrics.visit(basic);
|
||||
|
||||
List<MetaTimedMetric> timed = basic.timedMetrics();
|
||||
assertThat(timed).hasSize(3);
|
||||
|
||||
assertThat(timed.get(0).count()).isEqualTo(1);
|
||||
assertThat(timed.get(0).name()).isEqualTo("iud.one.insert");
|
||||
assertThat(timed.get(1).count()).isEqualTo(2);
|
||||
assertThat(timed.get(1).name()).isEqualTo("iud.one.update");
|
||||
assertThat(timed.get(2).count()).isEqualTo(2);
|
||||
assertThat(timed.get(2).name()).isEqualTo("iud.one.delete");
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.common.BeanList;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
||||
public class BeanPropertyAssocManyTest extends BaseTestCase {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = spiEbeanServer().descriptor(Customer.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private BeanPropertyAssocMany<Customer> contacts() {
|
||||
return (BeanPropertyAssocMany<Customer>) customerDesc.beanProperty("contacts");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReferenceIfNull_when_notBeanCollection_expect_null() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(new ArrayList<>());
|
||||
|
||||
BeanCollection<?> ref = contacts().createReferenceIfNull((EntityBean) customer);
|
||||
assertNull(ref);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createReferenceIfNull_when_null_expect_ref() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(null);
|
||||
|
||||
BeanCollection<?> ref = contacts().createReferenceIfNull((EntityBean) customer);
|
||||
assertNotNull(ref);
|
||||
assertTrue(ref.isReference());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lazyLoadMany_addsToParentCollection() {
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setContacts(new BeanList<>());
|
||||
|
||||
Contact contact = new Contact();
|
||||
contact.setCustomer(customer);
|
||||
|
||||
contacts().lazyLoadMany((EntityBean) contact);
|
||||
|
||||
assertThat(customer.getContacts()).hasSize(1);
|
||||
assertThat(customer.getContacts().get(0)).isSameAs(contact);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findIdsByParentId() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
List<Object> customerIds = new ArrayList<>();
|
||||
customerIds.add(1L);
|
||||
customerIds.add(2L);
|
||||
|
||||
List<Object> contactIdsForOne = contacts().findIdsByParentId(1L, null, null, null, true);
|
||||
|
||||
List<Object> contactIdsForMultiple = contacts().findIdsByParentId(null, customerIds, null, null, true);
|
||||
|
||||
assertThat(contactIdsForOne).isNotEmpty();
|
||||
assertThat(contactIdsForMultiple).isNotEmpty();
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class DeployPropertyParserMapTests {
|
||||
|
||||
@Test
|
||||
public void test_like_escape() {
|
||||
|
||||
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("customer.name", "t1.name");
|
||||
map.put("id", "t0.id");
|
||||
|
||||
DeployPropertyParserMap parser = new DeployPropertyParserMap(map);
|
||||
|
||||
String output = parser.parse("(lower(customer.name) like ? escape'' or id > ?)");
|
||||
assertEquals("(lower(t1.name) like ? escape'' or t0.id > ?)", output);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.BWithQIdent;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class DeployPropertyParserTest extends BaseTestCase {
|
||||
|
||||
private final BeanDescriptor<Customer> descriptor = getBeanDescriptor(Customer.class);
|
||||
|
||||
private final BeanDescriptor<Address> addressBeanDescriptor = getBeanDescriptor(Address.class);
|
||||
|
||||
private final BeanDescriptor<BWithQIdent> bWithQIdentDescriptor = getBeanDescriptor(BWithQIdent.class);
|
||||
|
||||
@Test
|
||||
public void from_prefix_expect_unchanged() {
|
||||
assertThat(parser().parse("(select x from status join status)")).isEqualTo("(select x from status join status)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depth0_path() {
|
||||
assertThat(parser().parse("pre status post")).isEqualTo("pre ${}status post");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depth1_path() {
|
||||
assertThat(parser().parse("billingAddress.city")).isEqualTo("${billingAddress}city");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void depth2_path() {
|
||||
assertThat(parser().parse("max(billingAddress.country.name)")).isEqualTo("max(${billingAddress.country}name)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleMax() {
|
||||
assertThat(parser().parse("max(name)")).isEqualTo("max(${}name)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combined() {
|
||||
assertThat(parser().parse("sum(status * name)")).isEqualTo("sum(${}status * ${}name)");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combined_withAtColumn() {
|
||||
assertThat(addressParser().parse("concat(line1, line2, '-EA')")).isEqualTo("concat(${}line_1, ${}line_2, '-EA')");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withExplicitQuote_all_platforms() {
|
||||
assertThat(withQuoteParser().parse("t0.`CODE` like ?")).isEqualTo("t0.`CODE` like ?");
|
||||
assertThat(withQuoteParser().parse("t0.[CODE] like ?")).isEqualTo("t0.[CODE] like ?");
|
||||
assertThat(withQuoteParser().parse("t0.\"CODE\" like ?")).isEqualTo("t0.\"CODE\" like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform({Platform.H2, Platform.POSTGRES})
|
||||
public void withQuote_when_match_h2() {
|
||||
assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}\"Name\" like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.SQLSERVER)
|
||||
public void withQuote_when_match_sqlserver() {
|
||||
assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}[Name] like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForPlatform(Platform.MYSQL)
|
||||
public void withQuote_when_match_mysql() {
|
||||
assertThat(withQuoteParser().parse("name like ?")).isEqualTo("${}`Name` like ?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknown_path() {
|
||||
assertThat(parser().parse(" foo ")).isEqualTo(" foo ");
|
||||
}
|
||||
|
||||
private DeployPropertyParser parser() {
|
||||
return descriptor.parser();
|
||||
}
|
||||
|
||||
private DeployPropertyParser addressParser() {
|
||||
return addressBeanDescriptor.parser();
|
||||
}
|
||||
|
||||
private DeployPropertyParser withQuoteParser() {
|
||||
return bWithQIdentDescriptor.parser();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class DetermineAggPathTest {
|
||||
|
||||
@Test
|
||||
public void path() throws Exception {
|
||||
|
||||
assertThat(DetermineAggPath.path("count(details)")).isEqualTo("details");
|
||||
assertThat(DetermineAggPath.path("count(details )")).isEqualTo("details");
|
||||
|
||||
assertThat(DetermineAggPath.path("count(person.contacts)")).isEqualTo("person.contacts");
|
||||
assertThat(DetermineAggPath.path("sum(details.quantity*details.unitPrice)")).isEqualTo("details.quantity");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paths_simple() throws Exception {
|
||||
|
||||
DetermineAggPath.Path paths = DetermineAggPath.paths("count(details)");
|
||||
assertThat(paths.paths).isEqualTo(new String[]{"details"});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void paths_nested() throws Exception {
|
||||
|
||||
DetermineAggPath.Path paths = DetermineAggPath.paths("count(person.contacts)");
|
||||
assertThat(paths.paths).isEqualTo(new String[]{"person", "contacts"});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebeaninternal.server.query.STreeProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FormulaPropertyPathTest extends BaseTestCase {
|
||||
|
||||
private BeanDescriptor<Customer> customerDesc = getBeanDescriptor(Customer.class);
|
||||
|
||||
@Test
|
||||
public void isFormula() {
|
||||
|
||||
assertFormula("max(version)", "max", "version");
|
||||
assertFormula("min(name)", "min", "name");
|
||||
assertFormula("avg(id)", "avg", "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isFormula_count() {
|
||||
assertFormula("count(status)", "count", "status");
|
||||
assertFormula("count(distinct name)", "count", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concat() {
|
||||
|
||||
assertFormula("concat(name,'-end')", "concat", "name,'-end'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void castFormula() {
|
||||
|
||||
assertFormula("concat(name,'-end')::String", "concat", "name,'-end'", "String", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cast_javaInstant() {
|
||||
|
||||
assertFormula("max(updtime)::Instant", "max", "updtime", "Instant", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alias() {
|
||||
assertFormula("concat(name,'-end') name", "concat", "name,'-end'", null, "name");
|
||||
assertFormula("concat(name,'-end') as name", "concat", "name,'-end'", null, "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void castAndAlias() {
|
||||
assertFormula("concat(name,'-end')::String name", "concat", "name,'-end'", "String", "name");
|
||||
assertFormula("concat(name,'-end')::String as name", "concat", "name,'-end'", "String", "name");
|
||||
}
|
||||
|
||||
private void assertFormula(String input, String funcName, String expression) {
|
||||
assertFormula(input, funcName, expression, null, null);
|
||||
}
|
||||
|
||||
private void assertFormula(String input, String funcName, String expression, String cast, String alias) {
|
||||
|
||||
FormulaPropertyPath propertyPath = new FormulaPropertyPath(customerDesc, input, null);
|
||||
|
||||
assertThat(propertyPath.internalExpression()).isEqualTo(expression);
|
||||
assertThat(propertyPath.outerFunction()).isEqualTo(funcName);
|
||||
if (cast != null) {
|
||||
assertThat(propertyPath.cast()).isEqualTo(cast);
|
||||
} else {
|
||||
assertThat(propertyPath.cast()).isNull();
|
||||
}
|
||||
if (alias != null) {
|
||||
assertThat(propertyPath.alias()).isEqualTo(alias);
|
||||
} else {
|
||||
assertThat(propertyPath.alias()).isNull();
|
||||
}
|
||||
|
||||
assertThat(propertyPath.build()).isNotNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class IndexDefinitionTest {
|
||||
|
||||
private static final String[] simpleCol1 = new String[]{"one"};
|
||||
private static final String[] simpleCol2 = new String[]{"one","two"};
|
||||
private static final String[] formulaCol1 = new String[]{"lower(one)"};
|
||||
private static final String[] formulaCol2 = new String[]{"one","lower(two)"};
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_TRUE_when_simpleMultiColumn() {
|
||||
assertTrue(new IndexDefinition(simpleCol1).isUniqueConstraint());
|
||||
assertTrue(new IndexDefinition(simpleCol2).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_columnWithFormula() {
|
||||
assertFalse(new IndexDefinition(formulaCol1).isUniqueConstraint());
|
||||
assertFalse(new IndexDefinition(formulaCol2).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_concurrentTrue() {
|
||||
assertFalse(new IndexDefinition(simpleCol1, "name", true, null, true, null).isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_NOT_when_definitionNotEmpty() {
|
||||
assertFalse(new IndexDefinition(simpleCol1, "name", true, null, false, "create index foo").isUniqueConstraint());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isUniqueConstraint_TRUE_otherwise() {
|
||||
assertTrue(new IndexDefinition(simpleCol1, "name", true, null, false, "").isUniqueConstraint());
|
||||
assertTrue(new IndexDefinition(simpleCol1, "name", true, null, false, null).isUniqueConstraint());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebeaninternal.server.deploy.meta.DeployTableJoinColumn;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TableJoinColumnTest {
|
||||
|
||||
TableJoinColumn col(String localDbColumn, String foreignDbColumn, boolean insertable, boolean updateable) {
|
||||
DeployTableJoinColumn column = new DeployTableJoinColumn(localDbColumn, foreignDbColumn, insertable, updateable);
|
||||
return new TableJoinColumn(column);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_same() {
|
||||
assertSame(col("a", "b", true, true), col("a", "b", true, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffFirstCol() {
|
||||
assertDifferent(col("a", "b", true, true), col("c", "b", true, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffSecondCol() {
|
||||
assertDifferent(col("a", "b", true, true), col("a", "c", true, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffInsertable() {
|
||||
assertDifferent(col("a", "b", true, true), col("a", "b", false, true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffUpdateable() {
|
||||
assertDifferent(col("a", "b", true, true), col("a", "b", true, false));
|
||||
}
|
||||
|
||||
private void assertDifferent(TableJoinColumn col, TableJoinColumn col2) {
|
||||
assertThat(col).isNotEqualTo(col2);
|
||||
assertThat(col.hashCode()).isNotEqualTo(col2.hashCode());
|
||||
}
|
||||
|
||||
private void assertSame(TableJoinColumn col, TableJoinColumn col2) {
|
||||
assertThat(col).isEqualTo(col2);
|
||||
assertThat(col.hashCode()).isEqualTo(col2.hashCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
|
||||
import io.ebeaninternal.server.deploy.meta.DeployTableJoin;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployTableJoinColumn;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TableJoinTest {
|
||||
|
||||
DeployTableJoinColumn col(String localDbColumn, String foreignDbColumn, boolean insertable, boolean updateable) {
|
||||
return new DeployTableJoinColumn(localDbColumn, foreignDbColumn, insertable, updateable);
|
||||
}
|
||||
|
||||
TableJoin table(String tableName, String col1, String col2) {
|
||||
DeployTableJoin deploy = new DeployTableJoin();
|
||||
deploy.setTable(tableName);
|
||||
deploy.addJoinColumn(col(col1, col2, true, true));
|
||||
return new TableJoin(deploy);
|
||||
}
|
||||
|
||||
TableJoin table(String tableName, String col1, String col2, String col3, String col4) {
|
||||
DeployTableJoin deploy = new DeployTableJoin();
|
||||
deploy.setTable(tableName);
|
||||
deploy.addJoinColumn(col(col1, col2, true, true));
|
||||
deploy.addJoinColumn(col(col3, col4, true, true));
|
||||
return new TableJoin(deploy);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_same() {
|
||||
assertSame(table("myTable", "a", "b"), table("myTable", "a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffTable() {
|
||||
assertDifferent(table("myTable", "a", "b"), table("diffTable", "a", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_diffColumn() {
|
||||
assertDifferent(table("myTable", "a", "b"), table("myTable", "c", "b"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_moreColumns() {
|
||||
assertDifferent(table("myTable", "a", "b"), table("myTable", "a", "b", "c", "d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_when_lessColumns() {
|
||||
assertDifferent(table("myTable", "a", "b", "c", "d"), table("myTable", "a", "b"));
|
||||
}
|
||||
|
||||
void assertSame(TableJoin join1, TableJoin join2) {
|
||||
assertThat(join1).isEqualTo(join1);
|
||||
assertThat(join1.hashCode()).isEqualTo(join1.hashCode());
|
||||
}
|
||||
|
||||
|
||||
void assertDifferent(TableJoin join1, TableJoin join2) {
|
||||
assertThat(join1).isNotEqualTo(join2);
|
||||
assertThat(join1.hashCode()).isNotEqualTo(join2.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.composite.RCustomer;
|
||||
import org.tests.model.composite.RCustomerKey;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.embedded.UserInterestLive;
|
||||
import org.tests.model.embedded.UserInterestLiveKey;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestBeanDescriptorHasIdProperty extends BaseTestCase {
|
||||
|
||||
SpiEbeanServer spiServer;
|
||||
|
||||
public TestBeanDescriptorHasIdProperty() {
|
||||
Database server = DB.getDefault();
|
||||
spiServer = (SpiEbeanServer) server;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHasId() {
|
||||
|
||||
BeanDescriptor<Order> beanDescriptor = spiServer.descriptor(Order.class);
|
||||
assertNotNull(beanDescriptor.idProperty());
|
||||
assertEquals("id", beanDescriptor.idProperty().name());
|
||||
|
||||
assertNotNull(beanDescriptor.versionProperty());
|
||||
assertEquals("updtime", beanDescriptor.versionProperty().name());
|
||||
|
||||
Order order = new Order();
|
||||
|
||||
assertFalse(beanDescriptor.hasIdValue(entityBean(order)));
|
||||
assertFalse(beanDescriptor.hasVersionProperty(getIntercept(order)));
|
||||
|
||||
order.setId(23);
|
||||
order.setUpdtime(new Timestamp(System.currentTimeMillis()));
|
||||
|
||||
assertTrue(beanDescriptor.hasIdValue(entityBean(order)));
|
||||
assertTrue(beanDescriptor.hasVersionProperty(getIntercept(order)));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsReference() {
|
||||
|
||||
BeanDescriptor<Customer> beanDescriptor = spiServer.descriptor(Customer.class);
|
||||
|
||||
Customer order = new Customer();
|
||||
EntityBeanIntercept ebi = getIntercept(order);
|
||||
assertFalse(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
|
||||
order.setId(23);
|
||||
assertTrue(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
|
||||
order.setName("custName");
|
||||
assertFalse(beanDescriptor.referenceIdPropertyOnly(ebi));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isReference_withGeneratedOnInsertOnlyProperty_expect_false() {
|
||||
BeanDescriptor<UserInterestLive> descriptor = spiServer.descriptor(UserInterestLive.class);
|
||||
UserInterestLive bean = new UserInterestLive(new UserInterestLiveKey(1L, 2L));
|
||||
EntityBeanIntercept ebi = getIntercept(bean);
|
||||
assertFalse(descriptor.referenceIdPropertyOnly(ebi));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_getIdForJson() {
|
||||
|
||||
BeanDescriptor<Order> orderDesc = spiServer.descriptor(Order.class);
|
||||
|
||||
Order order = new Order();
|
||||
order.setId(42);
|
||||
assertEquals(42, orderDesc.idForJson(order));
|
||||
|
||||
assertEquals(42, orderDesc.convertIdFromJson(42));
|
||||
assertEquals(42, orderDesc.convertIdFromJson("42"));
|
||||
assertEquals(42, orderDesc.convertIdFromJson(42L));
|
||||
|
||||
|
||||
RCustomerKey key = new RCustomerKey();
|
||||
key.setCompany("comp");
|
||||
key.setName("fred");
|
||||
|
||||
RCustomer rCustomer = new RCustomer();
|
||||
rCustomer.setKey(key);
|
||||
|
||||
BeanDescriptor<RCustomer> rcustDesc = spiServer.descriptor(RCustomer.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> idForJson = (Map<String, Object>) rcustDesc.idForJson(rCustomer);
|
||||
assertEquals("comp", idForJson.get("company"));
|
||||
assertEquals("fred", idForJson.get("name"));
|
||||
assertEquals(2, idForJson.size());
|
||||
|
||||
RCustomerKey keyVal = (RCustomerKey) rcustDesc.convertIdFromJson(idForJson);
|
||||
assertEquals("comp", keyVal.getCompany());
|
||||
assertEquals("fred", keyVal.getName());
|
||||
|
||||
}
|
||||
|
||||
private EntityBean entityBean(Object bean) {
|
||||
return (EntityBean) bean;
|
||||
}
|
||||
|
||||
private EntityBeanIntercept getIntercept(Object bean) {
|
||||
return ((EntityBean) bean)._ebean_getIntercept();
|
||||
}
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestCollectionLoadedStatus extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
SpiEbeanServer server = (SpiEbeanServer) DB.getDefault();
|
||||
BeanDescriptor<Customer> custDesc = server.descriptor(Customer.class);
|
||||
|
||||
Customer customer = new Customer();
|
||||
EntityBean eb = (EntityBean) customer;
|
||||
EntityBeanIntercept ebi = eb._ebean_getIntercept();
|
||||
|
||||
BeanProperty contactsProperty = custDesc.beanProperty("contacts");
|
||||
assertFalse(ebi.isLoadedProperty(contactsProperty.propertyIndex()));
|
||||
|
||||
Object contactsViaInternal = contactsProperty.getValue(eb);
|
||||
assertNull(contactsViaInternal);
|
||||
assertFalse(ebi.isLoadedProperty(contactsProperty.propertyIndex()));
|
||||
|
||||
List<Contact> contacts = customer.getContacts();
|
||||
assertNotNull(contacts);
|
||||
assertTrue(contacts instanceof BeanCollection);
|
||||
assertTrue(ebi.isLoadedProperty(contactsProperty.propertyIndex()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.json.SpiJsonWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.Order.Status;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Date;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
public class TestDiffHelpInsertSimple extends BaseTestCase {
|
||||
|
||||
private final long firstTime = System.currentTimeMillis() - 10000;
|
||||
|
||||
private final Database server;
|
||||
|
||||
private final BeanDescriptor<Order> orderDesc;
|
||||
|
||||
public TestDiffHelpInsertSimple() {
|
||||
server = DB.getDefault();
|
||||
SpiEbeanServer spiServer = (SpiEbeanServer) server;
|
||||
orderDesc = spiServer.descriptor(Order.class);
|
||||
}
|
||||
|
||||
private Order createBaseOrder(Database server) {
|
||||
Order order1 = new Order();
|
||||
order1.setId(12);
|
||||
order1.setCretime(new Timestamp(firstTime));
|
||||
order1.setCustomer(server.reference(Customer.class, 1234));
|
||||
order1.setStatus(Status.NEW);
|
||||
//order1.setShipDate(new Date(firstTime));
|
||||
order1.setOrderDate(new Date(firstTime));
|
||||
return order1;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basic() throws IOException {
|
||||
|
||||
Date date = Date.valueOf("2000-01-01");
|
||||
|
||||
Order order1 = createBaseOrder(server);
|
||||
order1.setOrderDate(date);
|
||||
|
||||
StringWriter buffer = new StringWriter();
|
||||
|
||||
SpiJsonWriter jsonWriter = spiEbeanServer().jsonExtended().createJsonWriter(buffer);
|
||||
|
||||
orderDesc.jsonWriteForInsert(jsonWriter, (EntityBean) order1);
|
||||
jsonWriter.flush();
|
||||
|
||||
String asJson = buffer.toString();
|
||||
|
||||
assertThat(asJson).startsWith("{\"status\":\"NEW\",\"orderDate\":\"2000-01-01\"");
|
||||
assertThat(asJson).endsWith(",\"customer\":{\"id\":1234}}");
|
||||
}
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.json.SpiJsonWriter;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.embedded.EMain;
|
||||
import org.tests.model.embedded.Eembeddable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestDiffHelpInsertWithEmbedded extends BaseTestCase {
|
||||
|
||||
private final BeanDescriptor<EMain> emainDesc;
|
||||
|
||||
public TestDiffHelpInsertWithEmbedded() {
|
||||
Database server = DB.getDefault();
|
||||
SpiEbeanServer spiServer = (SpiEbeanServer) server;
|
||||
emainDesc = spiServer.descriptor(EMain.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simple() throws IOException {
|
||||
|
||||
EMain emain1 = createEMain();
|
||||
|
||||
String asJson = asInsertJson((EntityBean) emain1);
|
||||
|
||||
assertThat(asJson).contains("{\"name\":\"foo\",\"version\":13,\"embeddable\":{\"description\":\"bar\"}}");
|
||||
|
||||
}
|
||||
|
||||
private String asInsertJson(EntityBean emain1) throws IOException {
|
||||
StringWriter buffer = new StringWriter();
|
||||
|
||||
SpiJsonWriter jsonWriter = spiEbeanServer().jsonExtended().createJsonWriter(buffer);
|
||||
|
||||
emainDesc.jsonWriteForInsert(jsonWriter, emain1);
|
||||
jsonWriter.flush();
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void scalarPropertyAsNull() throws IOException {
|
||||
|
||||
EMain emain1 = createEMain();
|
||||
emain1.setName(null);
|
||||
|
||||
String asJson = asInsertJson((EntityBean) emain1);
|
||||
|
||||
assertThat(asJson).contains("{\"version\":13,\"embeddable\":{\"description\":\"bar\"}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void embeddedAsNull() throws IOException {
|
||||
|
||||
EMain emain1 = createEMain();
|
||||
emain1.setEmbeddable(null);
|
||||
|
||||
String asJson = asInsertJson((EntityBean) emain1);
|
||||
|
||||
assertThat(asJson).contains("{\"name\":\"foo\",\"version\":13}");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void embeddedPropertiesAsNull() throws IOException {
|
||||
|
||||
EMain emain1 = createEMain();
|
||||
emain1.getEmbeddable().setDescription(null);
|
||||
|
||||
String asJson = asInsertJson((EntityBean) emain1);
|
||||
|
||||
assertThat(asJson).contains("{\"name\":\"foo\",\"version\":13,\"embeddable\":{}}");
|
||||
}
|
||||
|
||||
private EMain createEMain() {
|
||||
EMain emain = new EMain();
|
||||
emain.setName("foo");
|
||||
emain.setVersion(13L);
|
||||
|
||||
Eembeddable embeddable = new Eembeddable();
|
||||
embeddable.setDescription("bar");
|
||||
emain.setEmbeddable(embeddable);
|
||||
return emain;
|
||||
}
|
||||
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.mappedsuper.ASimpleBean;
|
||||
import org.tests.model.mappedsuper.NotEnhancedMappedSuper;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestNotEnhancedMappedSuper extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void simpleBean_mappedSuperNotEnhanced_ok() {
|
||||
|
||||
ASimpleBean bean = new ASimpleBean();
|
||||
bean.setName("junk");
|
||||
|
||||
DB.save(bean);
|
||||
assertNotNull(bean.getId());
|
||||
|
||||
bean.setName("junk mod");
|
||||
DB.save(bean);
|
||||
|
||||
ASimpleBean fetched = DB.find(ASimpleBean.class, bean.getId());
|
||||
assertEquals("junk mod", fetched.getName());
|
||||
assertEquals(bean.getName(), fetched.getName());
|
||||
|
||||
DB.delete(bean);
|
||||
ASimpleBean fetched2 = DB.find(ASimpleBean.class, bean.getId());
|
||||
assertNull(fetched2);
|
||||
|
||||
NotEnhancedMappedSuper mappedSuper = new NotEnhancedMappedSuper();
|
||||
assertTrue((mappedSuper instanceof EntityBean));
|
||||
}
|
||||
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestReferenceWithConstructorProperties extends BaseTestCase {
|
||||
|
||||
/**
|
||||
* Test when constructor sets some properties.
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Order order = DB.reference(Order.class, 1);
|
||||
|
||||
BeanState beanState = DB.beanState(order);
|
||||
Set<String> loadedProps = beanState.loadedProps();
|
||||
|
||||
assertEquals(1, loadedProps.size());
|
||||
assertTrue(beanState.isReference());
|
||||
|
||||
// read the status invokes lazy loading
|
||||
order.getStatus();
|
||||
|
||||
assertFalse(beanState.isReference());
|
||||
assertNotNull(order.getCustomer());
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Customer;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
|
||||
public class GeneratedCounterLongTest extends BaseTestCase {
|
||||
|
||||
private GeneratedCounterLong counter = new GeneratedCounterLong();
|
||||
|
||||
private BeanProperty version = getBeanDescriptor(Customer.class).beanProperty("version");
|
||||
|
||||
@Test
|
||||
public void when_null_expect_IllegalStateException() {
|
||||
Customer customer = new Customer();
|
||||
assertThrows(IllegalStateException.class, () -> counter.getUpdateValue(version, (EntityBean)customer, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_set_expect_incremented() {
|
||||
Customer customer = new Customer();
|
||||
customer.setVersion(7L);
|
||||
Object value = counter.getUpdateValue(version, (EntityBean) customer, System.currentTimeMillis());
|
||||
|
||||
assertThat(value).isEqualTo(8L);
|
||||
}
|
||||
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class GeneratedInsertJavaTimeTest {
|
||||
|
||||
@Test
|
||||
public void test_generatedOnInsert() {
|
||||
|
||||
GeneratedProperty gen = new GeneratedInsertJavaTime.InstantDT();
|
||||
assertTrue(GeneratedWhenCreated.class.isInstance(gen));
|
||||
assertTrue(gen instanceof GeneratedWhenCreated);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import io.ebean.config.ClassLoadConfig;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class InsertTimestampFactoryTest {
|
||||
|
||||
InsertTimestampFactory factory = new InsertTimestampFactory(new ClassLoadConfig());
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Instant() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Instant.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof Instant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_LocalDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, LocalDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof LocalDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_OffsetDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, OffsetDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof OffsetDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Timestamp() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Timestamp.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_utilDate() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, java.util.Date.class, null, null);
|
||||
|
||||
GeneratedProperty insertTimestamp = factory.createInsertTimestamp(prop);
|
||||
Object value = insertTimestamp.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof java.util.Date);
|
||||
}
|
||||
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package io.ebeaninternal.server.deploy.generatedproperty;
|
||||
|
||||
import io.ebean.config.ClassLoadConfig;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanProperty;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.OffsetDateTime;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class UpdateTimestampFactoryTest {
|
||||
|
||||
|
||||
UpdateTimestampFactory factory = new UpdateTimestampFactory(new ClassLoadConfig());
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Instant() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Instant.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof Instant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_LocalDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, LocalDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof LocalDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_OffsetDateTime() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, OffsetDateTime.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof OffsetDateTime);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_Timestamp() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, Timestamp.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof Timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_createdTimestamp_utilDate() {
|
||||
|
||||
DeployBeanProperty prop = new DeployBeanProperty(null, java.util.Date.class, null, null);
|
||||
|
||||
GeneratedProperty generatedProperty = factory.createUpdateTimestamp(prop);
|
||||
Object value = generatedProperty.getInsertValue(null, null, System.currentTimeMillis());
|
||||
assertTrue(value instanceof java.util.Date);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package io.ebeaninternal.server.deploy.parse;
|
||||
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.dbplatform.sqlserver.SqlServer17Platform;
|
||||
import io.ebeaninternal.server.core.bootup.BootupClasses;
|
||||
import io.ebeaninternal.server.deploy.generatedproperty.GeneratedPropertyFactory;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
|
||||
import io.ebeaninternal.server.type.DefaultTypeManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AnnotationClassTest {
|
||||
|
||||
@Test
|
||||
public void convertColumnNames_when_AllQuotedIdentifiersIsTrue() {
|
||||
|
||||
AnnotationClass annotationClass = createAnnotationClass(sqlServerPlatform(true));
|
||||
|
||||
String[] colNames = {"Col1", "Col2"};
|
||||
|
||||
final String[] columnNames = annotationClass.convertColumnNames(colNames);
|
||||
|
||||
assertThat(columnNames.length).isEqualTo(2);
|
||||
assertThat(columnNames[0]).isEqualTo("[Col1]");
|
||||
assertThat(columnNames[1]).isEqualTo("[Col2]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertColumnNames_when_AllQuotedIdentifiersIsFalse() {
|
||||
|
||||
AnnotationClass annotationClass = createAnnotationClass(sqlServerPlatform(false));
|
||||
|
||||
String[] colNames = {"Col1", "`Col2`", "col3"};
|
||||
|
||||
final String[] columnNames = annotationClass.convertColumnNames(colNames);
|
||||
|
||||
assertThat(columnNames.length).isEqualTo(3);
|
||||
assertThat(columnNames[0]).isEqualTo("Col1");
|
||||
assertThat(columnNames[1]).isEqualTo("[Col2]");
|
||||
assertThat(columnNames[2]).isEqualTo("col3");
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private AnnotationClass createAnnotationClass(DatabaseConfig config) {
|
||||
DeployUtil deployUtil = new DeployUtil(new DefaultTypeManager(config, new BootupClasses()), config);
|
||||
|
||||
DeployBeanInfo deployBeanInfo = new DeployBeanInfo(deployUtil, new DeployBeanDescriptor<>(null, null, null));
|
||||
ReadAnnotationConfig readAnnotationConfig = new ReadAnnotationConfig(new GeneratedPropertyFactory(true, new DatabaseConfig(), Collections.emptyList()), "","", new DatabaseConfig());
|
||||
return new AnnotationClass(deployBeanInfo, readAnnotationConfig);
|
||||
}
|
||||
|
||||
private DatabaseConfig sqlServerPlatform(boolean allQuotedIdentifiers) {
|
||||
SqlServer17Platform sqlServer17Platform = new SqlServer17Platform();
|
||||
DatabaseConfig config = new DatabaseConfig();
|
||||
config.setDatabasePlatform(sqlServer17Platform);
|
||||
config.setAllQuotedIdentifiers(allQuotedIdentifiers);
|
||||
|
||||
sqlServer17Platform.configure(config.getPlatformConfig());
|
||||
return config;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user