add mapping support

This commit is contained in:
温少
2012-03-12 16:31:58 +08:00
parent 6a493d1e3b
commit 05e310f36d
13 changed files with 449 additions and 42 deletions
@@ -0,0 +1,45 @@
package com.alibaba.druid.bvt.mapping;
import junit.framework.TestCase;
import org.junit.Assert;
import com.alibaba.druid.mapping.Entity;
import com.alibaba.druid.mapping.MappingEngine;
import com.alibaba.druid.mapping.Property;
public class MappingVisitorTest extends TestCase {
MappingEngine engine = new MappingEngine();
protected void setUp() throws Exception {
Entity entity = new Entity();
entity.setName("设备");
entity.setDescription("Device");
entity.setTableName("device");
entity.addProperty(new Property("编号", "", "serviceTag"));
entity.addProperty(new Property("IP地址", "", "ip"));
engine.addEntity(entity);
}
public void test_0() throws Exception {
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device", engine.explain("select *"));
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'",
engine.explain("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
}
public void test_1() throws Exception {
engine.setMaxLimit(10);
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nLIMIT 10", engine.explain("select *"));
Assert.assertEquals("SELECT serviceTag AS \"编号\", ip AS \"IP地址\"\nFROM device\nWHERE ip = '127.0.0.1'\nLIMIT 10",
engine.explain("select 编号, IP地址 WHERE IP地址 = '127.0.0.1'"));
engine.setMaxLimit(null);
}
}