diff --git a/e2e-test/README.md b/e2e-test/README.md index 00462e5d0..a8251c45d 100644 --- a/e2e-test/README.md +++ b/e2e-test/README.md @@ -35,4 +35,4 @@ Search Services 1.2.0 or above or Insight Engine 1.0.0 or above e.g. -`mvn clean install -Dtest=org.alfresco.service.search.e2e.insightEngine.sql.CustomModelTest` +`mvn clean install -Dtest=CustomModelTest` diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/jdbc/JDBCDriverTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/jdbc/JDBCDriverTest.java deleted file mode 100644 index 2919273af..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/jdbc/JDBCDriverTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.alfresco.service.search.e2e.insightEngine.jdbc; - -import java.sql.SQLException; -import java.util.List; - -import org.alfresco.utility.network.ServerHealth; -import org.alfresco.utility.network.db.DatabaseOperationImpl; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import static org.testng.Assert.*; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * This class is connecting via JDBC Driver (see default.properties) - * - * example: - * db.url= jdbc:alfresco://${alfresco.server}:${alfresco.port}?collection=alfresco - * - * I am using the TAS DatabaseOperationImpl service to connect - * - * @author Paul Brodner - * - */ -@ContextConfiguration("classpath:alfresco-search-e2e-context.xml") -public class JDBCDriverTest extends AbstractTestNGSpringContextTests { - - @Autowired - protected ServerHealth serverHealth; - - @Autowired - DatabaseOperationImpl jdbcOperation; - - @BeforeClass(alwaysRun = true) - public void checkServerHealth() throws Exception { - serverHealth.assertServerIsOnline(); - } - - /** - * In order to work start ACS + InsightEngine service - * @throws SQLException - */ - @Test - public void iCanConnectWithJDBCDriver() throws SQLException { - assertTrue(jdbcOperation.connect(), "I can connect via JDBC Driver"); - } - - @Test(dependsOnMethods="iCanConnectWithJDBCDriver") - public void iCanQueryTheTotalNumberOfDocumentsFromAlfresco() { - List results = jdbcOperation.executeQuery("select cm_name from alfresco where cm_Name = 'presentation*'"); - assertEquals(results.size(), 3); - } -} diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CaseSensitivityInFieldsNamesTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CaseSensitivityInFieldsNamesTest.java deleted file mode 100644 index fedeeb243..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CaseSensitivityInFieldsNamesTest.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 2019 Alfresco Software, Ltd. All rights reserved. - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - */ - -package org.alfresco.service.search.e2e.insightEngine.sql; - -import static java.util.Arrays.asList; -import static java.util.stream.IntStream.range; - -import org.alfresco.service.search.e2e.AbstractSearchServiceE2E; -import org.alfresco.utility.LogFactory; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.FolderModel; -import org.alfresco.utility.model.TestGroup; -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.hamcrest.Matchers; -import org.slf4j.Logger; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Purpose of this TestClass is to test that the fields name follows a given case-sensitive rule in different part of the query. - * Specifically: - * - * - * - * @author agazzarini - * {@link https://issues.alfresco.com/jira/browse/SEARCH-1491} - */ -public class CaseSensitivityInFieldsNamesTest extends AbstractSearchServiceE2E -{ - private static Logger LOG = LogFactory.getLogger(); - - /** - * Creates the test dataset that will be used in this test case. - */ - @BeforeClass(alwaysRun = true) - public void setupEnvironment() throws Exception - { - serverHealth.assertServerIsOnline(); - - super.springTestContextPrepareTestInstance(); - - try - { - deployCustomModel("model/expense-model.xml"); - } - catch (Exception e) - { - LOG.warn("Error Loading Expense Model", e); - } - - FolderModel testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); - - createAndAddNewFile(testFolder, 1, "Maidenhead", "GBP", 10.2); - createAndAddNewFile(testFolder, 2, "London", "GBP", 100.4); - createAndAddNewFile(testFolder, 3, "Manchester", "GBP", 1737.22); - FileModel lastFile = createAndAddNewFile(testFolder, 4, "Liverpool", "GBP", 445.9); - - waitForIndexing(lastFile.getName(), true); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInSelectListAreCaseSensitive() - { - List selectLists = - asList("EXPENSE_LOCATION,cm_name,expense_Currency", - "Expense_Currency,CM_NAME,ExPenSe_LOCATion", - "expense_location,expense_currency,cM_NaMe"); - - int expectedNumberOfResults = 4; - - selectLists.forEach(fields -> { - String query = "select " + fields + " from alfresco where expense_Currency='GBP' and TYPE = 'expense:expenseReport'"; - - testSqlQuery(query, expectedNumberOfResults); - - String[] expectedNames = fields.split(","); - - range(0, expectedNames.length) - .forEach(labelIndex -> { - String expectedName = expectedNames[labelIndex]; - - for (int entryIndex = 0; entryIndex < expectedNumberOfResults; entryIndex++) - restClient.onResponse() - .assertThat() - .body("list.entries.entry[" + entryIndex + "][" + labelIndex + "].label", Matchers.equalTo(expectedName)); - }); - }); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInCountListAreCaseInsensitive() - { - List selectLists = - asList("cm_name", "CM_NAME","cM_NaMe", "expense_Currency","EXPENSE_CURRENCY"); - - selectLists.forEach(field -> { - String query = "select count(" + field + ") from alfresco where expense_Currency='GBP' and TYPE = 'expense:expenseReport'"; - - testSqlQuery(query, 1); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalTo("EXPR$0")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalTo("4")); - }); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInPredicateAreCaseInsensitive() - { - List queries = - asList("select TYPE from alfresco where expense_Currency='GBP' and type = 'expense:expenseReport'", - "select TYPE from alfresco where EXPENSE_CURRENCY='GBP' and TYPE = 'expense:expenseReport'", - "select TYPE from alfresco where ExPeNsE_CurrENCY='GBP' and TyPe = 'expense:expenseReport'"); - - int expectedNumberOfResults = 4; - - queries.forEach(query -> { - testSqlQuery(query, expectedNumberOfResults); - - range(0, expectedNumberOfResults) - .forEach(entryIndex -> { - restClient.onResponse().assertThat().body("list.entries.entry[" + entryIndex + "][0].label", Matchers.equalTo("TYPE")); - restClient.onResponse().assertThat().body("list.entries.entry[" + entryIndex + "][0].value", Matchers.equalTo("{http://www.mycompany.com/model/expense/1.0}expenseReport")); - }); - }); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInExpressionsAreCaseInsensitive() - { - List fieldNames = asList("expense_Currency", "EXPENSE_CURRENCY", "ExPeNsE_CurrENCY"); - List queries = fieldNames.stream() - .map(fieldName -> asList( - "select " + fieldName + " from alfresco where TYPE = 'expense:expenseReport' group by " + fieldName + " having sum(EXPENSE_AMOUNT) > 0", - "select " + fieldName + " from alfresco where TYPE = 'expense:expenseReport' group by " + fieldName + " having sum(expense_Amount) > 0", - "select " + fieldName + " from alfresco where TYPE = 'expense:expenseReport' group by " + fieldName + " having sum(expense_amount) > 0")) - .flatMap(Collection::stream) - .collect(Collectors.toList()); - - queries.forEach(query -> { - testSqlQuery(query, 1); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("expense_Currency")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalTo("GBP")); - }); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInSortExpressionAreCaseInsensitive_descendingOrder() - { - List queries = - asList("select expense_Id from alfresco where expense_Currency='GBP' and type = 'expense:expenseReport' order by expense_id desc", - "select expense_Id from alfresco where expense_Currency='GBP' and TYPE = 'expense:expenseReport' order by expense_id desc", - "select expense_Id from alfresco where expense_Currency='GBP' and TyPe = 'expense:expenseReport' order by expense_id desc"); - - int expectedNumberOfResults = 4; - - queries.forEach(query -> { - testSqlQuery(query, expectedNumberOfResults); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalTo("4")); - - restClient.onResponse().assertThat().body("list.entries.entry[1][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalTo("3")); - - restClient.onResponse().assertThat().body("list.entries.entry[2][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[2][0].value", Matchers.equalTo("2")); - - restClient.onResponse().assertThat().body("list.entries.entry[3][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[3][0].value", Matchers.equalTo("1")); - }); - } - - @Test(groups = { TestGroup.INSIGHT_11 }) - public void fieldsInSortExpressionAreCaseInsensitive_ascendingOrder() - { - List queries = - asList("select expense_Id from alfresco where expense_Currency='GBP' and type = 'expense:expenseReport' order by expense_id asc", - "select expense_Id from alfresco where expense_Currency='GBP' and TYPE = 'expense:expenseReport' order by expense_id asc", - "select expense_Id from alfresco where expense_Currency='GBP' and TyPe = 'expense:expenseReport' order by expense_id asc", - "select expense_Id from alfresco where expense_Currency='GBP' and TYPE = 'expense:expenseReport' order by expense_id asc"); - - int expectedNumberOfResults = 4; - - queries.forEach(query -> { - testSqlQuery(query, expectedNumberOfResults); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalTo("1")); - - restClient.onResponse().assertThat().body("list.entries.entry[1][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalTo("2")); - - restClient.onResponse().assertThat().body("list.entries.entry[2][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[2][0].value", Matchers.equalTo("3")); - - restClient.onResponse().assertThat().body("list.entries.entry[3][0].label", Matchers.equalToIgnoringCase("expense_Id")); - restClient.onResponse().assertThat().body("list.entries.entry[3][0].value", Matchers.equalTo("4")); - }); - } - - /** - * Internal method used for creating a sample file, with some data used within the tests. - * - * @param parentFolder the parent folder. - * @param id the file identifier. - * @param location the location (a String property) - * @param currency the currency (another String property) - * @param amount the amount - * @return the just created {@link FileModel} instance. - */ - private FileModel createAndAddNewFile(final FolderModel parentFolder, int id, String location, String currency, double amount) throws Exception - { - FileModel file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "content #" + System.currentTimeMillis()); - file.setName("file-"+ file.getName()); - - Map properties = new HashMap<>(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "D:expense:expenseReport"); - properties.put(PropertyIds.NAME, file.getName()); - properties.put("expense:id", id); - properties.put("expense:Location", location); - properties.put("expense:Currency", currency); - properties.put("expense:Approved", true); - properties.put("expense:Amount", amount); - - cmisApi.authenticateUser(testUser) - .usingSite(testSite) - .usingResource(parentFolder) - .createFile(file, properties, VersioningState.MAJOR) - .assertThat() - .existsInRepo(); - - return file; - } -} \ No newline at end of file diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustoModelGroupByFacetableTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustoModelGroupByFacetableTest.java deleted file mode 100644 index 3cb9752a1..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustoModelGroupByFacetableTest.java +++ /dev/null @@ -1,224 +0,0 @@ -package org.alfresco.service.search.e2e.insightEngine.sql; - -import org.alfresco.rest.core.RestResponse; -import org.alfresco.rest.search.SearchSqlRequest; -import org.alfresco.service.search.e2e.AbstractSearchServiceE2E; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.model.*; -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.hamcrest.Matchers; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import java.util.HashMap; -import java.util.Map; - -public class CustoModelGroupByFacetableTest extends AbstractSearchServiceE2E -{ - - protected SiteModel testSite; - private UserModel testUser; - private FolderModel testFolder; - - private String filename1; - private String filename2; - private String filename3; - private String filename4; - - private String filecontent1; - private String filecontent2; - private String filecontent3; - private String filecontent4; - - private String author1; - private String author2; - - private Boolean exists; - - private int quantity1; - private int quantity2; - private int quantity3; - - @BeforeClass(alwaysRun = true) - public void setupEnvironment() throws Exception - { - - serverHealth.assertServerIsOnline(); - deployCustomModel("model/facetable-aspect-model.xml"); - testSite = dataSite.createPublicRandomSite(); - - // Create test user and add the user as a SiteContributor - testUser = dataUser.createRandomTestUser(); - dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor); - testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); - - filename1 = "file1"; - filename2 = "file2"; - filename3 = "file3"; - filename4 = "file4"; - - filecontent1 = "file content 1"; - filecontent2 = "content file 2"; - filecontent3 = "content file 3"; - filecontent4 = "content file 4"; - - author1 = "Giuseppe Verdi"; - author2 = "Mario Rossi"; - - exists = true; - - quantity1 = 9; - quantity2 = 10; - quantity3 = 12; - - FileModel customFile = new FileModel(filename1, FileType.TEXT_PLAIN, filecontent1); - - Map properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - properties.put(PropertyIds.NAME, customFile.getName()); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(customFile, properties, VersioningState.MAJOR).assertThat() - .existsInRepo(); - - cmisApi.authenticateUser(testUser).usingResource(customFile).addSecondaryTypes("P:csm:author").assertThat().secondaryTypeIsAvailable("P:csm:author"); - - cmisApi.authenticateUser(testUser).usingResource(customFile).addSecondaryTypes("P:csm:nontexttypes").assertThat() - .secondaryTypeIsAvailable("P:csm:nontexttypes"); - - cmisApi.authenticateUser(testUser).usingResource(customFile).updateProperty("csm:author", author2); - cmisApi.authenticateUser(testUser).usingResource(customFile).updateProperty("csm:quantity", quantity3); - cmisApi.authenticateUser(testUser).usingResource(customFile).updateProperty("csm:exists", exists); - - FileModel customFile2 = new FileModel(filename2, FileType.TEXT_PLAIN, filecontent2); - properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - properties.put(PropertyIds.NAME, customFile2.getName()); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(customFile2, properties, VersioningState.MAJOR).assertThat() - .existsInRepo(); - - cmisApi.authenticateUser(testUser).usingResource(customFile2).addSecondaryTypes("P:csm:author").assertThat().secondaryTypeIsAvailable("P:csm:author"); - cmisApi.authenticateUser(testUser).usingResource(customFile2).addSecondaryTypes("P:csm:nontexttypes").assertThat() - .secondaryTypeIsAvailable("P:csm:nontexttypes"); - cmisApi.authenticateUser(testUser).usingResource(customFile2).updateProperty("csm:author", author1); - cmisApi.authenticateUser(testUser).usingResource(customFile2).updateProperty("csm:quantity", quantity2); - cmisApi.authenticateUser(testUser).usingResource(customFile2).updateProperty("csm:exists", exists); - - FileModel customFile3 = new FileModel(filename3, FileType.TEXT_PLAIN, filecontent3); - properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - properties.put(PropertyIds.NAME, customFile3.getName()); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(customFile3, properties, VersioningState.MAJOR).assertThat() - .existsInRepo(); - - cmisApi.authenticateUser(testUser).usingResource(customFile3).addSecondaryTypes("P:csm:author").assertThat().secondaryTypeIsAvailable("P:csm:author"); - cmisApi.authenticateUser(testUser).usingResource(customFile3).addSecondaryTypes("P:csm:nontexttypes").assertThat() - .secondaryTypeIsAvailable("P:csm:nontexttypes"); - cmisApi.authenticateUser(testUser).usingResource(customFile3).updateProperty("csm:author", author1); - cmisApi.authenticateUser(testUser).usingResource(customFile3).updateProperty("csm:quantity", quantity2); - cmisApi.authenticateUser(testUser).usingResource(customFile3).updateProperty("csm:exists", exists); - - FileModel customFile4 = new FileModel(filename4, FileType.TEXT_PLAIN, filecontent4); - properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document"); - properties.put(PropertyIds.NAME, customFile4.getName()); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder).createFile(customFile4, properties, VersioningState.MAJOR).assertThat() - .existsInRepo(); - - cmisApi.authenticateUser(testUser).usingResource(customFile4).addSecondaryTypes("P:csm:nontexttypes").assertThat() - .secondaryTypeIsAvailable("P:csm:nontexttypes"); - cmisApi.authenticateUser(testUser).usingResource(customFile4).updateProperty("csm:quantity", quantity1); - cmisApi.authenticateUser(testUser).usingResource(customFile4).updateProperty("csm:exists", !exists); - - // wait for indexing - waitForIndexing("cm:name:'" + customFile4.getName() + "'", true); - waitForIndexing("cm:name:'" + testFolder.getName() + "'", true); - - } - - @Test(priority = 1, groups = { TestGroup.INSIGHT_11 }) - public void testGroupByTextFacetableModel() throws Exception - { - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_name, csm_author from alfresco group by cm_name, csm_author"); - - RestResponse response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("cm_name")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", Matchers.equalToIgnoringCase("csm_author")); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase(filename1)); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalToIgnoringCase(filename2)); - restClient.onResponse().assertThat().body("list.entries.entry[2][0].value", Matchers.equalToIgnoringCase(filename3)); - - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.equalToIgnoringCase(author2)); - restClient.onResponse().assertThat().body("list.entries.entry[1][1].value", Matchers.equalToIgnoringCase(author1)); - restClient.onResponse().assertThat().body("list.entries.entry[2][1].value", Matchers.equalToIgnoringCase(author1)); - - // Test changing the order of fields. - sqlRequest.setSql("select csm_author, cm_name from alfresco group by csm_author, cm_name"); - - response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - - restClient.onResponse().assertThat().body("list.pagination.count", Matchers.equalTo(3)); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("cm_name")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", Matchers.equalToIgnoringCase("csm_author")); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase(filename2)); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalToIgnoringCase(filename3)); - restClient.onResponse().assertThat().body("list.entries.entry[2][0].value", Matchers.equalToIgnoringCase(filename1)); - - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.equalToIgnoringCase(author1)); - restClient.onResponse().assertThat().body("list.entries.entry[1][1].value", Matchers.equalToIgnoringCase(author1)); - restClient.onResponse().assertThat().body("list.entries.entry[2][1].value", Matchers.equalToIgnoringCase(author2)); - - } - - @Test(priority = 2, groups = { TestGroup.INSIGHT_11 }) - public void testGroupByTextInteger() throws Exception - { - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select csm_quantity, csm_author from alfresco group by csm_quantity, csm_author"); - - RestResponse response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - - restClient.onResponse().assertThat().body("list.pagination.count", Matchers.equalTo(2)); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("csm_author")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", Matchers.equalToIgnoringCase("csm_quantity")); - - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.equalToIgnoringCase(Integer.toString(quantity2))); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase(author1)); - - restClient.onResponse().assertThat().body("list.entries.entry[1][1].value", Matchers.equalToIgnoringCase(Integer.toString(quantity3))); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalToIgnoringCase(author2)); - - } - - @Test(priority = 3, groups = { TestGroup.INSIGHT_11 }) - public void testGroupByBoolAggregation() throws Exception - { - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select csm_exists, max(csm_quantity) from alfresco group by csm_exists"); - - RestResponse response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - - restClient.onResponse().assertThat().body("list.pagination.count", Matchers.equalTo(2)); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase(Boolean.toString(!exists))); - restClient.onResponse().assertThat().body("list.entries.entry[1][0].value", Matchers.equalToIgnoringCase(Boolean.toString(exists))); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.equalToIgnoringCase(Integer.toString(quantity1))); - restClient.onResponse().assertThat().body("list.entries.entry[1][1].value", Matchers.equalToIgnoringCase(Integer.toString(quantity3))); - - } - -} diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelChangesTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelChangesTest.java deleted file mode 100644 index 6c1359852..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelChangesTest.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright 2018 Alfresco Software, Ltd. All rights reserved. - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. -*/ - -package org.alfresco.service.search.e2e.insightEngine.sql; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.rest.core.RestResponse; -import org.alfresco.rest.search.SearchSqlRequest; -import org.alfresco.service.search.e2e.AbstractSearchServiceE2E; -import org.alfresco.utility.constants.UserRole; -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.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.hamcrest.Matchers; -import org.springframework.http.HttpStatus; -import org.testng.Assert; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Purpose of this TestClass is to test that the SQLs work after model changes - * - * @author meenal bhave - */ -public class CustomModelChangesTest extends AbstractSearchServiceE2E -{ - protected SiteModel testSite; - - private UserModel testUser; - - private FolderModel testFolder; - - @BeforeClass(alwaysRun = true) - public void setupEnvironment() throws Exception - { - serverHealth.assertServerIsOnline(); - - deployCustomModel("model/flipStatus-model.xml"); - - testSite = dataSite.createPublicRandomSite(); - - // Create test user and add the user as a SiteContributor - testUser = dataUser.createRandomTestUser(); - - dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor); - - testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); - - // Wait for the file to be indexed - waitForIndexing(testFolder.getName(), true); - } - - @AfterClass(alwaysRun=true) - public void deleteModel() - { - deleteCustomModel("flipStatus-model.xml"); - } - - // SQL works after model is deactivated - @Test(priority = 1, groups = { TestGroup.INSIGHT_10 }) - public void testSqlWorksAfterDeactivatingModel() throws Exception - { - FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); - Map properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "D:flipFlop:song"); - properties.put(PropertyIds.NAME, customFile.getName()); - properties.put("flipFlop:genre", "Pop"); - properties.put("flipFlop:lyricist", "SomeLyricist"); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) - .createFile(customFile, properties, VersioningState.MAJOR) - .assertThat().existsInRepo(); - - // Wait for the file to be indexed - waitForIndexing(customFile.getName(), true); - - // Query custom model fields - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_name, flipFlop_genre, flipFlop_lyricist from alfresco where cm_name = '" + customFile.getName() + "'"); - sqlRequest.setLimit(10); - - RestResponse response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().body("list.pagination.count", Matchers.equalTo(1)); - - // Delete File and Delete from trash - dataContent.usingSite(testSite).usingUser(testUser).usingResource(customFile).deleteContent(); - restClient.withCoreAPI().usingTrashcan().deleteNodeFromTrashcan(customFile); - - // Wait for the file delete transaction to be indexed, until Search API returns no results - Boolean fileFound = waitForIndexing("cm:name:'" + customFile.getName() + "'", false); - Assert.assertTrue(fileFound, "File appears in the search results when deleted from trash"); - - // Query custom model fields: No matching content - response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - - // Deactivate the Model - deactivateCustomModel("flipStatus-model.xml"); - - fileFound = waitForIndexing("TYPE:'" + "flipFlop:song" + "'", false); - Assert.assertTrue(fileFound, "Indexes are not updated after deactivating a model"); - - // Query OOTB fields: Custom Model Deactivated - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select count(*) as TotalDocuments from alfresco where type = 'cm:content'"); - - response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().body("list.pagination.count", Matchers.equalTo(1)); - } -} diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelTest.java deleted file mode 100644 index 5035929eb..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/CustomModelTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2018 Alfresco Software, Ltd. All rights reserved. - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - */ - -package org.alfresco.service.search.e2e.insightEngine.sql; - -import java.util.HashMap; -import java.util.Map; - -import org.alfresco.rest.core.RestResponse; -import org.alfresco.rest.search.SearchSqlRequest; -import org.alfresco.service.search.e2e.AbstractSearchServiceE2E; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.DataContent; -import org.alfresco.utility.data.DataSite; -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.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.hamcrest.Matchers; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Purpose of this TestClass is to test that the SQL end point works as expected with CustomModels - * - * @author meenal bhave - */ - -public class CustomModelTest extends AbstractSearchServiceE2E -{ - @Autowired - protected DataSite dataSite; - - @Autowired - protected DataContent dataContent; - - protected SiteModel testSite; - - private UserModel testUser; - - private FolderModel testFolder; - - @BeforeClass(alwaysRun = true) - public void setupEnvironment() throws Exception - { - serverHealth.assertServerIsOnline(); - - testSite = dataSite.createPublicRandomSite(); - - // Create test user and add the user as a SiteContributor - testUser = dataUser.createRandomTestUser(); - - dataUser.addUserToSite(testUser, testSite, UserRole.SiteContributor); - - testFolder = dataContent.usingSite(testSite).usingUser(testUser).createFolder(); - } - - // Content of Custom Type is added to the Repo - @Test(priority = 1, groups = { TestGroup.INSIGHT_10 }) - public void testSqlListCustomFields() throws Exception - { - Long uniqueRef = System.currentTimeMillis(); - FileModel customFile = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "custom content"); - Map properties = new HashMap(); - properties.put(PropertyIds.OBJECT_TYPE_ID, "D:finance:Receipt"); - properties.put(PropertyIds.NAME, customFile.getName()); - properties.put("finance:ReceiptNo", uniqueRef); - properties.put("finance:ReceiptValue", 30); - - cmisApi.authenticateUser(testUser).usingSite(testSite).usingResource(testFolder) - .createFile(customFile, properties, VersioningState.MAJOR).assertThat().existsInRepo(); - - // Wait for the file to be indexed - waitForIndexing(customFile.getName(), true); - - // Select distinct site: json format - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select finance_ReceiptNo, finance_ReceiptValue from alfresco where finance_ReceiptNo = " + uniqueRef); - sqlRequest.setLimit(10); - - RestResponse response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(10)); - response.assertThat().body("list.pagination.count", Matchers.equalTo(1)); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", Matchers.equalToIgnoringCase("finance_ReceiptValue")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", Matchers.equalToIgnoringCase("finance_ReceiptNo")); - - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", Matchers.equalToIgnoringCase("30.0")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", Matchers.equalTo(uniqueRef.toString())); - - // Select distinct cm_name: solr format - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select finance_ReceiptNo, finance_ReceiptValue from alfresco where finance_ReceiptNo = " + uniqueRef + " limit 10"); - sqlRequest.setFormat("solr"); - - response = restClient.authenticateUser(testUser).withSearchSqlAPI().searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].finance_ReceiptValue", Matchers.equalTo(30)); - restClient.onResponse().assertThat().body("result-set.docs[0].finance_ReceiptNo", Matchers.equalTo(uniqueRef)); - } -} diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLAPITest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLAPITest.java deleted file mode 100644 index d2f5c0be7..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLAPITest.java +++ /dev/null @@ -1,781 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.service.search.e2e.insightEngine.sql; - -import static java.util.Arrays.asList; - -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.equalToIgnoringCase; -import static org.hamcrest.Matchers.everyItem; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.isIn; -import static org.hamcrest.Matchers.not; - -import org.alfresco.rest.core.RestResponse; -import org.alfresco.service.search.e2e.searchservices.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.hamcrest.Matchers; -import org.springframework.http.HttpStatus; -import org.testng.Assert; -import org.testng.annotations.Test; - -/** - * Tests for /sql end point Search API. - * - * @author Meenal Bhave - */ -public class SearchSQLAPITest extends AbstractSearchTest -{ - /** - * Path selector to get the values of all cm_name entries for returned search results. - *

- * For example it will retrieve the "alfresco.txt" from: - *

-     * {"list": {
-     *    "entries": [
-     *       {"entry": [{
-     *          "label": "cm_name",
-     *          "value": "alfresco.txt"
-     *       }]},
-     *       ...
-     * 
- */ - private static final String CM_NAME_VALUES = "list.entries.collect {it.entry.findAll {it.label == 'cm_name'}}.flatten().value"; - 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", equalToIgnoringCase("SITE")); - restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", is(true)); - restClient.onResponse().assertThat().body("result-set.docs[0].fields[0]", 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", equalToIgnoringCase("aliases")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", equalToIgnoringCase("{\"SITE\":\"SITE\",\"cm_owner\":\"CM_OWNER\"}")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", equalToIgnoringCase("isMetadata")); - restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", is("true")); - restClient.onResponse().assertThat().body("list.entries.entry[0][2].label", equalToIgnoringCase("fields")); - restClient.onResponse().assertThat().body("list.entries.entry[0][2].value", 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", 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", 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", 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", is(0)); - restClient.onResponse().assertThat().body("list.pagination.totalItems", is(0)); - restClient.onResponse().assertThat().body("list.pagination.hasMoreItems", is(false)); - restClient.onResponse().assertThat().body("list.entries", 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", greaterThan(0)); - restClient.onResponse().assertThat().body("list.pagination.totalItems", greaterThan(0)); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", equalToIgnoringCase("SITE")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", 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, TestGroup.NOT_INSIGHT_ENGINE }, 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); - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 14) - public void testSelectStar() throws Exception - { - // Select * with Limit, json format - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select * from alfresco"); - sqlRequest.setLimit(1); - - RestResponse response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(1)); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", equalToIgnoringCase("PATH")); - - // Select * with Limit, solr format: Also covered in JDBC - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select * from alfresco"); - sqlRequest.setFormat("solr"); - sqlRequest.setIncludeMetadata(true); - sqlRequest.setLimit(1); - - response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_name", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_created", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_creator", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_modified", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_modifier", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_owner", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.OWNER", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.TYPE", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.LID", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.DBID", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_title", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_description", Matchers.notNullValue()); - - // This type of assertion is required because of a '.' in the field name - Assert.assertTrue(response.getResponse().body().jsonPath().get("result-set.docs[0].aliases").toString().contains("cm_content.size=cm_content.size")); - Assert.assertTrue(response.getResponse().body().jsonPath().get("result-set.docs[0].aliases").toString().contains("cm_content.mimetype=cm_content.mimetype")); - Assert.assertTrue(response.getResponse().body().jsonPath().get("result-set.docs[0].aliases").toString().contains("cm_content.encoding=cm_content.encoding")); - Assert.assertTrue(response.getResponse().body().jsonPath().get("result-set.docs[0].aliases").toString().contains("cm_content.locale=cm_content.locale")); - - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_lockOwner", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.SITE", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.PARENT", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.PATH", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.PRIMARYPARENT", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.ASPECT", Matchers.notNullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.QNAME", Matchers.notNullValue()); - - // Test that cm_content and any other random field does not appear in the response - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.cm_content", Matchers.nullValue()); - restClient.onResponse().assertThat().body("result-set.docs[0].aliases.RandomNonExistentField", Matchers.nullValue()); - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 15) - public void testDistinct() throws Exception - { - // Select distinct site: json format - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select distinct Site from alfresco"); - sqlRequest.setLimit(10); - - RestResponse response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - response.assertThat().body("list.pagination.maxItems", Matchers.equalTo(10)); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", equalToIgnoringCase("site")); - - // Select distinct cm_name: solr format - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select distinct cm_name from alfresco limit 5"); - sqlRequest.setFormat("solr"); - - searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.notNullValue()); - } - - /** Check that a filter query can affect which results are included. */ - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_11 }, priority = 16) - public void testFilterQuery() throws Exception - { - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - String siteSQL = "select SITE, CM_OWNER from alfresco where SITE='" + siteModel.getId() + "'"; - sqlRequest.setSql(siteSQL); - // Add a filter query to only include results from inside the site (i.e. all results). - String[] filterQuery = { "SITE:'" + siteModel.getId() + "'" }; - sqlRequest.setFilterQuery(filterQuery); - - searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("list.pagination.count", greaterThan(0)); - restClient.onResponse().assertThat().body("list.pagination.totalItems", greaterThan(0)); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", equalToIgnoringCase("SITE")); - restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", equalToIgnoringCase("[\"" + siteModel.getId() + "\"]")); - - // Now try instead removing everything from the site (i.e. all results). - String[] inverseFilterQuery = { "-SITE:'" + siteModel.getId() + "'" }; - sqlRequest.setFilterQuery(inverseFilterQuery); - - searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("list.pagination.count", is(0)); - restClient.onResponse().assertThat().body("list.pagination.totalItems", is(0)); - restClient.onResponse().assertThat().body("list.pagination.hasMoreItems", is(false)); - restClient.onResponse().assertThat().body("list.entries", empty()); - } - - /** Check that the combination of multiple filter queries produce the intersection of results. */ - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_11 }, priority = 17) - public void testCombiningFilterQueries() throws Exception - { - String siteSQL = "select cm_name from alfresco where SITE='" + siteModel.getId() + "'"; - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql(siteSQL); - // Add a filter query to only include results from inside the site (i.e. all results). - String[] filterQueries = { "-cm_name:'cars'", "-cm_name:'pangram'" }; - sqlRequest.setFilterQuery(filterQueries); - - searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("list.pagination.count", greaterThan(0)); - restClient.onResponse().assertThat().body("list.pagination.totalItems", greaterThan(0)); - // Check that pangram.txt and cars.txt were both filtered out. - restClient.onResponse().assertThat() - .body(CM_NAME_VALUES, everyItem(not(isIn(asList("pangram.txt", "cars.txt"))))); - } - - /** Check that an empty list of filter queries doesn't remove anything from the results. */ - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_11 }, priority = 18) - public void testEmptyFilterQuery() throws Exception - { - String siteSQL = "select cm_name from alfresco where SITE='" + siteModel.getId() + "'"; - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql(siteSQL); - // Add an empty list of filter queries. - sqlRequest.setFilterQuery(new String[]{}); - - searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - // Check that the cm_names of all nodes in the site are returned. - restClient.onResponse().assertThat() - .body(CM_NAME_VALUES, containsInAnyOrder("documentLibrary", SEARCH_DATA_SAMPLE_FOLDER, "pangram.txt", "cars.txt", "alfresco.txt", unique_searchString + ".txt")); - } -} diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLPhraseTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLPhraseTest.java deleted file mode 100644 index d379e0116..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLPhraseTest.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.service.search.e2e.insightEngine.sql; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.alfresco.rest.core.RestResponse; -import org.alfresco.service.search.e2e.searchservices.AbstractSearchTest; -import org.alfresco.rest.search.SearchSqlJDBCRequest; -import org.alfresco.rest.search.SearchSqlRequest; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.TestGroup; -import org.springframework.http.HttpStatus; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.hamcrest.Matchers; - -/** - * Tests for /sql end point Search API: Phrase Searching. - * - * @author Meenal Bhave - */ -public class SearchSQLPhraseTest extends AbstractSearchTest -{ - FileModel fileBanana, fileYellowBanana, fileBigYellowBanana, fileBigBananaBoat, fileYellowBananaBigBoat, fileBigYellowBoat; - - List expectedContent = new ArrayList(); - - @BeforeClass(alwaysRun = true) - public void dataPreparation() throws Exception - { - super.dataPreparation(); - - // Create files with different phrases - fileBanana = new FileModel(unique_searchString + "-1.txt", "banana", "phrase searching", FileType.TEXT_PLAIN, "banana"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileBanana); - - fileYellowBanana = new FileModel(unique_searchString + "-2.txt", "yellow banana", "phrase searching", FileType.TEXT_PLAIN, "yellow banana"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileYellowBanana); - - fileBigYellowBanana = new FileModel(unique_searchString + "-3.txt", "big yellow banana", "phrase searching", FileType.TEXT_PLAIN, "big yellow banana"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileBigYellowBanana); - - fileBigBananaBoat = new FileModel(unique_searchString + "-4.txt", "big boat", "phrase searching", FileType.TEXT_PLAIN, "big boat"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileBigBananaBoat); - - fileYellowBananaBigBoat = new FileModel(unique_searchString + "-5.txt", "yellow banana big boat", "phrase searching", FileType.TEXT_PLAIN, "yellow banana big boat"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileYellowBananaBigBoat); - - fileBigYellowBoat = new FileModel(unique_searchString + "-6.txt", "big yellow boat", "phrase searching", FileType.TEXT_PLAIN, "big yellow boat"); - dataContent.usingUser(userModel).usingSite(siteModel).createContent(fileBigYellowBoat); - - waitForIndexing(fileBigYellowBoat.getName(), true); - } - - @SuppressWarnings("unchecked") - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 1) - public void testPhraseQueries() throws Exception - { - // yellow banana: 5 results expected - SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_content from alfresco where cm_content = '(yellow banana)'"); - sqlRequest.setLimit(10); - - RestResponse response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - - // Check Result count matches - response.assertThat().body("list.pagination.count", Matchers.equalTo(expectedContent.size())); - - // Check Results match - Collection> actualContent = response.getResponse().body().jsonPath().get("list.entries.entry.value"); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - - // yellow banana big boat: 6 results expected - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_content from alfresco where cm_content = '(yellow banana big boat)'"); - sqlRequest.setLimit(10); - - response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigBananaBoat.getContent())); - - // Check Result count matches - response.assertThat().body("list.pagination.count", Matchers.equalTo(expectedContent.size())); - - // Check Results match - actualContent = response.getResponse().body().jsonPath().get("list.entries.entry.value"); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - - // yellow banana big boat: 4 results expected - sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_content from alfresco where cm_content = '(big boat)'"); - sqlRequest.setLimit(10); - - response = searchSql(sqlRequest); - - restClient.assertStatusCodeIs(HttpStatus.OK); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigBananaBoat.getContent())); - - // Check Result count matches - response.assertThat().body("list.pagination.count", Matchers.equalTo(expectedContent.size())); - - // Check Results match - actualContent = response.getResponse().body().jsonPath().get("list.entries.entry.value"); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - } - - @SuppressWarnings("unchecked") - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 2) - public void testPhraseQueriesViaJDBC() throws Exception - { - // yellow banana: 5 results expected - SearchSqlJDBCRequest sqlRequest = new SearchSqlJDBCRequest(); - String sql = "select cm_content from alfresco where cm_content = '(yellow banana)'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - - Integer i = 0; - List actualContent = new ArrayList(); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("cm_content")); - actualContent.add(Arrays.asList(rs.getString("cm_content"))); - i++; - } - - Assert.assertTrue(i == expectedContent.size()); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - - // yellow banana big boat: 6 results expected - sql = "select cm_content from alfresco where cm_content = '(yellow banana big boat)'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigBananaBoat.getContent())); - - i = 0; - actualContent = new ArrayList(); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("cm_content")); - actualContent.add(Arrays.asList(rs.getString("cm_content"))); - i++; - } - - Assert.assertTrue(i == expectedContent.size()); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - - // big boat: 4 results expected - sql = "select cm_content from alfresco where cm_content = '(big boat)'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - // Set Expected Result - expectedContent = new ArrayList(); - expectedContent.add(Arrays.asList(fileBigYellowBanana.getContent())); - expectedContent.add(Arrays.asList(fileYellowBananaBigBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigYellowBoat.getContent())); - expectedContent.add(Arrays.asList(fileBigBananaBoat.getContent())); - - i = 0; - actualContent = new ArrayList(); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("cm_content")); - actualContent.add(Arrays.asList(rs.getString("cm_content"))); - i++; - } - - Assert.assertTrue(i == expectedContent.size()); - Assert.assertTrue(actualContent.containsAll(expectedContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - Assert.assertTrue(expectedContent.containsAll(actualContent), String.format("Phrase Search Results expected: %s Actual: %s", expectedContent.toString(), actualContent.toString())); - } -} \ No newline at end of file diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLViaJDBCTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLViaJDBCTest.java deleted file mode 100644 index 47219e4ad..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLViaJDBCTest.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.service.search.e2e.insightEngine.sql; - -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.alfresco.dataprep.SiteService.Visibility; -import org.alfresco.rest.requests.search.SearchSQLJDBC; -import org.alfresco.service.search.e2e.searchservices.AbstractSearchTest; -import org.alfresco.rest.search.SearchSqlJDBCRequest; -import org.alfresco.utility.data.RandomData; -import org.alfresco.utility.model.SiteModel; -import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.model.UserModel; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.Test; -import org.testng.Assert; - -/** - * Search SQL end point test via JDBC. - * @author MSuzuki - * @author Meenal Bhave - * - */ -public class SearchSQLViaJDBCTest extends AbstractSearchTest -{ - List sites = new ArrayList(); - SearchSQLJDBC searchSql; - SearchSqlJDBCRequest sqlRequest = new SearchSqlJDBCRequest(); - - @AfterMethod(alwaysRun=true) - public void cleanUp() throws SQLException - { - restClient.withSearchSqlViaJDBC().clearSearchQuery(sqlRequest); - sqlRequest = new SearchSqlJDBCRequest(); - sites = new ArrayList(); - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority=01) - public void testQueryPublicSite() throws SQLException - { - - SiteModel publicSite = new SiteModel(RandomData.getRandomName("SiteSearch")); - publicSite.setVisibility(Visibility.PUBLIC); - - publicSite = dataSite.usingUser(adminUserModel).createSite(publicSite); - - String sql = "select SITE,CM_OWNER from alfresco where SITE ='" + publicSite.getTitle() + "' group by SITE,CM_OWNER"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - - while (rs.next()) - { - // User can see the Public Site created by other user - Assert.assertNotNull(rs.getString("SITE")); - Assert.assertTrue(publicSite.getTitle().equalsIgnoreCase(rs.getString("SITE"))); - - Assert.assertNotNull(rs.getString("CM_OWNER")); - Assert.assertTrue(rs.getString("CM_OWNER").contains(adminUserModel.getUsername())); - } - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority=02) - public void testQueryMyCreatedPrivateSite() throws SQLException - { - String sql = "select distinct SITE from alfresco where SITE ='" + siteModel.getTitle() + "'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - - while (rs.next()) - { - // User can see Own Private Site - Assert.assertNotNull(rs.getString("SITE")); - Assert.assertTrue(siteModel.getTitle().equalsIgnoreCase(rs.getString("SITE"))); - } - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority=03) - public void testQueryPrivateSiteWithSuperUser() throws SQLException - { - String sql = "select distinct SITE from alfresco where SITE ='" + siteModel.getTitle() + "'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(adminUserModel); - - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - - while (rs.next()) - { - // Super user can see Private Site created by other user - Assert.assertNotNull(rs.getString("SITE")); - Assert.assertTrue(siteModel.getTitle().equalsIgnoreCase(rs.getString("SITE"))); - } - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority=04) - public void testQueryPrivateSiteWithSimpleUser() throws SQLException - { - UserModel managerUser = dataUser.createRandomTestUser("UserSearchMgr"); - - String sql = "select SITE from alfresco where SITE = '" + siteModel.getTitle() + "'"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(managerUser); - - // Non admin user can NOT see Private Site created by other user - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertFalse(rs.next()); - } - - - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority=05) - public void testQueryErrorReturned() throws SQLException - { - String expectedError = "Column 'SITE1' not found"; - - String sql = "select SITE1 from alfresco"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - // Appropriate error is retrieved when SQL is incorrect - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - - String error = sqlRequest.getErrorDetails(); - Assert.assertNotNull(error); - Assert.assertTrue(error.contains(expectedError), "Error shown: " + error + " Error expected: " + expectedError); - - // Record set is null - Assert.assertNull(rs); - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 06) - public void testQuerySelectStar() throws SQLException - { - // Select * query with limit clause - String sql = "select * from alfresco limit 5"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - // Select * with limit clause works: No error is retrieved - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("PATH")); - Assert.assertNotNull(rs.getString("DBID")); - Assert.assertNotNull(rs.getString("cm_name")); - } - - // Select * query Without limit clause: No error is retrieved - sql = "select * from alfresco"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(userModel); - - // No error is retrieved when SQL is incorrect - rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("PATH")); - Assert.assertNotNull(rs.getString("DBID")); - Assert.assertNotNull(rs.getString("cm_name")); - } - } - - @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 07) - public void testQuerySelectDistinct() throws SQLException - { - // Select distinct query with limit clause - String sql = "select distinct cm_name from alfresco limit 5"; - sqlRequest.setSql(sql); - sqlRequest.setAuthUser(adminUserModel); - - // Select distinct with limit clause works: No error is retrieved - ResultSet rs = restClient.withSearchSqlViaJDBC().executeQueryViaJDBC(sqlRequest); - Assert.assertNotNull(rs); - Assert.assertNull(sqlRequest.getErrorDetails()); - - while (rs.next()) - { - // Field values are retrieved - Assert.assertNotNull(rs.getString("cm_name")); - } - } -} \ No newline at end of file diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLWithQuotedIdentifiers.java deleted file mode 100644 index 50077f086..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SearchSQLWithQuotedIdentifiers.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * 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 . - */ -package org.alfresco.service.search.e2e.insightEngine.sql; - -import java.util.UUID; - -import org.alfresco.service.search.e2e.searchservices.AbstractSearchTest; -import org.alfresco.utility.constants.UserRole; -import org.alfresco.utility.data.CustomObjectTypeProperties; -import org.alfresco.utility.model.ContentModel; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.FolderModel; -import org.alfresco.utility.model.TestGroup; -import org.alfresco.utility.report.Bug; -import org.hamcrest.Matchers; -import org.springframework.http.HttpStatus; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.alfresco.rest.RestTest; - -/** - * Tests for /sql end point Search API when a custom model contains identifiers that need to be quoted in queries. - * While it seems there is not an ANSI standard for naming database objects, on the other side the most popular - * databases don't like columns starting with a number. - * In those cases, the column identifier need to be quoted. How to quote a given object identifier (a column name, in - * this case) depends on the specific database lexicon: Oracle uses double quotes ("), MySQL uses back quotes(`). - * - * At time of writing, the lexicon used by the /sql endpoint is MySql so queries that use column names starting with - * a number need to be quoted with back quotes. - * - */ -public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest -{ - - private String songName; - private String genre; - private String coProducer; - - private String artistName; - private String voiceType; - - private String bassistName; - private String drummerName; - private String saxophonistName; - - private FileModel file5; - - /** - * Setup fixture for this test case. - * Overrides the superlayer method because the data preparation requires a bit different preconditions. - * The method uses a transient test site created in the {@link RestTest#checkServerHealth()} and on top of that: - * - *
    - *
  • It adds a user which is added to the site as contributor
  • - *
  • - * It deploys a custom model which declares a set of prefixes composed by a combination of digits, hyphens - * and underscores. Those prefixes are associated with four entities (song, artist, bassist, drummer and - * sax) with their corresponding attributes. - *
  • - *
  • - * It creates a folder with 5 files associated with the types declared in the model. - * That allows those files to have a value for the properties/attributes included in the model definition. - *
  • - *
- * - * @see RestTest#checkServerHealth() - * @throws Exception hopefully never, otherwise the test fails. - */ - @BeforeClass(alwaysRun = true) - public void localDataPreparation() throws Exception - { - songName = "The Dry Cleaner from Des Moines "; - genre = "Jazz, vocal jazz "; - coProducer = "Roberta Joan Mitchell "; - - artistName = "Joni Mitchell " + UUID.randomUUID(); - voiceType = "Blue Mezzo (1965-1984) / Cloudy Contralto (1985-present) "; - - bassistName = "Jaco Pastorius"; - drummerName = "Peter Erskine"; - saxophonistName = "Wayne Shorter"; - - dataContent.usingAdmin().deployContentModel("model/search-1063-model.xml"); - - dataUser.addUserToSite(userModel, siteModel, UserRole.SiteContributor); - - testSite = siteModel; - - FolderModel testFolder = dataContent.usingSite(testSite).usingUser(userModel).createFolder(); - - file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - file2 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - file3 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - file4 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - file5 = FileModel.getRandomFileModel(FileType.TEXT_PLAIN); - - dataContent.usingUser(userModel) - .usingResource(testFolder) - .createCustomContent( - file, - "D:1:song", - new CustomObjectTypeProperties() - .addProperty("1:name", songName) - .addProperty("1:genre", genre) - .addProperty("1:co-producer", coProducer)); - - dataContent.usingUser(userModel) - .usingResource(testFolder) - .createCustomContent( - file2, - "D:123:artist", - new CustomObjectTypeProperties() - .addProperty("123:name", artistName) - .addProperty("123:voice_type", voiceType)); - - dataContent.usingUser(userModel) - .usingResource(testFolder) - .createCustomContent( - file3, - "D:1_2_3:bassist", - new CustomObjectTypeProperties() - .addProperty("1_2_3:name", bassistName)); - - dataContent.usingUser(userModel) - .usingResource(testFolder) - .createCustomContent( - file4, - "D:1-2-3:drummer", - new CustomObjectTypeProperties() - .addProperty("1-2-3:name", drummerName)); - - ContentModel content = - dataContent.usingUser(userModel) - .usingResource(testFolder) - .createCustomContent( - file5, - "D:1-2_3:saxophonist", - new CustomObjectTypeProperties() - .addProperty("1-2_3:name", saxophonistName)); - - waitForIndexing(content.getName(), true); - } - - @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) - @Bug(id = "SEARCH-1063") - public void prefixIsComposedByOneNumber() throws Exception - { - executeSqlAsSolr("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song' and SITE='" + testSite.getId() + "'"); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.equalTo(file.getName())); - restClient.onResponse().assertThat().body("result-set.docs[0].1_name", Matchers.equalTo(songName)); - restClient.onResponse().assertThat().body("result-set.docs[0].1_genre", Matchers.equalTo(genre)); - restClient.onResponse().assertThat().body("result-set.docs[0].1_co-producer", Matchers.equalTo(coProducer)); - } - - @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) - @Bug(id = "SEARCH-1063") - public void prefixIsComposedByMultipleNumbers() throws Exception - { - executeSqlAsSolr("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist' and SITE='" + testSite.getId() + "'"); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.equalTo(file2.getName())); - restClient.onResponse().assertThat().body("result-set.docs[0].123_name", Matchers.equalTo(artistName)); - restClient.onResponse().assertThat().body("result-set.docs[0].123_voice_type", Matchers.equalTo(voiceType)); - } - - @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) - @Bug(id = "SEARCH-1063") - public void prefixIncludesUnderscore() throws Exception - { - executeSqlAsSolr("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist' and SITE='" + testSite.getId() + "'"); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.equalTo(file3.getName())); - restClient.onResponse().assertThat().body("result-set.docs[0].1_2_3_name", Matchers.equalTo(bassistName)); - } - - @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) - @Bug(id = "SEARCH-1063") - public void prefixIncludesHyphen() throws Exception - { - executeSqlAsSolr("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer' and SITE='" + testSite.getId() + "'"); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.equalTo(file4.getName())); - restClient.onResponse().assertThat().body("result-set.docs[0].1-2-3_name", Matchers.equalTo(drummerName)); - } - - @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) - @Bug(id = "SEARCH-1063") - public void prefixIncludesHyphenAndUnderscore() throws Exception - { - executeSqlAsSolr("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist' and SITE='" + testSite.getId() + "'"); - - restClient.assertStatusCodeIs(HttpStatus.OK); - restClient.onResponse().assertThat().body("result-set.docs[0].cm_name", Matchers.equalTo(file5.getName())); - restClient.onResponse().assertThat().body("result-set.docs[0].1-2_3_name", Matchers.equalTo(saxophonistName)); - } -} \ No newline at end of file diff --git a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SelectStarTest.java b/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SelectStarTest.java deleted file mode 100644 index c4aab4c50..000000000 --- a/e2e-test/src/test/java/org/alfresco/service/search/e2e/insightEngine/sql/SelectStarTest.java +++ /dev/null @@ -1,584 +0,0 @@ -/* - * Copyright 2019 Alfresco Software, Ltd. All rights reserved. - * License rights for this program may be obtained from Alfresco Software, Ltd. - * pursuant to a written agreement and any use of this program without such an - * agreement is prohibited. - */ - -package org.alfresco.service.search.e2e.insightEngine.sql; - -import static java.util.Arrays.asList; - -import java.time.LocalDateTime; -import java.time.ZoneOffset; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.alfresco.service.search.e2e.AbstractSearchServiceE2E; -import org.alfresco.utility.LogFactory; -import org.alfresco.utility.data.DataContent; -import org.alfresco.utility.data.DataSite; -import org.alfresco.utility.model.FileModel; -import org.alfresco.utility.model.FileType; -import org.alfresco.utility.model.FolderModel; -import org.alfresco.utility.model.TestGroup; -import org.apache.chemistry.opencmis.commons.PropertyIds; -import org.apache.chemistry.opencmis.commons.enums.VersioningState; -import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Autowired; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Purpose of this TestClass is to test that the variants of