forked from fanruan/finekit
Browse Source
* commit 'aa488ac8c7854d25c94d0426b23bb497746ad805': 数据连接抽象类 资源仓库kit update: 新增方法,结构调整master
Mars.Ma
5 years ago
7 changed files with 246 additions and 2 deletions
@ -0,0 +1,51 @@
|
||||
package com.fanruan.api.data.open; |
||||
|
||||
import com.fanruan.api.util.ArrayKit; |
||||
import com.fr.data.impl.AbstractDatabaseConnection; |
||||
import com.fr.data.impl.Connection; |
||||
|
||||
/** |
||||
* @author richie |
||||
* @version 10.0 |
||||
* Created by richie on 2019-09-06 |
||||
* 用于数据连接插件的抽象类 |
||||
*/ |
||||
public abstract class BaseConnection extends AbstractDatabaseConnection { |
||||
|
||||
/** |
||||
* 测试连接 |
||||
* |
||||
* @throws Exception 异常 |
||||
*/ |
||||
@Override |
||||
public abstract void testConnection() throws Exception; |
||||
|
||||
/** |
||||
* 创建连接 |
||||
* |
||||
* @return 返回连接 |
||||
* @throws Exception 异常 |
||||
*/ |
||||
@Override |
||||
public java.sql.Connection createConnection() throws Exception { |
||||
return Connection.IGNORE; |
||||
} |
||||
|
||||
/** |
||||
* 连接成功或失败时给出的信息 |
||||
* |
||||
* @return 信息 |
||||
*/ |
||||
@Override |
||||
public abstract String connectMessage(boolean status); |
||||
|
||||
|
||||
/** |
||||
* 获取数据连接的摘要信息 |
||||
* |
||||
* @return 摘要 |
||||
*/ |
||||
public String[] summary(String... args) { |
||||
return ArrayKit.EMPTY_STRING_ARRAY; |
||||
} |
||||
} |
@ -0,0 +1,41 @@
|
||||
package com.fanruan.api.io; |
||||
|
||||
import com.fr.io.base.provider.RepositoryFactoryProvider; |
||||
import com.fr.io.context.ResourceModuleContext; |
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
/** |
||||
* |
||||
* 资源仓库插件开发套件 |
||||
* |
||||
* @author rinoux |
||||
* @version 10.0 |
||||
* Created by rinoux on 2019/9/5 |
||||
*/ |
||||
public class ResourceModuleKit { |
||||
|
||||
|
||||
/** |
||||
* 添加一个资源仓库工厂 |
||||
* |
||||
* @param factory 工厂 |
||||
* @param <T> 工厂类型 |
||||
*/ |
||||
public static <T extends RepositoryFactoryProvider> void addFactory(@NotNull T factory) { |
||||
ResourceModuleContext.addFactory(factory); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 移除一个资源仓库工厂 |
||||
* |
||||
* @param factory 工厂 |
||||
* @param <T> 工厂类型 |
||||
*/ |
||||
public static <T extends RepositoryFactoryProvider> void removeFactory(@NotNull T factory) { |
||||
ResourceModuleContext.removeFactory(factory.getIdentity()); |
||||
} |
||||
|
||||
|
||||
|
||||
} |
@ -0,0 +1,124 @@
|
||||
package com.fanruan.api.io; |
||||
|
||||
import com.fr.io.base.provider.FactoryLoaderProvider; |
||||
import com.fr.io.base.provider.RepositoryFactoryProvider; |
||||
import com.fr.io.base.provider.RepositoryInstallerProvider; |
||||
import com.fr.io.base.provider.RepositoryManagerProvider; |
||||
import com.fr.io.config.RepositoryConfig; |
||||
import com.fr.io.config.ResourceModuleConfigProvider; |
||||
import com.fr.io.context.RepositoryContextProvider; |
||||
import com.fr.io.context.ResourceModuleContext; |
||||
import com.fr.io.lock.LockFactory; |
||||
import org.easymock.EasyMock; |
||||
import org.junit.After; |
||||
import org.junit.Assert; |
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
|
||||
/** |
||||
* ResourceModuleKit Tester. |
||||
* |
||||
* @author <Authors name> |
||||
* @version 1.0 |
||||
* @since <pre>9月 5, 2019</pre> |
||||
*/ |
||||
public class ResourceModuleKitTest { |
||||
|
||||
@Before |
||||
public void before() throws Exception { |
||||
final FactoryLoaderProvider loaderProvider = new FactoryLoaderProvider() { |
||||
final Map<String, RepositoryFactoryProvider> map = new HashMap<>(); |
||||
|
||||
@Override |
||||
public <T extends RepositoryConfig> void add(RepositoryFactoryProvider<T> factory) { |
||||
map.put(factory.getIdentity(), factory); |
||||
} |
||||
|
||||
@Override |
||||
public void remove(String identity) { |
||||
map.remove(identity); |
||||
} |
||||
|
||||
@Override |
||||
@SuppressWarnings("unchecked") |
||||
public <T extends RepositoryConfig> RepositoryFactoryProvider<T> get(String identity) { |
||||
return map.get(identity); |
||||
} |
||||
}; |
||||
|
||||
ResourceModuleContext.setRepositoryContext(new RepositoryContextProvider() { |
||||
@Override |
||||
public FactoryLoaderProvider getFactoryLoader() { |
||||
|
||||
return loaderProvider; |
||||
} |
||||
|
||||
@Override |
||||
public ResourceModuleConfigProvider getConfig() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public RepositoryManagerProvider getManager() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public RepositoryInstallerProvider getInstaller() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public LockFactory getLockFactory() { |
||||
return null; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@After |
||||
public void after() throws Exception { |
||||
ResourceModuleContext.setRepositoryContext(null); |
||||
} |
||||
|
||||
/** |
||||
* Method: addFactory(@NotNull T factory) |
||||
*/ |
||||
@Test |
||||
public void testAddFactory() throws Exception { |
||||
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class); |
||||
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes(); |
||||
|
||||
EasyMock.replay(factory); |
||||
|
||||
Assert.assertNull(ResourceModuleContext.getFactory("MockRF")); |
||||
|
||||
ResourceModuleKit.addFactory(factory); |
||||
|
||||
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF")); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* Method: addFactory(@NotNull T factory) |
||||
*/ |
||||
@Test |
||||
public void testRemoveFactory() throws Exception { |
||||
RepositoryFactoryProvider factory = EasyMock.createMock(RepositoryFactoryProvider.class); |
||||
EasyMock.expect(factory.getIdentity()).andReturn("MockRF").anyTimes(); |
||||
|
||||
EasyMock.replay(factory); |
||||
|
||||
Assert.assertNull(ResourceModuleContext.getFactory("MockRF")); |
||||
|
||||
ResourceModuleKit.addFactory(factory); |
||||
|
||||
Assert.assertNotNull(ResourceModuleContext.getFactory("MockRF")); |
||||
|
||||
ResourceModuleKit.removeFactory(factory); |
||||
|
||||
Assert.assertNull(ResourceModuleContext.getFactory("MockRF")); |
||||
} |
||||
} |
@ -0,0 +1,18 @@
|
||||
package com.fanruan.api.security; |
||||
|
||||
import java.util.*; |
||||
|
||||
import com.fr.stable.CommonCodeUtils; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
public class SecurityKitTest { |
||||
@Test |
||||
public void passwordDecode(){ |
||||
Assert.assertEquals(SecurityKit.passwordDecode("1234"), CommonCodeUtils.passwordDecode("1234")); |
||||
} |
||||
@Test |
||||
public void passwordEncode(){ |
||||
Assert.assertEquals(SecurityKit.passwordEncode("1234"), CommonCodeUtils.passwordEncode("1234")); |
||||
} |
||||
} |
Loading…
Reference in new issue