本文整理了Java中org.mozilla.zest.core.v1.ZestVariables
类的一些代码示例,展示了ZestVariables
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestVariables
类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestVariables
类名称:ZestVariables
[英]The Class ZestTokens.
[中]这门课充满热情。
代码示例来源:origin: mozilla/zest
@Override
public ZestVariables deepCopy() {
ZestVariables zt = new ZestVariables();
zt.setTokenStart(this.tokenStart);
zt.setTokenEnd(this.tokenEnd);
for (Entry<String, String> entry : tokens.entrySet()) {
zt.setVariable(entry.getKey(), entry.getValue());
}
return zt;
}
代码示例来源:origin: mozilla/zest
for (String[] nvPair : getVariables()) {
String tokenStr = getTokenStart() + nvPair[0] + getTokenEnd();
if (str.contains(tokenStr)) {
if (!previous.contains(nvPair[0])) {
str = str.replace(tokenStr, getReplacementValue(nvPair[1]));
str = str.replace(tokenStr, getReplacementValue(nvPair[1]));
return this.replaceInString(str, urlEncode, previous);
代码示例来源:origin: mozilla/zest
@Override
public String getVariable(String name) {
return this.variables.getVariable(name);
}
代码示例来源:origin: mozilla/zest
private static String token(ZestVariables zestVars, String string) {
return zestVars.getTokenStart() + string + zestVars.getTokenEnd();
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReplaceVariablesInVariablesInString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.setVariable("Var1", "-1 < " + token(zestVars, "Var2"));
zestVars.setVariable("Var2", token(zestVars, "Var3"));
zestVars.setVariable("Var3", "1");
String string = token(zestVars, "Var1") + " <= " + token(zestVars, "Var3");
// When
String finalString = zestVars.replaceInString(string, false);
// Then
assertTrue("-1 < 1 <= 1".equals(finalString));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetVariableWithNullName() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
String name = null;
// When
zestVars.setVariable(name, VAR_VALUE);
// Then
assertTrue(zestVars.getVariables().size() == 1);
assertTrue(zestVars.getVariables().get(0)[0] == null);
assertTrue(zestVars.getVariables().get(0)[1] == VAR_VALUE);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldNotAddVarIfAlreadyAdded() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.addVariable(VAR_NAME);
// When
zestVars.addVariable(VAR_NAME);
// Then
assertTrue(zestVars.getVariables().size() == 1);
assertTrue(VAR_NAME.equals(zestVars.getVariables().get(0)[0]));
assertTrue(VAR_NAME.equals(zestVars.getVariables().get(0)[1]));
}
代码示例来源:origin: mozilla/zest
ZestVariables tokens = new ZestVariables();
tokens.setTokenStart("{{");
tokens.setTokenEnd("}}");
tokens.addVariable("token", "ABC");
tokens.addVariable("token1", "DEFG");
tokens.addVariable("token2", "GHI");
tokens.addVariable("token3", "JKL");
req2.replaceTokens(tokens);
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetTokenStart() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
String tokenStart = "\\|";
// When
zestVars.setTokenStart(tokenStart);
// Then
assertTrue(zestVars.getTokenStart().equals(tokenStart));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSetTokenEnd() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
String tokenEnd = "|//";
// When
zestVars.setTokenEnd(tokenEnd);
// Then
assertTrue(zestVars.getTokenEnd().equals(tokenEnd));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldAddVariables() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
Map<String, String> vars = new HashMap<>();
String varName1 = null;
String varValue1 = "Value1";
vars.put(varName1, varValue1);
String varName2 = "Var2";
String varValue2 = "Value2";
vars.put(varName2, varValue2);
String varName3 = "Var3";
String varValue3 = null;
vars.put(varName3, varValue3);
zestVars.addVariable(varName1, "123");
zestVars.addVariable(varName3, "abc");
// When
zestVars.addVariables(vars);
// Then
assertTrue(zestVars.getVariables().size() == 3);
assertTrue(zestVars.getVariables().get(0)[0] == varName1);
assertTrue(varValue1.equals(zestVars.getVariables().get(0)[1]));
assertTrue(varName3.equals(zestVars.getVariables().get(1)[0]));
assertTrue(zestVars.getVariables().get(1)[1] == varValue3);
assertTrue(varName2.equals(zestVars.getVariables().get(2)[0]));
assertTrue(zestVars.getVariables().get(2)[1] == varValue2);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldGetValueOfVariableAdded() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
zestVars.addVariable(VAR_NAME, VAR_VALUE);
// When
String valueObtained = zestVars.getVariable(VAR_NAME);
// Then
assertTrue(valueObtained.equals(VAR_VALUE));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldHaveTokenEndByDefault() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
String tokenEnd = zestVars.getTokenEnd();
// Then
assertTrue("}}".equals(tokenEnd));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldReturnNullStringIfReplacingVariablesInNullString() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
String finalString = zestVars.replaceInString(null, false);
// Then
assertTrue(finalString == null);
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldHaveTokenStartByDefault() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
String tokenStart = zestVars.getTokenStart();
// Then
assertTrue("{{".equals(tokenStart));
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldHaveNoVariablesByDefault() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
List<String[]> variables = zestVars.getVariables();
// Then
assertTrue(variables.isEmpty());
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldGetNullValueIfVariableWasNotAdded() throws Exception {
// Given
ZestVariables zestVars = new ZestVariables();
// When
String valueObtained = zestVars.getVariable(VAR_NAME);
// Then
assertTrue(valueObtained == null);
}
代码示例来源:origin: mozilla/zest
@Override
public String replaceVariablesInString(String str, boolean urlEncode) {
return this.variables.replaceInString(str, urlEncode);
}
代码示例来源:origin: mozilla/zest
@Override
public void setVariable(String name, String value) {
vars.setVariable(name, value);
}
代码示例来源:origin: mozilla/zest
@Override
public Set<String> getVariableNames() {
Set<String> tokens = new HashSet<String>();
// Add the 'standard' ones
tokens.add(ZestVariables.REQUEST_URL);
tokens.add(ZestVariables.REQUEST_METHOD);
tokens.add(ZestVariables.REQUEST_HEADER);
tokens.add(ZestVariables.REQUEST_BODY);
tokens.add(ZestVariables.RESPONSE_URL);
tokens.add(ZestVariables.RESPONSE_HEADER);
tokens.add(ZestVariables.RESPONSE_BODY);
List<String[]> vars = this.getParameters().getVariables();
for (String[] var : vars) {
tokens.add(var[0]);
}
ZestStatement next = this.getNext();
while (next != null) {
if (next instanceof ZestAssignment) {
tokens.add(((ZestAssignment) next).getVariableName());
} else if (next instanceof ZestClientAssignCookie) {
tokens.add(((ZestClientAssignCookie) next).getVariableName());
} else if (next instanceof ZestClientElementAssign) {
tokens.add(((ZestClientElementAssign) next).getVariableName());
} else if (next instanceof ZestLoop) {
tokens.add(((ZestLoop<?>) next).getVariableName());
}
next = next.getNext();
}
return tokens;
}
内容来源于网络,如有侵权,请联系作者删除!