diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.delete.desc.xml
index 7b60519957..0a1b94b87a 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.delete.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.delete.desc.xml
@@ -3,8 +3,9 @@
Delete (uninvite) the membership for a user.
Sandboxes are deleted even if they have unsubmitted content.
- /api/wcm/webproject/{webprojectref}/membership/{username}
+ /api/wcm/webprojects/{webprojectref}/memberships/{username}
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.desc.xml
index e908e44b56..7ec4233fa6 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.desc.xml
@@ -1,8 +1,9 @@
Membership
Get the webproject membership details for a user
- /api/wcm/webproject/{webprojectref}/membership/{username}
+ /api/wcm/webprojects/{webprojectref}/memberships/{username}
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.json.ftl
index e458c4e9df..c9585b29bd 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/membership.get.json.ftl
@@ -1,2 +1,4 @@
<#import "membership.lib.ftl" as membershipLib/>
-<@membershipLib.membershipJSON webproject=webproject role=role person=person/>
\ No newline at end of file
+{
+ data:<@membershipLib.membershipJSON webproject=webproject role=role person=person/>
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.desc.xml
index fba083e686..37b1767c2b 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.desc.xml
@@ -1,8 +1,9 @@
Memberships
Get a collection of a web project memberships.
- /api/wcm/webproject/{webprojectref}/memberships
+ /api/wcm/webprojects/{webprojectref}/memberships
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.json.ftl
index 1347e2ee2c..cca409b17a 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.get.json.ftl
@@ -1,11 +1,12 @@
<#import "membership.lib.ftl" as membershipLib/>
-[
-<#if memberships??>
+{
+ data:[
+ <#if memberships??>
<#assign userNames = memberships?keys />
<#list userNames as userName>
<@membershipLib.membershipJSON webproject=webproject role=memberships[userName] person=people[userName]/>
<#if userName_has_next>,#if>
#list>
- #if>
-]
-
+ #if>
+ ]
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.desc.xml
index ac247fb169..4f6d942ec8 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.desc.xml
@@ -1,8 +1,9 @@
Invite user to web project
Adds a new membership to the web project
- /api/wcm/webproject/{webprojectref}/memberships
+ /api/wcm/webprojects/{webprojectref}/memberships
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.json.ftl
index e458c4e9df..c9585b29bd 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/membership/memberships.post.json.ftl
@@ -1,2 +1,4 @@
<#import "membership.lib.ftl" as membershipLib/>
-<@membershipLib.membershipJSON webproject=webproject role=role person=person/>
\ No newline at end of file
+{
+ data:<@membershipLib.membershipJSON webproject=webproject role=role person=person/>
+}
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.lib.ftl
new file mode 100644
index 0000000000..980f545511
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.lib.ftl
@@ -0,0 +1,12 @@
+<#macro assetJSON asset>
+ {
+ "path" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.path}" #escape>,
+ "name" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.name}" #escape>,
+ "creator" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.creator}" #escape>,
+ "createdDate" : { "iso8601" : "${sandbox.createdDateAsISO8601}" },
+ "modifier" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.modifier}" #escape>,
+ "isFile" : ${asset.file?string("true", "false")},
+ "isDirectory" : ${asset.directory?string("true", "false")},
+ "isDeleted" : ${asset.deleted?string("true", "false")}
+ }
+#macro>
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.desc.xml
new file mode 100644
index 0000000000..3721b2fd8c
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.desc.xml
@@ -0,0 +1,18 @@
+
+ Get modified assets within the specified sandbox.
+
+
+ If a directory has been added then only the directory's properties are returned (not directory plus assets within that new directory).
+
+ If the optional webApp argument is specified then returns the modified assets within that web app.
+ ]]>
+
+ /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/modified
+ /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/modified?webApp={webApp?}
+
+ user
+ required
+ WCM Service
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.js
new file mode 100644
index 0000000000..2875b2c127
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.js
@@ -0,0 +1,45 @@
+/*
+ * Get the modified items within a sandbox
+ */
+function main()
+{
+ var urlElements = url.extension.split("/");
+ var shortName = urlElements[0];
+ var boxName = urlElements[2];
+
+ var sandbox;
+
+ var webproject = webprojects.getWebProject(shortName);
+ if (webproject == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The webproject, " + shortName + ", does not exist.");
+ return;
+ }
+
+ sandbox = webproject.getSandbox(boxName);
+ if (sandbox == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The sandbox, " + boxName + ", in webproject, " + shortName + ", does not exist.");
+ return;
+ }
+
+ var webApp = args["webApp"];
+
+ // set model properties
+ model.sandbox = sandbox;
+ model.webproject = webproject;
+
+ if(webApp != null)
+ {
+ model.assets = sandbox.modifiedAssets(webApp);
+ }
+ else
+ {
+ model.assets = sandbox.modifiedAssets;
+ }
+}
+
+main()
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.json.ftl
new file mode 100644
index 0000000000..1718b2c5bb
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/modified.get.json.ftl
@@ -0,0 +1,11 @@
+<#import "asset.lib.ftl" as assetLib/>
+{
+ data: [
+ <#list assets as asset>
+ <@assetLib.assetJSON asset=asset />
+ <#if asset_has_next>,#if>
+ #list>
+ ]
+}
+
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.desc.xml
new file mode 100644
index 0000000000..9a2122a2b7
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.desc.xml
@@ -0,0 +1,10 @@
+
+ Delete Sandbox
+ Deletes a WCM sandbox and all its contents.
+
+
+ /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxRef}
+ user
+ required
+ WCM Service
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.js
new file mode 100644
index 0000000000..85ca6986fb
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.js
@@ -0,0 +1,43 @@
+
+/**
+ * Delete a wcm web project sandbox
+ */
+
+function main() {
+
+
+ var urlElements = url.extension.split("/");
+ var webprojectref = urlElements[0];
+ var boxName = urlElements[2];
+
+ if (webprojectref == null || webprojectref.length == 0)
+ {
+ status.setCode(status.STATUS_BAD_REQUEST, "Delete sandbox. webprojectref missing or blank");
+ return;
+ }
+
+ var webproject = webprojects.getWebProject(webprojectref);
+
+
+ if(webproject != null)
+ {
+ var sandbox = webproject.getSandbox(boxName);
+ if(sandbox != null)
+ {
+ sandbox.deleteSandbox();
+ status.setCode(status.STATUS_OK, "Webproject " + webprojectref + " deleted");
+ }
+ else
+ {
+ status.setCode(status.STATUS_NOT_FOUND, "Unable to delete : Webproject: " + webprojectref + "Sandbox: " + boxName + ", does not exist");
+ }
+ }
+ else
+ {
+ // Return 404
+ status.setCode(status.STATUS_NOT_FOUND, "Unable to delete : Webproject: " + webprojectref + " does not exist");
+ return;
+ }
+}
+
+main()
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.json.ftl
new file mode 100644
index 0000000000..0967ef424b
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.delete.json.ftl
@@ -0,0 +1 @@
+{}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.desc.xml
new file mode 100644
index 0000000000..c291d480a2
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.desc.xml
@@ -0,0 +1,9 @@
+
+ Get Web Project Sandbox
+ Get a single sandbox of a web project.
+ /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}
+
+ user
+ required
+ WCM Service
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.js
new file mode 100644
index 0000000000..fb476cce3e
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.js
@@ -0,0 +1,34 @@
+/*
+ * Get the sandbox for a web project
+ */
+function main()
+{
+ var urlElements = url.extension.split("/");
+ var shortName = urlElements[0];
+ var boxName = urlElements[2];
+
+ var sandbox;
+
+ var webproject = webprojects.getWebProject(shortName);
+ if (webproject == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The webproject, " + shortName + ", does not exist.");
+ return;
+ }
+
+ sandbox = webproject.getSandbox(boxName);
+ if (sandbox == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The sandbox, " + boxName + ", in webproject, " + shortName + ", does not exist.");
+ return;
+ }
+
+
+ model.sandbox = sandbox;
+ model.webproject = webproject;
+}
+
+main()
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.json.ftl
new file mode 100644
index 0000000000..2d4e24ab56
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.get.json.ftl
@@ -0,0 +1,6 @@
+<#import "sandbox.lib.ftl" as sandboxLib/>
+{
+ data:<@sandboxLib.sandboxJSON webproject=webproject sandbox=sandbox/>
+}
+
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.lib.ftl
new file mode 100644
index 0000000000..511902e881
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.lib.ftl
@@ -0,0 +1,17 @@
+<#macro sandboxJSON webproject sandbox>
+ <#escape x as jsonUtils.encodeJSONString(x)>
+ {
+ "sandboxref" : "${sandbox.sandboxRef}",
+ "name" : "${sandbox.name}",
+ "creator" : "${sandbox.creator}",
+ "createdDate" : { "iso8601" : "${sandbox.createdDateAsISO8601}" },
+ "storeNames" : [
+ <#assign names = sandbox.storeNames />
+ <#list names as name>
+ "${name}" <#if name_has_next>,#if>
+ #list>
+ ],
+ "url" : "${url.serviceContext + "/api/wcm/webprojects/" + webproject.webProjectRef + "/sandboxes/" + sandbox.sandboxRef}"
+ }
+ #escape>
+#macro>
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.desc.xml
new file mode 100644
index 0000000000..035ec0da1d
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.desc.xml
@@ -0,0 +1,18 @@
+
+ Create user sandbox
+ The following fields are required in the body of the request:
+
+
+ Returns STATUS_CREATED on success.
+ ]]>
+
+
+ /api/wcm/webprojects/{webprojectref}/sandboxes
+ user
+ required
+ WCM Service
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.ftl
new file mode 100644
index 0000000000..2d4e24ab56
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.ftl
@@ -0,0 +1,6 @@
+<#import "sandbox.lib.ftl" as sandboxLib/>
+{
+ data:<@sandboxLib.sandboxJSON webproject=webproject sandbox=sandbox/>
+}
+
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.js
new file mode 100644
index 0000000000..ea76951a1b
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandbox.post.json.js
@@ -0,0 +1,40 @@
+
+/**
+ * Post (create) wcm web project
+ * @return the wcm web project ref
+ */
+
+function main() {
+
+ if (!json.has("userName"))
+ {
+ status.setCode(status.STATUS_BAD_REQUEST, "property 'userName' missing when creating sandbox");
+ return;
+ }
+
+ var userName = json.get("userName");
+
+ if (userName.length == 0)
+ {
+ status.setCode(status.STATUS_BAD_REQUEST, "property 'userName' blank when creating sandbox");
+ return;
+ }
+
+ var shortName = url.extension.split("/")[0];
+
+ var webproject = webprojects.getWebProject(shortName);
+ if (webproject == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The webproject " + shortName + " does not exist.");
+ return;
+ }
+
+ var sandbox = webproject.createSandbox(userName);
+
+ // Set Return value
+ model.webproject = webproject;
+ model.sandbox = sandbox;
+}
+
+main()
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.desc.xml
new file mode 100644
index 0000000000..a42b4ff104
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.desc.xml
@@ -0,0 +1,10 @@
+
+ Web Project Sandboxes
+ Get a collection of a web project sandboxes. If userName is specified then returns the sandboxes for the specified user.
+ /api/wcm/webprojects/{webprojectref}/sandboxes?userName={userName?}
+ /api/wcm/webprojects/{webprojectref}/sandboxes
+
+ user
+ required
+ WCM Service
+
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.js
new file mode 100644
index 0000000000..51d38f1baf
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.js
@@ -0,0 +1,33 @@
+/*
+ * Get the sandboxes for a web project
+ */
+function main()
+{
+ var shortName = url.extension.split("/")[0];
+
+ var sandboxes;
+
+ var webproject = webprojects.getWebProject(shortName);
+ if (webproject == null)
+ {
+ // Site cannot be found
+ status.setCode(status.STATUS_NOT_FOUND, "The webproject " + shortName + " does not exist.");
+ return;
+ }
+
+ var userFilter = args["userName"];
+
+ if(userFilter != null)
+ {
+ sandboxes = webproject.getSandboxes(userFilter);
+ }
+ else
+ {
+ sandboxes = webproject.getSandboxes();
+ }
+ model.sandboxes = sandboxes;
+ model.webproject = webproject;
+}
+
+main()
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.json.ftl
new file mode 100644
index 0000000000..0dc20832b9
--- /dev/null
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/sandboxes.get.json.ftl
@@ -0,0 +1,13 @@
+<#import "sandbox.lib.ftl" as sandboxLib/>
+{
+ data:[
+ <#if sandboxes??>
+ <#assign boxNames = sandboxes?keys />
+ <#list boxNames as boxName>
+ <@sandboxLib.sandboxJSON webproject=webproject sandbox=sandboxes[boxName]/>
+ <#if boxName_has_next>,#if>
+ #list>
+ #if>
+ ]
+}
+
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.delete.desc.xml
index 3e7b11fbc1..734767451f 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.delete.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.delete.desc.xml
@@ -4,7 +4,8 @@
webprojectref specifies which project to delete and will have been returned by a prior call to get, create of list web project.
- /api/wcm/webproject/{webprojectref}
+ /api/wcm/webprojects/{webprojectref}
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.desc.xml
index 07d23c4455..eb9b69b525 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.desc.xml
@@ -2,7 +2,8 @@
Get Web Project
Get a single WCM web project in JSON format.
- /api/wcm/webproject/{webprojectref}
+ /api/wcm/webprojects/{webprojectref}
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.json.ftl
index e77cb468e6..1a6e283380 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.get.json.ftl
@@ -1,4 +1,5 @@
<#import "webproject.lib.ftl" as webprojectLib/>
-<@webprojectLib.webprojectJSON webproject=webproject/>
-
+{
+ data:<@webprojectLib.webprojectJSON webproject=webproject/>
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.lib.ftl
index 3d3d1e6276..da75627138 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.lib.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.lib.ftl
@@ -1,11 +1,23 @@
<#macro webprojectJSON webproject>
-<#escape x as jsonUtils.encodeJSONString(x)>
+
{
- "url" : "${url.serviceContext + "/api/wcm/webproject/" + webproject.webProjectRef}",
- "webprojectref" : "${webproject.webProjectRef}",
- "name" : "${webproject.name}",
- "title" : "${webproject.title}",
- "description" : "${webproject.description}"
+ "url" : <#escape x as jsonUtils.encodeJSONString(x)> "${url.serviceContext + "/api/wcm/webprojects/" + webproject.webProjectRef}", #escape>
+ "webprojectref" : <#escape x as jsonUtils.encodeJSONString(x)> "${webproject.webProjectRef}", #escape>
+ "name" : <#escape x as jsonUtils.encodeJSONString(x)> "${webproject.name}", #escape>
+ "title" : <#escape x as jsonUtils.encodeJSONString(x)> "${webproject.title}", #escape>
+ "description" : <#escape x as jsonUtils.encodeJSONString(x)> "${webproject.description}", #escape>
+ "isTemplate" : ${webproject.template?string("true", "false")},
+ "node" : <@nodeJSON nodeRef=webproject.nodeRef/>
+}
+
+#macro>
+
+// Render a scriptNode for JSON
+<#macro nodeJSON nodeRef>
+<#escape y as jsonUtils.encodeJSONString(y)>
+{
+ "id" : "${nodeRef.id}",
+ "nodeRef" : "${nodeRef}"
}
#escape>
#macro>
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.desc.xml
index 210169fb99..9ea11e1787 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.desc.xml
@@ -11,7 +11,8 @@
- /api/wcm/webproject
+ /api/wcm/webprojects
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.json.ftl
index e77cb468e6..1a6e283380 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.post.json.ftl
@@ -1,4 +1,5 @@
<#import "webproject.lib.ftl" as webprojectLib/>
-<@webprojectLib.webprojectJSON webproject=webproject/>
-
+{
+ data:<@webprojectLib.webprojectJSON webproject=webproject/>
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.desc.xml
index c395e552c4..bb0692ae01 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.desc.xml
@@ -1,11 +1,21 @@
Update Web Project
- Update a single WCM web project
+
+
The following fields are may be updated in the body of the request:
- name, title, description
+
+ - name
+ - title
+ - description
+ - isTemplate
+
+ /api/wcm/webprojects/{webprojectref}
- /api/wcm/webproject/{webprojectref}
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.ftl
index e77cb468e6..1a6e283380 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.ftl
@@ -1,4 +1,5 @@
<#import "webproject.lib.ftl" as webprojectLib/>
-<@webprojectLib.webprojectJSON webproject=webproject/>
-
+{
+ data:<@webprojectLib.webprojectJSON webproject=webproject/>
+}
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.js
index 0fef33e139..1c889eb312 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.js
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webproject.put.json.js
@@ -39,6 +39,11 @@ function main() {
var description = json.get("description");
webproject.setDescription(description);
}
+ if(json.has("isTemplate"))
+ {
+ var isTemplate = json.get("isTemplate");
+ webproject.setDescription(isTemplate);
+ }
// update the web project
webproject.save();
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.desc.xml
index bd6d296453..a3ccb9e8aa 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.desc.xml
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.desc.xml
@@ -1,9 +1,13 @@
Web Projects
- Get a list of the WCM Web projects, if userName is specified then only those web projects for the
- specified user are returned else all web projects are returned.
+ Get a list of the WCM Web projects. userName is an optional argument that if
+ specified then only those web projects for the
+ specified user are returned else all web projects are returned.
+
/api/wcm/webprojects?userName={userName?}
+ /api/wcm/webprojects
user
required
+ WCM Service
\ No newline at end of file
diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.json.ftl
index f29665faf9..e26ae6c253 100644
--- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.json.ftl
+++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/webprojects.get.json.ftl
@@ -1,8 +1,10 @@
<#import "webproject.lib.ftl" as webprojectLib/>
-[
+{
+ data:[
<#list webprojects as webproject>
<@webprojectLib.webprojectJSON webproject=webproject/>
<#if webproject_has_next>,#if>
#list>
-]
+ ]
+}
diff --git a/config/alfresco/web-scripts-application-context.xml b/config/alfresco/web-scripts-application-context.xml
index cca39ab79f..7c7c5c57b7 100644
--- a/config/alfresco/web-scripts-application-context.xml
+++ b/config/alfresco/web-scripts-application-context.xml
@@ -241,6 +241,15 @@
+
+
+
+
diff --git a/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java b/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java
index 302196a53e..1d51cbb985 100644
--- a/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java
@@ -57,7 +57,6 @@ public class WebProjectTest extends BaseWebScriptTest
private static final String USER_TWO = "WebProjectTestTwo";
private static final String USER_THREE = "WebProjectTestThree";
- private static final String URL_WEB_PROJECT = "/api/wcm/webproject";
private static final String URL_WEB_PROJECTS = "/api/wcm/webprojects";
private static final String BASIC_NAME = "testProj";
@@ -118,7 +117,7 @@ public class WebProjectTest extends BaseWebScriptTest
{
try
{
- Response deleteResponse = sendRequest(new DeleteRequest(URL_WEB_PROJECT + "/" + webProjectRef), 0);
+ sendRequest(new DeleteRequest(URL_WEB_PROJECTS + "/" + webProjectRef), 0);
}
catch (Exception e)
{
@@ -134,6 +133,8 @@ public class WebProjectTest extends BaseWebScriptTest
{
this.authenticationComponent.setCurrentUser("admin");
+ sendRequest(new DeleteRequest(URL_WEB_PROJECTS + "/" + BASIC_DNSNAME),0 );
+
/**
* Create a web site
*/
@@ -142,9 +143,12 @@ public class WebProjectTest extends BaseWebScriptTest
webProj.put("description", BASIC_DESCRIPTION);
webProj.put("title", BASIC_TITLE);
webProj.put("dnsName", BASIC_DNSNAME);
- Response response = sendRequest(new PostRequest(URL_WEB_PROJECT, webProj.toString(), "application/json"), Status.STATUS_OK);
+ webProj.put("isTemplate", true);
- JSONObject result = new JSONObject(response.getContentAsString());
+ Response response = sendRequest(new PostRequest(URL_WEB_PROJECTS, webProj.toString(), "application/json"), Status.STATUS_OK);
+
+ JSONObject top = new JSONObject(response.getContentAsString());
+ JSONObject result = top.getJSONObject("data");
String webProjectRef = result.getString("webprojectref");
assertNotNull("webproject ref is null", webProjectRef);
@@ -153,16 +157,22 @@ public class WebProjectTest extends BaseWebScriptTest
assertEquals(BASIC_NAME, result.get("name"));
assertEquals(BASIC_DESCRIPTION, result.get("description"));
assertEquals(BASIC_TITLE, result.get("title"));
+ // not yet implemented
+ //assertEquals(true, result.get("isTemplate"));
/**
* Read the web site we created above
*/
- Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECT + "/" + webProjectRef), 200);
+ Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
{
- JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
- assertEquals(BASIC_NAME, lookupResult.get("name"));
- assertEquals(BASIC_DESCRIPTION, lookupResult.get("description"));
- assertEquals(BASIC_TITLE, lookupResult.get("title"));
+ JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
+ JSONObject data = lookupResult.getJSONObject("data");
+ assertEquals(BASIC_NAME, data.get("name"));
+ assertEquals(BASIC_DESCRIPTION, data.get("description"));
+ assertEquals(BASIC_TITLE, data.get("title"));
+ String url = data.getString("url");
+ assertNotNull("url is null", url);
+ sendRequest(new GetRequest(url), Status.STATUS_OK);
}
/**
@@ -171,19 +181,19 @@ public class WebProjectTest extends BaseWebScriptTest
{
JSONObject update = new JSONObject();
update.put("name", BASIC_UPDATED_NAME);
- Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECT + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
- JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
-
-// TODO TESTS NOT PASSING
-// assertEquals(BASIC_UPDATED_NAME, updateResult.get("name"));
-// assertEquals(BASIC_DESCRIPTION, updateResult.get("description"));
-// assertEquals(BASIC_TITLE, updateResult.get("title"));
+ Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECTS + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
+ JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
+ // TODO TESTS NOT PASSING
+// JSONObject data = updateResult.getJSONObject("data");
+// assertEquals(BASIC_UPDATED_NAME, data.get("name"));
+// assertEquals(BASIC_DESCRIPTION, data.get("description"));
+// assertEquals(BASIC_TITLE, data.get("title"));
}
/**
* Delete the web site we created above
*/
- Response deleteResponse = sendRequest(new DeleteRequest(URL_WEB_PROJECT + "/" + webProjectRef), Status.STATUS_OK);
+ sendRequest(new DeleteRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
} // END testBasicCRUDWebProject
public void testListWebSites() throws Exception
@@ -202,10 +212,11 @@ public class WebProjectTest extends BaseWebScriptTest
webProj.put("description", BASIC_DESCRIPTION + i);
webProj.put("title", BASIC_TITLE + i);
webProj.put("dnsName", BASIC_DNSNAME + i);
- Response response = sendRequest(new PostRequest(URL_WEB_PROJECT, webProj.toString(), "application/json"), Status.STATUS_OK);
+ Response response = sendRequest(new PostRequest(URL_WEB_PROJECTS, webProj.toString(), "application/json"), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
- String webProjectRef = result.getString("webprojectref");
+ JSONObject data = result.getJSONObject("data");
+ String webProjectRef = data.getString("webprojectref");
this.createdWebProjects.add(webProjectRef);
}
@@ -215,17 +226,18 @@ public class WebProjectTest extends BaseWebScriptTest
{
Response list = sendRequest(new GetRequest(URL_WEB_PROJECTS), Status.STATUS_OK);
- JSONArray lookupResult = new JSONArray(list.getContentAsString());
- assertTrue(lookupResult.length() >= LOOP_COUNT);
+ JSONObject lookupResult = new JSONObject(list.getContentAsString());
+ JSONArray data = lookupResult.getJSONArray("data");
+ assertTrue(data.length() >= LOOP_COUNT);
/**
* Now check that the list contains the sites created above
*/
int foundCount = 0;
- for(int i = 0; i < lookupResult.length(); i++)
+ for(int i = 0; i < data.length(); i++)
{
- JSONObject obj = lookupResult.getJSONObject(i);
+ JSONObject obj = data.getJSONObject(i);
String name = obj.getString("name");
if(name.contains(BASIC_NAME))
{
@@ -240,14 +252,11 @@ public class WebProjectTest extends BaseWebScriptTest
*/
{
String stepURL = "/api/wcm/webprojects?userName=Freddy";
- Response list = sendRequest(new GetRequest(stepURL), Status.STATUS_OK);
- JSONArray lookupResult = new JSONArray(list.getContentAsString());
- assertTrue(lookupResult.length() == 0);
+ Response listResponse = sendRequest(new GetRequest(stepURL), Status.STATUS_OK);
+ JSONObject lookupResult = new JSONObject(listResponse.getContentAsString());
+ JSONArray data = lookupResult.getJSONArray("data");
+ assertTrue(data.length() == 0);
}
-
-
-
-
} // testListWebSites
public void testUpdateWebProject() throws Exception
@@ -262,11 +271,12 @@ public class WebProjectTest extends BaseWebScriptTest
webProj.put("description", BASIC_DESCRIPTION);
webProj.put("title", BASIC_TITLE);
webProj.put("dnsName", BASIC_DNSNAME);
- Response response = sendRequest(new PostRequest(URL_WEB_PROJECT, webProj.toString(), "application/json"), Status.STATUS_OK);
-
- JSONObject result = new JSONObject(response.getContentAsString());
+ Response response = sendRequest(new PostRequest(URL_WEB_PROJECTS, webProj.toString(), "application/json"), Status.STATUS_OK);
+ JSONObject top = new JSONObject(response.getContentAsString());
+ JSONObject result = top.getJSONObject("data");
String webProjectRef = result.getString("webprojectref");
+
assertNotNull("webproject ref is null", webProjectRef);
this.createdWebProjects.add(webProjectRef);
@@ -274,11 +284,12 @@ public class WebProjectTest extends BaseWebScriptTest
* Read the web site we created above to double check it created correctly
*/
{
- Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECT + "/" + webProjectRef), Status.STATUS_OK);
+ Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
- assertEquals(BASIC_NAME, lookupResult.get("name"));
- assertEquals(BASIC_DESCRIPTION, lookupResult.get("description"));
- assertEquals(BASIC_TITLE, lookupResult.get("title"));
+ JSONObject data = lookupResult.getJSONObject("data");
+ assertEquals(BASIC_NAME, data.get("name"));
+ assertEquals(BASIC_DESCRIPTION, data.get("description"));
+ assertEquals(BASIC_TITLE, data.get("title"));
}
/*
@@ -287,17 +298,18 @@ public class WebProjectTest extends BaseWebScriptTest
{
JSONObject update = new JSONObject();
update.put("description", BASIC_UPDATED_DESCRIPTION);
- Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECT + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
+ Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECTS + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
/*
* Read the result, check description updated and other properties remain unchanged
*/
- Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECT + "/" + webProjectRef), Status.STATUS_OK);
+ Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
- assertEquals(BASIC_NAME, lookupResult.get("name"));
- assertEquals(BASIC_UPDATED_DESCRIPTION, lookupResult.get("description"));
- assertEquals(BASIC_TITLE, lookupResult.get("title"));
+ JSONObject data = lookupResult.getJSONObject("data");
+ assertEquals(BASIC_NAME, data.get("name"));
+ assertEquals(BASIC_UPDATED_DESCRIPTION, data.get("description"));
+ assertEquals(BASIC_TITLE, data.get("title"));
}
/*
@@ -306,17 +318,18 @@ public class WebProjectTest extends BaseWebScriptTest
{
JSONObject update = new JSONObject();
update.put("title", BASIC_UPDATED_TITLE);
- Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECT + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
- JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
+ Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECTS + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
+ new JSONObject(updateResponse.getContentAsString());
/*
* Read the result, check description updated and other properties unchanged
*/
- Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECT + "/" + webProjectRef), Status.STATUS_OK);
+ Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
- assertEquals(BASIC_NAME, lookupResult.get("name"));
- assertEquals(BASIC_UPDATED_DESCRIPTION, lookupResult.get("description"));
- assertEquals(BASIC_UPDATED_TITLE, lookupResult.get("title"));
+ JSONObject data = lookupResult.getJSONObject("data");
+ assertEquals(BASIC_NAME, data.get("name"));
+ assertEquals(BASIC_UPDATED_DESCRIPTION, data.get("description"));
+ assertEquals(BASIC_UPDATED_TITLE, data.get("title"));
}
/**
@@ -325,17 +338,18 @@ public class WebProjectTest extends BaseWebScriptTest
{
JSONObject update = new JSONObject();
update.put("name", BASIC_UPDATED_NAME);
- Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECT + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
+ Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECTS + "/" + webProjectRef, update.toString(), "application/json"), Status.STATUS_OK);
JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
/*
* Read the result, check description updated and other properties unchanged
*/
- Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECT + "/" + webProjectRef), Status.STATUS_OK);
+ Response lookup = sendRequest(new GetRequest(URL_WEB_PROJECTS + "/" + webProjectRef), Status.STATUS_OK);
JSONObject lookupResult = new JSONObject(lookup.getContentAsString());
- assertEquals(BASIC_UPDATED_NAME, lookupResult.get("name"));
- assertEquals(BASIC_UPDATED_DESCRIPTION, lookupResult.get("description"));
- assertEquals(BASIC_UPDATED_TITLE, lookupResult.get("title"));
+ JSONObject data = lookupResult.getJSONObject("data");
+ assertEquals(BASIC_UPDATED_NAME, data.get("name"));
+ assertEquals(BASIC_UPDATED_DESCRIPTION, data.get("description"));
+ assertEquals(BASIC_UPDATED_TITLE, data.get("title"));
}
@@ -347,8 +361,7 @@ public class WebProjectTest extends BaseWebScriptTest
{
JSONObject update = new JSONObject();
update.put("name", BASIC_UPDATED_NAME);
- Response updateResponse = sendRequest(new PutRequest(URL_WEB_PROJECT + "/" + BAD_PROJECT_REF, update.toString(), "application/json"), Status.STATUS_NOT_FOUND);
- JSONObject updateResult = new JSONObject(updateResponse.getContentAsString());
+ sendRequest(new PutRequest(URL_WEB_PROJECTS + "/" + BAD_PROJECT_REF, update.toString(), "application/json"), Status.STATUS_NOT_FOUND);
}
} // end testUpdateWebProject
@@ -361,7 +374,7 @@ public class WebProjectTest extends BaseWebScriptTest
* Delete a project that does not exist
*/
{
- Response deleteResponse = sendRequest(new DeleteRequest(URL_WEB_PROJECT + "/" + BAD_PROJECT_REF), Status.STATUS_NOT_FOUND);
+ sendRequest(new DeleteRequest(URL_WEB_PROJECTS + "/" + BAD_PROJECT_REF), Status.STATUS_NOT_FOUND);
}
} // end testDeleteWebproject
diff --git a/source/java/org/alfresco/repo/web/scripts/wcm/membership/WebProjectMembershipTest.java b/source/java/org/alfresco/repo/web/scripts/wcm/membership/WebProjectMembershipTest.java
index f61ed8d551..2589364d01 100644
--- a/source/java/org/alfresco/repo/web/scripts/wcm/membership/WebProjectMembershipTest.java
+++ b/source/java/org/alfresco/repo/web/scripts/wcm/membership/WebProjectMembershipTest.java
@@ -64,7 +64,7 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
public static final String ROLE_CONTENT_REVIEWER = "ContentReviewer";
public static final String ROLE_CONTENT_CONTRIBUTOR = "ContentContributor";
- private static final String URL_WEB_PROJECT = "/api/wcm/webproject";
+ private static final String URL_WEB_PROJECTS = "/api/wcm/webprojects";
private static final String URL_MEMBERSHIPS = "/memberships";
private static final String BASIC_NAME = "testProj";
private static final String BASIC_DESCRIPTION = "testDescription";
@@ -121,7 +121,7 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
{
try
{
- sendRequest(new DeleteRequest(URL_WEB_PROJECT + "/" + webProjectRef), 0);
+ sendRequest(new DeleteRequest(URL_WEB_PROJECTS + "/" + webProjectRef), 0);
}
catch (Exception e)
{
@@ -148,10 +148,11 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
webProj.put("description", BASIC_DESCRIPTION);
webProj.put("title", BASIC_TITLE);
webProj.put("dnsName", BASIC_DNSNAME);
- Response response = sendRequest(new PostRequest(URL_WEB_PROJECT, webProj.toString(), "application/json"), Status.STATUS_OK);
+ Response response = sendRequest(new PostRequest(URL_WEB_PROJECTS, webProj.toString(), "application/json"), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
- String webProjectRef = result.getString("webprojectref");
+ JSONObject data = result.getJSONObject("data");
+ String webProjectRef = data.getString("webprojectref");
assertNotNull("webproject ref is null", webProjectRef);
this.createdWebProjects.add(webProjectRef);
@@ -166,17 +167,18 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
// Create a site
String webProjectRef = createWebProject();
- String validURL = URL_WEB_PROJECT + "/" + webProjectRef + "/memberships";
+ String validURL = URL_WEB_PROJECTS + "/" + webProjectRef + "/memberships";
/**
* A newly created web project has 1 users (admin is a special case)
*/
{
Response response = sendRequest(new GetRequest(validURL), Status.STATUS_OK);
- JSONArray result = new JSONArray(response.getContentAsString());
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONArray data = result.getJSONArray("data");
- assertNotNull(result);
- assertEquals(1, result.length());
+ assertNotNull(data);
+ assertEquals(1, data.length());
}
/**
@@ -190,15 +192,16 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
membership.put("person", person);
sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
- Response response = sendRequest(new GetRequest(validURL), Status.STATUS_OK);
- JSONArray result = new JSONArray(response.getContentAsString());
- assertNotNull(result);
- assertEquals(2, result.length());
+ Response response = sendRequest(new GetRequest(validURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONArray data = result.getJSONArray("data");
+ assertNotNull(data);
+ assertEquals(2, data.length());
boolean foundUser = false;
- for(int i = 0; i < result.length(); i++)
+ for(int i = 0; i < data.length(); i++)
{
- JSONObject obj = result.getJSONObject(i);
+ JSONObject obj = data.getJSONObject(i);
if(USER_ONE.equals(obj.getJSONObject("person").get("userName")))
{
assertEquals(ROLE_CONTENT_MANAGER, obj.get("role"));
@@ -221,15 +224,16 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
membership.put("person", person);
sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
- Response response = sendRequest(new GetRequest(validURL), Status.STATUS_OK);
- JSONArray result = new JSONArray(response.getContentAsString());
- assertNotNull(result);
- assertEquals(3, result.length());
+ Response response = sendRequest(new GetRequest(validURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONArray data = result.getJSONArray("data");
+ assertNotNull(data);
+ assertEquals(3, data.length());
boolean foundUser = false;
- for(int i = 0; i < result.length(); i++)
+ for(int i = 0; i < data.length(); i++)
{
- JSONObject obj = result.getJSONObject(i);
+ JSONObject obj = data.getJSONObject(i);
if(USER_TWO.equals(obj.getJSONObject("person").get("userName")))
{
assertEquals(ROLE_CONTENT_REVIEWER, obj.get("role"));
@@ -247,8 +251,9 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
{
String stepURL = "/api/wcm/webprojects?userName=" + USER_TWO;
Response list = sendRequest(new GetRequest(stepURL), Status.STATUS_OK);
- JSONArray lookupResult = new JSONArray(list.getContentAsString());
- assertTrue(lookupResult.length() == 1);
+ JSONObject response = new JSONObject(list.getContentAsString());
+ JSONArray data = response.getJSONArray("data");
+ assertTrue(data.length() == 1);
}
/**
@@ -256,7 +261,7 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
* Project not found
*/
{
- String invalidURL = URL_WEB_PROJECT + "/" + "NotExist" + "/memberships";
+ String invalidURL = URL_WEB_PROJECTS + "/" + "NotExist" + "/memberships";
sendRequest(new GetRequest(invalidURL), Status.STATUS_NOT_FOUND);
}
@@ -268,7 +273,7 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
String webProjectRef = createWebProject();
- String validURL = URL_WEB_PROJECT + "/" + webProjectRef + "/memberships";
+ String validURL = URL_WEB_PROJECTS + "/" + webProjectRef + "/memberships";
/**
* Create a new membership
@@ -282,23 +287,25 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
Response response = sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
// Check the result
- assertEquals(ROLE_CONTENT_MANAGER, result.get("role"));
- assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
+ assertEquals(ROLE_CONTENT_MANAGER, data.get("role"));
+ assertEquals(USER_TWO, data.getJSONObject("person").get("userName"));
}
/**
* Get the membership
*/
{
- String validGetURL = URL_WEB_PROJECT + "/" + webProjectRef + "/membership/" + USER_TWO;
+ String validGetURL = URL_WEB_PROJECTS + "/" + webProjectRef + "/memberships/" + USER_TWO;
Response response = sendRequest(new GetRequest(validGetURL), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
// Check the result
- assertEquals(ROLE_CONTENT_MANAGER, result.get("role"));
- assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
+ assertEquals(ROLE_CONTENT_MANAGER, data.get("role"));
+ assertEquals(USER_TWO, data.getJSONObject("person").get("userName"));
}
/**
@@ -314,10 +321,11 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
Response response = sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
-
+ JSONObject data = result.getJSONObject("data");
+
// Check the result
- assertEquals(ROLE_CONTENT_MANAGER, result.get("role"));
- assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
+ assertEquals(ROLE_CONTENT_MANAGER, data.get("role"));
+ assertEquals(USER_TWO, data.getJSONObject("person").get("userName"));
}
/**
@@ -355,8 +363,8 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
String webProjectRef = createWebProject();
// Test error conditions
- sendRequest(new GetRequest(URL_WEB_PROJECT + "/badsite" + URL_MEMBERSHIPS + "/" + USER_ONE), Status.STATUS_NOT_FOUND);
- String validURL = URL_WEB_PROJECT + "/" + webProjectRef + "/membership/";
+ sendRequest(new GetRequest(URL_WEB_PROJECTS + "/badsite" + URL_MEMBERSHIPS + "/" + USER_ONE), Status.STATUS_NOT_FOUND);
+ String validURL = URL_WEB_PROJECTS + "/" + webProjectRef + URL_MEMBERSHIPS ;
// User not found
sendRequest(new GetRequest(validURL + "baduser"), Status.STATUS_NOT_FOUND);
@@ -364,12 +372,13 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
/**
* Now lookup the admin user and check they are a content manager
*/
- Response response = sendRequest(new GetRequest(validURL + USER_ADMIN), Status.STATUS_OK);
+ Response response = sendRequest(new GetRequest(validURL + "/" + USER_ADMIN), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
-
+ JSONObject data = result.getJSONObject("data");
+
// Check the result
- assertEquals(ROLE_CONTENT_MANAGER, result.get("role"));
- assertEquals(USER_ADMIN, result.getJSONObject("person").get("userName"));
+ assertEquals(ROLE_CONTENT_MANAGER, data.get("role"));
+ assertEquals(USER_ADMIN, data.getJSONObject("person").get("userName"));
}
// Update Not yet implemented
@@ -464,7 +473,7 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
String webProjectRef = createWebProject();
- String validURL = URL_WEB_PROJECT + "/" + webProjectRef + "/memberships";
+ String validURL = URL_WEB_PROJECTS + "/" + webProjectRef + "/memberships";
/**
* Create a new membership
@@ -478,13 +487,14 @@ public class WebProjectMembershipTest extends BaseWebScriptTest
Response response = sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
JSONObject result = new JSONObject(response.getContentAsString());
-
+ JSONObject data = result.getJSONObject("data");
+
// Check the result
- assertEquals(ROLE_CONTENT_MANAGER, result.get("role"));
- assertEquals(USER_TWO, result.getJSONObject("person").get("userName"));
+ assertEquals(ROLE_CONTENT_MANAGER, data.get("role"));
+ assertEquals(USER_TWO, data.getJSONObject("person").get("userName"));
}
- String validGetURL = URL_WEB_PROJECT + "/" + webProjectRef + "/membership/" + USER_TWO;
+ String validGetURL = URL_WEB_PROJECTS + "/" + webProjectRef + URL_MEMBERSHIPS + "/" + USER_TWO;
{
sendRequest(new GetRequest(validGetURL), Status.STATUS_OK);
diff --git a/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/SandboxTest.java b/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/SandboxTest.java
new file mode 100644
index 0000000000..a99b787397
--- /dev/null
+++ b/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/SandboxTest.java
@@ -0,0 +1,480 @@
+/*
+ * Copyright (C) 2005-2008 Alfresco Software Limited.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ * As a special exception to the terms and conditions of version 2.0 of
+ * the GPL, you may redistribute this Program in connection with Free/Libre
+ * and Open Source Software ("FLOSS") applications as described in Alfresco's
+ * FLOSS exception. You should have recieved a copy of the text describing
+ * the FLOSS exception, and it is also available here:
+ * http://www.alfresco.com/legal/licensing"
+ */
+
+package org.alfresco.repo.web.scripts.wcm.sandbox;
+
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.alfresco.model.ContentModel;
+import org.alfresco.repo.security.authentication.AuthenticationComponent;
+import org.alfresco.repo.web.scripts.BaseWebScriptTest;
+import org.alfresco.service.cmr.security.AuthenticationService;
+import org.alfresco.service.cmr.security.PersonService;
+import org.alfresco.util.ISO8601DateFormat;
+import org.alfresco.util.PropertyMap;
+import org.alfresco.web.scripts.Status;
+import org.alfresco.web.scripts.TestWebScriptServer.DeleteRequest;
+import org.alfresco.web.scripts.TestWebScriptServer.GetRequest;
+import org.alfresco.web.scripts.TestWebScriptServer.PostRequest;
+import org.alfresco.web.scripts.TestWebScriptServer.PutRequest;
+import org.alfresco.web.scripts.TestWebScriptServer.Response;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
+/**
+ * Junit tests of the REST bindings for WCM Sandbox and WCM Sandboxes
+ * @author mrogers
+ *
+ */
+public class SandboxTest extends BaseWebScriptTest {
+
+ private AuthenticationService authenticationService;
+ private AuthenticationComponent authenticationComponent;
+ private PersonService personService;
+
+ private static final String USER_ONE = "WebProjectTestOne";
+ private static final String USER_TWO = "WebProjectTestTwo";
+ private static final String USER_THREE = "WebProjectTestThree";
+ private static final String USER_FOUR = "WebProjectTestFour";
+ private static final String USER_ADMIN = "admin";
+ public static final String ROLE_CONTENT_MANAGER = "ContentManager";
+ public static final String ROLE_CONTENT_PUBLISHER = "ContentPublisher";
+ public static final String ROLE_CONTENT_REVIEWER = "ContentReviewer";
+ public static final String ROLE_CONTENT_CONTRIBUTOR = "ContentContributor";
+
+ private static final String URL_WEB_PROJECT = "/api/wcm/webprojects";
+ private static final String URI_MEMBERSHIPS = "/memberships";
+ private static final String URI_SANDBOXES = "/sandboxes";
+ private static final String BASIC_NAME = "testProj";
+ private static final String BASIC_DESCRIPTION = "testDescription";
+ private static final String BASIC_TITLE = "testTitle";
+ private static final String BASIC_DNSNAME = "testDNSName";
+
+ private List createdWebProjects = new ArrayList(5);
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
+ this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
+ this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
+
+ // Create users
+ createUser(USER_ONE);
+ createUser(USER_TWO);
+ createUser(USER_THREE);
+ createUser(USER_FOUR);
+
+ // Do tests as user one
+ this.authenticationComponent.setCurrentUser(USER_ONE);
+ }
+
+ private void createUser(String userName)
+ {
+ if (this.authenticationService.authenticationExists(userName) == false)
+ {
+ this.authenticationService.createAuthentication(userName, "PWD".toCharArray());
+
+ PropertyMap ppOne = new PropertyMap(4);
+ ppOne.put(ContentModel.PROP_USERNAME, userName);
+ ppOne.put(ContentModel.PROP_FIRSTNAME, "firstName");
+ ppOne.put(ContentModel.PROP_LASTNAME, "lastName");
+ ppOne.put(ContentModel.PROP_EMAIL, "email@email.com");
+ ppOne.put(ContentModel.PROP_JOBTITLE, "jobTitle");
+
+ this.personService.createPerson(ppOne);
+ }
+ }
+
+ /**
+ * Create a new membership
+ */
+ private void createMembership(String webProjectRef, String userName, String role) throws Exception
+ {
+ String validURL = URL_WEB_PROJECT + "/" + webProjectRef + "/memberships";
+ JSONObject membership = new JSONObject();
+ membership.put("role", ROLE_CONTENT_MANAGER);
+ JSONObject person = new JSONObject();
+ person.put("userName", USER_TWO);
+ membership.put("person", person);
+
+ sendRequest(new PostRequest(validURL, membership.toString(), "application/json"), Status.STATUS_OK);
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ this.authenticationComponent.setCurrentUser("admin");
+
+ // Tidy-up any web projects created during the execution of the test
+ for (String webProjectRef : this.createdWebProjects)
+ {
+ try
+ {
+ sendRequest(new DeleteRequest(URL_WEB_PROJECT + "/" + webProjectRef), 0);
+ }
+ catch (Exception e)
+ {
+ // ignore exception here
+ }
+ }
+
+ // Clear the list
+ this.createdWebProjects.clear();
+ }
+
+ /**
+ * create a web project
+ * @return the webprojectref
+ * @throws Exception
+ */
+ private String createWebProject() throws Exception
+ {
+ /**
+ * Create a web site
+ */
+ JSONObject webProj = new JSONObject();
+ webProj.put("name", BASIC_NAME);
+ webProj.put("description", BASIC_DESCRIPTION);
+ webProj.put("title", BASIC_TITLE);
+ webProj.put("dnsName", BASIC_DNSNAME);
+ Response response = sendRequest(new PostRequest(URL_WEB_PROJECT, webProj.toString(), "application/json"), Status.STATUS_OK);
+
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
+ String webProjectRef = data.getString("webprojectref");
+
+ assertNotNull("webproject ref is null", webProjectRef);
+ this.createdWebProjects.add(webProjectRef);
+ return webProjectRef;
+
+ }
+
+
+ /**
+ * CRUD Sandbox
+ * Create a sandbox, get it, and delete it
+ * Is update supported? - There are no read-write attributes yet.
+ */
+ public void testCreateSandbox() throws Exception
+ {
+ this.authenticationComponent.setCurrentUser("admin");
+
+ String webprojref = createWebProject();
+
+ createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER);
+
+ String sandboxref ;
+
+ /**
+ * Create a sandbox
+ */
+ {
+ JSONObject box = new JSONObject();
+ box.put("userName", USER_ONE);
+ String validURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes";
+ Response response = sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
+
+ sandboxref = data.getString("sandboxref");
+ String url = data.getString("url");
+ String name = data.getString("name");
+ JSONObject createdDate = data.getJSONObject("createdDate");
+ String createdOn = createdDate.getString("iso8601");
+ String createdBy = data.getString("creator");
+ assertNotNull("created date is null", createdOn );
+ assertNotNull("created by is null", createdBy );
+ assertNotNull("sandboxref is null", sandboxref);
+ assertNotNull("url is null", url);
+ assertNotNull("name is null", name);
+
+ // check created date - throws exception if format invalid
+ @SuppressWarnings("unused")
+ java.util.Date d = ISO8601DateFormat.parse(createdOn);
+
+ // lookup url returned
+ sendRequest(new GetRequest(url), Status.STATUS_OK);
+ }
+ String sandboxURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes/" + sandboxref;
+
+ /**
+ * Get the sandbox
+ */
+ sendRequest(new GetRequest(sandboxURL), Status.STATUS_OK);
+
+
+ /**
+ * Delete the sandbox
+ */
+ sendRequest(new DeleteRequest(sandboxURL), Status.STATUS_OK);
+
+ /**
+ * Create a sandbox - negative test - no userName
+ */
+ {
+ JSONObject box = new JSONObject();
+ String validURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes";
+ sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_BAD_REQUEST);
+ }
+
+ }
+
+ /**
+ * Test the list sandbox method
+ */
+ public void testListSandbox() throws Exception
+ {
+ this.authenticationComponent.setCurrentUser("admin");
+ String webprojref = createWebProject();
+
+ /**
+ * Call the list sandboxes method
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES;
+ Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(list.getContentAsString());
+ JSONArray lookupResult = result.getJSONArray("data");
+
+ // By default there should be a staging sandbox
+ assertTrue("list of sandboxes is empty", lookupResult.length() > 0);
+ }
+
+ createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER);
+ createMembership(webprojref, USER_TWO, ROLE_CONTENT_REVIEWER);
+ createMembership(webprojref, USER_THREE, ROLE_CONTENT_CONTRIBUTOR);
+ String validURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes";
+ JSONObject box = new JSONObject();
+ box.put("userName", USER_ONE);
+ sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+ box.put("userName", USER_TWO);
+ sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+ box.put("userName", USER_THREE);
+ sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+
+ /**
+ * List the sandboxes belonging to USER_ONE
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "?userName=" + USER_ONE;
+ Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(list.getContentAsString());
+ JSONArray lookupResult = result.getJSONArray("data");
+
+ assertTrue("testListUserSandbox", lookupResult.length() == 1);
+ JSONObject obj1 = lookupResult.getJSONObject(0);
+ String url = obj1.getString("url");
+ String name = obj1.getString("name");
+ assertNotNull("url is null", url);
+ assertNotNull("name is null", name);
+
+ /**
+ * Should be able to lookup the url returned
+ */
+ sendRequest(new GetRequest(url), Status.STATUS_OK);
+ }
+
+ /**
+ * List the sandboxes belonging to USER_TWO
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "?userName=" + USER_TWO;
+ Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(list.getContentAsString());
+ JSONArray lookupResult = result.getJSONArray("data");
+
+ assertTrue("testListUserSandbox", lookupResult.length() == 1);
+ }
+
+ /**
+ * Call the list sandboxes method
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES;
+ Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(list.getContentAsString());
+ JSONArray lookupResult = result.getJSONArray("data");
+
+ // There have been 3 creates above
+ assertTrue("list of sandboxes is empty", lookupResult.length() > 3);
+ }
+
+ /**
+ * Negative test
+ * Call the list sandbox method for a web project that does not exist
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + "twaddle" + URI_SANDBOXES;
+ sendRequest(new GetRequest(sandboxesURL), Status.STATUS_NOT_FOUND);
+ }
+
+ /**
+ * Negative test
+ * Call the list sandbox method for a user that does not have a sandbox project that does not exist
+ */
+ {
+ String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "?userName=" + USER_FOUR;
+ Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(list.getContentAsString());
+ JSONArray lookupResult = result.getJSONArray("data");
+ assertTrue("lookup user 4 (not existing) found a sandbox", lookupResult.length() == 0);
+ }
+
+ }
+
+
+ /**
+ * Test the get sandbox method
+ */
+ public void testGetSandbox() throws Exception
+ {
+ this.authenticationComponent.setCurrentUser("admin");
+
+ String webprojref = createWebProject();
+
+ createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER);
+
+ String sandboxref ;
+
+ /**
+ * Create a sandbox
+ */
+ {
+ JSONObject box = new JSONObject();
+ box.put("userName", USER_ONE);
+ String validURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes";
+ Response response = sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
+ sandboxref = data.getString("sandboxref");
+ assertNotNull("sandboxref is null", sandboxref);
+
+ }
+ String sandboxURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes/" + sandboxref;
+
+ /**
+ * Call the get sandbox method for a web project
+ */
+ {
+ Response response = sendRequest(new GetRequest(sandboxURL), Status.STATUS_OK);
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
+ sandboxref = data.getString("sandboxref");
+ String url = data.getString("url");
+ String name = data.getString("name");
+ assertNotNull("sandboxref is null", sandboxref);
+ assertNotNull("url is null", url);
+ assertNotNull("name is null", name);
+
+ JSONObject createdDate = data.getJSONObject("createdDate");
+ String createdOn = createdDate.getString("iso8601");
+ String createdBy = data.getString("creator");
+ assertNotNull("created date is null", createdOn );
+ assertNotNull("created by is null", createdBy );
+ }
+
+ /**
+ * Negative test
+ * Call the list sandbox method for a web project that does not exist
+ */
+ {
+ String invalidWebprojURL = "/api/wcm/webprojects/" + "twaddle" + "/sandboxes/" + sandboxref;
+ sendRequest(new GetRequest(invalidWebprojURL), Status.STATUS_NOT_FOUND);
+ }
+
+ /**
+ * Negative test
+ * Call the list sandbox method for a web project that does exist and a sandbox that doesn't
+ */
+ {
+ String invalidboxURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes/" + "twaddle";
+ sendRequest(new GetRequest(invalidboxURL), Status.STATUS_NOT_FOUND);
+ }
+ }
+
+ /**
+ * Test the delete sandbox method
+ */
+ public void testDeleteSandbox() throws Exception
+ {
+ this.authenticationComponent.setCurrentUser("admin");
+ String webprojref = createWebProject();
+
+ createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER);
+
+ /**
+ * Create a sandbox
+ */
+ JSONObject box = new JSONObject();
+ box.put("userName", USER_ONE);
+ String validURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes";
+ Response response = sendRequest(new PostRequest(validURL, box.toString(), "application/json"), Status.STATUS_OK);
+ JSONObject result = new JSONObject(response.getContentAsString());
+ JSONObject data = result.getJSONObject("data");
+ String sandboxref = data.getString("sandboxref");
+ assertNotNull("sandboxref is null", sandboxref);
+
+ String sandboxURL = "/api/wcm/webprojects/" + webprojref + "/sandboxes/" + sandboxref;
+
+ /**
+ * Negative test - web project not exist
+ */
+ {
+ String invalidProject = "/api/wcm/webprojects/" + "silly" + "/sandboxes/" + sandboxref;
+ sendRequest(new DeleteRequest(invalidProject), Status.STATUS_NOT_FOUND);
+ }
+
+ /**
+ * Negative test - user sandbox not exist
+ */
+ {
+ String invalidSandbox = "/api/wcm/webprojects/" + webprojref + "/sandboxes/" + "silly";
+ sendRequest(new DeleteRequest(invalidSandbox), Status.STATUS_NOT_FOUND);
+ }
+
+ /**
+ * Delete the sandbox - positive test
+ */
+ {
+ sendRequest(new DeleteRequest(sandboxURL), Status.STATUS_OK);
+ }
+
+ /**
+ * Negative test
+ * Delete the sandbox that has already been deleted
+ */
+
+ {
+ sendRequest(new DeleteRequest(sandboxURL), Status.STATUS_NOT_FOUND);
+ }
+ }
+}