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


Java RestAssured类代码示例

本文整理汇总了Java中io.restassured.RestAssured的典型用法代码示例。如果您正苦于以下问题:Java RestAssured类的具体用法?Java RestAssured怎么用?Java RestAssured使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Resource

import io.restassured.RestAssured; //导入依赖的package包/类
public Resource(HashMap<CommsRouterResource, String> state) {
  RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
  java.util.Map<String, String> env = System.getenv();

  if (System.getProperty("autHost") == null) {
    String host = env.get("AUT_HOST");
    if (host != null) {
      RestAssured.baseURI = host;
    } else {
      RestAssured.baseURI = "http://localhost:8080";
    }
  } else {
    // you can specify it using -DautHost=http://localhost:8080
    RestAssured.baseURI = System.getProperty("autHost");
  }
  RestAssured.basePath = "/comms-router-web/api";
  this.state = state;
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:19,代码来源:Resource.java

示例2: testPropertiesRelationships

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void testPropertiesRelationships() {
    // @formatter:off
    RestAssured
        .given()
        .when()
            .get(snitchURI)
        .then()
            .statusCode(200)
            .contentType(ContentType.JSON)
            .body("componentRelationships[0].component.name", Matchers.is("app-props-detector"))
            .body("componentRelationships[0].component.type", Matchers.is("properties/application"))
            .body("componentRelationships[0].dependencies", Matchers.hasSize(1))
            .body("componentRelationships[0].dependencies[0].component.name", Matchers.is("dependency"))
            .body("componentRelationships[0].dependencies[0].component.type", Matchers.is("properties/dependency"))
            .body("componentRelationships[0].consumers", Matchers.hasSize(1))
            .body("componentRelationships[0].consumers[0].component.name", Matchers.is("consumer"))
            .body("componentRelationships[0].consumers[0].component.type", Matchers.is("properties/consumer"));
    // @formatter:on
}
 
开发者ID:cereebro,项目名称:cereebro,代码行数:21,代码来源:SnitchEndpointConfigurationPropertiesDetectorTest.java

示例3: badSnitchUriShouldYield200AndResolutionError

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void badSnitchUriShouldYield200AndResolutionError() {
    // @formatter:off
    RestAssured
        .given()
            .accept(ContentType.JSON)
        .when()
            .get(systemURI)
        .then()
            .statusCode(200)
            .body("name", Matchers.is("error-system"))
            .body("errors.size()", Matchers.is(1))
            .body("errors[0].snitchUri", Matchers.is("http://cereebro.nope"))
            .body("errors[0].message", Matchers.not(Matchers.isEmptyOrNullString()))
            // cause (Throwable) should not be serialized
            .body("errors[0].cause", Matchers.nullValue());
    // @formatter:on
}
 
开发者ID:cereebro,项目名称:cereebro,代码行数:19,代码来源:CereebroServerErrorApplicationTest.java

示例4: getDataToSignOneDocument

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void getDataToSignOneDocument() throws Exception {

	DSSPrivateKeyEntry dssPrivateKeyEntry = token.getKeys().get(0);

	DataToSignOneDocumentDTO dataToSign = new DataToSignOneDocumentDTO();

	RemoteSignatureParameters parameters = new RemoteSignatureParameters();
	parameters.setSignatureLevel(SignatureLevel.CAdES_BASELINE_B);
	parameters.setSignaturePackaging(SignaturePackaging.ENVELOPING);
	parameters.setDigestAlgorithm(DigestAlgorithm.SHA256);
	parameters.setSigningCertificate(new RemoteCertificate(dssPrivateKeyEntry.getCertificate().getEncoded()));

	BLevelParameters bLevelParams = new BLevelParameters();
	bLevelParams.setSigningDate(new Date());
	parameters.setBLevelParams(bLevelParams);
	dataToSign.setParameters(parameters);

	RemoteDocument toSignDocument = new RemoteDocument();
	toSignDocument.setBytes("Hello".getBytes("UTF-8"));
	dataToSign.setToSignDocument(toSignDocument);

	RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(dataToSign, ObjectMapperType.JACKSON_2)
			.post("/services/rest/signature/one-document/getDataToSign").then().assertThat().statusCode(equalTo(200));

}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:27,代码来源:RestDocumentationApp.java

示例5: validateDoc

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void validateDoc() throws IOException {

	DataToValidateDTO dataToValidateDTO = new DataToValidateDTO();

	File signature = new File("src/test/resources/xades-detached.xml");
	RemoteDocument signedDoc = new RemoteDocument();
	signedDoc.setBytes(toByteArray(signature));
	signedDoc.setMimeType(MimeType.XML);
	signedDoc.setName(signature.getName());
	dataToValidateDTO.setSignedDocument(signedDoc);

	File detached = new File("src/test/resources/sample.xml");
	RemoteDocument originalDoc = new RemoteDocument();
	originalDoc.setBytes(toByteArray(detached));
	originalDoc.setMimeType(MimeType.XML);
	originalDoc.setName(detached.getName());

	dataToValidateDTO.setOriginalDocument(originalDoc);

	RestAssured.given(this.spec).accept(ContentType.JSON).contentType(ContentType.JSON).body(dataToValidateDTO, ObjectMapperType.JACKSON_2)
			.post("/services/rest/validation/validateSignature").then().assertThat().statusCode(equalTo(200));

}
 
开发者ID:esig,项目名称:dss-demonstrations,代码行数:25,代码来源:RestDocumentationApp.java

示例6: setUp

import io.restassured.RestAssured; //导入依赖的package包/类
@BeforeClass
public static void setUp() throws MalformedURLException {
    // set base URI and port number to use for all requests
    serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    username = System.getProperty("test.user");
    password = System.getProperty("test.pwd");

    if (username != null && password != null) {
        RestAssured.authentication = RestAssured.basic(username, password);
        RestAssured.useRelaxedHTTPSValidation();
    }
    RestAssured.defaultParser = Parser.JSON;

    if (StringUtils.isBlank(serverUrl)) {
        serverUrl = DEFAULT_PROTOCOL + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT;
    }
    headers.put(YamlToJsonConverterServlet.TCK_HEADER_SERVERURL, serverUrl);
    if (StringUtils.isNotBlank(username)) {
        headers.put(YamlToJsonConverterServlet.TCK_HEADER_USERNAME, username);
    }
    if (StringUtils.isNotBlank(password)) {
        headers.put(YamlToJsonConverterServlet.TCK_HEADER_PASSWORD, password);
    }
}
 
开发者ID:eclipse,项目名称:microprofile-open-api,代码行数:39,代码来源:AppTestBase.java

示例7: using

import io.restassured.RestAssured; //导入依赖的package包/类
/**
 * @author wasiq.bhamla
 * @since 20-Aug-2017 3:42:25 PM
 * @return instance
 */
public RequestHandler using () {
	final String endPoint = this.setting.getEndPoint ();
	final int port = this.setting.getPort ();
	final ContentType type = this.setting.getContentType ();
	this.request = RestAssured.given ()
		.baseUri (endPoint);
	LOG.info (LINE);
	LOG.info ("Preparing to execute request with following parameters:");
	LOG.info (LINE);
	LOG.info (format ("End-point url: %s", endPoint));
	if (port > 0) {
		LOG.info (format ("End-point port: %d", port));
		this.request = this.request.port (port);
	}
	if (type != null) {
		LOG.info (format ("End-point content-tyoe: %s", type));
		this.request = this.request.contentType (type);
	}
	return this;
}
 
开发者ID:WasiqB,项目名称:coteafs-services,代码行数:26,代码来源:RequestHandler.java

示例8: test

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void test() throws InstantiationException, IllegalAccessException {
	String url = getBaseUri() + "country/ch";
	io.restassured.response.Response getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());

	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Schweiz"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));

	String patchData = "{'data':{'id':'ch','type':'country','attributes':{'deText':'Test','enText':'Switzerland','ctlActCd':true}}}".replaceAll("'", "\"");

	Response patchResponse = RestAssured.given().body(patchData.getBytes()).header("content-type", JsonApiMediaType.APPLICATION_JSON_API).when().patch(url);
	patchResponse.then().statusCode(HttpStatus.SC_OK);

	getResponse = RestAssured.get(url);
	Assert.assertEquals(200, getResponse.getStatusCode());
	getResponse.then().assertThat().body("data.attributes.deText", Matchers.equalTo("Test"));
	getResponse.then().assertThat().body("data.attributes.enText", Matchers.equalTo("Switzerland"));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:20,代码来源:CustomResourceFieldTest.java

示例9: testInvokeRepositoryActionWithException

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void testInvokeRepositoryActionWithException() {
	// resources should be received in json api format
	String url = getBaseUri() + "schedules/repositoryActionWithException?msg=hello";
	io.restassured.response.Response res = RestAssured.get(url);
	Assert.assertEquals(403, res.getStatusCode());

	res.then().assertThat().body("errors[0].status", Matchers.equalTo("403"));

	// check filters
	ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
	Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
	DocumentFilterContext actionContext = contexts.getAllValues().get(0);
	Assert.assertEquals("GET", actionContext.getMethod());
	Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:17,代码来源:InteroperabilityTest.java

示例10: testInvokeRepositoryActionWithException

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void testInvokeRepositoryActionWithException() {
	// resources should be received in json api format
	String url = getBaseUri() + "schedules/repositoryActionWithException?msg=hello";
	io.restassured.response.Response response = RestAssured.get(url);
	Assert.assertEquals(403, response.getStatusCode());

	response.then().assertThat().body("errors[0].status", Matchers.equalTo("403"));

	// check filters
	ArgumentCaptor<DocumentFilterContext> contexts = ArgumentCaptor.forClass(DocumentFilterContext.class);
	Mockito.verify(filter, Mockito.times(1)).filter(contexts.capture(), Mockito.any(DocumentFilterChain.class));
	DocumentFilterContext actionContext = contexts.getAllValues().get(0);
	Assert.assertEquals("GET", actionContext.getMethod());
	Assert.assertTrue(actionContext.getJsonPath() instanceof ActionPath);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:17,代码来源:JsonApiActionResponseTest.java

示例11: setup

import io.restassured.RestAssured; //导入依赖的package包/类
@Before
public void setup() {
	RestAssured.baseURI = "https://127.0.0.1:6443/as-api";
	RestAssured.basePath = "/api/v1";
	//单项认证允许所有客户端通过
	RestAssured.useRelaxedHTTPSValidation();
}
 
开发者ID:strictnerd,项目名称:LearningSummary,代码行数:8,代码来源:HTTPAPITest.java

示例12: testAuthJson

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void testAuthJson() {
	Map<String, Object> map = new HashMap<>();
	map.put("mode", 2);
	map.put("id", "23452345234");
	map.put("identity", "11111111");
	map.put("challenge", "s随风倒根深蒂固g");
	map.put("response", "98CF0059D520E39E2016EB3AC70763BB26B665D77CD81378F11E5479E7094ACD");
	map.put("sign", "1232321");
	
	Response post = RestAssured
			.given()
			.contentType("application/json")
			.request()
			.body(JSON.toJSONString(map))
			.post("/auth");
	
	Assert.assertEquals(500, post.getStatusCode());
	//JsonPath jp = new JsonPath(post.asString());
	//System.out.println(post.asString());//根据要求添加断言
}
 
开发者ID:strictnerd,项目名称:LearningSummary,代码行数:22,代码来源:HTTPAPITest.java

示例13: canGetC3POandParseWithJsonPath

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void canGetC3POandParseWithJsonPath(){

    // use RestAssured to make an HTML Call
    Response response = RestAssured.get(
                      "http://swapi.co/api/people/2/?format=json").
                       andReturn();

    String json = response.getBody().asString();
    System.out.println(json);

    // Use the JsonPath parsing library of RestAssured to Parse the JSON
    
    JsonPath jsonPath = new JsonPath(json);
    Assert.assertEquals(
            "C-3PO",
            jsonPath.getString("name"));

}
 
开发者ID:eviltester,项目名称:libraryexamples,代码行数:20,代码来源:SwapiAPIUsageTest.java

示例14: canGetC3POandParseWithJsonPathIntoObject

import io.restassured.RestAssured; //导入依赖的package包/类
@Test
public void canGetC3POandParseWithJsonPathIntoObject(){

    // use RestAssured to make an HTML Call
    Response response = RestAssured.get(
            "http://swapi.co/api/people/2/?format=json").
            andReturn();

    String json = response.getBody().asString();
    System.out.println(json);

    // Use the JsonPath parsing library of RestAssured to Parse the JSON into an object

   Person c3po = new JsonPath(json).getObject("$", Person.class);
    Assert.assertEquals(
            "C-3PO",
            c3po.name);

}
 
开发者ID:eviltester,项目名称:libraryexamples,代码行数:20,代码来源:SwapiAPIUsageTest.java

示例15: getProjects

import io.restassured.RestAssured; //导入依赖的package包/类
public List<ProjectFromXmlOrJson> getProjects(){

        List<ProjectFromXmlOrJson> projects = new ArrayList<>();

        String xml = RestAssured.
                when().get(xmlendpoint).
                andReturn().body().asString();

        XmlPath xmlPath = new XmlPath(xml);
        int numberOfProjects = xmlPath.getInt("projects.project.size()");
        for(int projectIndex=0; projectIndex<numberOfProjects; projectIndex++){

            String query = String.format("projects.project[%d]",projectIndex);
            ProjectFromXmlOrJson project = xmlPath.getObject(query,ProjectFromXmlOrJson.class);

            projects.add(project);
        }

        return projects;
    }
 
开发者ID:eviltester,项目名称:tracksrestcasestudy,代码行数:21,代码来源:SerialisingApi.java


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