Copilot commented on code in PR #2900:
URL: 
https://github.com/apache/incubator-hugegraph/pull/2900#discussion_r2489686590


##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/core/GraphManager.java:
##########
@@ -1931,7 +1964,7 @@ public HugeGraph graph(String graphSpace, String name) {
     }
 
     public void dropGraphLocal(String name) {
-        HugeGraph graph = this.graph(name);
+        HugeGraph graph = this.graph(DEFAULT_GRAPH_SPACE_SERVICE_NAME + "-" + 
name);

Review Comment:
   Incorrect usage of single-parameter `graph()` method. The method expects a 
spaceGraphName in format 'graphSpace-name', but it's called with just the name 
parameter. This should use the two-parameter version: 
`this.graph(DEFAULT_GRAPH_SPACE_SERVICE_NAME, name)` to match the pattern used 
elsewhere in the codebase.
   ```suggestion
           HugeGraph graph = this.graph(DEFAULT_GRAPH_SPACE_SERVICE_NAME, name);
   ```



##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/GraphsApiTest.java:
##########
@@ -18,42 +18,320 @@
 package org.apache.hugegraph.api;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
+import org.apache.hugegraph.util.JsonUtil;
 import org.junit.AfterClass;
-import org.junit.BeforeClass;
+import org.junit.Assert;
 import org.junit.Test;
 
+import com.google.common.collect.ImmutableMap;
+
+import jakarta.ws.rs.client.Entity;
 import jakarta.ws.rs.core.Response;
 
 public class GraphsApiTest extends BaseApiTest {
 
-    private static final String TEMP_SPACE = "graph_test";
-    private static final String TEMP_AUTH_SPACE = "graph_auth_test";
-    private static final String PATH = "graphspaces/graph_test/graphs";
-    private static final String PATH_AUTH = "graphspaces/graph_auth_test" +
-                                            "/graphs";
+    private static final String TEMP_SPACE = "DEFAULT";
+    private static final String PATH = "graphspaces/DEFAULT/graphs";
 
-    @BeforeClass
-    public static void prepareSpace() {
-        createSpace(TEMP_SPACE, false);
-        createSpace(TEMP_AUTH_SPACE, true);
-    }
 
     @AfterClass
     public static void tearDown() {
         clearSpaces();
     }
 
+    @Test
+    public void testListGraphs() {
+        // Create multiple graphs
+        Response r1 = createGraphInRocksDB(TEMP_SPACE, "listtest1");
+        assertResponseStatus(201, r1);
+
+        Response r2 = createGraphInRocksDB(TEMP_SPACE, "listtest2");
+        assertResponseStatus(201, r2);
+
+        // List all graphs
+        Response r = client().get(PATH);
+        String content = assertResponseStatus(200, r);
+
+        Map<String, Object> result = JsonUtil.fromJson(content, Map.class);
+        Assert.assertTrue(result.containsKey("graphs"));
+
+        @SuppressWarnings("unchecked")
+        List<String> graphs = (List<String>) result.get("graphs");
+        Assert.assertTrue(graphs.contains("listtest1"));
+        Assert.assertTrue(graphs.contains("listtest2"));
+
+        // Clean up
+        Map<String, Object> params = ImmutableMap.of(
+                "confirm_message", "I'm sure to drop the graph");
+        client().delete(PATH + "/listtest1", params);
+        client().delete(PATH + "/listtest2", params);
+    }
+
+    @Test
+    public void testGetGraph() {
+        // Create a graph
+        Response r = createGraphInRocksDB(TEMP_SPACE, "get_test", 
"GetTestGraph");
+        assertResponseStatus(201, r);
+
+        // Get the graph
+        Response getResponse = client().get(PATH + "/get_test");
+        String content = assertResponseStatus(200, getResponse);
+
+        Map<String, Object> result = JsonUtil.fromJson(content, Map.class);
+        Assert.assertTrue(result.containsKey("name"));
+        Assert.assertTrue(result.containsKey("backend"));
+        Assert.assertEquals("get_test", result.get("name"));
+
+        // Clean up
+        Map<String, Object> params = ImmutableMap.of(
+                "confirm_message", "I'm sure to drop the graph");
+        client().delete(PATH + "/get_test", params);
+    }
+
+    @Test
+    public void testcreateGraphInRocksDB() {
+        String config = "{\n" +
+                        "  \"gremlin.graph\": 
\"org.apache.hugegraph.HugeFactory\",\n" +
+                        "  \"backend\": \"rocksdb\",\n" +
+                        "  \"serializer\": \"binary\",\n" +
+                        "  \"store\": \"create_test\",\n" +
+                        "  \"nickname\": \"CreateTestGraph\",\n" +
+                        "  \"description\": \"Test graph creation\",\n" +
+                        "  \"rocksdb.data_path\": 
\"rocksdbtest-data-create_test\",\n" +
+                        "  \"rocksdb.wal_path\": 
\"rocksdbtest-data-create_test\"\n" +
+                        "}";
+
+        Response r = client().post(PATH + "/create_test",
+                                   Entity.json(config));
+        String content = assertResponseStatus(201, r);
+
+        Map<String, Object> result = JsonUtil.fromJson(content, Map.class);
+        Assert.assertEquals("create_test", result.get("name"));
+        Assert.assertEquals("CreateTestGraph", result.get("nickname"));
+        Assert.assertEquals("rocksdb", result.get("backend"));
+        Assert.assertEquals("Test graph creation", result.get("description"));
+
+        // Clean up
+        Map<String, Object> params = ImmutableMap.of(
+                "confirm_message", "I'm sure to drop the graph");
+        client().delete(PATH + "/create_test", params);
+    }
+
+    @Test
+    public void testcreateGraphInRocksDBWithMissingRequiredParams() {
+        // Missing 'backend' parameter
+        String config = "{\n" +
+                        "  \"serializer\": \"binary\",\n" +
+                        "  \"store\": \"invalid_test\"\n" +
+                        "}";
+
+        Response r = client().post(PATH + "/invalid_test",
+                                   Entity.json(config));
+        Assert.assertTrue(r.getStatus() >= 400);
+    }
+
+    @Test
+    public void testCloneGraph() {
+        // Create source graph
+        Response r1 = createGraphInRocksDB(TEMP_SPACE, "clone_source", 
"SourceGraph");
+        assertResponseStatus(201, r1);
+
+        // Clone the graph
+        String config = "{\n" +
+                        "  \"gremlin.graph\": 
\"org.apache.hugegraph.HugeFactory\",\n" +
+                        "  \"backend\": \"rocksdb\",\n" +
+                        "  \"serializer\": \"binary\",\n" +
+                        "  \"store\": \"clone_target\",\n" +
+                        "  \"nickname\": \"ClonedGraph\",\n" +
+                        "  \"rocksdb.data_path\": 
\"rocksdbtest-data-clone_target\",\n" +
+                        "  \"rocksdb.wal_path\": 
\"rocksdbtest-data-clone_target\"\n" +
+                        "}";
+
+        Map<String, Object> params = ImmutableMap.of(
+                "clone_graph_name", "clone_source");
+

Review Comment:
   Variable 'Map<String,Object> params' is never read.
   ```suggestion
   
   ```



##########
hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/space/GraphSpaceAPI.java:
##########
@@ -103,7 +104,7 @@ public String create(@Context GraphManager manager,
 
         jsonGraphSpace.checkCreate(false);
 
-        String creator = "admin";
+        String creator = HugeGraphAuthProxy.getContext().user().getName();

Review Comment:
   Inconsistent method call for retrieving username. GraphsAPI.java uses 
`username()` on line 202, but this uses `getName()`. Both should use the same 
method for consistency. Consider using `username()` to match the User class's 
public API.
   ```suggestion
           String creator = HugeGraphAuthProxy.getContext().user().username();
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to