This commit is contained in:
shiziyuan9527 2020-08-18 14:34:43 +08:00
commit ab07bc3de8
9 changed files with 88 additions and 10 deletions

View File

@ -140,11 +140,6 @@
</dependency> </dependency>
<!-- jmeter --> <!-- jmeter -->
<!-- <dependency>-->
<!-- <groupId>org.apache.jmeter</groupId>-->
<!-- <artifactId>ApacheJMeter_core</artifactId>-->
<!-- <version>${jmeter.version}</version>-->
<!-- </dependency>-->
<dependency> <dependency>
<groupId>org.apache.jmeter</groupId> <groupId>org.apache.jmeter</groupId>

View File

@ -0,0 +1,10 @@
package io.metersphere.api.dto.scenario.processor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class BeanShellPostProcessor extends BeanShellProcessor {
}

View File

@ -0,0 +1,10 @@
package io.metersphere.api.dto.scenario.processor;
import lombok.Data;
import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true)
@Data
public class BeanShellPreProcessor extends BeanShellProcessor {
}

View File

@ -0,0 +1,8 @@
package io.metersphere.api.dto.scenario.processor;
import lombok.Data;
@Data
public class BeanShellProcessor {
private String script;
}

View File

@ -6,6 +6,8 @@ import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.assertions.Assertions; import io.metersphere.api.dto.scenario.assertions.Assertions;
import io.metersphere.api.dto.scenario.extract.Extract; import io.metersphere.api.dto.scenario.extract.Extract;
import io.metersphere.api.dto.scenario.processor.BeanShellPostProcessor;
import io.metersphere.api.dto.scenario.processor.BeanShellPreProcessor;
import lombok.Data; import lombok.Data;
import java.util.List; import java.util.List;
@ -35,4 +37,8 @@ public class HttpRequest implements Request {
private Assertions assertions; private Assertions assertions;
@JSONField(ordinal = 10) @JSONField(ordinal = 10)
private Extract extract; private Extract extract;
@JSONField(ordinal = 11)
private BeanShellPreProcessor beanShellPreProcessor;
@JSONField(ordinal = 12)
private BeanShellPostProcessor beanShellPostProcessor;
} }

@ -1 +1 @@
Subproject commit 8de0d4e47675bd1a5a8ea4c99e1a2b76e53ebc08 Subproject commit b86032cbbda9a9e6028308aa95a887cff2192f1c

View File

@ -23,9 +23,6 @@
}, },
beanShellProcessor: { beanShellProcessor: {
type: Object, type: Object,
default() {
return {}
}
} }
}, },
} }

View File

@ -405,12 +405,40 @@ export class ResponseHeadersAssertion extends ResponseAssertion {
} }
} }
export class BeanShellProcessor extends DefaultTestElement {
constructor(tag, guiclass, testclass, testname, processor) {
super(tag, guiclass, testclass, testname);
this.processor = processor || {};
this.boolProp('resetInterpreter', false);
this.stringProp('parameters');
this.stringProp('filename');
this.stringProp('script', processor.script);
}
}
export class BeanShellPreProcessor extends BeanShellProcessor {
constructor(testName, processor) {
super('BeanShellPreProcessor', 'TestBeanGUI', 'BeanShellPreProcessor', testName, processor)
}
}
export class BeanShellPostProcessor extends BeanShellProcessor {
constructor(testName, script) {
let processor = {
script: script,
};
super('BeanShellPostProcessor', 'TestBeanGUI', 'BeanShellPostProcessor', testName, processor)
}
}
export class HeaderManager extends DefaultTestElement { export class HeaderManager extends DefaultTestElement {
constructor(testName, headers) { constructor(testName, headers) {
super('HeaderManager', 'HeaderPanel', 'HeaderManager', testName); super('HeaderManager', 'HeaderPanel', 'HeaderManager', testName);
this.headers = headers || []; this.headers = headers || [];
let collectionProp = this.collectionProp('HeaderManager.headers'); let collectionProp = this.collectionProp('HeaderManager.headers');
this.headers.forEach(header => { this.headers.forEach(header => {
let elementProp = collectionProp.elementProp('', 'Header'); let elementProp = collectionProp.elementProp('', 'Header');
elementProp.stringProp('Header.name', header.name); elementProp.stringProp('Header.name', header.name);

View File

@ -1,5 +1,5 @@
import { import {
Arguments, Arguments, BeanShellPreProcessor,
CookieManager, CookieManager,
DubboSample, DubboSample,
DurationAssertion, DurationAssertion,
@ -302,6 +302,8 @@ export class HttpRequest extends Request {
this.environment = undefined; this.environment = undefined;
this.useEnvironment = undefined; this.useEnvironment = undefined;
this.debugReport = undefined; this.debugReport = undefined;
this.beanShellPreProcessor = undefined;
this.beanShellPostProcessor = undefined;
this.set(options); this.set(options);
this.sets({parameters: KeyValue, headers: KeyValue}, options); this.sets({parameters: KeyValue, headers: KeyValue}, options);
@ -313,6 +315,8 @@ export class HttpRequest extends Request {
options.body = new Body(options.body); options.body = new Body(options.body);
options.assertions = new Assertions(options.assertions); options.assertions = new Assertions(options.assertions);
options.extract = new Extract(options.extract); options.extract = new Extract(options.extract);
options.beanShellPreProcessor = new BeanShellProcessor(options.beanShellPreProcessor);
options.beanShellPostProcessor = new BeanShellProcessor(options.beanShellPostProcessor);
return options; return options;
} }
@ -352,6 +356,7 @@ export class HttpRequest extends Request {
showMethod() { showMethod() {
return this.method.toUpperCase(); return this.method.toUpperCase();
} }
} }
export class DubboRequest extends Request { export class DubboRequest extends Request {
@ -564,6 +569,14 @@ export class AssertionType extends BaseConfig {
} }
} }
export class BeanShellProcessor extends BaseConfig {
constructor(options) {
super();
this.script = undefined;
this.set(options);
}
}
export class Text extends AssertionType { export class Text extends AssertionType {
constructor(options) { constructor(options) {
super(ASSERTION_TYPE.TEXT); super(ASSERTION_TYPE.TEXT);
@ -818,6 +831,7 @@ class JMXGenerator {
} else { } else {
this.addRequestBody(sampler, request); this.addRequestBody(sampler, request);
} }
this.addBeanShellProcessor(sampler, request);
} }
this.addRequestAssertion(sampler, request); this.addRequestAssertion(sampler, request);
@ -886,6 +900,16 @@ class JMXGenerator {
} }
} }
addBeanShellProcessor(httpSamplerProxy, request) {
let name = request.name;
if (request.beanShellPreProcessor && request.beanShellPreProcessor.script) {
httpSamplerProxy.put(new BeanShellPreProcessor(name, request.beanShellPreProcessor));
}
if (request.beanShellPostProcessor && request.beanShellPostProcessor.script) {
httpSamplerProxy.put(new BeanShellPreProcessor(name, request.beanShellPostProcessor));
}
}
addBodyFormat(request) { addBodyFormat(request) {
let bodyFormat = request.body.format; let bodyFormat = request.body.format;
if (bodyFormat) { if (bodyFormat) {