Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected String type() {
@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});

Expand Down Expand Up @@ -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());
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -136,7 +130,6 @@ public void testCreateAndDropGraph() {
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"));

Expand Down Expand Up @@ -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();
Expand All @@ -212,13 +201,12 @@ public void testCloneAndDropGraph() {
}
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);
Expand Down Expand Up @@ -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();
Expand All @@ -281,7 +265,6 @@ public void testCloneAndDropGraphWithoutConfig() {
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"));

Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
BatchElementRequestTest.class,
PropertyKeyTest.class,
IndexLabelTest.class,
GraphsAPITest.class,
CommonUtilTest.class,
IdUtilTest.class,
SplicingIdGeneratorTest.class
Expand Down
5 changes: 5 additions & 0 deletions hugegraph-client/src/test/resources/hugegraph-clone.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"store": "hugegraph3",
"rocksdb.data_path": "rocksdb-data/data_hugegraph3",
"rocksdb.wal_path": "rocksdb-data/wal_hugegraph3"
}
20 changes: 0 additions & 20 deletions hugegraph-client/src/test/resources/hugegraph-clone.properties

This file was deleted.

8 changes: 8 additions & 0 deletions hugegraph-client/src/test/resources/hugegraph-create.json
Original file line number Diff line number Diff line change
@@ -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"
}
23 changes: 0 additions & 23 deletions hugegraph-client/src/test/resources/hugegraph-create.properties

This file was deleted.

3 changes: 1 addition & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Loading