本文整理汇总了Java中com.jayway.restassured.path.json.JsonPath类的典型用法代码示例。如果您正苦于以下问题:Java JsonPath类的具体用法?Java JsonPath怎么用?Java JsonPath使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonPath类属于com.jayway.restassured.path.json包,在下文中一共展示了JsonPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testMissingParameterForUnregister
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test missing parameter for unregister.
*/
@Test
public void testMissingParameterForUnregister() {
User user = getUserWithUserTypeKunde();
userRepository.save(user);
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured.given()
.header("Authorization", "Basic " + encodedString)
.when()
.delete(UNREGISTER_FAVORITE_API + "")
.then()
.statusCode(405).extract().jsonPath();
Assert.assertEquals("org.springframework.web.HttpRequestMethodNotSupportedException", response.getString("exception"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例2: testOptionalBaseMetrics
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
@Test
@RunAsClient
@InSequence(31)
public void testOptionalBaseMetrics() {
Header wantJson = new Header("Accept", APPLICATION_JSON);
JsonPath jsonPath = given().header(wantJson).options("/metrics/base").jsonPath();
Map<String, Object> elements = jsonPath.getMap(".");
Map<String, MiniMeta> names = getExpectedMetadataFromXmlFile(MetricRegistry.Type.BASE);
for (String item : names.keySet()) {
if (elements.containsKey(item) && names.get(item).optional) {
String prefix = names.get(item).name;
String type = "\""+prefix+"\""+".type";
String unit= "\""+prefix+"\""+".unit";
given().header(wantJson).options("/metrics/base/"+prefix).then().statusCode(200)
.body(type, equalTo(names.get(item).type))
.body(unit, equalTo(names.get(item).unit));
}
}
}
示例3: buildTestData
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
private void buildTestData() {
List<InputStream> testDataInputStreams = new ArrayList<InputStream>();
for(String testFile: testFiles) {
/** start / is required for getResourceAsStream method otherwise files is not loaded.**/
testFile = "/"+testFile;
testDataInputStreams.add(TestData.class.getResourceAsStream(testFile));
/** A new line character is added otherwise two files are not mearge properly and yaml parser gives error **/
testDataInputStreams.add(new ByteArrayInputStream("\n".getBytes()));
}
SequenceInputStream SequenceInputStream = new SequenceInputStream(Collections.enumeration(testDataInputStreams));
//System.out.print(convertToString(SequenceInputStream));
try {
Map testData = yamlMapper.readValue(SequenceInputStream, Map.class);
this.dataJsonPath = JsonPath.given(jsonMapper.writeValueAsString(testData));
} catch (Exception e) {
e.printStackTrace();
}
}
示例4: 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());
}
示例5: testIllegalMethodTypes
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test illegal method types.
*/
@Test
public void testIllegalMethodTypes() {
JsonPath response = RestAssured.given().when().delete(OFFERPHOTO_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'DELETE' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().put(OFFERPHOTO_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PUT' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().post(OFFERPHOTO_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'POST' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().patch(OFFERPHOTO_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PATCH' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例6: testIllegalMethodTypes
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test illegal method types.
*/
@Test
public void testIllegalMethodTypes() {
JsonPath response = RestAssured.given().when().delete(TYPE_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'DELETE' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().put(TYPE_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PUT' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().post(TYPE_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'POST' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().patch(TYPE_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PATCH' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例7: testIllegalMethodTypes
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test illegal method types.
*/
@Test
public void testIllegalMethodTypes() {
JsonPath response = RestAssured.given().when().delete(LOGIN_USER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'DELETE' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().put(LOGIN_USER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PUT' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().post(LOGIN_USER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'POST' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().patch(LOGIN_USER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PATCH' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例8: testInvalidAuthorizationHeader
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test invalid authorization header.
*/
@Test
public void testInvalidAuthorizationHeader()
{
JsonPath response = RestAssured
.given()
.header("Authorization", "Basic invalid")
.when()
.get(LOGIN_USER_API)
.then()
.statusCode(401)
.extract().jsonPath();
Assert.assertEquals("Invalid basic authentication token", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}
示例9: testInvalidUserType
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test if a user of invalid usertype (Anbieter) tries to login.
*/
@Test
public void testInvalidUserType()
{
User user = getUserWithUserTypeAnbieter();
userRepository.save(user);
// Since we need the password within the header as cleartext, it is extracted from the passwordconfirm field
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured
.given()
.header("Authorization", "Basic " + encodedString)
.when()
.get(LOGIN_USER_API)
.then()
.statusCode(401)
.extract().jsonPath();
Assert.assertEquals("UserDetailsService returned null, which is an interface contract violation", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}
示例10: testUserNotExisting
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test with user not present within database.
*/
@Test
public void testUserNotExisting()
{
User user = getUserWithUserTypeAnbieter();
// Since we need the password within the header as cleartext, it is extracted from the passwordconfirm field
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured
.given()
.header("Authorization", "Basic " + encodedString)
.when()
.get(LOGIN_USER_API)
.then()
.statusCode(401)
.extract().jsonPath();
Assert.assertEquals("UserDetailsService returned null, which is an interface contract violation", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}
示例11: testUserInvalidPassword
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test with invalid password for user.
*/
@Test
public void testUserInvalidPassword()
{
User user = getUserWithUserTypeKunde();
userRepository.save(user);
String authString = user.getUsername() + ":invalidPass";
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured
.given()
.header("Authorization", "Basic " + encodedString)
.when()
.get(LOGIN_USER_API)
.then()
.statusCode(401)
.extract().jsonPath();
Assert.assertEquals("Bad credentials", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}
示例12: testIllegalMethodTypes
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test illegal method types.
*/
@Test
public void testIllegalMethodTypes() {
JsonPath response = RestAssured.given().when().delete(OFFER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'DELETE' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().put(OFFER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PUT' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().post(OFFER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'POST' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
response = RestAssured.given().when().patch(OFFER_API).then().statusCode(405).extract().jsonPath();
Assert.assertEquals("Request method 'PATCH' not supported", response.getString("message"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例13: testMissingAuthorizationForRegister
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test missing authorization for register.
*/
@Test
public void testMissingAuthorizationForRegister()
{
PushNotification p = getPush(1);
JsonPath response = RestAssured
.given()
.contentType("application/json")
.body(p)
.when()
.post(REGISTER_PUSH_API)
.then()
.statusCode(401).extract().jsonPath();
Assert.assertEquals("Full authentication is required to access this resource", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}
示例14: testMissingParameterForUnregister
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test missing parameter for unregister.
*/
@Test
public void testMissingParameterForUnregister() {
User user = getUserWithUserTypeKunde();
userRepository.save(user);
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured.given()
.header("Authorization", "Basic " + encodedString)
.when()
.delete(UNREGISTER_PUSH_API + "")
.then()
.statusCode(405).extract().jsonPath();
Assert.assertEquals("org.springframework.web.HttpRequestMethodNotSupportedException", response.getString("exception"));
Assert.assertEquals("Method Not Allowed", response.getString("error"));
}
示例15: testWrongUserTypeForRegister
import com.jayway.restassured.path.json.JsonPath; //导入依赖的package包/类
/**
* Test wrong user type for register.
*/
@Test
public void testWrongUserTypeForRegister() {
PushNotification p = getPush(1);
User user = getUserWithUserTypeAnbieter();
// Since we need the password within the header as cleartext, it is extracted from the passwordconfirm field
String authString = user.getUsername() + ":" + user.getPasswordconfirm();
byte[] base64Encoded = Base64.getEncoder().encode(authString.getBytes());
String encodedString = new String(base64Encoded);
JsonPath response = RestAssured.given()
.contentType("application/json")
.body(p)
.header("Authorization", "Basic " + encodedString)
.when()
.post(REGISTER_PUSH_API)
.then()
.statusCode(401)
.extract().jsonPath();
Assert.assertEquals("UserDetailsService returned null, which is an interface contract violation", response.getString("message"));
Assert.assertEquals("Unauthorized", response.getString("error"));
}