tests support

This commit is contained in:
FangfangZhao 2019-01-03 13:24:00 +08:00
parent 377f3e6acb
commit 90ff700e79
9 changed files with 123 additions and 39 deletions

View file

@ -18,7 +18,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<argLine>-Dfile.encoding=UTF-8</argLine>
<skipTests>true</skipTests>
<skipTests>false</skipTests>
<spring.version>4.3.18.RELEASE</spring.version>
</properties>
@ -109,11 +109,13 @@
<artifactId>spring-websocket</artifactId>
<version>${spring.version}</version>
</dependency>
<!--
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
-->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
@ -129,11 +131,13 @@
<artifactId>quartz</artifactId>
<version>2.3.0</version>
</dependency>
<!--
<dependency>
<groupId>bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>140</version>
</dependency>
-->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>

View file

@ -138,11 +138,20 @@ public final class Application {
Runtime.getRuntime().addShutdownHook(hook);
}
public static <T> T getBean(Class<T> beanClazz) {
/**
* SPRING Context
*
* @return
*/
public static ApplicationContext getApplicationContext() {
if (APPLICATION_CTX == null) {
throw new IllegalStateException("Rebuild unstarted");
}
return APPLICATION_CTX.getBean(beanClazz);
return APPLICATION_CTX;
}
public static <T> T getBean(Class<T> beanClazz) {
return getApplicationContext().getBean(beanClazz);
}
public static OnlineSessionStore getSessionStore() {
@ -202,13 +211,10 @@ public final class Application {
}
public static IEntityService getEntityService(int entityCode) {
if (ESS == null) {
throw new IllegalStateException("Unstarted");
}
if (ESS.containsKey(entityCode)) {
if (ESS != null && ESS.containsKey(entityCode)) {
return ESS.get(entityCode);
} else {
return (GeneralEntityService) APPLICATION_CTX.getBean("generalEntityService");
return (GeneralEntityService) getApplicationContext().getBean("generalEntityService");
}
}
}

View file

@ -32,8 +32,7 @@ import org.springframework.jdbc.datasource.DataSourceUtils;
import com.alibaba.fastjson.JSON;
import com.rebuild.server.helper.SystemConfiguration;
import com.rebuild.server.helper.cache.BaseCacheTemplate;
import com.rebuild.server.helper.cache.CacheTemplate;
import com.rebuild.server.helper.cache.CommonCache;
import com.rebuild.utils.JSONUtils;
import cn.devezhao.commons.CodecUtils;
@ -149,13 +148,11 @@ public class ServerStatus {
* @return
*/
protected static State checkCacheService() {
String name = "Cache/";
CacheTemplate cacheTemplate = Application.getCommonCache();
String type = ((BaseCacheTemplate) cacheTemplate).isUseRedis() ? "REDIS" : "EHCACHE";
name += type;
CommonCache cache = Application.getCommonCache();
String name = "Cache/" + (cache.isUseRedis() ? "REDIS" : "EHCACHE");
try {
cacheTemplate.putx("test", 1, 60);
cache.putx("test", 1, 60);
} catch (Exception ex) {
return State.error(name, ThrowableUtils.getRootCause(ex).getLocalizedMessage());
}

View file

@ -77,7 +77,7 @@ public class IncreasingVar extends SeriesVar {
}
synchronized (keyLock) {
Object val = Application.getCommonCache().get(key);
Object val = Application.getCommonCache().getx(key);
if (val != null) {
intAuto = ObjectUtils.toInt(val);
} else {

View file

@ -13,7 +13,7 @@
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd" default-lazy-init="false">
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd" default-lazy-init="true">
<aop:aspectj-autoproxy proxy-target-class="true" />

View file

@ -25,11 +25,11 @@ import org.junit.Test;
* @author zhaofang123@gmail.com
* @since 05/19/2018
*/
public class StartupTest {
public class StartupTest extends TestSupport {
@Test
public void startup() {
Application.debug();
Application.debug().getBeansOfType(Object.class);
public void initAllBeans() {
LOG.warn("Initialize all beans ^_^");
Application.getApplicationContext().getBeansOfType(Object.class);
}
}

View file

@ -16,21 +16,30 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.server.metadata.entityhub;
package com.rebuild.server;
import org.junit.Test;
import com.rebuild.server.bizz.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.AfterClass;
import org.junit.BeforeClass;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
* @author devezhao
* @since 01/03/2019
*/
public class Entity2SchemaTest {
public class TestSupport {
protected static final Log LOG = LogFactory.getLog(TestSupport.class);
@Test
public void testCreate() throws Exception {
new Entity2Schema(UserService.ADMIN_USER).create("测试一把", null, null);
@BeforeClass
public static void startup() {
LOG.warn("TESTING Startup ...");
Application.debug();
}
@AfterClass
public static void shutdown() {
LOG.warn("TESTING Shutdown ...");
}
}

View file

@ -19,13 +19,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package com.rebuild.server.business.series;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Assert;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.server.Application;
import com.rebuild.server.TestSupport;
import com.rebuild.server.metadata.MetadataHelper;
import cn.devezhao.commons.ThreadPool;
@ -36,7 +39,7 @@ import cn.devezhao.persist4j.Field;
* @author devezhao
* @since 12/24/2018
*/
public class SeriesGeneratorTest {
public class SeriesGeneratorTest extends TestSupport {
@Test
public void testTimeVar() throws Exception {
@ -46,10 +49,7 @@ public class SeriesGeneratorTest {
@Test
public void testIncrementVar() throws Exception {
Application.debug();
Field field = MetadataHelper.getEntity("ceshiziduan").getField("ZIDONGBIANHAO");
IncreasingVar var = new IncreasingVar("0000", field, null);
IncreasingVar var = new IncreasingVar("0000", getSeriesField(), null);
System.out.println(var.generate());
System.out.println(var.generate());
System.out.println(var.generate());
@ -58,15 +58,19 @@ public class SeriesGeneratorTest {
@Test
public void testIncrementVarNThreads() throws Exception {
final IncreasingVar var = new IncreasingVar("0000", getSeriesField(), "Y");
final Set<String> set = new HashSet<>();
for (int i = 0; i < 2000; i++) {
ThreadPool.exec(new Runnable() {
@Override
public void run() {
System.out.println(var.generate());
String s = var.generate();
set.add(s);
System.out.print(s + " ");
}
});
}
ThreadPool.waitFor(1000);
Assert.assertTrue(set.size() == 2000);
}
@Test
@ -82,7 +86,6 @@ public class SeriesGeneratorTest {
}
private Field getSeriesField() {
Application.debug();
Field field = MetadataHelper.getEntity("ceshiziduan").getField("ZIDONGBIANHAO");
return field;
}

View file

@ -0,0 +1,65 @@
/*
rebuild - Building your system freely.
Copyright (C) 2018 devezhao <zhaofang123@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.rebuild.server.metadata.entityhub;
import org.junit.Test;
import com.rebuild.server.TestSupport;
import com.rebuild.server.bizz.UserService;
import com.rebuild.server.metadata.MetadataHelper;
import cn.devezhao.persist4j.Entity;
/**
*
* @author zhaofang123@gmail.com
* @since 08/03/2018
*/
public class Meta2SchemaTest extends TestSupport {
@Test
public void testCreateEntity() throws Exception {
String newEntityName = new Entity2Schema(UserService.ADMIN_USER).create("测试实体", null, null);
System.out.println("New entity is created : " + newEntityName);
Entity newEntity = MetadataHelper.getEntity(newEntityName);
boolean drop = new Entity2Schema(UserService.ADMIN_USER).drop(newEntity);
System.out.println("New entity is clear : " + newEntityName + " > " + drop);
}
@Test
public void testCreateField() throws Exception {
createField("数字", DisplayType.NUMBER, null);
createField("货币", DisplayType.DECIMAL, null);
boolean drop = new Entity2Schema(UserService.ADMIN_USER).drop(entity);
System.out.println("Field entity is clear : " + entity + " > " + drop);
}
static Entity entity;
static String createField(String fieldLabel, DisplayType type, String refEntity) {
if (entity == null) {
String newEntityName = new Entity2Schema(UserService.ADMIN_USER).create("测试字段实体", null, null);
entity = MetadataHelper.getEntity(newEntityName);
}
String fieldName = new Field2Schema(UserService.ADMIN_USER).create(entity, fieldLabel, type, null, refEntity);
System.out.println("New field is create : " + fieldName + " < " + fieldLabel);
return fieldName;
}
}