Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -122,6 +122,11 @@ public static HugeClientBuilder builder(String url, String graphSpace, String gr
return new HugeClientBuilder(url, graphSpace, graph);
}

public static HugeClientBuilder builder(String url, String graphSpace, String graph,
boolean skipRequiredChecks) {
return new HugeClientBuilder(url, graphSpace, graph, skipRequiredChecks);
}
Comment thread
FrostyHec marked this conversation as resolved.
Outdated

public static HugeClientBuilder builder(String url, String graph) {
return new HugeClientBuilder(url, HugeClientBuilder.DEFAULT_GRAPHSPACE, graph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,26 @@ public class HugeClientBuilder {
/** Set them null by default to keep compatibility with 'timeout' */
private Integer connectTimeout;
private Integer readTimeout;
private final boolean skipRequiredChecks;

public HugeClientBuilder(String url, String graphSpace, String graph) {
E.checkArgument(url != null && !url.isEmpty(),
"Expect a string value as the url parameter argument, but got: %s", url);
E.checkArgument(graph != null && !graph.isEmpty(),
"Expect a string value as the graph name parameter argument, but got: %s",
graph);
this(url, graphSpace, graph, false);
}

public HugeClientBuilder(String url, String graphSpace, String graph,
boolean skipRequiredChecks) {
this.skipRequiredChecks = skipRequiredChecks;

if (!skipRequiredChecks) {
E.checkArgument(url != null && !url.isEmpty(),
"Expect a string value as the url parameter " +
"argument, but got: %s", url);
E.checkArgument(graph != null && !graph.isEmpty(),
"Expect a string value as the graph name " +
"parameter argument, but got: %s",
graph);
}

this.url = url;
this.graphSpace = graphSpace;
this.graph = graph;
Expand All @@ -76,8 +89,10 @@ public HugeClientBuilder(String url, String graphSpace, String graph) {
}

public HugeClient build() {
E.checkArgument(this.url != null, "The url parameter can't be null");
E.checkArgument(this.graph != null, "The graph parameter can't be null");
if (!this.skipRequiredChecks) {
E.checkArgument(this.url != null, "The url parameter can't be null");
E.checkArgument(this.graph != null, "The graph parameter can't be null");
}
return new HugeClient(this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,11 @@ public static class UserRole {

// Mapping of: graphSpace -> graph -> permission -> resourceType -> resources
@JsonProperty("roles")
private Map<String, Map<String, Map<HugePermission, Map<String, List<HugeResource>>>>> roles;
private Map<String, Map<String, Map<HugePermission, Map<String,
List<HugeResource>>>>> roles;

public Map<String, Map<String, Map<HugePermission, Map<String, List<HugeResource>>>>> roles() {
public Map<String, Map<String, Map<HugePermission, Map<String,
List<HugeResource>>>>> roles() {
Comment thread
FrostyHec marked this conversation as resolved.
Outdated
return Collections.unmodifiableMap(this.roles);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.apache.hugegraph.unit;

import org.apache.hugegraph.driver.HugeClient;
import org.apache.hugegraph.driver.HugeClientBuilder;
import org.apache.hugegraph.rest.ClientException;
Comment thread
FrostyHec marked this conversation as resolved.
Outdated
import org.junit.Assert;
import org.junit.Test;

public class HugeClientBuilderTest {

@Test
public void testBuilderWithSkipRequiredChecks() {
// Should not throw IllegalArgumentException when skipRequiredChecks is true and graph is null
HugeClientBuilder builder = new HugeClientBuilder("http://127.0.0.1:8080", "DEFAULT", null, true);
try {
builder.build();
} catch (IllegalArgumentException e) {
Assert.fail("Should not throw IllegalArgumentException when skipRequiredChecks is true, but got: " + e.getMessage());
} catch (Exception e) {
// Expected since there is probably no server running at localhost:8080
// The fact we reach here means the bypass of graph/url check was successful.
}
Comment thread
FrostyHec marked this conversation as resolved.
}

@Test(expected = IllegalArgumentException.class)
public void testBuilderWithoutSkipRequiredChecks() {
// Should throw exception when skipRequiredChecks is false and graph is null
HugeClientBuilder builder = new HugeClientBuilder("http://127.0.0.1:8080", "DEFAULT", null, false);
builder.build();
}
Comment thread
FrostyHec marked this conversation as resolved.

@Test
public void testHugeClientBuilderMethod() {
// Should not throw IllegalArgumentException
HugeClientBuilder builder = HugeClient.builder("http://127.0.0.1:8080", "DEFAULT", null, true);
try {
builder.build();
} catch (IllegalArgumentException e) {
Assert.fail("Should not throw IllegalArgumentException when skipRequiredChecks is true, but got: " + e.getMessage());
} catch (Exception e) {
// Expected
}
}

@Test(expected = IllegalArgumentException.class)
public void testHugeClientBuilderMethodWithoutSkip() {
// Should throw exception
HugeClientBuilder builder = HugeClient.builder("http://127.0.0.1:8080", "DEFAULT", null);
builder.build();
}
}
Loading