本文整理汇总了Java中com.jayway.restassured.response.Response.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getStatusCode方法的具体用法?Java Response.getStatusCode怎么用?Java Response.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jayway.restassured.response.Response
的用法示例。
在下文中一共展示了Response.getStatusCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: attachFileToIssue
import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
/**
* Attaches given file to the jira ticket provided.
*
* @param jiraTicket - jira ticket id
* @param fileToAttach - file path, that needs to be attached
* @throws MalformedURLException
*/
public boolean attachFileToIssue(String jiraTicket, String fileToAttach) throws MalformedURLException
{
URL request = new URL("https://" + configuration.getProperty(DEFECT_MGMT_HOST) +
configuration.getProperty(BUG_API) + "/" + jiraTicket + "/attachments");
File file = new File(fileToAttach);
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
RequestSpecification given = RestAssured.given();
Header header2 = new Header("X-Atlassian-Token", "nocheck");
given = given.header(authenticationHeader).and().header(header2);
if (null != configuration.getProperty(PROXY_HOST))
{
given = given.proxy(configuration.getProperty(PROXY_HOST), Integer.parseInt(configuration.getProperty(PROXY_PORT)));
LOG.info("Using proxy server - " + configuration.getProperty(PROXY_HOST) + ":" +
configuration.getProperty(PROXY_PORT) + " given: " + given);
}
Response response = given
.accept(CONTENT_TYPE_APPLICATION_JSON)
.when().multiPart(file)
.post(request).then()
.extract().response();
return response.getStatusCode() == 200;
}
示例2: addCommentToIssue
import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
/**
* Adds a comment to the jira ticket
*
* @param jiraTicket - jira ticket id
* @param comment - comment to add
* @return
* @throws MalformedURLException
*/
public boolean addCommentToIssue(String jiraTicket, String comment) throws MalformedURLException
{
URL request = new URL("https://" + configuration.getProperty(DEFECT_MGMT_HOST) +
configuration.getProperty(BUG_API) + "/" + jiraTicket + "/comment");
comment = comment + "\n\n\n" + "Test Run URL: " + buildUrl;
comment = comment + "\n" + "Note: This comment is created automatically by DolphinNG.";
comment = StringEscapeUtils.escapeHtml3(comment);
comment = StringEscapeUtils.escapeHtml4(comment);
comment = JSONObject.escape(comment);
String payload =
"{" +
"\"body\":" + "\"" + comment + "\"" +
"}";
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
RequestSpecification given = RestAssured.given();
given = given.header(authenticationHeader);
Response response = given
.contentType(CONTENT_TYPE_APPLICATION_JSON)
.accept(CONTENT_TYPE_APPLICATION_JSON)
.when().body(payload).post(request).then()
.extract().response();
LOG.info("JIRA ticket creation result---> StatusCode=" +
response.getStatusCode() + " status=" + response.getStatusLine() +
" payload=" + payload +
" Response=" + response.getBody().prettyPrint());
return response.getStatusCode() == 201;
}
示例3: createJiraTicket
import com.jayway.restassured.response.Response; //导入方法依赖的package包/类
/**
* Creates a jira ticket, and returns jira id.
*
* @param summary
* @param description
* @return
*/
public String createJiraTicket(String summary, String description, Map<String, Object> overrideBugFields)
throws IOException
{
String jiraId = null;
String searchSummary = truncateAfterStopWords(summary, System.getProperty(SEARCH_TRUNCATE_AFTER_WORDS,
configuration.getProperty(SEARCH_TRUNCATE_AFTER_WORDS)));
searchSummary = searchSummary.replaceAll("[^a-zA-Z0-9\\s]", " ").replaceAll("\\s+", " ").trim();
searchSummary = removeStopWordsFrom(searchSummary, System.getProperty(SEARCH_STOP_WORDS_REGEX,
configuration.getProperty(SEARCH_STOP_WORDS_REGEX)));
String createConditionQuery = "summary~\"" + searchSummary + "\" ";
Bug foundBug = getBugsBySearchQuery(createConditionQuery);
jiraId = (null != foundBug && !foundBug.getStatus().equalsIgnoreCase("closed")) ? foundBug.getID() : null;
if (!Boolean.parseBoolean(System.getProperty(AUTO_CREATE_BUG, configuration.getProperty(AUTO_CREATE_BUG, "false"))))
{
System.err.println("Auto bug creation disabled! Already open bug for same fail reason - " + jiraId);
return jiraId;
}
summary = summary.replaceAll("[^a-zA-Z0-9\\s]", " ").replaceAll("\\s+", " ").trim();
if (null != foundBug && !foundBug.getStatus().equalsIgnoreCase("closed"))
{
LOG.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
LOG.info("Bug already exists for " + createConditionQuery);
LOG.info(foundBug);
if (Boolean.parseBoolean(System.getProperty(AUTO_ATTACH_FILES_ON_FOUNDBUGS,
configuration.getProperty(AUTO_ATTACH_FILES_ON_FOUNDBUGS, "true"))))
{
LOG.info("Attaching files for this run!");
String attached = attachFilesToIssue(foundBug.getID());
description = "||Testcase failing|| Parameters||\n" +
description +
"\n\n" +
System.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS,
configuration.getProperty(AUTO_CREATE_ADDITIONAL_DETAILS, "")) + "\n" +
"Attaching files for this failure, files are: " + attached;
addCommentToIssue(foundBug.getID(), description);
}
LOG.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
return foundBug.getID();
}
LOG.info("Creating jira ticket for " + summary);
URL request = new URL("https://" + configuration.getProperty(DEFECT_MGMT_HOST) + configuration.getProperty(BUG_API));
String payloadTemplateFile = configuration.getProperty(BUG_CREATE_BODY, "resources/jiracreateTemplate.vm");
summary = removeStopWordsFrom(summary, System.getProperty(AUTO_CREATE_STOP_WORDS_REGEX,
configuration.getProperty(AUTO_CREATE_STOP_WORDS_REGEX)));
String payload = preparePayload(summary, description, payloadTemplateFile, overrideBugFields);
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
RequestSpecification given = RestAssured.given();
given = given.header(authenticationHeader);
if (null != configuration.getProperty(PROXY_HOST))
{
given = given.proxy(configuration.getProperty(PROXY_HOST), Integer.parseInt(configuration.getProperty(PROXY_PORT)));
LOG.info("Using proxy server - " + configuration.getProperty(PROXY_HOST) + ":" +
configuration.getProperty(PROXY_PORT) + " given: " + given);
}
Response response = given
.contentType(CONTENT_TYPE_APPLICATION_JSON)
.accept(CONTENT_TYPE_APPLICATION_JSON)
.when().body(payload).post(request).then()
.extract().response();
LOG.info("JIRA ticket creation result---> StatusCode=" +
response.getStatusCode() + " status=" + response.getStatusLine() +
" payload=" + payload +
" Response=" + response.getBody().prettyPrint());
if (201 == response.getStatusCode())
{
JSONUtil jsonUtil = new JSONUtil(response.getBody().print());
jiraId = jsonUtil.getValue("$.key");
LOG.info("Created JIRA for [" + summary + "], bug: " + jiraId);
attachFilesToIssue(jiraId);
}
return jiraId;
}