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