// 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 out the repository, since we only need a few methods ...
repoTypeManager = new RepositoryNodeTypeManager(context);
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"));
stub(repository.getRepositoryTypeManager()).toReturn(repoTypeManager);
stub(repository.getRepositorySourceName()).toReturn(repositorySourceName);
stub(repository.getPersistentRegistry()).toReturn(context.getNamespaceRegistry());
stub(repository.createWorkspaceGraph(anyString())).toAnswer(new Answer<Graph>() {