Java Code Examples for com.baidu.hugegraph.testutil.Assert#assertThrows()
The following examples show how to use
com.baidu.hugegraph.testutil.Assert#assertThrows() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConditionTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testConditionTextContains() { Condition c1 = Condition.textContains(IdGenerator.of("1"), "tom"); Assert.assertTrue(c1.test("tom")); Assert.assertTrue(c1.test("tomcat")); Assert.assertFalse(c1.test("cat")); Assert.assertFalse(c1.test("text")); Assert.assertFalse(c1.test("abc")); Assert.assertThrows(IllegalArgumentException.class, () -> { c1.test((Object) null); }, e -> { Assert.assertEquals("Can't execute `textcontains` on type null, " + "expect String", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { c1.test(123L); }, e -> { Assert.assertEquals("Can't execute `textcontains` on type Long, " + "expect String", e.getMessage()); }); }
Example 2
Source File: EdgeLabelCoreTest.java From hugegraph with Apache License 2.0 | 6 votes |
@Test public void testAddEdgeLabelWithSortKeyAssignedMultiTimes() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .create(); schema.vertexLabel("book").properties("id", "name") .primaryKeys("id") .create(); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.edgeLabel("look") .multiTimes() .properties("date") .link("person", "book") .sortKeys("date") .sortKeys("date") .create(); }); }
Example 3
Source File: NeighborRankApiTest.java From hugegraph-client with Apache License 2.0 | 6 votes |
@Test public void testNeighborRankWithCapacity() { NeighborRankAPI.Request.Builder builder; builder = NeighborRankAPI.Request.builder(); builder.source("O"); builder.steps().direction(Direction.OUT); builder.steps().direction(Direction.OUT); builder.steps().direction(Direction.OUT); builder.alpha(0.9).capacity(1); NeighborRankAPI.Request request = builder.build(); Assert.assertThrows(ServerException.class, () -> { neighborRankAPI.post(request); }, e -> { String expect = "Exceed capacity '1' while finding neighbor rank"; Assert.assertTrue(e.toString(), e.getMessage().contains(expect)); }); }
Example 4
Source File: FileLoadTest.java From hugegraph-loader with Apache License 2.0 | 6 votes |
@Test public void testTooManyColumns() { ioUtil.write("vertex_person.csv", "name,age,city", "marko,29,Beijing,Extra"); String[] args = new String[]{ "-f", structPath("too_many_columns/struct.json"), "-s", configPath("too_many_columns/schema.groovy"), "-g", GRAPH, "-h", SERVER, "--batch-insert-threads", "2", "--test-mode", "true" }; Assert.assertThrows(ParseException.class, () -> { HugeGraphLoader.main(args); }); }
Example 5
Source File: EdgeLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRemoveEdgeLabel() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .create(); schema.vertexLabel("book") .properties("name", "contribution") .primaryKeys("name") .create(); schema.edgeLabel("look").link("person", "book") .properties("time", "city") .create(); Assert.assertNotNull(schema.getEdgeLabel("look")); schema.edgeLabel("look").remove(); Assert.assertThrows(NotFoundException.class, () -> { schema.getEdgeLabel("look"); }); }
Example 6
Source File: IndexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testAddIndexLabelWithFieldsContainSameProp() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .create(); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.indexLabel("personByAgeAndCity").onV("person").secondary() .by("age", "city", "age").create(); }); }
Example 7
Source File: ListIteratorTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testNext() { Iterator<Integer> results = new ListIterator<>(-1, DATA1.iterator()); Assert.assertEquals(1, (int) results.next()); Assert.assertThrows(NoSuchElementException.class, () -> { results.next(); }); }
Example 8
Source File: VertexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRemoveVertexLabelWithVertex() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .nullableKeys("city") .create(); graph().addVertex(T.label, "person", "name", "marko", "age", 22); graph().addVertex(T.label, "person", "name", "jerry", "age", 5); graph().addVertex(T.label, "person", "name", "tom", "age", 8); graph().tx().commit(); List<Vertex> vertex = graph().traversal().V().hasLabel("person") .toList(); Assert.assertNotNull(vertex); Assert.assertEquals(3, vertex.size()); schema.vertexLabel("person").remove(); Assert.assertThrows(NotFoundException.class, () -> { schema.getVertexLabel("person"); }); Assert.assertThrows(IllegalArgumentException.class, () -> { graph().traversal().V().hasLabel("person").toList(); }); }
Example 9
Source File: CommonTraverserApiTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testScanVertexInPagingWithNegativeLimit() { List<Shard> shards = verticesAPI.shards(1 * 1024 * 1024); for (Shard shard : shards) { String page = ""; Assert.assertThrows(ServerException.class, () -> { verticesAPI.scan(shard, page, -1); }, e -> { String expect = "Invalid limit -1"; Assert.assertTrue(e.toString(), e.getMessage().contains(expect)); }); } }
Example 10
Source File: RestoreCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testCreateVertexWithPrimaryKeyStrategyAndIdInNoneMode() { HugeGraph graph = graph(); graph.schema().propertyKey("name").create(); graph.schema().vertexLabel("person").properties("name") .idStrategy(IdStrategy.PRIMARY_KEY).primaryKeys("name").create(); graph.mode(GraphMode.NONE); Assert.assertThrows(IllegalArgumentException.class, () -> graph.addVertex(T.label, "person", T.id, 100L, "name", "Tom") ); }
Example 11
Source File: UsersTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testUpdateBelong() throws InterruptedException { HugeGraph graph = graph(); UserManager userManager = graph.userManager(); Id user = userManager.createUser(makeUser("tom", "pass1")); Id group = userManager.createGroup(makeGroup("group1")); HugeBelong belong = makeBelong(user, group); belong.description("description1"); Id id = userManager.createBelong(belong); belong = userManager.getBelong(id); Assert.assertEquals(user, belong.source()); Assert.assertEquals(group, belong.target()); Assert.assertEquals("description1", belong.description()); Assert.assertEquals(belong.create(), belong.update()); Date oldUpdateTime = belong.update(); Thread.sleep(1L); belong.description("description2"); userManager.updateBelong(belong); HugeBelong belong2 = userManager.getBelong(id); Assert.assertEquals(user, belong.source()); Assert.assertEquals(group, belong.target()); Assert.assertEquals("description2", belong.description()); Assert.assertEquals(oldUpdateTime, belong2.create()); Assert.assertNotEquals(oldUpdateTime, belong2.update()); Assert.assertThrows(IllegalArgumentException.class, () -> { Id group2 = userManager.createGroup(makeGroup("group2")); HugeBelong belong3 = makeBelong(user, group2); userManager.updateBelong(belong3); }, e -> { Assert.assertContains("Can't save belong", e.getMessage()); Assert.assertContains("that not exists", e.getMessage()); }); }
Example 12
Source File: RestoreCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testCreatePropertyKeyWithNegativeIdInRestoringMode() { HugeGraph graph = graph(); graph.mode(GraphMode.RESTORING); Assert.assertThrows(IllegalStateException.class, () -> graph.schema().propertyKey("name").id(-100L).create() ); }
Example 13
Source File: VertexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRemoveVertexLabelUsedByEdgeLabel() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .nullableKeys("city") .create(); schema.vertexLabel("book") .properties("name") .primaryKeys("name") .create(); schema.edgeLabel("write").link("person", "book") .properties("time", "weight") .create(); Vertex marko = graph().addVertex(T.label, "person", "name", "marko", "age", 22); Vertex java = graph().addVertex(T.label, "book", "name", "java in action"); marko.addEdge("write", java, "time", "2016-12-12", "weight", 0.3); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("person").remove(); }); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("book").remove(); }); }
Example 14
Source File: IndexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testRemoveIndexLabelOfVertexWithoutLabelIndex() { Assume.assumeFalse("Support query by label", storeFeatures().supportsQueryByLabel()); initDataWithoutLabelIndex(); // Not support query by label Assert.assertThrows(NoIndexException.class, () -> { graph().traversal().V().hasLabel("reader").toList(); }, e -> { Assert.assertTrue( e.getMessage().startsWith("Don't accept query by label") && e.getMessage().endsWith("label index is disabled")); }); // Query by property index is ok List<Vertex> vertices = graph().traversal().V() .has("city", "Shanghai").toList(); Assert.assertEquals(10, vertices.size()); graph().schema().indexLabel("readerByCity").remove(); Assert.assertThrows(NoIndexException.class, () -> graph().traversal().V().has("city", "Shanghai").toList() ); }
Example 15
Source File: FilterIteratorTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testNextWithMultiTimes() { Iterator<Integer> vals = DATA.iterator(); Iterator<Integer> results = new FilterIterator<>(vals, val -> true); for (int i = 0; i < 4; i++) { results.next(); } Assert.assertThrows(NoSuchElementException.class, () -> { results.next(); }); }
Example 16
Source File: VersionUtilTest.java From hugegraph-common with Apache License 2.0 | 5 votes |
@Test public void testVersionCheck() { Version version = Version.of("0.6.5"); VersionUtil.check(version, "0.6", "0.7", "test-component"); VersionUtil.check(version, "0.6.5", "0.7", "test-component"); VersionUtil.check(version, "0.6.5", "0.6.6", "test-component"); Assert.assertThrows(IllegalStateException.class, () -> { VersionUtil.check(version, "0.6.5", "0.6.5", "test-component"); }); Assert.assertThrows(IllegalStateException.class, () -> { VersionUtil.check(version, "0.6.5", "0.6", "test-component"); }); Assert.assertThrows(IllegalStateException.class, () -> { VersionUtil.check(version, "0.7", "0.6", "test-component"); }); Assert.assertThrows(IllegalStateException.class, () -> { VersionUtil.check(version, "0.5", "0.6", "test-component"); }); Assert.assertThrows(IllegalStateException.class, () -> { VersionUtil.check(version, "0.7", "1.0", "test-component"); }); }
Example 17
Source File: VertexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testEliminateVertexLabelWithoutUserdata() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); schema.vertexLabel("player") .properties("name", "age") .primaryKeys("name") .nullableKeys("age") .userdata("super_vl", "person") .create(); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("player").useCustomizeStringId().eliminate(); }); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("player").primaryKeys("name").eliminate(); }); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("player").enableLabelIndex(false).eliminate(); }); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("player").properties("age").eliminate(); }); Assert.assertThrows(HugeException.class, () -> { schema.vertexLabel("player").nullableKeys("age").eliminate(); }); }
Example 18
Source File: UserApiTest.java From hugegraph-client with Apache License 2.0 | 5 votes |
@Test public void testList() { createUser("test1", "psw1"); createUser("test2", "psw2"); createUser("test3", "psw3"); List<User> users = api.list(-1); Assert.assertEquals(4, users.size()); users.sort((t1, t2) -> t1.name().compareTo(t2.name())); Assert.assertEquals("admin", users.get(0).name()); Assert.assertEquals("test1", users.get(1).name()); Assert.assertEquals("test2", users.get(2).name()); Assert.assertEquals("test3", users.get(3).name()); users = api.list(1); Assert.assertEquals(1, users.size()); users = api.list(2); Assert.assertEquals(2, users.size()); Assert.assertThrows(IllegalArgumentException.class, () -> { api.list(0); }, e -> { Assert.assertContains("Limit must be > 0 or == -1", e.getMessage()); }); }
Example 19
Source File: VertexLabelCoreTest.java From hugegraph with Apache License 2.0 | 5 votes |
@Test public void testAddVertexLabelWithNullableKeysIntersectPrimarykeys() { super.initPropertyKeys(); SchemaManager schema = graph().schema(); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .nullableKeys("name") .create(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name", "age") .nullableKeys("age") .create(); }); Assert.assertThrows(IllegalArgumentException.class, () -> { schema.vertexLabel("person") .properties("name", "age", "city") .primaryKeys("name") .nullableKeys("name", "age") .create(); }); }
Example 20
Source File: PropertyCoreTest.java From hugegraph with Apache License 2.0 | 4 votes |
@Test public void testTypeByte() { Assert.assertEquals((byte) 3, property("byte", (byte) 3)); Assert.assertEquals((byte) 3, property("byte", 3)); Assert.assertEquals((byte) 18, property("byte", 18L)); Assert.assertEquals(Byte.MIN_VALUE, property("byte", Byte.MIN_VALUE)); Assert.assertEquals(Byte.MAX_VALUE, property("byte", Byte.MAX_VALUE)); List<Byte> list = ImmutableList.of((byte) 1, (byte) 3, (byte) 3, (byte) 127, (byte) 128); Assert.assertEquals(list, propertyList("byte", (byte) 1, (byte) 3, (byte) 3, (byte) 127, (byte) 128)); Assert.assertEquals(list, propertyList("byte", (byte) 1, 3, (long) 3, (byte) 127, (byte) 128)); Set<Byte> set = ImmutableSet.of((byte) 1, (byte) 3, (byte) 127, (byte) 128); Assert.assertEquals(set, propertySet("byte", (byte) 1, (byte) 3, (byte) 3, (byte) 127, (byte) 128)); Assert.assertThrows(IllegalArgumentException.class, () -> { property("byte", 1.0); }, e -> { Assert.assertContains("Invalid property value '1.0' " + "for key 'byte'", e.getMessage()); Assert.assertContains("Can't read '1.0' as byte: ", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { property("byte", 128); }, e -> { Assert.assertContains("Invalid property value '128' " + "for key 'byte'", e.getMessage()); Assert.assertContains("Can't read '128' as byte: " + "Value out of range", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { property("byte", "1"); }, e -> { Assert.assertContains("Invalid property value '1' " + "for key 'byte'", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { propertyList("byte", (byte) 1, true); }, e -> { Assert.assertContains("Invalid property value '[1, true]' " + "for key 'list_byte'", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { propertyList("byte", (byte) 1, 128); }, e -> { Assert.assertContains("Invalid property value '[1, 128]' " + "for key 'list_byte'", e.getMessage()); Assert.assertContains("Can't read '128' as byte: " + "Value out of range", e.getMessage()); }); Assert.assertThrows(IllegalArgumentException.class, () -> { propertySet("byte", (byte) 1, true); }, e -> { Assert.assertContains("Invalid property value '[1, true]' " + "for key 'set_byte'", e.getMessage()); }); }