You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/12/09 14:31:49 UTC
svn commit: r1817615 - in /jmeter/trunk:
src/functions/org/apache/jmeter/functions/ChangeCase.java
test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
test/src/org/apache/jmeter/functions/TestChangeCase.java
xdocs/usermanual/functions.xml
Author: pmouawad
Date: Sat Dec 9 14:31:49 2017
New Revision: 1817615
URL: http://svn.apache.org/viewvc?rev=1817615&view=rev
Log:
Bug 61759 - New __changeCase function
Remove camel case as per Ori Marko contribution
More edge cases for changeCase function and slight behaviour changes.
This closes #342
Bugzilla Id: 61759
Added:
jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
Modified:
jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java
jmeter/trunk/xdocs/usermanual/functions.xml
Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java?rev=1817615&r1=1817614&r2=1817615&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java Sat Dec 9 14:31:49 2017
@@ -22,7 +22,6 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
-import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.engine.util.CompoundVariable;
@@ -40,7 +39,6 @@ import org.slf4j.LoggerFactory;
* <li>upper case</li>
* <li>lower case</li>
* <li>capitalize</li>
- * <li>camel cases</li>
* <li></li>
* </ul>
*
@@ -48,9 +46,6 @@ import org.slf4j.LoggerFactory;
*
*/
public class ChangeCase extends AbstractFunction {
-
- private static final Pattern NOT_ALPHANUMERIC_REGEX =
- Pattern.compile("[^a-zA-Z]");
private static final Logger LOGGER = LoggerFactory.getLogger(ChangeCase.class);
private static final List<String> DESC = new LinkedList<>();
private static final String KEY = "__changeCase";
@@ -96,12 +91,6 @@ public class ChangeCase extends Abstract
case CAPITALIZE:
targetString = StringUtils.capitalize(originalString);
break;
- case LOWER_CAMEL_CASE:
- targetString = camel(originalString, false);
- break;
- case UPPER_CAMEL_CASE:
- targetString = camel(originalString, true);
- break;
default:
// default not doing nothing to string
}
@@ -126,21 +115,6 @@ public class ChangeCase extends Abstract
public List<String> getArgumentDesc() {
return DESC;
}
-
- private static String camel(String str, boolean isFirstCapitalized) {
- StringBuilder builder = new StringBuilder(str.length());
- String[] tokens = NOT_ALPHANUMERIC_REGEX.split(str);
- for (int i = 0; i < tokens.length; i++) {
- String lowerCased = StringUtils.lowerCase(tokens[i]);
- if(i == 0) {
- builder.append(isFirstCapitalized ? StringUtils.capitalize(lowerCased):
- lowerCased);
- } else {
- builder.append(StringUtils.capitalize(lowerCased));
- }
- }
- return builder.toString();
- }
/**
* ChangeCase Modes
@@ -149,8 +123,7 @@ public class ChangeCase extends Abstract
*
*/
public enum ChangeCaseMode {
- UPPER("UPPER"), LOWER("LOWER"), CAPITALIZE("CAPITALIZE"),
- UPPER_CAMEL_CASE("UPPER_CAMEL_CASE"), LOWER_CAMEL_CASE("LOWER_CAMEL_CASE");
+ UPPER("UPPER"), LOWER("LOWER"), CAPITALIZE("CAPITALIZE");
private String mode;
private ChangeCaseMode(String mode) {
Added: jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy?rev=1817615&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/ChangeCaseSpec.groovy Sat Dec 9 14:31:49 2017
@@ -0,0 +1,69 @@
+/*
+ * 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.functions
+
+import org.apache.jmeter.engine.util.CompoundVariable;
+import org.apache.jmeter.samplers.SampleResult;
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.JMeterVariables;
+
+import spock.lang.Specification
+import spock.lang.Unroll
+
+@Unroll
+class ChangeCaseSpec extends Specification {
+
+ def "convert '#input' using mode #mode to '#output'"() {
+ given:
+ def changeCase = new ChangeCase();
+ def jMCtx = JMeterContextService.getContext();
+ def result = new SampleResult();
+ result.setResponseData("dummy data", null);
+ jMCtx.setVariables(new JMeterVariables());
+ jMCtx.setPreviousResult(result);
+ when:
+ changeCase.setParameters([new CompoundVariable(input), new CompoundVariable(mode)]);
+ then:
+ output == changeCase.execute(result, null)
+ where:
+ input | mode | output
+ "simple" | "lower" | "simple"
+ "simple" | "upper" | "SIMPLE"
+ "simple" | "capitalize" | "Simple"
+ "simple" | "" | "SIMPLE"
+ " with space " | "lower" | " with space "
+ " with space " | "upper" | " WITH SPACE "
+ " with space " | "capitalize" | " with space "
+ "#_with-signs." | "lower" | "#_with-signs."
+ "#_with-signs." | "upper" | "#_WITH-SIGNS."
+ "#_with-signs." | "capitalize" | "#_with-signs."
+ "m4u file" | "lower" | "m4u file"
+ "m4u file" | "upper" | "M4U FILE"
+ "m4u file" | "capitalize" | "M4u file"
+ "WITH Ãmläuts" | "lower" | "with ümläuts"
+ "WITH Ãmläuts" | "upper" | "WITH ÃMLÃUTS"
+ "WITH Ãmläuts" | "capitalize" | "WITH Ãmläuts"
+ "+ - special space" | "lower" | "+ - special space"
+ "+ - special space" | "upper" | "+ - SPECIAL SPACE"
+ "+ - special space" | "capitalize" | "+ - special space"
+ " " | "lower" | " "
+ " " | "upper" | " "
+ " " | "capitalize" | " "
+ }
+
+}
\ No newline at end of file
Modified: jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java?rev=1817615&r1=1817614&r2=1817615&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java Sat Dec 9 14:31:49 2017
@@ -90,32 +90,11 @@ public class TestChangeCase extends JMet
}
@Test
- public void testChangeCaseCamelCase() throws Exception {
- String returnValue = execute("ab-CD eF", "UPPER_CAMEL_CASE");
- assertEquals("AbCdEf", returnValue);
- }
-
- @Test
public void testChangeCaseCapitalize() throws Exception {
String returnValue = execute("ab-CD eF", "CAPITALIZE");
assertEquals("Ab-CD eF", returnValue);
}
- @Test
- public void testChangeCaseCamelCaseFirstLower() throws Exception {
- String returnValue = execute("ab-CD eF", "LOWER_CAMEL_CASE");
- assertEquals("abCdEf", returnValue);
- }
-
- @Test
- public void testChangeCaseCamelCaseFirstLowerWithFirstUpperCaseChar() throws Exception {
- String returnValue = execute("Ab-CD eF", "lower_CAMEL_CASE");
- assertEquals("abCdEf", returnValue);
-
- returnValue = execute(" zadad", "lower_CAMEL_CASE");
- assertEquals("Zadad", returnValue);
- }
-
@Test(expected = InvalidVariableException.class)
public void testChangeCaseError() throws Exception {
changeCase.setParameters(new LinkedList<>());
Modified: jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1817615&r1=1817614&r2=1817615&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jmeter/trunk/xdocs/usermanual/functions.xml Sat Dec 9 14:31:49 2017
@@ -1647,15 +1647,13 @@ becomes:
<property name="String to change case" required="Yes">The String
which case will be changed</property>
<property name="change case mode" required="Yes">
- The mode to be used to change case, for example for ab-CD eF:
+ The mode to be used to change case, for example for <code>ab-CD eF</code>:
<ul>
<li><code>UPPER</code> result as AB-CD EF</li>
<li><code>LOWER</code> result as ab-cd ed</li>
<li><code>CAPITALIZE</code> result as Ab-CD eF</li>
- <li><code>UPPER_CAMEL_CASE</code>result as AbCdEf</li>
- <li><code>LOWER_CAMEL_CASE</code>result as abCdEf</li>
</ul>
- <note>mode is case insensitive</note>
+ <note><code>change case mode</code> is case insensitive</note>
</property>
<property name="Name of variable" required="No">The name of the variable to set.</property>
</properties>