Search in sources :

Example 76 with JsonObject

use of javax.json.JsonObject in project sling by apache.

the class UserPrivilegesInfoTest method testCanAddGroup.

/**
	 * Checks whether the current user has been granted privileges
	 * to add a new group.
	 */
@Test
public void testCanAddGroup() throws IOException, JsonException {
    testUserId = H.createTestUser();
    String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".privileges-info.json";
    //fetch the JSON for the test page to verify the settings.
    Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
    String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals(false, jsonObj.getBoolean("canAddGroup"));
}
Also used : JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Example 77 with JsonObject

use of javax.json.JsonObject in project sling by apache.

the class RepositoryTestUtil method getDescriptor.

public static String getDescriptor(HttpTestBase H, String descriptorName) throws JsonException, IOException {
    final String path = "/testing/RepositoryDescriptors.json";
    final JsonObject json = JsonUtil.parseObject(H.getContent(HttpTest.HTTP_BASE_URL + path, HttpTest.CONTENT_TYPE_JSON));
    return json.getJsonObject("descriptors").getString(descriptorName);
}
Also used : JsonObject(javax.json.JsonObject)

Example 78 with JsonObject

use of javax.json.JsonObject in project sling by apache.

the class UpdateGroupTest method getTestGroupMembers.

JsonArray getTestGroupMembers(Credentials creds) throws IOException, JsonException {
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    JsonArray members = jsonObj.getJsonArray("members");
    return members;
}
Also used : JsonArray(javax.json.JsonArray) JsonObject(javax.json.JsonObject)

Example 79 with JsonObject

use of javax.json.JsonObject in project sling by apache.

the class UpdateGroupTest method testUpdateGroup.

public void testUpdateGroup() throws IOException, JsonException {
    testGroupId = createTestGroup();
    String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test Group"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
    Credentials creds = new UsernamePasswordCredentials("admin", "admin");
    assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
    //fetch the user profile json to verify the settings
    String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
    //make sure the profile request returns some data
    assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null);
    String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
    assertNotNull(json);
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertEquals("My Updated Test Group", jsonObj.getString("displayName"));
    assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 80 with JsonObject

use of javax.json.JsonObject in project sling by apache.

the class UpdateUserTest method testUpdateUserResponseAsJSON.

/**
	 * Test for SLING-1677
	 */
@Test
public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
    testUserId = H.createTestUser();
    String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";
    List<NameValuePair> postParams = new ArrayList<NameValuePair>();
    postParams.add(new NameValuePair("displayName", "My Updated Test User"));
    postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
    Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
    String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
    //make sure the json response can be parsed as a JSON object
    JsonObject jsonObj = JsonUtil.parseObject(json);
    assertNotNull(jsonObj);
}
Also used : NameValuePair(org.apache.commons.httpclient.NameValuePair) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) Credentials(org.apache.commons.httpclient.Credentials) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials) HttpTest(org.apache.sling.commons.testing.integration.HttpTest) Test(org.junit.Test)

Aggregations

JsonObject (javax.json.JsonObject)302 Test (org.junit.Test)110 JsonArray (javax.json.JsonArray)97 HashMap (java.util.HashMap)68 StringReader (java.io.StringReader)66 ArrayList (java.util.ArrayList)58 Credentials (org.apache.commons.httpclient.Credentials)52 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)52 JsonString (javax.json.JsonString)50 JsonReader (javax.json.JsonReader)49 NameValuePair (org.apache.commons.httpclient.NameValuePair)43 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)41 HashSet (java.util.HashSet)20 Map (java.util.Map)20 JsonException (javax.json.JsonException)20 JsonObjectBuilder (javax.json.JsonObjectBuilder)20 Response (javax.ws.rs.core.Response)19 LinkedHashMap (java.util.LinkedHashMap)17 JsonValue (javax.json.JsonValue)14 StringWriter (java.io.StringWriter)13