Skip to content

Commit 22f7920

Browse files
committed
chore: rework httpRequestDefaults
1 parent 1decb14 commit 22f7920

File tree

2 files changed

+80
-12
lines changed

2 files changed

+80
-12
lines changed

src/protocol/http/src/test/kotlin/org/apache/jmeter/protocol/http/sampler/HttpSamplerDisableArgumentsTest.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ import com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor
2929
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
3030
import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo
3131
import com.github.tomakehurst.wiremock.junit5.WireMockTest
32-
import org.apache.jmeter.config.ConfigTestElement
32+
import org.apache.jmeter.config.Argument
3333
import org.apache.jmeter.junit.JMeterTestCase
34+
import org.apache.jmeter.protocol.http.control.arguments
35+
import org.apache.jmeter.protocol.http.control.httpRequestDefaults
36+
import org.apache.jmeter.protocol.http.util.HTTPArgument
3437
import org.apache.jmeter.test.assertions.executePlanAndCollectEvents
35-
import org.apache.jmeter.treebuilder.oneRequest
3638
import org.apache.jmeter.treebuilder.TreeBuilder
39+
import org.apache.jmeter.treebuilder.oneRequest
3740
import org.junit.jupiter.params.ParameterizedTest
3841
import org.junit.jupiter.params.provider.ValueSource
3942
import kotlin.time.Duration.Companion.seconds
@@ -115,22 +118,25 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
115118

116119
executePlanAndCollectEvents(10.seconds) {
117120
oneRequest {
118-
httpRequest {
119-
ConfigTestElement::class {
120-
addArgument("param0", "value0")
121-
arguments.getArgument(0).isEnabled = false
122-
addArgument("param4", "value4")
123-
props {
124-
// guiClass is needed for org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.applies
125-
it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui"
126-
}
121+
httpRequestDefaults {
122+
arguments {
123+
addArgument(
124+
HTTPArgument("param0", "value0").apply {
125+
isEnabled = false
126+
}
127+
)
128+
addArgument(
129+
HTTPArgument("param4", "value4")
130+
)
127131
}
132+
}
133+
httpRequest {
128134
method = "POST"
129135
doMultipart = true
130136
implementation = httpImplementation
131137
port = server.httpPort
132138
addArgument("param1", "value1")
133-
arguments.getArgument(1).isEnabled = false
139+
arguments.getArgument(0).isEnabled = false
134140
addArgument("param2", "value2")
135141
}
136142
}
@@ -142,6 +148,9 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
142148
.withRequestBodyPart(
143149
aMultipart("param2").withBody(equalTo("value2")).build()
144150
)
151+
.withRequestBodyPart(
152+
aMultipart("param4").withBody(equalTo("value4")).build()
153+
)
145154
.withRequestBody(
146155
httpImplementation,
147156
"""
@@ -151,6 +160,12 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
151160
Content-Transfer-Encoding: 8bit
152161
153162
value2
163+
-----------------------------7d159c1302d0y0
164+
Content-Disposition: form-data; name="param4"
165+
Content-Type: text/plain; charset=UTF-8
166+
Content-Transfer-Encoding: 8bit
167+
168+
value4
154169
-----------------------------7d159c1302d0y0--
155170
156171
""".trimIndent()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package org.apache.jmeter.protocol.http.control
19+
20+
import org.apache.jmeter.config.Arguments
21+
import org.apache.jmeter.config.ConfigTestElement
22+
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerBaseSchema
23+
import org.apache.jmeter.testelement.property.TestElementProperty
24+
import org.apache.jmeter.treebuilder.Action
25+
import org.apache.jmeter.treebuilder.TreeBuilder
26+
27+
fun TreeBuilder.httpRequestDefaults(configure: Action<ConfigTestElement> = Action {}) {
28+
ConfigTestElement::class {
29+
props {
30+
it[name] = "HTTP Request Defaults"
31+
it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui"
32+
}
33+
setProperty(
34+
TestElementProperty(
35+
HTTPSamplerBaseSchema.arguments.name,
36+
Arguments().apply {
37+
props {
38+
it[guiClass] = "org.apache.jmeter.protocol.http.gui.HTTPArgumentsPanel"
39+
it[testClass] = "org.apache.jmeter.config.Arguments"
40+
}
41+
}
42+
)
43+
)
44+
configure(this)
45+
}
46+
}
47+
48+
val ConfigTestElement.arguments: Arguments
49+
get() = getProperty(HTTPSamplerBaseSchema.arguments.name) as Arguments
50+
51+
fun ConfigTestElement.arguments(configure: Action<Arguments> = Action {}) {
52+
configure((getProperty(HTTPSamplerBaseSchema.arguments.name) as TestElementProperty).element as Arguments)
53+
}

0 commit comments

Comments
 (0)