test cases

This commit is contained in:
FangfangZhao 2019-01-04 18:17:58 +08:00
parent 4b32b81753
commit d5bf9f9d20
30 changed files with 481 additions and 67 deletions

View file

@ -158,8 +158,8 @@ public final class Application {
return getBean(OnlineSessionStore.class);
}
public static ID currentCallerUser() {
return getSessionStore().getCurrentCaller();
public static ID getCurrentUser() {
return getSessionStore().get();
}
public static PersistManagerFactory getPersistManagerFactory() {

View file

@ -63,7 +63,7 @@ public class ChartDataFactory {
throw new ChartsException("源实体 [" + e.toUpperCase() + "] 不存在");
}
ID user = Application.currentCallerUser();
ID user = Application.getCurrentUser();
Entity entity = MetadataHelper.getEntity(e);
if (!Application.getSecurityManager().allowedR(user, entity.getEntityCode())) {
throw new ChartsException("没有读取 [" + EasyMeta.getLabel(entity) + "] 的权限");

View file

@ -51,9 +51,9 @@ import cn.devezhao.persist4j.engine.ID;
* @author zhaofang123@gmail.com
* @since 08/30/2018
*/
public class FormManager extends LayoutManager {
public class FormsManager extends LayoutManager {
private static final Log LOG = LogFactory.getLog(FormManager.class);
private static final Log LOG = LogFactory.getLog(FormsManager.class);
private static final ThreadLocal<ID> MASTERID4NEWSLAVE = new ThreadLocal<>();
@ -162,7 +162,7 @@ public class FormManager extends LayoutManager {
Record data = null;
if (!elements.isEmpty() && record != null) {
data = queryRecord(record, elements);
data = record(record, user, elements);
if (data == null) {
return formatModelError("此记录已被删除,或你对此记录没有读取权限");
}
@ -291,7 +291,7 @@ public class FormManager extends LayoutManager {
* @param elements
* @return
*/
protected static Record queryRecord(ID id, JSONArray elements) {
protected static Record record(ID id, ID user, JSONArray elements) {
if (elements.isEmpty()) {
return null;
}
@ -323,7 +323,7 @@ public class FormManager extends LayoutManager {
.append(" where ").append(entity.getPrimaryField().getName())
.append(" = '").append(id).append("'");
return Application.getQueryFactory().record(ajql.toString());
return Application.getQueryFactory().createQuery(ajql.toString(), user).record();
}
/**

View file

@ -34,7 +34,10 @@ import cn.devezhao.commons.CalendarUtils;
*/
public abstract class BulkTask implements Runnable {
protected final Log LOG = LogFactory.getLog(getClass());
protected static final Log LOG = LogFactory.getLog(BulkTask.class);
volatile
private boolean interrupt = false;
private int total = -1;
private int complete = 0;
@ -147,10 +150,10 @@ public abstract class BulkTask implements Runnable {
// -- for Thread
public void interrupt() {
Thread.currentThread().interrupt();
this.interrupt = true;
}
public boolean isInterrupted() {
return Thread.currentThread().isInterrupted();
return interrupt;
}
}

View file

@ -52,7 +52,9 @@ public class BulkTaskExecutor extends QuartzJobBean {
*/
public static String submit(BulkTask task) {
ThreadPoolExecutor tpe = (ThreadPoolExecutor) EXECS;
if (tpe.getTaskCount() > EXECS_MAX * 5) {
int queueSize = tpe.getQueue().size();
System.out.println(queueSize);
if (queueSize > EXECS_MAX * 5) {
throw new RejectedExecutionException("Too many task : " + tpe.getTaskCount());
}

View file

@ -53,7 +53,7 @@ public class PickListService extends BaseService {
*/
public void updateBatch(Field field, JSONObject config) {
Assert.notNull(config, "无效配置");
ID user = Application.currentCallerUser();
ID user = Application.getCurrentUser();
JSONArray showItems = config.getJSONArray("show");
JSONArray hideItems = config.getJSONArray("hide");

View file

@ -61,7 +61,7 @@ public abstract class ObservableService extends Observable implements IEntitySer
if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.valueOf(Application.currentCallerUser(), BizzPermission.CREATE, null, record));
notifyObservers(OperatingContext.valueOf(Application.getCurrentUser(), BizzPermission.CREATE, null, record));
}
return record;
}
@ -74,7 +74,7 @@ public abstract class ObservableService extends Observable implements IEntitySer
if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.valueOf(Application.currentCallerUser(), BizzPermission.UPDATE, before, record));
notifyObservers(OperatingContext.valueOf(Application.getCurrentUser(), BizzPermission.UPDATE, before, record));
}
return record;
}
@ -83,7 +83,7 @@ public abstract class ObservableService extends Observable implements IEntitySer
public int delete(ID recordId) {
Record deleted = null;
if (countObservers() > 0) {
deleted = EntityHelper.forUpdate(recordId, Application.currentCallerUser());
deleted = EntityHelper.forUpdate(recordId, Application.getCurrentUser());
deleted = getBeforeRecord(deleted);
}
@ -91,7 +91,7 @@ public abstract class ObservableService extends Observable implements IEntitySer
if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.valueOf(Application.currentCallerUser(), BizzPermission.DELETE, deleted, null));
notifyObservers(OperatingContext.valueOf(Application.getCurrentUser(), BizzPermission.DELETE, deleted, null));
}
return affected;
}

View file

@ -187,7 +187,7 @@ public class GeneralEntityService extends ObservableService {
if (countObservers() > 0) {
setChanged();
notifyObservers(OperatingContext.valueOf(Application.currentCallerUser(), BizzPermission.ASSIGN, before, assigned));
notifyObservers(OperatingContext.valueOf(Application.getCurrentUser(), BizzPermission.ASSIGN, before, assigned));
}
return affected;
}
@ -206,7 +206,7 @@ public class GeneralEntityService extends ObservableService {
return 1;
}
ID currentUser = Application.currentCallerUser();
ID currentUser = Application.getCurrentUser();
Record shared = EntityHelper.forNew(EntityHelper.ShareAccess, currentUser);
shared.setString("belongEntity", entityName);
@ -238,7 +238,7 @@ public class GeneralEntityService extends ObservableService {
public int unshare(ID record, ID accessId) {
// TODO 级联取消共享 ??
ID currentUser = Application.currentCallerUser();
ID currentUser = Application.getCurrentUser();
Record unshared = EntityHelper.forUpdate(accessId, currentUser);
if (countObservers() > 0) {
unshared.setNull("belongEntity");
@ -298,7 +298,7 @@ public class GeneralEntityService extends ObservableService {
sql = sql.substring(0, sql.length() - 4); // remove last ' or '
sql += " )";
Filter filter = Application.getSecurityManager().createQueryFilter(Application.currentCallerUser(), action);
Filter filter = Application.getSecurityManager().createQueryFilter(Application.getCurrentUser(), action);
Object[][] array = Application.getQueryFactory().createQuery(sql, filter).array();
Set<ID> records = new HashSet<>();

View file

@ -21,8 +21,6 @@ package com.rebuild.server.service.base;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.github.stuxuhai.jpinyin.PinyinHelper;
import com.rebuild.server.Application;
@ -39,16 +37,14 @@ import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
/**
* QuickCode 重建
* QuickCode 字段值重建
*
* @author devezhao
* @since 12/28/2018
*/
public class QuickCodeReindexTask extends BulkTask {
private static final Log LOG = LogFactory.getLog(QuickCodeReindexTask.class);
private Entity entity;
final private Entity entity;
/**
* @param entity

View file

@ -55,7 +55,7 @@ public class ChangeOwningDeptTask extends BulkTask {
String updeptSql = "update `{0}` set OWNING_DEPT = ''%s'' where OWNING_USER = ''%s''";
updeptSql = String.format(updeptSql, deptNew.toLiteral(), user.toLiteral());
for (Entity e : MetadataHelper.getEntities()) {
if (isInterrupted()) {
if (this.isInterrupted()) {
LOG.error("Task interrupted : " + user + " > " + deptNew);
break;
}

View file

@ -16,8 +16,9 @@ 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.web;
package com.rebuild.server.service.bizz;
import cn.devezhao.bizz.security.AccessDeniedException;
import cn.devezhao.persist4j.engine.ID;
/**
@ -31,35 +32,35 @@ public class CurrentCaller {
private static final ThreadLocal<ID> CALLER = new ThreadLocal<>();
/**
* @param user
* @param caller
*/
protected void setCurrentCaller(ID user) {
CALLER.set(user);
public void set(ID caller) {
CALLER.set(caller);
}
/**
*/
protected void clearCurrentCaller() {
public void clean() {
CALLER.remove();
}
/**
* @return
* @throws IllegalParameterException
*/
public ID getCurrentCaller() throws IllegalParameterException {
return getCurrentCaller(false);
public ID get() {
return get(false);
}
/**
* @param allowedNull
* @return
* @throws IllegalParameterException
* @throws AccessDeniedException If caller not found
*/
public ID getCurrentCaller(boolean allowNull) throws IllegalParameterException {
ID user = CALLER.get();
if (user == null && allowNull == false) {
throw new IllegalParameterException("无效请求用户", 403);
public ID get(boolean allowedNull) throws AccessDeniedException {
ID caller = CALLER.get();
if (caller == null && allowedNull == false) {
throw new AccessDeniedException("无有效用户");
}
return user;
return caller;
}
}

View file

@ -50,8 +50,15 @@ public class DepartmentService extends BizzEntityService {
}
@Override
public Record createOrUpdate(Record record) {
record = super.createOrUpdate(record);
public Record create(Record record) {
record = super.create(record);
Application.getUserStore().refreshDepartment(record.getPrimary());
return record;
}
@Override
public Record update(Record record) {
record = super.update(record);
Application.getUserStore().refreshDepartment(record.getPrimary());
return record;
}

View file

@ -52,8 +52,15 @@ public class RoleService extends BizzEntityService {
}
@Override
public Record createOrUpdate(Record record) {
record = super.createOrUpdate(record);
public Record create(Record record) {
record = super.create(record);
Application.getUserStore().refreshRole(record.getPrimary(), false);
return record;
}
@Override
public Record update(Record record) {
record = super.update(record);
Application.getUserStore().refreshRole(record.getPrimary(), false);
return record;
}
@ -80,7 +87,7 @@ public class RoleService extends BizzEntityService {
* @param definition
*/
public void updatePrivileges(ID roleId, JSONObject definition) {
final ID user = Application.currentCallerUser();
final ID user = Application.getCurrentUser();
Object[][] array = Application.createQuery(
"select privilegesId,definition,entity,zeroKey from RolePrivileges where roleId = ?")

View file

@ -108,7 +108,7 @@ public class UserService extends BizzEntityService {
return;
}
Record record = EntityHelper.forUpdate(user, Application.currentCallerUser());
Record record = EntityHelper.forUpdate(user, Application.getCurrentUser());
record.setID("deptId", deptNew);
super.update(record);
Application.getUserStore().refreshUser(user);

View file

@ -72,7 +72,7 @@ public class PrivilegesGuardInterceptor implements MethodInterceptor, Guard {
}
BulkContext context = (BulkContext) first;
ID caller = Application.currentCallerUser();
ID caller = Application.getCurrentUser();
Entity entity = context.getMainEntity();
if (!Application.getSecurityManager().allowed(caller, entity.getEntityCode(), context.getAction())) {
@ -97,7 +97,7 @@ public class PrivilegesGuardInterceptor implements MethodInterceptor, Guard {
throw new IllegalArgumentException("First argument must be Record/ID!");
}
ID caller = Application.currentCallerUser();
ID caller = Application.getCurrentUser();
Permission action = getPermissionByMethod(invocation.getMethod(), recordId == null);
boolean isAllowed = false;

View file

@ -172,14 +172,14 @@ public class AdvFilterParser {
} else if ("REM".equalsIgnoreCase(op)) {
value = CalendarUtils.getUTCDateFormat().format(CalendarUtils.addMonth(-NumberUtils.toInt(value))) + fullTime;
} else if ("SFU".equalsIgnoreCase(op)) {
value = Application.currentCallerUser().toLiteral();
value = Application.getCurrentUser().toLiteral();
} else if ("SFB".equalsIgnoreCase(op)) {
Department dept = UserHelper.getDepartment(Application.currentCallerUser());
Department dept = UserHelper.getDepartment(Application.getCurrentUser());
if (dept != null && fieldMeta.getReferenceEntities()[0].getEntityCode() == EntityHelper.User) {
sb.insert(sb.indexOf(" "), "." + EntityHelper.OwningDept);
}
} else if ("SFD".equalsIgnoreCase(op)) {
Department dept = UserHelper.getDepartment(Application.currentCallerUser());
Department dept = UserHelper.getDepartment(Application.getCurrentUser());
if (dept != null) {
value = StringUtils.join(UserHelper.getAllChildrenId(dept), "|");
}

View file

@ -53,7 +53,7 @@ public class QueryFactory {
* @return
*/
public Query createQuery(String ajql) {
return createQuery(ajql, Application.currentCallerUser());
return createQuery(ajql, Application.getCurrentUser());
}
/**

View file

@ -33,6 +33,8 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.Assert;
import com.rebuild.server.service.bizz.CurrentCaller;
import cn.devezhao.commons.CalendarUtils;
import cn.devezhao.commons.web.WebUtils;
import cn.devezhao.persist4j.engine.ID;

View file

@ -70,9 +70,9 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
throws Exception {
super.afterCompletion(request, response, handler, exception);
ID caller = Application.getSessionStore().getCurrentCaller(true);
ID caller = Application.getSessionStore().get(true);
if (caller != null) {
Application.getSessionStore().clearCurrentCaller();
Application.getSessionStore().clean();
}
logProgressTime(request);
@ -141,7 +141,7 @@ public class RequestWatchHandler extends HandlerInterceptorAdapter {
ID user = AppUtils.getRequestUser(request);
if (user != null) {
Application.getSessionStore().setCurrentCaller(user);
Application.getSessionStore().set(user);
// 管理后台访问
if (requestUrl.contains("/admin/") && !AdminEntryControll.isAdminVerified(request)) {

View file

@ -31,7 +31,7 @@ import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.server.Application;
import com.rebuild.server.helper.manager.FormManager;
import com.rebuild.server.helper.manager.FormsManager;
import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.web.BaseControll;
import com.rebuild.web.LayoutConfig;
@ -52,7 +52,7 @@ public class FormDesignControll extends BaseControll implements LayoutConfig {
public ModelAndView pageFormDesign(@PathVariable String entity, HttpServletRequest request) throws IOException {
ModelAndView mv = createModelAndView("/admin/entity/form-design.jsp");
MetaEntityControll.setEntityBase(mv, entity);
JSON cfg = FormManager.getFormLayout(entity, getRequestUser(request));
JSON cfg = FormsManager.getFormLayout(entity, getRequestUser(request));
if (cfg != null) {
request.setAttribute("FormConfig", cfg);
}
@ -69,7 +69,7 @@ public class FormDesignControll extends BaseControll implements LayoutConfig {
JSON formJson = ServletUtils.getRequestJson(request);
Record record = EntityHelper.parse((JSONObject) formJson, getRequestUser(request));
if (record.getPrimary() == null) {
record.setString("applyTo", FormManager.APPLY_ALL);
record.setString("applyTo", FormsManager.APPLY_ALL);
}
Application.getCommonService().createOrUpdate(record);

View file

@ -30,7 +30,7 @@ import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.server.helper.manager.FormManager;
import com.rebuild.server.helper.manager.FormsManager;
import com.rebuild.server.helper.manager.ViewAddonsManager;
import com.rebuild.server.helper.manager.value.DefaultValueManager;
import com.rebuild.server.metadata.MetadataHelper;
@ -86,12 +86,12 @@ public class GeneralEntityControll extends BaseControll {
// 创建明细实体必须制定主实体以便验证权限
String master = ((JSONObject) initialVal).getString(DefaultValueManager.DV_MASTER);
if (ID.isId(master)) {
FormManager.setCurrentMasterId(ID.valueOf(master));
FormsManager.setCurrentMasterId(ID.valueOf(master));
}
}
}
JSON model = FormManager.getFormModel(entity, user, record);
JSON model = FormsManager.getFormModel(entity, user, record);
// 填充前端设定的初始值
if (record == null && initialVal != null) {
DefaultValueManager.setFieldsValue(MetadataHelper.getEntity(entity), model, initialVal);
@ -104,7 +104,7 @@ public class GeneralEntityControll extends BaseControll {
HttpServletRequest request, HttpServletResponse response) throws IOException {
ID user = getRequestUser(request);
ID record = getIdParameterNotNull(request, "id");
JSON modal = FormManager.getViewModel(entity, user, record);
JSON modal = FormsManager.getViewModel(entity, user, record);
writeSuccess(response, modal);
}
}

View file

@ -40,6 +40,7 @@ public class TestSupport {
@AfterClass
public static void shutdown() {
Application.getSessionStore().clean();
LOG.warn("TESTING Shutdown ...");
}
}

View file

@ -0,0 +1,45 @@
/*
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.business.charts;
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.service.bizz.UserService;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class ChartsTest extends TestSupport {
@Test
public void testIndex() throws Exception {
Application.getSessionStore().set(UserService.ADMIN_USER);
JSONObject config = JSON.parseObject(
"{'entity':'User','title':'指标卡','type':'INDEX','axis':{'dimension':[],'numerical':[{'field':'userId','sort':'','calc':'COUNT'}]}}");
ChartData index = ChartDataFactory.create(config);
System.out.println(index.build());
}
}

View file

@ -0,0 +1,48 @@
/*
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.helper.manager;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.rebuild.server.TestSupport;
import com.rebuild.server.service.bizz.UserService;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class FormsManagerTest extends TestSupport {
@Test
public void testModel() throws Exception {
JSON newModel = FormsManager.getFormModel("User", UserService.ADMIN_USER);
System.out.println(newModel);
JSON editModel = FormsManager.getFormModel("User", UserService.ADMIN_USER, UserService.SYSTEM_USER);
System.out.println(editModel);
}
@Test
public void testViewModel() throws Exception {
JSON viewModel = FormsManager.getViewModel("User", UserService.ADMIN_USER, UserService.SYSTEM_USER);
System.out.println(viewModel);
}
}

View file

@ -0,0 +1,89 @@
/*
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.helper.task;
import java.util.concurrent.RejectedExecutionException;
import org.junit.Test;
import cn.devezhao.commons.ThreadPool;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class BulkTaskTest {
@Test
public void testTask() throws Exception {
String taskid1 = BulkTaskExecutor.submit(new TestTask("testTask1", 5));
System.out.println("Submit Task1 : " + taskid1);
String taskid2 = BulkTaskExecutor.submit(new TestTask("testTask2",5));
System.out.println("Submit Task2 : " + taskid2);
ThreadPool.waitFor(2 * 1000);
}
@Test(expected=RejectedExecutionException.class)
public void testRejected() throws Exception {
for (int i = 0; i < 30; i++) {
BulkTaskExecutor.submit(new TestTask("testRejected", 2));
}
}
@Test
public void testCancel() throws Exception {
ThreadPool.waitFor(1 * 1000); // Wait testRejected
String taskid = BulkTaskExecutor.submit(new TestTask("testCancel", 100));
System.out.println("Submit Task : " + taskid);
ThreadPool.waitFor(1000 * 2);
boolean cancel = BulkTaskExecutor.cancel(taskid);
System.out.println("Cancel Task : " + taskid + " > " + cancel);
ThreadPool.waitFor(1 * 1000);
}
static class TestTask extends BulkTask {
private String name;
private int number;
protected TestTask(String name, int number) {
this.name = "[ " + name.toUpperCase() + " ] ";
this.number = number;
}
@Override
public void run() {
this.setTotal(this.number);
for (int i = 0; i < this.number; i++) {
if (this.isInterrupted()) {
System.err.println(this.name + "Interrupted : " + this.getComplete() + " / " + this.getTotal());
break;
}
ThreadPool.waitFor(200); // Mock time
System.out.println(this.name + "Mock ... " + i);
this.setCompleteOne();
}
this.completedAfter();
}
}
}

View file

@ -16,13 +16,21 @@ 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.task;
package com.rebuild.server.helper.task;
import org.junit.Test;
import com.rebuild.server.TestSupport;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class QuickCodeReindexTaskTest {
public class QuickCodeReindexTaskTest extends TestSupport {
@Test
public void testReindex() throws Exception {
}
}

View file

@ -0,0 +1,63 @@
/*
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.service.base;
import org.junit.Assert;
import org.junit.Test;
import com.rebuild.server.Application;
import com.rebuild.server.TestSupport;
import com.rebuild.server.metadata.EntityHelper;
import com.rebuild.server.service.IEntityService;
import com.rebuild.server.service.bizz.UserService;
import cn.devezhao.persist4j.Record;
import cn.devezhao.persist4j.engine.ID;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class GeneralEntityServiceTest extends TestSupport {
@Test
public void testGetEntityService() throws Exception {
IEntityService ies = Application.getEntityService(EntityHelper.User);
Assert.assertTrue(ies.getEntityCode() == EntityHelper.User);
}
@Test
public void testCRUD() throws Exception {
Record record = EntityHelper.forNew(EntityHelper.Role, UserService.ADMIN_USER);
record.setString("name", "测试角色");
record = Application.getEntityService(EntityHelper.Role).create(record);
ID roleId = record.getPrimary();
System.out.println(Application.getUserStore().getRole(roleId).getName());
record = EntityHelper.forUpdate(roleId, UserService.ADMIN_USER);
record.setString("name", "测试角色-2");
record = Application.getEntityService(EntityHelper.Role).createOrUpdate(record);
System.out.println(Application.getUserStore().getRole(roleId).getName());
Application.getEntityService(EntityHelper.Role).delete(roleId);
}
}

View file

@ -0,0 +1,45 @@
/*
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.service.bizz;
import org.junit.Test;
import com.rebuild.server.Application;
import com.rebuild.server.TestSupport;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class UserStoreTest extends TestSupport {
@Test
public void testStore() throws Exception {
Application.getUserStore().getAllUsers();
Application.getUserStore().getAllDepartments();
}
@Test
public void testRefresh() throws Exception {
Application.getUserStore().refreshUser(UserService.ADMIN_USER);
Application.getUserStore().refreshDepartment(DepartmentService.ROOT_DEPT);
Application.getUserStore().refreshRole(RoleService.ADMIN_ROLE, true);
}
}

View file

@ -0,0 +1,48 @@
/*
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.service.query;
import org.junit.Test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.rebuild.server.TestSupport;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class AdvFilterParserTest extends TestSupport {
@Test
public void testBaseParse() throws Exception {
JSONObject filterExp = new JSONObject();
filterExp.put("entity", "User");
JSONArray items = new JSONArray();
filterExp.put("items", items);
// Filter entry
items.add(JSON.parseObject("{ op:'LK', field:'loginName', value:'admin' }"));
String where = new AdvFilterParser(filterExp).toSqlWhere();
System.out.println(where);
}
}

View file

@ -0,0 +1,49 @@
/*
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.service.query;
import org.junit.Assert;
import org.junit.Test;
import com.rebuild.server.Application;
import com.rebuild.server.TestSupport;
import com.rebuild.server.service.bizz.UserService;
import cn.devezhao.bizz.security.AccessDeniedException;
import cn.devezhao.persist4j.Filter;
/**
*
* @author devezhao
* @since 01/04/2019
*/
public class QueryFactoryTest extends TestSupport {
@Test
public void testBaseQuery() throws Exception {
Filter filter = Application.getSecurityManager().createQueryFilter(UserService.SYSTEM_USER);
Object[][] array = Application.getQueryFactory().createQuery("select loginName from User", filter).array();
Assert.assertTrue(array.length > 0);
}
@Test(expected=AccessDeniedException.class)
public void testNoUser() throws Exception {
Application.getQueryFactory().createQuery("select loginName from User").array();
}
}