@@ -21,52 +21,59 @@ import org.apache.jmeter.engine.util.CompoundVariable
2121import org.apache.jmeter.samplers.SampleResult
2222import org.apache.jmeter.threads.JMeterContextService
2323import org.apache.jmeter.threads.JMeterVariables
24+ import org.junit.jupiter.api.Assertions.assertEquals
25+ import org.junit.jupiter.api.Assumptions.assumeTrue
26+ import org.junit.jupiter.params.ParameterizedTest
27+ import org.junit.jupiter.params.provider.MethodSource
28+ import java.util.Locale
2429
25- import spock.lang.IgnoreIf
26- import spock.lang.Specification
27- import spock.lang.Unroll
30+ class ChangeCaseTest {
31+ data class ExecuteCase (val input : String , val mode : String , val output : String )
2832
29- @Unroll
30- class ChangeCaseSpec extends Specification {
31-
32- // See https://github.com/apache/jmeter/issues/5723
33- @IgnoreIf({ ' i' .toUpperCase() != ' I' || ' I' .toLowerCase() != ' i' })
34- def " convert '#input' using mode #mode to '#output'" () {
35- given:
36- def changeCase = new ChangeCase ()
37- def jMCtx = JMeterContextService .getContext()
38- def result = new SampleResult ()
39- result.setResponseData(" dummy data" , null )
40- jMCtx.setVariables(new JMeterVariables ())
41- jMCtx.setPreviousResult(result)
42- when :
43- changeCase.setParameters([new CompoundVariable (input), new CompoundVariable (mode)])
44- then:
45- output == changeCase.execute(result, null )
46- where:
47- input | mode | output
48- " simple" | " lower" | " simple"
49- " simple" | " upper" | " SIMPLE"
50- " simple" | " capitalize" | " Simple"
51- " simple" | " " | " SIMPLE"
52- " with space " | " lower" | " with space "
53- " with space " | " upper" | " WITH SPACE "
54- " with space " | " capitalize" | " with space "
55- " #_with-signs." | " lower" | " #_with-signs."
56- " #_with-signs." | " upper" | " #_WITH-SIGNS."
57- " #_with-signs." | " capitalize" | " #_with-signs."
58- " m4u file" | " lower" | " m4u file"
59- " m4u file" | " upper" | " M4U FILE"
60- " m4u file" | " capitalize" | " M4u file"
61- " WITH Ümläuts" | " lower" | " with ümläuts"
62- " WITH Ümläuts" | " upper" | " WITH ÜMLÄUTS"
63- " WITH Ümläuts" | " capitalize" | " WITH Ümläuts"
64- " + - special space" | " lower" | " + - special space"
65- " + - special space" | " upper" | " + - SPECIAL SPACE"
66- " + - special space" | " capitalize" | " + - special space"
67- " " | " lower" | " "
68- " " | " upper" | " "
69- " " | " capitalize" | " "
33+ companion object {
34+ @JvmStatic
35+ fun executeCases () = listOf (
36+ ExecuteCase (" simple" , " lower" , " simple" ),
37+ ExecuteCase (" simple" , " upper" , " SIMPLE" ),
38+ ExecuteCase (" simple" , " capitalize" , " Simple" ),
39+ ExecuteCase (" simple" , " " , " SIMPLE" ),
40+ ExecuteCase (" with space " , " lower" , " with space " ),
41+ ExecuteCase (" with space " , " upper" , " WITH SPACE " ),
42+ ExecuteCase (" with space " , " capitalize" , " with space " ),
43+ ExecuteCase (" #_with-signs." , " lower" , " #_with-signs." ),
44+ ExecuteCase (" #_with-signs." , " upper" , " #_WITH-SIGNS." ),
45+ ExecuteCase (" #_with-signs." , " capitalize" , " #_with-signs." ),
46+ ExecuteCase (" m4u file" , " lower" , " m4u file" ),
47+ ExecuteCase (" m4u file" , " upper" , " M4U FILE" ),
48+ ExecuteCase (" m4u file" , " capitalize" , " M4u file" ),
49+ ExecuteCase (" WITH Ümläuts" , " lower" , " with ümläuts" ),
50+ ExecuteCase (" WITH Ümläuts" , " upper" , " WITH ÜMLÄUTS" ),
51+ ExecuteCase (" WITH Ümläuts" , " capitalize" , " WITH Ümläuts" ),
52+ ExecuteCase (" + - special space" , " lower" , " + - special space" ),
53+ ExecuteCase (" + - special space" , " upper" , " + - SPECIAL SPACE" ),
54+ ExecuteCase (" + - special space" , " capitalize" , " + - special space" ),
55+ ExecuteCase (" " , " lower" , " " ),
56+ ExecuteCase (" " , " upper" , " " ),
57+ ExecuteCase (" " , " capitalize" , " " ),
58+ ).also {
59+ assumeTrue(
60+ " i" .uppercase(Locale .getDefault()) == " I" && " I" .lowercase(Locale .getDefault()) == " i" ,
61+ " ChangeCase does not behave well in tr_TR locale, see https://github.com/apache/jmeter/issues/5723"
62+ )
63+ }
7064 }
7165
66+ @ParameterizedTest
67+ @MethodSource(" executeCases" )
68+ fun changeCase (case : ExecuteCase ) {
69+ val changeCase = ChangeCase ()
70+ val jMCtx = JMeterContextService .getContext()
71+ val result = SampleResult ()
72+ result.setResponseData(" dummy data" , null )
73+ jMCtx.variables = JMeterVariables ()
74+ jMCtx.previousResult = result
75+ changeCase.setParameters(listOf (CompoundVariable (case.input), CompoundVariable (case.mode)))
76+
77+ assertEquals(case.output, changeCase.execute(result, null ))
78+ }
7279}
0 commit comments