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

The following examples show how to use com.baidu.hugegraph.testutil.Assert#assertNotNull() . 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: UsersTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testMatchUser() {
    HugeGraph graph = graph();
    UserManager userManager = graph.userManager();

    String password = StringEncoding.hashPassword("pass1");
    userManager.createUser(makeUser("tom", password));

    Assert.assertNotNull(userManager.matchUser("tom", "pass1"));
    Assert.assertNull(userManager.matchUser("tom", "pass2"));
    Assert.assertNull(userManager.matchUser("Tom", "pass1"));

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        userManager.matchUser("Tom", null);
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        userManager.matchUser(null, "pass1");
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        userManager.matchUser(null, null);
    });
}
 
Example 2
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testAppendVertexLabelWithNullableKeysInAppendProperties() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person")
          .properties("name", "age")
          .primaryKeys("name")
          .create();

    VertexLabel person = schema.vertexLabel("person")
                         .properties("city")
                         .nullableKeys("city")
                         .append();

    Assert.assertNotNull(person);
    Assert.assertEquals("person", person.name());
    Assert.assertEquals(3, person.properties().size());
    assertContainsPk(person.properties(), "name", "age", "city");
    Assert.assertEquals(1, person.primaryKeys().size());
    assertContainsPk(person.primaryKeys(), "name");
    Assert.assertEquals(1, person.nullableKeys().size());
    assertContainsPk(person.nullableKeys(), "city");
}
 
Example 3
Source File: RestClientTest.java    From hugegraph-common with Apache License 2.0 6 votes vote down vote up
@Test
public void testClose() {
    RestClient client = new RestClientImpl("/test", 1000, 10, 5, 200);
    RestResult restResult = client.post("path", "body");
    Assert.assertEquals(200, restResult.status());

    client.close();
    Assert.assertThrows(IllegalStateException.class, () -> {
        client.post("path", "body");
    });

    PoolingHttpClientConnectionManager pool;
    pool = Whitebox.getInternalState(client, "pool");
    Assert.assertNotNull(pool);
    AtomicBoolean isShutDown = Whitebox.getInternalState(pool, "isShutDown");
    Assert.assertTrue(isShutDown.get());

    ScheduledExecutorService cleanExecutor;
    cleanExecutor = Whitebox.getInternalState(client, "cleanExecutor");
    Assert.assertNotNull(cleanExecutor);
    Assert.assertTrue(cleanExecutor.isShutdown());
}
 
Example 4
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveVertexLabel() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .create();

    Assert.assertNotNull(schema.getVertexLabel("person"));

    schema.vertexLabel("person").remove();

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getVertexLabel("person");
    });
}
 
Example 5
Source File: FileLoadTest.java    From hugegraph-loader with Apache License 2.0 6 votes vote down vote up
@Test
public void testIdFieldAsProperty() {
    ioUtil.write("vertex_person.csv",
                 "id,name,age,city",
                 "1,marko,29,Beijing",
                 "2,vadas,27,Hongkong",
                 "3,josh,32,Beijing",
                 "4,peter,35,Shanghai",
                 "5,\"li,nary\",26,\"Wu,han\"");

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

    List<Vertex> vertices = CLIENT.graph().listVertices();
    Assert.assertEquals(5, vertices.size());
    for (Vertex vertex : vertices) {
        Assert.assertNotNull(vertex.property("id"));
    }
}
 
Example 6
Source File: EdgeLabelCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddEdgeLabel() {
    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();
    EdgeLabel look = schema.edgeLabel("look").multiTimes()
                           .properties("time")
                           .link("person", "book")
                           .sortKeys("time")
                           .create();

    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(1, look.properties().size());
    assertContainsPk(look.properties(), "time");
    Assert.assertEquals(1, look.sortKeys().size());
    assertContainsPk(look.sortKeys(), "time");
    Assert.assertEquals(Frequency.MULTIPLE, look.frequency());
}
 
Example 7
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddVertexLabel() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    VertexLabel person = schema.vertexLabel("person")
                               .properties("name", "age", "city")
                               .primaryKeys("name")
                               .create();

    Assert.assertNotNull(person);
    Assert.assertEquals("person", person.name());
    Assert.assertEquals(3, person.properties().size());
    assertContainsPk(person.properties(), "name", "age", "city");
    Assert.assertEquals(1, person.primaryKeys().size());
    assertContainsPk(person.primaryKeys(), "name");
}
 
Example 8
Source File: IndexLabelCoreTest.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddIndexLabelOfEdge() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();
    schema.vertexLabel("author").properties("id", "name")
          .primaryKeys("id").create();
    schema.vertexLabel("book").properties("name")
          .primaryKeys("name").create();
    schema.edgeLabel("authored").singleTime()
          .link("author", "book")
          .properties("contribution")
          .create();

    schema.indexLabel("authoredByContri").onE("authored").secondary()
          .by("contribution").create();

    EdgeLabel authored = schema.getEdgeLabel("authored");
    IndexLabel authoredByContri = schema.getIndexLabel("authoredByContri");

    Assert.assertNotNull(authoredByContri);
    Assert.assertEquals(1, authored.indexLabels().size());
    assertContainsIl(authored.indexLabels(), "authoredByContri");
    Assert.assertEquals(HugeType.EDGE_LABEL, authoredByContri.baseType());
    assertELEqual("authored", authoredByContri.baseValue());
    Assert.assertEquals(IndexType.SECONDARY, authoredByContri.indexType());
}
 
Example 9
Source File: JobApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebuildEdgeLabel() {
    EdgeLabel created = schema().getEdgeLabel("created");
    long taskId = rebuildAPI.rebuild(created);
    Task task = taskAPI.get(taskId);
    Assert.assertNotNull(task);
    Assert.assertEquals(taskId, task.id());
    waitUntilTaskCompleted(taskId);
}
 
Example 10
Source File: JobApiTest.java    From hugegraph-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebuildIndexLabel() {
    IndexLabel personByCity = schema().getIndexLabel("personByAge");
    long taskId = rebuildAPI.rebuild(personByCity);
    Task task = taskAPI.get(taskId);
    Assert.assertNotNull(task);
    Assert.assertEquals(taskId, task.id());
    waitUntilTaskCompleted(taskId);
}
 
Example 11
Source File: IndexLabelCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddIndexLabelOfVertexWithVertexExist() {
    Assume.assumeTrue("Not support range condition query",
                      storeFeatures().supportsQueryWithRangeCondition());
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person").properties("name", "age", "city")
          .primaryKeys("name").create();
    graph().addVertex(T.label, "person", "name", "Baby",
                      "city", "Hongkong", "age", 3);
    graph().tx().commit();

    Assert.assertThrows(NoIndexException.class, () -> {
        graph().traversal().V().hasLabel("person")
               .has("city", "Hongkong").next();
    });

    schema.indexLabel("personByCity").onV("person").secondary()
          .by("city").create();

    Vertex vertex = graph().traversal().V().hasLabel("person")
                           .has("city", "Hongkong").next();
    Assert.assertNotNull(vertex);

    Assert.assertThrows(NoIndexException.class, () -> {
        graph().traversal().V().hasLabel("person")
               .has("age", P.inside(2, 4)).next();
    });
    schema.indexLabel("personByAge").onV("person").range()
          .by("age").create();

    vertex = graph().traversal().V().hasLabel("person")
                    .has("age", P.inside(2, 4)).next();
    Assert.assertNotNull(vertex);
}
 
Example 12
Source File: EdgeLabelCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppendEdgeLabelWithNullableKeysInOriginProperties() {
    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();
    schema.vertexLabel("book").properties("id", "name")
          .primaryKeys("id").create();
    schema.edgeLabel("look")
          .properties("time", "weight")
          .link("person", "book")
          .create();

    EdgeLabel look = schema.edgeLabel("look")
                     .nullableKeys("weight")
                     .append();

    Assert.assertNotNull(look);
    Assert.assertEquals("look", look.name());
    assertVLEqual("person", look.sourceLabel());
    assertVLEqual("book", look.targetLabel());
    Assert.assertEquals(2, look.properties().size());
    assertContainsPk(look.properties(), "time", "weight");
    Assert.assertEquals(1, look.nullableKeys().size());
    assertContainsPk(look.nullableKeys(), "weight");
}
 
Example 13
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveVertexLabelWithVertexAndRangeIndex() {
    Assume.assumeTrue("Not support range condition query",
                      storeFeatures().supportsQueryWithRangeCondition());
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .nullableKeys("city")
          .create();

    schema.indexLabel("personByAge").onV("person").by("age").range()
          .create();

    graph().addVertex(T.label, "person", "name", "marko", "age", 22);
    graph().addVertex(T.label, "person", "name", "jerry", "age", 5);
    graph().addVertex(T.label, "person", "name", "tom", "age", 8);
    graph().tx().commit();

    List<Vertex> vertex = graph().traversal().V().hasLabel("person")
                                 .has("age", P.inside(4, 10)).toList();
    Assert.assertNotNull(vertex);
    Assert.assertEquals(2, vertex.size());

    schema.vertexLabel("person").remove();

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getVertexLabel("person");
    });

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("personByAge");
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph().traversal().V().hasLabel("person").toList();
    });
}
 
Example 14
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testRowLock() {
    RowLock<?> lock = this.group.rowLock("lock");
    Assert.assertNotNull(lock);
    RowLock<?> lock1 = this.group.rowLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 15
Source File: LockGroupTest.java    From hugegraph-common with Apache License 2.0 5 votes vote down vote up
@Test
public void testKeyLockWithSize() {
    KeyLock lock = this.group.keyLock("lock", 10);
    Assert.assertNotNull(lock);
    KeyLock lock1 = this.group.keyLock("lock");
    Assert.assertSame(lock, lock1);
}
 
Example 16
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveVertexLabelWithVertex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .nullableKeys("city")
          .create();

    graph().addVertex(T.label, "person", "name", "marko", "age", 22);
    graph().addVertex(T.label, "person", "name", "jerry", "age", 5);
    graph().addVertex(T.label, "person", "name", "tom", "age", 8);
    graph().tx().commit();

    List<Vertex> vertex = graph().traversal().V().hasLabel("person")
                                 .toList();
    Assert.assertNotNull(vertex);
    Assert.assertEquals(3, vertex.size());

    schema.vertexLabel("person").remove();

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getVertexLabel("person");
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph().traversal().V().hasLabel("person").toList();
    });
}
 
Example 17
Source File: EdgeLabelCoreTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testAddEdgeLabelWithTtl() {
    super.initPropertyKeys();

    SchemaManager schema = graph().schema();

    schema.propertyKey("date").asDate().ifNotExist().create();

    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .nullableKeys("city")
          .create();

    schema.vertexLabel("book")
          .properties("name")
          .primaryKeys("name")
          .create();

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book")
              .properties("date", "weight")
              .ttl(-86400L)
              .create();
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book")
              .properties("date", "weight")
              .ttlStartTime("date")
              .create();
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book")
              .properties("date", "weight")
              .ttlStartTime("name")
              .create();
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        schema.edgeLabel("read").link("person", "book")
              .properties("date", "weight")
              .ttlStartTime("weight")
              .create();
    });

    EdgeLabel read = schema.edgeLabel("read").link("person", "book")
                           .properties("date", "weight")
                           .ttl(86400L)
                           .create();

    Assert.assertNotNull(read);
    Assert.assertEquals("read", read.name());
    assertVLEqual("person", read.sourceLabel());
    assertVLEqual("book", read.targetLabel());
    Assert.assertEquals(2, read.properties().size());
    assertContainsPk(read.properties(), "date", "weight");
    Assert.assertEquals(0, read.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, read.frequency());
    Assert.assertEquals(86400L, read.ttl());
    Assert.assertEquals(IdGenerator.ZERO, read.ttlStartTime());

    EdgeLabel write = schema.edgeLabel("write").link("person", "book")
                            .properties("date", "weight")
                            .ttl(86400L)
                            .ttlStartTime("date")
                            .create();

    Assert.assertNotNull(write);
    Assert.assertEquals("write", write.name());
    assertVLEqual("person", write.sourceLabel());
    assertVLEqual("book", write.targetLabel());
    Assert.assertEquals(2, write.properties().size());
    assertContainsPk(write.properties(), "date", "weight");
    Assert.assertEquals(0, write.sortKeys().size());
    Assert.assertEquals(Frequency.SINGLE, write.frequency());
    Assert.assertEquals(86400L, write.ttl());
    Assert.assertNotNull(write.ttlStartTime());
    assertContainsPk(ImmutableSet.of(write.ttlStartTime()), "date");
}
 
Example 18
Source File: BaseClientTest.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
public static GremlinManager gremlin() {
    Assert.assertNotNull("Not opened client", client);
    return client.gremlin();
}
 
Example 19
Source File: BaseClientTest.java    From hugegraph-client with Apache License 2.0 4 votes vote down vote up
public static TaskManager task() {
    Assert.assertNotNull("Not opened client", client);
    return client.task();
}
 
Example 20
Source File: VertexLabelCoreTest.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testRemoveVertexLabelWithVertexAndSecondaryIndex() {
    super.initPropertyKeys();
    SchemaManager schema = graph().schema();

    schema.vertexLabel("person")
          .properties("name", "age", "city")
          .primaryKeys("name")
          .nullableKeys("age")
          .create();

    schema.indexLabel("personByCity").onV("person").by("city").secondary()
          .create();

    graph().addVertex(T.label, "person", "name", "marko",
                      "city", "Beijing");
    graph().addVertex(T.label, "person", "name", "jerry",
                      "city", "Beijing");
    graph().addVertex(T.label, "person", "name", "tom",
                      "city", "HongKong");
    graph().tx().commit();

    List<Vertex> vertex = graph().traversal().V().hasLabel("person")
                                 .has("city", "Beijing").toList();
    Assert.assertNotNull(vertex);
    Assert.assertEquals(2, vertex.size());

    schema.vertexLabel("person").remove();

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getVertexLabel("person");
    });

    Assert.assertThrows(NotFoundException.class, () -> {
        schema.getIndexLabel("personByCity");
    });

    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph().traversal().V().hasLabel("person").toList();
    });
}