This is an automated email from the ASF dual-hosted git repository.

jin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


The following commit(s) were added to refs/heads/master by this push:
     new 1c577de9b chore(api): support ignore graphspaces segment in url (#2612)
1c577de9b is described below

commit 1c577de9baf22efe773354dd861a5bd16476c638
Author: V_Galaxy <[email protected]>
AuthorDate: Tue Aug 13 20:56:53 2024 +0800

    chore(api): support ignore graphspaces segment in url (#2612)
    
    For forwards compatibility with the "graphspace" mode
    
    ---------
    
    Co-authored-by: imbajin <[email protected]>
---
 .../hugegraph/api/filter/GraphSpaceFilter.java     | 126 +++++++++++++++++++++
 .../org/apache/hugegraph/config/ServerOptions.java |   8 ++
 .../assembly/static/conf/rest-server.properties    |   1 +
 .../src/assembly/travis/run-api-test.sh            |   1 +
 .../org/apache/hugegraph/api/ApiTestSuite.java     |   4 +-
 .../java/org/apache/hugegraph/api/BaseApiTest.java |   5 +-
 .../GraphSpaceApiTestSuite.java}                   |  33 ++----
 .../GraphSpaceEdgeApiTest.java}                    |  39 ++-----
 .../GraphSpaceEdgeLabelApiTest.java}               |  39 ++-----
 .../GraphSpaceIndexLabelApiTest.java}              |  39 ++-----
 .../GraphSpacePropertyKeyApiTest.java}             |  39 ++-----
 .../GraphSpaceVertexApiTest.java}                  |  39 ++-----
 .../GraphSpaceVertexLabelApiTest.java}             |  39 ++-----
 13 files changed, 222 insertions(+), 190 deletions(-)

diff --git 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/GraphSpaceFilter.java
 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/GraphSpaceFilter.java
new file mode 100644
index 000000000..97e0cec93
--- /dev/null
+++ 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/filter/GraphSpaceFilter.java
@@ -0,0 +1,126 @@
+/*
+ * 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.hugegraph.api.filter;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.stream.Collectors;
+
+import org.apache.hugegraph.config.HugeConfig;
+import org.apache.hugegraph.config.ServerOptions;
+import org.apache.hugegraph.util.Log;
+import org.slf4j.Logger;
+
+import jakarta.inject.Singleton;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.UriBuilder;
+import jakarta.ws.rs.ext.Provider;
+
+/**
+ * TODO: Change the adaptor logic to keep compatibility with the 
non-"GraphSpace" version after we
+ * support "GraphSpace"
+ */
+@Provider
+@Singleton
+@PreMatching
+public class GraphSpaceFilter implements ContainerRequestFilter {
+
+    private static final Logger LOG = Log.logger(GraphSpaceFilter.class);
+
+    private static final String GRAPHSPACES_PATH = "graphspaces/";
+
+    @Context
+    private jakarta.inject.Provider<HugeConfig> configProvider;
+
+    /**
+     * Filters incoming HTTP requests to modify the request URI if it matches 
certain criteria.
+     * <p>
+     * This filter checks if the request URI starts with the {@link 
#GRAPHSPACES_PATH} path
+     * segment. If it does,
+     * the filter removes the {@link #GRAPHSPACES_PATH} segment along with the 
following segment
+     * and then reconstructs
+     * the remaining URI. The modified URI is set back into the request 
context. This is useful for
+     * supporting legacy paths or adapting to new API structures.
+     * </p>
+     *
+     * <p><b>Example:</b></p>
+     * <pre>
+     * URI baseUri = URI.create("http://localhost:8080/";);
+     * URI requestUri = 
URI.create("http://localhost:8080/graphspaces/DEFAULT/graphs";);
+     *
+     * // Before filter:
+     * context.getUriInfo().getRequestUri();  // returns 
http://localhost:8080/graphspaces/DEFAULT/graphs
+     *
+     * // After filter:
+     * context.getUriInfo().getRequestUri();  // returns 
http://localhost:8080/graphs
+     * </pre>
+     *
+     * @param context The {@link ContainerRequestContext} which provides 
access to the request
+     *                details.
+     * @throws IOException If an input or output exception occurs.
+     */
+    @Override
+    public void filter(ContainerRequestContext context) throws IOException {
+        HugeConfig config = configProvider.get();
+        if (!config.get(ServerOptions.REST_SERVER_ENABLE_GRAPHSPACES_FILTER)) {
+            return;
+        }
+
+        // Step 1: Get relativePath
+        URI baseUri = context.getUriInfo().getBaseUri();
+        URI requestUri = context.getUriInfo().getRequestUri();
+        URI relativePath = baseUri.relativize(requestUri);
+
+        String relativePathStr = relativePath.getPath();
+        // TODO: remember remove the logic after we support "GraphSpace"
+        if (!relativePathStr.startsWith(GRAPHSPACES_PATH)) {
+            return;
+        }
+
+        // Step 2: Extract the next substring after {@link #GRAPHSPACES_PATH}
+        String[] parts = relativePathStr.split("/");
+        if (parts.length <= 1) {
+            return;
+        }
+
+        String ignoredPart = Arrays.stream(parts)
+                                   .limit(2) // Ignore the first two segments
+                                   .collect(Collectors.joining("/"));
+
+        // Reconstruct the remaining path
+        String newPath = Arrays.stream(parts)
+                               .skip(2) // Skip the first two segments
+                               .collect(Collectors.joining("/"));
+
+        // Step 3: Modify RequestUri and log the ignored part
+        URI newUri = UriBuilder.fromUri(baseUri)
+                               .path(newPath)
+                               .replaceQuery(requestUri.getRawQuery())
+                               .build();
+        context.setRequestUri(newUri);
+
+        // Log the ignored part
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("Ignored graphspaces segment: {}", ignoredPart);
+        }
+    }
+}
diff --git 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java
 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java
index 63da169c9..084e9a338 100644
--- 
a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java
+++ 
b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/config/ServerOptions.java
@@ -47,6 +47,14 @@ public class ServerOptions extends OptionHolder {
                     "http://127.0.0.1:8080";
             );
 
+    public static final ConfigOption<Boolean> 
REST_SERVER_ENABLE_GRAPHSPACES_FILTER =
+            new ConfigOption<>(
+                    "restserver.enable_graphspaces_filter",
+                    "Whether to enable graphspaces url filter.",
+                    disallowEmpty(),
+                    false
+            );
+
     public static final ConfigOption<String> SERVER_ID =
             new ConfigOption<>(
                     "server.id",
diff --git 
a/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties
 
b/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties
index 507867380..f89966e6c 100644
--- 
a/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties
+++ 
b/hugegraph-server/hugegraph-dist/src/assembly/static/conf/rest-server.properties
@@ -1,6 +1,7 @@
 # bind url
 # could use '0.0.0.0' or specified (real)IP to expose external network access
 restserver.url=http://127.0.0.1:8080
+#restserver.enable_graphspaces_filter=false
 # gremlin server url, need to be consistent with host and port in 
gremlin-server.yaml
 #gremlinserver.url=http://127.0.0.1:8182
 
diff --git 
a/hugegraph-server/hugegraph-dist/src/assembly/travis/run-api-test.sh 
b/hugegraph-server/hugegraph-dist/src/assembly/travis/run-api-test.sh
index 8008f39cd..bd821712d 100755
--- a/hugegraph-server/hugegraph-dist/src/assembly/travis/run-api-test.sh
+++ b/hugegraph-server/hugegraph-dist/src/assembly/travis/run-api-test.sh
@@ -41,6 +41,7 @@ fi
 # config rest-server
 sed -i 
's/#auth.authenticator=/auth.authenticator=org.apache.hugegraph.auth.StandardAuthenticator/'
 $REST_SERVER_CONF
 sed -i 's/#auth.admin_token=/auth.admin_token=pa/' $REST_SERVER_CONF
+sed -i 
's/#restserver.enable_graphspaces_filter=false/restserver.enable_graphspaces_filter=true/'
 $REST_SERVER_CONF
 
 # config hugegraph.properties
 sed -i 
's/gremlin.graph=.*/gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy/'
 $CONF
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
index 11d3e6409..cca27a78c 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
@@ -17,6 +17,7 @@
 
 package org.apache.hugegraph.api;
 
+import org.apache.hugegraph.api.graphspaces.GraphSpaceApiTestSuite;
 import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
 import org.apache.hugegraph.dist.RegisterUtil;
 import org.junit.BeforeClass;
@@ -40,7 +41,8 @@ import org.junit.runners.Suite;
         ProjectApiTest.class,
         TraversersApiTestSuite.class,
         CypherApiTest.class,
-        ArthasApiTest.class
+        ArthasApiTest.class,
+        GraphSpaceApiTestSuite.class
 })
 public class ApiTestSuite {
 
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
index 4b6c0ed7f..72821ecb1 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/BaseApiTest.java
@@ -55,7 +55,7 @@ import jakarta.ws.rs.core.Response;
 
 public class BaseApiTest {
 
-    private static final String BASE_URL = "http://127.0.0.1:8080";;
+    protected static final String BASE_URL = "http://127.0.0.1:8080";;
     private static final String GRAPH = "hugegraph";
     private static final String USERNAME = "admin";
     private static final String PASSWORD = "pa";
@@ -71,7 +71,7 @@ public class BaseApiTest {
 
     protected static final String TRAVERSERS_API = URL_PREFIX + "/traversers";
 
-    private static RestClient client;
+    protected static RestClient client;
 
     private static final ObjectMapper MAPPER = new ObjectMapper();
 
@@ -84,6 +84,7 @@ public class BaseApiTest {
     @AfterClass
     public static void clear() throws Exception {
         client.close();
+        client = null;
     }
 
     @After
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceApiTestSuite.java
similarity index 53%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceApiTestSuite.java
index 11d3e6409..d5090058b 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceApiTestSuite.java
@@ -15,37 +15,20 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
-import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
 
 @RunWith(Suite.class)
 @Suite.SuiteClasses({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
+        GraphSpacePropertyKeyApiTest.class,
+        GraphSpaceVertexLabelApiTest.class,
+        GraphSpaceEdgeLabelApiTest.class,
+        GraphSpaceIndexLabelApiTest.class,
+        GraphSpaceEdgeApiTest.class,
+        GraphSpaceVertexApiTest.class
 })
-public class ApiTestSuite {
+public class GraphSpaceApiTestSuite {
 
-    @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
-    }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeApiTest.java
index 11d3e6409..643888a95 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.EdgeApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpaceEdgeApiTest extends EdgeApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeLabelApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeLabelApiTest.java
index 11d3e6409..80e21b163 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceEdgeLabelApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.EdgeLabelApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpaceEdgeLabelApiTest extends EdgeLabelApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceIndexLabelApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceIndexLabelApiTest.java
index 11d3e6409..f5f3e4c4d 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceIndexLabelApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.IndexLabelApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpaceIndexLabelApiTest extends IndexLabelApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpacePropertyKeyApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpacePropertyKeyApiTest.java
index 11d3e6409..6096c10ee 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpacePropertyKeyApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.PropertyKeyApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpacePropertyKeyApiTest extends PropertyKeyApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexApiTest.java
index 11d3e6409..f967540e1 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.VertexApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpaceVertexApiTest extends VertexApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }
diff --git 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexLabelApiTest.java
similarity index 50%
copy from 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
copy to 
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexLabelApiTest.java
index 11d3e6409..5b12576a6 100644
--- 
a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/ApiTestSuite.java
+++ 
b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/graphspaces/GraphSpaceVertexLabelApiTest.java
@@ -15,37 +15,22 @@
  * limitations under the License.
  */
 
-package org.apache.hugegraph.api;
+package org.apache.hugegraph.api.graphspaces;
 
-import org.apache.hugegraph.api.traversers.TraversersApiTestSuite;
-import org.apache.hugegraph.dist.RegisterUtil;
+import java.util.Objects;
+
+import org.apache.hugegraph.api.BaseApiTest;
+import org.apache.hugegraph.api.VertexLabelApiTest;
 import org.junit.BeforeClass;
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
 
-@RunWith(Suite.class)
[email protected]({
-        PropertyKeyApiTest.class,
-        VertexLabelApiTest.class,
-        EdgeLabelApiTest.class,
-        IndexLabelApiTest.class,
-        SchemaApiTest.class,
-        VertexApiTest.class,
-        EdgeApiTest.class,
-        TaskApiTest.class,
-        GremlinApiTest.class,
-        MetricsApiTest.class,
-        UserApiTest.class,
-        LoginApiTest.class,
-        ProjectApiTest.class,
-        TraversersApiTestSuite.class,
-        CypherApiTest.class,
-        ArthasApiTest.class
-})
-public class ApiTestSuite {
+public class GraphSpaceVertexLabelApiTest extends VertexLabelApiTest {
 
     @BeforeClass
-    public static void initEnv() {
-        RegisterUtil.registerBackends();
+    public static void init() {
+        if (Objects.nonNull(client)) {
+            client.close();
+        }
+        client = new RestClient(String.join("/", BASE_URL, "graphspaces", 
"DEFAULT"));
+        BaseApiTest.clearData();
     }
 }

Reply via email to