本文整理匯總了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());
}