@Test
  public void testCreateAndClear() throws Exception {
    AccumuloGraphConfiguration cfg =
        AccumuloGraphTestUtils.generateGraphConfig("noCreate").setCreate(false);
    try {
      new AccumuloGraph(cfg);
      fail("Create is disabled and graph does not exist");
    } catch (Exception e) {
      assertTrue(true);
    }

    cfg = AccumuloGraphTestUtils.generateGraphConfig("yesCreate").setCreate(true);
    for (String t : cfg.getTableNames()) {
      assertFalse(cfg.getConnector().tableOperations().exists(t));
    }
    AccumuloGraph graph = new AccumuloGraph(cfg);
    for (String t : cfg.getTableNames()) {
      assertTrue(cfg.getConnector().tableOperations().exists(t));
    }
    graph.shutdown();

    graph = new AccumuloGraph(cfg.clone().setCreate(false));
    assertTrue(graph.isEmpty());
    graph.addVertex("A");
    graph.addVertex("B");
    assertFalse(graph.isEmpty());
    graph.shutdown();

    graph = new AccumuloGraph(cfg.clone().setClear(true));
    assertTrue(graph.isEmpty());
    graph.shutdown();
  }
  @Test
  public void testSplits() throws Exception {
    AccumuloGraphConfiguration cfg;

    // Tests for splits string.
    cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplits").setSplits((String) null);
    AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
    }
    graph.shutdown();

    cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplits").setSplits("");
    graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
    }
    graph.shutdown();

    cfg = AccumuloGraphTestUtils.generateGraphConfig("threeSplits").setSplits(" a b c ");
    graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
      assertEquals(3, splits.size());
      List<Text> arr = new ArrayList<Text>(splits);
      assertEquals("a", arr.get(0).toString());
      assertEquals("b", arr.get(1).toString());
      assertEquals("c", arr.get(2).toString());
    }
    graph.shutdown();

    // Tests for splits array.
    cfg = AccumuloGraphTestUtils.generateGraphConfig("nullSplitsArray").setSplits((String[]) null);
    graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
    }
    graph.shutdown();

    cfg = AccumuloGraphTestUtils.generateGraphConfig("emptySplitsArray").setSplits(new String[] {});
    graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      assertEquals(0, cfg.getConnector().tableOperations().listSplits(table).size());
    }
    graph.shutdown();

    cfg =
        AccumuloGraphTestUtils.generateGraphConfig("threeSplitsArray")
            .setSplits(new String[] {"d", "e", "f"});
    graph = (AccumuloGraph) GraphFactory.open(cfg.getConfiguration());
    for (String table : cfg.getTableNames()) {
      Collection<Text> splits = cfg.getConnector().tableOperations().listSplits(table);
      assertEquals(3, splits.size());
      List<Text> arr = new ArrayList<Text>(splits);
      assertEquals("d", arr.get(0).toString());
      assertEquals("e", arr.get(1).toString());
      assertEquals("f", arr.get(2).toString());
    }
    graph.shutdown();
  }