Java Code Examples for com.baidu.hugegraph.testutil.Assert

The following examples show how to use com.baidu.hugegraph.testutil.Assert. These examples are extracted from open source projects. 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 Project: hugegraph-common   Source File: EventHubTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventRemoveListenerButNonResult() {
    final String event = "event-test";

    EventListener listener = new EventListener() {
        @Override
        public Object event(Event arg0) {
            return null;
        }
    };

    this.eventHub.listen(event, listener);

    Assert.assertTrue(this.eventHub.containsListener(event));
    Assert.assertEquals(1, this.eventHub.listeners(event).size());
    Assert.assertEquals(listener, this.eventHub.listeners(event).get(0));

    Assert.assertEquals(0, this.eventHub.unlisten(event, null));
    Assert.assertEquals(0, this.eventHub.unlisten("event-fake", listener));

    Assert.assertTrue(this.eventHub.containsListener(event));
    Assert.assertEquals(1, this.eventHub.listeners(event).size());
    Assert.assertEquals(listener, this.eventHub.listeners(event).get(0));
}
 
Example 2
Source Project: hugegraph-client   Source File: AccessApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
    Access access1 = createAccess(HugePermission.WRITE, "description 1");
    Access access2 = createAccess(HugePermission.READ, "description 2");

    Assert.assertEquals("description 1", access1.description());
    Assert.assertEquals("description 2", access2.description());

    access1 = api.get(access1.id());
    access2 = api.get(access2.id());

    Assert.assertEquals(group.id(), access1.group());
    Assert.assertEquals(gremlin.id(), access1.target());
    Assert.assertEquals(HugePermission.WRITE, access1.permission());
    Assert.assertEquals("description 1", access1.description());

    Assert.assertEquals(group.id(), access2.group());
    Assert.assertEquals(gremlin.id(), access2.target());
    Assert.assertEquals(HugePermission.READ, access2.permission());
    Assert.assertEquals("description 2", access2.description());
}
 
Example 3
Source Project: hugegraph-client   Source File: AllShortestPathsApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAllShortestPathWithLabel() {
    List<Path> paths = allShortestPathsAPI.get(1, 6, Direction.BOTH,
                                               "link", 6, -1L, 0L,
                                               -1L);
    Assert.assertEquals(4, paths.size());
    List<List<Object>> expected = ImmutableList.of(
            ImmutableList.of(1, 10, 11, 6),
            ImmutableList.of(1, 19, 20, 6),
            ImmutableList.of(1, 21, 22, 6),
            ImmutableList.of(1, 23, 24, 6)
    );
    for (Path path : paths){
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
 
Example 4
Source Project: hugegraph   Source File: CachedGraphTransactionTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventInvalid() throws Exception {

    CachedGraphTransaction cache = this.cache();

    cache.addVertex(this.newVertex(IdGenerator.of(1)));
    cache.addVertex(this.newVertex(IdGenerator.of(2)));
    cache.commit();

    Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
    Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
    Assert.assertEquals(2L,
                        Whitebox.invoke(cache, "verticesCache", "size"));

    this.params.graphEventHub().notify(Events.CACHE, "invalid",
                                       IdGenerator.of(1)).get();

    Assert.assertEquals(1L,
                        Whitebox.invoke(cache, "verticesCache", "size"));
    Assert.assertTrue(cache.queryVertices(IdGenerator.of(2)).hasNext());
    Assert.assertEquals(1L,
                        Whitebox.invoke(cache, "verticesCache", "size"));
    Assert.assertTrue(cache.queryVertices(IdGenerator.of(1)).hasNext());
    Assert.assertEquals(2L,
                        Whitebox.invoke(cache, "verticesCache", "size"));
}
 
Example 5
Source Project: hugegraph   Source File: PropertyKeyCoreTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEliminatePropertyKeyWithUserdata() {
    SchemaManager schema = graph().schema();

    PropertyKey age = schema.propertyKey("age")
                            .userdata("min", 0)
                            .userdata("max", 100)
                            .create();
    Assert.assertEquals(3, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    Assert.assertEquals(100, age.userdata().get("max"));

    age = schema.propertyKey("age")
                .userdata("max", "")
                .eliminate();
    Assert.assertEquals(2, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
}
 
Example 6
Source Project: hugegraph-client   Source File: VertexLabelApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAppend() {
    VertexLabel vertexLabel1 = schema().vertexLabel("person")
                                       .useAutomaticId()
                                       .properties("name", "age")
                                       .build();
    vertexLabel1 = vertexLabelAPI.create(vertexLabel1);
    Assert.assertEquals("person", vertexLabel1.name());
    Assert.assertEquals(IdStrategy.AUTOMATIC, vertexLabel1.idStrategy());
    Set<String> props = ImmutableSet.of("name", "age");
    Set<String> nullableKeys = ImmutableSet.of();
    Assert.assertEquals(props, vertexLabel1.properties());
    Assert.assertEquals(nullableKeys, vertexLabel1.nullableKeys());

    VertexLabel vertexLabel2 = schema().vertexLabel("person")
                                       .properties("city")
                                       .nullableKeys("city")
                                       .build();
    vertexLabel2 = vertexLabelAPI.append(vertexLabel2);
    Assert.assertEquals("person", vertexLabel2.name());
    Assert.assertEquals(IdStrategy.AUTOMATIC, vertexLabel2.idStrategy());
    props = ImmutableSet.of("name", "age", "city");
    nullableKeys = ImmutableSet.of("city");
    Assert.assertEquals(props, vertexLabel2.properties());
    Assert.assertEquals(nullableKeys, vertexLabel2.nullableKeys());
}
 
Example 7
Source Project: hugegraph   Source File: EdgeLabelCoreTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddEdgeLabelMultipleWithoutSortKey() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .create();
    schema.vertexLabel("author").properties("id", "name")
          .primaryKeys("id").create();

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("look").multiTimes().properties("date")
              .link("person", "book")
              .create();
    });
}
 
Example 8
Source Project: hugegraph   Source File: CacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCapacity() {
    Cache<Id, Object> cache = newCache(10);
    Assert.assertEquals(10, cache.capacity());

    cache = newCache(1024);
    Assert.assertEquals(1024, cache.capacity());

    cache = newCache(8);
    Assert.assertEquals(8, cache.capacity());

    cache = newCache(1);
    Assert.assertEquals(1, cache.capacity());

    cache = newCache(0);
    Assert.assertEquals(0, cache.capacity());

    int huge = (int) (200 * Bytes.GB);
    cache = newCache(huge);
    Assert.assertEquals(huge, cache.capacity());

    // The min capacity is 0
    cache = newCache(-1);
    Assert.assertEquals(0, cache.capacity());
}
 
Example 9
Source Project: hugegraph-client   Source File: VertexTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetAllVertices() {
    BaseClientTest.initVertex();

    List<Vertex> vertices = graph().listVertices();
    Assert.assertEquals(6, vertices.size());
    assertContains(vertices, T.label, "person", "name", "marko",
                             "age", 29, "city", "Beijing");
    assertContains(vertices, T.label, "person", "name", "vadas",
                             "age", 27, "city", "Hongkong");
    assertContains(vertices, T.label, "software", "name", "lop",
                             "lang", "java", "price", 328);
    assertContains(vertices, T.label, "person", "name", "josh",
                             "age", 32, "city", "Beijing");
    assertContains(vertices, T.label, "software", "name", "ripple",
                             "lang", "java", "price", 199);
    assertContains(vertices, T.label, "person", "name", "peter",
                             "age", 29, "city", "Shanghai");
}
 
Example 10
Source Project: hugegraph-client   Source File: BelongApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testList() {
    createBelong(user1, group1, "user1 => group1");
    createBelong(user1, group2, "user1 => group2");
    createBelong(user2, group2, "user2 => group2");

    List<Belong> belongs = api.list(null, null, -1);
    Assert.assertEquals(3, belongs.size());

    belongs.sort((t1, t2) -> t1.description().compareTo(t2.description()));
    Assert.assertEquals("user1 => group1", belongs.get(0).description());
    Assert.assertEquals("user1 => group2", belongs.get(1).description());
    Assert.assertEquals("user2 => group2", belongs.get(2).description());

    belongs = api.list(null, null, 1);
    Assert.assertEquals(1, belongs.size());

    belongs = api.list(null, null, 2);
    Assert.assertEquals(2, belongs.size());

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        api.list(null, null, 0);
    }, e -> {
        Assert.assertContains("Limit must be > 0 or == -1", e.getMessage());
    });
}
 
Example 11
Source Project: hugegraph   Source File: CacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMutiThreadsGetAndUpdate() {
    Cache<Id, Object> cache = newCache(10);

    Id id1 = IdGenerator.of("1");
    cache.update(id1, "value-1");
    Id id2 = IdGenerator.of("2");
    cache.update(id2, "value-2");
    Id id3 = IdGenerator.of("3");
    cache.update(id3, "value-3");
    Assert.assertEquals(3, cache.size());

    runWithThreads(THREADS_NUM, () -> {
        for (int i = 0; i < 10000 * 100; i++) {
            Assert.assertEquals("value-1", cache.get(id1));
            Assert.assertEquals("value-2", cache.get(id2));
            Assert.assertEquals("value-2", cache.get(id2));
            Assert.assertEquals("value-3", cache.get(id3));
            cache.update(id2, "value-2");
            Assert.assertEquals("value-1", cache.get(id1));
        }
    });
    Assert.assertEquals(3, cache.size());
}
 
Example 12
Source Project: hugegraph-common   Source File: HugeConfigTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testOptionsToString() {
    Assert.assertEquals("[String]group1.text1=text1-value",
                        TestOptions.text1.toString());
    Assert.assertEquals("[Integer]group1.int1=1",
                        TestOptions.int1.toString());
    Assert.assertEquals("[Long]group1.long1=100",
                        TestOptions.long1.toString());
    Assert.assertEquals("[Float]group1.float1=100.0",
                        TestOptions.float1.toString());
    Assert.assertEquals("[Double]group1.double1=100.0",
                        TestOptions.double1.toString());
    Assert.assertEquals("[Boolean]group1.bool=true",
                        TestOptions.bool.toString());
    Assert.assertEquals("[List]group1.list=[list-value1, list-value2]",
                        TestOptions.list.toString());
    Assert.assertEquals("[List]group1.map=[key1:value1, key2:value2]",
                        TestOptions.map.toString());

    Assert.assertEquals("[String]group1.text1=text1-value",
                        TestSubOptions.text1.toString());
    Assert.assertEquals("[String]group1.text2=text2-value-override",
                        TestSubOptions.text2.toString());
    Assert.assertEquals("[String]group1.textsub=textsub-value",
                        TestSubOptions.textsub.toString());
}
 
Example 13
Source Project: hugegraph-client   Source File: VertexApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetWithCustomizeNumberId() {
    schema().vertexLabel("log")
            .useCustomizeNumberId()
            .properties("date")
            .ifNotExist()
            .create();

    Vertex vertex1 = new Vertex("log");
    vertex1.id(123456);
    vertex1.property("date", "2018-01-01");

    vertex1 = vertexAPI.create(vertex1);

    Vertex vertex2 = vertexAPI.get(123456);
    Assert.assertEquals(vertex1.id(), vertex2.id());
    Assert.assertEquals(vertex1.label(), vertex2.label());
    Assert.assertEquals(vertex1.properties(), vertex2.properties());
}
 
Example 14
Source Project: hugegraph   Source File: RocksDBSessionsTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteByKey() throws RocksDBException {
    put("person:1gname", "James");
    put("person:1gage", "19");
    put("person:1gcity", "Beijing");

    Assert.assertEquals("James", get("person:1gname"));
    Assert.assertEquals("19", get("person:1gage"));
    Assert.assertEquals("Beijing", get("person:1gcity"));

    this.rocks.session().remove(TABLE, b("person:1gage"));
    this.commit();

    Assert.assertEquals("James", get("person:1gname"));
    Assert.assertEquals(null, get("person:1gage"));
    Assert.assertEquals("Beijing", get("person:1gcity"));
}
 
Example 15
Source Project: hugegraph-common   Source File: EventHubTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEventAddListenerTwice() {
    final String event = "event-test";

    EventListener listener = new EventListener() {
        @Override
        public Object event(Event arg0) {
            return null;
        }
    };

    this.eventHub.listen(event, listener);
    this.eventHub.listen(event, listener);

    Assert.assertTrue(this.eventHub.containsListener(event));
    Assert.assertEquals(2, this.eventHub.listeners(event).size());
    Assert.assertEquals(listener, this.eventHub.listeners(event).get(0));
    Assert.assertEquals(listener, this.eventHub.listeners(event).get(1));
}
 
Example 16
Source Project: hugegraph   Source File: RocksDBCountersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCounterWithMutiThreads() {
    final int TIMES = 1000;

    AtomicLong times = new AtomicLong(0);
    Map<Id, Boolean> ids = new ConcurrentHashMap<>();

    runWithThreads(THREADS_NUM, () -> {
        Session session = this.rocks.session();

        for (int i = 0; i < TIMES; i++) {
            Id id = nextId(session, HugeType.PROPERTY_KEY);
            Assert.assertFalse(ids.containsKey(id));
            ids.put(id, true);

            times.incrementAndGet();
        }
        this.rocks.close();
    });
    Assert.assertEquals(THREADS_NUM * TIMES, times.get());
}
 
Example 17
Source Project: hugegraph-client   Source File: EdgeLabelTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testListByNames() {
    SchemaManager schema = schema();
    EdgeLabel father = schema.edgeLabel("father")
                             .link("person", "person")
                             .create();

    EdgeLabel write = schema.edgeLabel("write")
                            .link("person", "book")
                            .create();

    List<EdgeLabel> edgeLabels;

    edgeLabels = schema.getEdgeLabels(ImmutableList.of("father"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, father);

    edgeLabels = schema.getEdgeLabels(ImmutableList.of("write"));
    Assert.assertEquals(1, edgeLabels.size());
    assertContains(edgeLabels, write);

    edgeLabels = schema.getEdgeLabels(ImmutableList.of("father", "write"));
    Assert.assertEquals(2, edgeLabels.size());
    assertContains(edgeLabels, father);
    assertContains(edgeLabels, write);
}
 
Example 18
Source Project: hugegraph   Source File: CassandraTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testParseRepilcaWithNetworkTopologyStrategy() {
    String strategy = CassandraOptions.CASSANDRA_STRATEGY.name();
    String replica = CassandraOptions.CASSANDRA_REPLICATION.name();

    Configuration conf = Mockito.mock(PropertiesConfiguration.class);
    Mockito.when(conf.getKeys())
           .thenReturn(ImmutableList.of(strategy, replica).iterator());
    Mockito.when(conf.getProperty(strategy))
           .thenReturn("NetworkTopologyStrategy");
    Mockito.when(conf.getProperty(replica))
           .thenReturn(ImmutableList.of("dc1:2", "dc2:1"));
    HugeConfig config = new HugeConfig(conf);

    Map<String, Object> result = Whitebox.invokeStatic(CassandraStore.class,
                                                       "parseReplica",
                                                       config);

    Map<String, Object> expected = ImmutableMap.of(
                                   "class", "NetworkTopologyStrategy",
                                   "dc1", 2,
                                   "dc2", 1);
    Assert.assertEquals(expected, result);
}
 
Example 19
Source Project: hugegraph-loader   Source File: FileLoadTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testParseEmptyCsvLine() {
    ioUtil.write("vertex_person.csv",
                 "name,age,city",
                 "");

    String[] args = new String[]{
            "-f", structPath("parse_empty_csv_line/struct.json"),
            "-s", configPath("parse_empty_csv_line/schema.groovy"),
            "-g", GRAPH,
            "-h", SERVER,
            "--batch-insert-threads", "2",
            "--test-mode", "true"
    };
    Assert.assertThrows(ParseException.class, () -> {
        HugeGraphLoader.main(args);
    }, (e) -> {
        Assert.assertTrue(e.getMessage().contains("Parse line '' error"));
    });
}
 
Example 20
Source Project: hugegraph-client   Source File: VertexLabelTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddVertexLabelWithUserData() {
    SchemaManager schema = schema();

    VertexLabel player = schema.vertexLabel("player")
                               .properties("name")
                               .userdata("super_vl", "person")
                               .create();
    Assert.assertEquals(2, player.userdata().size());
    Assert.assertEquals("person", player.userdata().get("super_vl"));
    String time = (String) player.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));

    VertexLabel runner = schema.vertexLabel("runner")
                               .properties("name")
                               .userdata("super_vl", "person")
                               .userdata("super_vl", "player")
                               .create();
    // The same key user data will be overwritten
    Assert.assertEquals(2, runner.userdata().size());
    Assert.assertEquals("player", runner.userdata().get("super_vl"));
    time = (String) runner.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
 
Example 21
Source Project: hugegraph-client   Source File: EdgeApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
    Object outVId = getVertexId("person", "name", "peter");
    Object inVId = getVertexId("software", "name", "lop");

    Edge edge1 = new Edge("created");
    edge1.sourceLabel("person");
    edge1.targetLabel("software");
    edge1.sourceId(outVId);
    edge1.targetId(inVId);
    edge1.property("date", "2017-03-24");
    edge1.property("city", "Hongkong");

    edge1 = edgeAPI.create(edge1);

    Edge edge2 = edgeAPI.get(edge1.id());

    Assert.assertEquals(edge1.label(), edge2.label());
    Assert.assertEquals(edge1.sourceLabel(), edge2.sourceLabel());
    Assert.assertEquals(edge1.targetLabel(), edge2.targetLabel());
    Assert.assertEquals(edge1.sourceId(), edge2.sourceId());
    Assert.assertEquals(edge1.targetId(), edge2.targetId());
    Assert.assertEquals(edge1.properties(), edge2.properties());
}
 
Example 22
Source Project: hugegraph   Source File: UsersTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGetUser() {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    Id id = userManager.createUser(makeUser("tom", "pass1"));

    HugeUser user = userManager.getUser(id);
    Assert.assertEquals("tom", user.name());
    Assert.assertEquals("pass1", user.password());

    Assert.assertThrows(NotFoundException.class, () -> {
        userManager.getUser(IdGenerator.of("fake"));
    });

    Assert.assertThrows(NotFoundException.class, () -> {
        userManager.getUser(null);
    });
}
 
Example 23
Source Project: hugegraph   Source File: EdgeLabelCoreTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testAddEdgeLabelWithSortKeyContainSameProp() {
    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", "date")
              .create();
    });
}
 
Example 24
Source Project: hugegraph-client   Source File: GroupApiTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testGet() {
    Group group1 = createGroup("test1", "description 1");
    Group group2 = createGroup("test2", "description 2");

    Assert.assertEquals("description 1", group1.description());
    Assert.assertEquals("description 2", group2.description());

    group1 = api.get(group1.id());
    group2 = api.get(group2.id());

    Assert.assertEquals("test1", group1.name());
    Assert.assertEquals("description 1", group1.description());

    Assert.assertEquals("test2", group2.name());
    Assert.assertEquals("description 2", group2.description());
}
 
Example 25
Source Project: hugegraph-loader   Source File: HDFSLoadTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHDFSWithCoreSitePath() {
    ioUtil.write("vertex_person.csv",
                 "name,age,city",
                 "marko,29,Beijing",
                 "vadas,27,Hongkong",
                 "josh,32,Beijing",
                 "peter,35,Shanghai",
                 "\"li,nary\",26,\"Wu,han\"");

    String[] args = new String[]{
            "-f", structPath("hdfs_with_core_site_path/struct.json"),
            "-s", configPath("hdfs_with_core_site_path/schema.groovy"),
            "-g", GRAPH,
            "-h", SERVER,
            "--batch-insert-threads", "2",
            "--test-mode", "true"
    };
    HugeGraphLoader loader = new HugeGraphLoader(args);
    loader.load();
    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(5, vertices.size());
}
 
Example 26
Source Project: hugegraph-client   Source File: IndexLabelTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAddIndexLabelWithUserData() {
    SchemaManager schema = schema();
    BaseFuncTest.initVertexLabel();

    IndexLabel personByCity = schema.indexLabel("personByCity")
                                    .onV("person")
                                    .by("city")
                                    .secondary()
                                    .userdata("type", "secondary")
                                    .ifNotExist()
                                    .create();
    Assert.assertEquals(2, personByCity.userdata().size());
    Assert.assertEquals("secondary", personByCity.userdata().get("type"));
    String time = (String) personByCity.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));

    IndexLabel personByAge = schema.indexLabel("personByAge")
                                   .onV("person")
                                   .by("age")
                                   .range()
                                   .userdata("type", "secondary")
                                   .userdata("type", "range")
                                   .ifNotExist()
                                   .create();
    Assert.assertEquals(2, personByAge.userdata().size());
    Assert.assertEquals("range", personByAge.userdata().get("type"));
    time = (String) personByAge.userdata().get("~create_time");
    createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));
}
 
Example 27
Source Project: hugegraph   Source File: BackendMutationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testInsertAndAppendEntry() {
    BackendMutation mutation = new BackendMutation();
    BackendEntry entry1 = constructBackendEntry("1");
    BackendEntry entry2 = constructBackendEntry("1", "name", "marko");

    mutation.add(entry1, Action.INSERT);
    Assert.assertThrows(HugeException.class, () -> {
        mutation.add(entry2, Action.APPEND);
    });
}
 
Example 28
Source Project: hugegraph   Source File: EdgeLabelCoreTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testAddEdgeLabelWithIllegalName() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .create();
    schema.vertexLabel("author").properties("id", "name")
          .primaryKeys("id").create();

    // Empty string
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("").link("person", "author").create();
    });
    // One space
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel(" ").link("person", "author").create();
    });
    // Two spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("  ").link("person", "author").create();
    });
    // Multi spaces
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("    ").link("person", "author").create();
    });
    // Start with '~'
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~").link("person", "author").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~ ").link("person", "author").create();
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("~x").link("person", "author").create();
    });
}
 
Example 29
Source Project: hugegraph   Source File: RolePermissionTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testHugeResourceFilterSchema() {
    HugeResource all = HugeResource.ALL;

    // schema
    HugeResource vlp = new HugeResource(ResourceType.VERTEX_LABEL,
                                        "p-.*", null);

    ResourceObject<?> r3 = ResourceObject.of("g1",
                                             ResourceType.VERTEX_LABEL,
                                             NameObject.of("test"));
    Assert.assertTrue(all.filter(r3));
    Assert.assertFalse(vlp.filter(r3));

    ResourceObject<?> r4 = ResourceObject.of("g1",
                                             ResourceType.VERTEX_LABEL,
                                             NameObject.of("p-test"));
    Assert.assertTrue(all.filter(r4));
    Assert.assertTrue(vlp.filter(r4));

    FakeObjects fo = new FakeObjects();

    VertexLabel vl1 = fo.newVertexLabel(IdGenerator.of("id1"), "person",
                                        IdStrategy.PRIMARY_KEY,
                                        IdGenerator.of("1"));
    ResourceObject<?> r5 = ResourceObject.of("g1", vl1);
    Assert.assertTrue(all.filter(r5));
    Assert.assertFalse(vlp.filter(r5));

    VertexLabel vl2 = fo.newVertexLabel(IdGenerator.of("id1"), "p-person",
                                        IdStrategy.PRIMARY_KEY,
                                        IdGenerator.of("1"));
    ResourceObject<?> r6 = ResourceObject.of("g1", vl2);
    Assert.assertTrue(all.filter(r6));
    Assert.assertTrue(vlp.filter(r6));
}
 
Example 30
Source Project: hugegraph-common   Source File: OptionSpaceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void tesRegister() {
    int oldSize = OptionSpace.keys().size();

    OptionSpace.register("testgroup1", OptionHolder1.class.getName());
    Assert.assertEquals(oldSize + 2, OptionSpace.keys().size());
    Assert.assertTrue(OptionSpace.containKey("testgroup1.text1"));
    Assert.assertTrue(OptionSpace.containKey("testgroup1.text2"));

    OptionSpace.register("testgroup1", new OptionHolder1());
    Assert.assertEquals(oldSize + 2, OptionSpace.keys().size());
    Assert.assertTrue(OptionSpace.containKey("testgroup1.text1"));
    Assert.assertTrue(OptionSpace.containKey("testgroup1.text2"));

    OptionSpace.register("testgroup2", OptionHolder2.class.getName());
    Assert.assertEquals(oldSize + 4, OptionSpace.keys().size());

    Assert.assertTrue(OptionSpace.containKey("testgroup1.text1"));
    Assert.assertTrue(OptionSpace.containKey("testgroup1.text2"));
    Assert.assertTrue(OptionSpace.containKey("testgroup2.text1"));
    Assert.assertTrue(OptionSpace.containKey("testgroup2.text2"));

    Assert.assertEquals("text1 value",
                        OptionSpace.get("testgroup1.text1").defaultValue());
    Assert.assertEquals("text2 value",
                        OptionSpace.get("testgroup1.text2").defaultValue());
    Assert.assertEquals("text1 value",
                        OptionSpace.get("testgroup2.text1").defaultValue());
    Assert.assertEquals("text2 value",
                        OptionSpace.get("testgroup2.text2").defaultValue());
}