本文整理了Java中org.mozilla.zest.core.v1.ZestRequest
类的一些代码示例,展示了ZestRequest
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZestRequest
类的具体详情如下:
包路径:org.mozilla.zest.core.v1.ZestRequest
类名称:ZestRequest
[英]The Class ZestRequest.
[中]这门课充满激情。
代码示例来源:origin: mozilla/zest
@Override
public ZestRequest deepCopy() {
ZestRequest zr = new ZestRequest(this.getIndex());
zr.setUrl(this.url);
zr.setUrlToken(this.urlToken);
zr.setData(this.data);
zr.setMethod(this.method);
zr.setHeaders(this.headers);
zr.setFollowRedirects(this.followRedirects);
zr.setTimestamp(this.timestamp);
if (this.getResponse() != null) {
zr.setResponse(this.getResponse().deepCopy());
}
for (ZestAssertion zt : this.getAssertions()) {
zr.addAssertion((ZestAssertion) zt.deepCopy());
}
for (ZestCookie cookie : this.cookies) {
zr.addCookie(
new ZestCookie(
cookie.getDomain(),
cookie.getName(),
cookie.getValue(),
cookie.getPath(),
cookie.getExpiryDate(),
cookie.isSecure()));
}
zr.setEnabled(this.isEnabled());
return zr;
}
代码示例来源:origin: mozilla/zest
@Test
public void shouldSerialiseAndDeserialise() throws Exception {
ZestRequest request = new ZestRequest();
URL url = new URL("http://example.com/");
request.setUrl(url);
String urlToken = "http://{{host}}/";
request.setUrlToken(urlToken);
String method = "POST";
request.setMethod(method);
String headers = "Header-A: value-a\r\nHeader-B: value-b";
request.setHeaders(headers);
String data = "a=b&c=d";
request.setData(data);
boolean followRedirects = false;
request.setFollowRedirects(followRedirects);
long timestamp = Instant.now().toEpochMilli();
request.setTimestamp(timestamp);
assertThat(deserialisedRequest.getUrl()).isEqualTo(url);
assertThat(deserialisedRequest.getUrlToken()).isEqualTo(urlToken);
assertThat(deserialisedRequest.getMethod()).isEqualTo(method);
assertThat(deserialisedRequest.getHeaders()).isEqualTo(headers);
assertThat(deserialisedRequest.getData()).isEqualTo(data);
assertThat(deserialisedRequest.isFollowRedirects()).isEqualTo(followRedirects);
assertThat(deserialisedRequest.getTimestamp()).isEqualTo(timestamp);
代码示例来源:origin: mozilla/zest
@Override
public void setPrefix(String oldPrefix, String newPrefix) throws MalformedURLException {
if (this.getUrl() != null && this.getUrl().toString().startsWith(oldPrefix)) {
String urlStr = newPrefix + getUrl().toString().substring(oldPrefix.length());
this.setUrl(new URL(urlStr));
} else {
throw new IllegalArgumentException(
"Request url " + getUrl() + " does not start with " + oldPrefix);
}
}
代码示例来源:origin: mozilla/zest
/**
* Sets the standard variables for a request.
*
* @param request the new standard variables
*/
@Override
public void setStandardVariables(ZestRequest request) {
if (request != null) {
if (request.getUrl() != null) {
this.setVariable(ZestVariables.REQUEST_URL, request.getUrl().toString());
}
this.setVariable(ZestVariables.REQUEST_HEADER, request.getHeaders());
this.setVariable(ZestVariables.REQUEST_METHOD, request.getMethod());
this.setVariable(ZestVariables.REQUEST_BODY, request.getData());
}
}
代码示例来源:origin: mozilla/zest
ZestRequest req = new ZestRequest();
req.setUrl(new URL("http://www.example.com/app/{{token1}}"));
req.setHeaders("Set-Cookie: test={{token2}}");
req.setData("test={{token3}}&user=12{{token3}}34");
req.addCookie(
new ZestCookie(
"{{token}}.{{token3}}",
true));
ZestRequest req2 = req.deepCopy();
tokens.addVariable("token2", "GHI");
tokens.addVariable("token3", "JKL");
req2.replaceTokens(tokens);
assertEquals("http://www.example.com/app/DEFG", req2.getUrl().toString());
assertEquals("Set-Cookie: test=GHI", req2.getHeaders());
assertEquals("test=JKL&user=12JKL34", req2.getData());
assertEquals("ABC.JKL", req2.getZestCookies().get(0).getDomain());
assertEquals("12JKL34", req2.getZestCookies().get(0).getName());
assertEquals("56GHI78", req2.getZestCookies().get(0).getValue());
assertEquals("/DEFGA/GHIB", req2.getZestCookies().get(0).getPath());
代码示例来源:origin: mozilla/zest
ZestRequest req = new ZestRequest();
req.setUrl(new URL("http://www.example.com/app/{{token1}}"));
req.setHeaders("Set-Cookie: test={{token2}}");
req.setData("test={{token3}}&user=12{{token3}}34");
req.setTimestamp(Instant.now().toEpochMilli());
req.addCookie(
new ZestCookie(
"{{token}}.{{token3}}",
true));
ZestRequest req2 = req.deepCopy();
assertTrue(req.getHeaders().equals(req2.getHeaders()));
assertTrue(req.getData().equals(req2.getData()));
assertTrue(req.getTimestamp() == req2.getTimestamp());
ZestCookie cookie = req.getZestCookies().get(0);
ZestCookie cookie2 = req2.getZestCookies().get(0);
代码示例来源:origin: mozilla/zest
/**
* Replace tokens.
*
* @param tokens the tokens
*/
public void replaceTokens(ZestVariables tokens) {
if (this.urlToken != null) {
this.setUrlToken(tokens.replaceInString(this.urlToken, true));
try {
this.setUrl(new URL(this.getUrlToken()));
} catch (MalformedURLException e) {
// Ignore
}
} else if (this.url != null) {
try {
this.setUrl(new URL(tokens.replaceInString(this.url.toString(), true)));
} catch (MalformedURLException e) {
// Ignore
}
}
this.setMethod(tokens.replaceInString(this.getMethod(), false));
this.setHeaders(tokens.replaceInString(this.getHeaders(), false));
this.setData(tokens.replaceInString(this.getData(), false));
for (ZestCookie cookie : this.cookies) {
cookie.setDomain(tokens.replaceInString(cookie.getDomain(), false));
cookie.setName(tokens.replaceInString(cookie.getName(), false));
cookie.setValue(tokens.replaceInString(cookie.getValue(), false));
cookie.setPath(tokens.replaceInString(cookie.getPath(), false));
}
}
代码示例来源:origin: mozilla/zest
ZestRequest request = new ZestRequest();
URL url = new URL(getServerUrl(PATH_SERVER_FILE));
String method = "POST";
request.setMethod(method);
request.setUrl(url);
String headers =
"User-Agent: xyz\r\n"
+ "\r\n"
+ "Content-Length: 7\r\n";
request.setHeaders(headers);
String data = "a=b&c=d";
request.setData(data);
script.add(request);
ZestBasicRunner runner = new ZestBasicRunner();
assertThat(request.getTimestamp()).isCloseTo(System.currentTimeMillis(), byLessThan(2000L));
assertThat(request.getMethod()).isEqualTo(method);
assertThat(request.getUrl()).isEqualTo(url);
assertThat(request.getHeaders()).isEqualTo(headers);
assertThat(request.getData()).isEqualTo(data);
代码示例来源:origin: mozilla/zest
@Override
public ZestResponse send(ZestRequest req) throws IOException {
HttpMethod method;
URI uri = new URI(req.getUrl().toString(), false);
switch (req.getMethod()) {
case "GET":
method = new GetMethod(uri.toString());
method.setFollowRedirects(req.isFollowRedirects());
break;
case "POST":
break;
default:
throw new IllegalArgumentException("Method not supported: " + req.getMethod());
setHeaders(method, req.getHeaders());
for (ZestCookie zestCookie : req.getZestCookies()) {
Cookie cookie =
new Cookie(
RequestEntity requestEntity = new StringRequestEntity(req.getData(), null, null);
String responseBody = null;
Date start = new Date();
req.setTimestamp(start.getTime());
try {
code = httpclient.executeMethod(method);
代码示例来源:origin: mozilla/zest
private static ZestRequest createRequest() {
return new ZestRequest();
}
代码示例来源:origin: mozilla/zest
+ "Content-Type: application/x-www-form-urlencoded"
+ "Content-length: 0";
ZestRequest request = new ZestRequest();
request.setMethod("GET");
request.setHeaders(requestH);
request.setUrl(new URL("http://localhost:8080/bodgeit/"));
代码示例来源:origin: mozilla/zest
this.lastRequest = ((ZestRequest) stmt).deepCopy();
this.lastRequest.replaceTokens(this.variables);
this.debug(this.lastRequest.getMethod() + " : " + this.lastRequest.getUrl());
this.lastResponse = send(this.lastRequest);
代码示例来源:origin: mozilla/zest
/**
* Method testAddingIfs.
*
* @throws Exception
*/
@Test
public void testAddingIfs() throws Exception {
ZestConditional zc = new ZestConditional(new ZestExpressionRegex("BODY", ""));
ZestRequest req = new ZestRequest();
zc.addIf(req);
assertEquals(1, req.getIndex());
checkOrder(new ZestStatement[] {zc, req, null});
ZestRequest req2 = new ZestRequest();
zc.addIf(req2);
// 0: zc
// 1: req
// 2: req2
checkOrder(new ZestStatement[] {zc, req, req2, null});
ZestRequest req3 = new ZestRequest();
zc.addIf(1, req3);
// 0: zc
// 1: req
// 2: req3
// 3: req2
checkOrder(new ZestStatement[] {zc, req, req3, req2, null});
}
代码示例来源:origin: mozilla/zest
@Test
public void testIsTrue() {
ZestExpressionURL urlExpr = new ZestExpressionURL();
urlExpr.setIncludeRegexes(includeStrings);
urlExpr.setExcludeRegexes(excludeStrings);
try {
ZestRequest request = new ZestRequest();
request.setUrl(new URL("http://www.PING1.com"));
assertTrue(urlExpr.isTrue(new TestRuntime(request)));
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
代码示例来源:origin: mozilla/zest
302,
0);
ZestRequest req = new ZestRequest();
req.setResponse(resp);
代码示例来源:origin: mozilla/zest
@Override
public void responseFailed(ZestRequest request, ZestResponse response)
throws ZestAssertFailException {
this.debug(request.getIndex() + " Response FAILED");
}
代码示例来源:origin: mozilla/zest
public void addCookie(
String domain, String name, String value, String path, Date expiry, boolean secure) {
this.addCookie(new ZestCookie(domain, name, value, path, expiry, secure));
}
代码示例来源:origin: mozilla/zest
/**
* Tells whether or not the {@link ZestRuntime#getLastRequest() last request} matches {@link
* #getProtocol() the protocol} set.
*/
@Override
public boolean isTrue(ZestRuntime runtime) {
if (protocol == null) {
return false;
}
ZestRequest request = runtime.getLastRequest();
if (request == null) {
return false;
}
URL url = request.getUrl();
if (url == null) {
return false;
}
return protocol.equalsIgnoreCase(url.getProtocol());
}
代码示例来源:origin: mozilla/zest
@Override
public void setStandardVariables(ZestRequest request) {
if (request != null) {
if (request.getUrl() != null) {
this.setVariable(ZestVariables.REQUEST_URL, request.getUrl().toString());
}
this.setVariable(ZestVariables.REQUEST_HEADER, request.getHeaders());
this.setVariable(ZestVariables.REQUEST_METHOD, request.getMethod());
this.setVariable(ZestVariables.REQUEST_BODY, request.getData());
}
}
代码示例来源:origin: mozilla/zest
/**
* Method testSimpleIndexing.
*
* @throws Exception
*/
@Test
public void testSimpleIndexing() throws Exception {
ZestScript script = new ZestScript();
ZestRequest req = new ZestRequest();
script.add(req);
checkOrder(new ZestStatement[] {script, req, null});
ZestRequest req2 = new ZestRequest();
script.add(req2);
checkOrder(new ZestStatement[] {script, req, req2, null});
ZestRequest req1b = new ZestRequest();
script.add(1, req1b);
checkOrder(new ZestStatement[] {script, req, req1b, req2, null});
}
内容来源于网络,如有侵权,请联系作者删除!