From 25bdfff02d746659a52e8c542dd2e7ef2df1331a Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 11:55:15 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/api/conf/HolderKit.java | 75 ++++++++++++++++++- .../com/fanruan/api/conf/impl/ColConf.java | 19 +++++ .../com/fanruan/api/conf/impl/MapConf.java | 19 +++++ .../com/fanruan/api/conf/impl/ObjConf.java | 16 ++++ .../fanruan/api/conf/impl/ObjectColConf.java | 22 ++++++ .../fanruan/api/conf/impl/ObjectMapConf.java | 26 +++++++ .../com/fanruan/api/conf/impl/SimConf.java | 17 +++++ 7 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/fanruan/api/conf/impl/ColConf.java create mode 100644 src/main/java/com/fanruan/api/conf/impl/MapConf.java create mode 100644 src/main/java/com/fanruan/api/conf/impl/ObjConf.java create mode 100644 src/main/java/com/fanruan/api/conf/impl/ObjectColConf.java create mode 100644 src/main/java/com/fanruan/api/conf/impl/ObjectMapConf.java create mode 100644 src/main/java/com/fanruan/api/conf/impl/SimConf.java diff --git a/src/main/java/com/fanruan/api/conf/HolderKit.java b/src/main/java/com/fanruan/api/conf/HolderKit.java index cb93332..014fa10 100644 --- a/src/main/java/com/fanruan/api/conf/HolderKit.java +++ b/src/main/java/com/fanruan/api/conf/HolderKit.java @@ -1,7 +1,13 @@ package com.fanruan.api.conf; +import com.fanruan.api.conf.impl.ObjConf; +import com.fanruan.api.conf.impl.ObjectColConf; +import com.fanruan.api.conf.impl.ObjectMapConf; +import com.fanruan.api.conf.impl.SimConf; import com.fr.config.holder.Conf; -import com.fr.config.holder.factory.Holders; + +import java.util.Collection; +import java.util.Map; /** * @author richie @@ -11,11 +17,74 @@ import com.fr.config.holder.factory.Holders; */ public class HolderKit { + /** + * 初始化一个基本对象类型的配置 + * @param t 初始值 + * @param 类型 + * @return 配置对象 + */ public static Conf simple(T t) { - return Holders.simple(t); + return new SimConf<>(t); } + /** + * 初始化一个对象类型的配置 + * @param t 初始值 + * @param type 对象class类 + * @param 类型 + * @return 配置对象 + */ public static Conf obj(T t, Class type) { - return Holders.obj(t, type); + return new ObjConf<>(t, type); + } + + /** + * 初始化一个集合类型的配置 + * @param collection 初始值 + * @param type 对象class类型 + * @param 类型 + * @return 配置对象 + */ + public static ObjectColConf> objCollection(Collection collection, Class type) { + return new ObjectColConf<>(collection, type); + } + + /** + * 初始化一个集合类型的配置 + * @param collection 初始值 + * @param type 对象class类型 + * @param order 是否是有序的配置 + * @param 类型 + * @return 配置对象 + */ + public static ObjectColConf> objCollection(Collection collection, Class type, boolean order) { + return new ObjectColConf<>(collection, type, order); + } + + /** + * 初始化一个字典类型的配置 + * @param map 初始值 + * @param keyType 键class类型 + * @param valueType 值class类型 + * @param 键类型 + * @param 值类型 + * @return 配置对象 + */ + public static ObjectMapConf> objMap(Map map, Class keyType, Class valueType) { + return new ObjectMapConf<>(map, keyType, valueType); + } + + /** + * 初始化一个字典类型的配置 + * @param map 初始值 + * @param keyType 键class类型 + * @param valueType 值class类型 + * @param order 是否是有序配置 + * @param 键类型 + * @param 值类型 + * @return 配置对象 + */ + public static ObjectMapConf> objMap(Map map, Class keyType, Class valueType, boolean order) { + return new ObjectMapConf<>(map, keyType, valueType, order); } } diff --git a/src/main/java/com/fanruan/api/conf/impl/ColConf.java b/src/main/java/com/fanruan/api/conf/impl/ColConf.java new file mode 100644 index 0000000..77718d6 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/ColConf.java @@ -0,0 +1,19 @@ +package com.fanruan.api.conf.impl; + +import java.util.Collection; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class ColConf extends com.fr.config.holder.impl.ColConf { + + public ColConf(String property, Collection collection, Class valueType) { + super(property, collection, valueType); + } + + public ColConf(Collection collection, Class valueType) { + super(collection, valueType); + } +} diff --git a/src/main/java/com/fanruan/api/conf/impl/MapConf.java b/src/main/java/com/fanruan/api/conf/impl/MapConf.java new file mode 100644 index 0000000..1bbf120 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/MapConf.java @@ -0,0 +1,19 @@ +package com.fanruan.api.conf.impl; + +import java.util.Map; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class MapConf extends com.fr.config.holder.impl.MapConf { + + public MapConf(String property, Map map, Class keyType, Class valueType) { + super(property, map, keyType, valueType); + } + + public MapConf(Map map, Class keyType, Class valueType) { + super(map, keyType, valueType); + } +} diff --git a/src/main/java/com/fanruan/api/conf/impl/ObjConf.java b/src/main/java/com/fanruan/api/conf/impl/ObjConf.java new file mode 100644 index 0000000..57c3d71 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/ObjConf.java @@ -0,0 +1,16 @@ +package com.fanruan.api.conf.impl; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class ObjConf extends com.fr.config.holder.impl.ObjConf { + public ObjConf(String property, T t, Class classType) { + super(property, t, classType); + } + + public ObjConf(T t, Class classType) { + super(t, classType); + } +} diff --git a/src/main/java/com/fanruan/api/conf/impl/ObjectColConf.java b/src/main/java/com/fanruan/api/conf/impl/ObjectColConf.java new file mode 100644 index 0000000..0c175c0 --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/ObjectColConf.java @@ -0,0 +1,22 @@ +package com.fanruan.api.conf.impl; + +import java.util.Collection; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class ObjectColConf extends com.fr.config.holder.impl.ObjectColConf { + public ObjectColConf(String property, Collection collection, Class valueType) { + super(property, collection, valueType); + } + + public ObjectColConf(Collection collection, Class valueType) { + super(collection, valueType); + } + + public ObjectColConf(Collection collection, Class valueType, boolean order) { + super(collection, valueType, order); + } +} diff --git a/src/main/java/com/fanruan/api/conf/impl/ObjectMapConf.java b/src/main/java/com/fanruan/api/conf/impl/ObjectMapConf.java new file mode 100644 index 0000000..22280cd --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/ObjectMapConf.java @@ -0,0 +1,26 @@ +package com.fanruan.api.conf.impl; + +import java.util.Map; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class ObjectMapConf extends com.fr.config.holder.impl.ObjectMapConf { + public ObjectMapConf(String property, Map map, Class keyType, Class valueType) { + super(property, map, keyType, valueType); + } + + public ObjectMapConf(String property, Map map, Class keyType, Class valueType, boolean order) { + super(property, map, keyType, valueType, order); + } + + public ObjectMapConf(Map map, Class keyType, Class valueType, boolean order) { + super(map, keyType, valueType, order); + } + + public ObjectMapConf(Map map, Class keyType, Class valueType) { + super(map, keyType, valueType); + } +} diff --git a/src/main/java/com/fanruan/api/conf/impl/SimConf.java b/src/main/java/com/fanruan/api/conf/impl/SimConf.java new file mode 100644 index 0000000..15e320c --- /dev/null +++ b/src/main/java/com/fanruan/api/conf/impl/SimConf.java @@ -0,0 +1,17 @@ +package com.fanruan.api.conf.impl; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class SimConf extends com.fr.config.holder.impl.SimConf { + + public SimConf(T t) { + super(t); + } + + public SimConf(String property, T t) { + super(property, t); + } +} From 2592b7a2099c34b4b09961be75152c3c7abc0f50 Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 11:55:56 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E7=B1=BB=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fanruan/api/conf/HolderKit.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/fanruan/api/conf/HolderKit.java b/src/main/java/com/fanruan/api/conf/HolderKit.java index 014fa10..6268e47 100644 --- a/src/main/java/com/fanruan/api/conf/HolderKit.java +++ b/src/main/java/com/fanruan/api/conf/HolderKit.java @@ -14,6 +14,7 @@ import java.util.Map; * @version 10.0 * Created by richie on 2019-08-15 * 配置对象操作类 + * TODO:补充单元测试 */ public class HolderKit { From 2423b973bbe7096a2139a9c6eb04538c324a4dcb Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 12:49:50 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fanruan/api/data/TableDataKitTest.java | 59 +++++++++++++++++++ .../com/fanruan/api/util/StringKitTest.java | 29 +++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/test/java/com/fanruan/api/util/StringKitTest.java diff --git a/src/test/java/com/fanruan/api/data/TableDataKitTest.java b/src/test/java/com/fanruan/api/data/TableDataKitTest.java index 78dd869..7367acc 100644 --- a/src/test/java/com/fanruan/api/data/TableDataKitTest.java +++ b/src/test/java/com/fanruan/api/data/TableDataKitTest.java @@ -1,8 +1,22 @@ package com.fanruan.api.data; import com.fanruan.api.Prepare; +import com.fr.base.AbstractTableData; +import com.fr.base.TableData; +import com.fr.data.TableDataSource; +import com.fr.file.TableDataConfig; +import com.fr.general.data.DataModel; +import com.fr.main.impl.WorkBook; +import com.fr.script.Calculator; +import com.fr.stable.ParameterProvider; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; +import org.junit.Assert; import org.junit.Test; +import java.util.HashMap; +import java.util.Map; + import static org.junit.Assert.*; /** @@ -14,9 +28,54 @@ public class TableDataKitTest extends Prepare { @Test public void getTableData() { + Map map = new HashMap<>(); + map.put("test", TD); + TableDataConfig.getInstance().setTableDatas(map); + Calculator calculator = Calculator.createCalculator(); + calculator.setAttribute(TableDataSource.KEY, new WorkBook()); + TableData r = TableDataKit.getTableData(calculator, "test"); + Assert.assertEquals(TD, r); } @Test public void testGetTableData() { + Calculator calculator = Calculator.createCalculator(); + WorkBook workBook = new WorkBook(); + workBook.putTableData("test", TD); + calculator.setAttribute(TableDataSource.KEY, workBook); + TableData r = TableDataKit.getTableData(calculator, "test"); + Assert.assertEquals(TD, r); } + + private static final TableData TD = new AbstractTableData() { + @Override + public ParameterProvider[] getParameters(Calculator calculator) { + return new ParameterProvider[0]; + } + + @Override + public DataModel createDataModel(Calculator calculator) { + return null; + } + + @Override + public DataModel createDataModel(Calculator calculator, String s) { + return null; + } + + @Override + public DataModel createDataModel(Calculator calculator, int i) { + return null; + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + }; } \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/util/StringKitTest.java b/src/test/java/com/fanruan/api/util/StringKitTest.java new file mode 100644 index 0000000..be66448 --- /dev/null +++ b/src/test/java/com/fanruan/api/util/StringKitTest.java @@ -0,0 +1,29 @@ +package com.fanruan.api.util; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class StringKitTest { + + @Test + public void isEmpty() { + } + + @Test + public void isNotEmpty() { + } + + @Test + public void isBlank() { + } + + @Test + public void isNotBlank() { + } +} \ No newline at end of file From 6d5cd48d444eb6bef3373eef61e894fd7e15fefb Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 13:51:31 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/fanruan/api/Prepare.java | 4 ++ .../fanruan/api/data/TableDataKitTest.java | 68 ++++++------------- .../java/com/fanruan/api/data/TestTD.java | 59 ++++++++++++++++ 3 files changed, 83 insertions(+), 48 deletions(-) create mode 100644 src/test/java/com/fanruan/api/data/TestTD.java diff --git a/src/test/java/com/fanruan/api/Prepare.java b/src/test/java/com/fanruan/api/Prepare.java index caba8ee..d74dfbf 100644 --- a/src/test/java/com/fanruan/api/Prepare.java +++ b/src/test/java/com/fanruan/api/Prepare.java @@ -8,6 +8,8 @@ import com.fr.runtime.FineRuntime; import com.fr.store.StateHubManager; import com.fr.store.impl.MemoryLock; import com.fr.store.impl.MemoryStore; +import com.fr.transaction.Configurations; +import com.fr.transaction.LocalConfigurationHelper; import org.junit.After; import org.junit.Before; @@ -24,6 +26,7 @@ public class Prepare { DaoContext.setEntityDao(new LocalEntityDao()); DaoContext.setClassHelperDao(new LocalClassHelperDao()); DaoContext.setXmlEntityDao(new LocalXmlEntityDao()); + Configurations.setHelper(new LocalConfigurationHelper()); StateHubManager.setStorage(new MemoryStore()); StateHubManager.setLock(new MemoryLock()); } @@ -33,6 +36,7 @@ public class Prepare { DaoContext.setEntityDao(null); DaoContext.setClassHelperDao(null); DaoContext.setXmlEntityDao(null); + Configurations.setHelper(null); StateHubManager.setStorage(null); StateHubManager.setLock(null); } diff --git a/src/test/java/com/fanruan/api/data/TableDataKitTest.java b/src/test/java/com/fanruan/api/data/TableDataKitTest.java index 7367acc..f898f40 100644 --- a/src/test/java/com/fanruan/api/data/TableDataKitTest.java +++ b/src/test/java/com/fanruan/api/data/TableDataKitTest.java @@ -1,24 +1,17 @@ package com.fanruan.api.data; import com.fanruan.api.Prepare; -import com.fr.base.AbstractTableData; import com.fr.base.TableData; +import com.fr.config.Configuration; import com.fr.data.TableDataSource; import com.fr.file.TableDataConfig; -import com.fr.general.data.DataModel; import com.fr.main.impl.WorkBook; import com.fr.script.Calculator; -import com.fr.stable.ParameterProvider; -import com.fr.stable.xml.XMLPrintWriter; -import com.fr.stable.xml.XMLableReader; +import com.fr.transaction.Configurations; +import com.fr.transaction.Worker; import org.junit.Assert; import org.junit.Test; -import java.util.HashMap; -import java.util.Map; - -import static org.junit.Assert.*; - /** * @author richie * @version 10.0 @@ -28,54 +21,33 @@ public class TableDataKitTest extends Prepare { @Test public void getTableData() { - Map map = new HashMap<>(); - map.put("test", TD); - TableDataConfig.getInstance().setTableDatas(map); + TestTD td = new TestTD(); + Configurations.update(new Worker() { + @Override + public void run() { + TableDataConfig.getInstance().addTableData("first", td); + } + + @Override + public Class[] targets() { + return new Class[]{TableDataConfig.class}; + } + }); Calculator calculator = Calculator.createCalculator(); calculator.setAttribute(TableDataSource.KEY, new WorkBook()); - TableData r = TableDataKit.getTableData(calculator, "test"); - Assert.assertEquals(TD, r); + TableData r = TableDataKit.getTableData(calculator, "first"); + Assert.assertEquals(td, r); } @Test public void testGetTableData() { + TestTD td = new TestTD(); Calculator calculator = Calculator.createCalculator(); WorkBook workBook = new WorkBook(); - workBook.putTableData("test", TD); + workBook.putTableData("test", td); calculator.setAttribute(TableDataSource.KEY, workBook); TableData r = TableDataKit.getTableData(calculator, "test"); - Assert.assertEquals(TD, r); + Assert.assertEquals(td, r); } - private static final TableData TD = new AbstractTableData() { - @Override - public ParameterProvider[] getParameters(Calculator calculator) { - return new ParameterProvider[0]; - } - - @Override - public DataModel createDataModel(Calculator calculator) { - return null; - } - - @Override - public DataModel createDataModel(Calculator calculator, String s) { - return null; - } - - @Override - public DataModel createDataModel(Calculator calculator, int i) { - return null; - } - - @Override - public void readXML(XMLableReader xmLableReader) { - - } - - @Override - public void writeXML(XMLPrintWriter xmlPrintWriter) { - - } - }; } \ No newline at end of file diff --git a/src/test/java/com/fanruan/api/data/TestTD.java b/src/test/java/com/fanruan/api/data/TestTD.java new file mode 100644 index 0000000..f531706 --- /dev/null +++ b/src/test/java/com/fanruan/api/data/TestTD.java @@ -0,0 +1,59 @@ +package com.fanruan.api.data; + +import com.fanruan.api.conf.HolderKit; +import com.fr.base.AbstractTableData; +import com.fr.config.holder.Conf; +import com.fr.general.data.DataModel; +import com.fr.script.Calculator; +import com.fr.stable.ParameterProvider; +import com.fr.stable.xml.XMLPrintWriter; +import com.fr.stable.xml.XMLableReader; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class TestTD extends AbstractTableData { + + private Conf count = HolderKit.simple(10); + + public TestTD() { + + } + + @Override + public ParameterProvider[] getParameters(Calculator calculator) { + return new ParameterProvider[0]; + } + + @Override + public DataModel createDataModel(Calculator calculator) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public DataModel createDataModel(Calculator calculator, String s) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public DataModel createDataModel(Calculator calculator, int i) { + return DataModel.EMPTY_DATAMODEL; + } + + @Override + public void readXML(XMLableReader xmLableReader) { + + } + + @Override + public void writeXML(XMLPrintWriter xmlPrintWriter) { + + } + + @Override + public boolean equals(Object obj) { + return obj instanceof TestTD; + } +} From 23383b91aa42f7a788cc66bf3c9e492088bf27ee Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 16:57:48 +0800 Subject: [PATCH 5/6] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fanruan/api/data/TableDataKit.java | 35 +++++++++++++++++-- .../fanruan/api/data/TableDataKitTest.java | 19 ++-------- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/fanruan/api/data/TableDataKit.java b/src/main/java/com/fanruan/api/data/TableDataKit.java index 6039b01..333245f 100644 --- a/src/main/java/com/fanruan/api/data/TableDataKit.java +++ b/src/main/java/com/fanruan/api/data/TableDataKit.java @@ -3,11 +3,15 @@ package com.fanruan.api.data; import com.fr.base.TableData; import com.fr.data.TableDataSource; import com.fr.data.api.TableDataAssist; +import com.fr.file.TableDataConfig; import com.fr.script.Calculator; import com.fr.stable.script.CalculatorProvider; +import com.fr.third.guava.collect.Maps; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Map; + /** * @author richie * @version 10.0 @@ -26,7 +30,7 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, String name) { + public static @Nullable TableData getTableData(@NotNull CalculatorProvider cal, @NotNull String name) { return TableDataAssist.getTableData((Calculator) cal, name); } @@ -40,7 +44,34 @@ public class TableDataKit { * @param name 数据集名字 * @return 数据集 */ - public static @Nullable TableData getTableData(@NotNull TableDataSource source, String name) { + public static @Nullable TableData getTableData(@NotNull TableDataSource source, @NotNull String name) { return TableDataAssist.getTableData(source, name); } + + /** + * 获取所有的服务器数据集 + * @return 所有的服务器数据集组成的键值对集合 + */ + public static @NotNull Map getAllServerTableData() { + Map maps = TableDataConfig.getInstance().getTableDatas(); + return Maps.newHashMap(maps); + } + + /** + * 根据名字获取服务器数据集 + * @param name 待查找的服务器数据集的名字 + * @return 服务器数据集,如果没有这个名字的服务器数据集,则返回null + */ + public static @Nullable TableData findTableData(@NotNull String name) { + return TableDataConfig.getInstance().getTableData(name); + } + + /** + * 重命名数据集 + * @param oldName 原来的名字 + * @param newName 新名字 + */ + public static void renameTableData(@NotNull String oldName, @NotNull String newName) { + TableDataConfig.getInstance().renameTableData(oldName, newName); + } } diff --git a/src/test/java/com/fanruan/api/data/TableDataKitTest.java b/src/test/java/com/fanruan/api/data/TableDataKitTest.java index f898f40..cb8e78f 100644 --- a/src/test/java/com/fanruan/api/data/TableDataKitTest.java +++ b/src/test/java/com/fanruan/api/data/TableDataKitTest.java @@ -2,13 +2,10 @@ package com.fanruan.api.data; import com.fanruan.api.Prepare; import com.fr.base.TableData; -import com.fr.config.Configuration; import com.fr.data.TableDataSource; import com.fr.file.TableDataConfig; import com.fr.main.impl.WorkBook; import com.fr.script.Calculator; -import com.fr.transaction.Configurations; -import com.fr.transaction.Worker; import org.junit.Assert; import org.junit.Test; @@ -22,17 +19,7 @@ public class TableDataKitTest extends Prepare { @Test public void getTableData() { TestTD td = new TestTD(); - Configurations.update(new Worker() { - @Override - public void run() { - TableDataConfig.getInstance().addTableData("first", td); - } - - @Override - public Class[] targets() { - return new Class[]{TableDataConfig.class}; - } - }); + TableDataConfig.getInstance().addTableData("first", td); Calculator calculator = Calculator.createCalculator(); calculator.setAttribute(TableDataSource.KEY, new WorkBook()); TableData r = TableDataKit.getTableData(calculator, "first"); @@ -42,11 +29,9 @@ public class TableDataKitTest extends Prepare { @Test public void testGetTableData() { TestTD td = new TestTD(); - Calculator calculator = Calculator.createCalculator(); WorkBook workBook = new WorkBook(); workBook.putTableData("test", td); - calculator.setAttribute(TableDataSource.KEY, workBook); - TableData r = TableDataKit.getTableData(calculator, "test"); + TableData r = TableDataKit.getTableData(workBook, "test"); Assert.assertEquals(td, r); } From 21f405bc1b3539b242861cea87f72b65237cc09a Mon Sep 17 00:00:00 2001 From: richie Date: Mon, 19 Aug 2019 17:37:36 +0800 Subject: [PATCH 6/6] =?UTF-8?q?url=E5=88=AB=E5=90=8D=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/api/net/URLAliasKit.java | 96 +++++++++++++++++++ .../com/fanruan/api/net/URLAliasKitTest.java | 75 +++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 src/main/java/com/fanruan/api/net/URLAliasKit.java create mode 100644 src/test/java/com/fanruan/api/net/URLAliasKitTest.java diff --git a/src/main/java/com/fanruan/api/net/URLAliasKit.java b/src/main/java/com/fanruan/api/net/URLAliasKit.java new file mode 100644 index 0000000..eb31b8f --- /dev/null +++ b/src/main/java/com/fanruan/api/net/URLAliasKit.java @@ -0,0 +1,96 @@ +package com.fanruan.api.net; + +import com.fr.decision.webservice.url.alias.URLAlias; +import com.fr.decision.webservice.url.alias.URLAliasFactory; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + * 路由工具类 + * 宽泛匹配:/foo 和 /aaa/bbb/foo 是匹配的 + */ +public class URLAliasKit { + + /** + * 创建路由的别名 + * + * @param aliasPath 别名 + * @param targetURL 原始路由 + * @return 别名对象 + */ + public static URLAlias createRawAlias(String aliasPath, String targetURL) { + return URLAliasFactory.createRawAlias(aliasPath, targetURL); + } + + /** + * 创建路由的别名 + * + * @param aliasPath 别名 + * @param targetURL 原始路由 + * @param wideRange 是否宽泛匹配 + * @return 别名对象 + */ + public static URLAlias createRawAlias(String aliasPath, String targetURL, boolean wideRange) { + return URLAliasFactory.createRawAlias(aliasPath, targetURL, wideRange); + } + + /** + * 创建决策平台的路由别名 + * + * @param aliasPath 别名 + * @param decisionTargetURL 原始路由地址 + * @return 加了决策平台servlet名字前缀的别名对象 + */ + public static URLAlias createDecisionAlias(String aliasPath, String decisionTargetURL) { + return URLAliasFactory.createDecisionAlias(aliasPath, decisionTargetURL); + } + + /** + * 创建决策平台的路由别名 + * + * @param aliasPath 别名 + * @param decisionTargetURL 原始路由地址 + * @param wideRange 是否宽泛匹配 + * @return 加了决策平台servlet名字前缀的别名对象 + */ + public static URLAlias createDecisionAlias(String aliasPath, String decisionTargetURL, boolean wideRange) { + return URLAliasFactory.createDecisionAlias(aliasPath, decisionTargetURL, wideRange); + } + + /** + * 创建插件的路由别名 + * + * @param aliasPath 别名 + * @param pluginPath 插件请求地址 + * @return 别名对象 + */ + public static URLAlias createPluginAlias(String aliasPath, String pluginPath) { + return URLAliasFactory.createPluginAlias(aliasPath, pluginPath); + } + + /** + * 创建插件的路由别名 + * + * @param aliasPath 别名 + * @param pluginPath 插件请求地址 + * @param isPublic 是否为公开可访问的地址 + * @return 别名对象 + */ + public static URLAlias createPluginAlias(String aliasPath, String pluginPath, boolean isPublic) { + return URLAliasFactory.createPluginAlias(aliasPath, pluginPath, isPublic); + } + + /** + * 创建插件的路由别名 + * + * @param aliasPath 别名 + * @param pluginPath 插件请求地址 + * @param isPublic 是否为公开可访问的地址 + * @param wideRange 是否宽泛匹配 + * @return 别名对象 + */ + public static URLAlias createPluginAlias(String aliasPath, String pluginPath, boolean isPublic, boolean wideRange) { + return URLAliasFactory.createPluginAlias(aliasPath, pluginPath, isPublic, wideRange); + } +} diff --git a/src/test/java/com/fanruan/api/net/URLAliasKitTest.java b/src/test/java/com/fanruan/api/net/URLAliasKitTest.java new file mode 100644 index 0000000..7867bda --- /dev/null +++ b/src/test/java/com/fanruan/api/net/URLAliasKitTest.java @@ -0,0 +1,75 @@ +package com.fanruan.api.net; + +import com.fanruan.api.Prepare; +import com.fr.decision.webservice.url.alias.URLAlias; +import com.fr.decision.webservice.url.alias.impl.PluginURLAlias; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author richie + * @version 10.0 + * Created by richie on 2019-08-19 + */ +public class URLAliasKitTest extends Prepare { + + @Test + public void raw() { + URLAlias alias = URLAliasKit.createRawAlias("/foo", "/aaa/bbb/foo"); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/aaa/bbb/foo"); + Assert.assertFalse(alias.isWideRange()); + } + + @Test + public void raw2() { + URLAlias alias = URLAliasKit.createRawAlias("/foo", "/aaa/bbb/foo", true); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/aaa/bbb/foo"); + Assert.assertTrue(alias.isWideRange()); + } + + @Test + public void decision() { + URLAlias alias = URLAliasKit.createDecisionAlias("/foo", "/aaa/bbb/foo"); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/decision/aaa/bbb/foo"); + Assert.assertFalse(alias.isWideRange()); + } + + @Test + public void decision2() { + URLAlias alias = URLAliasKit.createDecisionAlias("/foo", "/aaa/bbb/foo", true); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/decision/aaa/bbb/foo"); + Assert.assertTrue(alias.isWideRange()); + } + + @Test + public void plugin() { + URLAlias alias = URLAliasKit.createPluginAlias("/foo", "/aaa/bbb/foo"); + ((PluginURLAlias)alias).setPluginId("abcd"); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/decision/plugin/private/abcd/aaa/bbb/foo"); + Assert.assertFalse(alias.isWideRange()); + } + + @Test + public void plugin2() { + URLAlias alias = URLAliasKit.createPluginAlias("/foo", "/aaa/bbb/foo", true); + ((PluginURLAlias)alias).setPluginId("abcd"); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/decision/plugin/public/abcd/aaa/bbb/foo"); + Assert.assertFalse(alias.isWideRange()); + } + + @Test + public void plugin3() { + URLAlias alias = URLAliasKit.createPluginAlias("/foo", "/aaa/bbb/foo", true, true); + ((PluginURLAlias)alias).setPluginId("abcd"); + Assert.assertEquals(alias.getShortPath(), "/foo"); + Assert.assertEquals(alias.getTargetURL(), "/decision/plugin/public/abcd/aaa/bbb/foo"); + Assert.assertTrue(alias.isWideRange()); + } + +} \ No newline at end of file