当前位置: 首页>>代码示例>>Java>>正文


Java RequestSpecification.header方法代码示例

本文整理汇总了Java中com.jayway.restassured.specification.RequestSpecification.header方法的典型用法代码示例。如果您正苦于以下问题:Java RequestSpecification.header方法的具体用法?Java RequestSpecification.header怎么用?Java RequestSpecification.header使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jayway.restassured.specification.RequestSpecification的用法示例。


在下文中一共展示了RequestSpecification.header方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restrictions

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
@Test
public void restrictions() throws IOException, DateParseException
{
	String stagingUrl = staging.create();

	// put a file to the folder1 content url
	final File file = new File(getPathFromUrl(Attachments.get("avatar.png")));

	Response response = staging.putFile(stagingUrl, AVATAR_PATH, file);
	assertEquals(response.getHeader("ETag"), AVATAR_PNG_ETAG);

	RequestSpecification notModified = staging.notModified();
	notModified.header("If-None-Match", AVATAR_PNG_ETAG);
	staging.get(notModified, stagingUrl, AVATAR_PATH);
	response = staging.head(stagingUrl, AVATAR_PATH);
	Date date = DateUtil.parseDate(response.header("Last-Modified"));

	notModified = staging.notModified();
	notModified.header("If-Modified-Since", DateUtil.formatDate(date));
	staging.get(notModified, stagingUrl, AVATAR_PATH);
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:StagingApiTest.java

示例2: restrictions

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
@Test
public void restrictions() throws DateParseException
{
	RequestSpecification notModified = staging.notModified();
	notModified.header("If-None-Match", AVATAR_PNG_ETAG);
	staging.file(notModified, ITEM_ID, AVATAR_PATH);

	Response response = staging.headFile(ITEM_ID, AVATAR_PATH);
	Date date = DateUtil.parseDate(response.header("Last-Modified"));

	notModified = staging.notModified();
	notModified.header("If-Modified-Since", DateUtil.formatDate(date));
	staging.file(notModified, ITEM_ID, AVATAR_PATH);
}
 
开发者ID:equella,项目名称:Equella,代码行数:15,代码来源:ItemDownloadTest.java

示例3: addCommentToIssue

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的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;
}
 
开发者ID:basavaraj1985,项目名称:DolphinNG,代码行数:36,代码来源:JIRAClient.java

示例4: whenAuthenticated

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
/**
 * Helper method for authenticating via REST
 * @return REST-assured RequestSpecification
 */
public RequestSpecification whenAuthenticated() {
    RequestSpecification spec = given();
    if (!isAnonymous) {
        spec = spec.auth().preemptive().basic(username, password);
    }
    return spec.header("Content-Type", "application/json");
}
 
开发者ID:Vincit,项目名称:multi-user-test-runner,代码行数:12,代码来源:TestMultiUserRestConfig.java

示例5: whenAuthenticated

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
protected RequestSpecification whenAuthenticated() {
    RequestSpecification spec = given();
    if (!isAnonymous) {
        spec = spec.auth().preemptive().basic(username, password);
    } else {
        spec = spec;
    }
    return spec.header("Content-Type", "application/json");
}
 
开发者ID:Vincit,项目名称:multi-user-test-runner-examples,代码行数:10,代码来源:AbstractConfiguredRestAssuredIT.java

示例6: givenWithContent

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
public static RequestSpecification givenWithContent(String authToken) {
    RequestSpecification spec = given().spec(new RequestSpecBuilder()
            .addHeader("Content-Type", "application/json;charset=UTF-8")
            .build());
    if (authToken != null) {
        return spec.header("Authorization", "Bearer " + authToken);
    } else {
        return spec;
    }
}
 
开发者ID:HSLdevcom,项目名称:parkandrideAPI,代码行数:11,代码来源:AbstractIntegrationTest.java

示例7: prepareRequestSpecWithOriginHeader

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的package包/类
private RequestSpecification prepareRequestSpecWithOriginHeader(String requestOrigin) {
	RequestSpecification rs = given().contentType(ContentType.JSON);
	if (requestOrigin != null) {
		rs.header(CORSWithCredentialsFilter.HEADER_ORIGIN, requestOrigin);
	}
	return rs;
}
 
开发者ID:searchisko,项目名称:searchisko,代码行数:8,代码来源:CORSWithCredentialsFilterTest.java

示例8: createJiraTicket

import com.jayway.restassured.specification.RequestSpecification; //导入方法依赖的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;
}
 
开发者ID:basavaraj1985,项目名称:DolphinNG,代码行数:80,代码来源:JIRAClient.java


注:本文中的com.jayway.restassured.specification.RequestSpecification.header方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。