[TEST] make JsonPath independent of data format, rename to ObjectPath

The internal representation of the object that JsonPath gives access to is a map. That is independent of the initial input format, which is json but could also be yaml etc.
This commit renames JsonPath to ObjectPath and adds a static method to create an ObjectPath from an XContent

Original commit: elastic/x-pack-elasticsearch@bc84c68161
This commit is contained in:
javanna 2016-06-24 13:29:15 +02:00 committed by Luca Cavanna
parent 8d6d96d2f8
commit 579baa2bca
1 changed files with 7 additions and 7 deletions

View File

@ -16,7 +16,7 @@ import org.elasticsearch.xpack.security.authz.InternalAuthorizationService;
import org.elasticsearch.xpack.security.user.AnonymousUser;
import org.elasticsearch.test.SecurityIntegTestCase;
import org.elasticsearch.test.SecuritySettingsSource;
import org.elasticsearch.test.rest.json.JsonPath;
import org.elasticsearch.test.rest.ObjectPath;
import org.junit.BeforeClass;
import java.util.Collections;
@ -56,10 +56,10 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
new BasicHeader("Authorization", basicAuthHeaderValue(SecuritySettingsSource.DEFAULT_USER_NAME,
new SecuredString(SecuritySettingsSource.DEFAULT_PASSWORD.toCharArray()))))) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
assertThat(jsonPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME));
ObjectPath objectPath = ObjectPath.createFromXContent(EntityUtils.toString(response.getEntity()));
assertThat(objectPath.evaluate("username").toString(), equalTo(SecuritySettingsSource.DEFAULT_USER_NAME));
@SuppressWarnings("unchecked")
List<String> roles = (List<String>) jsonPath.evaluate("roles");
List<String> roles = (List<String>) objectPath.evaluate("roles");
assertThat(roles.size(), is(1));
assertThat(roles, contains(SecuritySettingsSource.DEFAULT_ROLE));
}
@ -70,10 +70,10 @@ public class RestAuthenticateActionTests extends SecurityIntegTestCase {
Collections.emptyMap(), null)) {
if (anonymousEnabled) {
assertThat(response.getStatusLine().getStatusCode(), is(200));
JsonPath jsonPath = new JsonPath(EntityUtils.toString(response.getEntity()));
assertThat(jsonPath.evaluate("username").toString(), equalTo("anon"));
ObjectPath objectPath = ObjectPath.createFromXContent(EntityUtils.toString(response.getEntity()));
assertThat(objectPath.evaluate("username").toString(), equalTo("anon"));
@SuppressWarnings("unchecked")
List<String> roles = (List<String>) jsonPath.evaluate("roles");
List<String> roles = (List<String>) objectPath.evaluate("roles");
assertThat(roles.size(), is(2));
assertThat(roles, contains(SecuritySettingsSource.DEFAULT_ROLE, "foo"));
} else {