mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merge WCM_SERVICES into HEAD 11697, 11698, 11702, 11751, 11801, 11924, 12023, 12073
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12076 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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<String> createdWebProjects = new ArrayList<String>(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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user