mirror of
https://github.com/getrebuild/rebuild.git
synced 2025-02-24 22:35:04 +08:00
commit
cb4d270ae0
6 changed files with 69 additions and 99 deletions
|
@ -18,7 +18,7 @@ services:
|
|||
# - master
|
||||
|
||||
before_script:
|
||||
- mysql -e "CREATE DATABASE rebuild10 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;"
|
||||
- mysql -e "CREATE DATABASE rebuild10 COLLATE utf8mb4_general_ci;"
|
||||
- mysql -e "CREATE USER 'rebuild'@'127.0.0.1' IDENTIFIED BY 'rebuild'; GRANT ALL PRIVILEGES ON rebuild10.* TO 'rebuild'@'127.0.0.1'; FLUSH PRIVILEGES;"
|
||||
- mysql -D rebuild10 < src/main/resources/scripts/db-init.sql
|
||||
|
||||
|
|
|
@ -19,19 +19,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.server;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.business.rbstore.MetaschemaImporter;
|
||||
import com.rebuild.server.helper.task.TaskExecutors;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.metadata.entity.DisplayType;
|
||||
import com.rebuild.server.metadata.entity.Entity2Schema;
|
||||
import com.rebuild.server.metadata.entity.Field2Schema;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -154,26 +151,25 @@ public class TestSupport {
|
|||
if (!MetadataHelper.containsEntity(Account)) {
|
||||
URL url = TestSupport.class.getClassLoader().getResource("metaschema.Account.json");
|
||||
String content = FileUtils.readFileToString(new File(url.toURI()));
|
||||
TaskExecutors.run(new MetaschemaImporter(JSON.parseObject(content)).setUser(UserService.ADMIN_USER));
|
||||
|
||||
MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(content));
|
||||
if (this instanceof TestSupportWithUser) {
|
||||
TaskExecutors.exec(importer);
|
||||
} else {
|
||||
TaskExecutors.run(importer.setUser(UserService.ADMIN_USER));
|
||||
}
|
||||
}
|
||||
|
||||
if (!MetadataHelper.containsEntity(SalesOrder)) {
|
||||
URL url = TestSupport.class.getClassLoader().getResource("metaschema.SalesOrder.json");
|
||||
String content = FileUtils.readFileToString(new File(url.toURI()));
|
||||
TaskExecutors.run(new MetaschemaImporter(JSON.parseObject(content)).setUser(UserService.ADMIN_USER));
|
||||
|
||||
MetaschemaImporter importer = new MetaschemaImporter(JSON.parseObject(content));
|
||||
if (this instanceof TestSupportWithUser) {
|
||||
TaskExecutors.exec(importer);
|
||||
} else {
|
||||
TaskExecutors.run(importer.setUser(UserService.ADMIN_USER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一条测试记录。注意调用前设置线程用户 {@link Application#getSessionStore()}
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ID addRecordOfTestAllFields() {
|
||||
final ID opUser = UserService.ADMIN_USER;
|
||||
Entity test = MetadataHelper.getEntity(TEST_ENTITY);
|
||||
Record record = EntityHelper.forNew(test.getEntityCode(), opUser);
|
||||
record.setString("text", "TEXT-" + RandomUtils.nextLong());
|
||||
return Application.getGeneralEntityService().create(record).getPrimary();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
||||
package com.rebuild.server;
|
||||
|
||||
import cn.devezhao.persist4j.Entity;
|
||||
import cn.devezhao.persist4j.Record;
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.metadata.EntityHelper;
|
||||
import com.rebuild.server.metadata.MetadataHelper;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.apache.commons.lang.math.RandomUtils;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
|
||||
|
@ -52,4 +58,26 @@ public abstract class TestSupportWithUser extends TestSupport {
|
|||
protected ID getSessionUser() {
|
||||
return SIMPLE_USER;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加一条测试记录
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected ID addRecordOfTestAllFields() {
|
||||
Entity testEntity = MetadataHelper.getEntity(TEST_ENTITY);
|
||||
// 自动添加权限
|
||||
if (!Application.getSecurityManager().allowedR(getSessionUser(), testEntity.getEntityCode())) {
|
||||
Record p = EntityHelper.forNew(EntityHelper.RolePrivileges, UserService.SYSTEM_USER);
|
||||
p.setID("roleId", SIMPLE_ROLE);
|
||||
p.setInt("entity", testEntity.getEntityCode());
|
||||
p.setString("definition", "{'A':1,'R':1,'C':4,'S':1,'D':1,'U':1}");
|
||||
Application.getCommonService().create(p, Boolean.FALSE);
|
||||
Application.getUserStore().refreshRole(SIMPLE_ROLE);
|
||||
}
|
||||
|
||||
Record record = EntityHelper.forNew(testEntity.getEntityCode(), getSessionUser());
|
||||
record.setString("text", "TEXT-" + RandomUtils.nextLong());
|
||||
return Application.getGeneralEntityService().create(record).getPrimary();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
rebuild - Building your business-systems freely.
|
||||
Copyright (C) 2019 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.business.recyclebin;
|
||||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author devezhao zhaofang123@gmail.com
|
||||
* @since 2019/08/21
|
||||
*/
|
||||
public class RecycleBeanTest extends TestSupport {
|
||||
|
||||
@Test
|
||||
public void serialize() {
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
ID test = addRecordOfTestAllFields();
|
||||
JSON s = new RecycleBean(test).serialize();
|
||||
System.out.println(s);
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,8 +20,7 @@ package com.rebuild.server.business.recyclebin;
|
|||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.rebuild.server.TestSupportWithUser;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -29,28 +28,21 @@ import org.junit.Test;
|
|||
* @author devezhao zhaofang123@gmail.com
|
||||
* @since 2019/08/21
|
||||
*/
|
||||
public class RecycleRestoreTest extends TestSupport {
|
||||
public class RecycleRestoreTest extends TestSupportWithUser {
|
||||
|
||||
@Test
|
||||
public void restore() {
|
||||
ID testId = null;
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
|
||||
testId = addRecordOfTestAllFields();
|
||||
Application.getGeneralEntityService().delete(testId);
|
||||
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
ID testId = addRecordOfTestAllFields();
|
||||
Application.getGeneralEntityService().delete(testId);
|
||||
|
||||
// Is in?
|
||||
Object[] recycle = Application.createQueryNoFilter(
|
||||
"select recycleId from RecycleBin where recordId = ?")
|
||||
.setParameter(1, testId)
|
||||
.unique();
|
||||
Assert.assertTrue(recycle != null);
|
||||
Assert.assertNotNull(recycle);
|
||||
|
||||
int a = new RecycleRestore((ID) recycle[0]).restore();
|
||||
Assert.assertTrue(a == 1);
|
||||
Assert.assertEquals(1, a);
|
||||
}
|
||||
}
|
|
@ -19,36 +19,36 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package com.rebuild.server.business.recyclebin;
|
||||
|
||||
import cn.devezhao.persist4j.engine.ID;
|
||||
import com.rebuild.server.Application;
|
||||
import com.rebuild.server.TestSupport;
|
||||
import com.rebuild.server.service.bizz.UserService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.rebuild.server.TestSupportWithUser;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author devezhao zhaofang123@gmail.com
|
||||
* @since 2019/08/21
|
||||
*/
|
||||
public class RecycleStoreTest extends TestSupport {
|
||||
public class RecycleStoreTest extends TestSupportWithUser {
|
||||
|
||||
@Test
|
||||
public void serialize() {
|
||||
ID test = addRecordOfTestAllFields();
|
||||
JSON s = new RecycleBean(test).serialize();
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void store() {
|
||||
try {
|
||||
Application.getSessionStore().set(UserService.ADMIN_USER);
|
||||
ID test1 = addRecordOfTestAllFields();
|
||||
ID test2 = addRecordOfTestAllFields();
|
||||
|
||||
ID test1 = addRecordOfTestAllFields();
|
||||
ID test2 = addRecordOfTestAllFields();
|
||||
RecycleStore recycleStore = new RecycleStore(getSessionUser());
|
||||
recycleStore.add(test1);
|
||||
recycleStore.add(test2);
|
||||
recycleStore.removeLast();
|
||||
|
||||
RecycleStore recycleStore = new RecycleStore(UserService.ADMIN_USER);
|
||||
recycleStore.add(test1);
|
||||
recycleStore.add(test2);
|
||||
recycleStore.removeLast();
|
||||
recycleStore.add(test2, test1);
|
||||
|
||||
recycleStore.add(test2, test1);
|
||||
|
||||
int s = recycleStore.store();
|
||||
System.out.println(s);
|
||||
} finally {
|
||||
Application.getSessionStore().clean();
|
||||
}
|
||||
int s = recycleStore.store();
|
||||
System.out.println(s);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue