diff --git a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java index 1f35da5f1c..2ab55f584a 100644 --- a/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java +++ b/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/gremlin/GremlinQueryAPI.java @@ -43,7 +43,8 @@ public class GremlinQueryAPI extends API { "java.util.concurrent.TimeoutException", "groovy.lang.", "org.codehaus.", - "org.apache.hugegraph." + "org.apache.hugegraph.", + "org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException" ); @Context diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java index f9f20ab9e5..52bf104b01 100644 --- a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/UnitTestSuite.java @@ -19,6 +19,7 @@ import org.apache.hugegraph.core.RoleElectionStateMachineTest; import org.apache.hugegraph.unit.api.filter.PathFilterTest; +import org.apache.hugegraph.unit.api.gremlin.GremlinQueryAPITest; import org.apache.hugegraph.unit.auth.HugeGraphAuthProxyTest; import org.apache.hugegraph.unit.cache.CacheManagerTest; import org.apache.hugegraph.unit.cache.CacheTest; @@ -81,6 +82,9 @@ /* api filter */ PathFilterTest.class, + /* api gremlin */ + GremlinQueryAPITest.class, + /* cache */ CacheTest.RamCacheTest.class, CacheTest.OffheapCacheTest.class, diff --git a/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java new file mode 100644 index 0000000000..94deaf921d --- /dev/null +++ b/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/unit/api/gremlin/GremlinQueryAPITest.java @@ -0,0 +1,63 @@ +/* + * 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.api.gremlin; + +import java.lang.reflect.Method; + +import org.apache.hugegraph.api.gremlin.GremlinQueryAPI; +import org.apache.hugegraph.testutil.Assert; +import org.apache.hugegraph.unit.BaseUnitTest; +import org.junit.Test; + +public class GremlinQueryAPITest extends BaseUnitTest { + + private static boolean matchBadRequest(String exClass) throws Exception { + Method m = GremlinQueryAPI.class.getDeclaredMethod( + "matchBadRequestException", String.class); + m.setAccessible(true); + return (boolean) m.invoke(null, exClass); + } + + @Test + public void testMatchBadRequestExceptionWithTinkerpop() throws Exception { + Assert.assertTrue(matchBadRequest( + "org.apache.tinkerpop.gremlin.process.traversal.util.FastNoSuchElementException")); + } + + @Test + public void testMatchBadRequestExceptionWithAuthExceptions() throws Exception { + Assert.assertFalse(matchBadRequest( + "org.apache.tinkerpop.gremlin.server.auth.AuthenticationException")); + Assert.assertFalse(matchBadRequest( + "org.apache.tinkerpop.gremlin.server.authz.AuthorizationException")); + } + + @Test + public void testMatchBadRequestExceptionWithHugegraph() throws Exception { + Assert.assertTrue(matchBadRequest("org.apache.hugegraph.exception.NotFoundException")); + Assert.assertTrue(matchBadRequest("java.lang.IllegalArgumentException")); + Assert.assertTrue(matchBadRequest("groovy.lang.MissingPropertyException")); + } + + @Test + public void testMatchBadRequestExceptionWithOther() throws Exception { + Assert.assertFalse(matchBadRequest(null)); + Assert.assertFalse(matchBadRequest("java.lang.NullPointerException")); + Assert.assertFalse(matchBadRequest("java.io.IOException")); + } +}