Merged HEAD (5.2) to 5.2.N (5.2.1)

127531 jkaabimofrad: Merged API-STRIKES-BACK (5.2.0) to HEAD (5.2)
      125513 jvonka: RA-779 / RA-780: Sites API - create site & delete site
      - follow-on improvemnts (generating site id, adding favorite with option to sip)
      - more tests (+ve & -ve)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@127641 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-06-03 14:00:09 +00:00
parent 96a9c61e8b
commit 5e3eff4113
6 changed files with 203 additions and 136 deletions

View File

@@ -63,7 +63,6 @@ import org.alfresco.rest.api.tests.client.data.SiteImpl;
import org.alfresco.rest.api.tests.client.data.SiteMember;
import org.alfresco.rest.api.tests.client.data.SiteMembershipRequest;
import org.alfresco.rest.api.tests.client.data.Tag;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.apache.chemistry.opencmis.client.api.CmisObject;
import org.apache.chemistry.opencmis.client.api.Document;
import org.apache.chemistry.opencmis.client.api.FileableCmisObject;
@@ -676,23 +675,19 @@ public class PublicApiClient
throw new PublicApiException(e);
}
}
public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage) throws PublicApiException
public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage) throws PublicApiException
{
return getSingle(entityCollectionName, entityId, relationCollectionName, relationId, errorMessage, HttpServletResponse.SC_OK);
}
public HttpResponse getSingle(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage, int expectedStatus) throws PublicApiException
{
try
{
HttpResponse response = get("public", entityCollectionName, entityId, relationCollectionName, relationId, null);
if (HttpServletResponse.SC_OK != response.getStatusCode())
{
String msg = errorMessage + ": \n" +
" Response: " + response;
throw new PublicApiException(msg, response);
}
else
{
return response;
}
checkStatus(errorMessage, expectedStatus, response);
return response;
}
catch(IOException e)
{
@@ -727,46 +722,38 @@ public class PublicApiClient
throw new PublicApiException(e);
}
}
public HttpResponse create(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException
{
return create(entityCollectionName, entityId, relationCollectionName, relationId, body, errorMessage, HttpServletResponse.SC_CREATED);
}
public HttpResponse create(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage) throws PublicApiException
public HttpResponse create(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String body, String errorMessage, int expectedStatus) throws PublicApiException
{
try
{
HttpResponse response = post("public", entityCollectionName, entityId, relationCollectionName, relationId, body);
if (HttpServletResponse.SC_CREATED != response.getStatusCode())
{
String msg = errorMessage + ": \n" +
" Response: " + response;
throw new PublicApiException(msg, response);
}
else
{
return response;
}
checkStatus(errorMessage, expectedStatus, response);
return response;
}
catch(IOException e)
catch (IOException e)
{
throw new PublicApiException(e);
}
}
public HttpResponse remove(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage) throws PublicApiException
{
return remove(entityCollectionName, entityId, relationCollectionName, relationId, errorMessage, HttpServletResponse.SC_GONE);
}
public HttpResponse remove(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage) throws PublicApiException
public HttpResponse remove(String entityCollectionName, String entityId, String relationCollectionName, String relationId, String errorMessage, int expectedStatus) throws PublicApiException
{
try
{
HttpResponse response = delete("public", entityCollectionName, entityId, relationCollectionName, relationId);
if (HttpServletResponse.SC_NO_CONTENT != response.getStatusCode())
{
String msg = errorMessage + ": \n" +
" Response: " + response;
throw new PublicApiException(msg, response);
}
else
{
return response;
}
checkStatus(errorMessage, expectedStatus, response);
return response;
}
catch(IOException e)
{
@@ -783,6 +770,17 @@ public class PublicApiClient
assertNotNull(source);
return source;
}
public void checkStatus(String errorMessage, int expectedStatus, HttpResponse response) throws PublicApiException
{
int actualStatus = response.getStatusCode();
if ((expectedStatus > 0) && (expectedStatus != actualStatus))
{
String msg = "Status code " + actualStatus + " returned, but expected " + expectedStatus + ": \n"+
errorMessage + ": \n" + " Response: " + response;
throw new PublicApiException(msg, response);
}
}
}
public static class ListResponse<T>
@@ -815,22 +813,44 @@ public class PublicApiClient
HttpResponse response = getAll("sites", null, null, null, params, "Failed to get sites");
return SiteImpl.parseSites(response.getJsonResponse());
}
public Site getSite(String siteId) throws PublicApiException
{
return getSite(siteId, 200);
}
public Site getSite(String siteId) throws PublicApiException
public Site getSite(String siteId, int expectedStatus) throws PublicApiException
{
HttpResponse response = getSingle("sites", siteId, null, null, "Failed to get site " + siteId);
return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry"));
HttpResponse response = getSingle("sites", siteId, null, null, "Failed to get site " + siteId, expectedStatus);
if ((response != null) && (response.getJsonResponse() != null))
{
return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry"));
}
else
{
return null;
}
}
public Site createSite(Site site) throws PublicApiException
public Site createSite(Site site) throws PublicApiException
{
return createSite(site, 201);
}
public Site createSite(Site site, int expectedStatus) throws PublicApiException
{
HttpResponse response = create("sites", null, null, null, site.toJSON().toString(), "Failed to create site");
return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry"));
HttpResponse response = create("sites", null, null, null, site.toJSON().toString(), "Failed to create site "+site.getTitle(), expectedStatus);
return SiteImpl.parseSite((JSONObject)response.getJsonResponse().get("entry"));
}
public void removeSite(String siteId) throws PublicApiException
{
remove("sites", siteId, null, null, "Failed to remove site");
removeSite(siteId, 204);
}
public void removeSite(String siteId, int expectedStatus) throws PublicApiException
{
remove("sites", siteId, null, null, "Failed to remove site", expectedStatus);
}
public ListResponse<SiteContainer> getSiteContainers(String siteId, Map<String, String> params) throws PublicApiException

View File

@@ -218,6 +218,11 @@ public class SiteImpl implements Serializable, Site, Comparable<SiteImpl>, Expec
public static Site parseSite(JSONObject jsonObject)
{
if (jsonObject == null)
{
return null;
}
String id = (String)jsonObject.get("id");
String guid = (String)jsonObject.get("guid");
String title = (String)jsonObject.get("title");