You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/08/23 20:43:59 UTC
svn commit: r1805955 - in /sling/trunk/launchpad:
integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/
test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/
Author: rombert
Date: Wed Aug 23 20:43:59 2017
New Revision: 1805955
URL: http://svn.apache.org/viewvc?rev=1805955&view=rev
Log:
SLING-7081 - Restore FullTextIndexingTest
Restore the test and update it to no longer use the QueryServlet
Added:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/FullTextQueryServlet.java
Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java?rev=1805955&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java (added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/indexing/FullTextIndexingTest.java Wed Aug 23 20:43:59 2017
@@ -0,0 +1,112 @@
+/*
+ * 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.launchpad.webapp.integrationtest.indexing;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.InputStream;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.jackrabbit.JcrConstants;
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.testing.tools.retry.RetryLoop;
+import org.apache.sling.testing.tools.retry.RetryLoop.Condition;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+/**
+ * The <tt>FullTextIndexingTest</tt> verifies that a PDF file which is uploaded will have its contents indexed and
+ * available for full-text searches, in several different paths.
+ *
+ */
+@RunWith(Parameterized.class)
+public class FullTextIndexingTest {
+
+ private final HttpTest H = new HttpTest();
+
+ private final String uploadPath;
+ private final String fileName;
+ private final String expectedText;
+
+ @Parameters(name="{index} - {0}")
+ public static Collection<Object[]> data() {
+ final List<Object []> result = new ArrayList<Object []>();
+ result.add(new Object[] { "lorem-ipsum.pdf", "Excepteur", "/tmp/test-" });
+ result.add(new Object[] { "another.pdf", "some text that we will search for", "/var/test-" });
+ result.add(new Object[] { "french.pdf", "un autre PDF pour le test fulltext", "/libs/test-" });
+ return result;
+ }
+
+ public FullTextIndexingTest(String filename, String expectedText, String uploadPathPrefix) {
+ this.fileName = filename;
+ this.expectedText = expectedText;
+ this.uploadPath = uploadPathPrefix + getClass().getSimpleName();
+ }
+
+ @Test
+ public void testUploadedPdfIsIndexed() throws Exception {
+
+ final String queryUrl = HttpTest.WEBDAV_BASE_URL + "/testing/fullTextQuery?q=" + URLEncoder.encode(expectedText, "UTF-8");
+
+ final Condition c = new Condition() {
+
+ public boolean isTrue() throws Exception {
+ String result = H.getContent(queryUrl, HttpTest.CONTENT_TYPE_PLAIN).trim();
+ return result.equals(uploadPath + "/" + fileName + "/" + JcrConstants.JCR_CONTENT);
+ }
+
+ public String getDescription() {
+ return "A document containing '" + expectedText + "' is found under " + uploadPath;
+ }
+ };
+
+ assertFalse("Expecting search to return nothing before upload", c.isTrue());
+
+ String localPath = "/integration-test/indexing/" + fileName;
+ InputStream resourceToUpload = getClass().getResourceAsStream(localPath);
+ if (resourceToUpload == null)
+ throw new IllegalArgumentException("No resource to upload found at " + localPath);
+
+ H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, uploadPath);
+ final int status = H.getTestClient().upload(HttpTest.WEBDAV_BASE_URL + uploadPath + "/" + fileName, resourceToUpload);
+ assertEquals("Upload status code", 201, status);
+
+ // Increased the timeout to 45 seconds to avoid failures with Oak - indexes not ready??
+ new RetryLoop(c, 45, 50);
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ H.setUp();
+ H.getTestClient().delete(HttpTest.WEBDAV_BASE_URL + uploadPath);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ H.getTestClient().delete(HttpTest.WEBDAV_BASE_URL + uploadPath);
+ H.tearDown();
+ }
+}
\ No newline at end of file
Added: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/FullTextQueryServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/FullTextQueryServlet.java?rev=1805955&view=auto
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/FullTextQueryServlet.java (added)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/FullTextQueryServlet.java Wed Aug 23 20:43:59 2017
@@ -0,0 +1,88 @@
+/*
+ * 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.launchpad.testservices.jcr;
+
+import java.io.IOException;
+
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Properties;
+import org.apache.felix.scr.annotations.Property;
+import org.apache.felix.scr.annotations.Service;
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
+
+/** Servlet used to test HtmlResponse escaping */
+@Component(immediate=true, metatype=false)
+@Service(value=javax.servlet.Servlet.class)
+@Properties({
+ @Property(name="service.description", value="FullText Query Servlet"),
+ @Property(name="service.vendor", value="The Apache Software Foundation"),
+ @Property(name="sling.servlet.paths", value={
+ "/testing/fullTextQuery"
+ })
+})
+/**
+ * Outputs paths of nodes matching the specified full-text search
+ *
+ * <p>The paths are written in text format, one per line.</p>
+ *
+ */
+public class FullTextQueryServlet extends SlingSafeMethodsServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
+ throws ServletException, IOException {
+
+ response.setContentType("text/plain");
+
+ String queryText = request.getParameter("q");
+ if ( queryText == null || queryText.isEmpty() ) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ response.getWriter().write("Missing mandatory 'q' parameter");
+ return;
+ }
+
+ Session session = request.getResourceResolver().adaptTo(Session.class);
+
+ try {
+ Query query = session.getWorkspace().getQueryManager().createQuery("SELECT * FROM [nt:base] AS s WHERE CONTAINS(s.*, $queryText)", Query.JCR_SQL2);
+ query.bindValue("queryText", session.getValueFactory().createValue(queryText));
+ QueryResult result = query.execute();
+ NodeIterator iterator = result.getNodes();
+ while( iterator.hasNext() ) {
+ response.getWriter().println(iterator.nextNode().getPath());
+ }
+ } catch (RepositoryException e) {
+ throw new ServletException(e);
+ }
+
+ }
+
+}