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

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


The following commit(s) were added to refs/heads/master by this push:
     new 3f213575 fix(client): update Content-Type in GraphsAPI for adding 
graphs (#714)
3f213575 is described below

commit 3f2135755bc0ef156f4814b4ef53dbe4016d22b3
Author: Benc <[email protected]>
AuthorDate: Sun Apr 19 23:13:29 2026 +0800

    fix(client): update Content-Type in GraphsAPI for adding graphs (#714)
    
    - Use RestHeaders.APPLICATION_JSON constant in GraphsAPI.create()
    - Bump hugegraph-common version from 1.5.0 to 1.7.0
    - Add unit tests (Mockito) to verify Content-Type and clone params
    - Re-enable integration tests (server NPE fixed in hugegraph#2900)
    - Migrate test config files from .properties to JSON format
    - Remove outdated assertEquals on response size (server now returns 4 
fields)
    
    * chore(client): cleanup review findings
    
    - Delete orphaned .properties test config files (replaced by .json)
    - Remove unused VersionUtil import in GraphsAPITest
    
    * fix(test): align error message assertion with common 1.7.0 Date 
serialization
    
    hugegraph-common 1.7.0 added MAPPER.disable(WRITE_DATES_AS_TIMESTAMPS)
    with SimpleDateFormat, so Date values are now serialized as String
    ("yyyy-MM-dd HH:mm:ss.SSS") instead of Long (epoch millis).
    
    This causes the server's UpdateStrategy.formatError() to report
    "Date, String" instead of "Date, Long" when checking INTERSECTION
    strategy on non-collection properties.
    
    ---------
    
    Co-authored-by: imbajin <[email protected]>
---
 .../org/apache/hugegraph/api/graphs/GraphsAPI.java |   3 +-
 .../hugegraph/api/BatchUpdateElementApiTest.java   |   4 +-
 .../org/apache/hugegraph/api/GraphsApiTest.java    |  23 +----
 .../org/apache/hugegraph/unit/GraphsAPITest.java   | 110 +++++++++++++++++++++
 .../org/apache/hugegraph/unit/UnitTestSuite.java   |   1 +
 .../src/test/resources/hugegraph-clone.json        |   5 +
 .../src/test/resources/hugegraph-clone.properties  |  20 ----
 .../src/test/resources/hugegraph-create.json       |   8 ++
 .../src/test/resources/hugegraph-create.properties |  23 -----
 pom.xml                                            |   3 +-
 10 files changed, 132 insertions(+), 68 deletions(-)

diff --git 
a/hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java 
b/hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java
index 17d0a537..030cf126 100644
--- 
a/hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java
+++ 
b/hugegraph-client/src/main/java/org/apache/hugegraph/api/graphs/GraphsAPI.java
@@ -74,7 +74,8 @@ public class GraphsAPI extends API {
     @SuppressWarnings("unchecked")
     public Map<String, String> create(String name, String cloneGraphName, 
String configText) {
         this.client.checkApiVersion("0.67", "dynamic graph add");
-        RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_TYPE, 
"text/plain");
+        RestHeaders headers = new RestHeaders().add(RestHeaders.CONTENT_TYPE,
+                                                    
RestHeaders.APPLICATION_JSON);
         Map<String, Object> params = null;
         if (StringUtils.isNotEmpty(cloneGraphName)) {
             params = ImmutableMap.of("clone_graph_name", cloneGraphName);
diff --git 
a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BatchUpdateElementApiTest.java
 
b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BatchUpdateElementApiTest.java
index 88a9088b..4604f686 100644
--- 
a/hugegraph-client/src/test/java/org/apache/hugegraph/api/BatchUpdateElementApiTest.java
+++ 
b/hugegraph-client/src/test/java/org/apache/hugegraph/api/BatchUpdateElementApiTest.java
@@ -330,7 +330,7 @@ public class BatchUpdateElementApiTest extends BaseApiTest {
             vertexAPI.update(req5);
         }, e -> {
             String expect = "Property type must be Set or List for " +
-                            "strategy INTERSECTION, but got type Date, Long";
+                            "strategy INTERSECTION, but got type Date, String";
             Assert.assertContains(expect, e.getMessage());
         });
 
@@ -622,7 +622,7 @@ public class BatchUpdateElementApiTest extends BaseApiTest {
             edgeAPI.update(req5);
         }, e -> {
             String expect = "Property type must be Set or List for " +
-                            "strategy INTERSECTION, but got type Date, Long";
+                            "strategy INTERSECTION, but got type Date, String";
             Assert.assertContains(expect, e.getMessage());
         });
 
diff --git 
a/hugegraph-client/src/test/java/org/apache/hugegraph/api/GraphsApiTest.java 
b/hugegraph-client/src/test/java/org/apache/hugegraph/api/GraphsApiTest.java
index a60b2a86..5947cd5f 100644
--- a/hugegraph-client/src/test/java/org/apache/hugegraph/api/GraphsApiTest.java
+++ b/hugegraph-client/src/test/java/org/apache/hugegraph/api/GraphsApiTest.java
@@ -33,19 +33,17 @@ import org.apache.hugegraph.structure.graph.Vertex;
 import org.apache.hugegraph.structure.gremlin.ResultSet;
 import org.apache.hugegraph.testutil.Assert;
 import org.junit.After;
-import org.junit.Ignore;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableSet;
 
-//@Ignore
 public class GraphsApiTest extends BaseApiTest {
 
     private static final String GRAPH2 = "hugegraph2";
-    private static final String CONFIG2_PATH = 
"src/test/resources/hugegraph-create.properties";
+    private static final String CONFIG2_PATH = 
"src/test/resources/hugegraph-create.json";
 
     private static final String GRAPH3 = "hugegraph3";
-    private static final String CONFIG3_PATH = 
"src/test/resources/hugegraph-clone.properties";
+    private static final String CONFIG3_PATH = 
"src/test/resources/hugegraph-clone.json";
 
     protected static void initPropertyKey(HugeClient client) {
         SchemaManager schema = client.schema();
@@ -118,10 +116,6 @@ public class GraphsApiTest extends BaseApiTest {
         }
     }
 
-    // FIXME: This test fails due to NullPointerException in server's 
metaManager.graphConfigs()
-    //        when calling graphsAPI.list(). Need to update and fix after 
server metaManager is fixed.
-    //        See: GraphManager.graphs() line 2055 in hugegraph-server
-    @Ignore("Temporarily disabled due to server metaManager 
NullPointerException")
     @Test
     public void testCreateAndDropGraph() {
         int initialGraphNumber = graphsAPI.list().size();
@@ -136,7 +130,6 @@ public class GraphsApiTest extends BaseApiTest {
                                       CONFIG2_PATH);
         }
         Map<String, String> result = graphsAPI.create(GRAPH2, null, config);
-        Assert.assertEquals(2, result.size());
         Assert.assertEquals(GRAPH2, result.get("name"));
         Assert.assertEquals("rocksdb", result.get("backend"));
 
@@ -193,10 +186,6 @@ public class GraphsApiTest extends BaseApiTest {
         Assert.assertEquals(initialGraphNumber, graphsAPI.list().size());
     }
 
-    // FIXME: This test fails due to NullPointerException in server's 
metaManager.graphConfigs()
-    //        when calling graphsAPI.list(). Need to update and fix after 
server metaManager is fixed.
-    //        See: GraphManager.graphs() line 2055 in hugegraph-server
-    @Ignore("Temporarily disabled due to server metaManager 
NullPointerException")
     @Test
     public void testCloneAndDropGraph() {
         int initialGraphNumber = graphsAPI.list().size();
@@ -212,13 +201,12 @@ public class GraphsApiTest extends BaseApiTest {
         }
         Map<String, String> result = graphsAPI.create(GRAPH3, "hugegraph",
                                                       config);
-        Assert.assertEquals(2, result.size());
         Assert.assertEquals(GRAPH3, result.get("name"));
         Assert.assertEquals("rocksdb", result.get("backend"));
 
         Assert.assertEquals(initialGraphNumber + 1, graphsAPI.list().size());
 
-        HugeClient client = new HugeClient(baseClient(), DEFAULT_GRAPHSPACE, 
GRAPH3);
+        HugeClient client = new HugeClient(baseClient(), GRAPHSPACE, GRAPH3);
         // Insert graph schema and data
         initPropertyKey(client);
         initVertexLabel(client);
@@ -269,10 +257,6 @@ public class GraphsApiTest extends BaseApiTest {
         Assert.assertEquals(initialGraphNumber, graphsAPI.list().size());
     }
 
-    // FIXME: This test fails due to NullPointerException in server's 
metaManager.graphConfigs()
-    //        when calling graphsAPI.list(). Need to update and fix after 
server metaManager is fixed.
-    //        See: GraphManager.graphs() line 2055 in hugegraph-server
-    @Ignore("Temporarily disabled due to server metaManager 
NullPointerException")
     @Test
     public void testCloneAndDropGraphWithoutConfig() {
         int initialGraphNumber = graphsAPI.list().size();
@@ -281,7 +265,6 @@ public class GraphsApiTest extends BaseApiTest {
         String config = null;
         Map<String, String> result = graphsAPI.create(GRAPH3, "hugegraph",
                                                       config);
-        Assert.assertEquals(2, result.size());
         Assert.assertEquals(GRAPH3, result.get("name"));
         Assert.assertEquals("rocksdb", result.get("backend"));
 
diff --git 
a/hugegraph-client/src/test/java/org/apache/hugegraph/unit/GraphsAPITest.java 
b/hugegraph-client/src/test/java/org/apache/hugegraph/unit/GraphsAPITest.java
new file mode 100644
index 00000000..d10f84f4
--- /dev/null
+++ 
b/hugegraph-client/src/test/java/org/apache/hugegraph/unit/GraphsAPITest.java
@@ -0,0 +1,110 @@
+/*
+ * 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.unit;
+
+import java.util.Map;
+
+import org.apache.hugegraph.api.graphs.GraphsAPI;
+import org.apache.hugegraph.client.RestClient;
+import org.apache.hugegraph.rest.RestHeaders;
+import org.apache.hugegraph.rest.RestResult;
+import org.apache.hugegraph.testutil.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+
+public class GraphsAPITest extends BaseUnitTest {
+
+    private RestClient mockClient;
+    private GraphsAPI graphsAPI;
+
+    @Before
+    public void setup() {
+        this.mockClient = Mockito.mock(RestClient.class);
+        Mockito.when(this.mockClient.apiVersionLt(Mockito.anyString()))
+               .thenReturn(false);
+        this.graphsAPI = new GraphsAPI(this.mockClient, "DEFAULT");
+    }
+
+    @Test
+    public void testCreateGraphUsesJsonContentType() {
+        RestResult mockResult = Mockito.mock(RestResult.class);
+        Mockito.when(mockResult.readObject(Map.class))
+               .thenReturn(null);
+
+        ArgumentCaptor<String> pathCaptor =
+                ArgumentCaptor.forClass(String.class);
+        ArgumentCaptor<Object> bodyCaptor =
+                ArgumentCaptor.forClass(Object.class);
+        ArgumentCaptor<RestHeaders> headersCaptor =
+                ArgumentCaptor.forClass(RestHeaders.class);
+        @SuppressWarnings("unchecked")
+        ArgumentCaptor<Map<String, Object>> paramsCaptor =
+                ArgumentCaptor.forClass(Map.class);
+
+        Mockito.when(this.mockClient.post(
+                pathCaptor.capture(),
+                bodyCaptor.capture(),
+                headersCaptor.capture(),
+                paramsCaptor.capture()
+        )).thenReturn(mockResult);
+
+        this.graphsAPI.create("test-graph", null, "{}");
+
+        RestHeaders capturedHeaders = headersCaptor.getValue();
+        Assert.assertEquals("application/json",
+                            capturedHeaders.get(RestHeaders.CONTENT_TYPE));
+
+        Assert.assertTrue(
+                pathCaptor.getValue().contains("test-graph"));
+        Assert.assertEquals("{}", bodyCaptor.getValue());
+        Assert.assertNull(paramsCaptor.getValue());
+    }
+
+    @Test
+    public void testCloneGraphUsesJsonContentTypeAndParams() {
+        RestResult mockResult = Mockito.mock(RestResult.class);
+        Mockito.when(mockResult.readObject(Map.class))
+               .thenReturn(null);
+
+        ArgumentCaptor<RestHeaders> headersCaptor =
+                ArgumentCaptor.forClass(RestHeaders.class);
+        @SuppressWarnings("unchecked")
+        ArgumentCaptor<Map<String, Object>> paramsCaptor =
+                ArgumentCaptor.forClass(Map.class);
+
+        Mockito.when(this.mockClient.post(
+                Mockito.anyString(),
+                Mockito.any(),
+                headersCaptor.capture(),
+                paramsCaptor.capture()
+        )).thenReturn(mockResult);
+
+        this.graphsAPI.create("new-graph", "source-graph", "{}");
+
+        RestHeaders capturedHeaders = headersCaptor.getValue();
+        Assert.assertEquals("application/json",
+                            capturedHeaders.get(RestHeaders.CONTENT_TYPE));
+
+        Map<String, Object> capturedParams = paramsCaptor.getValue();
+        Assert.assertNotNull(capturedParams);
+        Assert.assertEquals("source-graph",
+                            capturedParams.get("clone_graph_name"));
+    }
+}
diff --git 
a/hugegraph-client/src/test/java/org/apache/hugegraph/unit/UnitTestSuite.java 
b/hugegraph-client/src/test/java/org/apache/hugegraph/unit/UnitTestSuite.java
index c4abd46e..5ddb23a5 100644
--- 
a/hugegraph-client/src/test/java/org/apache/hugegraph/unit/UnitTestSuite.java
+++ 
b/hugegraph-client/src/test/java/org/apache/hugegraph/unit/UnitTestSuite.java
@@ -28,6 +28,7 @@ import org.junit.runners.Suite;
         BatchElementRequestTest.class,
         PropertyKeyTest.class,
         IndexLabelTest.class,
+        GraphsAPITest.class,
         CommonUtilTest.class,
         IdUtilTest.class,
         SplicingIdGeneratorTest.class
diff --git a/hugegraph-client/src/test/resources/hugegraph-clone.json 
b/hugegraph-client/src/test/resources/hugegraph-clone.json
new file mode 100644
index 00000000..0fa14589
--- /dev/null
+++ b/hugegraph-client/src/test/resources/hugegraph-clone.json
@@ -0,0 +1,5 @@
+{
+    "store": "hugegraph3",
+    "rocksdb.data_path": "rocksdb-data/data_hugegraph3",
+    "rocksdb.wal_path": "rocksdb-data/wal_hugegraph3"
+}
diff --git a/hugegraph-client/src/test/resources/hugegraph-clone.properties 
b/hugegraph-client/src/test/resources/hugegraph-clone.properties
deleted file mode 100644
index e0a8c873..00000000
--- a/hugegraph-client/src/test/resources/hugegraph-clone.properties
+++ /dev/null
@@ -1,20 +0,0 @@
-#
-# 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.
-#
-
-store=hugegraph3
-rocksdb.data_path=./hg3
-rocksdb.wal_path=./hg3
diff --git a/hugegraph-client/src/test/resources/hugegraph-create.json 
b/hugegraph-client/src/test/resources/hugegraph-create.json
new file mode 100644
index 00000000..d0913eaa
--- /dev/null
+++ b/hugegraph-client/src/test/resources/hugegraph-create.json
@@ -0,0 +1,8 @@
+{
+    "gremlin.graph": "org.apache.hugegraph.auth.HugeFactoryAuthProxy",
+    "backend": "rocksdb",
+    "serializer": "binary",
+    "store": "hugegraph2",
+    "rocksdb.data_path": "rocksdb-data/data_hugegraph2",
+    "rocksdb.wal_path": "rocksdb-data/wal_hugegraph2"
+}
diff --git a/hugegraph-client/src/test/resources/hugegraph-create.properties 
b/hugegraph-client/src/test/resources/hugegraph-create.properties
deleted file mode 100644
index 882b5bf4..00000000
--- a/hugegraph-client/src/test/resources/hugegraph-create.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# 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.
-#
-
-gremlin.graph=org.apache.hugegraph.auth.HugeFactoryAuthProxy
-backend=rocksdb
-serializer=binary
-store=hugegraph2
-rocksdb.data_path=./hg2
-rocksdb.wal_path=./hg2
diff --git a/pom.xml b/pom.xml
index f64ad728..714440e8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -99,8 +99,7 @@
 
     <properties>
         <revision>1.7.0</revision>
-        <!-- TODO: upgrade common later -->
-        <hugegraph.common.version>1.5.0</hugegraph.common.version>
+        <hugegraph.common.version>1.7.0</hugegraph.common.version>
         <release.name>${project.artifactId}</release.name>
         <final.name>apache-${release.name}-${project.version}</final.name>
         <assembly.dir>${project.basedir}/assembly</assembly.dir>

Reply via email to