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

129168 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
      128517 jvonka: REPO-874: Improve REST fwk: improve error message if a POST operation is attempted with multiple items
      - rationalise the code when handling POST for an API "operation" or POST to a collection that is marked as "allowMultiple=false"
      - they should now consistently return the same existing error message: "Only 1 entity is supported in the HTTP request body"
      - add api sanity tests to "create site", "create rating" and some of the node op's, such as "/move" & "/copy"


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129342 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alexandru Epure
2016-08-09 14:12:44 +00:00
parent 2254b1fa0e
commit c3eeea134f
4 changed files with 103 additions and 38 deletions

View File

@@ -1659,6 +1659,17 @@ public class NodeApiTest extends AbstractBaseApiTest
publicApiClient.setRequestContext(new RequestContext("-default-", "admin", "admin"));
response = publicApiClient.post(getScope(), "nodes/"+ddNodeId+"/move", null, null, null, toJsonAsStringNonNull(tgt));
checkStatus(403, response.getStatusCode());
// -ve test - cannot move to multiple destinations in single POST call (unsupported)
List<NodeTarget> nodeDestinations = new ArrayList<>(2);
NodeTarget nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(f1Id);
nodeDestinations.add(nodeTarget);
nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(f2Id);
nodeDestinations.add(nodeTarget);
post("nodes/"+d1Id+"/move", user1, toJsonAsStringNonNull(nodeDestinations), null, 405);
}
/**
@@ -1746,6 +1757,17 @@ public class NodeApiTest extends AbstractBaseApiTest
tgt = new NodeTarget();
tgt.setTargetParentId(rootNodeId);
post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(tgt), null, 403);
// -ve test - cannot copy to multiple destinations in single POST call (unsupported)
List<NodeTarget> nodeDestinations = new ArrayList<>(2);
NodeTarget nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(sourceId);
nodeDestinations.add(nodeTarget);
nodeTarget = new NodeTarget();
nodeTarget.setTargetParentId(targetId);
nodeDestinations.add(nodeTarget);
post("nodes/"+d1Id+"/copy", user1, toJsonAsStringNonNull(nodeDestinations), null, 405);
}
@Test

View File

@@ -1,28 +1,28 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.rest.api.tests;
import static org.junit.Assert.assertEquals;
@@ -59,6 +59,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
import org.apache.commons.httpclient.HttpStatus;
import org.json.simple.JSONArray;
import org.junit.Test;
public class TestNodeRatings extends EnterpriseTestApi
@@ -467,6 +468,22 @@ public class TestNodeRatings extends EnterpriseTestApi
// Test Case cloud-1977
// invalid methods
{
try
{
// -ve test - cannot create multiple ratings in single POST call (unsupported)
List<NodeRating> ratings = new ArrayList<>(2);
ratings.add(new NodeRating("likes", true));
ratings.add(new NodeRating("likes", false));
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
nodesProxy.create("nodes", nodeRef1.getId(), "ratings", null, JSONArray.toJSONString(ratings), "Unable to POST to multiple ratings");
fail();
}
catch(PublicApiException e)
{
assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode());
}
// get an arbitrary rating
publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11.getId()));
ListResponse<NodeRating> resp = nodesProxy.getNodeRatings(nodeRef1.getId(), createParams(getPaging(0, Integer.MAX_VALUE), null));

View File

@@ -29,6 +29,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -47,6 +48,7 @@ import org.alfresco.rest.api.tests.client.data.SiteRole;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.GUID;
import org.apache.commons.httpclient.HttpStatus;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.junit.Before;
import org.junit.Test;
@@ -311,6 +313,15 @@ public class TestSites extends EnterpriseTestApi
sitesProxy.removeSite(siteId); // cleanup
}
// -ve test - cannot create multiple sites in single POST call (unsupported)
{
List<Site> sites = new ArrayList<>(2);
sites.add(new SiteImpl(null, "siteA1", null, "siteA1", null, SiteVisibility.PRIVATE.toString(), null, null));
sites.add(new SiteImpl(null, "siteB1", null, "siteB1", null, SiteVisibility.PRIVATE.toString(), null, null));
sitesProxy.create("sites", null, null, null, JSONArray.toJSONString(sites), null, 405);
}
// -ve tests - belts-and-braces for unsupported methods
{