// Set up the execution context ...
context = new ExecutionContext();
// Register the test namespace
context.getNamespaceRegistry().register(TestLexicon.Namespace.PREFIX, TestLexicon.Namespace.URI);
PathFactory pathFactory = context.getValueFactories().getPathFactory();
// Set up the initial content ...
graph = Graph.create(source, context);
// Make sure the path to the namespaces exists ...
graph.create("/jcr:system").and(); // .and().create("/jcr:system/dna:namespaces");
graph.set("jcr:primaryType").on("/jcr:system").to(DnaLexicon.SYSTEM);
graph.create("/jcr:system/dna:namespaces").and();
graph.set("jcr:primaryType").on("/jcr:system/dna:namespaces").to(DnaLexicon.NAMESPACES);
// Add the built-ins, ensuring we overwrite any badly-initialized values ...
for (Map.Entry<String, String> builtIn : JcrNamespaceRegistry.STANDARD_BUILT_IN_NAMESPACES_BY_PREFIX.entrySet()) {
context.getNamespaceRegistry().register(builtIn.getKey(), builtIn.getValue());
}
initializeContent();
// Stub out the connection factory ...
connectionFactory = new RepositoryConnectionFactory() {
/**
* {@inheritDoc}
*
* @see org.jboss.dna.graph.connector.RepositoryConnectionFactory#createConnection(java.lang.String)
*/
public RepositoryConnection createConnection( String sourceName ) throws RepositorySourceException {
return repositorySourceName.equals(sourceName) ? source.getConnection() : null;
}
};
stub(repository.getExecutionContext()).toReturn(context);
stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
stub(repository.getPersistentRegistry()).toReturn(context.getNamespaceRegistry());
stub(repository.createWorkspaceGraph(anyString(), (ExecutionContext)anyObject())).toAnswer(new Answer<Graph>() {
public Graph answer( InvocationOnMock invocation ) throws Throwable {
return graph;
}
});
stub(repository.createSystemGraph(context)).toAnswer(new Answer<Graph>() {
public Graph answer( InvocationOnMock invocation ) throws Throwable {
return graph;
}
});
stub(this.repository.getRepositoryObservable()).toReturn(new MockObservable());
// Stub out the repository, since we only need a few methods ...
repoTypeManager = new RepositoryNodeTypeManager(repository, true);
stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
try {
this.repoTypeManager.registerNodeTypes(new CndNodeTypeSource(new String[] {"/org/jboss/dna/jcr/jsr_170_builtins.cnd",
"/org/jboss/dna/jcr/dna_builtins.cnd"}));
this.repoTypeManager.registerNodeTypes(new NodeTemplateNodeTypeSource(getTestTypes()));
} catch (RepositoryException re) {
re.printStackTrace();
throw new IllegalStateException("Could not load node type definition files", re);
} catch (IOException ioe) {
ioe.printStackTrace();
throw new IllegalStateException("Could not access node type definition files", ioe);
}
this.repoTypeManager.projectOnto(graph, pathFactory.create("/jcr:system/jcr:nodeTypes"));
Path locksPath = pathFactory.createAbsolutePath(JcrLexicon.SYSTEM, DnaLexicon.LOCKS);
workspaceLockManager = new WorkspaceLockManager(context, repository, workspaceName, locksPath);
stub(repository.getLockManager(anyString())).toAnswer(new Answer<WorkspaceLockManager>() {
public WorkspaceLockManager answer( InvocationOnMock invocation ) throws Throwable {
return workspaceLockManager;