package com.bonait.ealm.tomp.action.test; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Result; import org.apache.struts2.convention.annotation.Results; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import com.bonait.ealm.core.web.action.EalmBaseAction; import com.bonait.ealm.tomp.model.test.NewTestCase; import com.bonait.ealm.tomp.model.test.NewTestCaseStep; import com.bonait.ealm.tomp.model.test.ReuseTestCase; import com.bonait.ealm.tomp.model.test.ReuseTestCaseStep; import com.bonait.ealm.tomp.model.testprocess.SystemModule; import com.bonait.ealm.tomp.model.testprocess.TestCase; import com.bonait.ealm.tomp.model.testprocess.TestCaseStep; import com.bonait.ealm.tomp.service.test.PublicTestCaseService; import com.bonait.ealm.tomp.service.test.ReuseTestCaseService; import com.bonait.ealm.tomp.service.testprocess.SystemModuleService; import com.bonait.ealm.tomp.service.testprocess.TestCaseService; import com.htsoft.core.command.QueryFilter; import flexjson.JSONSerializer; import flexjson.transformer.DateTransformer; @Component("TestCaseReuseAction") @Action(value = "testCaseReuse") @Scope("prototype") @Results({ @Result(name = "reuseTestCaseInfo", type = "dispatcher", location = "/pages/testCase/reuseTestCaseInfo.jsp") }) public class TestCaseReuseAction extends EalmBaseAction { private final static Logger logger = Logger .getLogger(TestCaseReuseAction.class); @Resource private PublicTestCaseService publicTestCaseService; @Resource private ReuseTestCaseService reuseTestCaseService; @Resource private TestCaseService testCaseService; @Resource private SystemModuleService systemModuleService; private Long id; private ReuseTestCase reuseTestCase; private ReuseTestCase frontReuseTestCase; /** * 封装要复用到个人用例模版的对象 * * @param reuseNewTestCase * @param moduleId * @param tcName * @param editTcName * @return */ public NewTestCase addTestCase(ReuseTestCase reuseNewTestCase, String moduleId, String tcName, String editTcName) { NewTestCase newTestCase = new NewTestCase(); newTestCase.setCondition(reuseNewTestCase.getCondition()); newTestCase.setDataGroupId(reuseNewTestCase.getDataGroupId()); newTestCase.setExecuteWay(reuseNewTestCase.getExecuteWay()); newTestCase.setModuleId(new Long(moduleId)); newTestCase.setPriority(reuseNewTestCase.getPriority()); newTestCase.setRelateFlag(reuseNewTestCase.getRelateFlag()); newTestCase.setTcDesc(reuseNewTestCase.getTcDesc()); newTestCase.setState(reuseNewTestCase.getState()); newTestCase.setTcType(reuseNewTestCase.getTcType()); newTestCase.setTcSn(reuseNewTestCase.getTcSn()); newTestCase.setCreateId(reuseNewTestCase.getCreateId()); newTestCase.setCreater(reuseNewTestCase.getCreater()); if (tcName.equals("") || tcName == null) { newTestCase.setTcName(editTcName); } else { newTestCase.setTcName(tcName); } return newTestCase; } /** * 将复用后的用例添加到个人用例模版 * * @return reuseTestCaseService */ public String addTestCaseToPersonal() { // 要复用用例的Id String id = getRequest().getParameter("ids"); // 用例名称 String tcName = getRequest().getParameter("tcName"); // 替换前的名称 String editTcName = getRequest().getParameter("editTcName"); // 要复用到那个模块的Id String moduleId = getRequest().getParameter("moduleId"); // 根据id查找复用用例 ReuseTestCase reuseNewTestCase = reuseTestCaseService.get(Long .parseLong(id)); // 解析用例步骤 String steps = delSteps(reuseNewTestCase); // 调用封装方法 NewTestCase newTestCase = addTestCase(reuseNewTestCase, moduleId, tcName, editTcName); // 保存到个人用例 publicTestCaseService.save(newTestCase, steps); return SUCCESS; } /** * 从公共用例选择要复用的用例 * * @param newTestCase * @param state */ public void dealData(NewTestCase newTestCase, String state) { ReuseTestCase tempNewTestCase = new ReuseTestCase(); tempNewTestCase.setCondition(newTestCase.getCondition()); tempNewTestCase.setCreateId(newTestCase.getCreateId()); tempNewTestCase.setCreater(newTestCase.getCreater()); tempNewTestCase.setExecuteWay(newTestCase.getExecuteWay()); tempNewTestCase.setExpertResults(newTestCase.getExpertResults()); tempNewTestCase.setPriority(newTestCase.getPriority()); tempNewTestCase.setRelateFlag(newTestCase.getRelateFlag()); tempNewTestCase.setSetpDesc(newTestCase.getStepDesc()); tempNewTestCase.setState(state);// 用于用例是否被复用 (01 未复用 02 已复用) tempNewTestCase.setTcDesc(newTestCase.getTcDesc()); tempNewTestCase.setTcName(newTestCase.getTcName()); tempNewTestCase.setTcSn(newTestCase.getTcSn()); tempNewTestCase.setTcType(newTestCase.getTcType()); // tempNewTestCase.setEditTcName(null); Set<ReuseTestCaseStep> tempTestCaseSteps = new HashSet<ReuseTestCaseStep>(); Set<NewTestCaseStep> newTestCaseSteps = newTestCase.getTestCaseSteps(); for (Iterator<NewTestCaseStep> iterator = newTestCaseSteps.iterator(); iterator .hasNext();) { NewTestCaseStep newTestCaseStep = iterator.next(); ReuseTestCaseStep tempTestCaseStep = new ReuseTestCaseStep(); tempTestCaseStep.setExpectResult(newTestCaseStep.getExpectResult()); tempTestCaseStep.setSort(newTestCaseStep.getSort()); tempTestCaseStep.setStepDesc(newTestCaseStep.getStepDesc()); tempTestCaseSteps.add(tempTestCaseStep); } reuseTestCaseService.save(tempNewTestCase, tempTestCaseSteps); } // public void dealData2(TestCase newTestCase, String state) { ReuseTestCase tempNewTestCase = new ReuseTestCase(); tempNewTestCase.setCondition(newTestCase.getCondition()); tempNewTestCase.setCreateId(newTestCase.getCreateId()); tempNewTestCase.setCreater(newTestCase.getCreater()); tempNewTestCase.setExecuteWay(newTestCase.getExecuteWay()); // tempNewTestCase.setExpertResults(newTestCase.getExpertResults()); tempNewTestCase.setPriority(newTestCase.getPriority()); tempNewTestCase.setRelateFlag(newTestCase.getRelateFlag()); tempNewTestCase.setSetpDesc(newTestCase.getStepDesc()); tempNewTestCase.setState(state);// 用于用例是否被复用 (01 未复用 02 已复用) tempNewTestCase.setTcDesc(newTestCase.getTcDesc()); tempNewTestCase.setTcName(newTestCase.getTcName()); tempNewTestCase.setTcSn(newTestCase.getTcSn()); tempNewTestCase.setTcType(newTestCase.getTcType()); // tempNewTestCase.setEditTcName(null); Set<ReuseTestCaseStep> tempTestCaseSteps = new HashSet<ReuseTestCaseStep>(); Set<TestCaseStep> newTestCaseSteps = newTestCase.getTestCaseSteps(); for (Iterator<TestCaseStep> iterator = newTestCaseSteps.iterator(); iterator .hasNext();) { TestCaseStep newTestCaseStep = iterator.next(); ReuseTestCaseStep tempTestCaseStep = new ReuseTestCaseStep(); tempTestCaseStep.setExpectResult(newTestCaseStep.getExpectResult()); tempTestCaseStep.setSort(newTestCaseStep.getSort()); tempTestCaseStep.setStepDesc(newTestCaseStep.getStepDesc()); tempTestCaseSteps.add(tempTestCaseStep); } reuseTestCaseService.save(tempNewTestCase, tempTestCaseSteps); } // public void dealData3(TestCase newTestCase, String state) { ReuseTestCase tempNewTestCase = new ReuseTestCase(); tempNewTestCase.setCondition(newTestCase.getCondition()); tempNewTestCase.setCreateId(newTestCase.getCreateId()); tempNewTestCase.setCreater(newTestCase.getCreater()); tempNewTestCase.setExecuteWay(newTestCase.getExecuteWay()); // tempNewTestCase.setExpertResults(newTestCase.getExpertResults()); tempNewTestCase.setPriority(newTestCase.getPriority()); tempNewTestCase.setRelateFlag(newTestCase.getRelateFlag()); tempNewTestCase.setSetpDesc(newTestCase.getStepDesc()); tempNewTestCase.setState(state);// 用于用例是否被复用 (01 未复用 02 已复用) tempNewTestCase.setTcDesc(newTestCase.getTcDesc()); tempNewTestCase.setTcName(newTestCase.getTcName()); tempNewTestCase.setTcSn(newTestCase.getTcSn()); tempNewTestCase.setTcType(newTestCase.getTcType()); // tempNewTestCase.setEditTcName(null); Set<ReuseTestCaseStep> tempTestCaseSteps = new HashSet<ReuseTestCaseStep>(); Set<TestCaseStep> newTestCaseSteps = newTestCase.getTestCaseSteps(); for (Iterator<TestCaseStep> iterator = newTestCaseSteps.iterator(); iterator .hasNext();) { TestCaseStep newTestCaseStep = iterator.next(); ReuseTestCaseStep tempTestCaseStep = new ReuseTestCaseStep(); tempTestCaseStep.setExpectResult(newTestCaseStep.getExpectResult()); tempTestCaseStep.setSort(newTestCaseStep.getSort()); tempTestCaseStep.setStepDesc(newTestCaseStep.getStepDesc()); tempTestCaseSteps.add(tempTestCaseStep); } reuseTestCaseService.save(tempNewTestCase, tempTestCaseSteps); } /** * 解析步骤 * * @param tempNewTestCase * @return */ public String delSteps(ReuseTestCase tempNewTestCase) { StringBuffer sb = new StringBuffer("["); Set<ReuseTestCaseStep> tempTestCaseSteps = tempNewTestCase .getTestCaseSteps(); for (Iterator<ReuseTestCaseStep> iterator = tempTestCaseSteps .iterator(); iterator.hasNext();) { ReuseTestCaseStep tempTestCaseStep = iterator.next(); sb.append("{\"stepDesc\":" + "\"" + tempTestCaseStep.getStepDesc() + "\""); sb.append( ",\"expectResult\":" + "\"" + tempTestCaseStep.getExpectResult() + "\"") .append("},"); } sb.deleteCharAt(sb.length() - 1); sb.append("]"); return sb.toString(); } public ReuseTestCase getFrontReuseTestCase() { return frontReuseTestCase; } public Long getId() { return id; } public ReuseTestCase getReuseTestCase() { return reuseTestCase; } /** * 批量删除数据 * * @return */ public String multiDel() { String ids[] = getRequest().getParameterValues("ids"); reuseTestCaseService.multiDel(ids); jsonString = "{success:true}"; return SUCCESS; } /** * 查询方法 * * @return */ public String queryList() { String state = getRequest().getParameter("state"); QueryFilter filter = new QueryFilter(getRequest()); List<ReuseTestCase> list = reuseTestCaseService.queryList(state, filter.getPagingBean()); StringBuffer sb = (new StringBuffer("{success:true,'totalCounts':")) .append(filter.getPagingBean().getTotalItems()).append( ",result:"); JSONSerializer json = new JSONSerializer(); json.transform(new DateTransformer("yyyy-MM-dd"), new String[] { "createTime", "updateTime" }); sb.append(json.serialize(list)); sb.append("}"); setJsonString(sb.toString()); jsonString = sb.toString(); logger.debug(jsonString); return SUCCESS; } /** * 复用后的查询方法 * * @return */ public String queryList1() { String state = getRequest().getParameter("state"); QueryFilter filter = new QueryFilter(getRequest()); List<ReuseTestCase> tempTestCases = reuseTestCaseService.queryList( state, filter.getPagingBean()); List<ReuseTestCase> list = new ArrayList<ReuseTestCase>(); List<Long> ids = new ArrayList<Long>(); for (Iterator<ReuseTestCase> iterator = tempTestCases.iterator(); iterator .hasNext();) { ReuseTestCase testCase = iterator.next(); ids.add(testCase.getTempTcId()); } for (Iterator<ReuseTestCase> iterator = tempTestCases.iterator(); iterator .hasNext();) { ReuseTestCase testCase = iterator.next(); if (testCase.getEditFrontId() != null) { ids.remove(testCase.getEditFrontId()); } } for (int i = 0; i < ids.size(); i++) { ReuseTestCase tc = reuseTestCaseService.get(ids.get(i)); if (tc.getEditFrontId() != null) { ReuseTestCase frontTc = reuseTestCaseService.get(tc .getEditFrontId()); tc.setEditTcName(frontTc.getTcName()); } else { tc.setEditTcName(tc.getTcName()); tc.setTcName(null); } list.add(tc); } StringBuffer sb = (new StringBuffer("{success:true,'totalCounts':")) .append(filter.getPagingBean().getTotalItems()).append( ",result:"); JSONSerializer json = new JSONSerializer(); json.transform(new DateTransformer("yyyy-MM-dd"), new String[] { "createTime", "updateTime" }); sb.append(json.serialize(list)); sb.append("}"); setJsonString(sb.toString()); jsonString = sb.toString(); logger.debug(jsonString); return SUCCESS; } // 替换方法 public void replace(ReuseTestCase tempNewTestCase, String str1, String replace) { ReuseTestCase testCase = new ReuseTestCase(); testCase.setCreateId(tempNewTestCase.getCreateId()); testCase.setCreater(tempNewTestCase.getCreater()); testCase.setExecuteWay(tempNewTestCase.getExecuteWay()); testCase.setPriority(tempNewTestCase.getPriority()); testCase.setRelateFlag(tempNewTestCase.getRelateFlag()); testCase.setModuleId(tempNewTestCase.getModuleId()); testCase.setModuleName(tempNewTestCase.getModuleName()); testCase.setTcType(tempNewTestCase.getTcType()); testCase.setModuleDm(tempNewTestCase.getModuleDm()); testCase.setpId(tempNewTestCase.getpId()); testCase.setSysId(tempNewTestCase.getSysId()); int num = 0;// 统计要替换的次数 String tcName = tempNewTestCase.getTcName(); String desc = tempNewTestCase.getTcDesc(); String condition = tempNewTestCase.getCondition(); String replaceName = null; String replaceDesc = null; String replaceCondition = null; if (tcName != null && !"".equals(tcName)) { if (tcName.contains(str1)) { replaceName = tcName.replaceAll(str1, replace); testCase.setTcName(replaceName); num++; } else { testCase.setTcName(tempNewTestCase.getTcName()); } } else { testCase.setTcName(""); } if (desc != null && !"".equals(desc)) { if (desc.contains(str1)) { replaceDesc = desc.replaceAll(str1, replace); testCase.setTcDesc(replaceDesc); num++; } else { testCase.setTcDesc(tempNewTestCase.getTcDesc()); } } else { testCase.setTcDesc(""); } if (condition != null && !"".equals(condition)) { if (condition.contains(str1)) { replaceCondition = condition.replaceAll(str1, replace); testCase.setCondition(replaceCondition); num++; } else { testCase.setCondition(tempNewTestCase.getCondition()); } } else { testCase.setCondition(""); } Set<ReuseTestCaseStep> tempTestCaseSteps = tempNewTestCase .getTestCaseSteps(); Set<ReuseTestCaseStep> testCaseSteps = new HashSet<ReuseTestCaseStep>(); if (tempTestCaseSteps != null) { for (Iterator<ReuseTestCaseStep> iterator = tempTestCaseSteps .iterator(); iterator.hasNext();) { ReuseTestCaseStep tempTestCaseStep = iterator.next(); ReuseTestCaseStep testCaseStep = new ReuseTestCaseStep(); testCaseStep.setSort(tempTestCaseStep.getSort()); String expectResult = tempTestCaseStep.getExpectResult(); String stepDesc = tempTestCaseStep.getStepDesc(); String replaceExpectResult = null; String replaceStepDesc = null; if (expectResult.contains(str1)) { replaceExpectResult = expectResult .replaceAll(str1, replace); testCaseStep.setExpectResult(replaceExpectResult); num++; } else { testCaseStep.setExpectResult(tempTestCaseStep .getExpectResult()); } if (stepDesc.contains(str1)) { replaceStepDesc = stepDesc.replaceAll(str1, replace); testCaseStep.setStepDesc(replaceStepDesc); num++; } else { testCaseStep.setStepDesc(tempTestCaseStep.getStepDesc()); } testCaseSteps.add(testCaseStep); } if (num != 0) { testCase.setEditFrontId(tempNewTestCase.getTempTcId()); testCase.setState("02"); reuseTestCaseService.save(testCase, testCaseSteps); } } } public TestCase reuseDealData(ReuseTestCase temp, String tcName, String editTcName) { SystemModule systemModule = systemModuleService.get(temp.getModuleId()); TestCase testCase = new TestCase(); testCase.setCondition(temp.getCondition()); testCase.setCreateId(temp.getCreateId()); testCase.setCreater(temp.getCreater()); testCase.setCreateTime(temp.getCreateTime()); testCase.setExecuteWay(temp.getExecuteWay()); testCase.setPriority(temp.getPriority()); testCase.setRelateFlag(temp.getRelateFlag()); testCase.setState("01"); testCase.setSystemModule(systemModule); testCase.setTcDesc(temp.getTcDesc()); if (tcName.equals("") || tcName == null) { testCase.setTcName(editTcName); } else { testCase.setTcName(tcName); } testCase.setTcSn(""); testCase.setTcType(temp.getTcType()); return testCase; } /** * 将用例复用到具体的模块中 * * @return */ @SuppressWarnings("unchecked") public String reuserTestCase() { String tempTcId = getRequest().getParameter("tempTcId"); String tempTcName = getRequest().getParameter("tcName"); String tempEditTcName = getRequest().getParameter("editTcName"); ReuseTestCase tempNewTestCase = reuseTestCaseService.get(Long .parseLong(tempTcId)); String projectId = tempNewTestCase.getpId().toString(); String sysId = tempNewTestCase.getSysId().toString(); StringBuffer sb = new StringBuffer("["); Set<ReuseTestCaseStep> tempTestCaseSteps = tempNewTestCase .getTestCaseSteps(); for (Iterator<ReuseTestCaseStep> iterator = tempTestCaseSteps .iterator(); iterator.hasNext();) { ReuseTestCaseStep tempTestCaseStep = iterator.next(); sb.append("{\"stepDesc\":" + "\"" + tempTestCaseStep.getStepDesc() + "\""); sb.append( ",\"expectResult\":" + "\"" + tempTestCaseStep.getExpectResult() + "\"") .append("},"); } sb.deleteCharAt(sb.length() - 1); sb.append("]"); String moduleDm = tempNewTestCase.getModuleDm(); TestCase testCase = reuseDealData(tempNewTestCase, tempTcName, tempEditTcName); try { Map params = new HashMap<String, Object>(); params.put("testCase", testCase); params.put("projectId", projectId); params.put("sysId", sysId); params.put("testCaseSteps", sb.toString()); params.put("moduleDm", moduleDm); setJsonString(testCaseService.save(params)); } catch (Exception e) { logger.error("保存异常", e); } return SUCCESS; } /** * 保存选择的用例 * save1 */ public String save() { // 处理页面非正常关闭时,操作的不合理性 QueryFilter filter = new QueryFilter(getRequest()); // 查询所有的用例 List<ReuseTestCase> oldList = reuseTestCaseService.queryList(null, filter.getPagingBean()); // 在复用前在数据库中还有数据,将其先删除 if (oldList.size() != 0) { String delIds[] = new String[oldList.size()]; for (int j = 0; j < oldList.size(); j++) { ReuseTestCase temp = oldList.get(j); delIds[j] = temp.getTempTcId().toString(); // System.out.println(delIds[j]); } reuseTestCaseService.multiDel(delIds); } // 选中要复用的用例id String ids[] = getRequest().getParameterValues("ids"); int num = 0; if (ids != null && ids.length > 0) { for (int i = 0; i < ids.length; i++) { List<ReuseTestCase> list = reuseTestCaseService.queryList(null, filter.getPagingBean()); Long tcId = new Long(ids[i]); NewTestCase newTestCase = publicTestCaseService.get(tcId); if (list.size() == 0) { dealData(newTestCase, "01"); continue; } else { for (int j = 0; j < list.size(); j++) { ReuseTestCase temp = list.get(j);// 过滤重复项 if (temp.getTcName().equals(newTestCase.getTcName())) { num++; break; } } } if (num == 0) { dealData(newTestCase, "01"); } } } StringBuffer sb = (new StringBuffer("{success:true,'num':")); JSONSerializer json = new JSONSerializer(); sb.append(json.serialize(num)); sb.append("}"); setJsonString(sb.toString()); return SUCCESS; } /** * 保存选择的用例 * save2 */ public String save2() { // 处理页面非正常关闭时,操作的不合理性 QueryFilter filter = new QueryFilter(getRequest()); // 查询所有的用例 List<ReuseTestCase> oldList = reuseTestCaseService.queryList(null, filter.getPagingBean()); // 在复用前在数据库中还有数据,将其先删除 if (oldList.size() != 0) { String delIds[] = new String[oldList.size()]; for (int j = 0; j < oldList.size(); j++) { ReuseTestCase temp = oldList.get(j); delIds[j] = temp.getTempTcId().toString(); // System.out.println(delIds[j]); } reuseTestCaseService.multiDel(delIds); } // 选中要复用的用例id String ids[] = getRequest().getParameterValues("ids"); int num = 0; if (ids != null && ids.length > 0) { for (int i = 0; i < ids.length; i++) { List<ReuseTestCase> list = reuseTestCaseService.queryList(null,filter.getPagingBean()); Long tcId = new Long(ids[i]); // NewTestCase newTestCase = publicTestCaseService.get(tcId); TestCase testCase =testCaseService.get(tcId); // 2014-5-9 17:02:55 if (list.size() == 0) { dealData2(testCase, "01"); continue; } else { for (int j = 0; j < list.size(); j++) { ReuseTestCase temp = list.get(j);// 过滤重复项 if (temp.getTcName().equals(testCase.getTcName())) { num++; break; } } } if (num == 0) { dealData2(testCase, "01"); } } } StringBuffer sb = (new StringBuffer("{success:true,'num':")); JSONSerializer json = new JSONSerializer(); sb.append(json.serialize(num)); sb.append("}"); setJsonString(sb.toString()); return SUCCESS; } /** * 保存选择的用例 * save3 */ public String save3() { // 处理页面非正常关闭时,操作的不合理性 QueryFilter filter = new QueryFilter(getRequest()); // 查询所有的用例 List<ReuseTestCase> oldList = reuseTestCaseService.queryList(null, filter.getPagingBean()); // 在复用前在数据库中还有数据,将其先删除 if (oldList.size() != 0) { String delIds[] = new String[oldList.size()]; for (int j = 0; j < oldList.size(); j++) { ReuseTestCase temp = oldList.get(j); delIds[j] = temp.getTempTcId().toString(); // System.out.println(delIds[j]); } reuseTestCaseService.multiDel(delIds); } // 选中要复用的用例id String ids[] = getRequest().getParameterValues("ids"); int num = 0; if (ids != null && ids.length > 0) { for (int i = 0; i < ids.length; i++) { List<ReuseTestCase> list = reuseTestCaseService.queryList(null,filter.getPagingBean()); Long tcId = new Long(ids[i]); // NewTestCase newTestCase = publicTestCaseService.get(tcId); TestCase testCase =testCaseService.get(tcId); // 2014-5-9 17:02:55 if (list.size() == 0) { dealData3(testCase, "01"); continue; } else { for (int j = 0; j < list.size(); j++) { ReuseTestCase temp = list.get(j);// 过滤重复项 if (temp.getTcName().equals(testCase.getTcName())) { num++; break; } } } if (num == 0) { dealData3(testCase, "01"); } } } StringBuffer sb = (new StringBuffer("{success:true,'num':")); JSONSerializer json = new JSONSerializer(); sb.append(json.serialize(num)); sb.append("}"); setJsonString(sb.toString()); return SUCCESS; } /** * 选择用例,开始复用 * * @return */ public String select() { // 选择的要复用的用例Id String ids[] = getRequest().getParameterValues("ids"); String id = getRequest().getParameter("moduleId"); // 要将用例中的那写内容替换。 String tcName[] = getRequest().getParameterValues("tcName"); // 对应要替换为什么内容 String replaceName[] = getRequest().getParameterValues("replaceName"); // 要复用到那个项目的项目Id Long pId = Long.parseLong(getRequest().getParameter("pId")); SystemModule systemModule = systemModuleService .getSystemModuleById(Long.parseLong(id)); // 要复用到的模块Id Long moduleId = systemModule.getModuleId(); // 模块代码 String moduleDm = systemModule.getModuleDm(); // 系统Id String sysId = systemModule.getSysId().toString(); // 模块名称 String moduleName = systemModule.getModuleName(); // 标记 int num = 0; // 首先判断用没有选择要复用的用例 if (ids != null) { // 循环处理要复用的用例 for (int i = 0; i < ids.length; i++) { if (!"".equals(ids[i]) && !"".equals(tcName[i]) && !"".equals(replaceName[i])) { ReuseTestCase tempNewTestCase = reuseTestCaseService .get(Long.parseLong(ids[i])); tempNewTestCase.setState("02"); tempNewTestCase.setModuleId(moduleId); tempNewTestCase.setModuleName(moduleName); tempNewTestCase.setpId(pId); tempNewTestCase.setModuleDm(moduleDm); tempNewTestCase.setSysId(Long.parseLong(sysId)); tempNewTestCase.setEditTcName(tempNewTestCase.getTcName()); reuseTestCaseService.merge(tempNewTestCase); replace(tempNewTestCase, tcName[i], replaceName[i]); num++; } else { // 选择不替换 Long tcId = new Long(ids[i]); ReuseTestCase tempNewTestCase = reuseTestCaseService .get(tcId); tempNewTestCase.setState("02"); tempNewTestCase.setModuleId(moduleId); tempNewTestCase.setModuleName(moduleName); tempNewTestCase.setpId(pId); tempNewTestCase.setModuleDm(moduleDm); tempNewTestCase.setSysId(Long.parseLong(sysId)); tempNewTestCase.setEditTcName(tempNewTestCase.getTcName()); reuseTestCaseService.merge(tempNewTestCase); num++; } } } StringBuffer sb = (new StringBuffer("{success:true,'num':")); JSONSerializer json = new JSONSerializer(); sb.append(json.serialize(num)); sb.append("}"); setJsonString(sb.toString()); return SUCCESS; } public void setFrontReuseTestCase(ReuseTestCase frontReuseTestCase) { this.frontReuseTestCase = frontReuseTestCase; } public void setId(Long id) { this.id = id; } public void setReuseTestCase(ReuseTestCase reuseTestCase) { this.reuseTestCase = reuseTestCase; } /** * 测试用例信息 * * @return */ public String testCaseInfo() { ReuseTestCase tempTestCaseInfo = reuseTestCaseService.get(id); if (tempTestCaseInfo.getEditFrontId() != null && !tempTestCaseInfo.getEditFrontId().equals("")) { this.setFrontReuseTestCase(reuseTestCaseService .get(tempTestCaseInfo.getEditFrontId())); this.setReuseTestCase(tempTestCaseInfo); } else { this.setFrontReuseTestCase(tempTestCaseInfo); this.setReuseTestCase(null); } return "reuseTestCaseInfo"; } }
111111111
猜你喜欢
转载自lee4.iteye.com/blog/2075907
今日推荐
周排行