diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.desc.xml index 18e9a6b78d..fd085f88b5 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.desc.xml @@ -1,17 +1,19 @@ - Delete the specified assets. + Delete the specified asset. - If the optional webApp argument is specified then returns the modified assets within that web app. + Delete the specified asset. +
+ If the optional webApp argument is specified then the path is relative to the webapp e.g. /index.htm +
+ If webApp is not specified then the path is will be absolute e.g. /www/avm_webapps/ROOT/index.htm +
+ Returns STATUS_OK(200) for success. ]]>
/api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path} - - + /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path}?webApp={webApp?} + argument user required WCM Service diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.js index 5b1b81f42c..b2f0b8b613 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.delete.js @@ -6,9 +6,8 @@ function main() var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; - var path = url.extension - - + var pathArray = urlElements.slice(4); + var path = pathArray.join("/"); var webproject = webprojects.getWebProject(shortName); if (webproject == null) @@ -29,15 +28,26 @@ function main() var webApp = args["webApp"]; + var asset ; if(webApp != null) { - sandbox. + asset = sandbox.getAssetWebApp(webApp, path); } else { + asset = sandbox.getAsset(path); } + if (asset == null) + { + // Site cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The asset, " + path + ", in webproject, " + shortName + ", does not exist."); + return; + } + + // now do the delete of the asset + asset.deleteAsset(); // set model properties model.sandbox = sandbox; diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.desc.xml index d579f6a1a2..a65252fe93 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.desc.xml @@ -1,19 +1,39 @@ - Get the details of the specified asset within the specified sandbox. + Get the details of the specified asset within the specified web project and sandbox. - If the asset is a folder, lists the children. + If the asset is a folder, lists the children of that folder.
- If the optional webApp argument is specified then returns the modified assets relative to that web app. + If the asset is a folder, gives the size of the file. +
+ If the optional webApp argument is specified then returns the modified assets relative to that web app e.g. /index.htm +
+ If webApp is not specified then the path is will be absolute e.g. /www/avm_webapps/ROOT/index.htm + +
+ Output - The asset in JSON format +
+  data:
+         path, the full path of the asset.
+         name, the name of the asset
+         creator
+         createdDate, iso8601,
+         modifier
+         modifiedDate,  iso8601,
+         isLocked, boolean
+         isFile, boolean
+         isFolder, boolean
+         isDeleted, boolean
+	 	 children, JSON array, only present for folder
+	 	 fileSize, numeric, only present for files	
+  
]]>
/api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path} - - + /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path}?webApp={webApp?} + argument user required WCM Service diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.js index 4739648cd1..6ae8f0bc9c 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.js @@ -1,14 +1,14 @@ /* - * Get the modified items within a sandbox + * Get asset script */ function main() { var urlElements = url.extension.split("/"); var shortName = urlElements[0]; var boxName = urlElements[2]; + var pathArray = urlElements.slice(4); + var path = pathArray.join("/"); - var sandbox; - var webproject = webprojects.getWebProject(shortName); if (webproject == null) { @@ -17,6 +17,7 @@ function main() return; } + var sandbox; sandbox = webproject.getSandbox(boxName); if (sandbox == null) { @@ -26,21 +27,30 @@ function main() } var webApp = args["webApp"]; - - // set model properties - model.sandbox = sandbox; - model.webproject = webproject; + var asset; + if(webApp != null) { - - model.assets = sandbox.getModifiedAssetsWebApp(webApp); + asset = sandbox.getAssetWebApp(webApp, path); } else { - model.assets = sandbox.modifiedAssets; + asset = sandbox.getAsset(path); } + + if (asset == null) + { + // Site cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The asset, " + path + ", in webproject, " + shortName + ", does not exist."); + return; + } + + // set model properties + model.sandbox = sandbox; + model.webproject = webproject; + model.asset = asset } main() - + \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.json.ftl index 3afd137573..cd436e2544 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.get.json.ftl @@ -1,11 +1,6 @@ <#import "asset.lib.ftl" as assetLib/> { - data: [ - <#list assets as asset> - <@assetLib.assetJSON asset=asset /> - <#if asset_has_next>, - - ] + data: <@assetLib.assetJSON asset=asset depth=1 /> } 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 index f18d33365a..2f59670d7b 100644 --- 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 @@ -1,14 +1,36 @@ -<#macro assetJSON asset> - { - "path" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.path}" , - "name" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.name}" , +<#macro assetJSON asset depth=1> + { + "path" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.path}" , + "name" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.name}" , "creator" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.creator}" , "createdDate" : { "iso8601" : "${sandbox.createdDateAsISO8601}" }, "modifier" : <#escape x as jsonUtils.encodeJSONString(x)> "${asset.modifier}" , "modifiedDate" : { "iso8601" : "${asset.modifiedDateAsISO8601}" }, "isLocked" : ${asset.locked?string("true", "false")}, "isFile" : ${asset.file?string("true", "false")}, - "isDirectory" : ${asset.directory?string("true", "false")}, - "isDeleted" : ${asset.deleted?string("true", "false")} - } + "isFolder" : ${asset.folder?string("true", "false")}, + "isDeleted" : ${asset.deleted?string("true", "false")}, + "properties" : { + <#list asset.properties?keys as id> + <#assign property = asset.properties[id]> + "${id}" : "${property}" <#if id_has_next>, + + }, + <#if (asset.folder) > + <#if (depth > 0) > + "children" : [ + <#list asset.children as child > + <@assetJSON child depth-1 /> + <#if child_has_next>, + + ], + + <#else> + "version" : ${asset.version}, + "fileSize" : ${asset.fileSize}, + + "url" : <#escape x as jsonUtils.encodeJSONString(x)>"${url.serviceContext + "/api/wcm/webprojects/" + webproject.webProjectRef + "/sandboxes/" + sandbox.sandboxRef + "/assets" + asset.path}" , + "contentURL" : <#escape x as jsonUtils.encodeJSONString(x)>"${url.serviceContext + "/api/path/content/avm/" + sandbox.sandboxRef + asset.path}" + + } \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.desc.xml index a62791b0cd..e55109b383 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.desc.xml @@ -1,18 +1,30 @@ - Update a new WCM Asset. + Create a new WCM asset in the path of the URI. - + If the optional webApp argument is specified then the specified path is relative to the webapp. +
+ If webApp is not specified then the path is will be absolute e.g. /www/avm_webapps/ROOT +
+ JSON Input values +
+
name
mandatory name of this asset
+
type
mandatory "file" or "folder"
+
content/dt>
optional, string content of the new file, this is a convenience method, normally content is added via + the file upload which gives greater control over the content.
+
+ + JSON Return value: + data:The newly created asset in JSON format. + ]]>
/api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path} - - + /api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path}?webApp={webApp?} + argument user required WCM Service diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.js deleted file mode 100644 index 4739648cd1..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.getModifiedAssetsWebApp(webApp); - } - else - { - model.assets = sandbox.modifiedAssets; - } -} - -main() - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.ftl index 3afd137573..55145f9add 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.ftl @@ -1,11 +1,6 @@ <#import "asset.lib.ftl" as assetLib/> { - data: [ - <#list assets as asset> - <@assetLib.assetJSON asset=asset /> - <#if asset_has_next>, - - ] + data: <@assetLib.assetJSON asset=asset depth=0/> } diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.js new file mode 100644 index 0000000000..078772e5af --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.post.json.js @@ -0,0 +1,99 @@ +/* + * Post -create a new asset file/folder + * optionally created with properties and/or simple content + */ +function main() +{ + var urlElements = url.extension.split("/"); + var shortName = urlElements[0]; + var boxName = urlElements[2]; + var boxName = urlElements[2]; + var pathArray = urlElements.slice(4); + var path = pathArray.join("/"); + + 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; + 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"]; + + var parent = null; + if(webApp != null) + { + if(path=="") + { + path = "/"; + } + parent = sandbox.getAssetWebApp(webApp, path); + } + else + { + parent = sandbox.getAsset(path); + } + + if (parent == null) + { + // parent cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The folder, " + path + ", in webproject, " + shortName + ", does not exist."); + return; + } + + // Now read the values from the json form + if(!json.has("type")) + { + status.setCode(status.BAD_REQUEST, "JSON property 'type' must specified"); + return; + } + if(!json.has("name") || json.get("name").length() == 0) + { + status.setCode(status.BAD_REQUEST, "JSON property 'name' must specified"); + return; + } + + var name = json.get("name"); + var type = json.get("type"); + var content = null; + var properties = null + + if(json.has("content")) + { + content = json.get("content"); + } + + if(type == "file") + { + // create a new file + parent.createFile(name, content); + } + else + { + // create a new folder + parent.createFolder(name); + } + + // Get the newly created asset + var asset = sandbox.getAsset(parent.path + "/" + name); + + // set model properties + model.sandbox = sandbox; + model.webproject = webproject; + model.asset = asset; + + status.code = status.STATUS_CREATED + +} + +main() + diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.desc.xml index 27e31494a3..dc2b80cfad 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.desc.xml @@ -1,15 +1,27 @@ - Create a new WCM asset. + Update a WCM asset. - + + JSON Input properties +
+
name
optional rename this file or folder to this new name
+
path
optional move this file or folder to this path. The destination folder must already exist.
+
properties
optional JSONObject containing property/value pairs. Alfresco protected properties cannot be changed via this API and will remain unchanged.
+
+
+ JSON Return + data: + + ]]>
/api/wcm/webprojects/{webprojectref}/sandboxes/{sandboxref}/assets/{path} - + argument user required WCM Service diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.js deleted file mode 100644 index 4739648cd1..0000000000 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * 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.getModifiedAssetsWebApp(webApp); - } - else - { - model.assets = sandbox.modifiedAssets; - } -} - -main() - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.ftl index 3afd137573..2a241c6e09 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.ftl @@ -1,11 +1,5 @@ <#import "asset.lib.ftl" as assetLib/> { - data: [ - <#list assets as asset> - <@assetLib.assetJSON asset=asset /> - <#if asset_has_next>, - - ] + data: <@assetLib.assetJSON asset=asset depth=0 /> } - diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.js b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.js new file mode 100644 index 0000000000..e166bccb22 --- /dev/null +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/wcm/sandbox/Asset/asset.put.json.js @@ -0,0 +1,73 @@ +/* + * Update asset - put method + */ +function main() +{ + var urlElements = url.extension.split("/"); + var shortName = urlElements[0]; + var boxName = urlElements[2]; + var pathArray = urlElements.slice(4); + var path = pathArray.join("/"); + + var webproject = webprojects.getWebProject(shortName); + if (webproject == null) + { + // webproject cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The webproject, " + shortName + ", does not exist."); + return; + } + var sandbox; + sandbox = webproject.getSandbox(boxName); + if (sandbox == null) + { + // sandbox cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The sandbox, " + boxName + ", in webproject, " + shortName + ", does not exist."); + return; + } + + var webApp = args["webApp"]; + + var asset = null; + + if(webApp != null) + { + asset = sandbox.getAssetWebApp(webApp, path); + } + else + { + asset = sandbox.getAsset(path); + } + + if (asset == null) + { + // parent cannot be found + status.setCode(status.STATUS_NOT_FOUND, "The asset, " + path + ", in webproject, " + shortName + ", does not exist."); + return; + } + + // Is this a rename ?? + if(json.has("name") && json.get("name").length() > 0) + { + asset = asset.rename(json.get("name")); + } + + // Is this a move ?? + if(json.has("path") && json.get("path").length() > 0) + { + asset = asset.move(json.get("path")); + } + + // Is this a set properties? + if(json.has("properties")) + { + var properties = json.getJSONObject("properties"); + asset.setProperties(properties); + } + + // set model properties + model.asset = asset; + model.sandbox = sandbox; + model.webproject = webproject; +} + +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 index 1718b2c5bb..2ecbbe4ba4 100644 --- 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 @@ -2,7 +2,7 @@ { data: [ <#list assets as asset> - <@assetLib.assetJSON asset=asset /> + <@assetLib.assetJSON asset=asset depth=0 /> <#if asset_has_next>, ] 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 1c889eb312..64cc33cf38 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 @@ -47,7 +47,6 @@ function main() { // update the web project webproject.save(); - status.setCode(status.STATUS_OK, "Webproject " + webprojectref + " updated"); // Set Return value model.webproject = webproject; 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 1413430b50..00519da081 100644 --- a/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java +++ b/source/java/org/alfresco/repo/web/scripts/wcm/WebProjectTest.java @@ -184,12 +184,11 @@ public class WebProjectTest extends BaseWebScriptTest JSONObject update = new JSONObject(); update.put("name", BASIC_UPDATED_NAME); 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")); + JSONObject updateResult = new JSONObject(updateResponse.getContentAsString()); + JSONObject data = updateResult.getJSONObject("data"); + assertEquals(BASIC_UPDATED_NAME, data.get("name")); + assertEquals(BASIC_DESCRIPTION, data.get("description")); + assertEquals(BASIC_TITLE, data.get("title")); } /** diff --git a/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/AssetTest.java b/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/AssetTest.java index cc8c7aea7c..5002c242b5 100644 --- a/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/AssetTest.java +++ b/source/java/org/alfresco/repo/web/scripts/wcm/sandbox/AssetTest.java @@ -32,7 +32,6 @@ 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.avm.AVMService; import org.alfresco.service.cmr.security.AuthenticationService; import org.alfresco.service.cmr.security.PersonService; import org.alfresco.util.PropertyMap; @@ -40,14 +39,13 @@ 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 - * + * Junit tests of the REST bindings for WCM Assets */ public class AssetTest extends BaseWebScriptTest { @@ -55,11 +53,6 @@ public class AssetTest extends BaseWebScriptTest { private AuthenticationComponent authenticationComponent; private PersonService personService; - // TODO - Replace the use of these two services as and when the REST API is available - private AVMService avmNonLockingAwareService; - private AVMService avmLockingAwareService; - private char AVM_STORE_SEPARATOR = ':'; - private static final String USER_ONE = "WebProjectTestOne"; private static final String USER_TWO = "WebProjectTestTwo"; private static final String USER_THREE = "WebProjectTestThree"; @@ -81,7 +74,6 @@ public class AssetTest extends BaseWebScriptTest { private static final String WEBAPP_ROOT = "ROOT"; private static final String WEBAPP_YELLOW = "YELLOW"; private static final String WEBAPP_GREEN = "GREEN"; - private List createdWebProjects = new ArrayList(5); @@ -93,11 +85,7 @@ public class AssetTest extends BaseWebScriptTest { this.authenticationService = (AuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService"); this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent"); this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService"); - - // TODO - Replace the use of these two services as and when the REST API is available - this.avmNonLockingAwareService = (AVMService)getServer().getApplicationContext().getBean("AVMService"); - this.avmLockingAwareService = (AVMService)getServer().getApplicationContext().getBean("AVMLockingAwareService"); - + this.authenticationComponent.setSystemUserAsCurrentUser(); // Create users @@ -233,22 +221,20 @@ public class AssetTest extends BaseWebScriptTest { String webprojref = createWebProject(); createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); String sandboxref = createSandbox(webprojref, USER_ONE); - - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgeRootPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_ROOT; - String bodgeYellowPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_YELLOW; - - avmLockingAwareService.createDirectory(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps", WEBAPP_YELLOW); + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW ); String submitterURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/submitter"; + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "rootFile1" ); + JSONObject submitForm = new JSONObject(); submitForm.put("label", "the label"); submitForm.put("comment", "the comment"); submitForm.put("all", true); - Response response = sendRequest(new PostRequest(submitterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); + sendRequest(new PostRequest(submitterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); - - avmLockingAwareService.createFile(bodgeRootPath, "rootFile1"); - avmLockingAwareService.createFile(bodgeYellowPath, "yellowFile1"); + /* + * Background set up now create a new file which is our test + */ + createFile(webprojref, sandboxref, "/www/avm_webapps/" + WEBAPP_YELLOW, "yellowFile1" ); /** * Get the modified asset and verify its format @@ -257,6 +243,7 @@ public class AssetTest extends BaseWebScriptTest { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified?webApp=" + WEBAPP_YELLOW; Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK); JSONObject result = new JSONObject(list.getContentAsString()); + System.out.println(list.getContentAsString()); JSONArray lookupResult = result.getJSONArray("data"); assertTrue("testListUserSandbox", lookupResult.length() == 1); @@ -268,13 +255,13 @@ public class AssetTest extends BaseWebScriptTest { String creator = x.getString("creator"); boolean isFile = x.getBoolean("isFile"); boolean isDeleted = x.getBoolean("isDeleted"); - boolean isDirectory = x.getBoolean("isDirectory"); + boolean isFolder = x.getBoolean("isFolder"); assertNotNull("name is null", name); assertEquals("name is wrong", "yellowFile1", name); assertEquals("creator is wrong", "admin", creator); assertTrue("not isFile", isFile); - assertFalse("not isDirectory", isDirectory); + assertFalse("not isFolder", isFolder); assertFalse("not isDeleted", isDeleted); assertNotNull("path is null", path); @@ -324,9 +311,7 @@ public class AssetTest extends BaseWebScriptTest { /** * add a single asset */ - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgePath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT"; - avmLockingAwareService.createFile(bodgePath, "myFile1"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile1"); /** * Get the modified asset and verify its format @@ -346,13 +331,13 @@ public class AssetTest extends BaseWebScriptTest { String creator = x.getString("creator"); boolean isFile = x.getBoolean("isFile"); boolean isDeleted = x.getBoolean("isDeleted"); - boolean isDirectory = x.getBoolean("isDirectory"); + boolean isFolder = x.getBoolean("isFolder"); assertNotNull("name is null", name); assertEquals("name is wrong", "myFile1", name); assertEquals("creator is wrong", "admin", creator); assertTrue("not isFile", isFile); - assertFalse("not isDirectory", isDirectory); + assertFalse("not isDirectory", isFolder); assertFalse("not isDeleted", isDeleted); assertNotNull("path is null", path); @@ -361,20 +346,29 @@ public class AssetTest extends BaseWebScriptTest { } /** - * Add some more assets, a dir and a file + * Add a second asset */ - avmLockingAwareService.createDirectory(bodgePath, "fileA"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "fileA"); /** - * Get the modified assets - should be 2 (filex) is in a new dir + * Get the modified assets should be myFile1, fileA */ + { + String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; + Response list = sendRequest(new GetRequest(sandboxesURL), Status.STATUS_OK); + JSONObject result = new JSONObject(list.getContentAsString()); + JSONArray lookupResult = result.getJSONArray("data"); + + assertTrue("testListUserSandbox", lookupResult.length() == 2); + } /** * Add a new dir containing assets */ - avmLockingAwareService.createDirectory(bodgePath, "dir1"); - avmLockingAwareService.createFile(bodgePath + "/dir1", "filex"); - avmLockingAwareService.createFile(bodgePath + "/dir1", "filey"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "dir1"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/dir1", "filex"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/dir1", "filey"); + /** * Get the modified assets should be myFile1, fileA, dir1 @@ -400,10 +394,11 @@ public class AssetTest extends BaseWebScriptTest { createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); String sandboxref = createSandbox(webprojref, USER_ONE); - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgePath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT"; - avmLockingAwareService.createFile(bodgePath, "myFile1"); - + /** + * add a single asset + */ + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile1"); + String submitterURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/submitter"; /** @@ -469,7 +464,7 @@ public class AssetTest extends BaseWebScriptTest { * Positive test - Submit all */ { - avmLockingAwareService.createFile(bodgePath, "myFile2"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile2"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -484,8 +479,7 @@ public class AssetTest extends BaseWebScriptTest { submitForm.put("label", "the label"); submitForm.put("comment", "the comment"); submitForm.put("all", true); - Response response = sendRequest(new PostRequest(submitterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); - //TODO Nothing in the response now. + sendRequest(new PostRequest(submitterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); checkSandboxEmpty(webprojref, sandboxref); @@ -495,7 +489,7 @@ public class AssetTest extends BaseWebScriptTest { * Submit paths */ { - avmLockingAwareService.createFile(bodgePath, "myFile3"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile3"); JSONObject submitForm = new JSONObject(); submitForm.put("label", "the label"); submitForm.put("comment", "the comment"); @@ -511,7 +505,7 @@ public class AssetTest extends BaseWebScriptTest { * Submit assets - get a list of modified assets and submit them back */ { - avmLockingAwareService.createFile(bodgePath, "myFile4"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile4"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -538,14 +532,14 @@ public class AssetTest extends BaseWebScriptTest { * Also has a delete to process */ { - avmLockingAwareService.removeNode(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT/myFile3"); - avmLockingAwareService.createFile(bodgePath, "buffy.jpg"); - avmLockingAwareService.createDirectory(bodgePath, "vampires"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "master"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "drusilla"); - avmLockingAwareService.createDirectory(bodgePath, "humans"); - avmLockingAwareService.createFile(bodgePath + "/humans", "willow"); - avmLockingAwareService.createFile(bodgePath + "/humans", "xander"); + deleteFile(webprojref, sandboxref, "/www/avm_webapps/ROOT/myFile3"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "buffy.jpg"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "vampires"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "master"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "drusilla"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "humans"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "willow"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "xander"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -572,19 +566,20 @@ public class AssetTest extends BaseWebScriptTest { */ { // single file in existing dir - avmLockingAwareService.createFile(bodgePath + "/vampires", "angel"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "angel"); //delete from an existing dir - avmLockingAwareService.removeNode(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT/vampires/drusilla"); + deleteFile(webprojref, sandboxref, "/www/avm_webapps/ROOT/vampires/drusilla"); + // multiple file in existing dir - avmLockingAwareService.createFile(bodgePath + "/humans", "giles"); - avmLockingAwareService.createFile(bodgePath + "/humans", "dawn"); - avmLockingAwareService.createFile(bodgePath + "/humans", "anya"); - // new directory - avmLockingAwareService.createDirectory(bodgePath, "cast"); - avmLockingAwareService.createFile(bodgePath + "/cast", "Anthony Head"); - avmLockingAwareService.createFile(bodgePath + "/cast", "James Marsters"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "giles"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "dawn"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "anya"); + // new directory + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "cast"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/cast", "Anthony Head"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/cast", "James Marsters"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -656,11 +651,8 @@ public class AssetTest extends BaseWebScriptTest { createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); String sandboxref = createSandbox(webprojref, USER_ONE); - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgeRootPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_ROOT; - String bodgeYellowPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_YELLOW; - avmLockingAwareService.createDirectory(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps", WEBAPP_YELLOW); - + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW ); + String submitterURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/submitter"; JSONObject submitForm = new JSONObject(); submitForm.put("label", "the label"); @@ -671,8 +663,8 @@ public class AssetTest extends BaseWebScriptTest { /** * Now we can set up our test data */ - avmLockingAwareService.createFile(bodgeRootPath, "rootFile1"); - avmLockingAwareService.createFile(bodgeYellowPath, "yellowFile1"); + createFile(webprojref, sandboxref, "/www/avm_webapps/" + WEBAPP_ROOT, "rootFile1" ); + createFile(webprojref, sandboxref, "/www/avm_webapps/" + WEBAPP_YELLOW, "yellowFile1" ); /** * Submit YELLOW - Should leave root alone @@ -712,10 +704,7 @@ public class AssetTest extends BaseWebScriptTest { String webprojref = createWebProject(); createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); String sandboxref = createSandbox(webprojref, USER_ONE); - - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgePath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT"; - avmLockingAwareService.createFile(bodgePath, "myFile1"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile1"); String reverterURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/reverter"; @@ -756,7 +745,7 @@ public class AssetTest extends BaseWebScriptTest { * Positive test - Revert all */ { - avmLockingAwareService.createFile(bodgePath, "myFile2"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile2"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -769,8 +758,7 @@ public class AssetTest extends BaseWebScriptTest { JSONObject submitForm = new JSONObject(); submitForm.put("all", true); - Response response = sendRequest(new PostRequest(reverterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); - //TODO Nothing in the response now. + sendRequest(new PostRequest(reverterURL, submitForm.toString(), "application/json"), Status.STATUS_OK); checkSandboxEmpty(webprojref, sandboxref); @@ -780,7 +768,7 @@ public class AssetTest extends BaseWebScriptTest { * Revert via paths */ { - avmLockingAwareService.createFile(bodgePath, "myFile3"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile3"); JSONObject submitForm = new JSONObject(); JSONArray paths = new JSONArray(); @@ -794,7 +782,7 @@ public class AssetTest extends BaseWebScriptTest { * Revert assets - get a list of modified assets and revert them back */ { - avmLockingAwareService.createFile(bodgePath, "myFile4"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "myFile4"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -818,13 +806,13 @@ public class AssetTest extends BaseWebScriptTest { * Also has a delete to revert */ { - avmLockingAwareService.createFile(bodgePath, "buffy.jpg"); - avmLockingAwareService.createDirectory(bodgePath, "vampires"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "master"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "drusilla"); - avmLockingAwareService.createDirectory(bodgePath, "humans"); - avmLockingAwareService.createFile(bodgePath + "/humans", "willow"); - avmLockingAwareService.createFile(bodgePath + "/humans", "xander"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "buffy.jpg"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "vampires"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "master"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "drusilla"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "humans"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "willow"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "xander"); { String sandboxesURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/modified"; @@ -849,13 +837,13 @@ public class AssetTest extends BaseWebScriptTest { */ { // First submit a chunk of data - avmLockingAwareService.createFile(bodgePath, "buffy.jpg"); - avmLockingAwareService.createDirectory(bodgePath, "vampires"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "master"); - avmLockingAwareService.createFile(bodgePath + "/vampires", "drusilla"); - avmLockingAwareService.createDirectory(bodgePath, "humans"); - avmLockingAwareService.createFile(bodgePath + "/humans", "willow"); - avmLockingAwareService.createFile(bodgePath + "/humans", "xander"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "buffy.jpg"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "vampires"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "master"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "drusilla"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "humans"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "willow"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "xander"); JSONObject submitForm = new JSONObject(); submitForm.put("label", "the label"); @@ -867,18 +855,20 @@ public class AssetTest extends BaseWebScriptTest { // Now we can set up the data that will get reverted // single file in existing dir - avmLockingAwareService.createFile(bodgePath + "/vampires", "angel"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/vampires", "angel"); //delete from an existing dir - avmLockingAwareService.removeNode(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/ROOT/vampires/drusilla"); + deleteFile(webprojref, sandboxref, "/www/avm_webapps/ROOT/vampires/drusilla"); + // multiple file in existing dir - avmLockingAwareService.createFile(bodgePath + "/humans", "giles"); - avmLockingAwareService.createFile(bodgePath + "/humans", "dawn"); - avmLockingAwareService.createFile(bodgePath + "/humans", "anya"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "giles"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "dawn"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/humans", "anya"); + // new directory - avmLockingAwareService.createDirectory(bodgePath, "cast"); - avmLockingAwareService.createFile(bodgePath + "/cast", "Anthony Head"); - avmLockingAwareService.createFile(bodgePath + "/cast", "James Marsters"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "cast"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/cast", "Anthony Head"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/cast", "James Marsters"); { @@ -947,10 +937,7 @@ public class AssetTest extends BaseWebScriptTest { createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); String sandboxref = createSandbox(webprojref, USER_ONE); - //TODO REPLACE THIS IMPLEMENTATION WITH THE REST API ONCE AVAILABLE - String bodgeRootPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_ROOT; - String bodgeYellowPath = sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps/" + WEBAPP_YELLOW; - avmLockingAwareService.createDirectory(sandboxref + AVM_STORE_SEPARATOR + "/www/avm_webapps", WEBAPP_YELLOW); + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW); String submitterURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/submitter"; JSONObject submitForm = new JSONObject(); @@ -962,8 +949,8 @@ public class AssetTest extends BaseWebScriptTest { /** * Now we can set up our test data */ - avmLockingAwareService.createFile(bodgeRootPath, "rootFile1"); - avmLockingAwareService.createFile(bodgeYellowPath, "yellowFile1"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", "rootFile1"); + createFile(webprojref, sandboxref, WEBAPP_YELLOW, "/", "yellowFile1"); /** * Revert YELLOW - Should leave root alone @@ -993,4 +980,487 @@ public class AssetTest extends BaseWebScriptTest { assertEquals("name is wrong", "rootFile1", name); } } // End of testRevertAssetsWebAppTest + + public void testGetAsset() throws Exception + { + final String YELLOW_FILE = "YellowFile.xyz"; + final String ROOT_FILE = "index.htm"; + + this.authenticationComponent.setCurrentUser("admin"); + String webprojref = createWebProject(); + createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); + String sandboxref = createSandbox(webprojref, USER_ONE); + + // Set up a file/folder to read + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", ROOT_FILE); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "characters"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/characters", "Buffy Ann Summers.jpg"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/characters", "Willow Rosenberg.png"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/characters", "Joyce Summers.jpg"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/characters", "Cordelia Chase.jpg"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/characters", "out"); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/characters/out", "Giles"); + + createFile(webprojref, sandboxref, WEBAPP_YELLOW, "/", YELLOW_FILE); + + /** + * Positive test - read ROOT folder + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT ; + Response root = sendRequest(new GetRequest(rootURL), Status.STATUS_OK); + JSONObject result = new JSONObject(root.getContentAsString()); + System.out.println(root.getContentAsString()); + JSONObject rootDir = result.getJSONObject("data"); + String name = rootDir.getString("name"); + JSONArray children = rootDir.getJSONArray("children"); + assertEquals("name is wrong", WEBAPP_ROOT, name); + assertEquals("too many children", children.length(), 2); + } + + /** + * Positive test - read yellowFile file absolute + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + Response yellow = sendRequest(new GetRequest(yellowURL), Status.STATUS_OK); + JSONObject result = new JSONObject(yellow.getContentAsString()); + JSONObject yellowFile = result.getJSONObject("data"); + String name = yellowFile.getString("name"); + long version = yellowFile.getLong("version"); + long fileSize = yellowFile.getLong("fileSize"); + assertEquals("name is wrong", YELLOW_FILE, name); + } + + /** + * Positive test - read yellowFile file relative to webApp + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/" + YELLOW_FILE +"?webApp="+ WEBAPP_YELLOW; + Response yellow = sendRequest(new GetRequest(yellowURL), Status.STATUS_OK); + JSONObject result = new JSONObject(yellow.getContentAsString()); + JSONObject yellowFile = result.getJSONObject("data"); + String name = yellowFile.getString("name"); + long version = yellowFile.getLong("version"); + long fileSize = yellowFile.getLong("fileSize"); + assertEquals("name is wrong", YELLOW_FILE, name); + } + + /** + * Negative test - read file that does not exist + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/crap" ; + sendRequest(new GetRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + + /** + * Negative test - missing web project + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + "crap" + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + sendRequest(new GetRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + + /** + * Negative test - missing sandbox + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + "crap" + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + sendRequest(new GetRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + + + /** + * Positive test - read children + */ + + + } + + public void testDeleteAsset() throws Exception + { + final String YELLOW_FILE = "YellowFile.xyz"; + final String YELLOW_FILE2 = "Buffy.jpg"; + final String ROOT_FILE = "index.htm"; + + this.authenticationComponent.setCurrentUser("admin"); + String webprojref = createWebProject(); + createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); + String sandboxref = createSandbox(webprojref, USER_ONE); + + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW); + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", ROOT_FILE); + createFile(webprojref, sandboxref, WEBAPP_YELLOW, "/", YELLOW_FILE); + createFile(webprojref, sandboxref, WEBAPP_YELLOW, "/", YELLOW_FILE2); + + + /** + * Positive test + * + * Read ROOT folder + * + * Delete ROOT folder + * + * Fail to read root folder + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT ; + sendRequest(new GetRequest(rootURL), Status.STATUS_OK); + + sendRequest(new DeleteRequest(rootURL), Status.STATUS_OK); + + sendRequest(new GetRequest(rootURL), Status.STATUS_NOT_FOUND); + } + + /** + * Positive test - delete yellowFile file with absolute path + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + sendRequest(new GetRequest(yellowURL), Status.STATUS_OK); + + sendRequest(new DeleteRequest(yellowURL), Status.STATUS_OK); + + sendRequest(new GetRequest(yellowURL), Status.STATUS_NOT_FOUND); + + /** + * Part 2 Negative test - fail delete file that does not exist + */ + sendRequest(new DeleteRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + + /** + * Positive test - delete yellowFile file with relative path + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/" + YELLOW_FILE2 + "?webApp="+ WEBAPP_YELLOW ; + sendRequest(new GetRequest(yellowURL), Status.STATUS_OK); + + sendRequest(new DeleteRequest(yellowURL), Status.STATUS_OK); + + sendRequest(new GetRequest(yellowURL), Status.STATUS_NOT_FOUND); + } + + /** + * Negative test - delete missing web project + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + "crap" + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + sendRequest(new DeleteRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + + /** + * Negative test - missing sandbox + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + "crap" + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW + "/" + YELLOW_FILE ; + sendRequest(new DeleteRequest(yellowURL), Status.STATUS_NOT_FOUND); + + } + } + + /** + * Create Asset + * @throws Exception + */ + public void testCreateAsset() throws Exception + { + final String YELLOW_FILE = "YellowFile.xyz"; + final String ROOT_FILE = "index.htm"; + + this.authenticationComponent.setCurrentUser("admin"); + String webprojref = createWebProject(); + createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); + String sandboxref = createSandbox(webprojref, USER_ONE); + + /** + * Positive test - create a Yellow webapp with an absolute path + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps"; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", WEBAPP_YELLOW); + submitForm.put("type", "folder"); + + Response response = sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + boolean isFolder = lookupResult.getBoolean("isFolder"); + boolean isFile = lookupResult.getBoolean("isFile"); + + assertEquals("name is wrong", WEBAPP_YELLOW, name); + assertTrue("folder not true", isFolder); + assertFalse("file not false", isFile); + + } + + /** + * Positive test - create a file in the root webapp with a little content + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", ROOT_FILE); + submitForm.put("type", "file"); + submitForm.put("content", "Hello World"); + Response response = sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + long fileSize = lookupResult.getLong("fileSize"); + assertEquals("name is wrong", ROOT_FILE, name); + boolean isFolder = lookupResult.getBoolean("isFolder"); + boolean isFile = lookupResult.getBoolean("isFile"); + assertTrue("file not true", isFile); + assertFalse("folder not false", isFolder); + assertTrue("file is empty", fileSize > 0); + } + + /** + * Positive test - create a file in the new Yellow webapp dir + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", YELLOW_FILE); + submitForm.put("type", "file"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Positive test - create a file in the new Yellow webapp dir with a relative path + */ + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets/" + "?webApp=" + WEBAPP_YELLOW; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", "willow.jpg"); + submitForm.put("type", "file"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Positive test - create a file in the new Yellow webapp dir with a relative path with some depth + */ + { + createFolder(webprojref, sandboxref, WEBAPP_YELLOW, "/", "humans" ); + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets/humans" + "?webApp=" + WEBAPP_YELLOW; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", "dawn.jpg"); + submitForm.put("type", "file"); + Response response = sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + String path = lookupResult.getString("path"); + assertEquals("name not correct", name, "dawn.jpg"); + assertEquals("path not correct", path, "/www/avm_webapps/" + WEBAPP_YELLOW + "/humans/dawn.jpg"); + + } + + + } + + /** + * Test rename asset + * @throws Exception + */ + public void testRenameAsset() throws Exception + { + final String YELLOW_FILE = "buffy.jpg"; + final String ROOT_FILE = "index.htm"; + final String PURPLE_FILE = "buffy.htm"; + final String PURPLE_FILE2 = "willow.htm"; + final String ROOT_MOVED_FILE = "smashing.htm"; + + this.authenticationComponent.setCurrentUser("admin"); + String webprojref = createWebProject(); + createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); + String sandboxref = createSandbox(webprojref, USER_ONE); + + /** + * Positive test - create a Yellow webapp with some content, rename it to green + */ + { + createFolder(webprojref, sandboxref, "/www/avm_webapps", WEBAPP_YELLOW ); + createFile(webprojref, sandboxref, WEBAPP_YELLOW, "/", YELLOW_FILE); + + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_YELLOW; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", WEBAPP_GREEN); + Response response = sendRequest(new PutRequest(yellowURL, submitForm.toString(), "application/json"), Status.STATUS_OK); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + assertEquals("name is wrong", WEBAPP_GREEN, name); + } + + /** + * rename a file - absolute + */ + { + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", ROOT_FILE); + + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT + "/" + ROOT_FILE; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", ROOT_MOVED_FILE); + Response response = sendRequest(new PutRequest(yellowURL, submitForm.toString(), "application/json"), Status.STATUS_OK); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + assertEquals("name is wrong", ROOT_MOVED_FILE, name); + + /** + * Part 2 Negative test - rename a file that should no longer exist + */ + sendRequest(new PutRequest(yellowURL, submitForm.toString(), "application/json"), Status.STATUS_NOT_FOUND); + } + + /** + * rename a file - relative + */ + { + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", PURPLE_FILE); + + String purpleURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets/" + PURPLE_FILE +"?webApp="+WEBAPP_ROOT; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", PURPLE_FILE2); + Response response = sendRequest(new PutRequest(purpleURL, submitForm.toString(), "application/json"), Status.STATUS_OK); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + assertEquals("name is wrong", PURPLE_FILE2, name); + } + + + /** + * Negative test - missing sandbox + */ + { + String yellowURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + "crap" + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT + "/" + ROOT_MOVED_FILE; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", ROOT_MOVED_FILE); + sendRequest(new PutRequest(yellowURL, submitForm.toString(), "application/json"), Status.STATUS_NOT_FOUND); + } + } + + /** + * Test rename asset + * @throws Exception + */ + public void testMoveAsset() throws Exception + { + final String YELLOW_FILE = "buffy.jpg"; + final String ROOT_FILE = "index.htm"; + + this.authenticationComponent.setCurrentUser("admin"); + String webprojref = createWebProject(); + createMembership(webprojref, USER_ONE, ROLE_CONTENT_MANAGER); + String sandboxref = createSandbox(webprojref, USER_ONE); + + /** + * move a file + */ + { + createFile(webprojref, sandboxref, WEBAPP_ROOT, "/", ROOT_FILE); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/", "actors"); + createFolder(webprojref, sandboxref, WEBAPP_ROOT, "/actors", "humans"); + + String myURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + "/www/avm_webapps/" + WEBAPP_ROOT + "/" + ROOT_FILE; + JSONObject submitForm = new JSONObject(); + submitForm.put("path", "/www/avm_webapps/ROOT/actors/humans"); + Response response = sendRequest(new PutRequest(myURL, submitForm.toString(), "application/json"), Status.STATUS_OK); + System.out.println(response.getContentAsString()); + JSONObject result = new JSONObject(response.getContentAsString()); + JSONObject lookupResult = result.getJSONObject("data"); + String name = lookupResult.getString("name"); + assertEquals("name is wrong", ROOT_FILE, name); + + /** + * Part 2 Negative test - rename a file that should no longer exist + */ + sendRequest(new PutRequest(myURL, submitForm.toString(), "application/json"), Status.STATUS_NOT_FOUND); + } + } + + /** + * Utility method to create a folder + * @param webprojref + * @param sandboxref + * @param parent + * @param name + * @throws Exception + */ + + private void createFolder(String webprojref, String sandboxref, String parent, String name) throws Exception + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + parent; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", name); + submitForm.put("type", "folder"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Utility method to create a folder in a web app + * @param webprojref + * @param sandboxref + * @param parent + * @param name + * @throws Exception + */ + private void createFolder(String webprojref, String sandboxref, String webApp, String parent, String name) throws Exception + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + parent + "?webApp="+webApp; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", name); + submitForm.put("type", "folder"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + + /** + * Utility method to create a file + * @param webprojref + * @param sandboxref + * @param parent + * @param name + + */ + private void createFile(String webprojref, String sandboxref, String parent, String name) throws Exception + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + parent; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", name); + submitForm.put("type", "file"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + /** + * Utility method to create a file in a web app + * @param webprojref + * @param sandboxref + * @param parent + * @param name + */ + + private void createFile(String webprojref, String sandboxref, String webApp, String parent, String name) throws Exception + { + String rootURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + parent+ "?webApp="+webApp; + JSONObject submitForm = new JSONObject(); + submitForm.put("name", name); + submitForm.put("type", "file"); + sendRequest(new PostRequest(rootURL, submitForm.toString(), "application/json"), Status.STATUS_CREATED); + } + + private void deleteFile(String webprojref, String sandboxref, String path) throws Exception + { + String deleteURL = URL_WEB_PROJECT + "/" + webprojref + URI_SANDBOXES + "/" + sandboxref + "/assets" + path ; + sendRequest(new DeleteRequest(deleteURL), Status.STATUS_OK); + } } // End of AssetTest