refactor to testplanRepository completely
This commit is contained in:
parent
5f631374ae
commit
4aefb273a5
|
@ -186,7 +186,6 @@ public class BusinessModelMapFactory {
|
|||
ret.setFailTimes(testPlanDB.getFailTimes());
|
||||
ret.setId(testPlanDB.getId());
|
||||
ret.setName(testPlanDB.getName());
|
||||
ret.setTestPlanModelContent(testPlanDB.getTestPlanModelContent());
|
||||
ret.setTestPlanRunId(testPlanDB.getTestPlanRunId());
|
||||
ret.setUserModel(toModel(testPlanDB.getUser()));
|
||||
return ret;
|
||||
|
|
|
@ -5,15 +5,12 @@ import javax.persistence.Entity;
|
|||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "planedConfig")
|
||||
public class PlanedConfig {
|
||||
private int id;
|
||||
private TestPlanScript testPlanScript;
|
||||
private long warmUp;
|
||||
private long executeRange;
|
||||
private long coolDown;
|
||||
|
@ -29,16 +26,6 @@ public class PlanedConfig {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "testPlanScriptId", nullable = false)
|
||||
public TestPlanScript getTestPlanScript() {
|
||||
return testPlanScript;
|
||||
}
|
||||
|
||||
public void setTestPlanScript(TestPlanScript testPlanScript) {
|
||||
this.testPlanScript = testPlanScript;
|
||||
}
|
||||
|
||||
@Column(name = "warmUp", nullable = false)
|
||||
public long getWarmUp() {
|
||||
return warmUp;
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
|
@ -19,9 +23,9 @@ public class TestPlanDB {
|
|||
private Date createDateTime;
|
||||
private User user;
|
||||
private String testPlanRunId;
|
||||
private String testPlanModelContent;
|
||||
private String currentStatus;
|
||||
private int failTimes;
|
||||
private Set<TestPlanScript> testPlanScripts;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -71,15 +75,6 @@ public class TestPlanDB {
|
|||
this.user = user;
|
||||
}
|
||||
|
||||
@Column(name = "testPlanModelContent", columnDefinition = "LONGText", nullable = false)
|
||||
public String getTestPlanModelContent() {
|
||||
return testPlanModelContent;
|
||||
}
|
||||
|
||||
public void setTestPlanModelContent(String testPlanModelContent) {
|
||||
this.testPlanModelContent = testPlanModelContent;
|
||||
}
|
||||
|
||||
@Column(name = "currentStatus", nullable = false)
|
||||
public String getCurrentStatus() {
|
||||
return currentStatus;
|
||||
|
@ -98,4 +93,22 @@ public class TestPlanDB {
|
|||
this.failTimes = failTimes;
|
||||
}
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "testPlanId")
|
||||
public Set<TestPlanScript> getTestPlanScripts() {
|
||||
return testPlanScripts;
|
||||
}
|
||||
|
||||
public void setTestPlanScripts(Set<TestPlanScript> testPlanScripts) {
|
||||
this.testPlanScripts = testPlanScripts;
|
||||
}
|
||||
|
||||
public TestPlanScript extracSpecifiedScript(Script script) {
|
||||
for (TestPlanScript testPlanScript : testPlanScripts) {
|
||||
if (testPlanScript.getScript().getId() == script.getId()) {
|
||||
return testPlanScript;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package org.bench4q.master.entity;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
|
@ -16,7 +17,7 @@ public class TestPlanScript {
|
|||
private int id;
|
||||
private Script script;
|
||||
private int requireLoad;
|
||||
private TestPlanDB testPlanDB;
|
||||
private PlanedConfig planedConfig;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
@ -48,14 +49,14 @@ public class TestPlanScript {
|
|||
this.requireLoad = requireLoad;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "testPlanId", nullable = false)
|
||||
public TestPlanDB getTestPlanDB() {
|
||||
return testPlanDB;
|
||||
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "configId", nullable = false)
|
||||
public PlanedConfig getPlanedConfig() {
|
||||
return planedConfig;
|
||||
}
|
||||
|
||||
public void setTestPlanDB(TestPlanDB testPlanDB) {
|
||||
this.testPlanDB = testPlanDB;
|
||||
public void setPlanedConfig(PlanedConfig planedConfig) {
|
||||
this.planedConfig = planedConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package org.bench4q.master.factory;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.PlanedConfig;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.service.infrastructure.ScriptService;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.models.master.RunningScriptModel;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class TestPlanFactory {
|
||||
private ScriptService scriptService;
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
public TestPlanDB createATestPlanWithoutIdentity(
|
||||
TestPlanBusinessModel testPlanBusinessModel, User user, UUID runId) {
|
||||
TestPlanDB result = new TestPlanDB();
|
||||
result.setCreateDateTime(new Date());
|
||||
result.setCurrentStatus(TestPlanStatus.NotStart.name());
|
||||
result.setFailTimes(0);
|
||||
result.setName(testPlanBusinessModel.getName());
|
||||
result.setTestPlanRunId(runId.toString());
|
||||
result.setUser(user);
|
||||
Set<TestPlanScript> testPlanScripts = new HashSet<TestPlanScript>();
|
||||
for (RunningScriptModel runningScriptModel : testPlanBusinessModel
|
||||
.getRunningScriptModels()) {
|
||||
testPlanScripts.add(createATestPlanScriptWithoutId(
|
||||
runningScriptModel.getRequireLoad(),
|
||||
runningScriptModel.getScriptId(),
|
||||
runningScriptModel.getConfig()));
|
||||
}
|
||||
result.setTestPlanScripts(testPlanScripts);
|
||||
return result;
|
||||
}
|
||||
|
||||
public TestPlanScript createATestPlanScriptWithoutId(int requireLoad,
|
||||
int scriptId, TestScriptConfig config) {
|
||||
TestPlanScript testPlanScript = new TestPlanScript();
|
||||
testPlanScript.setRequireLoad(requireLoad);
|
||||
testPlanScript.setScript(this.getScriptService().getScript(scriptId));
|
||||
testPlanScript.setPlanedConfig(createAPlanedConfigWithoutId(config));
|
||||
return testPlanScript;
|
||||
}
|
||||
|
||||
private PlanedConfig createAPlanedConfigWithoutId(TestScriptConfig config) {
|
||||
PlanedConfig planedConfig = new PlanedConfig();
|
||||
planedConfig.setWarmUp(config.getWarmUp());
|
||||
planedConfig.setExecuteRange(config.getExecuteRange());
|
||||
planedConfig.setCoolDown(config.getCoolDown());
|
||||
return planedConfig;
|
||||
}
|
||||
}
|
|
@ -3,11 +3,13 @@ package org.bench4q.master.report;
|
|||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.master.service.infrastructure.MonitorResultService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanScriptService;
|
||||
import org.bench4q.master.service.infrastructure.TestPlanService;
|
||||
|
@ -26,6 +28,7 @@ public class ScriptReportService {
|
|||
public static String MAX_RESPONSE_TIME = "maxResponseTime(unit : time)";
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanService testPlanService;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private MonitorResultService monitorResultService;
|
||||
private Logger logger = Logger.getLogger(ScriptReportService.class);
|
||||
|
||||
|
@ -58,10 +61,19 @@ public class ScriptReportService {
|
|||
this.monitorResultService = monitorResultService;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanRepository(TestPlanRepository testPlanRepository) {
|
||||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
void createScriptsResultsImage(UUID testPlanRunId, Document document) {
|
||||
|
||||
List<TestPlanScript> scripts = this.getTestPlanScriptService()
|
||||
.queryTestPlanScripts(testPlanRunId);
|
||||
Set<TestPlanScript> scripts = this.getTestPlanRepository()
|
||||
.getTestPlan(testPlanRunId).getTestPlanScripts();
|
||||
if (scripts == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,8 @@ package org.bench4q.master.repository;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.entity.PlanedConfig;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.hibernate.Session;
|
||||
|
@ -15,6 +14,23 @@ import org.springframework.stereotype.Component;
|
|||
|
||||
@Component
|
||||
public class TestPlanRepository extends AbstractRepositoty {
|
||||
private Logger logger = Logger.getLogger(TestPlanRepository.class);
|
||||
|
||||
public boolean attach(TestPlanDB testPlanDB) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
session.merge(testPlanDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error(ExceptionLog.getStackTrace(e));
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
releaseSession(session);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean detach(int testPlanId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
|
@ -26,27 +42,6 @@ public class TestPlanRepository extends AbstractRepositoty {
|
|||
if (testPlanInDB == null) {
|
||||
return false;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScript> testPlanScripts = session
|
||||
.createCriteria(TestPlanScript.class)
|
||||
.add(Restrictions.eq("testPlanDB", testPlanInDB)).list();
|
||||
if (testPlanScripts == null) {
|
||||
return false;
|
||||
}
|
||||
for (TestPlanScript testPlanScript : testPlanScripts) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<PlanedConfig> configs = session
|
||||
.createCriteria(PlanedConfig.class)
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.list();
|
||||
if (configs == null) {
|
||||
return false;
|
||||
}
|
||||
for (PlanedConfig config : configs) {
|
||||
session.delete(config);
|
||||
}
|
||||
session.delete(testPlanScript);
|
||||
}
|
||||
session.delete(testPlanInDB);
|
||||
transaction.commit();
|
||||
return true;
|
||||
|
|
|
@ -9,9 +9,11 @@ import java.util.UUID;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.TestPlanScriptResult;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.ValueTimeModel;
|
||||
import org.bench4q.share.models.master.statistics.ScriptBehaviorsBriefModel;
|
||||
|
@ -26,6 +28,8 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class TestPlanScriptResultService {
|
||||
private TestPlanScriptService testPlanScriptService;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private ScriptService scriptService;
|
||||
private SessionHelper sessionHelper;
|
||||
private static Logger logger = Logger
|
||||
.getLogger(TestPlanScriptResultService.class);
|
||||
|
@ -49,6 +53,24 @@ public class TestPlanScriptResultService {
|
|||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanRepository(TestPlanRepository testPlanRepository) {
|
||||
this.testPlanRepository = testPlanRepository;
|
||||
}
|
||||
|
||||
private ScriptService getScriptService() {
|
||||
return scriptService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Here I just use the Time that createDateTime in testplanscriptResult, If
|
||||
* it's not accuracy, i just need to modify the way of pick createDateTime
|
||||
|
@ -123,13 +145,17 @@ public class TestPlanScriptResultService {
|
|||
private List<TestPlanScriptResult> doGetTestPlanScriptResults(
|
||||
UUID testPlanId, int scriptId, long startTime, Class<?> resultType,
|
||||
Session session) {
|
||||
// TestPlanScript testPlanScript = this.getTestPlanScriptService()
|
||||
// .doGetTestPlanScript(scriptId, testPlanId, session);
|
||||
TestPlanScript testPlanScript = this
|
||||
.getTestPlanRepository()
|
||||
.getTestPlan(testPlanId)
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(scriptId));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||
.createCriteria(TestPlanScriptResult.class)
|
||||
.add(Restrictions.eq(
|
||||
"testPlanScript",
|
||||
this.getTestPlanScriptService().doGetTestPlanScript(
|
||||
scriptId, testPlanId, session)))
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.add(Restrictions.eq("resultType", resultType.getName()))
|
||||
.add(Restrictions.ge("createDatetime", new Date(startTime)))
|
||||
.list();
|
||||
|
@ -157,13 +183,15 @@ public class TestPlanScriptResultService {
|
|||
|
||||
private TestPlanScriptResult doGetLastSampleResult(UUID testPlanId,
|
||||
int scriptId, Class<?> resultType, Session session) {
|
||||
TestPlanScript testPlanScript = this
|
||||
.getTestPlanRepository()
|
||||
.getTestPlan(testPlanId)
|
||||
.extracSpecifiedScript(
|
||||
this.getScriptService().getScript(scriptId));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<TestPlanScriptResult> results = (List<TestPlanScriptResult>) session
|
||||
.createCriteria(TestPlanScriptResult.class)
|
||||
.add(Restrictions.eq(
|
||||
"testPlanScript",
|
||||
this.getTestPlanScriptService().getTestPlanScript(
|
||||
scriptId, testPlanId)))
|
||||
.add(Restrictions.eq("testPlanScript", testPlanScript))
|
||||
.add(Restrictions.eq("resultType", resultType.getName()))
|
||||
.addOrder(Order.desc("createDatetime")).setFetchSize(1).list();
|
||||
if (results.size() > 0) {
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
@ -63,27 +65,10 @@ public class TestPlanScriptService implements Observer {
|
|||
}
|
||||
|
||||
public TestPlanScript getTestPlanScript(int scriptId, UUID testPlanRunId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
return doGetTestPlanScript(scriptId, testPlanRunId, session);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TestPlanScript doGetTestPlanScript(int scriptId, UUID testPlanRunId,
|
||||
Session session) {
|
||||
return (TestPlanScript) session
|
||||
.createCriteria(TestPlanScript.class)
|
||||
.add(Restrictions.eq("script", this.getScriptService()
|
||||
.getScript(scriptId)))
|
||||
.add(Restrictions.eq("testPlanDB", this.getTestPlanRepository()
|
||||
.getTestPlan(testPlanRunId))).uniqueResult();
|
||||
TestPlanDB testPlan = this.getTestPlanRepository().getTestPlan(
|
||||
testPlanRunId);
|
||||
return testPlan == null ? null : testPlan.extracSpecifiedScript(this
|
||||
.getScriptService().getScript(scriptId));
|
||||
}
|
||||
|
||||
public boolean saveScriptBriefResult(final UUID testPlanRunId,
|
||||
|
@ -131,10 +116,9 @@ public class TestPlanScriptService implements Observer {
|
|||
if (script == null) {
|
||||
return;
|
||||
}
|
||||
TestPlanScript testPlanScript = (TestPlanScript) session
|
||||
.createCriteria(TestPlanScript.class)
|
||||
.add(Restrictions.eq("testPlanDB", testPlanDB))
|
||||
.add(Restrictions.eq("script", script)).uniqueResult();
|
||||
|
||||
TestPlanScript testPlanScript = testPlanDB
|
||||
.extracSpecifiedScript(script);
|
||||
if (testPlanScript == null) {
|
||||
return;
|
||||
}
|
||||
|
@ -169,23 +153,9 @@ public class TestPlanScriptService implements Observer {
|
|||
return result;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<TestPlanScript> queryTestPlanScripts(UUID testPlanRunId) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
try {
|
||||
return session
|
||||
.createCriteria(TestPlanScript.class)
|
||||
.add(Restrictions
|
||||
.eq("testPlanDB", this.getTestPlanRepository()
|
||||
.getTestPlan(testPlanRunId))).list();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null) {
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
public Collection<TestPlanScript> queryTestPlanScripts(UUID testPlanRunId) {
|
||||
return this.getTestPlanRepository().getTestPlan(testPlanRunId)
|
||||
.getTestPlanScripts();
|
||||
}
|
||||
|
||||
public List<TestPlanScriptResult> queryScriptBriefResults(UUID testPlanId,
|
||||
|
|
|
@ -1,27 +1,19 @@
|
|||
package org.bench4q.master.service.infrastructure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
import org.bench4q.master.domain.RunningScript;
|
||||
import org.bench4q.master.domain.TestPlanInBusiness;
|
||||
import org.bench4q.master.entity.PlanedConfig;
|
||||
import org.bench4q.master.entity.Script;
|
||||
import org.bench4q.master.entity.TestPlanDB;
|
||||
import org.bench4q.master.entity.TestPlanScript;
|
||||
import org.bench4q.master.entity.User;
|
||||
import org.bench4q.master.exception.ExceptionLog;
|
||||
import org.bench4q.master.factory.TestPlanFactory;
|
||||
import org.bench4q.master.helper.SessionHelper;
|
||||
import org.bench4q.master.repository.TestPlanRepository;
|
||||
import org.bench4q.share.enums.master.TestPlanStatus;
|
||||
import org.bench4q.share.helper.MarshalHelper;
|
||||
import org.bench4q.share.models.master.TestPlanBusinessModel;
|
||||
import org.bench4q.share.models.master.TestPlanDBModel;
|
||||
import org.bench4q.share.models.master.TestScriptConfig;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -30,9 +22,9 @@ import org.springframework.stereotype.Component;
|
|||
@Component
|
||||
public class TestPlanService {
|
||||
private SessionHelper sessionHelper;
|
||||
private ScriptService scriptService;
|
||||
private BusinessModelMapFactory businessMapFactory;
|
||||
private TestPlanRepository testPlanRepository;
|
||||
private TestPlanFactory testPlanFactory;
|
||||
private static Logger logger = Logger.getLogger(TestPlanService.class);
|
||||
public static final long TIME_UNIT = 1000;
|
||||
|
||||
|
@ -41,11 +33,6 @@ public class TestPlanService {
|
|||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setScriptService(ScriptService scriptService) {
|
||||
this.scriptService = scriptService;
|
||||
}
|
||||
|
||||
private TestPlanRepository getTestPlanRepository() {
|
||||
return testPlanRepository;
|
||||
}
|
||||
|
@ -65,24 +52,24 @@ public class TestPlanService {
|
|||
this.businessMapFactory = businessMapFactory;
|
||||
}
|
||||
|
||||
private TestPlanFactory getTestPlanFactory() {
|
||||
return testPlanFactory;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setTestPlanFactory(TestPlanFactory testPlanFactory) {
|
||||
this.testPlanFactory = testPlanFactory;
|
||||
}
|
||||
|
||||
public boolean saveTestPlanToDB(final TestPlanInBusiness testPlanInParam,
|
||||
final User user, final UUID testPlanRunId) {
|
||||
Session session = this.sessionHelper.openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
TestPlanDB testPlanInSession;
|
||||
try {
|
||||
testPlanInSession = saveToTestPlan(session,
|
||||
testPlanInParam.getName(), MarshalHelper.marshal(
|
||||
TestPlanBusinessModel.class,
|
||||
session.merge(this.getTestPlanFactory()
|
||||
.createATestPlanWithoutIdentity(
|
||||
this.getBusinessMapFactory().toModel(
|
||||
testPlanInParam)), user, testPlanRunId);
|
||||
if (testPlanInSession == null) {
|
||||
return false;
|
||||
}
|
||||
if (!saveToTestPlanScriptAndScriptConfig(session,
|
||||
testPlanInSession, testPlanInParam.getRunningScripts())) {
|
||||
return false;
|
||||
}
|
||||
testPlanInParam), user, testPlanRunId));
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
|
@ -96,59 +83,6 @@ public class TestPlanService {
|
|||
}
|
||||
}
|
||||
|
||||
private TestPlanDB saveToTestPlan(Session session, String testPlanName,
|
||||
String modelContent, User user, UUID testPlanRunId) {
|
||||
TestPlanDB ret = new TestPlanDB();
|
||||
ret.setCreateDateTime(new Date());
|
||||
ret.setName(testPlanName);
|
||||
ret.setUser(user);
|
||||
ret.setTestPlanRunId(testPlanRunId.toString());
|
||||
ret.setCurrentStatus(TestPlanStatus.NotStart.name());
|
||||
ret.setFailTimes(0);
|
||||
ret.setTestPlanModelContent(modelContent);
|
||||
return (TestPlanDB) session.merge(ret);
|
||||
|
||||
}
|
||||
|
||||
private boolean saveToTestPlanScriptAndScriptConfig(Session session,
|
||||
TestPlanDB testPlanDB, Collection<RunningScript> runningScripts) {
|
||||
TestPlanScript testPlanScript = new TestPlanScript();
|
||||
for (RunningScript runningScript : runningScripts) {
|
||||
testPlanScript = new TestPlanScript();
|
||||
testPlanScript.setTestPlanDB(testPlanDB);
|
||||
Script script = this.scriptService.getScript(runningScript
|
||||
.getScriptId());
|
||||
if (script == null) {
|
||||
logger.error("There is no this script with id "
|
||||
+ runningScript.getScriptId());
|
||||
return false;
|
||||
}
|
||||
testPlanScript.setScript(this.scriptService.getScript(runningScript
|
||||
.getScriptId()));
|
||||
testPlanScript.setRequireLoad(runningScript.getRequireLoad());
|
||||
TestPlanScript testPlanScriptInDB = (TestPlanScript) session
|
||||
.merge(testPlanScript);
|
||||
saveToScriptConfig(session, runningScript, testPlanScriptInDB);
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
private boolean saveToScriptConfig(Session session,
|
||||
RunningScript runningScript, TestPlanScript testPlanScript) {
|
||||
PlanedConfig planConfig = new PlanedConfig();
|
||||
planConfig.setTestPlanScript(testPlanScript);
|
||||
TestScriptConfig config = runningScript.getConfig();
|
||||
if (config == null) {
|
||||
return false;
|
||||
}
|
||||
planConfig.setWarmUp(config.getWarmUp());
|
||||
planConfig.setExecuteRange(config.getExecuteRange());
|
||||
planConfig.setCoolDown(config.getCoolDown());
|
||||
session.merge(planConfig);
|
||||
return true;
|
||||
}
|
||||
|
||||
public List<TestPlanDB> loadTestPlans(User user) {
|
||||
return this.getTestPlanRepository().loadEntities(user);
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import static org.junit.Assert.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bench4q.master.api.modelfactory.BusinessModelMapFactory;
|
||||
|
@ -101,6 +102,7 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan {
|
|||
User user = this.getUserRepository().getUser("admin");
|
||||
int planCountBeforeSubmit = this.getTestPlanRepository()
|
||||
.loadEntities(user).size();
|
||||
System.out.println(planCountBeforeSubmit);
|
||||
UUID randomUUID = UUID.randomUUID();
|
||||
TestPlanInBusiness testPlanInBusiness = new TestPlanInBusiness();
|
||||
testPlanInBusiness.setName("test1");
|
||||
|
@ -123,10 +125,14 @@ public class Test_TestPlanService extends TestBase_MakeUpTestPlan {
|
|||
int planCountAfterSubmit = this.getTestPlanRepository()
|
||||
.loadEntities(user).size();
|
||||
assertEquals(planCountBeforeSubmit + 1, planCountAfterSubmit);
|
||||
TestPlanScript testPlanScript = this.getTestPlanScriptService()
|
||||
.getTestPlanScript(userScript, randomUUID);
|
||||
assertNotNull(testPlanScript);
|
||||
Set<TestPlanScript> testPlanScripts = this.getTestPlanRepository()
|
||||
.getTestPlan(randomUUID).getTestPlanScripts();
|
||||
assertNotNull(testPlanScripts);
|
||||
assertEquals(1, testPlanScripts.size());
|
||||
for (TestPlanScript testPlanScript : testPlanScripts) {
|
||||
assertEquals(userScript, testPlanScript.getScript().getId());
|
||||
assertEquals(0, testPlanScript.getPlanedConfig().getWarmUp());
|
||||
}
|
||||
this.getTestPlanRepository().detach(
|
||||
this.getTestPlanRepository().getTestPlan(randomUUID).getId());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue