Skip to content

Commit 1decb14

Browse files
committed
test: move TreeBuilder.oneRequest to core testFixtures
1 parent 229f673 commit 1decb14

File tree

5 files changed

+50
-60
lines changed

5 files changed

+50
-60
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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.treebuilder
19+
20+
import org.apache.jmeter.control.LoopController
21+
import org.apache.jmeter.threads.ThreadGroup
22+
23+
fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) {
24+
ThreadGroup::class {
25+
numThreads = 1
26+
rampUp = 0
27+
setSamplerController(
28+
LoopController().apply {
29+
loops = 1
30+
}
31+
)
32+
body()
33+
}
34+
}

src/functions/src/test/kotlin/org/apache/jmeter/timers/ConstantThroughputTimerKtTest.kt

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,15 @@
1717

1818
package org.apache.jmeter.timers
1919

20-
import org.apache.jmeter.control.LoopController
2120
import org.apache.jmeter.junit.JMeterTestCase
2221
import org.apache.jmeter.sampler.DebugSampler
2322
import org.apache.jmeter.test.assertions.executePlanAndCollectEvents
24-
import org.apache.jmeter.threads.ThreadGroup
25-
import org.apache.jmeter.treebuilder.TreeBuilder
23+
import org.apache.jmeter.treebuilder.oneRequest
2624
import org.junit.jupiter.api.Assertions.assertEquals
2725
import org.junit.jupiter.api.Test
2826
import kotlin.time.Duration.Companion.seconds
2927

3028
class ConstantThroughputTimerKtTest : JMeterTestCase() {
31-
fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) {
32-
ThreadGroup::class {
33-
numThreads = 1
34-
rampUp = 0
35-
setSamplerController(
36-
LoopController().apply {
37-
loops = 1
38-
}
39-
)
40-
body()
41-
}
42-
}
43-
4429
@Test
4530
fun `throughput as variable`() {
4631
val events = executePlanAndCollectEvents(5.seconds) {

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

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ 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
3233
import org.apache.jmeter.junit.JMeterTestCase
3334
import org.apache.jmeter.test.assertions.executePlanAndCollectEvents
35+
import org.apache.jmeter.treebuilder.oneRequest
3436
import org.apache.jmeter.treebuilder.TreeBuilder
3537
import org.junit.jupiter.params.ParameterizedTest
3638
import org.junit.jupiter.params.provider.ValueSource
@@ -39,8 +41,8 @@ import kotlin.time.Duration.Companion.seconds
3941
@WireMockTest
4042
class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
4143

42-
fun TreeBuilder.httpGet(body: HTTPSamplerProxy.() -> Unit) {
43-
org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class {
44+
fun TreeBuilder.httpRequest(body: HTTPSamplerProxy.() -> Unit) {
45+
HTTPSamplerProxy::class {
4446
name = "Test disabled params"
4547
method = "GET"
4648
domain = "localhost"
@@ -49,27 +51,6 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
4951
}
5052
}
5153

52-
fun TreeBuilder.httpPut(body: HTTPSamplerProxy.() -> Unit) {
53-
org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class {
54-
name = "Test disabled params"
55-
method = "PUT"
56-
domain = "localhost"
57-
path = "/test"
58-
body()
59-
}
60-
}
61-
62-
fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) {
63-
org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class {
64-
name = "Test disabled params"
65-
method = "POST"
66-
domain = "localhost"
67-
path = "/test"
68-
doMultipart = true
69-
body()
70-
}
71-
}
72-
7354
@ParameterizedTest
7455
@ValueSource(strings = ["Java", "HttpClient4"])
7556
fun `GET disable param1 should send enabled param2`(httpImplementation: String, server: WireMockRuntimeInfo) {
@@ -79,7 +60,8 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
7960

8061
executePlanAndCollectEvents(10.seconds) {
8162
oneRequest {
82-
httpGet {
63+
httpRequest {
64+
method = "GET"
8365
implementation = httpImplementation
8466
port = server.httpPort
8567
addArgument("param1", "value1")
@@ -104,7 +86,8 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
10486

10587
executePlanAndCollectEvents(1000.seconds) {
10688
oneRequest {
107-
httpPut {
89+
httpRequest {
90+
method = "PUT"
10891
implementation = httpImplementation
10992
port = server.httpPort
11093
postBodyRaw = true
@@ -132,15 +115,18 @@ class HttpSamplerDisableArgumentsTest : JMeterTestCase() {
132115

133116
executePlanAndCollectEvents(10.seconds) {
134117
oneRequest {
135-
httpPost {
136-
org.apache.jmeter.config.ConfigTestElement::class {
118+
httpRequest {
119+
ConfigTestElement::class {
137120
addArgument("param0", "value0")
138121
arguments.getArgument(0).isEnabled = false
122+
addArgument("param4", "value4")
139123
props {
140124
// guiClass is needed for org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.applies
141125
it[guiClass] = "org.apache.jmeter.protocol.http.config.gui.HttpDefaultsGui"
142126
}
143127
}
128+
method = "POST"
129+
doMultipart = true
144130
implementation = httpImplementation
145131
port = server.httpPort
146132
addArgument("param1", "value1")

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.apache.jmeter.protocol.http.control.Header
3131
import org.apache.jmeter.protocol.http.util.HTTPFileArg
3232
import org.apache.jmeter.test.assertions.executePlanAndCollectEvents
3333
import org.apache.jmeter.treebuilder.TreeBuilder
34+
import org.apache.jmeter.treebuilder.oneRequest
3435
import org.junit.jupiter.api.Assumptions.assumeTrue
3536
import org.junit.jupiter.api.io.TempDir
3637
import org.junit.jupiter.params.ParameterizedTest
@@ -48,7 +49,7 @@ class HttpSamplerTest : JMeterTestCase() {
4849
lateinit var dir: Path
4950

5051
fun TreeBuilder.httpPost(body: HTTPSamplerProxy.() -> Unit) {
51-
org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy::class {
52+
HTTPSamplerProxy::class {
5253
name = "Upload file"
5354
method = "POST"
5455
domain = "localhost"

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ package org.apache.jmeter.protocol.http.sampler
2020
import com.github.tomakehurst.wiremock.client.WireMock.equalTo
2121
import com.github.tomakehurst.wiremock.client.WireMock.matching
2222
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder
23-
import org.apache.jmeter.control.LoopController
24-
import org.apache.jmeter.threads.ThreadGroup
25-
import org.apache.jmeter.treebuilder.TreeBuilder
26-
27-
fun TreeBuilder.oneRequest(body: ThreadGroup.() -> Unit) {
28-
ThreadGroup::class {
29-
numThreads = 1
30-
rampUp = 0
31-
setSamplerController(
32-
LoopController().apply {
33-
loops = 1
34-
}
35-
)
36-
body()
37-
}
38-
}
3923

4024
fun RequestPatternBuilder.withRequestBody(
4125
httpImplementation: String,

0 commit comments

Comments
 (0)