Merge remote-tracking branch 'origin/master'

This commit is contained in:
wenyann 2020-10-21 00:10:19 +08:00
commit e35a400bb0
52 changed files with 2653 additions and 170 deletions

View File

@ -150,6 +150,10 @@
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache-extras.beanshell</groupId>
<artifactId>bsh</artifactId>
</exclusion>
</exclusions>
</dependency>
@ -516,6 +520,15 @@
<outputDirectory>src/main/resources/jmeter/lib/ext</outputDirectory>
<destFileName>jython-standalone.jar</destFileName>
</artifactItem>
<artifactItem>
<groupId>org.apache-extras.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b6</version>
<type>jar</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/resources/jmeter/lib/ext</outputDirectory>
<destFileName>bsh-2.0b6.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
@ -594,4 +607,4 @@
</plugins>
</build>
</project>
</project>

View File

@ -10,4 +10,5 @@ public class ExtractCommon extends ExtractType {
private String value; // value: ${variable}
private String expression;
private String description;
private Boolean multipleMatching;
}

View File

@ -13,10 +13,13 @@ import io.metersphere.notice.service.MailService;
import io.metersphere.notice.service.NoticeService;
import io.metersphere.track.service.TestPlanTestCaseService;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.protocol.HTTP;
import org.apache.jmeter.assertions.AssertionResult;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.visualizers.backend.AbstractBackendListenerClient;
import org.apache.jmeter.visualizers.backend.BackendListenerContext;
import org.pac4j.core.context.HttpConstants;
import org.springframework.http.HttpMethod;
import java.io.Serializable;
import java.util.*;
@ -204,7 +207,13 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
return StringUtils.substringBetween(body, start, end).toUpperCase();
} else {
// Http Method
return StringUtils.substringBefore(body, " ");
String method = StringUtils.substringBefore(body, " ");
for (HttpMethod value : HttpMethod.values()) {
if (StringUtils.equals(method, value.name())) {
return method;
}
}
return "Request";
}
}

View File

@ -6,6 +6,7 @@ import io.metersphere.commons.utils.LogUtil;
import io.metersphere.config.JmeterProperties;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.NewDriver;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.util.JMeterUtils;
@ -29,6 +30,8 @@ public class JMeterService {
public void run(String testId, String debugReportId, InputStream is) {
String JMETER_HOME = getJmeterHome();
NewDriver.setContextClassLoader();
String JMETER_PROPERTIES = JMETER_HOME + "/bin/jmeter.properties";
JMeterUtils.loadJMeterProperties(JMETER_PROPERTIES);
JMeterUtils.setJMeterHome(JMETER_HOME);

View File

@ -0,0 +1,31 @@
package io.metersphere.api.jmeter;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import org.apache.jmeter.NewDriver;
import java.io.File;
import java.net.MalformedURLException;
public class NewDriverManager {
public static void loadJar(File file) {
if (file != null) {
try {
NewDriver.addURL(file.toURI().toURL());
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException(e.getMessage());
}
}
}
public static void loadJar(String path) {
try {
NewDriver.addPath(path);
} catch (MalformedURLException e) {
LogUtil.error(e.getMessage(), e);
MSException.throwException(e.getMessage());
}
}
}

View File

@ -0,0 +1,29 @@
package io.metersphere.base.domain;
import java.io.Serializable;
import lombok.Data;
@Data
public class JarConfig implements Serializable {
private String id;
private String name;
private String fileName;
private String creator;
private String modifier;
private String path;
private Boolean enable;
private String description;
private Long createTime;
private Long updateTime;
private static final long serialVersionUID = 1L;
}

View File

@ -0,0 +1,870 @@
package io.metersphere.base.domain;
import java.util.ArrayList;
import java.util.List;
public class JarConfigExample {
protected String orderByClause;
protected boolean distinct;
protected List<Criteria> oredCriteria;
public JarConfigExample() {
oredCriteria = new ArrayList<Criteria>();
}
public void setOrderByClause(String orderByClause) {
this.orderByClause = orderByClause;
}
public String getOrderByClause() {
return orderByClause;
}
public void setDistinct(boolean distinct) {
this.distinct = distinct;
}
public boolean isDistinct() {
return distinct;
}
public List<Criteria> getOredCriteria() {
return oredCriteria;
}
public void or(Criteria criteria) {
oredCriteria.add(criteria);
}
public Criteria or() {
Criteria criteria = createCriteriaInternal();
oredCriteria.add(criteria);
return criteria;
}
public Criteria createCriteria() {
Criteria criteria = createCriteriaInternal();
if (oredCriteria.size() == 0) {
oredCriteria.add(criteria);
}
return criteria;
}
protected Criteria createCriteriaInternal() {
Criteria criteria = new Criteria();
return criteria;
}
public void clear() {
oredCriteria.clear();
orderByClause = null;
distinct = false;
}
protected abstract static class GeneratedCriteria {
protected List<Criterion> criteria;
protected GeneratedCriteria() {
super();
criteria = new ArrayList<Criterion>();
}
public boolean isValid() {
return criteria.size() > 0;
}
public List<Criterion> getAllCriteria() {
return criteria;
}
public List<Criterion> getCriteria() {
return criteria;
}
protected void addCriterion(String condition) {
if (condition == null) {
throw new RuntimeException("Value for condition cannot be null");
}
criteria.add(new Criterion(condition));
}
protected void addCriterion(String condition, Object value, String property) {
if (value == null) {
throw new RuntimeException("Value for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value));
}
protected void addCriterion(String condition, Object value1, Object value2, String property) {
if (value1 == null || value2 == null) {
throw new RuntimeException("Between values for " + property + " cannot be null");
}
criteria.add(new Criterion(condition, value1, value2));
}
public Criteria andIdIsNull() {
addCriterion("id is null");
return (Criteria) this;
}
public Criteria andIdIsNotNull() {
addCriterion("id is not null");
return (Criteria) this;
}
public Criteria andIdEqualTo(String value) {
addCriterion("id =", value, "id");
return (Criteria) this;
}
public Criteria andIdNotEqualTo(String value) {
addCriterion("id <>", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThan(String value) {
addCriterion("id >", value, "id");
return (Criteria) this;
}
public Criteria andIdGreaterThanOrEqualTo(String value) {
addCriterion("id >=", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThan(String value) {
addCriterion("id <", value, "id");
return (Criteria) this;
}
public Criteria andIdLessThanOrEqualTo(String value) {
addCriterion("id <=", value, "id");
return (Criteria) this;
}
public Criteria andIdLike(String value) {
addCriterion("id like", value, "id");
return (Criteria) this;
}
public Criteria andIdNotLike(String value) {
addCriterion("id not like", value, "id");
return (Criteria) this;
}
public Criteria andIdIn(List<String> values) {
addCriterion("id in", values, "id");
return (Criteria) this;
}
public Criteria andIdNotIn(List<String> values) {
addCriterion("id not in", values, "id");
return (Criteria) this;
}
public Criteria andIdBetween(String value1, String value2) {
addCriterion("id between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andIdNotBetween(String value1, String value2) {
addCriterion("id not between", value1, value2, "id");
return (Criteria) this;
}
public Criteria andNameIsNull() {
addCriterion("`name` is null");
return (Criteria) this;
}
public Criteria andNameIsNotNull() {
addCriterion("`name` is not null");
return (Criteria) this;
}
public Criteria andNameEqualTo(String value) {
addCriterion("`name` =", value, "name");
return (Criteria) this;
}
public Criteria andNameNotEqualTo(String value) {
addCriterion("`name` <>", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThan(String value) {
addCriterion("`name` >", value, "name");
return (Criteria) this;
}
public Criteria andNameGreaterThanOrEqualTo(String value) {
addCriterion("`name` >=", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThan(String value) {
addCriterion("`name` <", value, "name");
return (Criteria) this;
}
public Criteria andNameLessThanOrEqualTo(String value) {
addCriterion("`name` <=", value, "name");
return (Criteria) this;
}
public Criteria andNameLike(String value) {
addCriterion("`name` like", value, "name");
return (Criteria) this;
}
public Criteria andNameNotLike(String value) {
addCriterion("`name` not like", value, "name");
return (Criteria) this;
}
public Criteria andNameIn(List<String> values) {
addCriterion("`name` in", values, "name");
return (Criteria) this;
}
public Criteria andNameNotIn(List<String> values) {
addCriterion("`name` not in", values, "name");
return (Criteria) this;
}
public Criteria andNameBetween(String value1, String value2) {
addCriterion("`name` between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andNameNotBetween(String value1, String value2) {
addCriterion("`name` not between", value1, value2, "name");
return (Criteria) this;
}
public Criteria andFileNameIsNull() {
addCriterion("file_name is null");
return (Criteria) this;
}
public Criteria andFileNameIsNotNull() {
addCriterion("file_name is not null");
return (Criteria) this;
}
public Criteria andFileNameEqualTo(String value) {
addCriterion("file_name =", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameNotEqualTo(String value) {
addCriterion("file_name <>", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameGreaterThan(String value) {
addCriterion("file_name >", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameGreaterThanOrEqualTo(String value) {
addCriterion("file_name >=", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameLessThan(String value) {
addCriterion("file_name <", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameLessThanOrEqualTo(String value) {
addCriterion("file_name <=", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameLike(String value) {
addCriterion("file_name like", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameNotLike(String value) {
addCriterion("file_name not like", value, "fileName");
return (Criteria) this;
}
public Criteria andFileNameIn(List<String> values) {
addCriterion("file_name in", values, "fileName");
return (Criteria) this;
}
public Criteria andFileNameNotIn(List<String> values) {
addCriterion("file_name not in", values, "fileName");
return (Criteria) this;
}
public Criteria andFileNameBetween(String value1, String value2) {
addCriterion("file_name between", value1, value2, "fileName");
return (Criteria) this;
}
public Criteria andFileNameNotBetween(String value1, String value2) {
addCriterion("file_name not between", value1, value2, "fileName");
return (Criteria) this;
}
public Criteria andCreatorIsNull() {
addCriterion("creator is null");
return (Criteria) this;
}
public Criteria andCreatorIsNotNull() {
addCriterion("creator is not null");
return (Criteria) this;
}
public Criteria andCreatorEqualTo(String value) {
addCriterion("creator =", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorNotEqualTo(String value) {
addCriterion("creator <>", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorGreaterThan(String value) {
addCriterion("creator >", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorGreaterThanOrEqualTo(String value) {
addCriterion("creator >=", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorLessThan(String value) {
addCriterion("creator <", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorLessThanOrEqualTo(String value) {
addCriterion("creator <=", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorLike(String value) {
addCriterion("creator like", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorNotLike(String value) {
addCriterion("creator not like", value, "creator");
return (Criteria) this;
}
public Criteria andCreatorIn(List<String> values) {
addCriterion("creator in", values, "creator");
return (Criteria) this;
}
public Criteria andCreatorNotIn(List<String> values) {
addCriterion("creator not in", values, "creator");
return (Criteria) this;
}
public Criteria andCreatorBetween(String value1, String value2) {
addCriterion("creator between", value1, value2, "creator");
return (Criteria) this;
}
public Criteria andCreatorNotBetween(String value1, String value2) {
addCriterion("creator not between", value1, value2, "creator");
return (Criteria) this;
}
public Criteria andModifierIsNull() {
addCriterion("modifier is null");
return (Criteria) this;
}
public Criteria andModifierIsNotNull() {
addCriterion("modifier is not null");
return (Criteria) this;
}
public Criteria andModifierEqualTo(String value) {
addCriterion("modifier =", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierNotEqualTo(String value) {
addCriterion("modifier <>", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierGreaterThan(String value) {
addCriterion("modifier >", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierGreaterThanOrEqualTo(String value) {
addCriterion("modifier >=", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierLessThan(String value) {
addCriterion("modifier <", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierLessThanOrEqualTo(String value) {
addCriterion("modifier <=", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierLike(String value) {
addCriterion("modifier like", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierNotLike(String value) {
addCriterion("modifier not like", value, "modifier");
return (Criteria) this;
}
public Criteria andModifierIn(List<String> values) {
addCriterion("modifier in", values, "modifier");
return (Criteria) this;
}
public Criteria andModifierNotIn(List<String> values) {
addCriterion("modifier not in", values, "modifier");
return (Criteria) this;
}
public Criteria andModifierBetween(String value1, String value2) {
addCriterion("modifier between", value1, value2, "modifier");
return (Criteria) this;
}
public Criteria andModifierNotBetween(String value1, String value2) {
addCriterion("modifier not between", value1, value2, "modifier");
return (Criteria) this;
}
public Criteria andPathIsNull() {
addCriterion("`path` is null");
return (Criteria) this;
}
public Criteria andPathIsNotNull() {
addCriterion("`path` is not null");
return (Criteria) this;
}
public Criteria andPathEqualTo(String value) {
addCriterion("`path` =", value, "path");
return (Criteria) this;
}
public Criteria andPathNotEqualTo(String value) {
addCriterion("`path` <>", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThan(String value) {
addCriterion("`path` >", value, "path");
return (Criteria) this;
}
public Criteria andPathGreaterThanOrEqualTo(String value) {
addCriterion("`path` >=", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThan(String value) {
addCriterion("`path` <", value, "path");
return (Criteria) this;
}
public Criteria andPathLessThanOrEqualTo(String value) {
addCriterion("`path` <=", value, "path");
return (Criteria) this;
}
public Criteria andPathLike(String value) {
addCriterion("`path` like", value, "path");
return (Criteria) this;
}
public Criteria andPathNotLike(String value) {
addCriterion("`path` not like", value, "path");
return (Criteria) this;
}
public Criteria andPathIn(List<String> values) {
addCriterion("`path` in", values, "path");
return (Criteria) this;
}
public Criteria andPathNotIn(List<String> values) {
addCriterion("`path` not in", values, "path");
return (Criteria) this;
}
public Criteria andPathBetween(String value1, String value2) {
addCriterion("`path` between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andPathNotBetween(String value1, String value2) {
addCriterion("`path` not between", value1, value2, "path");
return (Criteria) this;
}
public Criteria andEnableIsNull() {
addCriterion("`enable` is null");
return (Criteria) this;
}
public Criteria andEnableIsNotNull() {
addCriterion("`enable` is not null");
return (Criteria) this;
}
public Criteria andEnableEqualTo(Boolean value) {
addCriterion("`enable` =", value, "enable");
return (Criteria) this;
}
public Criteria andEnableNotEqualTo(Boolean value) {
addCriterion("`enable` <>", value, "enable");
return (Criteria) this;
}
public Criteria andEnableGreaterThan(Boolean value) {
addCriterion("`enable` >", value, "enable");
return (Criteria) this;
}
public Criteria andEnableGreaterThanOrEqualTo(Boolean value) {
addCriterion("`enable` >=", value, "enable");
return (Criteria) this;
}
public Criteria andEnableLessThan(Boolean value) {
addCriterion("`enable` <", value, "enable");
return (Criteria) this;
}
public Criteria andEnableLessThanOrEqualTo(Boolean value) {
addCriterion("`enable` <=", value, "enable");
return (Criteria) this;
}
public Criteria andEnableIn(List<Boolean> values) {
addCriterion("`enable` in", values, "enable");
return (Criteria) this;
}
public Criteria andEnableNotIn(List<Boolean> values) {
addCriterion("`enable` not in", values, "enable");
return (Criteria) this;
}
public Criteria andEnableBetween(Boolean value1, Boolean value2) {
addCriterion("`enable` between", value1, value2, "enable");
return (Criteria) this;
}
public Criteria andEnableNotBetween(Boolean value1, Boolean value2) {
addCriterion("`enable` not between", value1, value2, "enable");
return (Criteria) this;
}
public Criteria andDescriptionIsNull() {
addCriterion("description is null");
return (Criteria) this;
}
public Criteria andDescriptionIsNotNull() {
addCriterion("description is not null");
return (Criteria) this;
}
public Criteria andDescriptionEqualTo(String value) {
addCriterion("description =", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotEqualTo(String value) {
addCriterion("description <>", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThan(String value) {
addCriterion("description >", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionGreaterThanOrEqualTo(String value) {
addCriterion("description >=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThan(String value) {
addCriterion("description <", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLessThanOrEqualTo(String value) {
addCriterion("description <=", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionLike(String value) {
addCriterion("description like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotLike(String value) {
addCriterion("description not like", value, "description");
return (Criteria) this;
}
public Criteria andDescriptionIn(List<String> values) {
addCriterion("description in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotIn(List<String> values) {
addCriterion("description not in", values, "description");
return (Criteria) this;
}
public Criteria andDescriptionBetween(String value1, String value2) {
addCriterion("description between", value1, value2, "description");
return (Criteria) this;
}
public Criteria andDescriptionNotBetween(String value1, String value2) {
addCriterion("description not between", value1, value2, "description");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;
}
public Criteria andCreateTimeIsNotNull() {
addCriterion("create_time is not null");
return (Criteria) this;
}
public Criteria andCreateTimeEqualTo(Long value) {
addCriterion("create_time =", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotEqualTo(Long value) {
addCriterion("create_time <>", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThan(Long value) {
addCriterion("create_time >", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("create_time >=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThan(Long value) {
addCriterion("create_time <", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeLessThanOrEqualTo(Long value) {
addCriterion("create_time <=", value, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeIn(List<Long> values) {
addCriterion("create_time in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotIn(List<Long> values) {
addCriterion("create_time not in", values, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeBetween(Long value1, Long value2) {
addCriterion("create_time between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andCreateTimeNotBetween(Long value1, Long value2) {
addCriterion("create_time not between", value1, value2, "createTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNull() {
addCriterion("update_time is null");
return (Criteria) this;
}
public Criteria andUpdateTimeIsNotNull() {
addCriterion("update_time is not null");
return (Criteria) this;
}
public Criteria andUpdateTimeEqualTo(Long value) {
addCriterion("update_time =", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotEqualTo(Long value) {
addCriterion("update_time <>", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThan(Long value) {
addCriterion("update_time >", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeGreaterThanOrEqualTo(Long value) {
addCriterion("update_time >=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThan(Long value) {
addCriterion("update_time <", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeLessThanOrEqualTo(Long value) {
addCriterion("update_time <=", value, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeIn(List<Long> values) {
addCriterion("update_time in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotIn(List<Long> values) {
addCriterion("update_time not in", values, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeBetween(Long value1, Long value2) {
addCriterion("update_time between", value1, value2, "updateTime");
return (Criteria) this;
}
public Criteria andUpdateTimeNotBetween(Long value1, Long value2) {
addCriterion("update_time not between", value1, value2, "updateTime");
return (Criteria) this;
}
}
public static class Criteria extends GeneratedCriteria {
protected Criteria() {
super();
}
}
public static class Criterion {
private String condition;
private Object value;
private Object secondValue;
private boolean noValue;
private boolean singleValue;
private boolean betweenValue;
private boolean listValue;
private String typeHandler;
public String getCondition() {
return condition;
}
public Object getValue() {
return value;
}
public Object getSecondValue() {
return secondValue;
}
public boolean isNoValue() {
return noValue;
}
public boolean isSingleValue() {
return singleValue;
}
public boolean isBetweenValue() {
return betweenValue;
}
public boolean isListValue() {
return listValue;
}
public String getTypeHandler() {
return typeHandler;
}
protected Criterion(String condition) {
super();
this.condition = condition;
this.typeHandler = null;
this.noValue = true;
}
protected Criterion(String condition, Object value, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.typeHandler = typeHandler;
if (value instanceof List<?>) {
this.listValue = true;
} else {
this.singleValue = true;
}
}
protected Criterion(String condition, Object value) {
this(condition, value, null);
}
protected Criterion(String condition, Object value, Object secondValue, String typeHandler) {
super();
this.condition = condition;
this.value = value;
this.secondValue = secondValue;
this.typeHandler = typeHandler;
this.betweenValue = true;
}
protected Criterion(String condition, Object value, Object secondValue) {
this(condition, value, secondValue, null);
}
}
}

View File

@ -0,0 +1,30 @@
package io.metersphere.base.mapper;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.base.domain.JarConfigExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface JarConfigMapper {
long countByExample(JarConfigExample example);
int deleteByExample(JarConfigExample example);
int deleteByPrimaryKey(String id);
int insert(JarConfig record);
int insertSelective(JarConfig record);
List<JarConfig> selectByExample(JarConfigExample example);
JarConfig selectByPrimaryKey(String id);
int updateByExampleSelective(@Param("record") JarConfig record, @Param("example") JarConfigExample example);
int updateByExample(@Param("record") JarConfig record, @Param("example") JarConfigExample example);
int updateByPrimaryKeySelective(JarConfig record);
int updateByPrimaryKey(JarConfig record);
}

View File

@ -0,0 +1,291 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.base.mapper.JarConfigMapper">
<resultMap id="BaseResultMap" type="io.metersphere.base.domain.JarConfig">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="file_name" jdbcType="VARCHAR" property="fileName" />
<result column="creator" jdbcType="VARCHAR" property="creator" />
<result column="modifier" jdbcType="VARCHAR" property="modifier" />
<result column="path" jdbcType="VARCHAR" property="path" />
<result column="enable" jdbcType="BIT" property="enable" />
<result column="description" jdbcType="VARCHAR" property="description" />
<result column="create_time" jdbcType="BIGINT" property="createTime" />
<result column="update_time" jdbcType="BIGINT" property="updateTime" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, `name`, file_name, creator, modifier, `path`, `enable`, description, create_time,
update_time
</sql>
<select id="selectByExample" parameterType="io.metersphere.base.domain.JarConfigExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from jar_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from jar_config
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from jar_config
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="io.metersphere.base.domain.JarConfigExample">
delete from jar_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="io.metersphere.base.domain.JarConfig">
insert into jar_config (id, `name`, file_name,
creator, modifier, `path`,
`enable`, description, create_time,
update_time)
values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{fileName,jdbcType=VARCHAR},
#{creator,jdbcType=VARCHAR}, #{modifier,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR},
#{enable,jdbcType=BIT}, #{description,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT},
#{updateTime,jdbcType=BIGINT})
</insert>
<insert id="insertSelective" parameterType="io.metersphere.base.domain.JarConfig">
insert into jar_config
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="name != null">
`name`,
</if>
<if test="fileName != null">
file_name,
</if>
<if test="creator != null">
creator,
</if>
<if test="modifier != null">
modifier,
</if>
<if test="path != null">
`path`,
</if>
<if test="enable != null">
`enable`,
</if>
<if test="description != null">
description,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="fileName != null">
#{fileName,jdbcType=VARCHAR},
</if>
<if test="creator != null">
#{creator,jdbcType=VARCHAR},
</if>
<if test="modifier != null">
#{modifier,jdbcType=VARCHAR},
</if>
<if test="path != null">
#{path,jdbcType=VARCHAR},
</if>
<if test="enable != null">
#{enable,jdbcType=BIT},
</if>
<if test="description != null">
#{description,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=BIGINT},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="io.metersphere.base.domain.JarConfigExample" resultType="java.lang.Long">
select count(*) from jar_config
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update jar_config
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.name != null">
`name` = #{record.name,jdbcType=VARCHAR},
</if>
<if test="record.fileName != null">
file_name = #{record.fileName,jdbcType=VARCHAR},
</if>
<if test="record.creator != null">
creator = #{record.creator,jdbcType=VARCHAR},
</if>
<if test="record.modifier != null">
modifier = #{record.modifier,jdbcType=VARCHAR},
</if>
<if test="record.path != null">
`path` = #{record.path,jdbcType=VARCHAR},
</if>
<if test="record.enable != null">
`enable` = #{record.enable,jdbcType=BIT},
</if>
<if test="record.description != null">
description = #{record.description,jdbcType=VARCHAR},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=BIGINT},
</if>
<if test="record.updateTime != null">
update_time = #{record.updateTime,jdbcType=BIGINT},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update jar_config
set id = #{record.id,jdbcType=VARCHAR},
`name` = #{record.name,jdbcType=VARCHAR},
file_name = #{record.fileName,jdbcType=VARCHAR},
creator = #{record.creator,jdbcType=VARCHAR},
modifier = #{record.modifier,jdbcType=VARCHAR},
`path` = #{record.path,jdbcType=VARCHAR},
`enable` = #{record.enable,jdbcType=BIT},
description = #{record.description,jdbcType=VARCHAR},
create_time = #{record.createTime,jdbcType=BIGINT},
update_time = #{record.updateTime,jdbcType=BIGINT}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="io.metersphere.base.domain.JarConfig">
update jar_config
<set>
<if test="name != null">
`name` = #{name,jdbcType=VARCHAR},
</if>
<if test="fileName != null">
file_name = #{fileName,jdbcType=VARCHAR},
</if>
<if test="creator != null">
creator = #{creator,jdbcType=VARCHAR},
</if>
<if test="modifier != null">
modifier = #{modifier,jdbcType=VARCHAR},
</if>
<if test="path != null">
`path` = #{path,jdbcType=VARCHAR},
</if>
<if test="enable != null">
`enable` = #{enable,jdbcType=BIT},
</if>
<if test="description != null">
description = #{description,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=BIGINT},
</if>
<if test="updateTime != null">
update_time = #{updateTime,jdbcType=BIGINT},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="io.metersphere.base.domain.JarConfig">
update jar_config
set `name` = #{name,jdbcType=VARCHAR},
file_name = #{fileName,jdbcType=VARCHAR},
creator = #{creator,jdbcType=VARCHAR},
modifier = #{modifier,jdbcType=VARCHAR},
`path` = #{path,jdbcType=VARCHAR},
`enable` = #{enable,jdbcType=BIT},
description = #{description,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=BIGINT},
update_time = #{updateTime,jdbcType=BIGINT}
where id = #{id,jdbcType=VARCHAR}
</update>
</mapper>

View File

@ -98,8 +98,8 @@
</sql>
<select id="getTestCaseByNotInReview" resultType="io.metersphere.base.domain.TestCase">
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status
from test_case
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case as test_case
left join test_case_review_test_case as T2 on test_case.id=T2.case_id
<where>
<if test="request.combine != null">
<include refid="combine">
@ -107,7 +107,7 @@
<property name="name" value="request.name"/>
</include>
</if>
and test_case.id not in (select case_id from test_case_review_test_case where review_id =#{request.reviewId})
and T2.case_id is null
<if test="request.name != null">
and test_case.name like CONCAT('%', #{request.name},'%')
</if>
@ -152,8 +152,8 @@
</select>
<select id="getTestCaseByNotInPlan" resultType="io.metersphere.base.domain.TestCase">
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status
from test_case
select test_case.id, test_case.name, test_case.priority, test_case.type, test_case.review_status from test_case as test_case
left join test_plan_test_case as T2 on test_case.id=T2.case_id
<where>
<if test="request.combine != null">
<include refid="combine">
@ -161,7 +161,7 @@
<property name="name" value="request.name"/>
</include>
</if>
and test_case.id not in (select case_id from test_plan_test_case where plan_id =#{request.planId})
and T2.case_id is null
<if test="request.name != null">
and test_case.name like CONCAT('%', #{request.name},'%')
</if>

View File

@ -11,5 +11,5 @@ public interface ExtTestReviewCaseMapper {
List<TestReviewCaseDTO> list(@Param("request") QueryCaseReviewRequest request);
List<String> getStatusByReviewId(String reviewId);
List<String> findRelateTestReviewId(String userId, String workspaceId);
List<String> findRelateTestReviewId(@Param("userId") String userId, @Param("workspaceId") String workspaceId);
}

View File

@ -0,0 +1,61 @@
package io.metersphere.controller;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.commons.constants.RoleConstants;
import io.metersphere.commons.utils.PageUtils;
import io.metersphere.commons.utils.Pager;
import io.metersphere.service.JarConfigService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
@RestController
@RequestMapping(value = "/jar")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR)
public class JarConfigController {
@Resource
JarConfigService JarConfigService;
@PostMapping("list/{goPage}/{pageSize}")
@RequiresRoles(RoleConstants.ORG_ADMIN)
public Pager<List<JarConfig>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody JarConfig request) {
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, JarConfigService.list(request));
}
@GetMapping("list/all")
public List<JarConfig> listAll() {
return JarConfigService.list();
}
@GetMapping("/get/{id}")
public JarConfig get(@PathVariable String id) {
return JarConfigService.get(id);
}
@PostMapping(value = "/add", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER,}, logical = Logical.OR)
public String add(@RequestPart("request") JarConfig request, @RequestPart(value = "file") MultipartFile file) {
return JarConfigService.add(request, file);
}
@PostMapping(value = "/update", consumes = {"multipart/form-data"})
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER,}, logical = Logical.OR)
public void update(@RequestPart("request") JarConfig request, @RequestPart(value = "file", required = false) MultipartFile file) {
JarConfigService.update(request, file);
}
@GetMapping("/delete/{id}")
@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER,}, logical = Logical.OR)
public void delete(@PathVariable String id) {
JarConfigService.delete(id);
}
}

View File

@ -1,15 +1,20 @@
package io.metersphere.listener;
import io.metersphere.api.jmeter.JMeterService;
import io.metersphere.api.jmeter.NewDriverManager;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.service.JarConfigService;
import io.metersphere.service.ScheduleService;
import org.python.core.Options;
import org.python.util.PythonInterpreter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
@Component
public class AppStartListener implements ApplicationListener<ApplicationReadyEvent> {
@ -18,12 +23,20 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
private ScheduleService scheduleService;
@Resource
private JMeterService jMeterService;
@Resource
private JarConfigService jarConfigService;
@Value("${jmeter.home}")
private String jmeterHome;
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
System.out.println("================= 应用启动 =================");
System.setProperty("jmeter.home", jmeterHome);
loadJars();
initPythonEnv();
try {
@ -53,4 +66,19 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
LogUtil.error(e.getMessage(), e);
}
}
/**
* 加载jar包
*/
private void loadJars() {
List<JarConfig> jars = jarConfigService.list();
try {
jars.forEach(jarConfig -> {
NewDriverManager.loadJar(jarConfig.getPath());
});
} catch (Exception e) {
e.printStackTrace();
LogUtil.error(e.getMessage(), e);
}
}
}

View File

@ -0,0 +1,141 @@
package io.metersphere.service;
import io.metersphere.api.jmeter.NewDriverManager;
import io.metersphere.base.domain.JarConfig;
import io.metersphere.base.domain.JarConfigExample;
import io.metersphere.base.mapper.JarConfigMapper;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.i18n.Translator;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.util.FileUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.util.List;
import java.util.UUID;
@Service
@Transactional(rollbackFor = Exception.class)
public class JarConfigService {
private static final String JAR_FILE_DIR = "/opt/metersphere/data/jar";
@Resource
private JarConfigMapper jarConfigMapper;
public List<JarConfig> list() {
JarConfigExample example = new JarConfigExample();
return jarConfigMapper.selectByExample(example);
}
public List<JarConfig> list(JarConfig jarConfig) {
JarConfigExample example = new JarConfigExample();
if (StringUtils.isNotBlank(jarConfig.getName())) {
example.createCriteria().andNameLike("%" + jarConfig.getName() + "%");
}
example.setOrderByClause("update_time desc");
return jarConfigMapper.selectByExample(example);
}
public JarConfig get(String id) {
return jarConfigMapper.selectByPrimaryKey(id);
}
public void delete(String id) {
JarConfig JarConfig = jarConfigMapper.selectByPrimaryKey(id);
deleteJarFile(JarConfig.getPath());
jarConfigMapper.deleteByPrimaryKey(id);
}
public void update(JarConfig jarConfig, MultipartFile file) {
checkExist(jarConfig);
jarConfig.setEnable(true);// todo 审批机制时需修改
jarConfig.setModifier(SessionUtils.getUser().getId());
jarConfig.setUpdateTime(System.currentTimeMillis());
String deletePath = jarConfig.getPath();
if (file != null) {
jarConfig.setFileName(file.getOriginalFilename());
jarConfig.setPath(getJarPath(file));
}
jarConfigMapper.updateByPrimaryKey(jarConfig);
if (file != null) {
deleteJarFile(deletePath);
createJarFiles(file);
NewDriverManager.loadJar(jarConfig.getPath());
}
}
public String add(JarConfig jarConfig, MultipartFile file) {
jarConfig.setId(UUID.randomUUID().toString());
jarConfig.setCreator(SessionUtils.getUser().getId());
jarConfig.setModifier(SessionUtils.getUser().getId());
checkExist(jarConfig);
jarConfig.setEnable(true);// todo 审批机制时需修改
jarConfig.setCreateTime(System.currentTimeMillis());
jarConfig.setUpdateTime(System.currentTimeMillis());
jarConfig.setPath(getJarPath(file));
jarConfig.setFileName(file.getOriginalFilename());
jarConfigMapper.insert(jarConfig);
createJarFiles(file);
NewDriverManager.loadJar(jarConfig.getPath());
return jarConfig.getId();
}
public void deleteJarFiles(String testId) {
File file = new File(JAR_FILE_DIR + "/" + testId);
FileUtil.deleteContents(file);
if (file.exists()) {
file.delete();
}
}
public void deleteJarFile(String path) {
File file = new File(path);
if (file.exists()) {
file.delete();
}
}
public String getJarPath(MultipartFile file) {
return JAR_FILE_DIR + "/" + file.getOriginalFilename();
}
private String createJarFiles(MultipartFile jar) {
if (jar == null) {
return null;
}
File testDir = new File(JAR_FILE_DIR);
if (!testDir.exists()) {
testDir.mkdirs();
}
String filePath = testDir + "/" + jar.getOriginalFilename();
File file = new File(filePath);
try (InputStream in = jar.getInputStream(); OutputStream out = new FileOutputStream(file)) {
file.createNewFile();
FileUtil.copyStream(in, out);
} catch (IOException e) {
LogUtil.error(e);
MSException.throwException(Translator.get("upload_fail"));
}
return filePath;
}
private void checkExist(JarConfig jarConfig) {
if (jarConfig.getName() != null) {
JarConfigExample example = new JarConfigExample();
JarConfigExample.Criteria criteria = example.createCriteria();
criteria.andNameEqualTo(jarConfig.getName());
if (StringUtils.isNotBlank(jarConfig.getId())) {
criteria.andIdNotEqualTo(jarConfig.getId());
}
if (jarConfigMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("already_exists"));
}
}
}
}

View File

@ -167,7 +167,7 @@ public class TestCaseController {
}
@PostMapping("/file/download")
public ResponseEntity<byte[]> downloadJmx(@RequestBody FileOperationRequest fileOperationRequest) {
public ResponseEntity<byte[]> download(@RequestBody FileOperationRequest fileOperationRequest) {
byte[] bytes = fileService.loadFileAsBytes(fileOperationRequest.getId());
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
@ -175,4 +175,13 @@ public class TestCaseController {
.body(bytes);
}
@GetMapping("/file/preview/{fileId}")
public ResponseEntity<byte[]> preview(@PathVariable String fileId) {
byte[] bytes = fileService.loadFileAsBytes(fileId);
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/octet-stream"))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + fileId + "\"")
.body(bytes);
}
}

View File

@ -9,7 +9,18 @@ import java.util.List;
@Getter
@Setter
public class PlanCaseRelevanceRequest {
/**
* 测试计划ID
*/
private String planId;
private String projectId;
/**
* 当选择关联全部用例时把加载条件送到后台从后台查询
*/
private QueryTestCaseRequest request;
/**
* 具体要关联的用例
*/
private List<String> testCaseIds = new ArrayList<>();
}

View File

@ -1,5 +1,6 @@
package io.metersphere.track.request.testreview;
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
import lombok.Getter;
import lombok.Setter;
@ -9,7 +10,18 @@ import java.util.List;
@Getter
@Setter
public class ReviewRelevanceRequest {
/**
* 评审ID
*/
private String reviewId;
private String projectId;
/**
* 当选择关联全部用例时把加载条件送到后台从后台查询
*/
private QueryTestCaseRequest request;
/**
* 具体选择要关联的用例
*/
private List<String> testCaseIds = new ArrayList<>();
}

View File

@ -346,12 +346,9 @@ public class TestCaseReviewService {
if (testCaseIds.isEmpty()) {
return;
}
// 如果是关联全部指令则从新查询未关联的案例
// 如果是关联全部指令则根据条件查询未关联的案例
if (testCaseIds.get(0).equals("all")) {
QueryTestCaseRequest req = new QueryTestCaseRequest();
req.setReviewId(request.getReviewId());
req.setProjectId(request.getProjectId());
List<TestCase> testCases = extTestCaseMapper.getTestCaseByNotInReview(req);
List<TestCase> testCases = extTestCaseMapper.getTestCaseByNotInReview(request.getRequest());
if (!testCases.isEmpty()) {
testCaseIds = testCases.stream().map(testCase -> testCase.getId()).collect(Collectors.toList());
}

View File

@ -263,25 +263,22 @@ public class TestCaseService {
.map(TestCase::getName)
.collect(Collectors.toSet());
List<ExcelErrData<TestCaseExcelData>> errList = null;
if (multipartFile == null)
if (multipartFile == null) {
MSException.throwException(Translator.get("upload_fail"));
}
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
try {
errList = new ArrayList<>();
XmindCaseParser xmindParser = new XmindCaseParser(this, userId, projectId, testCaseNames);
String processLog = xmindParser.parse(multipartFile);
if (!StringUtils.isEmpty(processLog)) {
excelResponse.setSuccess(false);
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + "" + processLog);
errList.add(excelErrData);
excelResponse.setErrList(errList);
} else if (xmindParser.getNodePaths().isEmpty() && xmindParser.getTestCase().isEmpty()) {
excelResponse.setSuccess(false);
errList = xmindParser.parse(multipartFile);
if (xmindParser.getNodePaths().isEmpty() && xmindParser.getTestCase().isEmpty()) {
if (errList == null) {
errList = new ArrayList<>();
}
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + "" + Translator.get("upload_content_is_null"));
errList.add(excelErrData);
excelResponse.setErrList(errList);
} else {
}
if (errList.isEmpty()) {
if (!xmindParser.getNodePaths().isEmpty()) {
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
}
@ -290,7 +287,6 @@ public class TestCaseService {
this.saveImportData(xmindParser.getTestCase(), projectId);
xmindParser.clear();
}
excelResponse.setSuccess(true);
}
} catch (Exception e) {
LogUtil.error(e.getMessage(), e);

View File

@ -211,12 +211,9 @@ public class TestPlanService {
return;
}
// 如果是关联全部指令则从新查询未关联的案例
// 如果是关联全部指令则根据条件查询未关联的案例
if (testCaseIds.get(0).equals("all")) {
QueryTestCaseRequest req = new QueryTestCaseRequest();
req.setPlanId(request.getPlanId());
req.setProjectId(request.getProjectId());
List<TestCase> testCases = extTestCaseMapper.getTestCaseByNotInPlan(req);
List<TestCase> testCases = extTestCaseMapper.getTestCaseByNotInPlan(request.getRequest());
if (!testCases.isEmpty()) {
testCaseIds = testCases.stream().map(testCase -> testCase.getId()).collect(Collectors.toList());
}

View File

@ -6,12 +6,14 @@ import com.google.common.collect.ImmutableMap;
import io.metersphere.base.domain.TestCaseWithBLOBs;
import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.excel.domain.ExcelErrData;
import io.metersphere.excel.domain.TestCaseExcelData;
import io.metersphere.i18n.Translator;
import io.metersphere.track.service.TestCaseService;
import io.metersphere.xmind.parser.XmindParser;
import io.metersphere.xmind.parser.pojo.Attached;
import io.metersphere.xmind.parser.pojo.JsonRootBean;
import io.metersphere.xmind.utils.DetailUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.multipart.MultipartFile;
@ -32,7 +34,7 @@ public class XmindCaseParser {
/**
* 过程校验记录
*/
private StringBuffer process;
private DetailUtil process;
/**
* 已存在用例名称
*/
@ -57,7 +59,7 @@ public class XmindCaseParser {
this.testCaseNames = testCaseNames;
testCases = new LinkedList<>();
compartDatas = new ArrayList<>();
process = new StringBuffer();
process = new DetailUtil();
nodePaths = new ArrayList<>();
}
@ -90,15 +92,15 @@ public class XmindCaseParser {
nodePaths.forEach(nodePath -> {
String[] nodes = nodePath.split("/");
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
process.append(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
process.add(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"), nodePath);
}
String path = "";
for (int i = 0; i < nodes.length; i++) {
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
process.append(Translator.get("module") + ":【" + path + "" + Translator.get("module_not_null") + "; ");
process.add(Translator.get("module_not_null"), path);
} else if (nodes[i].trim().length() > 30) {
process.append(nodes[i].trim() + "" + Translator.get("test_track.length_less_than") + "30 ;");
process.add(Translator.get("module") + Translator.get("test_track.length_less_than") + "30", path + nodes[i].trim());
} else {
path += nodes[i].trim() + "/";
}
@ -109,7 +111,7 @@ public class XmindCaseParser {
/**
* 验证用例的合规性
*/
private boolean validate(TestCaseWithBLOBs data) {
private void validate(TestCaseWithBLOBs data) {
String nodePath = data.getNodePath();
if (!nodePath.startsWith("/")) {
nodePath = "/" + nodePath;
@ -119,37 +121,36 @@ public class XmindCaseParser {
}
data.setNodePath(nodePath);
StringBuilder stringBuilder = new StringBuilder();
if (data.getName().length() > 50) {
stringBuilder.append(data.getName() + "" + Translator.get("test_case") + Translator.get("test_track.length_less_than") + "50 ;");
process.add(Translator.get("test_case") + Translator.get("test_track.length_less_than") + "50", nodePath + data.getName());
}
if (!StringUtils.isEmpty(nodePath)) {
String[] nodes = nodePath.split("/");
if (nodes.length > TestCaseConstants.MAX_NODE_DEPTH + 1) {
stringBuilder.append(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level") + "; ");
process.add(Translator.get("test_case_node_level_tip") +
TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"), nodePath);
}
for (int i = 0; i < nodes.length; i++) {
if (i != 0 && StringUtils.equals(nodes[i].trim(), "")) {
stringBuilder.append(Translator.get("test_case") + ":【" + data.getName() + "" + Translator.get("module_not_null") + "; ");
process.add(Translator.get("test_case") + Translator.get("module_not_null"), nodePath + data.getName());
break;
} else if (nodes[i].trim().length() > 30) {
stringBuilder.append(nodes[i].trim() + "" + Translator.get("module") + Translator.get("test_track.length_less_than") + "30 ;");
process.add(Translator.get("module") + Translator.get("test_track.length_less_than") + "30 ", nodes[i].trim());
break;
}
}
}
if (StringUtils.equals(data.getType(), TestCaseConstants.Type.Functional.getValue()) && StringUtils.equals(data.getMethod(), TestCaseConstants.Method.Auto.getValue())) {
stringBuilder.append(Translator.get("functional_method_tip") + "; ");
process.add(Translator.get("functional_method_tip"), nodePath + data.getName());
}
if (testCaseNames.contains(data.getName())) {
boolean dbExist = testCaseService.exist(data);
if (dbExist) {
stringBuilder.append(Translator.get("test_case_already_exists_excel") + "" + data.getName() + "; ");
process.add(Translator.get("test_case_already_exists_excel"), nodePath + "/" + data.getName());
}
} else {
testCaseNames.add(data.getName());
@ -157,26 +158,19 @@ public class XmindCaseParser {
// 用例等级和用例性质处理
if (!priorityList.contains(data.getPriority())) {
stringBuilder.append(data.getName() + "" + Translator.get("test_case_priority") + Translator.get("incorrect_format") + "; ");
process.add(Translator.get("test_case_priority") + Translator.get("incorrect_format"), nodePath + data.getName());
}
if (data.getType() == null) {
stringBuilder.append(data.getName() + "" + Translator.get("test_case_type") + Translator.get("incorrect_format") + "; ");
process.add(Translator.get("test_case_type") + Translator.get("incorrect_format"), nodePath + data.getName());
}
// 重复用例校验
TestCaseExcelData compartData = new TestCaseExcelData();
BeanUtils.copyBean(compartData, data);
if (compartDatas.contains(compartData)) {
stringBuilder.append(Translator.get("test_case_already_exists_excel") + "" + compartData.getName() + "; ");
}
if (!StringUtils.isEmpty(stringBuilder.toString())) {
process.append(stringBuilder.toString());
return false;
process.add(Translator.get("test_case_already_exists_excel"), nodePath + "/" + compartData.getName());
}
compartDatas.add(compartData);
return true;
}
/**
@ -267,7 +261,7 @@ public class XmindCaseParser {
String tc = title.replace("", ":");
String[] tcArr = tc.split(":");
if (tcArr.length != 2) {
process.append(Translator.get("test_case_name") + "" + title + "" + Translator.get("incorrect_format"));
process.add(Translator.get("test_case_name") + Translator.get("incorrect_format"), title);
return;
}
// 用例名称
@ -301,17 +295,15 @@ public class XmindCaseParser {
});
}
testCase.setSteps(this.getSteps(steps));
testCases.add(testCase);
// 校验合规性
if (validate(testCase)) {
testCases.add(testCase);
}
validate(testCase);
}
/**
* 导入思维导图处理
*/
public String parse(MultipartFile multipartFile) {
public List<ExcelErrData<TestCaseExcelData>> parse(MultipartFile multipartFile) {
try {
// 获取思维导图内容
List<JsonRootBean> roots = XmindParser.parseObject(multipartFile);
@ -321,7 +313,7 @@ public class XmindCaseParser {
for (Attached item : root.getRootTopic().getChildren().getAttached()) {
// 用例
if (isAvailable(item.getTitle(), TC_REGEX)) {
return replace(item.getTitle(), TC_REGEX) + "" + Translator.get("test_case_create_module_fail");
return process.parse(replace(item.getTitle(), TC_REGEX) + "" + Translator.get("test_case_create_module_fail"));
} else {
String nodePath = item.getTitle();
item.setPath(nodePath);
@ -344,8 +336,8 @@ public class XmindCaseParser {
//检查目录合规性
this.validate();
} catch (Exception ex) {
return ex.getMessage();
return process.parse(ex.getMessage());
}
return process.toString();
return process.parse();
}
}

View File

@ -73,7 +73,7 @@ public class XmindParser {
JsonRootBean jsonRootBean = JSON.parseObject(content, JsonRootBean.class);
jsonRootBeans.add(jsonRootBean);
}
if (caseCount > 500) {
if (caseCount > 800) {
MSException.throwException(Translator.get("import_xmind_count_error"));
}
}

View File

@ -0,0 +1,59 @@
package io.metersphere.xmind.utils;
import io.metersphere.excel.domain.ExcelErrData;
import io.metersphere.excel.domain.TestCaseExcelData;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Getter
@Setter
public class DetailUtil implements Serializable {
private Map<String, StringBuilder> process;
public DetailUtil() {
process = new LinkedHashMap<>();
}
public void add(String type, String msContent) {
if (process.containsKey(type)) {
process.get(type).append(msContent + "");
} else {
process.put(type, new StringBuilder(msContent + ""));
}
}
public List<ExcelErrData<TestCaseExcelData>> parse(String content) {
List<ExcelErrData<TestCaseExcelData>> errList = new ArrayList<>();
ExcelErrData excelErrData = new ExcelErrData(null, 1, content);
errList.add(excelErrData);
return errList;
}
public List<ExcelErrData<TestCaseExcelData>> parse() {
List<ExcelErrData<TestCaseExcelData>> errList = new ArrayList<>();
List<String> result = new ArrayList<>();
process.entrySet().parallelStream().reduce(result, (first, second) -> {
first.add(second.getKey() + "" + second.getValue());
return first;
}, (first, second) -> {
if (first == second) {
return first;
}
first.addAll(second);
return first;
});
for (int i = 0; i < result.size(); i++) {
ExcelErrData excelErrData = new ExcelErrData(null, i, result.get(i));
errList.add(excelErrData);
}
return errList;
}
}

View File

@ -0,0 +1,387 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.jmeter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;
/**
* Main class for JMeter - sets up initial classpath and the loader.
*
*/
public final class NewDriver {
private static final String CLASSPATH_SEPARATOR = File.pathSeparator;
private static final String OS_NAME = System.getProperty("os.name");// $NON-NLS-1$
private static final String OS_NAME_LC = OS_NAME.toLowerCase(java.util.Locale.ENGLISH);
private static final String JAVA_CLASS_PATH = "java.class.path";// $NON-NLS-1$
private static final String JMETER_LOGFILE_SYSTEM_PROPERTY = "jmeter.logfile";// $NON-NLS-1$
private static final String HEADLESS_MODE_PROPERTY = "java.awt.headless";// $NON-NLS-1$
/** The class loader to use for loading JMeter classes. */
private static final DynamicClassLoader loader;
/** The directory JMeter is installed in. */
private static final String JMETER_INSTALLATION_DIRECTORY;
private static final List<Exception> EXCEPTIONS_IN_INIT = new ArrayList<>();
// 将当前类加载器设置为 loader 解决由系统类加载器加载的 JMeter 无法动态加载 jar 包问题
public static void setContextClassLoader() {
Thread.currentThread().setContextClassLoader(loader);
}
static {
final List<URL> jars = new LinkedList<>();
final String initiaClasspath = System.getProperty(JAVA_CLASS_PATH);
// Find JMeter home dir from the initial classpath
String tmpDir;
StringTokenizer tok = new StringTokenizer(initiaClasspath, File.pathSeparator);
if (tok.countTokens() == 1
|| (tok.countTokens() == 2 // Java on Mac OS can add a second entry to the initial classpath
&& OS_NAME_LC.startsWith("mac os x")// $NON-NLS-1$
)
) {
File jar = new File(tok.nextToken());
try {
tmpDir = jar.getCanonicalFile().getParentFile().getParent();
} catch (IOException e) {
tmpDir = null;
}
} else {// e.g. started from IDE with full classpath
tmpDir = System.getProperty("jmeter.home","");// Allow override $NON-NLS-1$ $NON-NLS-2$
if (tmpDir.length() == 0) {
File userDir = new File(System.getProperty("user.dir"));// $NON-NLS-1$
tmpDir = userDir.getAbsoluteFile().getParent();
}
}
JMETER_INSTALLATION_DIRECTORY=tmpDir;
/*
* Does the system support UNC paths? If so, may need to fix them up
* later
*/
boolean usesUNC = OS_NAME_LC.startsWith("windows");// $NON-NLS-1$
// Add standard jar locations to initial classpath
StringBuilder classpath = new StringBuilder();
File[] libDirs = new File[] { new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib"),// $NON-NLS-1$ $NON-NLS-2$
new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib" + File.separator + "ext"),// $NON-NLS-1$ $NON-NLS-2$
new File(JMETER_INSTALLATION_DIRECTORY + File.separator + "lib" + File.separator + "junit")};// $NON-NLS-1$ $NON-NLS-2$
for (File libDir : libDirs) {
File[] libJars = libDir.listFiles((dir, name) -> name.endsWith(".jar"));
if (libJars == null) {
new Throwable("Could not access " + libDir).printStackTrace(); // NOSONAR No logging here
continue;
}
Arrays.sort(libJars); // Bug 50708 Ensure predictable order of jars
for (File libJar : libJars) {
try {
String s = libJar.getPath();
// Fix path to allow the use of UNC URLs
if (usesUNC) {
if (s.startsWith("\\\\") && !s.startsWith("\\\\\\")) {// $NON-NLS-1$ $NON-NLS-2$
s = "\\\\" + s;// $NON-NLS-1$
} else if (s.startsWith("//") && !s.startsWith("///")) {// $NON-NLS-1$ $NON-NLS-2$
s = "//" + s;// $NON-NLS-1$
}
} // usesUNC
jars.add(new File(s).toURI().toURL());// See Java bug 4496398
classpath.append(CLASSPATH_SEPARATOR);
classpath.append(s);
} catch (MalformedURLException e) { // NOSONAR
EXCEPTIONS_IN_INIT.add(new Exception("Error adding jar:"+libJar.getAbsolutePath(), e));
}
}
}
// ClassFinder needs the classpath
System.setProperty(JAVA_CLASS_PATH, initiaClasspath + classpath.toString());
loader = AccessController.doPrivileged(
(PrivilegedAction<DynamicClassLoader>) () ->
new DynamicClassLoader(jars.toArray(new URL[jars.size()]))
);
}
/**
* Prevent instantiation.
*/
private NewDriver() {
}
/**
* Generate an array of jar files located in a directory.
* Jar files located in sub directories will not be added.
*
* @param dir to search for the jar files.
*/
private static File[] listJars(File dir) {
if (dir.isDirectory()) {
return dir.listFiles((f, name) -> {
if (name.endsWith(".jar")) {// $NON-NLS-1$
File jar = new File(f, name);
return jar.isFile() && jar.canRead();
}
return false;
});
}
return new File[0];
}
/**
* Add a URL to the loader classpath only; does not update the system classpath.
*
* @param path to be added.
* @throws MalformedURLException when <code>path</code> points to an invalid url
*/
public static void addURL(String path) throws MalformedURLException {
File furl = new File(path);
loader.addURL(furl.toURI().toURL()); // See Java bug 4496398
File[] jars = listJars(furl);
for (File jar : jars) {
loader.addURL(jar.toURI().toURL()); // See Java bug 4496398
}
}
/**
* Add a URL to the loader classpath only; does not update the system
* classpath.
*
* @param url
* The {@link URL} to add to the classpath
*/
public static void addURL(URL url) {
loader.addURL(url);
}
/**
* Add a directory or jar to the loader and system classpaths.
*
* @param path
* to add to the loader and system classpath
* @throws MalformedURLException
* if <code>path</code> can not be transformed to a valid
* {@link URL}
*/
public static void addPath(String path) throws MalformedURLException {
File file = new File(path);
// Ensure that directory URLs end in "/"
if (file.isDirectory() && !path.endsWith("/")) {// $NON-NLS-1$
file = new File(path + "/");// $NON-NLS-1$
}
loader.addURL(file.toURI().toURL()); // See Java bug 4496398
StringBuilder sb = new StringBuilder(System.getProperty(JAVA_CLASS_PATH));
sb.append(CLASSPATH_SEPARATOR);
sb.append(path);
File[] jars = listJars(file);
for (File jar : jars) {
loader.addURL(jar.toURI().toURL()); // See Java bug 4496398
sb.append(CLASSPATH_SEPARATOR);
sb.append(jar.getPath());
}
// ClassFinder needs this
System.setProperty(JAVA_CLASS_PATH,sb.toString());
}
/**
* Get the directory where JMeter is installed. This is the absolute path
* name.
*
* @return the directory where JMeter is installed.
*/
public static String getJMeterDir() {
return JMETER_INSTALLATION_DIRECTORY;
}
/**
* The main program which actually runs JMeter.
*
* @param args
* the command line arguments
*/
public static void main(String[] args) {
if(!EXCEPTIONS_IN_INIT.isEmpty()) {
System.err.println("Configuration error during init, see exceptions:"+exceptionsToString(EXCEPTIONS_IN_INIT)); // NOSONAR Intentional System.err use
} else {
Thread.currentThread().setContextClassLoader(loader);
setLoggingProperties(args);
try {
// Only set property if it has not been set explicitely
if(System.getProperty(HEADLESS_MODE_PROPERTY) == null && shouldBeHeadless(args)) {
System.setProperty(HEADLESS_MODE_PROPERTY, "true");
}
Class<?> initialClass = loader.loadClass("org.apache.jmeter.JMeter");// $NON-NLS-1$
Object instance = initialClass.getDeclaredConstructor().newInstance();
Method startup = initialClass.getMethod("start", new Class[] { new String[0].getClass() });// $NON-NLS-1$
startup.invoke(instance, new Object[] { args });
} catch(Throwable e){ // NOSONAR We want to log home directory in case of exception
e.printStackTrace(); // NOSONAR No logger at this step
System.err.println("JMeter home directory was detected as: "+JMETER_INSTALLATION_DIRECTORY); // NOSONAR Intentional System.err use
}
}
}
/**
* @param exceptionsInInit List of {@link Exception}
* @return String
*/
private static String exceptionsToString(List<Exception> exceptionsInInit) {
StringBuilder builder = new StringBuilder();
for (Exception exception : exceptionsInInit) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter); // NOSONAR
builder.append(stringWriter.toString())
.append("\r\n");
}
return builder.toString();
}
/*
* Set logging related system properties.
*/
private static void setLoggingProperties(String[] args) {
String jmLogFile = getCommandLineArgument(args, 'j', "jmeterlogfile");// $NON-NLS-1$ $NON-NLS-2$
if (jmLogFile != null && !jmLogFile.isEmpty()) {
jmLogFile = replaceDateFormatInFileName(jmLogFile);
System.setProperty(JMETER_LOGFILE_SYSTEM_PROPERTY, jmLogFile);// $NON-NLS-1$
} else if (System.getProperty(JMETER_LOGFILE_SYSTEM_PROPERTY) == null) {// $NON-NLS-1$
System.setProperty(JMETER_LOGFILE_SYSTEM_PROPERTY, "jmeter.log");// $NON-NLS-1$ $NON-NLS-2$
}
String jmLogConf = getCommandLineArgument(args, 'i', "jmeterlogconf");// $NON-NLS-1$ $NON-NLS-2$
File logConfFile = null;
if (jmLogConf != null && !jmLogConf.isEmpty()) {
logConfFile = new File(jmLogConf);
} else if (System.getProperty("log4j.configurationFile") == null) {// $NON-NLS-1$
logConfFile = new File("log4j2.xml");// $NON-NLS-1$
if (!logConfFile.isFile()) {
logConfFile = new File(JMETER_INSTALLATION_DIRECTORY, "bin" + File.separator + "log4j2.xml");// $NON-NLS-1$ $NON-NLS-2$
}
}
if (logConfFile != null) {
System.setProperty("log4j.configurationFile", logConfFile.toURI().toString());// $NON-NLS-1$
}
}
private static boolean shouldBeHeadless(String[] args) {
for (String arg : args) {
if("-n".equals(arg) || "-s".equals(arg) || "-g".equals(arg)) {
return true;
}
}
return false;
}
/*
* Find command line argument option value by the id and name.
*/
private static String getCommandLineArgument(String[] args, int id, String name) {
final String shortArgName = "-" + ((char) id);// $NON-NLS-1$
final String longArgName = "--" + name;// $NON-NLS-1$
String value = null;
for (int i = 0; i < args.length; i++) {
if ((shortArgName.equals(args[i]) && i < args.length - 1)
|| longArgName.equals(args[i])) {
if (!args[i + 1].startsWith("-")) {// $NON-NLS-1$
value = args[i + 1];
}
break;
} else if (!shortArgName.equals(args[i]) && args[i].startsWith(shortArgName)) {
value = args[i].substring(shortArgName.length());
break;
}
}
return value;
}
/*
* If the fileName contains at least one set of paired single-quotes, reformat using DateFormat
*/
private static String replaceDateFormatInFileName(String fileName) {
try {
StringBuilder builder = new StringBuilder();
final Date date = new Date();
int fromIndex = 0;
int begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
int end;
String format;
SimpleDateFormat dateFormat;
while (begin != -1) {
builder.append(fileName.substring(fromIndex, begin));
fromIndex = begin + 1;
end = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
if (end == -1) {
throw new IllegalArgumentException("Invalid pairs of single-quotes in the file name: " + fileName);// $NON-NLS-1$
}
format = fileName.substring(begin + 1, end);
dateFormat = new SimpleDateFormat(format);
builder.append(dateFormat.format(date));
fromIndex = end + 1;
begin = fileName.indexOf('\'', fromIndex);// $NON-NLS-1$
}
if (fromIndex < fileName.length() - 1) {
builder.append(fileName.substring(fromIndex));
}
return builder.toString();
} catch (Exception ex) {
System.err.println("Error replacing date format in file name:"+fileName+", error:"+ex.getMessage()); // NOSONAR
}
return fileName;
}
}

View File

@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS `jar_config` (
`id` varchar(50) NOT NULL COMMENT 'ID',
`name` varchar(64) NOT NULL COMMENT 'Name',
`file_name` varchar(64) NOT NULL COMMENT 'File name',
`creator` varchar(50) NOT NULL COMMENT 'creator User ID',
`modifier` varchar(50) NOT NULL COMMENT 'Modifier User ID',
`path` varchar(255) NOT NULL COMMENT 'File path',
`enable` tinyint(1) COMMENT 'Config enable',
`description` varchar(255) DEFAULT NULL COMMENT 'description',
`create_time` bigint(13) NOT NULL COMMENT 'Create timestamp',
`update_time` bigint(13) NOT NULL COMMENT 'Update timestamp',
PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4;

View File

@ -68,6 +68,5 @@
<table tableName="notice"/>
<table tableName="message_task"/>
</context>
</generatorConfiguration>

View File

@ -35,7 +35,8 @@
"jspdf": "^2.1.1",
"yan-progress": "^1.0.3",
"nprogress": "^0.2.0",
"el-table-infinite-scroll": "^1.0.10"
"el-table-infinite-scroll": "^1.0.10",
"vue-pdf": "^4.2.0"
},
"devDependencies": {
"@vue/cli-plugin-babel": "^4.1.0",

View File

@ -16,16 +16,16 @@
<ms-assertion-results :assertions="response.assertions"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.request.extract.label')" name="label" class="pane">
<pre>{{response.vars}}</pre>
</el-tab-pane>
<el-tab-pane v-if="activeName == 'body'" :disabled="true" name="mode" class="pane assertions">
<template v-slot:label>
<ms-dropdown :commands="modes" :default-command="mode" @command="modeChange"/>
</template>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.request.extract.label')" name="label" class="pane">
<pre>{{response.vars}}</pre>
</el-tab-pane>
</el-tabs>
</el-collapse-transition>
</div>

View File

@ -40,6 +40,9 @@
<el-dropdown-item command="report">
{{ $t('api_report.title') }}
</el-dropdown-item>
<el-dropdown-item command="jar" :disabled="isReadOnly">
{{ $t('api_test.jar_config.title') }}
</el-dropdown-item>
<el-dropdown-item command="performance" :disabled="create || isReadOnly">
{{ $t('api_test.create_performance_test') }}
</el-dropdown-item>
@ -58,6 +61,9 @@
<ms-schedule-config :schedule="test.schedule" :is-read-only="isReadOnly" :save="saveCronExpression"
@scheduleChange="saveSchedule" :test-id="id" :check-open="checkScheduleEdit"/>
<ms-jar-config :is-read-only="isReadOnly" ref="jarConfig"/>
</el-row>
</el-header>
<ms-api-scenario-config :debug-report-id="debugReportId" @runDebug="runDebug" :is-read-only="isReadOnly"
@ -80,11 +86,13 @@
import {ApiEvent, LIST_CHANGE} from "@/business/components/common/head/ListEvent";
import MsContainer from "@/business/components/common/components/MsContainer";
import MsMainContainer from "@/business/components/common/components/MsMainContainer";
import MsJarConfig from "./components/jar/JarConfig";
export default {
name: "MsApiTestConfig",
components: {
MsJarConfig,
MsMainContainer,
MsContainer, ApiImport, MsScheduleConfig, MsApiReportDialog, MsApiReportStatus, MsApiScenarioConfig
},
@ -316,6 +324,9 @@
case "export":
downloadFile(this.test.name + ".json", this.test.export());
break;
case "jar":
this.$refs.jarConfig.open();
break;
case "import":
this.$refs.apiImport.open();
break;

View File

@ -116,17 +116,13 @@
return true;
},
validateDomain(domain) {
let url = {};
try {
if (!domain.startsWith("http") || !domain.startsWith("https")) {
domain += "http://";
}
url = new URL(domain);
} catch (e) {
this.$warning(this.$t('load_test.input_domain'));
return false
let strRegex = "^(?=^.{3,255}$)(http(s)?:\\/\\/)?(www\\.)?[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+(:\\d+)*(\\/\\w+\\.\\w+)*$";
const re = new RegExp(strRegex);
if (re.test(domain) && domain.length < 26) {
return true;
}
return true;
this.$warning(this.$t('load_test.input_domain'));
return false;
},
dblHostTable: function (row) {
row.status = 'edit';

View File

@ -29,6 +29,10 @@
type: Boolean,
default: true
},
showCopyTipWithMultiple: {
type: Boolean,
default: false
},
},
data() {
@ -63,7 +67,7 @@
computed: {
variable() {
return "${" + this.value + "}";
return "${" + (this.showCopyTipWithMultiple ? (this.value + "_n") : this.value) + "}";
}
}

View File

@ -46,7 +46,10 @@
handleRemove(file) {
this.$refs.upload.handleRemove(file);
for (let i = 0; i < this.parameter.files.length; i++) {
if (file.file.name === this.parameter.files[i].file.name) {
let fileName = file.file ? file.file.name : file.name;
let paramFileName = this.parameter.files[i].file ?
this.parameter.files[i].file.name : this.parameter.files[i].name;
if (fileName === paramFileName) {
this.parameter.files.splice(i, 1);
this.$refs.upload.handleRemove(file);
break;

View File

@ -8,12 +8,17 @@
</el-col>
<el-col>
<ms-api-variable-input :is-read-only="isReadOnly" v-model="common.variable" size="small" maxlength="60"
@change="change" show-word-limit :placeholder="$t('api_test.variable_name')"/>
@change="change" :show-copy-tip-with-multiple="common.multipleMatching" show-word-limit :placeholder="$t('api_test.variable_name')"/>
</el-col>
<el-col>
<el-input :disabled="isReadOnly" v-model="common.expression" size="small" show-word-limit
:placeholder="expression"/>
</el-col>
<el-col class="multiple_checkbox">
<el-checkbox v-model="common.multipleMatching" :disabled="isReadOnly">
{{ $t('api_test.request.extract.multiple_matching') }}
</el-checkbox>
</el-col>
<el-col class="extract-btn">
<el-button :disabled="isReadOnly" type="danger" size="mini" icon="el-icon-delete" circle @click="remove"
v-if="edit"/>
@ -159,4 +164,10 @@
.extract-btn {
width: 60px;
}
.multiple_checkbox {
text-align: center;
width: 120px;
}
</style>

View File

@ -0,0 +1,76 @@
<template>
<el-dialog width="50%" :close-on-click-modal="false" :title="$t('api_test.jar_config.title')" :visible.sync="visible" class="jar-import" @close="close">
<div v-loading="result.loading">
<ms-jar-config-from :config="currentConfig" :callback="saveConfig" ref="jarConfigFrom" :read-only="isReadOnly"/>
<ms-jar-config-list @refresh="getJarConfigs" v-if="configs.length > 0" @rowSelect="rowSelect" :table-data="configs" ref="jarConfigList"/>
</div>
</el-dialog>
</template>
<script>
import MsDialogFooter from "../../../../common/components/MsDialogFooter";
import ApiEnvironmentConfig from "../ApiEnvironmentConfig";
import {listenGoBack, removeGoBackListener} from "../../../../../../common/js/utils";
import MsJarConfigList from "./JarConfigList";
import MsJarConfigFrom from "./JarConfigFrom";
export default {
name: "MsJarConfig",
components: {MsJarConfigFrom, MsJarConfigList, ApiEnvironmentConfig, MsDialogFooter},
data() {
return {
visible: false,
result: {},
currentConfig: {},
configs: []
}
},
props: {
isReadOnly: {
type: Boolean,
default: false
},
},
methods: {
open() {
this.visible = true;
this.getJarConfigs();
listenGoBack(this.close);
},
saveConfig(config, file) {
for (let item of this.configs) {
if (item.name === config.name && item.id !== config.id) {
this.$warning(this.$t('commons.already_exists'));
return;
}
if (item.fileName === file.name && item.id !== config.id) {
this.$warning(this.$t('api_test.jar_config.file_exist'));
return;
}
}
let url = config.id ? "/jar/update" : "/jar/add";
this.result = this.$fileUpload(url, file, null, config, () => {
this.$success(this.$t('commons.save_success'));
this.getJarConfigs();
});
},
getJarConfigs() {
this.result = this.$get("/jar/list/all", response => {
this.configs = response.data;
this.currentConfig = {};
})
},
rowSelect(config) {
this.currentConfig = config;
},
close() {
this.$refs.jarConfigFrom.clear();
removeGoBackListener(this.close);
this.visible = false;
}
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,187 @@
<template>
<el-form :model="currentConfig" :rules="rules" label-width="100px" v-loading="result.loading" ref="form">
<el-row>
<el-col :span="12">
<el-form-item :label="$t('commons.name')" prop="name">
<el-input size="small" v-model="currentConfig.name" clearable show-word-limit/>
</el-form-item>
<el-form-item :label="$t('commons.project')" prop="description">
<el-input :disabled="readOnly" v-model="currentConfig.description"
type="textarea"
:autosize="{ minRows: 2, maxRows: 4}"
:rows="2"
:placeholder="$t('commons.input_content')"/>
</el-form-item>
</el-col>
<el-col :span="1">
<el-divider direction="vertical"/>
</el-col>
<el-col :span="11">
<el-upload
class="jar-upload"
drag
action="#"
:http-request="upload"
:limit="1"
:beforeUpload="uploadValidate"
:on-remove="handleRemove"
:on-exceed="handleExceed"
:file-list="fileList"
ref="fileUpload">
<i class="el-icon-upload"></i>
<div class="el-upload__text" v-html="$t('load_test.upload_tips')"></div>
<div class="el-upload__tip" slot="tip">{{$t('api_test.api_import.file_size_limit')}}</div>
</el-upload>
</el-col>
<el-col>
<div class="buttons">
<el-button type="primary" v-show="currentConfig.id" size="small" @click="save('update')">{{$t('commons.update')}}</el-button>
<el-button type="primary" size="small" @click="save('add')">{{$t('commons.add')}}</el-button>
</div>
</el-col>
</el-row>
</el-form>
</template>
<script>
export default {
name: "MsJarConfigFrom",
data() {
return {
visible: false,
result: {},
currentConfig: {
name: '',
description: '',
fileName: '',
},
rules: {
name: [
{required: true, message: this.$t('commons.input_name'), trigger: 'blur'},
{max: 60, message: this.$t('commons.input_limit', [1, 60]), trigger: 'blur'}
],
},
fileList: []
}
},
props: {
readOnly: {
type: Boolean,
default: false
},
config: {
type: Object,
default() {
return {};
}
},
callback: {
type: Function
},
},
watch: {
config() {
this.currentConfig = {
name: '',
description: '',
fileName: ''
};
if (this.config.fileName) {
this.fileList = [{name: this.config.fileName}];
} else {
this.fileList = [];
}
Object.assign(this.currentConfig, this.config);
}
},
mounted() {
Object.assign(this.currentConfig, this.config);
},
methods: {
upload(file) {
this.fileList.push(file.file)
},
handleExceed(files, fileList) {
this.$warning(this.$t('test_track.case.import.upload_limit_count'));
},
handleRemove(file, fileList) {
this.fileList = [];
},
uploadValidate(file, fileList) {
let suffix = file.name.substring(file.name.lastIndexOf('.') + 1);
if (suffix != 'jar') {
this.$warning(this.$t('api_test.api_import.suffixFormatErr'));
return false;
}
if (file.size / 1024 / 1024 > 30) {
this.$warning(this.$t('jar_config.upload_limit_size'));
return false;
}
return true;
},
save(type) {
this.$refs['form'].validate((valid) => {
if (valid) {
if (this.fileList <= 0) {
this.$warning(this.$t('commons.please_upload'));
return;
}
if (this.callback) {
if (type === 'add') {
this.currentConfig.id = undefined;
}
this.callback(this.currentConfig, this.fileList[0]);
}
} else {
return false;
}
});
},
clear() {
this.$refs['form'].clearValidate();
this.fileList = [];
}
}
}
</script>
<style scoped>
.el-divider {
height: 200px;
}
.jar-upload {
text-align: center;
margin: auto 0;
}
.jar-upload >>> .el-upload {
width: 100%;
max-width: 350px;
}
.jar-upload >>> .el-upload-dragger {
width: 100%;
}
.el-form {
border: solid #E1E1E1 1px;
margin: 10px 0;
padding: 30px 10px;
border-radius: 3px;
}
.buttons {
margin-top: 10px;
margin-bottom: -10px;
float: right;
}
</style>

View File

@ -0,0 +1,83 @@
<template>
<div class="jar-config-list">
<el-table border :data="tableData"
class="adjust-table table-content"
highlight-current-row
@row-click="handleView">
<el-table-column prop="name" :label="$t('commons.name')" show-overflow-tooltip/>
<el-table-column prop="fileName" :label="$t('api_test.jar_config.jar_file')" show-overflow-tooltip/>
<el-table-column prop="description" :label="$t('commons.description')" show-overflow-tooltip/>
<el-table-column prop="updateTime" :label="$t('commons.update_time')" show-overflow-tooltip>
<template v-slot:default="scope">
<span>{{ scope.row.updateTime | timestampFormatDate }}</span>
</template>
</el-table-column>
<el-table-column prop="creator" :label="$t('report.user_name')" show-overflow-tooltip/>
<el-table-column prop="modifier" :label="$t('commons.modifier')" show-overflow-tooltip/>
<el-table-column :label="$t('commons.operating')" min-width="100">
<template v-slot:default="scope">
<ms-table-operator-button :isTesterPermission="true" :tip="$t('commons.delete')" icon="el-icon-delete" type="danger" @exec="handleDelete(scope.row.id)"/>
</template>
</el-table-column>
</el-table>
</div>
</template>
<script>
import MsTableOperatorButton from "../../../../common/components/MsTableOperatorButton";
export default {
name: "MsJarConfigList",
components: {MsTableOperatorButton},
props: {
tableData: Array,
isReadOnly: {
type: Boolean,
default: false
},
},
data() {
return {
result: {},
}
},
methods: {
handleView(row) {
this.$emit('rowSelect', row);
},
handleDelete(id) {
this.$confirm(this.$t('api_test.jar_config.delete_tip'), '', {
confirmButtonText: this.$t('commons.confirm'),
cancelButtonText: this.$t('commons.cancel'),
type: 'warning'
}).then(() => {
this.result = this.$get("/jar/delete/" + id, () => {
this.$success(this.$t('commons.delete_success'));
this.$emit('refresh');
});
}).catch(() => {
this.$message({
type: 'info',
message: this.$t('commons.delete_cancelled')
});
});
},
}
}
</script>
<style scoped>
.el-icon-check {
font-size: 20px;
font-weight: bold;
color: green;
margin-left: 20px;
}
</style>

View File

@ -49,43 +49,35 @@
<el-row :gutter="10">
<el-col :span="6">
<el-form-item>
<el-form-item :label="$t('api_test.request.refer_to_environment')">
<el-switch
v-model="request.useEnvironment"
:active-text="$t('api_test.request.refer_to_environment')"
@change="useEnvironmentChange">
</el-switch>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.re_use_connection')">
<el-checkbox v-model="request.reUseConnection"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.close_connection')">
<el-checkbox v-model="request.closeConnection"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-form-item>
<el-switch
v-model="request.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.no_delay')">
<el-checkbox v-model="request.nodelay"/>
</el-form-item>
</el-col>
</el-row>
<el-form-item :label="$t('api_test.request.tcp.request')" prop="request">
<el-input type="textarea" v-model="request.request" :autosize="{minRows: 4, maxRows: 6}">
</el-input>
<div class="send-request">
<ms-code-edit mode="text" :read-only="isReadOnly" :data.sync="request.request"
:modes="['text', 'json', 'xml', 'html']" theme="eclipse"/>
</div>
</el-form-item>
<el-row :gutter="10">
@ -128,10 +120,11 @@ import {Scenario, TCPConfig, TCPRequest} from "@/business/components/api/test/mo
import MsApiAssertions from "@/business/components/api/test/components/assertion/ApiAssertions";
import MsApiExtract from "@/business/components/api/test/components/extract/ApiExtract";
import MsJsr233Processor from "@/business/components/api/test/components/processor/Jsr233Processor";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
export default {
name: "MsApiTcpRequestForm",
components: {MsJsr233Processor, MsApiExtract, MsApiAssertions},
components: {MsCodeEdit, MsJsr233Processor, MsApiExtract, MsApiAssertions},
props: {
request: TCPRequest,
scenario: Scenario,
@ -144,15 +137,7 @@ export default {
return {
activeName: "assertions",
classes: TCPConfig.CLASSES,
rules: {
server: [
{
required: true,
message: this.$t('commons.required', [this.$t('api_test.request.tcp.server')]),
trigger: 'blur'
}
],
}
rules: {}
}
},
@ -175,4 +160,9 @@ export default {
.tcp >>> .el-input-number {
width: 100%;
}
.send-request {
padding: 15px 0;
height: 300px;
}
</style>

View File

@ -39,7 +39,7 @@
<el-form-item>
<div class="buttons">
<el-button type="primary" v-show="currentConfig.id" size="small" @click="validate()">{{$t('校验')}}</el-button>
<el-button type="primary" v-show="currentConfig.id" size="small" @click="validate()">{{$t('commons.validate')}}</el-button>
<el-button type="primary" v-show="currentConfig.id" size="small" @click="save('update')">{{$t('commons.update')}}</el-button>
<el-button type="primary" size="small" @click="save('add')">{{$t('commons.add')}}</el-button>
</div>

View File

@ -22,22 +22,25 @@
</el-row>
<el-row :gutter="10">
<el-col :span="6">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.connect')" prop="ctimeout">
<el-input-number v-model="config.ctimeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.response')" prop="timeout">
<el-input-number v-model="config.timeout" controls-position="right" :min="0" :step="1000" :controls="false"/>
</el-form-item>
</el-col>
<el-col :span="6">
</el-row>
<el-row :gutter="10">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.so_linger')" prop="soLinger">
<el-input v-model="config.soLinger"/>
</el-form-item>
</el-col>
<el-col :span="6">
<el-col :span="12">
<el-form-item :label="$t('api_test.request.tcp.eol_byte')" prop="eolByte">
<el-input v-model="config.eolByte"/>
</el-form-item>
@ -46,27 +49,18 @@
<el-row :gutter="10">
<el-col :span="8">
<el-form-item>
<el-switch
v-model="config.reUseConnection"
:active-text="$t('api_test.request.tcp.re_use_connection')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.re_use_connection')">
<el-checkbox v-model="config.reUseConnection"/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item>
<el-switch
v-model="config.closeConnection"
:active-text="$t('api_test.request.tcp.close_connection')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.close_connection')">
<el-checkbox v-model="config.closeConnection"/>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item>
<el-switch
v-model="config.nodelay"
:active-text="$t('api_test.request.tcp.no_delay')">
</el-switch>
<el-form-item :label="$t('api_test.request.tcp.no_delay')">
<el-checkbox v-model="config.nodelay"/>
</el-form-item>
</el-col>
</el-row>

View File

@ -855,6 +855,7 @@ export class ExtractCommon extends ExtractType {
this.value = ""; // ${variable}
this.expression = undefined;
this.description = undefined;
this.multipleMatching = undefined;
this.set(options);
}
@ -1460,6 +1461,7 @@ class JMXGenerator {
let props = {
name: extractCommon.variable,
expression: extractCommon.expression,
match: extractCommon.multipleMatching ? -1 : undefined
}
let testName = props.name
switch (extractCommon.type) {

View File

@ -37,7 +37,7 @@
<ms-table-operator :is-tester-permission="true" @editClick="edit(scope.row)"
@deleteClick="handleDelete(scope.row)">
<template v-if="baseUrl == 'api'" v-slot:behind>
<ms-table-operator-button :is-tester-permission="true" :tip="'环境配置'" icon="el-icon-setting"
<ms-table-operator-button :is-tester-permission="true" :tip="$t('api_test.environment.environment_config')" icon="el-icon-setting"
type="info" @exec="openEnvironmentConfig(scope.row)"/>
</template>
</ms-table-operator>
@ -76,6 +76,7 @@
<ms-delete-confirm :title="$t('project.delete')" @delete="_handleDelete" ref="deleteConfirm"/>
<api-environment-config ref="environmentConfig"/>
<ms-jar-config ref="jarConfig"/>
</ms-container>
</template>

View File

@ -211,7 +211,7 @@
</el-row>
<el-row style="margin-top: 15px;margin-bottom: 10px">
<el-col :offset="2" :span="20">附件:
<el-col :offset="2" :span="20">{{ $t('test_track.case.attachment') }}:
<el-upload
accept=".jpg,.jpeg,.png,.xlsx,.doc,.pdf,.docx"
action=""
@ -223,7 +223,7 @@
:limit="8"
:file-list="fileList">
<el-button icon="el-icon-plus" size="mini"></el-button>
<span slot="tip" class="el-upload__tip"> 只能上传jpgjpegpngdocxdocpdfxlsx文件 </span>
<span slot="tip" class="el-upload__tip"> {{ $t('test_track.case.upload_tip') }} </span>
</el-upload>
</el-col>
</el-row>
@ -252,6 +252,10 @@
<el-table-column
:label="$t('commons.operating')">
<template v-slot:default="scope">
<el-button @click="preview(scope.row)" :disabled="!scope.row.id || readOnly" type="primary"
v-if="isPreview(scope.row)"
icon="el-icon-view"
size="mini" circle/>
<el-button @click="handleDownload(scope.row)" :disabled="!scope.row.id || readOnly" type="primary"
icon="el-icon-download"
size="mini" circle/>
@ -277,6 +281,7 @@
</el-dialog>
<test-case-file ref="testCaseFile"/>
</div>
@ -289,10 +294,11 @@ import MsDialogFooter from '../../../common/components/MsDialogFooter'
import {listenGoBack, removeGoBackListener} from "../../../../../common/js/utils";
import {LIST_CHANGE, TrackEvent} from "@/business/components/common/head/ListEvent";
import {Message} from "element-ui";
import TestCaseFile from "@/business/components/track/case/components/TestCaseFile";
export default {
name: "TestCaseEdit",
components: {MsDialogFooter},
components: {MsDialogFooter, TestCaseFile},
data() {
return {
result: {},
@ -718,7 +724,13 @@ export default {
/// todo:
return file.size > 0;
},
preview(row) {
this.$refs.testCaseFile.open(row);
},
isPreview(row) {
const fileType = row.type;
return fileType === 'JPG' || fileType === 'JPEG' || fileType === 'PDF' || fileType === 'PNG';
}
}
}
</script>

View File

@ -0,0 +1,48 @@
<template>
<el-dialog :visible.sync="dialogVisible" width="80%" :destroy-on-close="true" :before-close="close">
<div>
<img :src="'/test/case/file/preview/' + file.id" :alt="$t('test_track.case.img_loading_fail')" style="width: 100%;height: 100%;"
v-if="file.type === 'JPG' || file.type === 'JPEG' || file.type === 'PNG'">
<div v-if="file.type === 'PDF'">
<test-case-pdf :file-id="file.id"/>
</div>
</div>
</el-dialog>
</template>
<script>
import TestCasePdf from "@/business/components/track/case/components/TestCasePdf";
export default {
name: "TestCaseFiles",
components: {TestCasePdf},
props: {},
data() {
return {
file: {
id: '',
type: ''
},
dialogVisible: false,
}
},
methods: {
open(file) {
this.file = file;
this.dialogVisible = true;
},
close() {
this.file = {
id: '',
type: ''
};
this.dialogVisible = false;
}
}
}
</script>
<style scoped>
</style>

View File

@ -0,0 +1,38 @@
<template>
<div v-loading="loading">
<pdf ref="pdf" v-for="i in numPages" :key="i" :src="loadingTask" :page="i"/>
</div>
</template>
<script>
import pdf from "vue-pdf";
export default {
name: "TestCasePdf",
components: {pdf},
props: {
fileId: String
},
data() {
return {
loading: false,
numPages: null,
loadingTask: null,
}
},
mounted() {
this.loading = true;
this.loadingTask = pdf.createLoadingTask("/test/case/file/preview/" + this.fileId);
this.loadingTask.promise.then(pdf => {
this.numPages = pdf.numPages
this.loading = false;
}).catch(() => {
this.loading = false;
this.$error(this.$t('test_track.case.pdf_loading_fail'));
})
}
}
</script>
<style scoped>
</style>

View File

@ -176,7 +176,7 @@
let param = {};
param.planId = this.planId;
param.testCaseIds = [...this.selectIds];
param.projectId = this.projectId;
param.request = this.condition;
//
if (this.testCases.length === param.testCaseIds.length) {
param.testCaseIds = ['all'];

View File

@ -5,7 +5,7 @@
<ms-table-header :is-tester-permission="true" :condition.sync="condition" @search="initTableData"
:show-create="false" :tip="$t('commons.search_by_name_or_id')">
<template v-slot:title>
<node-breadcrumb class="table-title" :nodes="selectParentNodes" @refresh="refresh"/>
<node-breadcrumb class="table-title" :nodes="selectParentNodes" @refresh="breadcrumbRefresh"/>
</template>
<template v-slot:button>
<ms-table-button :is-tester-permission="true" v-if="!showMyTestCase" icon="el-icon-s-custom"
@ -392,6 +392,10 @@ export default {
this.selectRows.clear();
this.$emit('refresh');
},
breadcrumbRefresh() {
this.showMyTestCase = false;
this.refresh();
},
refreshTableAndPlan() {
this.getTestPlanById();
this.initTableData();

View File

@ -185,7 +185,7 @@
let param = {};
param.reviewId = this.reviewId;
param.testCaseIds = [...this.selectIds];
param.projectId = this.projectId;
param.request = this.condition;
//
if (this.testReviews.length === param.testCaseIds.length) {
param.testCaseIds = ['all'];

View File

@ -16,7 +16,7 @@
<el-card>
<el-scrollbar>
<el-header>
<el-header style="height: 100%;">
<el-row type="flex" class="head-bar">
@ -27,7 +27,7 @@
</el-button>
</el-col>
<el-col :span="12" class="head-right">
<el-col :span="14" class="head-right">
<el-button plain size="mini" icon="el-icon-arrow-up"
:disabled="index + 1 <= 1"
@ -425,6 +425,7 @@ export default {
.head-right {
text-align: right;
margin-top: 30px;
}
.el-col:not(.test-detail) {

@ -1 +1 @@
Subproject commit cc38137a69a0f20fadece9c0f9f50a9468c4ace9
Subproject commit 06d935cd1d22ab36f09763745c2aff8ad3fb08c1

View File

@ -118,6 +118,8 @@ export default {
please_upload: 'Please upload file',
reference_documentation: "Reference documentation",
already_exists: 'The name already exists',
modifier: 'Modifier',
validate: "Validate",
date: {
select_date: 'Select date',
start_date: 'Start date',
@ -437,6 +439,13 @@ export default {
export_config: "Export",
enable_validate_tip: "No request available",
copy: "Copy Test",
jar_config: {
title: "The Jar Package Management",
jar_file: "Jar package",
delete_tip: "The deletion takes effect after the service is restarted",
file_exist: "The name already exists in the project",
upload_limit_size: "Upload file size cannot exceed 30MB!",
},
environment: {
name: "Environment Name",
socket: "Socket",
@ -547,6 +556,7 @@ export default {
select_type: "Choose type",
description: "Extract data from the response and store it in variables. Use the variables in subsequent requests.",
regex: "Regex",
multiple_matching: "Multiple matching",
regex_expression: "Regular expression",
json_path_expression: "JSONPath expression",
xpath_expression: "XPath expression",
@ -734,6 +744,10 @@ export default {
status_pass: 'Pass',
status_un_pass: 'UnPass',
cancel_relevance_project: "Disassociating the project will also cancel the associated test cases under the project",
img_loading_fail: "Image failed to load",
pdf_loading_fail: "PDF loading failed",
upload_tip: "Only jpg, jpeg, png, docx, doc, pdf, xlsx files can be uploaded",
attachment: "Attachment",
import: {
import: "Import test case",
case_import: "Import test case",
@ -741,7 +755,7 @@ export default {
click_upload: "Upload",
upload_limit: "Only XLS/XLSX/XMIND files can be uploaded, and no more than 20M",
upload_xmind_format: "Upload files can only be .xmind format",
upload_xmind: "Only xmind files can be uploaded, and no more than 500",
upload_xmind: "Only xmind files can be uploaded, and no more than 800",
upload_limit_count: "Only one file can be uploaded at a time",
upload_limit_format: "Upload files can only be XLS, XLSX format!",
upload_limit_size: "Upload file size cannot exceed 20MB!",

View File

@ -118,6 +118,8 @@ export default {
cannot_be_null: '不能为空',
required: "{0}是必填的",
already_exists: '名称不能重复',
modifier: '修改人',
validate: "校验",
date: {
select_date: '选择日期',
start_date: '开始日期',
@ -440,6 +442,13 @@ export default {
export_config: "导出",
enable_validate_tip: "没有可用请求",
copy: "复制测试",
jar_config: {
title: "jar包管理",
jar_file: "jar包",
delete_tip: "删除需重启服务后生效",
file_exist: "该项目下已存在改jar包",
upload_limit_size: "上传文件大小不能超过 30MB!",
},
environment: {
name: "环境名称",
socket: "环境域名",
@ -547,6 +556,7 @@ export default {
},
extract: {
label: "提取",
multiple_matching: "匹配多条",
select_type: "请选择类型",
description: "从响应结果中提取数据并将其存储在变量中,在后续请求中使用变量。",
regex: "正则",
@ -738,13 +748,17 @@ export default {
status_pass: '通过',
status_un_pass: '未通过',
cancel_relevance_project: "取消项目关联会同时取消该项目下已关联的测试用例",
img_loading_fail: "图片加载失败",
pdf_loading_fail: "PDF加载失败",
upload_tip: "只能上传jpg、jpeg、png、docx、doc、pdf、xlsx文件",
attachment: "附件",
import: {
import: "导入用例",
case_import: "导入测试用例",
download_template: "下载模版",
click_upload: "点击上传",
upload_limit: "只能上传xls/xlsx文件且不超过20M",
upload_xmind: "支持文件类型:.xmind一次至多导入500 条用例",
upload_xmind: "支持文件类型:.xmind一次至多导入800 条用例",
upload_xmind_format: "上传文件只能是 .xmind 格式",
upload_limit_other_size: "上传文件大小不能超过",
upload_limit_count: "一次只能上传一个文件",

View File

@ -118,6 +118,8 @@ export default {
cannot_be_null: '不能為空',
required: "{0}是必填的",
already_exists: '名稱不能重復',
modifier: '修改人',
validate: "校驗",
date: {
select_date: '選擇日期',
start_date: '開始日期',
@ -440,6 +442,13 @@ export default {
export_config: "導出",
enable_validate_tip: "沒有可用請求",
copy: "復制測試",
jar_config: {
title: "jar包管理",
jar_file: "jar包",
delete_tip: "刪除需重啟服務後生效",
file_exist: "該項目下已存在改jar包",
upload_limit_size: "上傳文件大小不能超過 30MB!",
},
environment: {
name: "環境名稱",
socket: "環境域名",
@ -547,6 +556,7 @@ export default {
},
extract: {
label: "提取",
multiple_matching: "匹配多條",
select_type: "請選擇類型",
description: "從響應結果中提取數據並將其存儲在變量中,在後續請求中使用變量。",
regex: "正則",
@ -592,24 +602,24 @@ export default {
dataSource_cannot_be_empty: "SQL請求數據源不能為空",
result_variable: "存儲結果",
variable_names: "按列存儲",
},
tcp: {
server: "服務器名或IP",
port: "端口",
connect: "連接(ms)",
response: "響應(ms)",
re_use_connection: "Re-use connection",
no_delay: "設置無延遲",
close_connection: "關閉連接",
so_linger: "SO LINGER",
eol_byte: "行尾(EOL)字節值",
request: "要發送的文本",
username: "用戶名",
password: "密碼",
login: "登錄設置",
server_cannot_be_empty: "服務器名或IP不能為空",
}
},
tcp: {
server: "服務器名或IP",
port: "端口",
connect: "連接(ms)",
response: "響應(ms)",
re_use_connection: "Re-use connection",
no_delay: "設置無延遲",
close_connection: "關閉連接",
so_linger: "SO LINGER",
eol_byte: "行尾EOL字節值",
request: "要發送的文本",
username: "用戶名",
password: "密碼",
login: "登錄設置",
server_cannot_be_empty: "服務器名或IP不能為空",
},
api_import: {
label: "導入",
title: "接口測試導入",
@ -738,13 +748,17 @@ export default {
status_pass: '通過',
status_un_pass: '未通過',
cancel_relevance_project: "取消項目關聯會同時取消該項目下已關聯的測試用例",
img_loading_fail: "圖片加載失敗",
pdf_loading_fail: "PDF加載失敗",
upload_tip: "只能上傳jpg、jpeg、png、docx、doc、pdf、xlsx文件",
attachment: "附件",
import: {
import: "導入用例",
case_import: "導入測試用例",
download_template: "下載模版",
click_upload: "點擊上傳",
upload_limit: "只能上傳xls/xlsx文件且不超過20M",
upload_xmind: "支持文件類型:.xmind壹次至多導入500 條用例",
upload_xmind: "支持文件類型:.xmind壹次至多導入800 條用例",
upload_xmind_format: "上傳文件只能是 .xmind 格式",
upload_limit_other_size: "上傳文件大小不能超過",
upload_limit_count: "壹次只能上傳壹個文件",
@ -813,7 +827,7 @@ export default {
reviewed_by_me: "待我評審",
creator: "創建人",
done: "已評用例",
result_distribution: "結果分"
result_distribution: "結果分"
},
comment: {
no_comment: "暫無評論",
@ -920,7 +934,7 @@ export default {
close_success: "關閉成功",
preview: "預覽",
please_choose_current_owner: "請選擇處理人",
tapd_current_owner: "Tapd平處理人:",
tapd_current_owner: "Tapd平處理人:",
}
},
test_resource_pool: {