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

The following examples show how to use com.baidu.hugegraph.testutil.Assert#assertNotEquals() . 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: FileLoadTest.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnmatchedEncodingCharset() {
    ioUtil.write("vertex_software.csv", GBK,
                 "name,lang,price",
                 "lop,中文,328");

    String[] args = new String[]{
            "-f", structPath("unmatched_encoding_charset/struct.json"),
            "-s", configPath("unmatched_encoding_charset/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());
    Vertex vertex = vertices.get(0);
    Assert.assertEquals("lop", vertex.property("name"));
    Assert.assertNotEquals("中文", vertex.property("lang"));
    Assert.assertEquals(328.0, vertex.property("price"));
}
 
Example 2
Source File: UsersTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateTarget() throws InterruptedException {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    HugeTarget target = makeTarget("target1", "url1");
    Id id = userManager.createTarget(target);

    target = userManager.getTarget(id);
    Assert.assertEquals("target1", target.name());
    Assert.assertEquals("url1", target.url());
    Assert.assertEquals(target.create(), target.update());

    Date oldUpdateTime = target.update();
    Thread.sleep(1L);

    target.url("url2");
    userManager.updateTarget(target);

    HugeTarget target2 = userManager.getTarget(id);
    Assert.assertEquals("target1", target2.name());
    Assert.assertEquals("url2", target2.url());
    Assert.assertEquals(oldUpdateTime, target2.create());
    Assert.assertNotEquals(oldUpdateTime, target2.update());
}
 
Example 3
Source File: UsersTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testUpdateGroup() throws InterruptedException {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    HugeGroup group = makeGroup("group1");
    group.description("description1");
    Id id = userManager.createGroup(group);

    group = userManager.getGroup(id);
    Assert.assertEquals("group1", group.name());
    Assert.assertEquals("description1", group.description());
    Assert.assertEquals(group.create(), group.update());

    Date oldUpdateTime = group.update();
    Thread.sleep(1L);

    group.description("description2");
    userManager.updateGroup(group);

    HugeGroup group2 = userManager.getGroup(id);
    Assert.assertEquals("group1", group2.name());
    Assert.assertEquals("description2", group2.description());
    Assert.assertEquals(oldUpdateTime, group2.create());
    Assert.assertNotEquals(oldUpdateTime, group2.update());
}
 
Example 4
Source File: StringEncodingTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testPassword() {
    String passwd = StringEncoding.hashPassword("");
    String passwd2 = StringEncoding.hashPassword("");
    Assert.assertNotEquals(passwd, passwd2);
    Assert.assertTrue(StringEncoding.checkPassword("", passwd));
    Assert.assertTrue(StringEncoding.checkPassword("", passwd2));

    passwd = StringEncoding.hashPassword("123");
    passwd2 = StringEncoding.hashPassword("123");
    Assert.assertNotEquals(passwd, passwd2);
    Assert.assertTrue(StringEncoding.checkPassword("123", passwd));
    Assert.assertTrue(StringEncoding.checkPassword("123", passwd2));

    passwd = StringEncoding.hashPassword("123456");
    passwd2 = StringEncoding.hashPassword("123456");
    Assert.assertNotEquals(passwd, passwd2);
    Assert.assertTrue(StringEncoding.checkPassword("123456", passwd));
    Assert.assertTrue(StringEncoding.checkPassword("123456", passwd2));
}
 
Example 5
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 6
Source File: BelongApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdate() {
    Belong belong1 = createBelong(user1, group1, "user1 => group1");
    Belong belong2 = createBelong(user2, group2, "user2 => group2");

    Assert.assertEquals("user1 => group1", belong1.description());
    Assert.assertEquals("user2 => group2", belong2.description());

    belong1.description("description updated");
    Belong updated = api.update(belong1);
    Assert.assertEquals("description updated", updated.description());
    Assert.assertNotEquals(belong1.updateTime(), updated.updateTime());

    Assert.assertThrows(ServerException.class, () -> {
        belong2.user(user1);
        api.update(belong2);
    }, e -> {
        Assert.assertContains("The user of belong can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        belong2.user(user2);
        belong2.group(group1);
        api.update(belong2);
    }, e -> {
        Assert.assertContains("The group of belong can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(belong2, "id", "fake-id");
        api.update(belong2);
    }, e -> {
        Assert.assertContains("Invalid belong id: fake-id",
                              e.getMessage());
    });
}
 
Example 7
Source File: UsersTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@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 8
Source File: UsersTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdateUser() throws InterruptedException {
    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.assertEquals(user.create(), user.update());

    Date oldUpdateTime = user.update();
    Thread.sleep(1L);

    user.password("pass2");
    userManager.updateUser(user);

    HugeUser user2 = userManager.getUser(id);
    Assert.assertEquals("tom", user2.name());
    Assert.assertEquals("pass2", user2.password());
    Assert.assertEquals(oldUpdateTime, user2.create());
    Assert.assertNotEquals(oldUpdateTime, user2.update());

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        userManager.updateUser(makeUser("tom2", "pass1"));
    }, e -> {
        Assert.assertContains("Can't save user", e.getMessage());
        Assert.assertContains("that not exists", e.getMessage());
    });
}
 
Example 9
Source File: BinaryBackendEntryTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testEquals() {
    BinaryBackendEntry entry = new BinaryBackendEntry(HugeType.VERTEX,
                                                      new byte[]{1, 2});
    BinaryBackendEntry entry2 = new BinaryBackendEntry(HugeType.VERTEX,
                                                       new byte[]{2, 2});
    BinaryBackendEntry entry3 = new BinaryBackendEntry(HugeType.VERTEX,
                                                       new byte[]{1, 2});
    BinaryBackendEntry entry4 = new BinaryBackendEntry(HugeType.VERTEX,
                                                       new byte[]{1, 2});
    BinaryBackendEntry entry5 = new BinaryBackendEntry(HugeType.VERTEX,
                                                       new byte[]{1, 2});
    BackendColumn col = BackendColumn.of(new byte[]{1, 2},
                                         new byte[]{3, 4});
    BackendColumn col2 = BackendColumn.of(new byte[]{5, 6},
                                          new byte[]{7, 8});

    entry.column(col);
    entry2.column(col2);
    entry3.column(col2);
    entry4.column(col);
    entry4.column(col2);
    entry5.column(col);

    Assert.assertNotEquals(entry, entry2);
    Assert.assertNotEquals(entry, entry3);
    Assert.assertNotEquals(entry, entry4);
    Assert.assertEquals(entry, entry5);
}
 
Example 10
Source File: IdTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testLongId() {
    Id id = IdGenerator.of(123L);

    Assert.assertEquals(IdType.LONG, id.type());
    Assert.assertFalse(id.string());
    Assert.assertTrue(id.number());
    Assert.assertFalse(id.uuid());

    Assert.assertEquals(8, id.length());

    Assert.assertEquals(123L, id.asLong());
    Assert.assertEquals(123L, id.asObject());
    Assert.assertEquals("123", id.asString());
    Assert.assertEquals("123", id.toString());
    Assert.assertArrayEquals(NumericUtil.longToBytes(123L),
                             id.asBytes());

    Assert.assertEquals(Long.hashCode(123L), id.hashCode());
    Assert.assertEquals(IdGenerator.of(123L), id);
    Assert.assertEquals(IdGenerator.of(123), id);
    Assert.assertNotEquals(IdGenerator.of(1233), id);
    Assert.assertNotEquals(IdGenerator.of("123"), id);

    Assert.assertEquals("1w", IdGenerator.asStoredString(id));
    Assert.assertEquals(id, IdGenerator.ofStoredString("1w", IdType.LONG));
}
 
Example 11
Source File: IdTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testStringId() {
    Id id = IdGenerator.of("test-id");

    Assert.assertEquals(IdType.STRING, id.type());
    Assert.assertTrue(id.string());
    Assert.assertFalse(id.number());
    Assert.assertFalse(id.uuid());

    Assert.assertEquals(7, id.length());

    Assert.assertEquals("test-id", id.asString());
    Assert.assertEquals("test-id", id.toString());
    Assert.assertEquals("test-id", id.asObject());
    Assert.assertArrayEquals(StringEncoding.encode("test-id"),
                             id.asBytes());

    Assert.assertEquals("test-id".hashCode(), id.hashCode());
    Assert.assertEquals(IdGenerator.of("test-id"), id);
    Assert.assertNotEquals(IdGenerator.of("test-id2"), id);

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        id.asLong();
    });

    Assert.assertEquals("test-id", IdGenerator.asStoredString(id));
    Assert.assertEquals(id, IdGenerator.ofStoredString("test-id",
                                                       IdType.STRING));
}
 
Example 12
Source File: TimeUtilTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testTillNextMillis() {
    for (int i = 0; i < 100; i++) {
        long lastTimestamp = TimeUtil.timeGen();
        long time = TimeUtil.tillNextMillis(lastTimestamp);
        Assert.assertNotEquals(lastTimestamp, time);
    }
}
 
Example 13
Source File: UserApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdate() {
    User user1 = createUser("test1", "psw1");
    User user2 = createUser("test2", "psw2");

    Assert.assertEquals("[email protected]", user1.email());
    Assert.assertEquals("16812345678", user1.phone());
    Assert.assertEquals("image.jpg", user1.avatar());

    String oldPassw = user1.password();
    Assert.assertNotEquals("psw1", oldPassw);

    user1.password("psw-udated");
    user1.email("[email protected]");
    user1.phone("1357924680");
    user1.avatar("image-updated.jpg");

    User updated = api.update(user1);
    Assert.assertNotEquals(oldPassw, updated.password());
    Assert.assertEquals("[email protected]", updated.email());
    Assert.assertEquals("1357924680", updated.phone());
    Assert.assertEquals("image-updated.jpg", updated.avatar());
    Assert.assertNotEquals(user1.updateTime(), updated.updateTime());

    Assert.assertThrows(ServerException.class, () -> {
        user2.name("test2-updated");
        api.update(user2);
    }, e -> {
        Assert.assertContains("The name of user can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(user2, "id", "fake-id");
        api.update(user2);
    }, e -> {
        Assert.assertContains("Invalid user id: fake-id",
                              e.getMessage());
    });
}
 
Example 14
Source File: GroupApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdate() {
    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.description("description updated");
    Group updated = api.update(group1);
    Assert.assertEquals("description updated", updated.description());
    Assert.assertNotEquals(group1.updateTime(), updated.updateTime());

    Assert.assertThrows(ServerException.class, () -> {
        group2.name("test2-updated");
        api.update(group2);
    }, e -> {
        Assert.assertContains("The name of group can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(group2, "id", "fake-id");
        api.update(group2);
    }, e -> {
        Assert.assertContains("Invalid group id: fake-id",
                              e.getMessage());
    });
}
 
Example 15
Source File: TargetApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testUpdate() {
    Target target1 = createTarget("test1", HugeResourceType.VERTEX);
    Target target2 = createTarget("test2", HugeResourceType.EDGE);

    Assert.assertEquals(HugeResourceType.VERTEX,
                        target1.resource().resourceType());
    Assert.assertEquals(HugeResourceType.EDGE,
                        target2.resource().resourceType());

    target1.resources(new HugeResource(HugeResourceType.ALL));
    Target updated = api.update(target1);
    Assert.assertEquals(HugeResourceType.ALL,
                        updated.resource().resourceType());
    Assert.assertNotEquals(target1.updateTime(), updated.updateTime());

    Assert.assertThrows(ServerException.class, () -> {
        target2.name("test2-updated");
        api.update(target2);
    }, e -> {
        Assert.assertContains("The name of target can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(target2, "id", "fake-id");
        api.update(target2);
    }, e -> {
        Assert.assertContains("Invalid target id: fake-id",
                              e.getMessage());
    });
}
 
Example 16
Source File: IdTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testUuidId() {
    Id id = IdGenerator.of("835e1153-9281-4957-8691-cf79258e90eb", true);

    Assert.assertEquals(IdType.UUID, id.type());
    Assert.assertFalse(id.string());
    Assert.assertFalse(id.number());
    Assert.assertTrue(id.uuid());

    Assert.assertEquals(16, id.length());

    Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb",
                        id.asObject().toString());
    Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb",
                        id.asString());
    Assert.assertEquals("835e1153-9281-4957-8691-cf79258e90eb",
                        id.toString());

    byte[] h = NumericUtil.longToBytes(
               Long.parseUnsignedLong("835e115392814957", 16));
    byte[] l = NumericUtil.longToBytes(
               Long.parseUnsignedLong("8691cf79258e90eb", 16));
    Assert.assertArrayEquals(Bytes.concat(h, l), id.asBytes());

    Id id2 = IdGenerator.of("835e1153928149578691cf79258e90eb", true);
    Id id3 = IdGenerator.of("835e1153928149578691cf79258e90eb", false);
    Id id4 = IdGenerator.of("835e1153928149578691cf79258e90ee", true);
    Assert.assertEquals(id2.hashCode(), id.hashCode());
    Assert.assertEquals(id2, id);
    Assert.assertNotEquals(id3, id);
    Assert.assertNotEquals(id4, id);

    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.asLong();
    });

    Assert.assertEquals("g14RU5KBSVeGkc95JY6Q6w==",
                        IdGenerator.asStoredString(id));
    Assert.assertEquals(id, IdGenerator.ofStoredString(
                            "g14RU5KBSVeGkc95JY6Q6w==", IdType.UUID));
}
 
Example 17
Source File: EdgeApiTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testBatchUpdate() throws IOException {
    String outVId = getVertexId("person", "name", "marko");
    String inVId = getVertexId("person", "name", "josh");
    // Create
    String edge = String.format("{"
            + "\"label\": \"knows\","
            + "\"outVLabel\": \"person\","
            + "\"inVLabel\": \"person\","
            + "\"outV\": \"%s\","
            + "\"inV\": \"%s\","
            + "\"properties\":{"
            + "\"date\": \"2013-02-20\","
            + "\"weight\": 1.0}"
            + "}", outVId, inVId);
    Response r = client().post(path, edge);
    // The edge id is 'S1:marko>1>7JooBil0>S1:josh'
    String content = assertResponseStatus(201, r);
    String edgeId = parseId(content);

    // Update edge with edgeId
    edge = String.format("{"
            + "\"edges\":["
            + "{"
            + "\"id\":\"%s\","
            + "\"label\":\"knows\","
            + "\"outV\":\"%s\","
            + "\"outVLabel\":\"person\","
            + "\"inV\":\"%s\","
            + "\"inVLabel\":\"person\","
            + "\"properties\":{"
            + "\"weight\":0.2,"
            + "\"date\":\"2014-02-20\""
            + "}"
            + "}"
            + "],"
            + "\"update_strategies\":{"
            + "\"weight\":\"SUM\","
            + "\"date\":\"BIGGER\""
            + "},"
            + "\"check_vertex\":false,"
            + "\"create_if_not_exist\":true"
            + "}", edgeId, outVId, inVId);
    r = client().put(path, "batch", edge, ImmutableMap.of());
    // Now allowed to modify sortkey values, the property 'date' has changed
    content = assertResponseStatus(400, r);
    Assert.assertTrue(content.contains(
                      "either be null or equal to origin when " +
                      "specified edge id"));

    // Update edge without edgeId
    edge = String.format("{"
            + "\"edges\":["
            + "{"
            + "\"label\":\"knows\","
            + "\"outV\":\"%s\","
            + "\"outVLabel\":\"person\","
            + "\"inV\":\"%s\","
            + "\"inVLabel\":\"person\","
            + "\"properties\":{"
            + "\"weight\":0.2,"
            + "\"date\":\"2014-02-20\""
            + "}"
            + "}"
            + "],"
            + "\"update_strategies\":{"
            + "\"weight\":\"SUM\","
            + "\"date\":\"BIGGER\""
            + "},"
            + "\"check_vertex\":false,"
            + "\"create_if_not_exist\":true"
            + "}", outVId, inVId);
    r = client().put(path, "batch", edge, ImmutableMap.of());
    // Add a new edge when sortkey value has changed
    content = assertResponseStatus(200, r);
    String newEdgeId = parseId(content);
    Assert.assertNotEquals(newEdgeId, edgeId);
}
 
Example 18
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 19
Source File: UsersTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testUpdateAccess() throws InterruptedException {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    Id group = userManager.createGroup(makeGroup("group1"));
    Id target = userManager.createTarget(makeTarget("graph1", "url1"));
    Id id = userManager.createAccess(makeAccess(group, target,
                                                HugePermission.READ));

    HugeAccess access = userManager.getAccess(id);
    Assert.assertEquals(group, access.source());
    Assert.assertEquals(target, access.target());
    Assert.assertEquals(HugePermission.READ, access.permission());
    Assert.assertEquals(access.create(), access.update());

    Date oldUpdateTime = access.update();
    Thread.sleep(1L);

    access.permission(HugePermission.READ);
    userManager.updateAccess(access);

    HugeAccess access2 = userManager.getAccess(id);
    Assert.assertEquals(group, access.source());
    Assert.assertEquals(target, access.target());
    Assert.assertEquals(HugePermission.READ, access.permission());
    Assert.assertEquals(oldUpdateTime, access2.create());
    Assert.assertNotEquals(oldUpdateTime, access2.update());

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        access.permission(HugePermission.WRITE);
        userManager.updateAccess(access);
    }, e -> {
        Assert.assertContains("Can't save access", e.getMessage());
        Assert.assertContains("that not exists", e.getMessage());
    });

    access.permission(HugePermission.READ);
    access.description("description updated");
    id = userManager.updateAccess(access);

    HugeAccess access3 = userManager.getAccess(id);
    Assert.assertEquals(group, access3.source());
    Assert.assertEquals(target, access3.target());
    Assert.assertEquals("description updated", access3.description());
    Assert.assertEquals(HugePermission.READ, access3.permission());
    Assert.assertEquals(oldUpdateTime, access3.create());
    Assert.assertNotEquals(access3.create(), access3.update());

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        HugeAccess access4 = makeAccess(group, target,
                                        HugePermission.DELETE);
        userManager.updateAccess(access4);
    }, e -> {
        Assert.assertContains("Can't save access", e.getMessage());
        Assert.assertContains("that not exists", e.getMessage());
    });
}
 
Example 20
Source File: AccessApiTest.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
@Test
public void testUpdate() {
    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.description("description updated");
    Access updated = api.update(access1);
    Assert.assertEquals("description updated", updated.description());
    Assert.assertNotEquals(access1.updateTime(), updated.updateTime());

    Assert.assertThrows(ServerException.class, () -> {
        Group hk = GroupApiTest.createGroup("group-hk", "");
        access2.group(hk);
        api.update(access2);
    }, e -> {
        Assert.assertContains("The group of access can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Target task = TargetApiTest.createTarget("task",
                                                 HugeResourceType.TASK);
        access2.group(group);
        access2.target(task);
        api.update(access2);
    }, e -> {
        Assert.assertContains("The target of access can't be updated",
                              e.getMessage());
    });

    Assert.assertThrows(ServerException.class, () -> {
        Whitebox.setInternalState(access2, "id", "fake-id");
        api.update(access2);
    }, e -> {
        Assert.assertContains("Invalid access id: fake-id",
                              e.getMessage());
    });
}