From 51de9741717616d25d3af2a8d86c9ac16c170179 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Tue, 30 Oct 2018 12:13:01 +0100 Subject: [PATCH 1/7] [ SEARCH-1063] Custom (test) model + Integration test --- .../sql/SearchSQLWithQuotedIdentifiers.java | 108 ++++++++++++++++++ e2e-test/resources/models/SEARCH-1063.xml | 43 +++++++ 2 files changed, 151 insertions(+) create mode 100644 e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java create mode 100755 e2e-test/resources/models/SEARCH-1063.xml diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java new file mode 100644 index 000000000..168a2122c --- /dev/null +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -0,0 +1,108 @@ +/* + * 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.rest.search.sql; + +import org.alfresco.rest.core.RestResponse; +import org.alfresco.rest.search.AbstractSearchTest; +import org.alfresco.rest.search.SearchSqlRequest; +import org.alfresco.utility.constants.UserRole; +import org.alfresco.utility.data.CustomObjectTypeProperties; +import org.alfresco.utility.model.*; +import org.alfresco.utility.report.Bug; +import org.apache.chemistry.opencmis.commons.PropertyIds; +import org.hamcrest.Matchers; +import org.springframework.http.HttpStatus; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * 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 final String songName = "Got a match?"; + private final String genre = "Fusion"; + + /** + * Setup fixture for this test case. + * Overrides the superlayer method because the data preparation requires a bit different preconditions. + * + * @throws Exception hopefully never, otherwise the test fails. + */ + @BeforeClass(alwaysRun = true) + public void dataPreparation() throws Exception + { + userModel = dataUser.createRandomTestUser(); + + dataContent.usingAdmin().deployContentModel("models/SEARCH-1063.xml"); + + userModel = dataUser.createRandomTestUser(); + + dataUser.addUserToSite(userModel, testSite, UserRole.SiteContributor); + + final FolderModel testFolder = dataContent.usingSite(testSite).usingUser(userModel).createFolder(); + + file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "Some text content."); + + final CustomObjectTypeProperties attributes = new CustomObjectTypeProperties(); +// attributes.addProperty(PropertyIds.NAME, file.getName()); + attributes.addProperty("1:name", songName); + attributes.addProperty("1:genre", genre); + + final ContentModel content = + dataContent.usingUser(userModel) + .usingResource(testFolder) + .createCustomContent(file, "D:1:song", attributes); + + waitForIndexing(content.getName(), true); + } + + @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) + @Bug(id = "SEARCH-1063") + public void testSearchUsingCustomAttributeStartingWithNumber() throws Exception + { + final SearchSqlRequest sqlRequest = new SearchSqlRequest(); + sqlRequest.setSql("select cm_name, `1_name`, `1_genre` from alfresco where TYPE='1:song'"); + sqlRequest.setFormat("solr"); + sqlRequest.setLocales(new String[] { "en-US" }); + sqlRequest.setIncludeMetadata(false); + + restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); + 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)); + } + + @AfterClass(alwaysRun = true) + public void tearDown() throws Exception + { + dataContent.usingSite(testSite).usingUser(dataUser.getAdminUser()).deleteSite(testSite); + } +} \ No newline at end of file diff --git a/e2e-test/resources/models/SEARCH-1063.xml b/e2e-test/resources/models/SEARCH-1063.xml new file mode 100755 index 000000000..3ba275d19 --- /dev/null +++ b/e2e-test/resources/models/SEARCH-1063.xml @@ -0,0 +1,43 @@ + + + Administrator admin user + + + + + + + + + + + + song + cm:content + + + name + d:text + false + + TRUE + false + + + + genre + d:text + false + + TRUE + false + + + + + + + + + + \ No newline at end of file From 61b0ae3541a087d8447706ef71420ee13044a30f Mon Sep 17 00:00:00 2001 From: agazzarini Date: Wed, 31 Oct 2018 14:53:00 +0100 Subject: [PATCH 2/7] [ SEARCH-1063] Custom (test) model + Integration test for numeric prefixes in columns --- .../rest/search/sql/SearchSQLWithQuotedIdentifiers.java | 1 - e2e-test/resources/models/SEARCH-1063.xml | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index 168a2122c..bf88ea9b7 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -70,7 +70,6 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "Some text content."); final CustomObjectTypeProperties attributes = new CustomObjectTypeProperties(); -// attributes.addProperty(PropertyIds.NAME, file.getName()); attributes.addProperty("1:name", songName); attributes.addProperty("1:genre", genre); diff --git a/e2e-test/resources/models/SEARCH-1063.xml b/e2e-test/resources/models/SEARCH-1063.xml index 3ba275d19..97c4f0882 100755 --- a/e2e-test/resources/models/SEARCH-1063.xml +++ b/e2e-test/resources/models/SEARCH-1063.xml @@ -20,7 +20,8 @@ d:text false - TRUE + true + BOTH false @@ -29,7 +30,8 @@ d:text false - TRUE + true + BOTH false From 69a9866ad89b24ed9e6c1ecc727ceb59a16cb0bf Mon Sep 17 00:00:00 2001 From: agazzarini Date: Sun, 4 Nov 2018 09:55:59 +0100 Subject: [PATCH 3/7] [ SEARCH-1063] more tests + review fixes --- .../sql/SearchSQLWithQuotedIdentifiers.java | 172 +++++++++++++++--- e2e-test/resources/models/SEARCH-1063.xml | 119 +++++++++++- 2 files changed, 262 insertions(+), 29 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index bf88ea9b7..71f472efa 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -18,17 +18,17 @@ */ package org.alfresco.rest.search.sql; -import org.alfresco.rest.core.RestResponse; +import java.util.UUID; + +import org.alfresco.rest.RestTest; import org.alfresco.rest.search.AbstractSearchTest; import org.alfresco.rest.search.SearchSqlRequest; import org.alfresco.utility.constants.UserRole; import org.alfresco.utility.data.CustomObjectTypeProperties; import org.alfresco.utility.model.*; import org.alfresco.utility.report.Bug; -import org.apache.chemistry.opencmis.commons.PropertyIds; import org.hamcrest.Matchers; import org.springframework.http.HttpStatus; -import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -45,63 +45,181 @@ import org.testng.annotations.Test; */ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { - private final String songName = "Got a match?"; - private final String genre = "Fusion"; + + 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 dataPreparation() 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"; + userModel = dataUser.createRandomTestUser(); dataContent.usingAdmin().deployContentModel("models/SEARCH-1063.xml"); - userModel = dataUser.createRandomTestUser(); - dataUser.addUserToSite(userModel, testSite, UserRole.SiteContributor); - final FolderModel testFolder = dataContent.usingSite(testSite).usingUser(userModel).createFolder(); + FolderModel testFolder = dataContent.usingSite(testSite).usingUser(userModel).createFolder(); - file = FileModel.getRandomFileModel(FileType.TEXT_PLAIN, "Some text content."); + 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); - final CustomObjectTypeProperties attributes = new CustomObjectTypeProperties(); - attributes.addProperty("1:name", songName); - attributes.addProperty("1:genre", genre); + 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)); - final ContentModel content = + 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(file, "D:1:song", attributes); + .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 testSearchUsingCustomAttributeStartingWithNumber() throws Exception + public void prefixIsComposedByOneNumber() throws Exception { - final SearchSqlRequest sqlRequest = new SearchSqlRequest(); - sqlRequest.setSql("select cm_name, `1_name`, `1_genre` from alfresco where TYPE='1:song'"); - sqlRequest.setFormat("solr"); - sqlRequest.setLocales(new String[] { "en-US" }); - sqlRequest.setIncludeMetadata(false); - - restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); + executeQuery("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song'"); 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)); } - @AfterClass(alwaysRun = true) - public void tearDown() throws Exception + @Test(groups={TestGroup.SEARCH, TestGroup.REST_API, TestGroup.ASS_1}) + @Bug(id = "SEARCH-1063") + public void prefixIsComposedByMultipleNumbers() throws Exception { - dataContent.usingSite(testSite).usingUser(dataUser.getAdminUser()).deleteSite(testSite); + executeQuery("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist'"); + + 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 + { + executeQuery("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist'"); + + 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 + { + executeQuery("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer'"); + + 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 + { + executeQuery("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist'"); + + 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)); + } + + /** + * Internal method for executing a SQL Query. + * + * TODO: maybe would be better to move this method (and similar methods) on a SQL supertype layer (e.g. AbstractSqlSearchTest) + * + * @param sql the SQL statement. + */ + private void executeQuery(String sql) throws Exception + { + SearchSqlRequest sqlRequest = new SearchSqlRequest(sql, "solr"); + + restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); + restClient.assertStatusCodeIs(HttpStatus.OK); } } \ No newline at end of file diff --git a/e2e-test/resources/models/SEARCH-1063.xml b/e2e-test/resources/models/SEARCH-1063.xml index 97c4f0882..2e647e150 100755 --- a/e2e-test/resources/models/SEARCH-1063.xml +++ b/e2e-test/resources/models/SEARCH-1063.xml @@ -6,7 +6,24 @@ + + + + + @@ -16,7 +33,7 @@ cm:content - name + Name d:text false @@ -26,7 +43,105 @@ - genre + Genre + d:text + false + + true + BOTH + false + + + + Producer + d:text + false + + true + BOTH + false + + + + + + + + + Artist + cm:content + + + Name + d:text + false + + true + BOTH + false + + + + + + Voice Type + d:text + false + + true + BOTH + false + + + + + + + + + Bassist + cm:content + + + Name + d:text + false + + true + BOTH + false + + + + + + + + + Drummer + cm:content + + + Name + d:text + false + + true + BOTH + false + + + + + + + + + Sax + cm:content + + + Name d:text false From 139c5b29aa252f88b14625096d4d239a0ab6f546 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Sun, 4 Nov 2018 18:52:24 +0100 Subject: [PATCH 4/7] [ issue MNT-19952 ] Fixed errors on multi-type model --- .../rest/search/sql/SearchSQLWithQuotedIdentifiers.java | 2 +- e2e-test/resources/models/SEARCH-1063.xml | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index 71f472efa..50b2a7c80 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -148,7 +148,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest .usingResource(testFolder) .createCustomContent( file5, - "D:1-2_3_saxophonist", + "D:1-2_3:saxophonist", new CustomObjectTypeProperties() .addProperty("1-2_3:name", saxophonistName)); diff --git a/e2e-test/resources/models/SEARCH-1063.xml b/e2e-test/resources/models/SEARCH-1063.xml index 2e647e150..816afd2bc 100755 --- a/e2e-test/resources/models/SEARCH-1063.xml +++ b/e2e-test/resources/models/SEARCH-1063.xml @@ -22,7 +22,7 @@ - + @@ -81,8 +81,6 @@ false - - Voice Type d:text @@ -98,11 +96,12 @@ + Bassist cm:content - + Name d:text false @@ -140,7 +139,7 @@ Sax cm:content - + Name d:text false From 5be15c2f22e09d6bf4a7ac845bac2be96406ad91 Mon Sep 17 00:00:00 2001 From: agazzarini Date: Sun, 4 Nov 2018 19:46:20 +0100 Subject: [PATCH 5/7] [ issue MNT-19952 ] added a SITE filter to test SQL statements --- .../search/sql/SearchSQLWithQuotedIdentifiers.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index 50b2a7c80..239013988 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -159,7 +159,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIsComposedByOneNumber() throws Exception { - executeQuery("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song'"); + executeQuery("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song' and SITE='" + testSite.getId() + "'"); 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)); @@ -171,7 +171,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIsComposedByMultipleNumbers() throws Exception { - executeQuery("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist'"); + executeQuery("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist' and SITE='" + testSite.getId() + "'"); 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)); @@ -182,7 +182,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesUnderscore() throws Exception { - executeQuery("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist'"); + executeQuery("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist' and SITE='" + testSite.getId() + "'"); 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)); @@ -192,7 +192,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesHyphen() throws Exception { - executeQuery("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer'"); + executeQuery("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer' and SITE='" + testSite.getId() + "'"); 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)); @@ -202,7 +202,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesHyphenAndUnderscore() throws Exception { - executeQuery("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist'"); + executeQuery("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist' and SITE='" + testSite.getId() + "'"); 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)); From aac75965550a0905a2595661962b54b0151fd6bd Mon Sep 17 00:00:00 2001 From: agazzarini Date: Mon, 5 Nov 2018 12:00:09 +0100 Subject: [PATCH 6/7] [ issue MNT-19952 ] moved SQL query execution on AbstractSearchTest --- .../rest/search/AbstractSearchTest.java | 17 ++++++++++++- .../sql/SearchSQLWithQuotedIdentifiers.java | 25 ++++--------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java index e8a0f955c..fac5b3db3 100644 --- a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java +++ b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java @@ -139,7 +139,22 @@ public class AbstractSearchTest extends RestTest { return restClient.authenticateUser(userModel).withSearchAPI().search(query); } - + + /** + * Executes an SQL Query using "solr" as output format. + * + * @param sql the SQL statement. + */ + protected void executeSqlAsSolr(String sql) throws Exception + { + SearchSqlRequest sqlRequest = new SearchSqlRequest(); + sqlRequest.setSql(sql); + sqlRequest.setFormat("solr"); + + restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); + restClient.assertStatusCodeIs(HttpStatus.OK); + } + protected SearchRequest createQuery(String term) { SearchRequest query = new SearchRequest(); diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index 239013988..2c368361a 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -159,7 +159,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIsComposedByOneNumber() throws Exception { - executeQuery("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song' and SITE='" + testSite.getId() + "'"); + executeSqlAsSolr("select cm_name, `1_name`, `1_genre`, `1_co-producer` from alfresco where TYPE='1:song' and SITE='" + testSite.getId() + "'"); 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)); @@ -171,7 +171,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIsComposedByMultipleNumbers() throws Exception { - executeQuery("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist' and SITE='" + testSite.getId() + "'"); + executeSqlAsSolr("select cm_name, `123_name`, `123_voice_type` from alfresco where TYPE='123:artist' and SITE='" + testSite.getId() + "'"); 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)); @@ -182,7 +182,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesUnderscore() throws Exception { - executeQuery("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist' and SITE='" + testSite.getId() + "'"); + executeSqlAsSolr("select cm_name, `1_2_3_name` from alfresco where TYPE='1_2_3:bassist' and SITE='" + testSite.getId() + "'"); 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)); @@ -192,7 +192,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesHyphen() throws Exception { - executeQuery("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer' and SITE='" + testSite.getId() + "'"); + executeSqlAsSolr("select cm_name, `1-2-3_name` from alfresco where TYPE='1-2-3:drummer' and SITE='" + testSite.getId() + "'"); 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)); @@ -202,24 +202,9 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest @Bug(id = "SEARCH-1063") public void prefixIncludesHyphenAndUnderscore() throws Exception { - executeQuery("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist' and SITE='" + testSite.getId() + "'"); + executeSqlAsSolr("select cm_name, `1-2_3_name` from alfresco where TYPE='1-2_3:saxophonist' and SITE='" + testSite.getId() + "'"); 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)); } - - /** - * Internal method for executing a SQL Query. - * - * TODO: maybe would be better to move this method (and similar methods) on a SQL supertype layer (e.g. AbstractSqlSearchTest) - * - * @param sql the SQL statement. - */ - private void executeQuery(String sql) throws Exception - { - SearchSqlRequest sqlRequest = new SearchSqlRequest(sql, "solr"); - - restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); - } } \ No newline at end of file From 336aeac07103dd67115c97837b7b79218bca614b Mon Sep 17 00:00:00 2001 From: agazzarini Date: Tue, 6 Nov 2018 14:26:25 +0100 Subject: [PATCH 7/7] [ SEARCH-1063 ] minor refactoring on executeSqlAsSolr method --- .../java/org/alfresco/rest/search/AbstractSearchTest.java | 6 ++---- .../rest/search/sql/SearchSQLWithQuotedIdentifiers.java | 5 +++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java index fac5b3db3..151c7c547 100644 --- a/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java +++ b/e2e-test/java/org/alfresco/rest/search/AbstractSearchTest.java @@ -145,14 +145,12 @@ public class AbstractSearchTest extends RestTest * * @param sql the SQL statement. */ - protected void executeSqlAsSolr(String sql) throws Exception + protected RestResponse executeSqlAsSolr(String sql) throws Exception { SearchSqlRequest sqlRequest = new SearchSqlRequest(); sqlRequest.setSql(sql); sqlRequest.setFormat("solr"); - - restClient.authenticateUser(userModel).withSearchSqlAPI().searchSql(sqlRequest); - restClient.assertStatusCodeIs(HttpStatus.OK); + return searchSql(sqlRequest); } protected SearchRequest createQuery(String term) diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java index 2c368361a..dca6d1793 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLWithQuotedIdentifiers.java @@ -161,6 +161,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { 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)); @@ -173,6 +174,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { 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)); @@ -184,6 +186,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { 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)); } @@ -194,6 +197,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { 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)); } @@ -204,6 +208,7 @@ public class SearchSQLWithQuotedIdentifiers extends AbstractSearchTest { 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)); }