Search-741, SEARCH-844: Added new api \sql for Insight engine + sanity tests

This commit is contained in:
Meenal Bhave
2018-05-14 18:02:05 +01:00
parent bbd5f4fe1c
commit efea12cfb9
2 changed files with 136 additions and 14 deletions
@@ -18,8 +18,11 @@
*/
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;
import org.alfresco.utility.Utility;
import org.alfresco.utility.data.RandomData;
import org.alfresco.utility.model.FileModel;
@@ -27,6 +30,7 @@ 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;
/**
@@ -44,9 +48,9 @@ public class AbstractSearchTest extends RestTest
{
protected static final String SEARCH_DATA_SAMPLE_FOLDER = "FolderSearch";
UserModel userModel, adminUserModel;
SiteModel siteModel;
UserModel searchedUser;
protected UserModel userModel, adminUserModel;
protected SiteModel siteModel;
protected UserModel searchedUser;
protected FileModel file, file2, file3, file4;
protected static String unique_searchString;
@@ -135,6 +139,7 @@ public class AbstractSearchTest extends RestTest
{
return restClient.authenticateUser(userModel).withSearchAPI().search(query);
}
protected SearchRequest createQuery(String term)
{
SearchRequest query = new SearchRequest();
@@ -148,8 +153,14 @@ 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
@@ -159,6 +170,7 @@ public class AbstractSearchTest extends RestTest
{
Boolean found = false;
Boolean resultAsExpected = false;
String expectedStatusCode = HttpStatus.OK.toString();
SearchRequest searchRequest = createQuery(userQuery);
SearchResponse response = query(searchRequest);
@@ -172,23 +184,30 @@ public class AbstractSearchTest extends RestTest
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing");
}
if (response.getEntries().size() >= 1)
if (restClient.getStatusCode().matches(expectedStatusCode))
{
found = true;
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
{
found = false;
}
// Loop again if result is not as expected: To cater for solr lag: eventual consistency
resultAsExpected = (expectedInResults.equals(found));
if (resultAsExpected)
{
break;
throw new AuthenticationException("API returned status code:" + restClient.getStatusCode() + " Expected: " + expectedStatusCode);
}
}
return resultAsExpected;
}
}
}
@@ -0,0 +1,103 @@
/*
* 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.search.AbstractSearchTest;
import org.alfresco.rest.search.SearchSqlRequest;
import org.alfresco.utility.model.TestGroup;
import org.springframework.http.HttpStatus;
import org.testng.annotations.Test;
/**
* 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";
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 01)
public void queryTestWithSolr() 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", org.hamcrest.Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", org.hamcrest.Matchers.notNullValue());
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 02)
public void queryTestWithJson() 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", org.hamcrest.Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", org.hamcrest.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", org.hamcrest.Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", org.hamcrest.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", org.hamcrest.Matchers.nullValue());
restClient.onResponse().assertThat().body("list.entries", org.hamcrest.Matchers.notNullValue());
}
@Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 03)
public void queryTestWithSolrIncludeMetadata() 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", org.hamcrest.Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs", org.hamcrest.Matchers.notNullValue());
restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", org.hamcrest.Matchers.is(true));
}
}