Aklakan commented on code in PR #3027:
URL: https://github.com/apache/jena/pull/3027#discussion_r2058651796


##########
jena-fuseki2/jena-fuseki-mod-geosparql/src/test/java/org/apache/jena/fuseki/mod/geosparql/TestFMod_SpatialIndexer.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * 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.jena.fuseki.mod.geosparql;
+
+import java.io.IOException;
+import java.time.Duration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+
+import org.apache.jena.atlas.iterator.Iter;
+import org.apache.jena.fuseki.main.FusekiServer;
+import org.apache.jena.fuseki.main.cmds.FusekiMain;
+import org.apache.jena.geosparql.spatial.SpatialIndex;
+import org.apache.jena.geosparql.spatial.SpatialIndexException;
+import org.apache.jena.geosparql.spatial.index.v2.GeometryGenerator;
+import 
org.apache.jena.geosparql.spatial.index.v2.GeometryGenerator.GeometryType;
+import org.apache.jena.geosparql.spatial.index.v2.SpatialIndexUtils;
+import org.apache.jena.graph.Node;
+import org.apache.jena.graph.NodeFactory;
+import org.apache.jena.sparql.core.DatasetGraph;
+import org.apache.jena.sparql.core.DatasetGraphFactory;
+import org.apache.jena.sparql.core.Quad;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.locationtech.jts.geom.Envelope;
+import org.openqa.selenium.By;
+import org.openqa.selenium.JavascriptExecutor;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.support.ui.WebDriverWait;
+
+import io.github.bonigarcia.wdm.WebDriverManager;
+
+public class TestFMod_SpatialIndexer {
+    private WebDriver driver;
+    private JavascriptExecutor js;
+
+    private static Envelope queryEnvelope = new Envelope(-180, 180, -90, 90);
+    private DatasetGraph dsg;
+    private SpatialIndex spatialIndex;
+    private Node graphName1 = 
NodeFactory.createURI("http://www.example.org/graph1";);
+
+    @Before
+    public void setUp() throws IOException, SpatialIndexException {
+        dsg = DatasetGraphFactory.create();
+        setupTestData(dsg);
+
+        spatialIndex = SpatialIndexUtils.buildSpatialIndex(dsg);
+
+        String[] argv = new String[] { "--empty" };
+        FusekiServer server = FusekiMain.builder(argv)
+            .add("test", dsg)
+            .build();
+        server.start();
+        int port = server.getPort();
+        String serverURL = "http://localhost:"; + port + "/";
+        String siteUrl = serverURL + "test/spatial";
+
+        ChromeOptions options = new ChromeOptions();
+        options.addArguments("--headless=new"); // use "new" headless mode 
(better support)
+        options.addArguments("--no-sandbox");
+        options.addArguments("--disable-dev-shm-usage");
+
+        WebDriverManager.chromedriver().setup(); // Automatically downloads 
and sets path
+        driver = new ChromeDriver(options);
+        driver.get(siteUrl);
+        js = (JavascriptExecutor) driver;
+    }
+
+    private void setupTestData(DatasetGraph dsg) {
+        // Fill the graph with a few geometries; spatial index construction 
will derive the SRS from them.
+        Envelope envelope = new Envelope(-175, 175, -85, 85);
+
+        Map<GeometryType, Number> conf = new HashMap<>();
+        conf.put(GeometryType.POINT, 1);
+
+        // Generate geometries into the default graph and a named graph
+        GeometryGenerator.generateGraph(dsg.getDefaultGraph(), envelope, conf);
+
+        conf.put(GeometryType.POLYGON, 1);
+        GeometryGenerator.generateGraph(dsg.getGraph(graphName1), envelope, 
conf);
+    }
+
+    @Test
+    @Ignore // Ignored for new because this test requires a local Chrome 
browser.
+    public void testIndexAndCleanButtons() {
+        // Index the test data (default graph and 1 named graph).
+        WebElement button = driver.findElement(By.id("apply-action"));
+        button.click();
+        awaitEvent();
+        Assert.assertEquals(1, spatialIndex.query(queryEnvelope, 
Quad.defaultGraphIRI).size());
+        Assert.assertEquals(2, spatialIndex.query(queryEnvelope, 
graphName1).size());
+        clearLastEvent();
+
+        // Remove the named graph and update the index.
+        dsg.removeGraph(graphName1);
+        WebElement cleanButton = driver.findElement(By.id("clean-action"));
+        cleanButton.click();
+        awaitEvent();
+        try (Stream<?> s = Iter.asStream(dsg.listGraphNodes())) {
+            long actualNamedGraphCount = s.count();
+            Assert.assertEquals(0, actualNamedGraphCount);

Review Comment:
   Whoops, this should test whether the spatial index (not dsg) only has one 
graph.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscr...@jena.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@jena.apache.org
For additional commands, e-mail: pr-h...@jena.apache.org

Reply via email to