Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2019 Infostretch Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
******************************************************************************/
package com.qmetry.qaf.automation.step.client.text;
import static com.qmetry.qaf.automation.core.ConfigurationManager.getBundle;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.lang.text.StrSubstitutor;
import com.qmetry.qaf.automation.util.JSONUtil;
import com.qmetry.qaf.automation.util.StringMatcher;
import com.qmetry.qaf.automation.util.StringUtil;
/**
* @author chirag.jayswal
*/
public class BDDDefinitionHelper {
/**
* This enumeration specifies BDD keywords used while BDD step mapping. You
* can specify synonyms for keyword in properties file by using keyword name
* as key.
*
* For example to specify Synonyms for "Given" keyword provide property:
*
* Given=Provided;GivenThat;Assume
*
* Above property enable "Provided", "GivenThat" and "Assume" as synonym of
* "Given"
*
* @author chirag.jayswal
*/
public enum BDDKeyword {
Given, When, Then, And, Using, Having, With;
/**
* all keywords including synonyms
*
* @return
*/
public static List getAllKeyWords() {
List keywords = new ArrayList();
for (BDDKeyword keyword : BDDKeyword.values()) {
keywords.add(keyword.name());
// add all synonyms for this keyword
for (String synonym : keyword.getSynonyms()) {
keywords.add(synonym);
}
}
return keywords;
}
public static String getKeyWordRegEx() {
StringBuilder sb = new StringBuilder("^(");
for (String keyword : getAllKeyWords()) {
sb.append(keyword);
sb.append("|");
}
sb.deleteCharAt(sb.length() - 1); // remove last |
sb.append(")");
return sb.toString();
}
/**
* @return Synonyms for keyword defined in properties using
* {@link BDDKeyword} name as key.
*/
public List getSynonyms() {
List synonyms = new ArrayList();
for (Object object : getBundle().getList(name())) {
if (null != object && StringUtil.isNotBlank(object.toString()))
synonyms.add(object.toString());
}
return synonyms;
}
public static String getKeywordFrom(String behavior) {
String regx = getKeyWordRegEx();
Pattern p = Pattern.compile(regx, Pattern.CASE_INSENSITIVE);
Matcher matcher = p.matcher(behavior);
if (matcher.find())
return matcher.group();
return "";
}
}
public enum ParamType {
STRING(
// "('[^(\\\\')*]*((\\\\')*(\\*|\\!|\\(|\\))*[^(\\\\')*]*)*')|(\"[^(\\\\\")*]*((\\\\\")*(\\*|\\!|\\(|\\))*[^(\\\\\")*]*)*\")"),
"('([^\\\\']|\\\\\\\\|\\\\')*')|(\"([^\\\\\"]|\\\\\\\\|\\\\\")*\")","String str"), MAP("(\\{.*})","Map