You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by pa...@apache.org on 2017/06/01 19:28:23 UTC
svn commit: r1797248 [2/3] - in /sling/trunk/launchpad/integration-tests: ./
src/main/java/org/apache/sling/launchpad/webapp/integrationtest/
src/main/java/org/apache/sling/launchpad/webapp/integrationtest/accessManager/
src/main/java/org/apache/sling/...
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/accessManager/RemoveAcesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/accessManager/RemoveAcesTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/accessManager/RemoveAcesTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/accessManager/RemoveAcesTest.java Thu Jun 1 19:28:22 2017
@@ -20,14 +20,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
/**
* Tests for the 'removeAce' Sling POST operation
@@ -65,7 +66,7 @@ public class RemoveAcesTest extends Acce
//todo delete test folder
}
- private String createFolderWithAces(boolean addGroupAce) throws IOException, JSONException {
+ private String createFolderWithAces(boolean addGroupAce) throws IOException, JsonException {
testUserId = createTestUser();
testFolderUrl = createTestFolder();
@@ -95,40 +96,40 @@ public class RemoveAcesTest extends Acce
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObject = new JSONObject(json);
+ JsonObject jsonObject = JsonUtil.parseObject(json);
if (addGroupAce) {
- assertEquals(2, jsonObject.length());
+ assertEquals(2, jsonObject.size());
} else {
- assertEquals(1, jsonObject.length());
+ assertEquals(1, jsonObject.size());
}
- JSONObject aceObject = jsonObject.optJSONObject(testUserId);
+ JsonObject aceObject = jsonObject.getJsonObject(testUserId);
assertNotNull(aceObject);
assertEquals(0, aceObject.getInt("order"));
- String principalString = aceObject.optString("principal");
+ String principalString = aceObject.getString("principal");
assertEquals(testUserId, principalString);
- JSONArray grantedArray = aceObject.optJSONArray("granted");
+ JsonArray grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals("jcr:read", grantedArray.getString(0));
- JSONArray deniedArray = aceObject.optJSONArray("denied");
+ JsonArray deniedArray = aceObject.getJsonArray("denied");
assertNotNull(deniedArray);
assertEquals("jcr:write", deniedArray.getString(0));
if (addGroupAce) {
- aceObject = jsonObject.optJSONObject(testGroupId);
+ aceObject = jsonObject.getJsonObject(testGroupId);
assertNotNull(aceObject);
- principalString = aceObject.optString("principal");
+ principalString = aceObject.getString("principal");
assertEquals(testGroupId, principalString);
assertEquals(1, aceObject.getInt("order"));
- grantedArray = aceObject.optJSONArray("granted");
+ grantedArray = aceObject.getJsonArray("granted");
assertNotNull(grantedArray);
assertEquals("jcr:read", grantedArray.getString(0));
}
@@ -137,7 +138,7 @@ public class RemoveAcesTest extends Acce
}
//test removing a single ace
- public void testRemoveAce() throws IOException, JSONException {
+ public void testRemoveAce() throws IOException, JsonException {
String folderUrl = createFolderWithAces(false);
//remove the ace for the testUser principal
@@ -153,13 +154,13 @@ public class RemoveAcesTest extends Acce
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObject = new JSONObject(json);
+ JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
- assertEquals(0, jsonObject.length());
+ assertEquals(0, jsonObject.size());
}
//test removing multiple aces
- public void testRemoveAces() throws IOException, JSONException {
+ public void testRemoveAces() throws IOException, JsonException {
String folderUrl = createFolderWithAces(true);
//remove the ace for the testUser principal
@@ -176,15 +177,15 @@ public class RemoveAcesTest extends Acce
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObject = new JSONObject(json);
+ JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
- assertEquals(0, jsonObject.length());
+ assertEquals(0, jsonObject.size());
}
/**
* Test for SLING-1677
*/
- public void testRemoveAcesResponseAsJSON() throws IOException, JSONException {
+ public void testRemoveAcesResponseAsJSON() throws IOException, JsonException {
String folderUrl = createFolderWithAces(true);
//remove the ace for the testUser principal
@@ -196,7 +197,7 @@ public class RemoveAcesTest extends Acce
String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
- JSONObject jsonObject = new JSONObject(json);
+ JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java Thu Jun 1 19:28:22 2017
@@ -27,9 +27,11 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONObject;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+
import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.testing.tools.retry.RetryLoop;
import org.apache.sling.testing.tools.retry.RetryLoop.Condition;
import org.junit.After;
@@ -79,16 +81,16 @@ public class FullTextIndexingTest {
public boolean isTrue() throws Exception {
String result = H.getContent(queryUrl, HttpTest.CONTENT_TYPE_JSON);
- JSONArray results = new JSONArray(result);
+ JsonArray results = JsonUtil.parseArray(result);
- if (results.length() == 0) {
+ if (results.size() == 0) {
return false;
}
String expectedPath = HttpTest.SERVLET_CONTEXT + uploadPath + "/" + fileName + "/jcr:content";
- for (int i = 0; i < results.length(); i++) {
- JSONObject object = results.getJSONObject(i);
+ for (int i = 0; i < results.size(); i++) {
+ JsonObject object = results.getJsonObject(i);
if (expectedPath.equals(object.getString("jcr:path"))) {
return true;
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/installer/InstallManyBundlesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/installer/InstallManyBundlesTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/installer/InstallManyBundlesTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/installer/InstallManyBundlesTest.java Thu Jun 1 19:28:22 2017
@@ -24,11 +24,12 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.testing.tools.sling.TimeoutsProvider;
import org.junit.After;
import org.junit.Before;
@@ -84,7 +85,7 @@ public class InstallManyBundlesTest {
.build();
}
- private void assertActiveBundle(String bsn, String expectedState, String expectedVersion) throws IOException, JSONException {
+ private void assertActiveBundle(String bsn, String expectedState, String expectedVersion) throws IOException, JsonException {
final String consoleUrl = HttpTest.HTTP_BASE_URL + "/system/console/bundles/" + bsn + ".json";
String state = null;
@@ -95,9 +96,9 @@ public class InstallManyBundlesTest {
while(System.currentTimeMillis() < endTime) {
try {
final String jsonStr = H.getContent(consoleUrl, HttpTest.CONTENT_TYPE_JSON);
- final JSONObject json = new JSONObject(jsonStr);
- state = json.getJSONArray("data").getJSONObject(0).getString("state");
- version = json.getJSONArray("data").getJSONObject(0).getString("version");
+ final JsonObject json = JsonUtil.parseObject(jsonStr);
+ state = json.getJsonArray("data").getJsonObject(0).getString("state");
+ version = json.getJsonArray("data").getJsonObject(0).getString("version");
if(expectedState.equalsIgnoreCase(state) && expectedVersion.equalsIgnoreCase(version)) {
return;
}
@@ -136,7 +137,7 @@ public class InstallManyBundlesTest {
return false;
}
- private void installAndCheckBundle(String bsn, int filenameVariant, String version) throws IOException, JSONException {
+ private void installAndCheckBundle(String bsn, int filenameVariant, String version) throws IOException, JsonException {
final String filename = bsn + "." + filenameVariant + ".jar";
final String url = HttpTest.HTTP_BASE_URL + INSTALL_PATH + "/" + filename;
H.getTestClient().upload(url, getBundleStream(bsn, version));
@@ -144,7 +145,7 @@ public class InstallManyBundlesTest {
}
@Test
- public void installAndUpgradeBundleManyTimes() throws IOException, JSONException {
+ public void installAndUpgradeBundleManyTimes() throws IOException, JsonException {
final String bsn = BASE_BSN + "_upgradetest";
int i = 0;
try {
@@ -162,7 +163,7 @@ public class InstallManyBundlesTest {
}
@Test
- public void installManyBundles() throws IOException, JSONException {
+ public void installManyBundles() throws IOException, JsonException {
final List<String> bsns = new ArrayList<String>();
int i = 0;
try {
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletAtDeleteTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletAtDeleteTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletAtDeleteTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletAtDeleteTest.java Thu Jun 1 19:28:22 2017
@@ -22,11 +22,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
/** Test support of @Delete suffix of SLING-458 */
@@ -59,8 +60,8 @@ public class PostServletAtDeleteTest ext
// assert property is set correctly
final String propURL = contentURL + "/" + PROP_NAME;
final String data = getContent(propURL + ".json", CONTENT_TYPE_JSON);
- final JSONObject json = new JSONObject(data);
- assertEquals(PROP_VALUE, json.get(PROP_NAME));
+ final JsonObject json = JsonUtil.parseObject(data);
+ assertEquals(PROP_VALUE, json.getString(PROP_NAME));
final List <NameValuePair> params = new LinkedList<NameValuePair> ();
params.add(new NameValuePair(PROP_NAME + SlingPostConstants.SUFFIX_DELETE, "don't care"));
@@ -81,8 +82,8 @@ public class PostServletAtDeleteTest ext
// assert property is set correctly
final String propURL = contentURL + "/" + PROP_NAME;
final String data = getContent(propURL + ".json", CONTENT_TYPE_JSON);
- final JSONObject json = new JSONObject(data);
- assertEquals(PROP_VALUE, json.get(PROP_NAME));
+ final JsonObject json = JsonUtil.parseObject(data);
+ assertEquals(PROP_VALUE, json.getString(PROP_NAME));
final List <NameValuePair> params = new LinkedList<NameValuePair> ();
params.add(new NameValuePair(PROP_NAME + SlingPostConstants.SUFFIX_DELETE, "don't care"));
@@ -93,9 +94,9 @@ public class PostServletAtDeleteTest ext
assertHttpStatus(contentURL + "/" + PROP_NAME2, HttpServletResponse.SC_OK, PROP_NAME2 + " must exist");
final String data2 = getContent(contentURL + ".json", CONTENT_TYPE_JSON);
- final JSONObject json2 = new JSONObject(data2);
- assertFalse(json2.has(PROP_VALUE));
- assertEquals(PROP_VALUE2, json2.get(PROP_NAME2));
+ final JsonObject json2 = JsonUtil.parseObject(data2);
+ assertFalse(json2.containsKey(PROP_VALUE));
+ assertEquals(PROP_VALUE2, json2.getString(PROP_NAME2));
} finally {
deleteNode(contentURL);
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCopyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCopyTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCopyTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCopyTest.java Thu Jun 1 19:28:22 2017
@@ -22,12 +22,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpStatusCodeException;
import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
/** Test node copy via the MicrojaxPostServlet */
@@ -411,8 +412,8 @@ public class PostServletCopyTest extends
// assert content test
String content = getContent(HTTP_BASE_URL + testPath
+ "/dest/src1.json", CONTENT_TYPE_JSON);
- JSONObject json = new JSONObject(content);
- assertEquals("Hello", json.get("text"));
+ final JsonObject json = JsonUtil.parseObject(content);
+ assertEquals("Hello", json.getString("text"));
// modify src1 content
nvPairs.clear();
@@ -436,8 +437,8 @@ public class PostServletCopyTest extends
// assert content test
String content2 = getContent(HTTP_BASE_URL + testPath
+ "/dest/src1.json", CONTENT_TYPE_JSON);
- JSONObject json2 = new JSONObject(content2);
- assertEquals("Modified Hello", json2.get("text"));
+ final JsonObject json2 = JsonUtil.parseObject(content2);
+ assertEquals("Modified Hello", json2.getString("text"));
// clean up
testClient.delete(testRoot);
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletImportTest.java Thu Jun 1 19:28:22 2017
@@ -30,15 +30,16 @@ import java.util.Map;
import java.util.Random;
import java.util.Set;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTestBase;
import org.apache.sling.commons.testing.integration.NameValuePairList;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
/** Test content import via the MicrojaxPostServlet */
@@ -95,27 +96,27 @@ public class PostServletImportTest exten
return tempFile;
}
- protected void assertExpectedJSON(JSONObject expectedJson, JSONObject actualJson) throws JSONException {
- Iterator<String> keys = expectedJson.keys();
+ protected void assertExpectedJSON(JsonObject expectedJson, JsonObject actualJson) throws JsonException {
+ Iterator<String> keys = expectedJson.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
Object object = expectedJson.get(key);
Object object2 = actualJson.get(key);
- if (object instanceof JSONObject) {
- assertTrue(object instanceof JSONObject);
- assertExpectedJSON((JSONObject)object, (JSONObject)object2);
- } else if (object instanceof JSONArray) {
+ if (object instanceof JsonObject) {
+ assertTrue(object2 instanceof JsonObject);
+ assertExpectedJSON((JsonObject)object, (JsonObject)object2);
+ } else if (object instanceof JsonArray) {
//compare the array
- assertTrue(object2 instanceof JSONArray);
- JSONArray actualArray = (JSONArray)object2;
+ assertTrue(object2 instanceof JsonArray);
+ JsonArray actualArray = (JsonArray)object2;
Set<Object> actualValuesSet = new HashSet<Object>();
- for (int i=0; i < actualArray.length(); i++) {
+ for (int i=0; i < actualArray.size(); i++) {
actualValuesSet.add(actualArray.get(i));
}
- JSONArray expectedArray = (JSONArray)object;
- for (int i=0; i < expectedArray.length(); i++) {
+ JsonArray expectedArray = (JsonArray)object;
+ for (int i=0; i < expectedArray.size(); i++) {
assertTrue(actualValuesSet.contains(expectedArray.get(i)));
}
} else {
@@ -127,7 +128,7 @@ public class PostServletImportTest exten
/**
* Test import operation which replaces existing content
*/
- public void testImportReplace() throws IOException, JSONException {
+ public void testImportReplace() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -155,20 +156,20 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl2 + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
- assertNull(jsonObj.optString("propTest", null)); //test property should be gone.
+ assertNull(jsonObj.get("propTest")); //test property should be gone.
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
/**
* SLING-1627: test import of content over existing content with the ':replaceProperties"
* parameter set and the ":replace" property not set.
*/
- public void testImportReplaceProperties() throws IOException, JSONException {
+ public void testImportReplaceProperties() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -190,12 +191,12 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
//2. Second, import on top of the node from #1 to replace some properties.
@@ -215,18 +216,18 @@ public class PostServletImportTest exten
// assert content at new location
String content2 = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj2 = new JSONObject(content2);
+ JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//assert the imported content is there.
String expectedJsonContent2 = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimport_replaceProps.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent2), jsonObj2);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent2), jsonObj2);
}
/**
* Test import operation which checks in versionable nodes.
*/
- public void testImportCheckinNodes() throws IOException, JSONException {
+ public void testImportCheckinNodes() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -248,7 +249,7 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert that the versionable node is checked in.
@@ -273,7 +274,7 @@ public class PostServletImportTest exten
// assert content at new location
String content2 = getContent(importedNodeUrl2 + ".json", CONTENT_TYPE_JSON);
- JSONObject jsonObj2 = new JSONObject(content2);
+ JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//assert that the versionable node is checked in.
@@ -283,7 +284,7 @@ public class PostServletImportTest exten
/**
* SLING-2108 Test import operation which auto checks out versionable nodes.
*/
- public void testImportAutoCheckoutNodes() throws IOException, JSONException {
+ public void testImportAutoCheckoutNodes() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -306,7 +307,7 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert that the versionable node is checked in.
@@ -337,15 +338,15 @@ public class PostServletImportTest exten
HttpMethod post = assertPostStatus(importedNodeUrl, HttpServletResponse.SC_CREATED, postParams, "Expected 201 status");
String responseBodyAsString = post.getResponseBodyAsString();
- JSONObject responseJSON = new JSONObject(responseBodyAsString);
- JSONArray changes = responseJSON.getJSONArray("changes");
- JSONObject checkoutChange = changes.getJSONObject(0);
+ JsonObject responseJSON = JsonUtil.parseObject(responseBodyAsString);
+ JsonArray changes = responseJSON.getJsonArray("changes");
+ JsonObject checkoutChange = changes.getJsonObject(0);
assertEquals("checkout", checkoutChange.getString("type"));
// assert content at new location
String content2 = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
- JSONObject jsonObj2 = new JSONObject(content2);
+ JsonObject jsonObj2 = JsonUtil.parseObject(content2);
assertNotNull(jsonObj2);
//make sure it was really updated
@@ -358,7 +359,7 @@ public class PostServletImportTest exten
/**
* Test import operation for a posted json file
*/
- public void testImportJSONFromFile() throws IOException, JSONException {
+ public void testImportJSONFromFile() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -379,18 +380,18 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
/**
* Test import operation for a posted json file without the optional name
*/
- public void testImportJSONFromFileWithoutOptionalName() throws IOException, JSONException {
+ public void testImportJSONFromFileWithoutOptionalName() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -412,18 +413,18 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
/**
* Test import operation for a posted json string
*/
- public void testImportJSONFromRequestParam() throws IOException, JSONException {
+ public void testImportJSONFromRequestParam() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -444,18 +445,18 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
/**
* Test import operation for a posted json string without the optional name
*/
- public void testImportJSONFromRequestParamWithoutOptionalName() throws IOException, JSONException {
+ public void testImportJSONFromRequestParamWithoutOptionalName() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -477,15 +478,15 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportXMLFromFile() throws IOException, JSONException {
+ public void testImportXMLFromFile() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -506,15 +507,15 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportXMLFromFileWithoutOptionalName() throws IOException, JSONException {
+ public void testImportXMLFromFileWithoutOptionalName() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -536,15 +537,15 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportXMLFromRequestParam() throws IOException, JSONException {
+ public void testImportXMLFromRequestParam() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -565,15 +566,15 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportXMLFromRequestParamWithoutOptionalName() throws IOException, JSONException {
+ public void testImportXMLFromRequestParamWithoutOptionalName() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -595,16 +596,16 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportZipFromFile() throws IOException, JSONException {
+ public void testImportZipFromFile() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -625,15 +626,15 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimportzip.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportJarFromFile() throws IOException, JSONException {
+ public void testImportJarFromFile() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -654,16 +655,16 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/testimportzip.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- public void testImportJCRXMLFromFile() throws IOException, JSONException {
+ public void testImportJCRXMLFromFile() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -684,18 +685,18 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
}
- protected String importNodeWithExactName(String testNodeName) throws IOException, JSONException {
+ protected String importNodeWithExactName(String testNodeName) throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -715,12 +716,12 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(location + ".3.json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
String expectedJsonContent = getStreamAsString(getClass().getResourceAsStream("/integration-test/servlets/post/importresults.json"));
- assertExpectedJSON(new JSONObject(expectedJsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(expectedJsonContent), jsonObj);
assertHttpStatus(location + DEFAULT_EXT, HttpServletResponse.SC_OK,
"POST must redirect to created resource (" + location + ")");
@@ -737,7 +738,7 @@ public class PostServletImportTest exten
/**
* SLING-1091: test create node with an exact node name (no filtering)
*/
- public void testImportNodeWithExactName() throws IOException, JSONException {
+ public void testImportNodeWithExactName() throws IOException, JsonException {
importNodeWithExactName("exactNodeName");
}
@@ -768,7 +769,7 @@ public class PostServletImportTest exten
* SLING-1091: test error reporting when attempting to import a node with an
* already used node name.
*/
- public void testImportNodeWithAlreadyUsedExactName() throws IOException, JSONException {
+ public void testImportNodeWithAlreadyUsedExactName() throws IOException, JsonException {
String testNodeName = "alreadyUsedExactNodeName";
String location = importNodeWithExactName(testNodeName);
@@ -785,7 +786,7 @@ public class PostServletImportTest exten
/**
* SLING-2143: test import where json is in a UTF-8 charset
*/
- public void testImportJSONWithUTF8Content() throws IOException, JSONException {
+ public void testImportJSONWithUTF8Content() throws IOException, JsonException {
final String testPath = TEST_BASE_PATH;
Map<String, String> props = new HashMap<String, String>();
String testNode = testClient.createNode(HTTP_BASE_URL + testPath, props);
@@ -807,11 +808,11 @@ public class PostServletImportTest exten
// assert content at new location
String content = getContent(importedNodeUrl + ".json", CONTENT_TYPE_JSON);
- JSONObject jsonObj = new JSONObject(content);
+ JsonObject jsonObj = JsonUtil.parseObject(content);
assertNotNull(jsonObj);
//assert the imported content is there.
- assertExpectedJSON(new JSONObject(jsonContent), jsonObj);
+ assertExpectedJSON(JsonUtil.parseObject(jsonContent), jsonObj);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletMoveTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletMoveTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletMoveTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletMoveTest.java Thu Jun 1 19:28:22 2017
@@ -22,12 +22,13 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpStatusCodeException;
import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
/** Test node move via the MicrojaxPostServlet */
@@ -440,8 +441,8 @@ public class PostServletMoveTest extends
// assert content test
String content = getContent(HTTP_BASE_URL + testPath
+ "/dest/src1.json", CONTENT_TYPE_JSON);
- JSONObject json = new JSONObject(content);
- assertEquals("Hello", json.get("text"));
+ JsonObject json = JsonUtil.parseObject(content);
+ assertEquals("Hello", json.getString("text"));
// modify src1 content
nvPairs.clear();
@@ -466,8 +467,8 @@ public class PostServletMoveTest extends
// assert content test
String content2 = getContent(HTTP_BASE_URL + testPath
+ "/dest/src1.json", CONTENT_TYPE_JSON);
- JSONObject json2 = new JSONObject(content2);
- assertEquals("Modified Hello", json2.get("text"));
+ JsonObject json2 = JsonUtil.parseObject(content2);
+ assertEquals("Modified Hello", json2.getString("text"));
// clean up
testClient.delete(testRoot);
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletOrderTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletOrderTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletOrderTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletOrderTest.java Thu Jun 1 19:28:22 2017
@@ -20,10 +20,12 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+
import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
/** Test the order option for node creation via the MicrojaxPostServlet */
public class PostServletOrderTest extends HttpTestBase {
@@ -192,17 +194,16 @@ public class PostServletOrderTest extend
//assertJavascript(expected, content, TEST_SCRIPT);
try {
String actual = "";
- JSONObject obj = new JSONObject(content);
- JSONArray n = obj.names();
- for (int i=0; i<n.length(); i++) {
- String name = n.getString(i);
+ JsonObject obj = JsonUtil.parseObject(content);
+
+ for (String name : obj.keySet()) {
Object o = obj.get(name);
- if (o instanceof JSONObject) {
+ if (o instanceof JsonObject) {
actual += name + ",";
}
}
assertEquals(expected, actual);
- } catch (JSONException e) {
+ } catch (JsonException e) {
throw new IOException(e.toString());
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPrivilegesUpdateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPrivilegesUpdateTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPrivilegesUpdateTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPrivilegesUpdateTest.java Thu Jun 1 19:28:22 2017
@@ -35,18 +35,20 @@ import javax.jcr.observation.Event;
import javax.jcr.observation.EventIterator;
import javax.jcr.observation.EventListener;
import javax.jcr.observation.ObservationManager;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
+import javax.json.JsonString;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTest;
import org.apache.sling.commons.testing.integration.NameValuePairList;
import org.apache.sling.launchpad.webapp.integrationtest.AuthenticatedTestUtil;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.junit.After;
import org.junit.Before;
@@ -93,7 +95,7 @@ public class PostServletPrivilegesUpdate
*/
@Test
@Ignore // TODO fails on jackrabbit 2.6.5 and on Oak
- public void testUpdatePropertyPrivilegesAndEvents() throws IOException, JSONException, RepositoryException, InterruptedException {
+ public void testUpdatePropertyPrivilegesAndEvents() throws IOException, JsonException, RepositoryException, InterruptedException {
//1. Create user as admin (OK)
// curl -F:name=myuser -Fpwd=password -FpwdConfirm=password http://admin:admin@localhost:8080/system/userManager/user.create.html
testUserId = H.createTestUser();
@@ -109,16 +111,16 @@ public class PostServletPrivilegesUpdate
String testNodeUrl = H.getTestClient().createNode(createTestNodeUrl, clientNodeProperties, null, false);
String content = H.getContent(testNodeUrl + ".json", HttpTest.CONTENT_TYPE_JSON);
- JSONObject json = new JSONObject(content);
- Object propOneObj = json.opt("propOne");
- assertTrue(propOneObj instanceof JSONArray);
- assertEquals(2, ((JSONArray)propOneObj).length());
- assertEquals("propOneValue1", ((JSONArray)propOneObj).get(0));
- assertEquals("propOneValue2", ((JSONArray)propOneObj).get(1));
+ JsonObject json = JsonUtil.parseObject(content);
+ Object propOneObj = json.get("propOne");
+ assertTrue(propOneObj instanceof JsonArray);
+ assertEquals(2, ((JsonArray)propOneObj).size());
+ assertEquals("propOneValue1", ((JsonArray)propOneObj).getString(0));
+ assertEquals("propOneValue2", ((JsonArray)propOneObj).getString(1));
- Object propTwoObj = json.opt("propTwo");
- assertTrue(propTwoObj instanceof String);
- assertEquals("propTwoValue", propTwoObj);
+ Object propTwoObj = json.get("propTwo");
+ assertTrue(propTwoObj instanceof JsonString);
+ assertEquals("propTwoValue", ((JsonString) propTwoObj).getString());
//3. Attempt to update property of node as testUser (500: javax.jcr.AccessDeniedException: /test/node/propOne: not allowed to add or modify item)
@@ -161,17 +163,17 @@ public class PostServletPrivilegesUpdate
//verify the change happened
String afterUpdateContent = H.getContent(testNodeUrl + ".json", HttpTest.CONTENT_TYPE_JSON);
- JSONObject afterUpdateJson = new JSONObject(afterUpdateContent);
- Object afterUpdatePropOneObj = afterUpdateJson.opt("propOne");
- assertTrue(afterUpdatePropOneObj instanceof JSONArray);
- assertEquals(1, ((JSONArray)afterUpdatePropOneObj).length());
- assertEquals("propOneValueChanged", ((JSONArray)afterUpdatePropOneObj).get(0));
+ JsonObject afterUpdateJson = JsonUtil.parseObject(afterUpdateContent);
+ Object afterUpdatePropOneObj = afterUpdateJson.get("propOne");
+ assertTrue(afterUpdatePropOneObj instanceof JsonArray);
+ assertEquals(1, ((JsonArray)afterUpdatePropOneObj).size());
+ assertEquals("propOneValueChanged", ((JsonArray)afterUpdatePropOneObj).getString(0));
- Object afterUpdatePropTwoObj = afterUpdateJson.opt("propTwo");
- assertTrue(afterUpdatePropTwoObj instanceof JSONArray);
- assertEquals(2, ((JSONArray)afterUpdatePropTwoObj).length());
- assertEquals("propTwoValueChanged1", ((JSONArray)afterUpdatePropTwoObj).get(0));
- assertEquals("propTwoValueChanged2", ((JSONArray)afterUpdatePropTwoObj).get(1));
+ Object afterUpdatePropTwoObj = afterUpdateJson.get("propTwo");
+ assertTrue(afterUpdatePropTwoObj instanceof JsonArray);
+ assertEquals(2, ((JsonArray)afterUpdatePropTwoObj).size());
+ assertEquals("propTwoValueChanged1", ((JsonArray)afterUpdatePropTwoObj).getString(0));
+ assertEquals("propTwoValueChanged2", ((JsonArray)afterUpdatePropTwoObj).getString(1));
//wait for the expected JCR events to be delivered
for (int second = 0; second < 15; second++) {
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletUpdateTest.java Thu Jun 1 19:28:22 2017
@@ -18,30 +18,18 @@ package org.apache.sling.launchpad.webap
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
-import javax.jcr.observation.Event;
-import javax.jcr.observation.EventIterator;
-import javax.jcr.observation.EventListener;
-import javax.jcr.observation.ObservationManager;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
-import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
-import org.apache.sling.commons.testing.integration.NameValuePairList;
import org.apache.sling.launchpad.webapp.integrationtest.AuthenticatedTestUtil;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
/** Test node updates via the MicrojaxPostServlet */
@@ -147,7 +135,7 @@ public void testPostPathIsUnique() throw
assertTrue(content.indexOf("\"g\":\"456\"") > 0);
}
- public void testMixinTypes() throws IOException, JSONException {
+ public void testMixinTypes() throws IOException, JsonException {
// create a node without mixin node types
final Map <String, String> props = new HashMap <String, String> ();
@@ -156,8 +144,8 @@ public void testPostPathIsUnique() throw
// assert no mixins
String content = getContent(location + ".json", CONTENT_TYPE_JSON);
- JSONObject json = new JSONObject(content);
- assertFalse("jcr:mixinTypes not expected to be set", json.has("jcr:mixinTypes"));
+ JsonObject json = JsonUtil.parseObject(content);
+ assertFalse("jcr:mixinTypes not expected to be set", json.containsKey("jcr:mixinTypes"));
// add mixin
props.clear();
@@ -165,15 +153,15 @@ public void testPostPathIsUnique() throw
testClient.createNode(location, props);
content = getContent(location + ".json", CONTENT_TYPE_JSON);
- json = new JSONObject(content);
- assertTrue("jcr:mixinTypes expected after setting them", json.has("jcr:mixinTypes"));
+ json = JsonUtil.parseObject(content);
+ assertTrue("jcr:mixinTypes expected after setting them", json.containsKey("jcr:mixinTypes"));
Object mixObject = json.get("jcr:mixinTypes");
- assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JSONArray);
+ assertTrue("jcr:mixinTypes must be an array", mixObject instanceof JsonArray);
- JSONArray mix = (JSONArray) mixObject;
- assertTrue("jcr:mixinTypes must have a single entry", mix.length() == 1);
- assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.get(0));
+ JsonArray mix = (JsonArray) mixObject;
+ assertTrue("jcr:mixinTypes must have a single entry", mix.size() == 1);
+ assertEquals("jcr:mixinTypes must have correct value", "mix:versionable", mix.getString(0));
// remove mixin
props.clear();
@@ -181,12 +169,12 @@ public void testPostPathIsUnique() throw
testClient.createNode(location, props);
content = getContent(location + ".json", CONTENT_TYPE_JSON);
- json = new JSONObject(content);
- final boolean noMixins = !json.has("jcr:mixinTypes") || json.getJSONArray("jcr:mixinTypes").length() == 0;
+ json = JsonUtil.parseObject(content);
+ final boolean noMixins = !json.containsKey("jcr:mixinTypes") || json.getJsonArray("jcr:mixinTypes").size() == 0;
assertTrue("no jcr:mixinTypes expected after clearing it", noMixins);
}
- public void testUpdatingNodetype() throws IOException, JSONException {
+ public void testUpdatingNodetype() throws IOException, JsonException {
// create a node without mixin node types
final Map <String, String> props = new HashMap <String, String> ();
@@ -195,7 +183,7 @@ public void testPostPathIsUnique() throw
// assert correct nodetype
String content = getContent(location + ".json", CONTENT_TYPE_JSON);
- JSONObject json = new JSONObject(content);
+ JsonObject json = JsonUtil.parseObject(content);
assertTrue("jcr:primaryType isn't set correctly", json.getString("jcr:primaryType").equals("nt:unstructured"));
// change nodetype
@@ -205,7 +193,7 @@ public void testPostPathIsUnique() throw
// assert correct nodetype
content = getContent(location + ".json", CONTENT_TYPE_JSON);
- json = new JSONObject(content);
+ json = JsonUtil.parseObject(content);
assertTrue("jcr:primaryType isn't set correctly", json.getString("jcr:primaryType").equals("sling:Folder"));
}
}
\ No newline at end of file
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/ReferenceTypeHintTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/ReferenceTypeHintTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/ReferenceTypeHintTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/ReferenceTypeHintTest.java Thu Jun 1 19:28:22 2017
@@ -20,10 +20,12 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONObject;
+import javax.json.JsonArray;
+import javax.json.JsonObject;
+
import org.apache.sling.commons.testing.integration.HttpTestBase;
import org.apache.sling.commons.testing.integration.NameValuePairList;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.custommonkey.xmlunit.NamespaceContext;
import org.custommonkey.xmlunit.SimpleNamespaceContext;
@@ -141,10 +143,10 @@ public class ReferenceTypeHintTest exten
}
private String[] getPropertyArray(String url, String name) throws Exception {
- JSONObject jo = new JSONObject(getContent(url + "/" + name + ".json", CONTENT_TYPE_JSON));
- JSONArray arr = jo.getJSONArray(name);
- String[] result = new String[arr.length()];
- for (int i = 0; i < arr.length(); i++) {
+ JsonObject jo = JsonUtil.parseObject(getContent(url + "/" + name + ".json", CONTENT_TYPE_JSON));
+ JsonArray arr = jo.getJsonArray(name);
+ String[] result = new String[arr.size()];
+ for (int i = 0; i < arr.size(); i++) {
result[i] = arr.getString(i);
}
return result;
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateGroupTest.java Thu Jun 1 19:28:22 2017
@@ -21,13 +21,14 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
/**
* Tests for the 'createGroup' Sling Post Operation
@@ -49,7 +50,7 @@ public class CreateGroupTest extends Use
super.tearDown();
}
- public void testCreateGroup() throws IOException, JSONException {
+ public void testCreateGroup() throws IOException, JsonException {
String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
testGroupId = "testGroup" + random.nextInt();
@@ -63,7 +64,7 @@ public class CreateGroupTest extends Use
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testGroupId, jsonObj.getString("marker"));
}
@@ -86,7 +87,7 @@ public class CreateGroupTest extends Use
assertAuthenticatedAdminPostStatus(postUrl, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, postParams, null);
}
- public void testCreateGroupWithExtraProperties() throws IOException, JSONException {
+ public void testCreateGroupWithExtraProperties() throws IOException, JsonException {
String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.html";
testGroupId = "testGroup" + random.nextInt();
@@ -102,7 +103,7 @@ public class CreateGroupTest extends Use
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testGroupId, jsonObj.getString("marker"));
assertEquals("My Test Group", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org", jsonObj.getString("url"));
@@ -112,7 +113,7 @@ public class CreateGroupTest extends Use
/**
* Test for SLING-1677
*/
- public void testCreateGroupResponseAsJSON() throws IOException, JSONException {
+ public void testCreateGroupResponseAsJSON() throws IOException, JsonException {
String postUrl = HTTP_BASE_URL + "/system/userManager/group.create.json";
testGroupId = "testGroup" + random.nextInt();
@@ -123,7 +124,7 @@ public class CreateGroupTest extends Use
String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/CreateUserTest.java Thu Jun 1 19:28:22 2017
@@ -25,14 +25,15 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -71,7 +72,7 @@ public class CreateUserTest {
</form>
*/
@Test
- public void testCreateUser() throws IOException, JSONException {
+ public void testCreateUser() throws IOException, JsonException {
testUserId = "testUser" + random.nextInt() + System.currentTimeMillis();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
final List<NameValuePair> postParams = new ArrayList<NameValuePair>();
@@ -87,11 +88,11 @@ public class CreateUserTest {
final String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
final String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- final JSONObject jsonObj = new JSONObject(json);
+ final JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("marker"));
- assertFalse(jsonObj.has(":name"));
- assertFalse(jsonObj.has("pwd"));
- assertFalse(jsonObj.has("pwdConfirm"));
+ assertFalse(jsonObj.containsKey(":name"));
+ assertFalse(jsonObj.containsKey("pwd"));
+ assertFalse(jsonObj.containsKey("pwdConfirm"));
}
{
@@ -100,7 +101,7 @@ public class CreateUserTest {
final String getUrl = HttpTest.HTTP_BASE_URL + "/system/sling/info.sessionInfo.json";
final String json = H.getAuthenticatedContent(newUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- final JSONObject jsonObj = new JSONObject(json);
+ final JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("userID"));
}
}
@@ -165,7 +166,7 @@ public class CreateUserTest {
</form>
*/
@Test
- public void testCreateUserWithExtraProperties() throws IOException, JSONException {
+ public void testCreateUserWithExtraProperties() throws IOException, JsonException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.html";
testUserId = "testUser" + random.nextInt();
@@ -183,13 +184,13 @@ public class CreateUserTest {
String getUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(testUserId, jsonObj.getString("marker"));
assertEquals("My Test User", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org", jsonObj.getString("url"));
- assertFalse(jsonObj.has(":name"));
- assertFalse(jsonObj.has("pwd"));
- assertFalse(jsonObj.has("pwdConfirm"));
+ assertFalse(jsonObj.containsKey(":name"));
+ assertFalse(jsonObj.containsKey("pwd"));
+ assertFalse(jsonObj.containsKey("pwdConfirm"));
}
/**
@@ -215,7 +216,7 @@ public class CreateUserTest {
* Test for SLING-1677
*/
@Test
- public void testCreateUserResponseAsJSON() throws IOException, JSONException {
+ public void testCreateUserResponseAsJSON() throws IOException, JsonException {
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user.create.json";
testUserId = "testUser" + random.nextInt();
@@ -228,7 +229,7 @@ public class CreateUserTest {
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 = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/RemoveAuthorizablesTest.java Thu Jun 1 19:28:22 2017
@@ -20,13 +20,14 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
/**
* Tests for the 'removeAuthorizable' Sling Post Operation
@@ -118,7 +119,7 @@ public class RemoveAuthorizablesTest ext
/**
* Test for SLING-1677
*/
- public void testRemoveAuthorizablesResponseAsJSON() throws IOException, JSONException {
+ public void testRemoveAuthorizablesResponseAsJSON() throws IOException, JsonException {
String userId = createTestUser();
String groupId = createTestGroup();
@@ -131,7 +132,7 @@ public class RemoveAuthorizablesTest ext
String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateGroupTest.java Thu Jun 1 19:28:22 2017
@@ -20,14 +20,15 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.json.JsonArray;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONArray;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
/**
* Tests for the 'updateAuthorizable' Sling Post Operation on
@@ -58,7 +59,7 @@ public class UpdateGroupTest extends Use
super.tearDown();
}
- public void testUpdateGroup() throws IOException, JSONException {
+ public void testUpdateGroup() throws IOException, JsonException {
testGroupId = createTestGroup();
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
@@ -75,23 +76,23 @@ public class UpdateGroupTest extends Use
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals("My Updated Test Group", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
}
- public void testUpdateGroupMembers() throws IOException, JSONException {
+ public void testUpdateGroupMembers() throws IOException, JsonException {
testGroupId = createTestGroup();
testUserId = createTestUser();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
// verify that the members array exists, but is empty
- JSONArray members = getTestGroupMembers(creds);
- assertEquals(0, members.length());
+ JsonArray members = getTestGroupMembers(creds);
+ assertEquals(0, members.size());
- JSONArray memberships = getTestUserMemberships(creds);
- assertEquals(0, memberships.length());
+ JsonArray memberships = getTestUserMemberships(creds);
+ assertEquals(0, memberships.size());
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
@@ -101,11 +102,11 @@ public class UpdateGroupTest extends Use
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
- assertEquals(1, members.length());
+ assertEquals(1, members.size());
assertEquals("/system/userManager/user/" + testUserId, members.getString(0));
memberships = getTestUserMemberships(creds);
- assertEquals(1, memberships.length());
+ assertEquals(1, memberships.size());
assertEquals("/system/userManager/group/" + testGroupId, memberships.getString(0));
// delete a group member
@@ -114,37 +115,37 @@ public class UpdateGroupTest extends Use
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
members = getTestGroupMembers(creds);
- assertEquals(0, members.length());
+ assertEquals(0, members.size());
memberships = getTestUserMemberships(creds);
- assertEquals(0, memberships.length());
+ assertEquals(0, memberships.size());
}
- JSONArray getTestUserMemberships(Credentials creds) throws IOException, JSONException {
+ JsonArray getTestUserMemberships(Credentials creds) throws IOException, JsonException {
String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
- JSONArray memberships = jsonObj.getJSONArray("memberOf");
+ JsonObject jsonObj = JsonUtil.parseObject(json);
+ JsonArray memberships = jsonObj.getJsonArray("memberOf");
return memberships;
}
- JSONArray getTestGroupMembers(Credentials creds) throws IOException, JSONException {
+ JsonArray getTestGroupMembers(Credentials creds) throws IOException, JsonException {
String getUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
- JSONArray members = jsonObj.getJSONArray("members");
+ JsonObject jsonObj = JsonUtil.parseObject(json);
+ JsonArray members = jsonObj.getJsonArray("members");
return members;
}
/**
* Test for SLING-1677
*/
- public void testUpdateGroupResponseAsJSON() throws IOException, JSONException {
+ public void testUpdateGroupResponseAsJSON() throws IOException, JsonException {
testGroupId = createTestGroup();
String postUrl = HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.json";
@@ -157,7 +158,7 @@ public class UpdateGroupTest extends Use
String json = getAuthenticatedPostContent(creds, postUrl, CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java?rev=1797248&r1=1797247&r2=1797248&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/userManager/UpdateUserTest.java Thu Jun 1 19:28:22 2017
@@ -24,15 +24,16 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+import javax.json.JsonException;
+import javax.json.JsonObject;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
-import org.apache.sling.commons.json.JSONException;
-import org.apache.sling.commons.json.JSONObject;
import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.launchpad.webapp.integrationtest.util.JsonUtil;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -64,7 +65,7 @@ public class UpdateUserTest {
}
@Test
- public void testUpdateUser() throws IOException, JSONException {
+ public void testUpdateUser() throws IOException, JsonException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.html";
@@ -82,7 +83,7 @@ public class UpdateUserTest {
H.assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
String json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- JSONObject jsonObj = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals("My Updated Test User", jsonObj.getString("displayName"));
assertEquals("http://www.apache.org/updated", jsonObj.getString("url"));
// get path (SLING-6753)
@@ -92,7 +93,7 @@ public class UpdateUserTest {
getUrl = HttpTest.HTTP_BASE_URL + path + "/nested.json";
json = H.getAuthenticatedContent(creds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
- jsonObj = new JSONObject(json);
+ jsonObj = JsonUtil.parseObject(json);
assertEquals("value", jsonObj.getString("param"));
}
@@ -147,7 +148,7 @@ public class UpdateUserTest {
* Test for SLING-1677
*/
@Test
- public void testUpdateUserResponseAsJSON() throws IOException, JSONException {
+ public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";
@@ -159,7 +160,7 @@ public class UpdateUserTest {
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 = new JSONObject(json);
+ JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}