@Test public void shouldInitializeFromPersistedContent() { // Add some namespaces ... namespaceRegistry.register(validPrefix1, validNamespaceUri1); namespaceRegistry.register(validPrefix2, validNamespaceUri2); assertThat(namespaceRegistry.getNamespaceForPrefix(validPrefix1), is(validNamespaceUri1)); assertThat(namespaceRegistry.getNamespaceForPrefix(validPrefix2), is(validNamespaceUri2)); // Now set up the graph-based namespace registry ... GraphNamespaceRegistry registry2 = new GraphNamespaceRegistry(graph, pathToParentOfNamespaceNodes, uriPropertyName, generatedPropertyName, additionalNamespaceProperties); // All namespaces should match ... Set<NamespaceRegistry.Namespace> all = namespaceRegistry.getNamespaces(); Set<NamespaceRegistry.Namespace> all2 = registry2.getNamespaces(); assertThat(all, is(all2)); assertThat(registry2.getNamespaceForPrefix(validPrefix1), is(validNamespaceUri1)); assertThat(registry2.getNamespaceForPrefix(validPrefix2), is(validNamespaceUri2)); registry2.refresh(); all2 = registry2.getNamespaces(); assertThat(all, is(all2)); assertThat(registry2.getNamespaceForPrefix(validPrefix1), is(validNamespaceUri1)); assertThat(registry2.getNamespaceForPrefix(validPrefix2), is(validNamespaceUri2)); }
/** * {@inheritDoc} * * @see org.modeshape.graph.property.basic.AbstractNamespaceRegistryTest#setUp() */ @Override public void setUp() { super.setUp(); // Set up the context and register any namespaces that we'll be using to manage the namespaces ... context = new ExecutionContext(); NameFactory nameFactory = context.getValueFactories().getNameFactory(); PropertyFactory propertyFactory = context.getPropertyFactory(); context.getNamespaceRegistry().register("nsx", "http://www.example.com/namespaces"); context.getNamespaceRegistry().register("other", "http://www.example.com/other"); uriPropertyName = context.getValueFactories().getNameFactory().create("nsx:uri"); generatedPropertyName = context.getValueFactories().getNameFactory().create("nsx:gen"); additionalNamespaceProperties = new Property[] { propertyFactory.create(nameFactory.create("nsx:something"), "Some value"), propertyFactory.create(nameFactory.create("nsx:something2"), "Some value2"), propertyFactory.create(nameFactory.create("other:something2"), "Some other value2")}; // Set up the repository that we'll be using ... source = new InMemoryRepositorySource(); source.setName("namespace repository"); graph = Graph.create(source, context); // Create the path to the where the namespaces will be managed ... pathToParentOfNamespaceNodes = graph.create("/a").and().create("/a/b").and().createAt("/a/b/c").getLocation().getPath(); // Now set up the graph-based namespace registry ... namespaceRegistry = new GraphNamespaceRegistry(graph, pathToParentOfNamespaceNodes, uriPropertyName, generatedPropertyName, additionalNamespaceProperties); }