forked from fanruan/finekit
Browse Source
* 'master' of https://cloud.finedevelop.com/scm/~zhaojunzhe/finekit: url别名工具类 单元测试 单元测试 单元测试 配置类的工具方法 配置类的工具方法remotes/1611766341912730171/master
zjz1993
5 years ago
14 changed files with 506 additions and 7 deletions
@ -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); |
||||
} |
||||
} |
||||
|
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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); |
||||
} |
||||
} |
@ -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; |
||||
} |
||||
} |
@ -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()); |
||||
} |
||||
|
||||
} |
@ -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…
Reference in new issue