From commits-return-8223-apmail-jmeter-commits-archive=jmeter.apache.org@jmeter.apache.org Tue Nov 21 20:59:34 2017 Return-Path: X-Original-To: apmail-jmeter-commits-archive@minotaur.apache.org Delivered-To: apmail-jmeter-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3796310E96 for ; Tue, 21 Nov 2017 20:59:34 +0000 (UTC) Received: (qmail 50735 invoked by uid 500); 21 Nov 2017 20:59:34 -0000 Delivered-To: apmail-jmeter-commits-archive@jmeter.apache.org Received: (qmail 50706 invoked by uid 500); 21 Nov 2017 20:59:33 -0000 Mailing-List: contact commits-help@jmeter.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jmeter.apache.org Delivered-To: mailing list commits@jmeter.apache.org Received: (qmail 50697 invoked by uid 99); 21 Nov 2017 20:59:33 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd3-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Nov 2017 20:59:33 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd3-us-west.apache.org (ASF Mail Server at spamd3-us-west.apache.org) with ESMTP id E1BCF180710 for ; Tue, 21 Nov 2017 20:59:32 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd3-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.799 X-Spam-Level: * X-Spam-Status: No, score=1.799 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd3-us-west.apache.org [10.40.0.10]) (amavisd-new, port 10024) with ESMTP id GF1Y8j7v26qT for ; Tue, 21 Nov 2017 20:59:28 +0000 (UTC) Received: from internetallee.de (internetallee.de [81.169.162.220]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 339785FD33 for ; Tue, 21 Nov 2017 20:59:28 +0000 (UTC) Received: from [192.168.178.20] (p5DE8F9C9.dip0.t-ipconnect.de [93.232.249.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by internetallee.de (Postfix) with ESMTPSA id D434B20A0663 for ; Tue, 21 Nov 2017 21:59:19 +0100 (CET) Subject: Re: svn commit: r1815838 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/ChangeCase.java test/src/org/apache/jmeter/functions/TestChangeCase.java xdocs/changes.xml xdocs/usermanual/functions.xml To: commits@jmeter.apache.org References: <20171120195053.BE90E3A0098@svn01-us-west.apache.org> From: Felix Schumacher Message-ID: <85828298-b700-fc81-84bc-dfcf5e8c5e82@internetallee.de> Date: Tue, 21 Nov 2017 21:59:18 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171120195053.BE90E3A0098@svn01-us-west.apache.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Am 20.11.2017 um 20:50 schrieb pmouawad@apache.org: > Author: pmouawad > Date: Mon Nov 20 19:50:51 2017 > New Revision: 1815838 > > URL: http://svn.apache.org/viewvc?rev=1815838&view=rev > Log: > Bug 61759 - New __changeCase function > Contributed by Orimarko > Bugzilla Id: 61759 > > Added: > jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java (with props) > jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java (with props) > Modified: > jmeter/trunk/xdocs/changes.xml > jmeter/trunk/xdocs/usermanual/functions.xml > > Added: 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=1815838&view=auto > ============================================================================== > --- jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java (added) > +++ jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java Mon Nov 20 19:50:51 2017 > @@ -0,0 +1,175 @@ > +/* > + * 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 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; > +import org.apache.jmeter.samplers.SampleResult; > +import org.apache.jmeter.samplers.Sampler; > +import org.apache.jmeter.util.JMeterUtils; > +import org.slf4j.Logger; > +import org.slf4j.LoggerFactory; > + > +/** > + * Change Case Function > + * > + * Support String manipulations of: > + *
    > + *
  • upper case
  • > + *
  • lower case
  • > + *
  • capitalize
  • > + *
  • camel cases
  • > + *
  • > + * > + * > + * @since 4.0 > + * > + */ > +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 DESC = new LinkedList<>(); > + private static final String KEY = "__changeCase"; > + > + private static final int MIN_PARAMETER_COUNT = 1; > + private static final int MAX_PARAMETER_COUNT = 3; > + > + static { > + DESC.add(JMeterUtils.getResString("change_case_string")); > + DESC.add(JMeterUtils.getResString("change_case_mode")); > + DESC.add(JMeterUtils.getResString("function_name_paropt")); > + } > + > + private CompoundVariable[] values; > + > + @Override > + public String execute(SampleResult previousResult, Sampler currentSampler) throws InvalidVariableException { > + String originalString = values[0].execute(); > + String mode = ChangeCaseMode.UPPER.getName(); // default > + if (values.length > 1) { > + mode = values[1].execute(); > + } > + String targetString = changeCase(originalString, mode); > + addVariableValue(targetString, values, 2); > + return targetString; > + } > + > + protected String changeCase(String originalString, String mode) { > + String targetString = originalString; > + // mode is case insensitive, allow upper for example > + ChangeCaseMode changeCaseMode = ChangeCaseMode.typeOf(mode.toUpperCase()); > + if (changeCaseMode != null) { > + switch (changeCaseMode) { > + case UPPER: > + targetString = StringUtils.upperCase(originalString); > + break; > + case LOWER: > + targetString = StringUtils.lowerCase(originalString); > + break; > + case CAPITALIZE: > + targetString = StringUtils.capitalize(originalString); > + break; > + case CAMEL_CASE: > + targetString = camel(originalString, false); > + break; > + case CAMEL_CASE_FIRST_LOWER: > + targetString = camel(originalString, true); > + break; > + default: > + // default not doing nothing to string > + } > + } else { > + LOGGER.error("Unknown mode {}, returning {} unchanged", mode, targetString); > + } > + return targetString; > + } > + > + @Override > + public void setParameters(Collection parameters) throws InvalidVariableException { > + checkParameterCount(parameters, MIN_PARAMETER_COUNT, MAX_PARAMETER_COUNT); > + values = parameters.toArray(new CompoundVariable[parameters.size()]); > + } > + > + @Override > + public String getReferenceKey() { > + return KEY; > + } > + > + @Override > + public List 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++) { > + if(i == 0) { > + builder.append(isFirstCapitalized ? tokens[0]: > + StringUtils.capitalize(tokens[i])); > + } else { > + builder.append(StringUtils.capitalize(tokens[i])); > + } > + } > + return builder.toString(); > + } > + > + /** > + * ChangeCase Modes > + * > + * Modes for different cases > + * > + */ > + public enum ChangeCaseMode { > + UPPER("UPPER"), LOWER("LOWER"), CAPITALIZE("CAPITALIZE"), CAMEL_CASE("CAMEL_CASE"), CAMEL_CASE_FIRST_LOWER( > + "CAMEL_CASE_FIRST_LOWER"); > + private String mode; > + > + private ChangeCaseMode(String mode) { > + this.mode = mode; > + } > + > + public String getName() { > + return this.mode; > + } > + > + /** > + * Get ChangeCaseMode by mode > + * > + * @param mode > + * @return relevant ChangeCaseMode > + */ > + public static ChangeCaseMode typeOf(String mode) { > + EnumSet allOf = EnumSet.allOf(ChangeCaseMode.class); > + for (ChangeCaseMode zs : allOf) { > + if (zs.getName().equals(mode)) > + return zs; > + } > + return null; > + } > + } > +} > > Propchange: jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java > ------------------------------------------------------------------------------ > svn:eol-style = native > > Propchange: jmeter/trunk/src/functions/org/apache/jmeter/functions/ChangeCase.java > ------------------------------------------------------------------------------ > svn:mime-type = text/plain > > Added: 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=1815838&view=auto > ============================================================================== > --- jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java (added) > +++ jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java Mon Nov 20 19:50:51 2017 > @@ -0,0 +1,138 @@ > +/* > + * 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 static org.junit.Assert.assertEquals; > + > +import java.util.Collection; > +import java.util.LinkedList; > + > +import org.apache.jmeter.engine.util.CompoundVariable; > +import org.apache.jmeter.junit.JMeterTestCase; > +import org.apache.jmeter.samplers.SampleResult; > +import org.apache.jmeter.threads.JMeterContext; > +import org.apache.jmeter.threads.JMeterContextService; > +import org.apache.jmeter.threads.JMeterVariables; > +import org.junit.Before; > +import org.junit.Test; > + > +/** > + * Test{@link ChangeCase} ChangeCase > + * > + * @see ChangeCase > + * @since 4.0 > + */ > +public class TestChangeCase extends JMeterTestCase { > + > + protected AbstractFunction changeCase; > + private SampleResult result; > + > + private Collection params; > + > + private JMeterVariables vars; > + > + private JMeterContext jmctx; > + > + @Before > + public void setUp() { > + changeCase = new ChangeCase(); > + result = new SampleResult(); > + jmctx = JMeterContextService.getContext(); > + String data = "dummy data"; > + result.setResponseData(data, null); > + vars = new JMeterVariables(); > + jmctx.setVariables(vars); > + jmctx.setPreviousResult(result); > + params = new LinkedList<>(); > + } > + > + @Test > + public void testParameterCountIsPropDefined() throws Exception { > + checkInvalidParameterCounts(changeCase, 1, 3); > + } > + > + @Test > + public void testChangeCase() throws Exception { > + params.add(new CompoundVariable("myUpperTest")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("MYUPPERTEST", returnValue); > + } > + > + @Test > + public void testChangeCaseLower() throws Exception { > + params.add(new CompoundVariable("myUpperTest")); > + params.add(new CompoundVariable("LOWER")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("myuppertest", returnValue); > + } > + > + @Test > + public void testChangeCaseWrongMode() throws Exception { > + params.add(new CompoundVariable("myUpperTest")); > + params.add(new CompoundVariable("Wrong")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("myUpperTest", returnValue); > + } > + > + @Test > + public void testChangeCaseCamelCase() throws Exception { > + params.add(new CompoundVariable("ab-CD eF")); > + params.add(new CompoundVariable("CAMEL_CASE")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("AbCDEF", returnValue); > + } > + > + @Test > + public void testChangeCaseCapitalize() throws Exception { > + params.add(new CompoundVariable("ab-CD eF")); > + params.add(new CompoundVariable("CAPITALIZE")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("Ab-CD eF", returnValue); > + } > + > + @Test > + public void testChangeCaseCamelCaseFirstLower() throws Exception { > + params.add(new CompoundVariable("ab-CD eF")); > + params.add(new CompoundVariable("camel_CASE_FIRST_LOWER")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("abCDEF", returnValue); > + } > + > + @Test(expected=InvalidVariableException.class) > + public void testChangeCaseError() throws Exception { > + changeCase.setParameters(params); > + changeCase.execute(result, null); > + } > + > + @Test > + public void testChangeCaseWrongModeIgnore() throws Exception { > + params.add(new CompoundVariable("ab-CD eF")); > + params.add(new CompoundVariable("Wrong")); > + changeCase.setParameters(params); > + String returnValue = changeCase.execute(result, null); > + assertEquals("ab-CD eF", returnValue); > + } > + > +} > > Propchange: jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java > ------------------------------------------------------------------------------ > svn:eol-style = native > > Propchange: jmeter/trunk/test/src/org/apache/jmeter/functions/TestChangeCase.java > ------------------------------------------------------------------------------ > svn:mime-type = text/plain > > Modified: jmeter/trunk/xdocs/changes.xml > URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1815838&r1=1815837&r2=1815838&view=diff > ============================================================================== > --- jmeter/trunk/xdocs/changes.xml [utf-8] (original) > +++ jmeter/trunk/xdocs/changes.xml [utf-8] Mon Nov 20 19:50:51 2017 > @@ -136,6 +136,7 @@ Summary >
  • 61724Add __digest function to provide computing of Hashes (SHA-XXX, MDX). Based on a contribution by orimarko at gmail.com
  • >
  • 61735Add __dateTimeConvert function to provide date formats conversions. Based on a contribution by orimarko at gmail.com
  • >
  • 61760Add __isPropDefined and __isVarDefined functions to know if property or variable exist. Contributed by orimarko at gmail.com
  • > +
  • 61759Add __changeCase function to change different cases of a string. Based on a contribution by orimarko at gmail.com
  • >
> >

I18N

> > Modified: jmeter/trunk/xdocs/usermanual/functions.xml > URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/functions.xml?rev=1815838&r1=1815837&r2=1815838&view=diff > ============================================================================== > --- jmeter/trunk/xdocs/usermanual/functions.xml (original) > +++ jmeter/trunk/xdocs/usermanual/functions.xml Mon Nov 20 19:50:51 2017 > @@ -143,13 +143,14 @@ Alternatively, just use / i > Variables evalVarevaluate an expression stored in a variable2.3.1 > Properties isVarDefined Test if a variable exists4.0 > Variables Vevaluate a variable name2.3RC3 > - String regexFunctionparse previous response using a regular expression1.X > - String escapeOroRegexpCharsquote meta chars used by ORO regular expression2.9 > String chargenerate Unicode char values from a list of numbers2.3.3 > - String unescapeProcess strings containing Java escapes (e.g. \n & \t)2.3.3 > - String unescapeHtmlDecode HTML-encoded strings2.3.3 > + String changeCaseChange case following different modes4.0 > String escapeHtmlEncode strings using HTML encoding2.3.3 > + String escapeOroRegexpCharsquote meta chars used by ORO regular expression2.9 > String escapeXmlEncode strings using XMl encoding3.2 > + String regexFunctionparse previous response using a regular expression1.X > + String unescapeProcess strings containing Java escapes (e.g. \n & \t)2.3.3 > + String unescapeHtmlDecode HTML-encoded strings2.3.3 > String urldecodeDecode a application/x-www-form-urlencoded string2.10 > String urlencodeEncode a string to a application/x-www-form-urlencoded string2.10 > String TestPlanNameReturn name of current test plan2.6 > @@ -1616,7 +1617,7 @@ becomes: > The name of the variable to set. > > > - > + > >

The __isPropDefined function returns true if property exists or false if not.

>
> @@ -1626,7 +1627,7 @@ becomes: > > >
> - > + > >

The __isVarDefined function returns true if variable exists or false if not.

>
> @@ -1636,6 +1637,30 @@ becomes: > > >
> + > + > +

The change case function returns a string value which > + case has been changed following a specific mode. > + Result can optionally be saved in a JMeter variable.

> +
> + > + The String > + which case will be changed > + > + The mode to be used to change case, for example for ab-CD eF: > +
    > +
  • UPPER result as AB-CD EF
  • > +
  • LOWER result as ab-cd ed
  • > +
  • CAPITALIZE result as Ab-CD eF
  • > +
  • CAMEL_CASEresult as AbCDEF
  • Shouldn't this be AbCdEf? > +
  • CAMEL_CASE_FIRST_LOWERresult as abCDEF
  • and this abCdEf? Regards,  Felix > +
> + mode is case insensitive > +
> + The name of the variable to set. > +
> +
> + > > > > >