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

The following examples show how to use com.baidu.hugegraph.testutil.Assert#assertFalse() . 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 vote down vote up
@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: FlatMapperIteratorTest.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
@Test
public void testHasNextAndNextWithMultiTimes() {
    Iterator<String> keys = DATA.keySet().iterator();

    Iterator<Integer> results = new FlatMapperIterator<>(keys, MAPPER);

    for (int i = 0; i < 12; i++) {
        Assert.assertTrue(results.hasNext());
    }

    for (int i = 0; i < 10; i++) {
        results.next();
    }

    Assert.assertFalse(results.hasNext());
    Assert.assertFalse(results.hasNext());

    Assert.assertThrows(NoSuchElementException.class, () -> {
        results.next();
    });
    Assert.assertThrows(NoSuchElementException.class, () -> {
        results.next();
    });
}
 
Example 3
Source File: EdgeIdTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testEdgeIdEqualWithDirection() {
    EdgeId edgeId1 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT,
                                IdGenerator.of(1), "",
                                IdGenerator.of("1:josh"), true);
    EdgeId edgeId2 = new EdgeId(IdGenerator.of("1:marko"), Directions.OUT,
                                IdGenerator.of(1), "",
                                IdGenerator.of("1:josh"), true);
    EdgeId edgeId3 = new EdgeId(IdGenerator.of("1:josh"), Directions.IN,
                                IdGenerator.of(1), "",
                                IdGenerator.of("1:marko"), true);
    Assert.assertTrue(edgeId1.equals(edgeId2));
    Assert.assertTrue(edgeId2.equals(edgeId1));
    Assert.assertFalse(edgeId1.equals(edgeId3));
    Assert.assertFalse(edgeId3.equals(edgeId1));
}
 
Example 4
Source File: PropertyCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Override
protected <V> V propertySet(String key, Object... values) {
    HugeGraph graph = graph();
    Vertex vertex1 = graph.addVertex(T.label, "person", "id", 1);
    Vertex vertex2 = graph.addVertex(T.label, "person", "id", 2);
    key = "set_" + key;
    Edge edge = vertex1.addEdge("transfer", vertex2, "id", 3,
                                key, Arrays.asList(values));
    graph.tx().commit();

    edge = graph.edges(edge.id()).next();
    Assert.assertTrue(TraversalUtil.testProperty(edge.property(key),
                                    ImmutableSet.copyOf(values)));
    Assert.assertFalse(TraversalUtil.testProperty(edge.property(key),
                                     ImmutableList.copyOf(values)));
    return edge.value(key);
}
 
Example 5
Source File: EventHubTest.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
@Test
public void testEventRemoveListener() {
    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(1, this.eventHub.unlisten(event, listener));

    Assert.assertFalse(this.eventHub.containsListener(event));
    Assert.assertEquals(0, this.eventHub.listeners(event).size());
}
 
Example 6
Source File: CollectionUtilTest.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
@Test
public void testHasIntersectionBetweenSetAndSet() {
    Set<Integer> first = new HashSet<>();
    first.add(1);
    first.add(2);
    first.add(3);

    Set<Integer> second = new HashSet<>();
    Assert.assertFalse(CollectionUtil.hasIntersection(first, second));

    second.add(4);
    Assert.assertFalse(CollectionUtil.hasIntersection(first, second));

    second.add(1);
    Assert.assertTrue(CollectionUtil.hasIntersection(first, second));
}
 
Example 7
Source File: EventHubTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testEventRemoveListenerOfOneInTwo() {
    final String event1 = "event-test1";
    final String event2 = "event-test2";

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

    this.eventHub.listen(event1, listener);
    this.eventHub.listen(event2, listener);

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

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

    Assert.assertEquals(1, this.eventHub.unlisten(event1, listener));

    Assert.assertFalse(this.eventHub.containsListener(event1));
    Assert.assertFalse(this.eventHub.containsListener(event1));
    Assert.assertEquals(0, this.eventHub.listeners(event1).size());

    Assert.assertTrue(this.eventHub.containsListener(event2));
    Assert.assertEquals(1, this.eventHub.listeners(event2).size());
    Assert.assertEquals(listener, this.eventHub.listeners(event2).get(0));
}
 
Example 8
Source File: BytesTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testBytesContains() {
    Assert.assertTrue(Bytes.contains(b("1234"), (byte) '1'));
    Assert.assertTrue(Bytes.contains(b("1234"), (byte) '3'));
    Assert.assertTrue(Bytes.contains(b("1234"), (byte) '4'));

    Assert.assertFalse(Bytes.contains(b("1234"), (byte) '0'));
    Assert.assertFalse(Bytes.contains(b(""), (byte) '0'));
}
 
Example 9
Source File: IdTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testObjectId() {
    Object object = ByteBuffer.wrap(new byte[]{1, 2});
    Object object2 = ByteBuffer.wrap(new byte[]{2, 2});
    Id id = IdGenerator.of(object);
    Assert.assertEquals(IdType.UNKNOWN, id.type());
    Assert.assertEquals(object, id.asObject());
    Assert.assertEquals(object.hashCode(), id.hashCode());
    Assert.assertEquals(object.toString(), id.toString());
    Assert.assertTrue(id.equals(IdGenerator.of(object)));
    Assert.assertFalse(id.equals(IdGenerator.of(object2)));
    Assert.assertFalse(id.equals(object));

    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.asString();
    });
    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.asLong();
    });
    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.asBytes();
    });
    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.compareTo(id);
    });
    Assert.assertThrows(UnsupportedOperationException.class, () -> {
        id.length();
    });
}
 
Example 10
Source File: VersionUtilTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testVersionGte() {
    String version = "0.2";

    Assert.assertTrue(VersionUtil.gte(version, "0.2"));
    Assert.assertTrue(VersionUtil.gte(version, "0.2.0"));
    Assert.assertTrue(VersionUtil.gte(version, "0.1"));
    Assert.assertTrue(VersionUtil.gte(version, "0.1.9"));
    Assert.assertTrue(VersionUtil.gte(version, "0.0.3"));

    Assert.assertFalse(VersionUtil.gte(version, "0.2.0.1"));
    Assert.assertFalse(VersionUtil.gte(version, "0.2.1"));
    Assert.assertFalse(VersionUtil.gte(version, "0.3"));
    Assert.assertFalse(VersionUtil.gte(version, "0.10"));
}
 
Example 11
Source File: MapperIteratorTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testClose() throws Exception {
    CloseableItor<String> keys = new CloseableItor<>(
                                 ImmutableList.of("fifth").iterator());

    MapperIterator<String, Integer> results =
                                    new MapperIterator<>(keys, k -> null);

    Assert.assertFalse(keys.closed());
    results.close();
    Assert.assertTrue(keys.closed());
}
 
Example 12
Source File: RolePermissionTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testHugeResourceFilterUser() {
    HugeResource all = HugeResource.ALL;

    // user
    ResourceObject<?> r3 = ResourceObject.of("g1", ResourceType.USER_GROUP,
                                             NameObject.ANY);
    Assert.assertFalse(all.filter(r3));

    HugeResource user = new HugeResource(ResourceType.USER_GROUP,
                                         HugeResource.ANY, null);
    Assert.assertTrue(user.filter(r3));

    ResourceObject<?> r4 = ResourceObject.of("g1", new HugeUser("fake"));
    Assert.assertTrue(user.filter(r4));

    HugeResource user2 = new HugeResource(ResourceType.USER_GROUP,
                                          "bj-.*", null);
    Assert.assertTrue(user2.filter(r3));
    Assert.assertFalse(user2.filter(r4));

    HugeResource user3 = new HugeResource(ResourceType.USER_GROUP,
                                          "fa.*", null);
    Assert.assertTrue(user3.filter(r3));
    Assert.assertTrue(user3.filter(r4));

    ResourceObject<?> r5 = ResourceObject.of("g1", new HugeTarget("g", ""));
    Assert.assertFalse(user.filter(r5));

    HugeResource root = new HugeResource(ResourceType.ROOT,
                                         HugeResource.ANY, null);
    Assert.assertTrue(root.filter(r3));
    Assert.assertTrue(root.filter(r4));
    Assert.assertTrue(root.filter(r5));
}
 
Example 13
Source File: ConditionTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testConditionAnd() {
    Condition c1 = Condition.gt(HugeKeys.ID, 18);
    Condition c2 = Condition.lt(HugeKeys.ID, 30);
    Condition c3 = c1.and(c2);
    Assert.assertEquals(Condition.and(c1, c2), c3);
    Assert.assertTrue(c3.test(19));
    Assert.assertTrue(c3.test(20));
    Assert.assertTrue(c3.test(29));
    Assert.assertFalse(c3.test(17));
    Assert.assertFalse(c3.test(18));
    Assert.assertFalse(c3.test(30));
    Assert.assertFalse(c3.test(31));
    Assert.assertFalse(c3.test((Object) null)); // null means 0
}
 
Example 14
Source File: ListIteratorTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasNext() {
    Iterator<Integer> origin = DATA1.iterator();
    Assert.assertTrue(origin.hasNext());

    Iterator<Integer> results = new ListIterator<>(-1, origin);
    Assert.assertTrue(results.hasNext());
    Assert.assertTrue(results.hasNext());
    Assert.assertFalse(origin.hasNext());
}
 
Example 15
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 16
Source File: BatchMapperIteratorTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapperReturnNullThenHasNext() {
    Iterator<Integer> results;

    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        return null;
    });
    Assert.assertFalse(results.hasNext());
    Assert.assertFalse(results.hasNext());
}
 
Example 17
Source File: RolePermissionTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testHugeResourceFilterVertexOrEdge() {
    HugeResource all = HugeResource.ALL;

    // vertex & edge
    FakeObjects fo = new FakeObjects();
    HugeEdge edge = fo.newEdge(1, 2);
    ResourceObject<?> r1 = ResourceObject.of("g1", edge.sourceVertex());
    ResourceObject<?> r2 = ResourceObject.of("g1", edge.targetVertex());
    ResourceObject<?> r3 = ResourceObject.of("g1", edge);

    Assert.assertTrue(all.filter(r1));
    Assert.assertTrue(all.filter(r2));
    Assert.assertTrue(all.filter(r3));

    HugeResource vr = new HugeResource(ResourceType.VERTEX,
                                       HugeResource.ANY, null);
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX,
                          "person", null);
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX,
                          "person", ImmutableMap.of("city", "Beijing"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertFalse(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX,
                          "person", ImmutableMap.of("city", "Shanghai"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX, "person", ImmutableMap.of(
                          "city", "P.within(\"Beijing\", \"Shanghai\")"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX, "person",
                          ImmutableMap.of("age", "P.gt(18)"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX, "person",
                          ImmutableMap.of("age", "P.between(20, 21)"));
    Assert.assertFalse(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    vr = new HugeResource(ResourceType.VERTEX, "person",
                          ImmutableMap.of("age", "P.between(18, 21)"));
    Assert.assertTrue(vr.filter(r1));
    Assert.assertTrue(vr.filter(r2));
    Assert.assertFalse(vr.filter(r3));

    HugeResource er = new HugeResource(ResourceType.EDGE,
                                       "knows", null);
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));

    er = new HugeResource(ResourceType.EDGE,
                          "knows", ImmutableMap.of("weight", "P.gt(0.7)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));

    er = new HugeResource(ResourceType.EDGE,
                          "knows", ImmutableMap.of("weight", "P.gt(0.8)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertFalse(er.filter(r3));

    er = new HugeResource(ResourceType.EDGE,
                          "knows", ImmutableMap.of("weight", "P.lt(0.8)"));
    Assert.assertFalse(er.filter(r1));
    Assert.assertFalse(er.filter(r2));
    Assert.assertTrue(er.filter(r3));
}
 
Example 18
Source File: CacheTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
protected void checkNotInCache(Cache<Id, Object> cache, Id id) {
    Assert.assertFalse(cache.containsKey(id));
}
 
Example 19
Source File: ConditionTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testConditionEqWithUserprop() {
    Condition c1 = Condition.eq(IdGenerator.of("1"), "123");

    Assert.assertEquals("1 == 123", c1.toString());

    Assert.assertTrue(c1.isRelation());
    Assert.assertFalse(c1.isSysprop());
    Assert.assertTrue(c1.isFlattened());
    Assert.assertFalse(c1.isLogic());
    Assert.assertTrue(c1.test("123"));
    Assert.assertFalse(c1.test("1234"));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(new Date(123)));
    Assert.assertFalse(c1.test((Object) null));

    Relation r1 = (Relation) c1;
    Assert.assertEquals(IdGenerator.of("1"), r1.key());
    Assert.assertEquals("123", r1.value());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertEquals(RelationType.EQ, r1.relation());
    Assert.assertTrue(r1.test("123"));

    Relation r2 = (Relation) c1.copy();
    Assert.assertEquals(r1, r2);
    Assert.assertEquals(IdGenerator.of("1"), r2.key());
    Assert.assertEquals("123", r2.value());
    Assert.assertEquals("123", r2.serialValue());
    Assert.assertEquals(RelationType.EQ, r2.relation());
    Assert.assertTrue(r2.test("123"));

    r2.serialValue("1234");
    Assert.assertEquals("1234", r2.serialValue());
    Assert.assertEquals("123", r1.serialValue());
    Assert.assertTrue(r2.test("123"));

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.eq(IdGenerator.of("1"), null).test("any");
    }, e -> {
        Assert.assertEquals("Can't test null value for `==`",
                            e.getMessage());
    });
}
 
Example 20
Source File: ListIteratorTest.java    From hugegraph-common with Apache License 2.0 3 votes vote down vote up
@Test
public void testClose() throws Exception {
    CloseableItor<Integer> c1 = new CloseableItor<>(DATA1.iterator());

    ListIterator<Integer> results = new ListIterator<>(-1, c1);

    Assert.assertFalse(c1.closed());

    results.close();

    Assert.assertTrue(c1.closed());
}