Browse Source

Merge branch 'master' of https://cloud.finedevelop.com/scm/~zhaojunzhe/finekit

* 'master' of https://cloud.finedevelop.com/scm/~zhaojunzhe/finekit:
  url别名工具类
  单元测试
  单元测试
  单元测试
  配置类的工具方法
  配置类的工具方法
pull/1/head
zjz1993 5 years ago
parent
commit
9d73651877
  1. 76
      src/main/java/com/fanruan/api/conf/HolderKit.java
  2. 19
      src/main/java/com/fanruan/api/conf/impl/ColConf.java
  3. 19
      src/main/java/com/fanruan/api/conf/impl/MapConf.java
  4. 16
      src/main/java/com/fanruan/api/conf/impl/ObjConf.java
  5. 22
      src/main/java/com/fanruan/api/conf/impl/ObjectColConf.java
  6. 26
      src/main/java/com/fanruan/api/conf/impl/ObjectMapConf.java
  7. 17
      src/main/java/com/fanruan/api/conf/impl/SimConf.java
  8. 35
      src/main/java/com/fanruan/api/data/TableDataKit.java
  9. 96
      src/main/java/com/fanruan/api/net/URLAliasKit.java
  10. 4
      src/test/java/com/fanruan/api/Prepare.java
  11. 20
      src/test/java/com/fanruan/api/data/TableDataKitTest.java
  12. 59
      src/test/java/com/fanruan/api/data/TestTD.java
  13. 75
      src/test/java/com/fanruan/api/net/URLAliasKitTest.java
  14. 29
      src/test/java/com/fanruan/api/util/StringKitTest.java

76
src/main/java/com/fanruan/api/conf/HolderKit.java

@ -1,21 +1,91 @@
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
* @version 10.0
* Created by richie on 2019-08-15
* 配置对象操作类
* TODO:补充单元测试
*/
public class HolderKit {
/**
* 初始化一个基本对象类型的配置
* @param t 初始值
* @param <T> 类型
* @return 配置对象
*/
public static <T> Conf<T> simple(T t) {
return Holders.simple(t);
return new SimConf<>(t);
}
/**
* 初始化一个对象类型的配置
* @param t 初始值
* @param type 对象class类
* @param <T> 类型
* @return 配置对象
*/
public static <T> Conf<T> obj(T t, Class<T> type) {
return Holders.obj(t, type);
return new ObjConf<>(t, type);
}
/**
* 初始化一个集合类型的配置
* @param collection 初始值
* @param type 对象class类型
* @param <T> 类型
* @return 配置对象
*/
public static <T> ObjectColConf<Collection<T>> objCollection(Collection<T> collection, Class<T> type) {
return new ObjectColConf<>(collection, type);
}
/**
* 初始化一个集合类型的配置
* @param collection 初始值
* @param type 对象class类型
* @param order 是否是有序的配置
* @param <T> 类型
* @return 配置对象
*/
public static <T> ObjectColConf<Collection<T>> objCollection(Collection<T> collection, Class<T> type, boolean order) {
return new ObjectColConf<>(collection, type, order);
}
/**
* 初始化一个字典类型的配置
* @param map 初始值
* @param keyType 键class类型
* @param valueType 值class类型
* @param <K> 键类型
* @param <V> 值类型
* @return 配置对象
*/
public static <K, V> ObjectMapConf<Map<K, V>> objMap(Map<K, V> map, Class<K> keyType, Class<V> valueType) {
return new ObjectMapConf<>(map, keyType, valueType);
}
/**
* 初始化一个字典类型的配置
* @param map 初始值
* @param keyType 键class类型
* @param valueType 值class类型
* @param order 是否是有序配置
* @param <K> 键类型
* @param <V> 值类型
* @return 配置对象
*/
public static <K, V> ObjectMapConf<Map<K, V>> objMap(Map<K, V> map, Class<K> keyType, Class<V> valueType, boolean order) {
return new ObjectMapConf<>(map, keyType, valueType, order);
}
}

19
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<T extends Collection> extends com.fr.config.holder.impl.ColConf<Collection> {
public ColConf(String property, Collection collection, Class valueType) {
super(property, collection, valueType);
}
public ColConf(Collection collection, Class valueType) {
super(collection, valueType);
}
}

19
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<T extends Map> extends com.fr.config.holder.impl.MapConf<Map> {
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);
}
}

16
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<T> extends com.fr.config.holder.impl.ObjConf<T> {
public ObjConf(String property, T t, Class classType) {
super(property, t, classType);
}
public ObjConf(T t, Class classType) {
super(t, classType);
}
}

22
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<T extends Collection> extends com.fr.config.holder.impl.ObjectColConf<Collection> {
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);
}
}

26
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<T extends Map> extends com.fr.config.holder.impl.ObjectMapConf<Map> {
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);
}
}

17
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<T> extends com.fr.config.holder.impl.SimConf<T> {
public SimConf(T t) {
super(t);
}
public SimConf(String property, T t) {
super(property, t);
}
}

35
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<String, TableData> getAllServerTableData() {
Map<String, TableData> 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);
}
}

96
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);
}
}

4
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);
}

20
src/test/java/com/fanruan/api/data/TableDataKitTest.java

@ -1,10 +1,14 @@
package com.fanruan.api.data;
import com.fanruan.api.Prepare;
import com.fr.base.TableData;
import com.fr.data.TableDataSource;
import com.fr.file.TableDataConfig;
import com.fr.main.impl.WorkBook;
import com.fr.script.Calculator;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author richie
* @version 10.0
@ -14,9 +18,21 @@ public class TableDataKitTest extends Prepare {
@Test
public void getTableData() {
TestTD td = new TestTD();
TableDataConfig.getInstance().addTableData("first", td);
Calculator calculator = Calculator.createCalculator();
calculator.setAttribute(TableDataSource.KEY, new WorkBook());
TableData r = TableDataKit.getTableData(calculator, "first");
Assert.assertEquals(td, r);
}
@Test
public void testGetTableData() {
TestTD td = new TestTD();
WorkBook workBook = new WorkBook();
workBook.putTableData("test", td);
TableData r = TableDataKit.getTableData(workBook, "test");
Assert.assertEquals(td, r);
}
}

59
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<Integer> 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;
}
}

75
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());
}
}

29
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() {
}
}
Loading…
Cancel
Save