Fix/mnt 19952 permissions islocked includes

This commit is contained in:
Alessandro Benedetti
2018-11-05 10:54:29 +00:00
parent f74e3899d5
commit a2fbc0943a
2 changed files with 101 additions and 11 deletions
@@ -18,8 +18,6 @@
*/
package org.alfresco.rest.search;
import javax.naming.AuthenticationException;
import org.alfresco.dataprep.SiteService.Visibility;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestResponse;
@@ -33,6 +31,8 @@ import org.alfresco.utility.model.UserModel;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
import javax.naming.AuthenticationException;
/**
* Abstract Search test class that contains useful methods
* such as:
@@ -129,15 +129,23 @@ public class AbstractSearchTest extends RestTest
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
/**
*
* Helper method which create an http post request to Search API end point.
* @param term String search term
* Executes the given search request without throwing checked exceptions (a {@link RuntimeException} will be thrown in case).
* @param query the search request.
* @return {@link SearchResponse} response.
* @throws Exception if error
*
*/
protected SearchResponse query(SearchRequest query) throws Exception
{
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
try
{
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
catch (final Exception exception)
{
throw new RuntimeException(exception);
}
}
protected SearchRequest createQuery(String term)
@@ -148,6 +156,7 @@ public class AbstractSearchTest extends RestTest
query.setQuery(queryReq);
return query;
}
protected SearchRequest carsQuery()
{
return createQuery("cars");
@@ -18,9 +18,8 @@
*/
package org.alfresco.rest.search;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.alfresco.rest.model.body.RestNodeLockBodyModel;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.testrail.ExecutionType;
import org.alfresco.utility.testrail.annotation.TestRail;
@@ -28,7 +27,14 @@ import org.hamcrest.Matchers;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
import junit.framework.Assert;
import java.util.ArrayList;
import java.util.List;
import static org.codehaus.groovy.runtime.InvokerHelper.asList;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* Search end point Public API test.
@@ -74,7 +80,83 @@ public class SearchTest extends AbstractSearchTest
response.getContext().assertThat().field("request").isNotEmpty();
}
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ACS_61n }) @TestRail(section = {
TestGroup.REST_API, TestGroup.SEARCH,
TestGroup.ACS_61n }, executionType = ExecutionType.REGRESSION, description = "Checks the \"include\" request parameter support the 'permissions' option") public void searchQuery_includePermissions_shouldReturnNodeWithPermissionsInformation()
throws Exception
{
String query = "fox";
String include = "permissions";
SearchRequest retrievalQueryIncludingPermissionsInformation = createQuery(query);
retrievalQueryIncludingPermissionsInformation.setInclude(asList(include));
query(retrievalQueryIncludingPermissionsInformation);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.entries[0].entry.permissions", notNullValue());
SearchRequest retrievalQueryNotIncludingLockInformation = createQuery(query);
query(retrievalQueryNotIncludingLockInformation);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.entries[0].entry.permissions", nullValue());
}
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ACS_61n })
@TestRail(section = {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ACS_61n }, executionType = ExecutionType.REGRESSION,
description = "Checks the \"include\" request parameter support the 'isLocked' option")
public void searchQuery_includeIsLocked_shouldReturnNodeWithLockInformation() throws Exception {
String query = "fox";
String include = "isLocked";
SearchRequest retrievalQueryIncludingLockInformation = createQuery(query);
retrievalQueryIncludingLockInformation.setInclude(asList(include));
query(retrievalQueryIncludingLockInformation);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.entries[0].entry.isLocked", equalTo(false));
RestNodeLockBodyModel lockBodyModel = new RestNodeLockBodyModel();
lockBodyModel.setLifetime("EPHEMERAL");
lockBodyModel.setTimeToExpire(20);
lockBodyModel.setType("FULL");
restClient.authenticateUser(userModel).withCoreAPI().usingNode(file).usingParams("include=isLocked").lockNode(lockBodyModel);
query(retrievalQueryIncludingLockInformation);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.entries[0].entry.isLocked", equalTo(true));
SearchRequest retrievalQueryNotIncludingLockInformation = createQuery(query);
query(retrievalQueryNotIncludingLockInformation);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.entries[0].entry.isLocked", nullValue());
}
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ACS_61n })
@TestRail(section = {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ACS_61n }, executionType = ExecutionType.REGRESSION,
description = "Checks the \"include\" request parameter does not support the 'notValid' option")
public void searchQuery_includeInvalid_shouldReturnBadResponse()
{
String query = "fox";
String notValidInclude = "notValid";
SearchRequest permissionsRetrieval = createQuery(query);
permissionsRetrieval.setInclude(asList(notValidInclude));
query(permissionsRetrieval);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse()
.assertThat()
.body("error.briefSummary", containsString("An invalid argument was received "+notValidInclude));
}
// Test that when fields parameter is set, only restricted fields appear in the response
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
public void searchWithFields() throws Exception
@@ -98,5 +180,4 @@ public class SearchTest extends AbstractSearchTest
restClient.onResponse().assertThat().body("list.entries.entry[0].name", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0].id", Matchers.nullValue());
}
}