[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16387725#comment-16387725 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on issue #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#issuecomment-370775985 Thanks @rombert for bearing with me! This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Assignee: Robert Munteanu >Priority: Major > Fix For: Testing Clients 1.1.6 > > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16387452#comment-16387452 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on issue #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#issuecomment-370701086 Merged, thanks @volteanu ! This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16387451#comment-16387451 ] ASF GitHub Bot commented on SLING-7509: --- rombert closed pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5 This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/pom.xml b/pom.xml index 17c4562..2eac034 100644 --- a/pom.xml +++ b/pom.xml @@ -132,6 +132,11 @@ org.apache.sling.xss 1.0.4 + +org.ops4j.pax.tinybundles +tinybundles +3.0.0 + @@ -158,5 +163,50 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.0 +provided + + +javax.servlet +servlet-api +2.4 +provided + + +javax.jcr +jcr +2.0 +provided + + + +com.fasterxml.jackson.core +jackson-core +2.9.4 +provided + + +com.fasterxml.jackson.core +jackson-databind +2.9.4 +provided + + +org.osgi +org.osgi.compendium +5.0.0 +provided + diff --git a/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java b/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java new file mode 100644 index 000..a6b5d2e --- /dev/null +++ b/src/main/java/org/apache/sling/testing/clients/query/QueryClient.java @@ -0,0 +1,218 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.query.servlet.QueryServlet; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; + +/** + * Sling client for performing oak queries. + * + * Uses a custom servlet {@link QueryServlet} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * The servlet is exposed under {@value QueryServlet#SERVLET_PATH}. + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16383513#comment-16383513 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on issue #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#issuecomment-369903060 Squashed the commits. The branch should be merge-able. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382665#comment-16382665 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171698381 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 Review comment: Actually, because of depending on `ServletResolverConstants`, the minimum version I can use is `2.16.0`. This version is since Nov 2016. Do you see a problem with it? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382542#comment-16382542 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171674340 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import org.osgi.service.component.annotations.Component; + +import javax.jcr.Session; +import javax.jcr.query.*; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} + +Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try { +String[] columnNames = result.getColumnNames(); +if (columnNames.length > 0) { +
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382365#comment-16382365 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171635590 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; +import org.osgi.service.component.annotations.Component; + +import javax.jcr.Session; +import javax.jcr.query.*; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} + +Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try { +String[] columnNames = result.getColumnNames(); +if (columnNames.length > 0) { +
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382118#comment-16382118 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171585999 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; + +import javax.jcr.Session; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import org.osgi.service.component.annotations.Component; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} +javax.jcr.query.Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try {
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382110#comment-16382110 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171585251 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 Review comment: Looking at the API usage something as low as 2.1.0 should work - at least all the classes/interfaces you referenced are there. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382112#comment-16382112 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171585383 ## File path: src/test/java/org/apache/sling/testing/clients/query/QueryClientTest.java ## @@ -1,43 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.apache.sling.testing.clients.query; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpEntityEnclosingRequest; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpRequestHandler; import org.apache.sling.testing.clients.ClientException; -import org.junit.Ignore; +import org.apache.sling.testing.clients.HttpServerRule; +import org.codehaus.jackson.JsonNode; +import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.net.URI; - -import static org.junit.Assert.*; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; -/** - * Ignored since these cannot be executed without a running instance - */ -@Ignore public class QueryClientTest { -QueryClient client; +private static final Logger LOG = LoggerFactory.getLogger(QueryClientTest.class); + +private static final String QUERY_PATH = "/system/testing/query"; // same as in QueryServlet +private static final String BUNDLE_PATH = "/system/console/bundles/org.apache.sling.testing.clients.query"; +private static final String QUERY_RESPONSE = "{\"total\": 1234,\"time\": 1}"; +private static final String EXPLAIN_RESPONSE = "{\"plan\": \"some plan\",\"time\": 1}"; +private static final String JSON_BUNDLE = "{\n" + +" \"status\": \"Bundle information: 546 bundles in total, 537 bundles active, 8 bundles active fragments, 1 bundle resolved.\",\n" + +" \"s\": [\n" + +"546,\n" + +"537,\n" + +"8,\n" + +"1,\n" + +"0\n" + +" ],\n" + +" \"data\": [\n" + +"{\n" + +" \"id\": 560,\n" + +" \"name\": \"Query servlet for testing\",\n" + +" \"fragment\": false,\n" + +" \"stateRaw\": 32,\n" + +" \"state\": \"Active\",\n" + +" \"version\": \"1.0.0\",\n" + +" \"symbolicName\": \"org.apache.sling.testing.clients.query\",\n" + +" \"category\": \"\"\n" + +"}\n" + +" ]\n" + +"}"; + +@ClassRule +public static HttpServerRule httpServer = new HttpServerRule() { +@Override +protected void registerHandlers() throws IOException { + +// Normal query request +serverBootstrap.registerHandler(QUERY_PATH, new HttpRequestHandler() { +@Override +public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { +List parameters = URLEncodedUtils.parse( +request.getRequestLine().getUri(), Charset.defaultCharset()); + +for (NameValuePair parameter : parameters) { +if (parameter.getName().equals("explain") && !parameter.getValue().equals("false")) { +response.setEntity(new StringEntity(EXPLAIN_RESPONSE)); +return; +} +} + +response.setEntity(new StringEntity(QUERY_RESPONSE)); +} +}); + +//
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16382102#comment-16382102 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171584049 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 +provided + + +javax.servlet +servlet-api +2.4 +provided + + +javax.jcr +jcr +2.0 +provided + + Review comment: Right, well, please add something about this in the pom.xml comment, it's much clearer now :-) This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381984#comment-16381984 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r17144 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -136,30 +128,42 @@ public JsonNode doQuery(final String query, final QueryType type) throws ClientE * @return total results returned by the query * @throws ClientException if the request failed to execute */ -public long doCount(final String query, final QueryType type) throws ClientException { -return doQuery(query, type, false).get("total").getLongValue(); +public long doCount(final String query, final QueryType type) throws ClientException, InterruptedException { +return doQuery(query, type, false, false).get("total").getLongValue(); } -protected JsonNode doQuery(final String query, final QueryType type, final boolean showResults) -throws ClientException { +/** + * Execute a query on the server and return only the number of rows in the result Review comment: Done, np, feedback is always welcome! This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381980#comment-16381980 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171555313 ## File path: src/test/java/org/apache/sling/testing/clients/query/QueryClientTest.java ## @@ -1,43 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.apache.sling.testing.clients.query; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpEntityEnclosingRequest; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpRequestHandler; import org.apache.sling.testing.clients.ClientException; -import org.junit.Ignore; +import org.apache.sling.testing.clients.HttpServerRule; +import org.codehaus.jackson.JsonNode; +import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.net.URI; - -import static org.junit.Assert.*; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; -/** - * Ignored since these cannot be executed without a running instance - */ -@Ignore public class QueryClientTest { -QueryClient client; +private static final Logger LOG = LoggerFactory.getLogger(QueryClientTest.class); + +private static final String QUERY_PATH = "/system/testing/query"; // same as in QueryServlet +private static final String BUNDLE_PATH = "/system/console/bundles/org.apache.sling.testing.clients.query"; +private static final String QUERY_RESPONSE = "{\"total\": 1234,\"time\": 1}"; +private static final String EXPLAIN_RESPONSE = "{\"plan\": \"some plan\",\"time\": 1}"; +private static final String JSON_BUNDLE = "{\n" + +" \"status\": \"Bundle information: 546 bundles in total, 537 bundles active, 8 bundles active fragments, 1 bundle resolved.\",\n" + +" \"s\": [\n" + +"546,\n" + +"537,\n" + +"8,\n" + +"1,\n" + +"0\n" + +" ],\n" + +" \"data\": [\n" + +"{\n" + +" \"id\": 560,\n" + +" \"name\": \"Query servlet for testing\",\n" + +" \"fragment\": false,\n" + +" \"stateRaw\": 32,\n" + +" \"state\": \"Active\",\n" + +" \"version\": \"1.0.0\",\n" + +" \"symbolicName\": \"org.apache.sling.testing.clients.query\",\n" + +" \"category\": \"\"\n" + +"}\n" + +" ]\n" + +"}"; + +@ClassRule +public static HttpServerRule httpServer = new HttpServerRule() { +@Override +protected void registerHandlers() throws IOException { + +// Normal query request +serverBootstrap.registerHandler(QUERY_PATH, new HttpRequestHandler() { +@Override +public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { +List parameters = URLEncodedUtils.parse( +request.getRequestLine().getUri(), Charset.defaultCharset()); + +for (NameValuePair parameter : parameters) { +if (parameter.getName().equals("explain") && !parameter.getValue().equals("false")) { +response.setEntity(new StringEntity(EXPLAIN_RESPONSE)); +return; +} +} + +response.setEntity(new StringEntity(QUERY_RESPONSE)); +} +}); + +//
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381979#comment-16381979 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171554941 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; + +import javax.jcr.Session; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import org.osgi.service.component.annotations.Component; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} +javax.jcr.query.Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381977#comment-16381977 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171554658 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; + +import javax.jcr.Session; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import org.osgi.service.component.annotations.Component; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} +javax.jcr.query.Query q = qm.createQuery(query, type); Review comment: Done. Always glad to have a second pair of eyes, especially when I'm relying too much on the IDE auto code completion... This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381903#comment-16381903 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171540013 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 +provided + + +javax.servlet +servlet-api +2.4 +provided + + +javax.jcr +jcr +2.0 +provided + + Review comment: Now we have two libraries for `jackson` because it changed (package) name. We need the new one because it's the only available in sling, but the clients are still built with the old. We should think to update the clients soon, but that will be a major change since jackson is exposed in the API. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381898#comment-16381898 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171539365 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 Review comment: Any suggestions? Launchpad-9 uses `2.16.2`. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381820#comment-16381820 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520225 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; + +import javax.jcr.Session; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import org.osgi.service.component.annotations.Component; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} +javax.jcr.query.Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try {
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381821#comment-16381821 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520086 ## File path: src/test/java/org/apache/sling/testing/clients/query/QueryClientTest.java ## @@ -1,43 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ package org.apache.sling.testing.clients.query; +import org.apache.http.HttpException; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.utils.URLEncodedUtils; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicHttpEntityEnclosingRequest; +import org.apache.http.protocol.HttpContext; +import org.apache.http.protocol.HttpRequestHandler; import org.apache.sling.testing.clients.ClientException; -import org.junit.Ignore; +import org.apache.sling.testing.clients.HttpServerRule; +import org.codehaus.jackson.JsonNode; +import org.junit.Assert; +import org.junit.ClassRule; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import java.net.URI; - -import static org.junit.Assert.*; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.List; -/** - * Ignored since these cannot be executed without a running instance - */ -@Ignore public class QueryClientTest { -QueryClient client; +private static final Logger LOG = LoggerFactory.getLogger(QueryClientTest.class); + +private static final String QUERY_PATH = "/system/testing/query"; // same as in QueryServlet +private static final String BUNDLE_PATH = "/system/console/bundles/org.apache.sling.testing.clients.query"; +private static final String QUERY_RESPONSE = "{\"total\": 1234,\"time\": 1}"; +private static final String EXPLAIN_RESPONSE = "{\"plan\": \"some plan\",\"time\": 1}"; +private static final String JSON_BUNDLE = "{\n" + +" \"status\": \"Bundle information: 546 bundles in total, 537 bundles active, 8 bundles active fragments, 1 bundle resolved.\",\n" + +" \"s\": [\n" + +"546,\n" + +"537,\n" + +"8,\n" + +"1,\n" + +"0\n" + +" ],\n" + +" \"data\": [\n" + +"{\n" + +" \"id\": 560,\n" + +" \"name\": \"Query servlet for testing\",\n" + +" \"fragment\": false,\n" + +" \"stateRaw\": 32,\n" + +" \"state\": \"Active\",\n" + +" \"version\": \"1.0.0\",\n" + +" \"symbolicName\": \"org.apache.sling.testing.clients.query\",\n" + +" \"category\": \"\"\n" + +"}\n" + +" ]\n" + +"}"; + +@ClassRule +public static HttpServerRule httpServer = new HttpServerRule() { +@Override +protected void registerHandlers() throws IOException { + +// Normal query request +serverBootstrap.registerHandler(QUERY_PATH, new HttpRequestHandler() { +@Override +public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { +List parameters = URLEncodedUtils.parse( +request.getRequestLine().getUri(), Charset.defaultCharset()); + +for (NameValuePair parameter : parameters) { +if (parameter.getName().equals("explain") && !parameter.getValue().equals("false")) { +response.setEntity(new StringEntity(EXPLAIN_RESPONSE)); +return; +} +} + +response.setEntity(new StringEntity(QUERY_RESPONSE)); +} +}); + +//
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381818#comment-16381818 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520712 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 Review comment: Can we use a lower version of the API? I don't think we need the latest and greatest. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381822#comment-16381822 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520306 ## File path: src/main/java/org/apache/sling/testing/clients/query/servlet/QueryServlet.java ## @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query.servlet; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.api.SlingHttpServletResponse; +import org.apache.sling.api.servlets.SlingSafeMethodsServlet; + +import javax.jcr.Session; +import javax.jcr.query.QueryManager; +import javax.jcr.query.QueryResult; +import javax.jcr.query.Row; +import javax.jcr.query.RowIterator; +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import java.io.IOException; +import java.util.Date; + +import org.osgi.service.component.annotations.Component; + +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_METHODS; +import static org.apache.sling.api.servlets.ServletResolverConstants.SLING_SERVLET_PATHS; + +@Component( +name = QueryServlet.SERVLET_NAME, +service = {Servlet.class}, +property = { +SLING_SERVLET_PATHS + "=" + QueryServlet.SERVLET_PATH, +SLING_SERVLET_METHODS + "=GET" +} +) +public class QueryServlet extends SlingSafeMethodsServlet { +private static final long serialVersionUID = 1L; + +public static final String SERVLET_PATH = "/system/testing/query"; +public static final String SERVLET_NAME = "Sling Testing Clients Query Servlet"; + +@Override +protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) +throws ServletException, IOException { + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +try { +final QueryManager qm = request.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = request.getParameter("query"); +String type = request.getParameter("type"); + +// default for showResults is true, unless parameter is matching exactly "false" +boolean showResults = !("false".equalsIgnoreCase(request.getParameter("showresults"))); +// default for explainQuery is false, unless parameter is present and is not matching "false" +String explainParam = request.getParameter("explain"); +boolean explainQuery = (explainParam != null) && !("false".equalsIgnoreCase(explainParam)); + +boolean tidy = false; +for (String selector : request.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { +response.sendError(400, "Parameters query and type are required"); // invalid request +return; +} + +// prepare +if (explainQuery) { +query = "explain " + query; +} +javax.jcr.query.Query q = qm.createQuery(query, type); Review comment: Should be an import (sorry for nitpicking) This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at:
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381823#comment-16381823 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520608 ## File path: pom.xml ## @@ -163,5 +163,44 @@ tests test + + + +org.apache.sling +org.apache.sling.api +2.16.4 +provided + + +javax.servlet +servlet-api +2.4 +provided + + +javax.jcr +jcr +2.0 +provided + + Review comment: I don't really understand this comment, sorry :-) This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16381819#comment-16381819 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171520839 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -136,30 +128,42 @@ public JsonNode doQuery(final String query, final QueryType type) throws ClientE * @return total results returned by the query * @throws ClientException if the request failed to execute */ -public long doCount(final String query, final QueryType type) throws ClientException { -return doQuery(query, type, false).get("total").getLongValue(); +public long doCount(final String query, final QueryType type) throws ClientException, InterruptedException { +return doQuery(query, type, false, false).get("total").getLongValue(); } -protected JsonNode doQuery(final String query, final QueryType type, final boolean showResults) -throws ClientException { +/** + * Execute a query on the server and return only the number of rows in the result Review comment: /s/return/returns/ (Again, sorry for nitpicking but since we have something to change...) This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380766#comment-16380766 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171302353 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380762#comment-16380762 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171302353 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380592#comment-16380592 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301761 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; Review comment: Changed to that for the service xml This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380618#comment-16380618 ] Valentin Olteanu commented on SLING-7509: - Thanks [~rombert] and [~andrei.dulvac] for reviewing! I've adapted the patch according to your comments, could you please re-evaluate? And can we stop [~githubbot] creating a jira comment for every PR comment? They are very verbose.. > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380610#comment-16380610 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171302353 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380596#comment-16380596 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301852 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; Review comment: Done This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380607#comment-16380607 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301960 ## File path: src/main/java/org/apache/sling/testing/clients/query/package-info.java ## @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * OSGI testing tools. + */ +@Version("1.0.0") Review comment: Done This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380602#comment-16380602 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301895 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380606#comment-16380606 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301936 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380591#comment-16380591 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301568 ## File path: src/main/java/org/apache/sling/testing/clients/query/package-info.java ## @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * OSGI testing tools. Review comment: Got me :) copy-paste old habits... This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380585#comment-16380585 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301293 ## File path: src/test/java/org/apache/sling/testing/clients/query/QueryClientTest.java ## @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.sling.testing.clients.ClientException; +import org.junit.Ignore; +import org.junit.Test; + +import java.net.URI; + +import static org.junit.Assert.*; + +/** + * Ignored since these cannot be executed without a running instance + */ +@Ignore Review comment: Made tests to work on a server mock also. They are not ignored anymore This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380587#comment-16380587 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301465 ## File path: src/main/resources/org/apache/sling/testing/clients/query/testQuery.json.jsp ## @@ -0,0 +1,136 @@ +<%-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%><%@ page session="false" +%><%@ page import=" + java.io.PrintWriter, + java.util.Date, + javax.jcr.Node, + javax.jcr.NodeIterator, + javax.jcr.RepositoryException, + javax.jcr.Session, + javax.jcr.query.Query, + javax.jcr.query.QueryManager, + javax.jcr.query.QueryResult, + javax.jcr.query.Row, + javax.jcr.query.RowIterator, + org.apache.jackrabbit.value.StringValue" +%><%@ taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0; +%><% + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +final PrintWriter pw = response.getWriter(); + +try { +final QueryManager qm = slingRequest.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = slingRequest.getParameter("query"); +String type = slingRequest.getParameter("type"); +boolean showResults = !("false".equalsIgnoreCase(slingRequest.getParameter("showresults"))); + +boolean tidy = false; +for (String selector : slingRequest.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { + response.sendError(400, "Parameters query and type are required"); // invalid request + return; +} + +// prepare +javax.jcr.query.Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try { +String[] columnNames = result.getColumnNames(); +if (columnNames.length > 0) { +String firstColumnName = columnNames[0]; +int firstDot = firstColumnName.indexOf('.'); +if (firstDot > 0) { +firstSelector = firstColumnName.substring(0, firstDot); +} +} +} catch (Exception e) { +log.warn("Could not get selector name of the first column", e); +} +} + +// start the response json object +pw.println("{"); Review comment: Switched to `com.fasterxml.jackson` in `QueryServlet` This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in >
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16380584#comment-16380584 ] ASF GitHub Bot commented on SLING-7509: --- volteanu commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r171301148 ## File path: src/main/resources/org/apache/sling/testing/clients/query/testQuery.json.jsp ## @@ -0,0 +1,136 @@ +<%-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%><%@ page session="false" +%><%@ page import=" + java.io.PrintWriter, + java.util.Date, + javax.jcr.Node, + javax.jcr.NodeIterator, + javax.jcr.RepositoryException, + javax.jcr.Session, + javax.jcr.query.Query, + javax.jcr.query.QueryManager, + javax.jcr.query.QueryResult, + javax.jcr.query.Row, + javax.jcr.query.RowIterator, + org.apache.jackrabbit.value.StringValue" Review comment: jsp was replaced by `QueryServlet.java` which imports only the required classes. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378704#comment-16378704 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170932869 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378705#comment-16378705 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170932985 ## File path: src/main/java/org/apache/sling/testing/clients/query/package-info.java ## @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/** + * OSGI testing tools. + */ +@Version("1.0.0") Review comment: Can we make the version 0.1.0? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378707#comment-16378707 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170932073 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; Review comment: Can we make that be more clear? "Sling Testing Clients Query Servlet"? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378706#comment-16378706 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170947383 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378702#comment-16378702 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170932557 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378703#comment-16378703 ] ASF GitHub Bot commented on SLING-7509: --- dulvac commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170936645 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; +private static final String RESOURCE_TYPE = "testQuery"; +private static final String COMPONENT_PATH = "apps/" + RESOURCE_TYPE; +private static final String JSP_PATH = COMPONENT_PATH + "/" + RESOURCE_TYPE + ".json.jsp"; +private static final String QUERY_NODE = "/content/testquery"; +private static final String QUERY_PATH = QUERY_NODE + ".json"; + +/** + * Constructor used by adaptTo + * @param http underlying HttpClient + * @param config config state + * @throws ClientException if the client cannot be created + */ +public QueryClient(CloseableHttpClient http, SlingClientConfig config) throws ClientException { +super(http, config); +} + +/** + * Convenience constructor + * @param url host url + * @param user username + * @param password password + * @throws
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378667#comment-16378667 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170940653 ## File path: src/main/resources/org/apache/sling/testing/clients/query/testQuery.json.jsp ## @@ -0,0 +1,136 @@ +<%-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%><%@ page session="false" +%><%@ page import=" + java.io.PrintWriter, + java.util.Date, + javax.jcr.Node, + javax.jcr.NodeIterator, + javax.jcr.RepositoryException, + javax.jcr.Session, + javax.jcr.query.Query, + javax.jcr.query.QueryManager, + javax.jcr.query.QueryResult, + javax.jcr.query.Row, + javax.jcr.query.RowIterator, + org.apache.jackrabbit.value.StringValue" Review comment: This import seems unused This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378669#comment-16378669 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170941108 ## File path: src/main/resources/org/apache/sling/testing/clients/query/testQuery.json.jsp ## @@ -0,0 +1,136 @@ +<%-- +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%><%@ page session="false" +%><%@ page import=" + java.io.PrintWriter, + java.util.Date, + javax.jcr.Node, + javax.jcr.NodeIterator, + javax.jcr.RepositoryException, + javax.jcr.Session, + javax.jcr.query.Query, + javax.jcr.query.QueryManager, + javax.jcr.query.QueryResult, + javax.jcr.query.Row, + javax.jcr.query.RowIterator, + org.apache.jackrabbit.value.StringValue" +%><%@ taglib prefix="sling" uri="http://sling.apache.org/taglibs/sling/1.0; +%><% + +response.setContentType("application/json"); +response.setCharacterEncoding("UTF-8"); + +final PrintWriter pw = response.getWriter(); + +try { +final QueryManager qm = slingRequest.getResourceResolver().adaptTo(Session.class) +.getWorkspace().getQueryManager(); + +long before = 0; +long after = 0; +long total = 0; + +String query = slingRequest.getParameter("query"); +String type = slingRequest.getParameter("type"); +boolean showResults = !("false".equalsIgnoreCase(slingRequest.getParameter("showresults"))); + +boolean tidy = false; +for (String selector : slingRequest.getRequestPathInfo().getSelectors()) { +if ("tidy".equals(selector)) { +tidy = true; +} +} + +if ((query == null) || query.equals("") || (type == null) || type.equals("")) { + response.sendError(400, "Parameters query and type are required"); // invalid request + return; +} + +// prepare +javax.jcr.query.Query q = qm.createQuery(query, type); + +// execute +before = new Date().getTime(); +QueryResult result = q.execute(); +after = new Date().getTime(); + +// collect results +String firstSelector = null; +if (result.getSelectorNames().length > 1) { +firstSelector = result.getSelectorNames()[0]; +try { +String[] columnNames = result.getColumnNames(); +if (columnNames.length > 0) { +String firstColumnName = columnNames[0]; +int firstDot = firstColumnName.indexOf('.'); +if (firstDot > 0) { +firstSelector = firstColumnName.substring(0, firstDot); +} +} +} catch (Exception e) { +log.warn("Could not get selector name of the first column", e); +} +} + +// start the response json object +pw.println("{"); Review comment: Why don't we use a JSON library? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in >
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378671#comment-16378671 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170940948 ## File path: src/test/java/org/apache/sling/testing/clients/query/QueryClientTest.java ## @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.sling.testing.clients.ClientException; +import org.junit.Ignore; +import org.junit.Test; + +import java.net.URI; + +import static org.junit.Assert.*; + +/** + * Ignored since these cannot be executed without a running instance + */ +@Ignore Review comment: Either provide a testing setup for this or remove them. This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16378670#comment-16378670 ] ASF GitHub Bot commented on SLING-7509: --- rombert commented on a change in pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5#discussion_r170941464 ## File path: src/main/java/org/apache/sling/testing/clients/query/QueryClient.java ## @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package org.apache.sling.testing.clients.query; + +import org.apache.http.NameValuePair; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.sling.testing.clients.ClientException; +import org.apache.sling.testing.clients.SlingClient; +import org.apache.sling.testing.clients.SlingClientConfig; +import org.apache.sling.testing.clients.SlingHttpResponse; +import org.apache.sling.testing.clients.osgi.OsgiConsoleClient; +import org.apache.sling.testing.clients.util.JsonUtils; +import org.apache.sling.testing.clients.util.URLParameterBuilder; +import org.codehaus.jackson.JsonNode; +import org.ops4j.pax.tinybundles.core.TinyBundles; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.nio.file.Files; +import java.util.List; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; +import static org.apache.http.HttpStatus.SC_NOT_FOUND; +import static org.apache.http.HttpStatus.SC_OK; +import static org.apache.sling.testing.clients.util.ResourceUtil.getResourceAsStream; + +/** + * Sling client for performing oak queries. + * + * Uses a custom query servlet {@code testQuery.json.jsp} to execute the query on the server + * and return the results as a json. If the servlet is not yet present, it automatically + * installs it and creates the corresponding nodes + * + * Paths created in jcr: + * - {@value JSP_PATH}, created by the bundle + * - {@value QUERY_NODE}, with {@code resourceType}={@value RESOURCE_TYPE} + * + * + * The servlet is not automatically uninstalled to avoid too much noise on the instance. + * The caller should take care of it, if needed, by calling {@link #uninstallServlet()} + */ +public class QueryClient extends SlingClient { + +/** + * Query types, as defined in {@code org.apache.jackrabbit.oak.query.QueryEngineImpl} + */ +public enum QueryType { +SQL2("JCR-SQL2"), +SQL("sql"), +XPATH("xpath"), +JQOM("JCR-JQOM"); + +private final String name; + +QueryType(String name) { +this.name = name; +} + +@Override +public String toString() { +return name; +} +} + +private static final Logger LOG = LoggerFactory.getLogger(QueryClient.class); + +private static final String BUNDLE_BSN = "org.apache.sling.testing.clients.query"; +private static final String BUNDLE_NAME = "Query servlet for testing"; +private static final String BUNDLE_VERSION = "1.0.0"; +private static final String BUNDLE_FILE = "testquery.bundle."; + +private static final String JSP_FILE = "/org/apache/sling/testing/clients/query/testQuery.json.jsp"; Review comment: I think getClass().getResourceAsStream(...) would allow for a more compact name and less package names duplication This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16372798#comment-16372798 ] Valentin Olteanu commented on SLING-7509: - I see, the attic was not moved to github. The part that I could use from it is the way the json is created ("// iterate through the result set and build the "json result""). Other than that it doesn't really fit my testing needs. > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16372784#comment-16372784 ] Bertrand Delacretaz commented on SLING-7509: The {{JsonQueryServlet}} is in the attic at https://svn.apache.org/repos/asf/sling/attic/bundles-servlets-compat/ See https://issues.apache.org/jira/browse/SLING-2226 for why it was deprecated. > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16372769#comment-16372769 ] Valentin Olteanu commented on SLING-7509: - Thanks [~olli] for the pointer. My requirement is that the tests should work on the out-of-the-box launchpad and any application built with sling. FWICT, {{org.apache.sling.servlets.compat}} is not included in the launchpad anymore... BTW, I was looking for the {{JsonQueryServlet}} to have some inspiration and could not find it in github, do you have any idea in which repo is it now? > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > The solution proposed in > [https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5] > * installs a custom query servlet > * runs the query in any of the supported format > * returns results as json -- This message was sent by Atlassian JIRA (v7.6.3#76005)
[jira] [Commented] (SLING-7509) Add QueryClient
[ https://issues.apache.org/jira/browse/SLING-7509?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16371978#comment-16371978 ] ASF GitHub Bot commented on SLING-7509: --- volteanu opened a new pull request #5: SLING-7509 - Add QueryClient URL: https://github.com/apache/sling-org-apache-sling-testing-clients/pull/5 @dulvac @rombert could please review the new client? I'm not sure about the paths where content is created, should we use a `test` _namespace_ that can be easily identified and deleted? This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Add QueryClient > --- > > Key: SLING-7509 > URL: https://issues.apache.org/jira/browse/SLING-7509 > Project: Sling > Issue Type: New Feature > Components: Apache Sling Testing Clients >Reporter: Valentin Olteanu >Priority: Major > > Currently, there is no way to run queries in sling using the clients. This is > needed in several tests to search content and assert the effects of a feature. > > -- This message was sent by Atlassian JIRA (v7.6.3#76005)