use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImpl method getPathFilterSetPreviewJSON.
/**
* {@inheritDoc}
*/
public String getPathFilterSetPreviewJSON(final Collection<PathFilterSet> pathFilterSets) throws JSONException {
final JSONObject json = new JSONObject();
json.put(KEY_STATUS, "preview");
json.put(KEY_PATH, "Not applicable (Preview)");
json.put(KEY_FILTER_SETS, new JSONArray());
for (final PathFilterSet pathFilterSet : pathFilterSets) {
final JSONObject tmp = new JSONObject();
tmp.put(KEY_IMPORT_MODE, "Not applicable (Preview)");
tmp.put(KEY_ROOT_PATH, pathFilterSet.getRoot());
json.accumulate("filterSets", tmp);
}
return json.toString();
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class PackageHelperImplTest method testGetPreviewJSON.
@Test
public void testGetPreviewJSON() throws Exception {
final Set<Resource> resources = new HashSet<Resource>();
resources.add(slingContext.create().resource("/a/b/c"));
resources.add(slingContext.create().resource("/d/e/f"));
resources.add(slingContext.create().resource("/g/h/i"));
final String actual = packageHelper.getPreviewJSON(resources);
final JSONObject json = new JSONObject(actual);
assertEquals("preview", json.getString("status"));
assertEquals("Not applicable (Preview)", json.getString("path"));
final String[] expectedFilterSets = new String[] { "/a/b/c", "/d/e/f", "/g/h/i" };
JSONArray actualArray = json.getJSONArray("filterSets");
for (int i = 0; i < actualArray.length(); i++) {
JSONObject tmp = actualArray.getJSONObject(i);
assertTrue(ArrayUtils.contains(expectedFilterSets, tmp.get("rootPath")));
}
assertEquals(expectedFilterSets.length, actualArray.length());
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServletTest method testNamePropertyUpdater_PropertyNames.
@Test
public void testNamePropertyUpdater_PropertyNames() throws Exception {
final Map<String, Object> config = new HashMap<String, Object>();
config.put(CQIncludePropertyNamespaceServlet.PROP_NAMESPACEABLE_PROPERTY_NAMES, new String[] { "fileName", "name", "noDotSlash" });
final CQIncludePropertyNamespaceServlet servlet = new CQIncludePropertyNamespaceServlet();
servlet.activate(config);
CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater visitor = servlet.new PropertyNamespaceUpdater("test");
final JSONObject json = new JSONObject();
json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
json.put("name", "./myValue");
json.put("fileName", "./myFile");
json.put("jcr:description", "words");
json.put("noDotSlash", "no dot slash");
visitor.accept(json);
assertEquals("./test/myValue", json.get("name"));
assertEquals("./test/myFile", json.get("fileName"));
assertEquals("words", json.get("jcr:description"));
assertEquals("test/no dot slash", json.get("noDotSlash"));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServletTest method testIsCqincludeNamspaceWidget.
@Test
public void testIsCqincludeNamspaceWidget() throws JSONException {
CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater pnu = new CQIncludePropertyNamespaceServlet().new PropertyNamespaceUpdater("my-namespace");
final JSONObject json = new JSONObject();
json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
json.put("xtype", "cqinclude");
json.put("path", "/apps/test.cqinclude.namespace.test.json");
assertEquals(true, pnu.isCqincludeNamespaceWidget(json));
}
use of org.apache.sling.commons.json.JSONObject in project acs-aem-commons by Adobe-Consulting-Services.
the class CQIncludePropertyNamespaceServletTest method testMakeMultiLevel.
@Test
public void testMakeMultiLevel() throws JSONException {
CQIncludePropertyNamespaceServlet.PropertyNamespaceUpdater pnu = new CQIncludePropertyNamespaceServlet().new PropertyNamespaceUpdater("my-namespace");
final JSONObject json = new JSONObject();
json.put(JcrConstants.JCR_PRIMARYTYPE, "cq:Widget");
json.put("xtype", "cqinclude");
json.put("path", "/apps/test.cqinclude.namespace.test.json");
JSONObject actual = pnu.makeMultiLevel(json);
assertEquals("/apps/test.cqinclude.namespace.my-namespace%252Ftest.json", actual.getString("path"));
}
Aggregations