fix merge

This commit is contained in:
Michael
2018-05-22 11:17:10 +01:00
15 changed files with 1004 additions and 165 deletions
@@ -1,5 +1,11 @@
package org.alfresco.rest.discovery;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.model.RestDiscoveryModel;
@@ -47,4 +53,30 @@ public class DiscoveryTests extends RestTest
response.getRepository().getEdition().equals(edition);
response.getRepository().getStatus().assertThat().field("isReadOnly").is(false);
}
@Test(groups = { TestGroup.REST_API, TestGroup.DISCOVERY, TestGroup.ALL_AMPS, TestGroup.SANITY })
@TestRail(section = { TestGroup.REST_API, TestGroup.DISCOVERY }, executionType = ExecutionType.SANITY,
description = "Sanity tests for GET /discovery endpoint")
public void getRepositoryInstalledModules() throws Exception
{
// Get repository info using Discovery API
restClient.authenticateUser(userModel).withDiscoveryAPI().getRepositoryInfo();
restClient.assertStatusCodeIs(HttpStatus.OK);
// Check that all modules are present
List<String> modules = restClient.onResponse().getResponse().jsonPath().getList("entry.repository.modules.id", String.class);
assertTrue(modules.contains("alfresco-aos-module"));
assertTrue(modules.contains("org.alfresco.integrations.google.docs"));
assertTrue(modules.contains("org_alfresco_integrations_S3Connector"));
assertTrue(modules.contains("org_alfresco_module_xamconnector"));
assertTrue(modules.contains("org.alfresco.module.KofaxAddon"));
assertTrue(modules.contains("alfresco-content-connector-for-salesforce-repo"));
assertTrue(modules.contains("alfresco-share-services"));
assertTrue(modules.contains("alfresco-saml-repo"));
assertTrue(modules.contains("org_alfresco_device_sync_repo"));
// Check that all installed modules are in INSTALLED state
List<String> modulesStates = restClient.onResponse().getResponse().jsonPath().getList("entry.repository.modules.installState", String.class);
assertEquals(Collections.frequency(modulesStates, "INSTALLED"), 9);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,14 +18,19 @@
*/
package org.alfresco.rest.search;
import javax.naming.AuthenticationException;
import org.alfresco.dataprep.SiteService.Visibility;
import org.alfresco.rest.RestTest;
import org.alfresco.rest.model.builder.NodesBuilder;
import org.alfresco.utility.model.ContentModel;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.utility.Utility;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel;
import org.alfresco.utility.model.SiteModel;
import org.alfresco.utility.model.UserModel;
import org.springframework.http.HttpStatus;
import org.testng.annotations.BeforeClass;
/**
@@ -36,41 +41,65 @@ import org.testng.annotations.BeforeClass;
* <li>Preparing search requests.
*
* @author Michael Suzuki
* @author Meenal Bhave
*
*/
public class AbstractSearchTest extends RestTest
{
protected static final String SEARCH_DATA_SAMPLE_FOLDER = "folder";
UserModel userModel, adminUserModel;
SiteModel siteModel;
UserModel searchedUser;
NodesBuilder nodesBuilder;
protected FileModel file,file2;
protected static final String SEARCH_DATA_SAMPLE_FOLDER = "FolderSearch";
protected UserModel userModel, adminUserModel;
protected SiteModel siteModel;
protected UserModel searchedUser;
protected FileModel file, file2, file3, file4;
protected static String unique_searchString;
@BeforeClass(alwaysRun = true)
public void dataPreparation() throws Exception
{
adminUserModel = dataUser.getAdminUser();
userModel = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
userModel = dataUser.createRandomTestUser("UserSearch");
siteModel = new SiteModel(RandomData.getRandomName("SiteSearch"));
siteModel.setVisibility(Visibility.PRIVATE);
siteModel = dataSite.usingUser(userModel).createSite(siteModel);
unique_searchString = siteModel.getTitle().replace("SiteSearch", "Unique");
/*
* Create the following file structure for preconditions :
* |- folder
* |-- pangram.txt
* |-- cars.pdf
* |-- cars.txt
* |-- alfresco.txt
* |-- <uniqueFileName>
*/
nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes();
FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER);
dataContent.usingUser(userModel).usingSite(siteModel).createFolder(folder);
//Create files
file = new FileModel("pangram.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog");
file2 = new FileModel("cars.txt", FileType.TEXT_PLAIN, "The landrover discovery is not a sports car");
ContentModel cm = new ContentModel();
cm.setCmisLocation(folder.getCmisLocation());
cm.setName(folder.getName());
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file2);
String title = "Title: " + unique_searchString;
String description = "Description: File is created for search tests by Author: " + unique_searchString + " . ";
file = new FileModel("pangram.txt", "pangram" + title, description, FileType.TEXT_PLAIN, description + " The quick brown fox jumps over the lazy dog");
file2 = new FileModel("cars.txt", "cars" + title, description, FileType.TEXT_PLAIN, "The landrover discovery is not a sports car ");
file3 = new FileModel("alfresco.txt", "alfresco", "alfresco", FileType.TEXT_PLAIN, "Alfresco text file for search ");
file4 = new FileModel(unique_searchString + ".txt", "uniquee" + title, description, FileType.TEXT_PLAIN, "Unique text file for search ");
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file2);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file3);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file4);
waitForIndexing(file4.getName(), true);
}
/**
* Helper method which create an http post request to Search API end point.
* @param term String search term
@@ -84,7 +113,7 @@ public class AbstractSearchTest extends RestTest
queryReq.setLanguage("afts");
queryReq.setQuery(term);
SearchRequest query = new SearchRequest(queryReq);
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query);
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
/**
* Helper method which create an http post request to Search API end point.
@@ -97,7 +126,7 @@ public class AbstractSearchTest extends RestTest
{
SearchRequest query = new SearchRequest(queryReq);
query.setHighlight(highlight);
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query);
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
/**
* Helper method which create an http post request to Search API end point.
@@ -108,8 +137,9 @@ public class AbstractSearchTest extends RestTest
*/
protected SearchResponse query(SearchRequest query) throws Exception
{
return restClient.authenticateUser(dataUser.getAdminUser()).withSearchAPI().search(query);
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
protected SearchRequest createQuery(String term)
{
SearchRequest query = new SearchRequest();
@@ -122,4 +152,62 @@ public class AbstractSearchTest extends RestTest
{
return createQuery("cars");
}
}
protected RestResponse searchSql(SearchSqlRequest searchSqlRequest) throws Exception
{
return restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(searchSqlRequest);
}
/**
* Wait for Solr to finish indexing: Indexing has caught up = true if search returns appropriate results
*
* @param userQuery: string to search for, unique search string will guarantee accurate results
* @param expectedInResults, true if entry is expected in the results set
* @return true (indexing is finished) if search returns appropriate results
* @throws Exception
*/
public boolean waitForIndexing(String userQuery, Boolean expectedInResults) throws Exception
{
Boolean found = false;
Boolean resultAsExpected = false;
String expectedStatusCode = HttpStatus.OK.toString();
SearchRequest searchRequest = createQuery(userQuery);
SearchResponse response = query(searchRequest);
// Repeat search until the query results are as expected or Search Retry count is hit
for (int searchCount = 1; searchCount <= 3; searchCount++)
{
if (searchCount > 1)
{
// Wait for the solr indexing.
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing");
}
if (restClient.getStatusCode().matches(expectedStatusCode))
{
if (response.getEntries().size() >= 1)
{
found = true;
}
else
{
found = false;
}
// Loop again if result is not as expected: To cater for solr lag: eventual consistency
resultAsExpected = (expectedInResults.equals(found));
if (resultAsExpected)
{
break;
}
}
else
{
throw new AuthenticationException("API returned status code:" + restClient.getStatusCode() + " Expected: " + expectedStatusCode);
}
}
return resultAsExpected;
}
}
@@ -48,23 +48,23 @@ public class FacetIntervalSearchTest extends AbstractSearchTest
facetIntervalsModel.setIntervals(Arrays.asList(facetInterval));
query.setFacetIntervals(facetIntervalsModel);
SearchResponse response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "facetIntervals intervals field"));
facetInterval.setField("created");
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_COLLECTION, "facetIntervals intervals sets"));
RestRequestFacetSetModel restFacetSetModel = new RestRequestFacetSetModel();
restFacetSetModel.setLabel("theRest");
facetInterval.setSets(Arrays.asList(restFacetSetModel));
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "facetIntervals intervals created sets start"));
restFacetSetModel.setStart("A");
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "facetIntervals intervals created sets end"));
@@ -74,7 +74,8 @@ public class FacetIntervalSearchTest extends AbstractSearchTest
duplicate.setLabel("theRest");
duplicate.setStart("A");
duplicate.setEnd("C");
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary("duplicate set interval label [theRest=2]");
@@ -83,7 +84,8 @@ public class FacetIntervalSearchTest extends AbstractSearchTest
FacetInterval duplicateLabel = new FacetInterval("creator", "thesame", Arrays.asList(duplicate));
facetIntervalsModel.setIntervals(Arrays.asList(facetInterval, duplicateLabel));
query.setFacetIntervals(facetIntervalsModel);
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary("duplicate interval label [thesame=2]");
@@ -61,11 +61,7 @@ import org.testng.annotations.Test;
*/
public class FacetRangeSearchTest extends AbstractSearchTest
{
@Override
public void dataPreparation() throws Exception
{
//Skip setup
}
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
@TestRail(section = {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 }, executionType = ExecutionType.REGRESSION,
description = "Check facet intervals mandatory fields")
@@ -76,7 +72,7 @@ public class FacetRangeSearchTest extends AbstractSearchTest
RestRequestRangesModel facetRangeModel = new RestRequestRangesModel();
ranges.add(facetRangeModel);
query.setRanges(ranges);
SearchResponse response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "field"));
@@ -84,21 +80,27 @@ public class FacetRangeSearchTest extends AbstractSearchTest
facetRangeModel.setField("content.size");
ranges.add(facetRangeModel);
query.setRanges(ranges);
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "start"));
facetRangeModel.setStart("0");
ranges.clear();
ranges.add(facetRangeModel);
query.setRanges(ranges);
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "end"));
facetRangeModel.setEnd("400");
query.setRanges(ranges);
ranges.clear();
ranges.add(facetRangeModel);
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "gap"));
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -36,9 +36,6 @@ import org.testng.annotations.Test;
public class FacetedSearchTest extends AbstractSearchTest
{
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
@TestRail(section = {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 }, executionType = ExecutionType.REGRESSION,
description = "Checks facet queries for the Search api")
/**
* Perform the below facet query.
* {
@@ -89,13 +86,16 @@ public class FacetedSearchTest extends AbstractSearchTest
* }}
* @throws Exception
*/
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
@TestRail(section = { TestGroup.REST_API, TestGroup.SEARCH,
TestGroup.ASS_1 }, executionType = ExecutionType.REGRESSION, description = "Checks facet queries for the Search api")
public void searchWithQueryFaceting() throws Exception
{
{
SearchRequest query = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cars");
query.setQuery(queryReq);
List<FacetQuery> facets = new ArrayList<FacetQuery>();
facets.add(new FacetQuery("content.size:[0 TO 102400]", "small"));
@@ -109,9 +109,11 @@ public class FacetedSearchTest extends AbstractSearchTest
query.setFacetFields(facetFields);
query.setIncludeRequest(true);
SearchResponse response = query(query);
SearchResponse response = query(query);
response.assertThat().entriesListIsNotEmpty();
response.getContext().assertThat().field("facetQueries").isNotEmpty();
FacetFieldBucket facet = response.getContext().getFacetQueries().get(0);
facet.assertThat().field("label").contains("small").and().field("count").isGreaterThan(0);
facet.assertThat().field("label").contains("small").and().field("filterQuery").is("content.size:[0 TO 102400]");
@@ -173,52 +175,53 @@ public class FacetedSearchTest extends AbstractSearchTest
public void searchQueryFacetingWithGroup() throws Exception
{
SearchRequest query = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cars");
query.setQuery(queryReq);
List<FacetQuery> facets = new ArrayList<FacetQuery>();
facets.add(new FacetQuery("content.size:[0 TO 102400]", "small", "foo"));
facets.add(new FacetQuery("content.size:[102400 TO 1048576]", "medium","foo"));
facets.add(new FacetQuery("content.size:[1048576 TO 16777216]", "large","foo"));
facets.add(new FacetQuery("content.size:[102400 TO 1048576]", "medium", "foo"));
facets.add(new FacetQuery("content.size:[1048576 TO 16777216]", "large", "foo"));
query.setFacetQueries(facets);
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
List<RestRequestFacetFieldModel> list = new ArrayList<>();
list.add(new RestRequestFacetFieldModel("'content.size'"));
facetFields.setFacets(list);
query.setFacetFields(facetFields);
SearchResponse response = query(query);
//We don't expect to see the FacetQueries if group is being used.
SearchResponse response = query(query);
// We don't expect to see the FacetQueries if group is being used.
Assert.assertTrue(response.getContext().getFacetQueries() == null);
//Validate the facet field structure is correct.
// Validate the facet field structure is correct.
Assert.assertFalse(response.getContext().getFacets().isEmpty());
Assert.assertEquals(response.getContext().getFacets().get(0).getLabel(), "foo");
RestGenericBucketModel bucket = response.getContext().getFacets().get(0).getBuckets().get(0);
bucket.assertThat().field("label").isNotEmpty();
Assert.assertEquals( bucket.getMetrics().get(0).getType(), "count");
Assert.assertNotEquals( bucket.getMetrics().get(0).getValue(), "");
Assert.assertEquals(bucket.getMetrics().get(0).getType(), "count");
Assert.assertNotEquals(bucket.getMetrics().get(0).getValue(), "");
bucket.assertThat().field("filterQuery").isNotEmpty();
response.getContext().getFacets().get(0).getBuckets().forEach(action -> {
switch (action.getLabel())
{
case "small":
Assert.assertEquals(action.getFilterQuery(), "content.size:[0 TO 102400]");
break;
case "medium":
Assert.assertEquals(action.getFilterQuery(), "content.size:[102400 TO 1048576]");
break;
case "large":
Assert.assertEquals(action.getFilterQuery(), "content.size:[1048576 TO 16777216]");
break;
case "small":
Assert.assertEquals(action.getFilterQuery(), "content.size:[0 TO 102400]");
break;
case "medium":
Assert.assertEquals(action.getFilterQuery(), "content.size:[102400 TO 1048576]");
break;
case "large":
Assert.assertEquals(action.getFilterQuery(), "content.size:[1048576 TO 16777216]");
break;
default:
throw new TestException("Unexpected value returned");
default:
throw new TestException("Unexpected value returned");
}
});
}
@Test
@@ -235,29 +238,34 @@ public class FacetedSearchTest extends AbstractSearchTest
public void searchWithFactedFields() throws Exception
{
SearchRequest query = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("*");
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery(unique_searchString);
query.setQuery(queryReq);
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
List<RestRequestFacetFieldModel>facets = new ArrayList<RestRequestFacetFieldModel>();
List<RestRequestFacetFieldModel> facets = new ArrayList<RestRequestFacetFieldModel>();
facets.add(new RestRequestFacetFieldModel("cm:mimetype"));
facets.add(new RestRequestFacetFieldModel("modifier"));
facetFields.setFacets(facets);
query.setFacetFields(facetFields);
SearchResponse response = query(query);
SearchResponse response = query(query);
Assert.assertFalse(response.getContext().getFacetsFields().isEmpty());
Assert.assertNull(response.getContext().getFacetQueries());
Assert.assertNull(response.getContext().getFacets());
RestResultBucketsModel model = response.getContext().getFacetsFields().get(0);
Assert.assertEquals(model.getLabel(), "modifier");
model.assertThat().field("label").is("modifier");
FacetFieldBucket bucket1 = model.getBuckets().get(0);
bucket1.assertThat().field("label").is("System");
bucket1.assertThat().field("display").is("System");
bucket1.assertThat().field("filterQuery").is("modifier:\"System\"");
bucket1.assertThat().field("count").is(684);
bucket1.assertThat().field("label").is(userModel.getUsername());
bucket1.assertThat().field("display").is(userModel.getUsername() + " FirstName LN-" + userModel.getUsername());
bucket1.assertThat().field("filterQuery").is("modifier:\"" + userModel.getUsername() + "\"");
bucket1.assertThat().field("count").is(1);
}
@Test
/**
* Test that items returned are in the format of generic facets.
@@ -274,29 +282,31 @@ public class FacetedSearchTest extends AbstractSearchTest
public void searchWithFactedFieldsFacetFormatV2() throws Exception
{
SearchRequest query = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("*");
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery(unique_searchString);
query.setQuery(queryReq);
query.setFacetFormat("V2");
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
List<RestRequestFacetFieldModel>facets = new ArrayList<RestRequestFacetFieldModel>();
List<RestRequestFacetFieldModel> facets = new ArrayList<RestRequestFacetFieldModel>();
facets.add(new RestRequestFacetFieldModel("cm:mimetype"));
facets.add(new RestRequestFacetFieldModel("modifier"));
facetFields.setFacets(facets);
query.setFacetFields(facetFields);
SearchResponse response = query(query);
SearchResponse response = query(query);
Assert.assertNull(response.getContext().getFacetsFields());
Assert.assertNull(response.getContext().getFacetQueries());
Assert.assertFalse(response.getContext().getFacets().isEmpty());
RestGenericFacetResponseModel model = response.getContext().getFacets().get(0);
Assert.assertEquals(model.getLabel(), "modifier");
model.assertThat().field("label").is("modifier");
RestGenericBucketModel bucket1 = model.getBuckets().get(0);
bucket1.assertThat().field("label").is("System");
bucket1.assertThat().field("display").isNull();
bucket1.assertThat().field("filterQuery").is("modifier:\"System\"");
bucket1.assertThat().field("metrics").is("[{entry=null, type=count, value={count=684}}]");
bucket1.assertThat().field("label").is(userModel.getUsername());
bucket1.assertThat().field("display").is(userModel.getUsername() + " FirstName LN-" + userModel.getUsername());
bucket1.assertThat().field("filterQuery").is("modifier:\"" + userModel.getUsername() + "\"");
bucket1.assertThat().field("metrics").is("[{entry=null, type=count, value={count=1}}]");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,7 +18,6 @@
*/
package org.alfresco.rest.search;
import org.alfresco.utility.model.ContentModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.FolderModel;
@@ -34,34 +33,37 @@ import org.testng.annotations.Test;
*/
public class FingerPrintTest extends AbstractSearchTest
{
private FileModel file1,file2,file3,file4;
@BeforeClass
private FileModel file1, file2, file3, file4;
@BeforeClass(alwaysRun = true)
public void indexSimilarFile() throws Exception
{
adminUserModel = dataUser.getAdminUser();
userModel = dataUser.createRandomTestUser();
siteModel = dataSite.usingUser(userModel).createPublicRandomSite();
/*
* Create the following file structure for preconditions :
* |- folder
* |-- fox.txt
* Create the following file structure in the same Site : In addition to the preconditions created in dataPreparation
* |- folder
* |-- pangram-banana.txt
* |-- pangram-taco.txt
* |-- pangram-cat.txt
* |-- dog.txt
*/
nodesBuilder = restClient.authenticateUser(userModel).withCoreAPI().usingNode(ContentModel.my()).defineNodes();
FolderModel folder = new FolderModel(SEARCH_DATA_SAMPLE_FOLDER);
FolderModel folder = new FolderModel("The quick brown fox jumps over");
dataContent.usingUser(userModel).usingSite(siteModel).createFolder(folder);
file1 = new FileModel("pangram-banana.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy banana");
file2 = new FileModel("pangram-taco.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy dog that ate the taco");
file3 = new FileModel("pangram-cat.txt", FileType.TEXT_PLAIN, "The quick brown fox jumps over the lazy cat");
file4 = new FileModel("dog.txt", FileType.TEXT_PLAIN, "The quick brown fox ate the lazy dog");
ContentModel cm = new ContentModel();
cm.setCmisLocation(folder.getCmisLocation());
cm.setName(folder.getName());
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file1);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file2);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file3);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(cm).createContent(file4);
Thread.sleep(35000);//Allow indexing to complete.
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file1);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file2);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file3);
dataContent.usingUser(userModel).usingSite(siteModel).usingResource(folder).createContent(file4);
waitForIndexing(file4.getName(), true);
}
/**
* Search similar document based on document finger print.
* The data prep should have loaded 2 files which one is similar
@@ -70,7 +72,7 @@ public class FingerPrintTest extends AbstractSearchTest
*
* @throws Exception
*/
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
public void search() throws Exception
{
String uuid = file1.getNodeRefWithoutVersion();
@@ -79,46 +81,50 @@ public class FingerPrintTest extends AbstractSearchTest
SearchResponse response = query(fingerprint);
int count = response.getEntries().size();
Assert.assertTrue(count > 1);
for(SearchNodeModel m :response.getEntries())
for (SearchNodeModel m : response.getEntries())
{
String match = m.getModel().getName();
switch (match)
{
case "pangram.txt":
break;
case "pangram-banana.txt":
break;
case "pangram-taco.txt":
break;
case "pangram-cat.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
case "pangram.txt":
break;
case "pangram-banana.txt":
break;
case "pangram-taco.txt":
break;
case "pangram-cat.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
}
m.getModel().assertThat().field("name").isNot("dog.txt");
m.getModel().assertThat().field("name").isNot("cars.txt");
}
}
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
public void searchSimilar() throws Exception
{
String uuid = file2.getNodeRefWithoutVersion();
Assert.assertNotNull(uuid);
// In the response eneity there is a score of each doc, change below threshold to bring more like or less.
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
// In the response entity there is a score of each doc, change below threshold to bring more like or less.
String fingerprint = String.format("FINGERPRINT:%s_68", uuid);
SearchResponse response = query(fingerprint);
int count = response.getEntries().size();
Assert.assertTrue(count > 1);
for(SearchNodeModel m :response.getEntries())
for (SearchNodeModel m : response.getEntries())
{
switch (m.getModel().getName())
{
case "pangram.txt":
break;
case "pangram-taco.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
case "pangram.txt":
break;
case "pangram-taco.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
}
m.getModel().assertThat().field("name").isNot("pangram-banana.txt");
m.getModel().assertThat().field("name").isNot("pangram-cat.txt");
@@ -126,7 +132,8 @@ public class FingerPrintTest extends AbstractSearchTest
m.getModel().assertThat().field("name").isNot("cars.txt");
}
}
@Test(groups= {TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1})
@Test(groups = { TestGroup.REST_API, TestGroup.SEARCH, TestGroup.ASS_1 })
public void searchSimilar67Percent() throws Exception
{
String uuid = file2.getNodeRefWithoutVersion();
@@ -135,18 +142,18 @@ public class FingerPrintTest extends AbstractSearchTest
SearchResponse response = query(fingerprint);
int count = response.getEntries().size();
Assert.assertTrue(count > 1);
for(SearchNodeModel m :response.getEntries())
for (SearchNodeModel m : response.getEntries())
{
switch (m.getModel().getName())
{
case "pangram.txt":
break;
case "pangram-taco.txt":
break;
case "pangram-cat.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
case "pangram.txt":
break;
case "pangram-taco.txt":
break;
case "pangram-cat.txt":
break;
default:
throw new AssertionError("Not a match to an expected file: " + m.getModel().getName());
}
m.getModel().assertThat().field("name").isNot("pangram-banana.txt");
m.getModel().assertThat().field("name").isNot("dog.txt");
@@ -60,12 +60,15 @@ public class PivotFacetedSearchTest extends AbstractSearchTest
pivotModelList.add(pivots);
query.setPivots(pivotModelList);
SearchResponse response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST).assertLastError()
.containsSummary(String.format(RestErrorModel.MANDATORY_PARAM, "pivot key"));
pivots.setKey("none_like_this");
response = query(query);
query(query);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST)
.assertLastError().containsSummary("invalid argument was received")
.containsSummary("Pivot parameter none_like_this does not reference");
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -116,12 +116,15 @@ public class SearchAPATHTest extends AbstractSearchTest
Assert.assertEquals(4,fresponse.getBuckets().size());
fresponse.getBuckets().get(0).assertThat().field("label").contains("1/");
}
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1})
public void searchLevel2() throws Exception
{
String queryString = "name:"+ "cars";
SearchRequest searchQuery = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("name:*");
queryReq.setQuery(queryString);
searchQuery.setQuery(queryReq);
RestRequestFacetFieldsModel facetFields = new RestRequestFacetFieldsModel();
@@ -131,6 +134,7 @@ public class SearchAPATHTest extends AbstractSearchTest
searchQuery.setFacetFields(facetFields);
SearchResponse response = query(searchQuery);
RestResultBucketsModel fresponse = response.getContext().getFacetsFields().get(0);
String path = fresponse.getBuckets().get(0).getLabel().replace("1/", "2/");
list.remove(0);
@@ -140,7 +144,7 @@ public class SearchAPATHTest extends AbstractSearchTest
searchQuery.setFacetFields(facetFields);
response = query(searchQuery);
fresponse = response.getContext().getFacetsFields().get(0);
Assert.assertEquals(fresponse.getBuckets().size(),3);
Assert.assertTrue(fresponse.getBuckets().size() >= 1);
fresponse.getBuckets().get(0).assertThat().field("label").contains("2/");
fresponse.getBuckets().get(0).assertThat().field("label").contains(path);
/**
@@ -151,7 +155,7 @@ public class SearchAPATHTest extends AbstractSearchTest
*/
searchQuery = new SearchRequest();
queryReq = new RestRequestQueryModel();
queryReq.setQuery("name:*");
queryReq.setQuery(queryString);
searchQuery.setQuery(queryReq);
facetFields = new RestRequestFacetFieldsModel();
list.remove(0);
@@ -160,8 +164,7 @@ public class SearchAPATHTest extends AbstractSearchTest
searchQuery.setFacetFields(facetFields);
response = query(searchQuery);
fresponse = response.getContext().getFacetsFields().get(0);
System.out.println(response);
Assert.assertTrue(fresponse.getBuckets().size() > 5);
Assert.assertTrue(fresponse.getBuckets().size() >= 1);
fresponse.getBuckets().get(0).assertThat().field("label").contains("3/");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -19,6 +19,8 @@
package org.alfresco.rest.search;
import org.alfresco.rest.model.RestRequestSpellcheckModel;
import org.alfresco.utility.model.FileModel;
import org.alfresco.utility.model.FileType;
import org.alfresco.utility.model.TestGroup;
import org.junit.Assert;
import org.testng.annotations.Test;
@@ -26,10 +28,11 @@ import org.testng.annotations.Test;
/**
* Search end point Public API test with spell checking enabled.
* @author Michael Suzuki
*5
* @author Meenal Bhave
*/
public class SearchSpellCheckTest extends AbstractSearchTest
{
/**
* Perform the below query
* {
@@ -61,24 +64,48 @@ public class SearchSpellCheckTest extends AbstractSearchTest
*
* @throws Exception
*/
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
public void searchMissSpelled() throws Exception
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n}, priority=1)
public void testSearchMissSpelled() throws Exception
{
// Name
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:name:alfrezco");
queryReq.setUserQuery("alfrezco");
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
assertResponse(query(searchReq));
// Title
queryReq.setQuery("cm:title:alfrezco");
queryReq.setUserQuery("alfrezco");
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
assertResponse(query(searchReq));
// Description
queryReq.setQuery("cm:description:alfrezco");
queryReq.setUserQuery("alfrezco");
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
assertResponse(query(searchReq));
// Content
queryReq.setQuery("cm:content:alfrezco");
queryReq.setUserQuery("alfrezco");
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
assertResponse(query(searchReq));
}
private void assertResponse(SearchResponse nodes) throws Exception
{
nodes.assertThat().entriesListIsNotEmpty();
nodes.getContext().assertThat().field("spellCheck").isNotEmpty();
nodes.getContext().getSpellCheck().assertThat().field("suggestions").contains("alfresco");
nodes.getContext().getSpellCheck().assertThat().field("type").is("searchInsteadFor");
}
@Test
/**
* Perform alternative way by setting the value in spellcheck object.
*
@@ -91,7 +118,8 @@ public class SearchSpellCheckTest extends AbstractSearchTest
* }
* @throws Exception
*/
public void searchMissSpelledVersion2() throws Exception
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n}, priority=2)
public void testSearchMissSpelledVersion2() throws Exception
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
@@ -103,8 +131,9 @@ public class SearchSpellCheckTest extends AbstractSearchTest
searchReq.setSpellcheck(spellCheck);
assertResponse(query(searchReq));
}
@Test
public void searchWithSpellcheckerAndCorrectSpelling() throws Exception
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n}, priority=3)
public void testSearchWithSpellcheckerAndCorrectSpelling() throws Exception
{
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
@@ -113,7 +142,31 @@ public class SearchSpellCheckTest extends AbstractSearchTest
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
SearchResponse res = query(searchReq);
Assert.assertNull(res.getContext());
Assert.assertNull(res.getContext().getSpellCheck());
res.assertThat().entriesListIsNotEmpty();
}
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n}, priority=4)
public void testSpellCheckType() throws Exception
{
// Create a file with mis-spelt name, expect spellcheck type = didYouMean
FileModel file = new FileModel(unique_searchString + "-1.txt", "uniquee" + "uniquee", "uniquee", FileType.TEXT_PLAIN, "Unique text file for search ");
dataContent.usingUser(userModel).usingSite(siteModel).createContent(file);
waitForIndexing(file.getName(), true);
// Search
SearchRequest searchReq = new SearchRequest();
RestRequestQueryModel queryReq = new RestRequestQueryModel();
queryReq.setQuery("cm:title:uniquee");
queryReq.setUserQuery("uniquee");
searchReq.setQuery(queryReq);
searchReq.setSpellcheck(new RestRequestSpellcheckModel());
SearchResponse nodes = query(searchReq);
nodes.assertThat().entriesListIsNotEmpty();
nodes.getContext().assertThat().field("spellCheck").isNotEmpty();
nodes.getContext().getSpellCheck().assertThat().field("suggestions").contains("unique");
nodes.getContext().getSpellCheck().assertThat().field("type").is("didYouMean");
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2017 Alfresco Software Limited.
* Copyright (C) 2018 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -36,14 +36,14 @@ public class SearchTest extends AbstractSearchTest
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
public void searchOnIndexedData() throws Exception
{
SearchResponse nodes = query("ipsum");
SearchResponse nodes = query(unique_searchString);
restClient.assertStatusCodeIs(HttpStatus.OK);
nodes.assertThat().entriesListIsNotEmpty();
SearchNodeModel entity = nodes.getEntryByIndex(0);
entity.assertThat().field("search").contains("score");
entity.getSearch().assertThat().field("score").isNotEmpty();
Assert.assertEquals("Project Overview.ppt",entity.getName());
Assert.assertEquals("pangram.txt",entity.getName());
}
@Test(groups={TestGroup.SEARCH,TestGroup.REST_API})
@@ -41,7 +41,7 @@ import org.testng.annotations.Test;
public class ShardInfoTest extends AbstractSearchTest
{
@Bug(id="DELENG-1", status=Bug.Status.OPENED)
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n})
public void getShardInfoWithAdminAuthority() throws JsonProcessingException, EmptyRestModelCollectionException
{
RestShardInfoModelCollection info = restClient.authenticateUser(dataUser.getAdminUser()).withShardInfoAPI().getInfo();
@@ -70,7 +70,8 @@ public class ShardInfoTest extends AbstractSearchTest
RestInstanceModel instance = instances.iterator().next();
assertNotNull(instance);
baseUrls.contains(instance.getBaseUrl());
assertEquals(instance.getHost(), "localhost");
// TODO: Ideally Solr Host and Port should be Parameterised
assertEquals(instance.getHost(), "search");
assertEquals(instance.getPort().intValue(), 8983);
assertEquals(instance.getState(), "ACTIVE");
assertEquals(instance.getMode(), "MASTER");
@@ -78,7 +79,7 @@ public class ShardInfoTest extends AbstractSearchTest
}
@Bug(id="DELENG-1", status=Bug.Status.OPENED)
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API})
@Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ACS_60n})
public void getShardInfoWithoutAdminAuthority() throws Exception
{
restClient.authenticateUser(dataUser.createRandomTestUser()).withShardInfoAPI().getInfo();
@@ -0,0 +1,602 @@
/*
* Copyright (C) 2018 Alfresco Software Limited.
* This file is part of Alfresco
* 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/>.
*/
package org.alfresco.rest.search.sql;
import org.alfresco.rest.core.RestResponse;
import org.alfresco.rest.search.AbstractSearchTest;
import org.alfresco.rest.search.SearchSqlRequest;
import org.alfresco.utility.constants.UserRole;
import org.alfresco.utility.model.TestGroup;
import org.alfresco.utility.model.UserModel;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
import org.hamcrest.Matchers;
/**
* Tests for /sql end point Search API.
*
* @author Meenal Bhave
*/
public class SearchSQLAPITest extends AbstractSearchTest
{
String sql = "select SITE, CM_OWNER from alfresco group by SITE,CM_OWNER";
String[] locales = { "en-US" };
String solrFormat = "solr";
/**
* API post:
* {
* "stmt": "select SITE from alfresco",
* "locales" : ["en_US"],
* "format" : "solr",
* "timezone":"",
* "includeMetadata":false
* }
* Example Response: In Solr Format
* {
* "result-set":
* {
* "docs":
* [
* {
* "SITE":
* [
* "swsdp"
* ]
* },
* {
* "SITE":
* [
* "swsdp"
* ]
* }
* ]
* }
*/
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 01)
public void testWithSolr() throws Exception
{
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setFormat(solrFormat);
sqlRequest.setLocales(locales);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", Matchers.notNullValue());
}
/**
* API post example:
* {
* "stmt": "select SITE from alfresco",
* "locales" : ["en_US"],
* "format" : "json",
* "timezone":"",
* "includeMetadata":false
* }
* Example Response: In json Format
* {
* "list":
* {
* "pagination":
* {
"count": 103,
"hasMoreItems": false,
"totalItems": 103,
"skipCount": 0,
"maxItems": 1000
},
* "entries":
* [
* "entry": [
{
"label": "SITE",
"value": "[\"swsdp\"]"
}
],
"entry": [
{
"label": "SITE",
"value": "[\"swsdp\"]"
}
]
* ]
* }
*/
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 02)
public void testWithJson() throws Exception
{
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(locales);
// Format not set
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(locales);
sqlRequest.setFormat("json"); // Format json
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(locales);
sqlRequest.setFormat("abcd"); // Format any other than solr
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
}
/**
* API post:
* {
* "stmt": "select SITE from alfresco",
* "locales" : ["en_US"],
* "format" : "solr",
* "timezone":"",
* "includeMetadata":true
* }
* Example Response: In Solr Format: Includes metadata: aliases, fields, isMetadata=true
* {
* "result-set": {
* "docs": [
* {
* "aliases": {
* "SITE": "SITE"
* },
* "isMetadata": true,
* "fields": [
* "SITE"
* ]
* },
* {
* "SITE": [
* "swsdp"
* ]
* },
* {
* "SITE": [
* "swsdp"
* ]
* },
* {
* "RESPONSE_TIME": 79,
* "EOF": true
* }
* ]
* }
* }
*/
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 03)
public void testWithSolrIncludeMetadata() throws Exception
{
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setFormat(solrFormat);
sqlRequest.setLocales(locales);
sqlRequest.setIncludeMetadata(true);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].aliases.SITE", Matchers.equalToIgnoringCase("SITE"));
restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", Matchers.is(true));
restClient.onResponse().assertThat().body("result-set.docs[0].fields[0]", Matchers.equalToIgnoringCase("SITE"));
}
/**
* API post example:
* {
* "stmt": "select SITE from alfresco limit 2",
* "locales" : ["en_US"],
* "format" : "json",
* "timezone":"",
* "includeMetadata":false
* }
* Example Response: In json Format
* {
* "list":
* {
* "pagination":
* {
"count": 3,
"hasMoreItems": false,
"totalItems": 3,
"skipCount": 0,
"maxItems": 1000
},
* "entries":
* [
* "entry": [
{
"label": "aliases",
"value": "{\"SITE\":\"SITE\"}"
},
{
"label": "isMetadata",
"value": "true"
},
{
"label": "fields",
"value": "[\"SITE\"]"
}
]
},
* "entry": [
{
"label": "SITE",
"value": "[\"swsdp\"]"
}
],
"entry": [
{
"label": "SITE",
"value": "[\"swsdp\"]"
}
]
* ]
* }
*/
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 04)
public void testWithJsonIncludeMetadata() throws Exception
{
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setFormat("");
sqlRequest.setLocales(locales);
sqlRequest.setIncludeMetadata(true);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("aliases"));
restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase("{\"SITE\":\"SITE\",\"cm_owner\":\"CM_OWNER\"}"));
restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", Matchers.equalToIgnoringCase("isMetadata"));
restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.is("true"));
restClient.onResponse().assertThat().body("list.entries.entry[0][2].label", Matchers.equalToIgnoringCase("fields"));
restClient.onResponse().assertThat().body("list.entries.entry[0][2].value", Matchers.equalToIgnoringCase("[\"SITE\",\"cm_owner\"]"));
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 05)
public void testIncludeMetadataFalse() throws Exception
{
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setFormat("solr"); // Format solr
sqlRequest.setIncludeMetadata(false);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].aliases", Matchers.nullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", Matchers.nullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].fields", Matchers.nullValue());
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setIncludeMetadata(false);
sqlRequest.setFormat("json"); // Format json
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.notNullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.not("aliases"));
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setIncludeMetadata(false); // Format not set
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", Matchers.notNullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.notNullValue());
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.not("aliases"));
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setFormat(solrFormat); // IncludeMetadata = false when not specified
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("result-set", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].aliases", Matchers.nullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", Matchers.nullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].fields", Matchers.nullValue());
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 06)
public void testLocales() throws Exception
{
String[] noLocales = {}; // Not specified
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(noLocales);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
String[] singleLocale = { "en-Uk" };
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(singleLocale);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
String[] multipleLocales = { "en-US", "ja" };
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(multipleLocales);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 07)
public void testTimezone() throws Exception
{
String timezone = ""; // Not specified
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setTimezone(timezone);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
timezone = "UTC"; // UTC
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setTimezone(timezone);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
timezone = "false"; // Invalid timezone is ignored
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setTimezone(timezone);
searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 8)
public void testAggregateSQL() throws Exception
{
String agSql = "select count(*) FROM alfresco where TYPE='cm:content'";
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(agSql);
RestResponse response = searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
response.assertThat().body("list.entries", Matchers.notNullValue());
response.assertThat().body("list.entries.entry[0][0].value", Matchers.not("0"));
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 9)
public void testLimit() throws Exception
{
Integer defaultLimit = 1000;
Integer limit = null; // Limit defaults to the default setting when null
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLimit(limit);
RestResponse response = searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(defaultLimit));
limit = 0; // Limit defaults to the default setting when 0
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLimit(limit);
response = searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(defaultLimit));
limit = 100; // Limit is applied correctly, with maxItems = limit
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLimit(limit);
response = searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(limit));
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 10)
public void testAuthenticationError() throws Exception
{
UserModel dummyUser = dataUser.createRandomTestUser("UserSearchDummy");
dummyUser.setPassword("incorrect-password");
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(locales);
restClient.authenticateUser(dummyUser).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.UNAUTHORIZED);
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 11)
public void testPermissions() throws Exception
{
UserModel userNoPerm = dataUser.createRandomTestUser("UserSearchNoPerm");
UserModel userPerm = dataUser.createRandomTestUser("UserSearchPerm");
dataUser.addUserToSite(userPerm, siteModel, UserRole.SiteContributor);
String siteSQL = "select SITE, CM_OWNER from alfresco where SITE='" + siteModel.getId() + "'";
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(siteSQL);
// 0 results expected for query as User does not have access to the private site
restClient.authenticateUser(userNoPerm).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.pagination.count", Matchers.is(0));
restClient.onResponse().assertThat().body("list.pagination.totalItems", Matchers.is(0));
restClient.onResponse().assertThat().body("list.pagination.hasMoreItems", Matchers.is(false));
restClient.onResponse().assertThat().body("list.entries", Matchers.empty());
// Results expected for query as User does has access to the private site
restClient.authenticateUser(userPerm).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.OK);
restClient.onResponse().assertThat().body("list.pagination.count", Matchers.greaterThan(0));
restClient.onResponse().assertThat().body("list.pagination.totalItems", Matchers.greaterThan(0));
restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("SITE"));
restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase("[\"" + siteModel.getId() + "\"]"));
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 12)
public void testErrors() throws Exception
{
String incorrectSQL = ""; // Missing SQL
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Required stmt parameter is missing"));
incorrectSQL = "select SITE from unknownTable"; // Wrong table name
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
// restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Table 'unknownTable' not found"));
incorrectSQL = "select Column1 from alfresco"; // Wrong ColumnName
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Column 'Column1' not found"));
incorrectSQL = "select SITE alfresco"; // BAD SQL Grammar: from missing
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Unable to execute the query"));
incorrectSQL = "select SITE, CM_OWNER from alfresco group by SITE"; // BAD SQL Grammar: CM_OWNER is not being grouped
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Expression 'CM_OWNER' is not being grouped"));
incorrectSQL = "delete SITE from alfresco"; // BAD SQL Grammar
sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(incorrectSQL);
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(HttpStatus.BAD_REQUEST);
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.notNullValue());
restClient.onResponse().assertThat().body("error.briefSummary", Matchers.containsString("Was expecting one of"));
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API }, priority = 13)
public void testErrorForSQLAPIWithASS() throws Exception
{
String acsVersion = serverHealth.getAlfrescoVersion();
HttpStatus expectedStatus = HttpStatus.OK;
SearchSqlRequest sqlRequest = new SearchSqlRequest();
sqlRequest.setSql(sql);
sqlRequest.setLocales(locales);
// Set expected result based on ACS Version and ASS Version
if (!acsVersion.startsWith("6"))
{
expectedStatus = HttpStatus.NOT_FOUND;
}
else
{
expectedStatus = HttpStatus.BAD_REQUEST;
}
restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest);
restClient.assertStatusCodeIs(expectedStatus);
}
}
@@ -1,7 +1,5 @@
package org.alfresco.rest.sharedLinks;
import static org.testng.Assert.assertEquals;
import javax.json.Json;
import org.alfresco.dataprep.CMISUtil.DocumentType;