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 17d0a5371..030cf1260 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 @@ protected String type() { @SuppressWarnings("unchecked") public Map 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 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 88a9088bf..4604f6860 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 void testVertexInvalidUpdateStrategy() { 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 void testEdgeInvalidUpdateStrategy() { 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 a60b2a862..5947cd5f7 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.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 void teardown() { } } - // 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 void testCreateAndDropGraph() { CONFIG2_PATH); } Map 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 void testCreateAndDropGraph() { 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 void testCloneAndDropGraph() { } Map 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 void testCloneAndDropGraph() { 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 void testCloneAndDropGraphWithoutConfig() { String config = null; Map 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 000000000..d10f84f45 --- /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 pathCaptor = + ArgumentCaptor.forClass(String.class); + ArgumentCaptor bodyCaptor = + ArgumentCaptor.forClass(Object.class); + ArgumentCaptor headersCaptor = + ArgumentCaptor.forClass(RestHeaders.class); + @SuppressWarnings("unchecked") + ArgumentCaptor> 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 headersCaptor = + ArgumentCaptor.forClass(RestHeaders.class); + @SuppressWarnings("unchecked") + ArgumentCaptor> 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 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 c4abd46e1..5ddb23a50 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 @@ 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 000000000..0fa14589e --- /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 e0a8c8735..000000000 --- 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 000000000..d0913eaaf --- /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 882b5bf4b..000000000 --- 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 f64ad728a..714440e8f 100644 --- a/pom.xml +++ b/pom.xml @@ -99,8 +99,7 @@ 1.7.0 - - 1.5.0 + 1.7.0 ${project.artifactId} apache-${release.name}-${project.version} ${project.basedir}/assembly