@Test
  public void shouldAllowSettingUpConfigurationRepositoryWithAuthenticationProviders()
      throws Exception {
    InMemoryRepositorySource configSource = new InMemoryRepositorySource();
    configSource.setName("config2");
    configSource.setRetryLimit(5);
    configuration.loadFrom(configSource, "workspaceXYZ");
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .authenticator("customAuth")
        .usingClass("org.modeshape.jcr.security.SecurityContextProvider")
        .loadedFromClasspath()
        .setDescription("customAuth Desc");
    configuration.save();
    // Save the configuration and start the engine ...
    engine = configuration.build();
    engine.start();

    ConfigurationDefinition configDefn = configuration.getConfigurationDefinition();
    assertThat(configDefn.getWorkspace(), is("workspaceXYZ"));
    assertThat(configDefn.getPath(), is(path("/")));

    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine.getRepositoryService().getRepositoryLibrary().getSource("config2");
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is("config2"));
    InMemoryRepositorySource configSource2 = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource2.getDefaultWorkspaceName(), is("")); // didn't change this

    Graph graph = engine.getGraph("config2");
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository/mode:authenticationProviders"),
        is(notNullValue()));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }
  @Test
  public void shouldAllowSettingUpConfigurationRepositoryWithDifferentConfigurationSourceName()
      throws Exception {
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test")
        .and()
        .save();

    // Start the engine ...
    engine = configuration.build();
    engine.start();
    // Get a graph to the configuration source ...
    RepositorySource configReposSource =
        engine
            .getRepositoryService()
            .getRepositoryLibrary()
            .getSource(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(configReposSource, is(notNullValue()));
    assertThat(configReposSource, is(instanceOf(InMemoryRepositorySource.class)));
    assertThat(configReposSource.getName(), is(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME));
    InMemoryRepositorySource configSource = (InMemoryRepositorySource) configReposSource;
    assertThat(configSource.getDefaultWorkspaceName(), is(JcrConfiguration.DEFAULT_WORKSPACE_NAME));
    Graph graph = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    assertThat(graph, is(notNullValue()));
    assertThat(graph.getNodeAt("/"), is(notNullValue()));
    assertThat(graph.getNodeAt("/mode:sources"), is(notNullValue()));
    assertThat(
        graph.getNodeAt("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.DESCRIPTION, "description"));
    assertThat(
        graph.getNodeAt("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));

    // Get the repository ...
    JcrRepository repository = engine.getRepository("JCR Repository");
    assertThat(repository, is(notNullValue()));
  }
  @SuppressWarnings("deprecation")
  @Test
  public void shouldAllowSpecifyingOptions() throws Exception {
    configuration
        .repositorySource("Source2")
        .usingClass(InMemoryRepositorySource.class.getName())
        .loadedFromClasspath()
        .setDescription("description")
        .and()
        .repository("JCR Repository")
        .setSource("Source2")
        .setOption(Option.JAAS_LOGIN_CONFIG_NAME, "test");

    engine = configuration.build();
    engine.start();

    // Verify that the graph has been updated correctly ...
    Graph config = engine.getGraph(JcrConfiguration.DEFAULT_CONFIGURATION_SOURCE_NAME);
    Subgraph subgraph = config.getSubgraphOfDepth(6).at("/");
    assertThat(subgraph.getNode("/mode:sources"), is(notNullValue()));
    assertThat(subgraph.getNode("/mode:sources/Source2"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:sources/Source2"),
        hasProperty(ModeShapeLexicon.CLASSNAME, InMemoryRepositorySource.class.getName()));
    assertThat(subgraph.getNode("/mode:repositories"), is(notNullValue()));
    assertThat(subgraph.getNode("/mode:repositories/JCR Repository"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/JCR Repository"),
        hasProperty(ModeShapeLexicon.SOURCE_NAME, "Source2"));
    assertThat(
        subgraph.getNode("/mode:repositories/JCR Repository/mode:options"), is(notNullValue()));
    assertThat(
        subgraph.getNode("/mode:repositories/JCR Repository/mode:options/JAAS_LOGIN_CONFIG_NAME"),
        hasProperty(ModeShapeLexicon.VALUE, "test"));

    JcrRepository repository = engine.getRepository("JCR Repository");

    Map<Option, String> options = new HashMap<Option, String>();
    options.put(Option.JAAS_LOGIN_CONFIG_NAME, "test");
    options.put(Option.PROJECT_NODE_TYPES, DefaultOption.PROJECT_NODE_TYPES);
    options.put(Option.READ_DEPTH, DefaultOption.READ_DEPTH);
    options.put(Option.INDEX_READ_DEPTH, DefaultOption.INDEX_READ_DEPTH);
    options.put(Option.ANONYMOUS_USER_ROLES, DefaultOption.ANONYMOUS_USER_ROLES);
    options.put(
        Option.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES,
        DefaultOption.TABLES_INCLUDE_COLUMNS_FOR_INHERITED_PROPERTIES);
    options.put(Option.QUERY_EXECUTION_ENABLED, DefaultOption.QUERY_EXECUTION_ENABLED);
    options.put(Option.QUERY_INDEX_DIRECTORY, DefaultOption.QUERY_INDEX_DIRECTORY);
    options.put(
        Option.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY,
        DefaultOption.QUERY_INDEXES_UPDATED_SYNCHRONOUSLY);
    options.put(
        Option.PERFORM_REFERENTIAL_INTEGRITY_CHECKS,
        DefaultOption.PERFORM_REFERENTIAL_INTEGRITY_CHECKS);
    options.put(
        Option.EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR,
        DefaultOption.EXPOSE_WORKSPACE_NAMES_IN_DESCRIPTOR);
    options.put(Option.VERSION_HISTORY_STRUCTURE, DefaultOption.VERSION_HISTORY_STRUCTURE);
    options.put(Option.REPOSITORY_JNDI_LOCATION, DefaultOption.REPOSITORY_JNDI_LOCATION);
    options.put(
        Option.USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN,
        DefaultOption.USE_ANONYMOUS_ACCESS_ON_FAILED_LOGIN);
    options.put(
        Option.REBUILD_QUERY_INDEX_ON_STARTUP, DefaultOption.REBUILD_QUERY_INDEX_ON_STARTUP);
    options.put(
        Option.QUERY_INDEXES_REBUILT_SYNCHRONOUSLY,
        DefaultOption.QUERY_INDEXES_REBUILT_SYNCHRONOUSLY);
    String defaultRemoveDerivedValue = DefaultOption.REMOVE_DERIVED_CONTENT_WITH_ORIGINAL;
    if (engine.getSequencingService().getSequencers().isEmpty()) {
      defaultRemoveDerivedValue = Boolean.FALSE.toString();
    }
    options.put(Option.REMOVE_DERIVED_CONTENT_WITH_ORIGINAL, defaultRemoveDerivedValue);
    options.put(
        Option.USE_SECURITY_CONTEXT_CREDENTIALS, DefaultOption.USE_SECURITY_CONTEXT_CREDENTIALS);
    assertThat(repository.getOptions(), is(options));
  }