Index: modeshape-graph/src/main/java/org/modeshape/graph/connector/inmemory/InMemoryRepositorySource.java =================================================================== --- modeshape-graph/src/main/java/org/modeshape/graph/connector/inmemory/InMemoryRepositorySource.java (revision 1814) +++ modeshape-graph/src/main/java/org/modeshape/graph/connector/inmemory/InMemoryRepositorySource.java (working copy) @@ -268,10 +268,16 @@ public class InMemoryRepositorySource implements BaseRepositorySource, ObjectFac ExecutionContext context = repositoryContext != null ? repositoryContext.getExecutionContext() : defaultContext; repository = new InMemoryRepository(context, name, rootNodeUuid, defaultWorkspaceName); - // Create the set of initial workspaces ... - for (String initialName : getPredefinedWorkspaceNames()) { - repository.createWorkspace(null, initialName, CreateConflictBehavior.DO_NOT_CREATE, null); + InMemoryTransaction txn = repository.startTransaction(context, false); + try { + // Create the set of initial workspaces ... + for (String initialName : getPredefinedWorkspaceNames()) { + repository.createWorkspace(txn, initialName, CreateConflictBehavior.DO_NOT_CREATE, null); + } + } finally { + txn.commit(); } + } return new Connection(this, repository); } Index: modeshape-graph/src/test/java/org/modeshape/graph/connector/inmemory/InMemoryRepositorySourceTest.java new file mode 100644 =================================================================== --- /dev/null (revision 1814) +++ modeshape-graph/src/test/java/org/modeshape/graph/connector/inmemory/InMemoryRepositorySourceTest.java (working copy) @@ -0,0 +1,44 @@ +package org.modeshape.graph.connector.inmemory; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.modeshape.graph.ExecutionContext; +import org.modeshape.graph.connector.RepositoryConnection; +import org.modeshape.graph.request.GetWorkspacesRequest; + +public class InMemoryRepositorySourceTest { + + private ExecutionContext context; + private InMemoryRepositorySource source; + private String[] predefinedWorkspaces = new String[] {"foo", "bar", "baz"}; + + @Before + public void beforeEach() { + context = new ExecutionContext(); + + source = new InMemoryRepositorySource(); + source.setName("In-Memory Repository Source"); + source.setPredefinedWorkspaceNames(predefinedWorkspaces); + // Have to do this or the comparison later will be off when the default workspace is also created + source.setDefaultWorkspaceName(predefinedWorkspaces[0]); + } + + @Test + public void shouldCreatePredefinedWorkspaces() { + RepositoryConnection connection = source.getConnection(); + + GetWorkspacesRequest request = new GetWorkspacesRequest(); + connection.execute(context, request); + + Set workspaces = request.getAvailableWorkspaceNames(); + Set graphWorkspaces = new HashSet(Arrays.asList(predefinedWorkspaces)); + assertThat(workspaces, is(graphWorkspaces)); + + } + +}