本文整理汇总了Java中io.restassured.RestAssured.get方法的典型用法代码示例。如果您正苦于以下问题:Java RestAssured.get方法的具体用法?Java RestAssured.get怎么用?Java RestAssured.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.restassured.RestAssured
的用法示例。
在下文中一共展示了RestAssured.get方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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"));
}
示例2: 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);
}
示例3: 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);
}
示例4: 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());
System.out.println("body: " + response.body().asString());
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);
}
示例5: the
import io.restassured.RestAssured; //导入方法依赖的package包/类
@When("^I want to get information on the (.+) project$")
public void usersGetInformationOnAProject(String projectName) throws IOException {
wireMockServer.start();
configureFor("localhost", 8080);
stubFor(get(urlEqualTo(GET_JSON_PATH+projectName))
.willReturn(aResponse().withBody(jsonString).withHeader("content-type", JSON_CONTENT_TYPE).withStatus(200)));
Response res = RestAssured.get(GET_JSON_PATH+projectName);
assertEquals(200, res.getStatusCode());
String json = res.body().asString();
JsonPath jp = new JsonPath(json);
assertNotNull(jp);
assertEquals("cucumber", jp.getString("testing-framework"));
assertEquals("cucumber.io", jp.getString("website"));
assertTrue(jp.getString("supported-language").contains("Java"));
assertTrue(jp.getString("supported-language").contains("C++"));
/* ANOTHER WAY TO DO THE SAME */
/* given().contentType(JSON_CONTENT_TYPE).expect()
.statusCode(200)
.body(
"testing-framework", Matchers.equalTo("cucumber"),
"website", Matchers.equalTo("cucumber.io"),
"supported-language", Matchers.contains(
"Ruby",
"Java",
"Javascript",
"PHP",
"Python",
"C++"))
.when()
.get(GET_JSON_PATH+projectName); */
wireMockServer.stop();
}
示例6: testInvokeRepositoryActionWithResourceResult
import io.restassured.RestAssured; //导入方法依赖的package包/类
@Test
public void testInvokeRepositoryActionWithResourceResult() {
// resources should be received in json api format
String url = getBaseUri() + "schedules/repositoryActionWithResourceResult?msg=hello";
io.restassured.response.Response res = RestAssured.get(url);
Assert.assertEquals(200, res.getStatusCode());
res.then().assertThat().body("data.attributes.name", Matchers.equalTo("hello"));
// 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);
}
示例7: testInvokeRepositoryActionWithResourceResult
import io.restassured.RestAssured; //导入方法依赖的package包/类
@Test
public void testInvokeRepositoryActionWithResourceResult() {
// resources should be received in json api format
String url = getBaseUri() + "schedules/repositoryActionWithResourceResult?msg=hello";
io.restassured.response.Response response = RestAssured.get(url);
Assert.assertEquals(200, response.getStatusCode());
response.then().assertThat().body("data.attributes.name", Matchers.equalTo("hello"));
// 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);
}
示例8: getVideo
import io.restassured.RestAssured; //导入方法依赖的package包/类
@Attachment(value = "Video on Failure", type = "video/mp4")
private static byte[] getVideo(URL videoCaptureURL)
throws TimeoutException, InterruptedException, ConnectException {
int i = 0;
while (i++ < 4) {
logger.debug("Download URL for Video Capture: " + videoCaptureURL);
Response response = RestAssured.get(videoCaptureURL);
if (response.getStatusCode() == HttpStatus.SC_OK) {
return response.asByteArray();
}
TimeUnit.SECONDS.sleep(2);
}
throw new TimeoutException();
}
示例9: testSongRest
import io.restassured.RestAssured; //导入方法依赖的package包/类
@Test
public void testSongRest() {
Response response = RestAssured.get("http://localhost:8080/api/songs/");
assertEquals(200, response.getStatusCode());
}