本文整理汇总了Java中com.jayway.restassured.path.json.JsonPath.from方法的典型用法代码示例。如果您正苦于以下问题:Java JsonPath.from方法的具体用法?Java JsonPath.from怎么用?Java JsonPath.from使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jayway.restassured.path.json.JsonPath
的用法示例。
在下文中一共展示了JsonPath.from方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dataverseCategory
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
@Test
public void dataverseCategory() {
Response enableNonPublicSearch = enableSetting(SettingsServiceBean.Key.SearchApiNonPublicAllowed);
assertEquals(200, enableNonPublicSearch.getStatusCode());
/**
* Unfortunately, it appears that the ability to specify the category of
* a dataverse when creating it is a GUI-only feature. It can't
* currently be done via the API, to our knowledge. You also can't tell
* from the API which category was persisted but it always seems to be
* "UNCATEGORIZED"
*/
TestDataverse dataverseToCreate = new TestDataverse(dv1, "dv1", Dataverse.DataverseType.ORGANIZATIONS_INSTITUTIONS);
Response createDvResponse = createDataverse(dataverseToCreate, homer);
assertEquals(201, createDvResponse.getStatusCode());
TestSearchQuery query = new TestSearchQuery("dv1");
Response searchResponse = search(query, homer);
JsonPath jsonPath = JsonPath.from(searchResponse.body().asString());
String dv1Category = jsonPath.get("data.facets." + SearchFields.DATAVERSE_CATEGORY).toString();
String msg = "dv1Category: " + dv1Category;
assertEquals("dv1Category: [null]", msg);
Response disableNonPublicSearch = deleteSetting(SettingsServiceBean.Key.SearchApiNonPublicAllowed);
assertEquals(200, disableNonPublicSearch.getStatusCode());
}
示例2: suggestLimit
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
@Test
public void suggestLimit() throws Exception {
// given
final String columnMetadata = IOUtils.toString(Application.class.getResourceAsStream("suggestions/date_column.json"),
UTF_8);
// when
final String response = given() //
.contentType(JSON) //
.body(columnMetadata) //
.when() //
.post("/suggest/column?limit=2") //
.asString();
// then
final JsonPath json = JsonPath.from(response);
assertThat(json.getList("").size(), is(2));
}
示例3: suggestLimitDefault
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
@Test
public void suggestLimitDefault() throws Exception {
// given
final String columnMetadata = IOUtils.toString(Application.class.getResourceAsStream("suggestions/date_column.json"),
UTF_8);
// when
final String response = given() //
.contentType(JSON) //
.body(columnMetadata) //
.when() //
.post("/suggest/column") //
.asString();
// then
final JsonPath json = JsonPath.from(response);
assertThat(json.getList("").size(), is(5)); // Default for "limit" is 5.
}
示例4: createUser
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
private static JsonObject createUser(String jsonStr) {
JsonObjectBuilder createdUser = Json.createObjectBuilder();
Response response = createUserViaApi(jsonStr, getPassword(jsonStr));
Assert.assertEquals(200, response.getStatusCode());
JsonPath jsonPath = JsonPath.from(response.body().asString());
createdUser.add(idKey, jsonPath.getInt("data.user." + idKey));
createdUser.add(usernameKey, jsonPath.get("data.user." + usernameKey).toString());
createdUser.add(apiTokenKey, jsonPath.get("data." + apiTokenKey).toString());
return createdUser.build();
}
示例5: findDatasetIdFromGlobalId
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
/**
* Assumes you have turned on experimental non-public search
* https://github.com/IQSS/dataverse/issues/1299
*
* curl -X PUT -d true
* http://localhost:8080/api/admin/settings/:SearchApiNonPublicAllowed
*
* @return The Integer found or null.
*/
private static Integer findDatasetIdFromGlobalId(String globalId, String apiToken) {
Response searchForGlobalId = given()
.get("api/search?key=" + apiToken
+ "&q=dsPersistentId:\""
+ globalId.replace(":", "\\:")
+ "\"&show_entity_ids=true");
JsonPath jsonPath = JsonPath.from(searchForGlobalId.body().asString());
int id;
try {
id = jsonPath.get("data.items[0].entity_id");
} catch (IllegalArgumentException ex) {
return null;
}
return id;
}
示例6: jsonBody
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
public static Matcher<TypedOutput> jsonBody(final Matcher<JsonPath> mimeType) {
return new FeatureMatcher<TypedOutput, JsonPath>(mimeType, "a request body with mime type", "mime type") {
@Override
protected JsonPath featureValueOf(TypedOutput actual) {
final int capacity = (int) Math.max(actual.length(), 32);
final ByteArrayOutputStream os = new ByteArrayOutputStream(capacity);
try {
actual.writeTo(os);
return JsonPath.from(new String(os.toByteArray(), StandardCharsets.UTF_8));
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
};
}
示例7: getRoleAssignmentId
import com.jayway.restassured.path.json.JsonPath; //导入方法依赖的package包/类
private long getRoleAssignmentId(Response response) {
JsonPath jsonPath = JsonPath.from(response.body().asString());
return jsonPath.getInt("data.id");
}