Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenyuT committed Nov 26, 2023
1 parent 743edb6 commit 7ab1cf2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
10 changes: 8 additions & 2 deletions hugegraph-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
License for the specific language governing permissions and limitations
under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
Expand Down Expand Up @@ -57,6 +57,12 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Consumer;

import org.apache.hugegraph.api.gremlin.GremlinRequest;
import org.apache.hugegraph.exception.ServerException;
Expand All @@ -43,6 +44,22 @@ public static void prepareSchema() {
BaseApiTest.initEdgeLabel();
}

private static void assertThrows(Class<? extends Throwable> expectedThrowable,
Assert.ThrowableRunnable runnable,
Consumer<Throwable> exceptionConsumer) {
try {
runnable.run();
Assert.fail(String.format("No exception was thrown(expected %s)",
expectedThrowable.getName()));
} catch (Throwable e) {
if (!expectedThrowable.isInstance(e)) {
Assert.fail(String.format("Bad exception type %s(expected %s)",
e.getClass().getName(), expectedThrowable.getName()));
}
exceptionConsumer.accept(e);
}
}

@Before
public void prepareData() {
BaseApiTest.initVertex();
Expand Down Expand Up @@ -207,11 +224,25 @@ public void testInvalidGremlin() {
@Test
public void testSecurityOperation() {
GremlinRequest request = new GremlinRequest("System.exit(-1)");
Assert.assertThrows(ServerException.class, () -> {

assertThrows(ServerException.class, () -> {
gremlin().execute(request);
}, e -> {
String msg = "Not allowed to call System.exit() via Gremlin";
Assert.assertContains(msg, e.getMessage());
});
}

@Test
public void testAssertEqualsWithError() {
Assert.assertThrows(AssertionError.class, () ->
assertThrows(AssertionError.class, () -> {
Assert.assertEquals((byte) 1, "1");
}, e -> {
Assert.assertContains("expected: java.lang.Byte",
e.getMessage());
Assert.fail("test");
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ public void testGetUserRole() {
UserRole role3 = api.getUserRole(user3.id());
System.out.println(role3.toString());

Assert.assertEquals("test3&", String.valueOf(user3.id()));
Assert.assertEquals("test4 test", String.valueOf(user4.id()));
Assert.assertContains("test3&", String.valueOf(user3.id()));
Assert.assertContains("test4 test", String.valueOf(user4.id()));

UserRole role1 = api.getUserRole(user1.id());
UserRole role2 = api.getUserRole(user2.id());
Expand Down

0 comments on commit 7ab1cf2

Please sign in to comment.