diff --git a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLAPITest.java b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLAPITest.java index 36e59760d..f7dbc66bd 100644 --- a/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLAPITest.java +++ b/e2e-test/java/org/alfresco/rest/search/sql/SearchSQLAPITest.java @@ -31,8 +31,38 @@ public class SearchSQLAPITest extends AbstractSearchTest 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 queryTestWithSolr() throws Exception + public void testWithSolr() throws Exception { SearchSqlRequest sqlRequest = new SearchSqlRequest(); sqlRequest.setSql(sql); @@ -46,8 +76,46 @@ public class SearchSQLAPITest extends AbstractSearchTest restClient.onResponse().assertThat().body("result-set.docs", org.hamcrest.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 queryTestWithJson() throws Exception + public void testWithJson() throws Exception { SearchSqlRequest sqlRequest = new SearchSqlRequest(); sqlRequest.setSql(sql); @@ -83,8 +151,48 @@ public class SearchSQLAPITest extends AbstractSearchTest restClient.onResponse().assertThat().body("list.entries", org.hamcrest.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 queryTestWithSolrIncludeMetadata() throws Exception + public void testWithSolrIncludeMetadata() throws Exception { SearchSqlRequest sqlRequest = new SearchSqlRequest(); sqlRequest.setSql(sql); @@ -98,6 +206,84 @@ public class SearchSQLAPITest extends AbstractSearchTest restClient.onResponse().assertThat().body("result-set", org.hamcrest.Matchers.notNullValue()); restClient.onResponse().assertThat().body("result-set.docs", org.hamcrest.Matchers.notNullValue()); + restClient.onResponse().assertThat().body("result-set.docs[0].aliases.SITE", org.hamcrest.Matchers.equalToIgnoringCase("SITE")); restClient.onResponse().assertThat().body("result-set.docs[0].isMetadata", org.hamcrest.Matchers.is(true)); + restClient.onResponse().assertThat().body("result-set.docs[0].fields[0]", org.hamcrest.Matchers.equalToIgnoringCase("SITE")); + } + + /** + * API post example: + * { + * "stmt": "select SITE from alfresco limit 2", + * "locales" : ["en_US"], + * "format" : "json", + * "timezone":"", + * "includeMetadata":false + * } + * Example Response: In json Format + * { + * "list": + * { + * "pagination": + * { + "count": 3, + "hasMoreItems": false, + "totalItems": 3, + "skipCount": 0, + "maxItems": 1000 + }, + * "entries": + * [ + * "entry": [ + { + "label": "aliases", + "value": "{\"SITE\":\"SITE\"}" + }, + { + "label": "isMetadata", + "value": "true" + }, + { + "label": "fields", + "value": "[\"SITE\"]" + } + ] + }, + * "entry": [ + { + "label": "SITE", + "value": "[\"swsdp\"]" + } + ], + "entry": [ + { + "label": "SITE", + "value": "[\"swsdp\"]" + } + ] + * ] + * } + */ + @Test(groups = { TestGroup.SEARCH, TestGroup.REST_API, TestGroup.INSIGHT_10 }, priority = 04) + public void testWithJsonIncludeMetadata() throws Exception + { + SearchSqlRequest sqlRequest = new SearchSqlRequest(); + sqlRequest.setSql(sql); + sqlRequest.setFormat(""); + sqlRequest.setLocales(locales); + sqlRequest.setIncludeMetadata(true); + + searchSql(sqlRequest); + + restClient.assertStatusCodeIs(HttpStatus.OK); + + restClient.onResponse().assertThat().body("result-set", org.hamcrest.Matchers.nullValue()); + restClient.onResponse().assertThat().body("list.entries", org.hamcrest.Matchers.notNullValue()); + restClient.onResponse().assertThat().body("list.entries.entry[0][0].label", org.hamcrest.Matchers.equalToIgnoringCase("aliases")); + restClient.onResponse().assertThat().body("list.entries.entry[0][0].value", org.hamcrest.Matchers.equalToIgnoringCase("{\"SITE\":\"SITE\",\"cm_owner\":\"CM_OWNER\"}")); + restClient.onResponse().assertThat().body("list.entries.entry[0][1].label", org.hamcrest.Matchers.equalToIgnoringCase("isMetadata")); + restClient.onResponse().assertThat().body("list.entries.entry[0][1].value", org.hamcrest.Matchers.is("true")); + restClient.onResponse().assertThat().body("list.entries.entry[0][2].label", org.hamcrest.Matchers.equalToIgnoringCase("fields")); + restClient.onResponse().assertThat().body("list.entries.entry[0][2].value", org.hamcrest.Matchers.equalToIgnoringCase("[\"SITE\",\"cm_owner\"]")); } } \ No newline at end of file