`

111111111

    博客分类:
  • 1111
 
阅读更多
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.zip

    【标题】:“英文文献111111111.zip” 这个压缩包文件的标题“英文文献111111111.zip”暗示了其内容主要为一系列的英文文献资料。在学术研究、专业学习或知识探索中,英文文献往往占据了重要的地位,因为许多原创的...

    VC 域名解析程序111111111

    【VC 域名解析程序111111111】 在计算机网络中,域名解析是将人类可读的域名转换为机器可识别的IP地址的过程。这个过程涉及到了DNS(Domain Name System)系统,它是互联网的一项基础服务。在VC++编程环境下,我们...

    航空订票系统波形图111111111

    在本案例中,“航空订票系统波形图111111111”可能指的是一个特定的分析或监控功能,用于帮助管理者理解和优化系统的运行状况。 首先,我们来详细探讨航空订票系统的基本组成部分和功能。航空订票系统通常由以下几...

    js问卷调查111111111.zip

    "js问卷调查111111111.zip"很可能包含了一整套使用JavaScript实现的问卷调查系统,具备单选、多选以及修改和删除功能。在本文中,我们将深入探讨JavaScript在创建问卷调查中的应用,以及相关的技术细节。 首先,...

    微服务治理目录111111111

    111111111

    テーブル定義書.xlsx111111111

    111111111

    111111111(1).zip

    标题和描述都是"111111111(1).zip",标签是"资料",压缩包内只有一个名为"111111111.doc"的文件。在这样的情况下,没有具体的内容或主题来展开讨论。若能提供更详细的信息,比如这个文档是关于编程、网络安全、数据...

    9 Spark.zip111111111

    这个名为"9 Spark.zip111111111"的压缩包可能包含了关于Spark的详细学习资源,包括笔记、晨测、资料和技术图解等。 笔记部分可能涵盖了Spark的基础概念,例如RDD(弹性分布式数据集)、DataFrame和DataSet,这些都...

    判断题.pdf111111111

    判断题.pdf111111111

    PFD13.py111111111

    PFD13.py111111111

    PFD6.py111111111

    PFD6.py111111111

    pd31.py111111111

    pd31.py111111111

    流程图示例111111111

    "流程图示例111111111" 本资源摘要信息是关于流程图示例的知识点总结,涵盖了业务全流程的节点、客户关系服务、客户注册、电子签章申请、代理收付款账户开通、发票易安装、预约申请等多个方面。 业务全流程节点 ...

    y优化大师111111111

    优化11111111111111111111111111111

    大学物理 动量守恒111111111

    "大学物理 动量守恒111111111"这个标题可能是对大学物理课程中关于动量守恒定律的深入讲解或一堂课的主题。 【描述】: "大学物理 动量守恒111111111"的描述虽然简略,但暗示了这个主题将涉及动量守恒的基本概念、...

    拨号程序的简单列子111111111

    拨号程序1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

    JSP网上购物系统111111111

    【标题】"JSP网上购物系统111111111" 涉及的知识点主要集中在Java Server Pages(JSP)技术上,它是一种用于开发动态网页的服务器端脚本语言,广泛应用于构建电子商务网站。在这个项目中,"111111111"可能是版本号...

    4.Zookeeper.zip111111111

    【标题】"4.Zookeeper.zip111111111" 提供的资源主要围绕着Apache ZooKeeper,这是一个分布式协调服务,广泛应用于分布式系统中,如Hadoop、HBase、Kafka等。该压缩包包含了一些重要的工具和Zookeeper的版本文件。 ...

    react源码一份111111111

    这份"react源码一份111111111"可能是React的源代码副本,对于深入理解React的工作原理和实现机制非常有帮助。下面将详细讨论React的核心概念和技术。 1. **虚拟DOM(Virtual DOM)**:React通过引入虚拟DOM来提高UI...

    vlan基础笔记111111111

    vlan基础笔记111111111

Global site tag (gtag.js) - Google Analytics