@Test
 public void testMockInstanceValue() {
   AccumuloGraphConfiguration conf =
       new AccumuloGraphConfiguration().setInstanceType(InstanceType.Mock);
   assertNotNull(conf.getInstanceName());
   assertEquals("mock-instance", conf.getInstanceName());
 }
 @Test
 public void testPreloadedProperties() {
   // Don't allow "all" and "some" preloaded properties.
   AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();
   conf.setPreloadAllProperties(true);
   conf.setPreloadedProperties(new String[] {"one", "two", "three"});
   try {
     conf.validate();
     fail();
   } catch (Exception e) {
   }
 }
  @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 testImmutableConnector() throws Exception {
    AccumuloGraphConfiguration cfg =
        new AccumuloGraphConfiguration()
            .setInstanceType(InstanceType.Mock)
            .setGraphName("immutableConnector")
            .setCreate(true)
            .setAutoFlush(false);

    cfg.getConnector();

    try {
      cfg.setCreate(false);
      fail();
    } catch (Exception e) {
    }

    try {
      cfg.setAutoFlush(true);
      fail();
    } catch (Exception e) {
    }

    assertTrue(cfg.getCreate());
    assertFalse(cfg.getAutoFlush());
  }
  /**
   * Test different kinds of graph names (hyphens, punctuation, etc).
   *
   * @throws Exception
   */
  @Test
  public void testGraphNames() throws Exception {
    AccumuloGraphConfiguration conf = new AccumuloGraphConfiguration();

    String[] valid =
        new String[] {
          "alpha", "12345", "alnum12345",
          "12345alnum", "under_score1", "_under_score_2"
        };
    String[] invalid = new String[] {"hyph-en", "dot..s", "quo\"tes"};

    for (String name : valid) {
      conf.setGraphName(name);
    }

    for (String name : invalid) {
      try {
        conf.setGraphName(name);
        fail();
      } catch (Exception e) {
      }
    }
  }
  @Test
  public void testConfigurationInterface() throws Exception {
    Configuration conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsValid");
    for (String key : AccumuloGraphConfiguration.getValidInternalKeys()) {
      // This is bad... but we should allow them if they are valid keys.
      conf.setProperty(key, "value");
    }

    conf = AccumuloGraphTestUtils.generateGraphConfig("setPropsInvalid");
    try {
      conf.setProperty("invalidKey", "value");
      fail();
    } catch (Exception e) {
    }
  }
  @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();
  }
  @Test
  public void testInvalidCacheParams() throws Exception {
    int size = 100;
    int timeout = 30000;

    AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("cacheParams");
    cfg.validate();

    // Vertex cache.

    assertFalse(cfg.getVertexCacheEnabled());

    try {
      cfg.setVertexCacheParams(-1, timeout);
      fail();
    } catch (Exception e) {
    }

    try {
      cfg.setVertexCacheParams(size, -1);
      fail();
    } catch (Exception e) {
    }

    assertFalse(cfg.getVertexCacheEnabled());

    cfg.setVertexCacheParams(size, timeout);
    cfg.validate();
    assertTrue(cfg.getVertexCacheEnabled());
    assertEquals(size, cfg.getVertexCacheSize());
    assertEquals(timeout, cfg.getVertexCacheTimeout());

    cfg.setVertexCacheParams(-1, -1);
    cfg.validate();
    assertFalse(cfg.getVertexCacheEnabled());

    // Edge cache.

    assertFalse(cfg.getEdgeCacheEnabled());

    try {
      cfg.setEdgeCacheParams(-1, timeout);
      fail();
    } catch (Exception e) {
    }

    try {
      cfg.setEdgeCacheParams(size, -1);
      fail();
    } catch (Exception e) {
    }

    assertFalse(cfg.getEdgeCacheEnabled());

    cfg.setEdgeCacheParams(size, timeout);
    cfg.validate();
    assertTrue(cfg.getEdgeCacheEnabled());
    assertEquals(size, cfg.getEdgeCacheSize());
    assertEquals(timeout, cfg.getEdgeCacheTimeout());

    cfg.setEdgeCacheParams(-1, -1);
    cfg.validate();
    assertFalse(cfg.getEdgeCacheEnabled());
  }
 @Test
 public void testPrint() throws Exception {
   AccumuloGraphConfiguration cfg = AccumuloGraphTestUtils.generateGraphConfig("printTest");
   cfg.print();
 }