Java Code Examples for com.baidu.hugegraph.testutil.Assert#assertEquals()

The following examples show how to use com.baidu.hugegraph.testutil.Assert#assertEquals() . 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: PropertyKeyTest.java    From hugegraph-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testEliminatePropertyKeyWithUserData() {
    SchemaManager schema = 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"));
    String time = (String) age.userdata().get("~create_time");
    Date createTime = DateUtil.parse(time);
    Assert.assertTrue(createTime.before(DateUtil.now()));

    age = schema.propertyKey("age")
                .userdata("max", "")
                .eliminate();
    Assert.assertEquals(2, age.userdata().size());
    Assert.assertEquals(0, age.userdata().get("min"));
    time = (String) age.userdata().get("~create_time");
    Assert.assertEquals(createTime, DateUtil.parse(time));
}
 
Example 2
Source File: FileLoadTest.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
@Test
public void testVertexIdColumnEmpty() {
    ioUtil.write("vertex_person.csv",
                 "id,name,age,city",
                 "1,marko,29,Beijing",
                 ",vadas,27,Hongkong",
                 "2,josh,32,Beijing",
                 ",peter,35,Shanghai",
                 "3,\"li,nary\",26,\"Wu,han\"");

    String[] args = new String[] {
            "-f", structPath("vertex_id_column_empty/struct.json"),
            "-s", configPath("vertex_id_column_empty/schema.groovy"),
            "-g", GRAPH,
            "-h", SERVER,
            "--batch-insert-threads", "2",
            "--test-mode", "true"
    };
    HugeGraphLoader.main(args);

    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(3, vertices.size());
}
 
Example 3
Source File: AccessApiTest.java    From hugegraph-client with 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 4
Source File: TextBackendEntryTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    TextBackendEntry entry = new TextBackendEntry(HugeType.VERTEX,
                                                  IdGenerator.of(1));
    TextBackendEntry entry2 = new TextBackendEntry(HugeType.VERTEX,
                                                   IdGenerator.of(2));
    TextBackendEntry entry3 = new TextBackendEntry(HugeType.VERTEX,
                                                   IdGenerator.of(1));
    TextBackendEntry entry4 = new TextBackendEntry(HugeType.VERTEX,
                                                   IdGenerator.of(1));
    TextBackendEntry entry5 = new TextBackendEntry(HugeType.VERTEX,
                                                   IdGenerator.of(1));
    entry.column(HugeKeys.NAME, "tom");
    entry2.column(HugeKeys.NAME, "tom");
    entry3.column(HugeKeys.NAME, "tom2");
    entry4.column(HugeKeys.NAME, "tom");
    entry4.column(HugeKeys.LABEL, "person");
    entry5.column(HugeKeys.NAME, "tom");

    Assert.assertNotEquals(entry, entry2);
    Assert.assertNotEquals(entry, entry3);
    Assert.assertNotEquals(entry, entry4);
    Assert.assertNotEquals(entry4, entry);
    Assert.assertEquals(entry, entry5);
}
 
Example 5
Source File: UsersTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateTargetWithRess() {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    String ress = "[{\"type\": \"VERTEX\", \"label\": \"person\", " +
                  "\"properties\":{\"city\": \"Beijing\"}}, " +
                  "{\"type\": \"EDGE\", \"label\": \"transfer\"}]";
    HugeTarget target = makeTarget("graph1", "127.0.0.1:8080");
    target.resources(ress);
    Id id = userManager.createTarget(target);

    target = userManager.getTarget(id);
    Assert.assertEquals("graph1", target.name());
    Assert.assertEquals("127.0.0.1:8080", target.url());
    Assert.assertEquals(target.create(), target.update());

    String expect = "[{\"type\":\"VERTEX\",\"label\":\"person\"," +
                    "\"properties\":{\"city\":\"Beijing\"}}," +
                    "{\"type\":\"EDGE\",\"label\":\"transfer\"," +
                    "\"properties\":null}]";
    Assert.assertEquals(expect, JsonUtil.toJson(target.asMap()
                                                .get("target_resources")));
}
 
Example 6
Source File: SerializerFactoryTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testSerializer() {
    AbstractSerializer serializer = SerializerFactory.serializer("text");
    Assert.assertEquals(TextSerializer.class, serializer.getClass());

    serializer = SerializerFactory.serializer("binary");
    Assert.assertEquals(BinarySerializer.class, serializer.getClass());

    serializer = SerializerFactory.serializer("binaryscatter");
    Assert.assertEquals(BinaryScatterSerializer.class,
                        serializer.getClass());

    Assert.assertThrows(BackendException.class, () -> {
        SerializerFactory.serializer("invalid");
    }, e -> {
        Assert.assertTrue(e.getMessage().contains(
                          "Not exists serializer:"));
    });
}
 
Example 7
Source File: FileLoadTest.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
@Test
public void testXZCompressFile() {
    ioUtil.write("vertex_person.xz", Compression.XZ,
                 "name,age,city",
                 "marko,29,Beijing");

    String[] args = new String[]{
            "-f", structPath("xz_compress_file/struct.json"),
            "-s", configPath("xz_compress_file/schema.groovy"),
            "-g", GRAPH,
            "-h", SERVER,
            "--batch-insert-threads", "2",
            "--test-mode", "true"
    };
    HugeGraphLoader.main(args);

    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(1, vertices.size());
}
 
Example 8
Source File: VertexApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreate() {
    Vertex vertex = new Vertex("person");
    vertex.property("name", "James");
    vertex.property("city", "Beijing");
    vertex.property("age", 19);

    vertex = vertexAPI.create(vertex);

    Assert.assertEquals("person", vertex.label());
    Map<String, Object> props = ImmutableMap.of("name", "James",
                                                "city", "Beijing",
                                                "age", 19);
    Assert.assertEquals(props, vertex.properties());
}
 
Example 9
Source File: CountApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCountWithLabel() {
    CountRequest.Builder builder = new CountRequest.Builder();
    builder.source("A").containsTraversed(false);
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    CountRequest request = builder.build();

    long count = countAPI.post(request);
    Assert.assertEquals(3L, count);

    builder = new CountRequest.Builder();
    builder.source("A").containsTraversed(true);
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    builder.steps().direction(Direction.OUT)
           .labels(ImmutableList.of("link"));
    request = builder.build();

    count = countAPI.post(request);
    Assert.assertEquals(8L, count);
}
 
Example 10
Source File: VertexLabelApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateWithUuidIdStrategy() {
    VertexLabel vertexLabel = schema().vertexLabel("person")
                                      .useCustomizeUuidId()
                                      .properties("name", "age", "city")
                                      .build();

    vertexLabel = vertexLabelAPI.create(vertexLabel);

    Assert.assertEquals("person", vertexLabel.name());
    Assert.assertEquals(IdStrategy.CUSTOMIZE_UUID, vertexLabel.idStrategy());
    Assert.assertEquals(true, vertexLabel.enableLabelIndex());
    Set<String> props = ImmutableSet.of("name", "age", "city");
    Assert.assertEquals(props, vertexLabel.properties());

    vertexLabel = schema().vertexLabel("person1")
                          .idStrategy(IdStrategy.CUSTOMIZE_UUID)
                          .properties("name", "age", "city")
                          .build();

    vertexLabel = vertexLabelAPI.create(vertexLabel);

    Assert.assertEquals("person1", vertexLabel.name());
    Assert.assertEquals(IdStrategy.CUSTOMIZE_UUID, vertexLabel.idStrategy());
    Assert.assertEquals(true, vertexLabel.enableLabelIndex());
    props = ImmutableSet.of("name", "age", "city");
    Assert.assertEquals(props, vertexLabel.properties());
}
 
Example 11
Source File: SameNeighborsApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testSameNeighbors() {
    List<Object> neighbors = sameNeighborsAPI.get(1, 2, Direction.BOTH,
                                                  null, -1, -1L);
    Assert.assertEquals(4, neighbors.size());

    Assert.assertTrue(neighbors.containsAll(ImmutableList.of(3, 4, 5, 6)));
}
 
Example 12
Source File: RestResultTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testReadVertexLabel() {
    String json = "{"
            + "\"id\": 1,"
            + "\"primary_keys\": [\"name\"],"
            + "\"index_labels\": [],"
            + "\"name\": \"software\","
            + "\"id_strategy\": \"PRIMARY_KEY\","
            + "\"properties\": [\"price\", \"name\", \"lang\"]"
            + "}";

    Mockito.when(this.mockResponse.getStatus()).thenReturn(200);
    Mockito.when(this.mockResponse.getHeaders()).thenReturn(null);
    Mockito.when(this.mockResponse.readEntity(String.class))
           .thenReturn(json);
    RestResult result = new RestResult(this.mockResponse);
    Assert.assertEquals(200, result.status());
    Assert.assertNull(result.headers());

    VertexLabel vertexLabel = result.readObject(VertexLabel.class);

    Assert.assertEquals("software", vertexLabel.name());
    Assert.assertEquals(IdStrategy.PRIMARY_KEY, vertexLabel.idStrategy());
    Assert.assertEquals(ImmutableList.of("name"),
                        vertexLabel.primaryKeys());
    Assert.assertEquals(ImmutableSet.of("price", "name", "lang"),
                        vertexLabel.properties());
}
 
Example 13
Source File: GroupApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testList() {
    createGroup("test1", "description 1");
    createGroup("test2", "description 2");
    createGroup("test3", "description 3");

    List<Group> groups = api.list(-1);
    Assert.assertEquals(3, groups.size());

    groups.sort((t1, t2) -> t1.name().compareTo(t2.name()));
    Assert.assertEquals("test1", groups.get(0).name());
    Assert.assertEquals("test2", groups.get(1).name());
    Assert.assertEquals("test3", groups.get(2).name());
    Assert.assertEquals("description 1", groups.get(0).description());
    Assert.assertEquals("description 2", groups.get(1).description());
    Assert.assertEquals("description 3", groups.get(2).description());

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

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

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        api.list(0);
    }, e -> {
        Assert.assertContains("Limit must be > 0 or == -1", e.getMessage());
    });
}
 
Example 14
Source File: CacheTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Override
protected void checkSize(Cache<Id, Object> cache, long size,
                         Map<Id, Object> kvs) {
    Assert.assertEquals(size, cache.size());
    if (kvs !=null) {
        for (Map.Entry<Id, Object> kv : kvs.entrySet()) {
            Assert.assertEquals(kv.getValue(), cache.get(kv.getKey()));
        }
    }
}
 
Example 15
Source File: TaskCoreTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testGremlinJobWithScript() throws TimeoutException {
    HugeGraph graph = graph();
    TaskScheduler scheduler = graph.taskScheduler();

    String script = "schema=graph.schema();"
            + "schema.propertyKey('name').asText().ifNotExist().create();"
            + "schema.propertyKey('age').asInt().ifNotExist().create();"
            + "schema.propertyKey('lang').asText().ifNotExist().create();"
            + "schema.propertyKey('date').asDate().ifNotExist().create();"
            + "schema.propertyKey('price').asInt().ifNotExist().create();"
            + "person1=schema.vertexLabel('person1').properties('name','age').ifNotExist().create();"
            + "person2=schema.vertexLabel('person2').properties('name','age').ifNotExist().create();"
            + "knows=schema.edgeLabel('knows').sourceLabel('person1').targetLabel('person2').properties('date').ifNotExist().create();"
            + "for(int i = 0; i < 1000; i++) {"
            + "  p1=graph.addVertex(T.label,'person1','name','p1-'+i,'age',29);"
            + "  p2=graph.addVertex(T.label,'person2','name','p2-'+i,'age',27);"
            + "  p1.addEdge('knows',p2,'date','2016-01-10');"
            + "}";

    HugeTask<Object> task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals("test-gremlin-job", task.name());
    Assert.assertEquals("gremlin", task.type());
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[]", task.result());

    script = "g.V().count()";
    task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[2000]", task.result());

    script = "g.V().hasLabel('person1').count()";
    task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[1000]", task.result());

    script = "g.V().hasLabel('person2').count()";
    task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[1000]", task.result());

    script = "g.E().count()";
    task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[1000]", task.result());

    script = "g.E().hasLabel('knows').count()";
    task = runGremlinJob(script);
    task = scheduler.waitUntilTaskCompleted(task.id(), 10);
    Assert.assertEquals(TaskStatus.SUCCESS, task.status());
    Assert.assertEquals("[1000]", task.result());
}
 
Example 16
Source File: WhereBuilderTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testGt() {
    WhereBuilder where = new WhereBuilder(false);
    where.gte(ImmutableList.of("k1", "k2"), ImmutableList.of("v1", "v2"));
    Assert.assertEquals(" (k1, k2) >= ('v1', 'v2')", where.toString());
}
 
Example 17
Source File: UserApiTest.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testCreate() {
    User user1 = new User();
    user1.name("user1");
    user1.password("p1");
    user1.email("[email protected]");
    user1.phone("123456789");
    user1.avatar("image1.jpg");

    User user2 = new User();
    user2.name("user2");
    user2.password("p2");
    user2.email("[email protected]");
    user2.phone("1357924680");
    user2.avatar("image2.jpg");

    User result1 = api.create(user1);
    User result2 = api.create(user2);

    Assert.assertEquals("user1", result1.name());
    Assert.assertNotEquals("p1", result1.password());
    Assert.assertEquals("[email protected]", result1.email());
    Assert.assertEquals("123456789", result1.phone());
    Assert.assertEquals("image1.jpg", result1.avatar());

    Assert.assertEquals("user2", result2.name());
    Assert.assertNotEquals("p2", result2.password());
    Assert.assertEquals("[email protected]", result2.email());
    Assert.assertEquals("1357924680", result2.phone());
    Assert.assertEquals("image2.jpg", result2.avatar());

    Assert.assertThrows(ServerException.class, () -> {
        api.create(new User());
    }, e -> {
        Assert.assertContains("The name of user can't be null",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        User user3 = new User();
        user3.name("test");
        api.create(user3);
    }, e -> {
        Assert.assertContains("The password of user can't be null",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        api.create(user1);
    }, e -> {
        Assert.assertContains("Can't save user", e.getMessage());
        Assert.assertContains("that already exists", e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        user1.name("admin");
        api.create(user1);
    }, e -> {
        Assert.assertContains("Invalid user name 'admin'", e.getMessage());
    });
}
 
Example 18
Source File: CachedSchemaTransactionTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testEventClear() throws Exception {
    CachedSchemaTransaction cache = this.cache();

    FakeObjects objects = new FakeObjects("unit-test");
    cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(1),
                                                "fake-pk-1"));
    cache.addPropertyKey(objects.newPropertyKey(IdGenerator.of(2),
                                                "fake-pk-2"));

    Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));

    Assert.assertEquals("fake-pk-1",
                        cache.getPropertyKey(IdGenerator.of(1)).name());
    Assert.assertEquals(IdGenerator.of(1),
                        cache.getPropertyKey("fake-pk-1").id());

    Assert.assertEquals("fake-pk-2",
                        cache.getPropertyKey(IdGenerator.of(2)).name());
    Assert.assertEquals(IdGenerator.of(2),
                        cache.getPropertyKey("fake-pk-2").id());

    this.params.schemaEventHub().notify(Events.CACHE, "clear", null).get();

    Assert.assertEquals(0L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(0L, Whitebox.invoke(cache, "nameCache", "size"));

    Assert.assertEquals("fake-pk-1",
                        cache.getPropertyKey(IdGenerator.of(1)).name());
    Assert.assertEquals(IdGenerator.of(1),
                        cache.getPropertyKey("fake-pk-1").id());

    Assert.assertEquals("fake-pk-2",
                        cache.getPropertyKey(IdGenerator.of(2)).name());
    Assert.assertEquals(IdGenerator.of(2),
                        cache.getPropertyKey("fake-pk-2").id());

    Assert.assertEquals(2L, Whitebox.invoke(cache, "idCache", "size"));
    Assert.assertEquals(2L, Whitebox.invoke(cache, "nameCache", "size"));
}
 
Example 19
Source File: AccessApiTest.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testListByGroup() {
    createAccess(HugePermission.READ, "description 1");
    createAccess(HugePermission.WRITE, "description 2");
    createAccess(HugePermission.EXECUTE, "description 3");

    Group hk = GroupApiTest.createGroup("group-hk", "group for hongkong");
    createAccess(hk, gremlin, HugePermission.READ, "description 4");
    createAccess(hk, gremlin, HugePermission.WRITE, "description 5");

    List<Access> accesss = api.list(null, null, -1);
    Assert.assertEquals(5, accesss.size());

    accesss = api.list(hk, null, -1);
    Assert.assertEquals(2, accesss.size());
    accesss.sort((t1, t2) -> t1.permission().compareTo(t2.permission()));
    Assert.assertEquals("description 4", accesss.get(0).description());
    Assert.assertEquals("description 5", accesss.get(1).description());

    accesss = api.list(group, null, -1);
    Assert.assertEquals(3, accesss.size());
    accesss.sort((t1, t2) -> t1.permission().compareTo(t2.permission()));
    Assert.assertEquals("description 1", accesss.get(0).description());
    Assert.assertEquals("description 2", accesss.get(1).description());
    Assert.assertEquals("description 3", accesss.get(2).description());

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

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

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        api.list(group, null, 0);
    }, e -> {
        Assert.assertContains("Limit must be > 0 or == -1", e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        api.list(group, gremlin, -1);
    }, e -> {
        Assert.assertContains("Can't pass both group and target " +
                              "at the same time", e.getMessage());
    });
}
 
Example 20
Source File: EventHubTest.java    From hugegraph-common with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
    this.eventHub = new EventHub("test");
    Assert.assertEquals("test", this.eventHub.name());
}