[dna-commits] DNA SVN: r476 - in trunk: extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation and 2 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Wed Aug 27 10:41:53 EDT 2008


Author: rhauch
Date: 2008-08-27 10:41:52 -0400 (Wed, 27 Aug 2008)
New Revision: 476

Added:
   trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
Modified:
   trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
   trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
Log:
DNA-212 - Create test for the federation connector that uses all the components of the connector
http://jira.jboss.com/jira/browse/DNA-212

Added an integration test that puts the FederatedRepositorySource (and its components) through some paces.  More tests will be required, as more is done to merge nodes.

Modified: trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java
===================================================================
--- trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java	2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/dna-spi/src/test/java/org/jboss/dna/spi/connector/SimpleRepositorySource.java	2008-08-27 14:41:52 UTC (rev 476)
@@ -33,13 +33,17 @@
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.spi.ExecutionContext;
 import org.jboss.dna.spi.cache.CachePolicy;
-import org.jboss.dna.spi.graph.InvalidPathException;
 import org.jboss.dna.spi.graph.Name;
 import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
 import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.ActsOnPath;
+import org.jboss.dna.spi.graph.commands.CreateNodeCommand;
+import org.jboss.dna.spi.graph.commands.DeleteBranchCommand;
 import org.jboss.dna.spi.graph.commands.GetChildrenCommand;
 import org.jboss.dna.spi.graph.commands.GetPropertiesCommand;
 import org.jboss.dna.spi.graph.commands.GraphCommand;
+import org.jboss.dna.spi.graph.commands.SetPropertiesCommand;
 import org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor;
 import org.jboss.dna.spi.graph.commands.executor.CommandExecutor;
 import org.jboss.dna.spi.graph.impl.BasicSingleValueProperty;
@@ -315,12 +319,10 @@
         @Override
         public void execute( GetChildrenCommand command ) throws RepositorySourceException {
             Path targetPath = command.getPath();
+            Map<Name, Property> properties = getProperties(command);
+            if (properties == null) return;
+            // Iterate through all of the properties, looking for any paths that are children of the path ...
             Map<Path, Map<Name, Property>> data = repository.getData();
-            if (data.get(targetPath) == null) {
-                command.setError(new InvalidPathException("Non-existant node: " + targetPath));
-                return;
-            }
-            // Iterate through all of the properties, looking for any paths that are children of the path ...
             List<Path.Segment> childSegments = new LinkedList<Path.Segment>();
             for (Path path : data.keySet()) {
                 if (!path.isRoot() && path.getParent().equals(targetPath)) {
@@ -330,8 +332,8 @@
             // This does not store children order, so sort ...
             Collections.sort(childSegments);
             for (Path.Segment childSegment : childSegments) {
-                Map<Name, Property> properties = repository.getData().get(targetPath);
-                Property uuidProperty = properties.get(uuidPropertyName);
+                Map<Name, Property> childProperties = repository.getData().get(targetPath);
+                Property uuidProperty = childProperties.get(uuidPropertyName);
                 command.addChild(childSegment,
                                  uuidProperty == null ? new BasicSingleValueProperty(uuidPropertyName, UUID.randomUUID()) : uuidProperty);
             }
@@ -344,18 +346,82 @@
          */
         @Override
         public void execute( GetPropertiesCommand command ) throws RepositorySourceException {
+            Map<Name, Property> properties = getProperties(command);
+            if (properties == null) return;
+            for (Property property : properties.values()) {
+                if (!property.getName().equals(this.uuidPropertyName)) {
+                    command.setProperty(property);
+                }
+            }
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.CreateNodeCommand)
+         */
+        @Override
+        public void execute( CreateNodeCommand command ) throws RepositorySourceException {
             Path targetPath = command.getPath();
+            ExecutionContext context = getExecutionContext();
+            repository.create(context, targetPath.getString(context.getNamespaceRegistry()));
             Map<Name, Property> properties = repository.getData().get(targetPath);
-            if (properties == null) {
-                command.setError(new InvalidPathException("Non-existant node: " + targetPath));
-                return;
+            assert properties != null;
+            for (Property property : command.getProperties()) {
+                if (!property.getName().equals(this.uuidPropertyName)) {
+                    properties.put(property.getName(), property);
+                }
             }
-            for (Property property : properties.values()) {
+        }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.SetPropertiesCommand)
+         */
+        @Override
+        public void execute( SetPropertiesCommand command ) throws RepositorySourceException {
+            Map<Name, Property> properties = getProperties(command);
+            if (properties == null) return;
+            for (Property property : command.getProperties()) {
                 if (!property.getName().equals(this.uuidPropertyName)) {
-                    command.setProperty(property);
+                    properties.put(property.getName(), property);
                 }
             }
         }
+
+        /**
+         * {@inheritDoc}
+         * 
+         * @see org.jboss.dna.spi.graph.commands.executor.AbstractCommandExecutor#execute(org.jboss.dna.spi.graph.commands.DeleteBranchCommand)
+         */
+        @Override
+        public void execute( DeleteBranchCommand command ) throws RepositorySourceException {
+            // Iterate through all of the dataq, looking for any paths that are children of the path ...
+            Path targetPath = command.getPath();
+            Map<Path, Map<Name, Property>> data = repository.getData();
+            for (Path path : data.keySet()) {
+                if (!path.isRoot() && path.isAtOrBelow(targetPath)) {
+                    data.remove(path);
+                }
+            }
+        }
+
+        protected <T extends ActsOnPath & GraphCommand> Map<Name, Property> getProperties( T command ) {
+            Path targetPath = command.getPath();
+            Map<Name, Property> properties = repository.getData().get(targetPath);
+            if (properties == null) {
+                Path ancestor = targetPath.getParent();
+                while (ancestor != null) {
+                    if (repository.getData().get(targetPath) != null) break;
+                    ancestor = ancestor.getParent();
+                }
+                if (ancestor == null) ancestor = getExecutionContext().getValueFactories().getPathFactory().createRootPath();
+                command.setError(new PathNotFoundException(targetPath, ancestor));
+                return null;
+            }
+            return properties;
+        }
     }
 
 }

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java	2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/FederatedRepositorySource.java	2008-08-27 14:41:52 UTC (rev 476)
@@ -107,7 +107,7 @@
     public static final String DNA_CACHE_SEGMENT = "dna:cache";
     public static final String DNA_PROJECTIONS_SEGMENT = "dna:projections";
     public static final String PROJECTION_RULES_CONFIG_PROPERTY_NAME = "dna:projectionRules";
-    public static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToLive";
+    public static final String CACHE_POLICY_TIME_TO_LIVE_CONFIG_PROPERTY_NAME = "dna:timeToCache";
 
     private String repositoryName;
     private String sourceName;
@@ -271,9 +271,7 @@
     }
 
     /**
-     * Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
-     * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
-     * repository.
+     * Get the path in the source that will be subgraph below the <code>/dna:system</code> branch of the repository.
      * <p>
      * This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
      * </p>
@@ -287,9 +285,7 @@
     }
 
     /**
-     * Get the projection rule definitions used for the {@link #getConfigurationSourceName() configuration source}. The
-     * {@link #DEFAULT_CONFIGURATION_SOURCE_PATH default path} is mapped into the <code>/dna:system</code> branch of the
-     * repository.
+     * Set the path in the source that will be subgraph below the <code>/dna:system</code> branch of the repository.
      * <p>
      * This is a required property (unless the {@link #getRepositoryJndiName() federated repository is to be found in JDNI}).
      * </p>
@@ -310,6 +306,7 @@
         if (this.configurationSourcePath == pathInSourceToConfigurationRoot || this.configurationSourcePath != null
             && this.configurationSourcePath.equals(pathInSourceToConfigurationRoot)) return;
         this.configurationSourcePath = pathInSourceToConfigurationRoot != null ? pathInSourceToConfigurationRoot : DEFAULT_CONFIGURATION_SOURCE_PATH;
+        changeRepositoryConfig();
     }
 
     /**
@@ -824,7 +821,15 @@
                                                                  getProjectionCommand.getPath(),
                                                                  getProjectionCommand.getPropertiesByName(),
                                                                  problems);
-                        if (projection != null) sourceProjections.add(projection);
+                        if (projection != null) {
+                            Logger logger = context.getLogger(getClass());
+                            if (logger.isTraceEnabled()) {
+                                logger.trace("Adding projection to federated repository {1}: {2}",
+                                             getRepositoryName(),
+                                             projection);
+                            }
+                            sourceProjections.add(projection);
+                        }
                     }
                 }
             }

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java	2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/Projection.java	2008-08-27 14:41:52 UTC (rev 476)
@@ -430,7 +430,7 @@
             first = false;
         }
         sb.append(" }");
-        return super.toString();
+        return sb.toString();
     }
 
     /**

Modified: trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java	2008-08-27 01:24:11 UTC (rev 475)
+++ trunk/extensions/dna-connector-federation/src/main/java/org/jboss/dna/connector/federation/executor/FederatingCommandExecutor.java	2008-08-27 14:41:52 UTC (rev 476)
@@ -21,6 +21,7 @@
  */
 package org.jboss.dna.connector.federation.executor;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -380,7 +381,7 @@
                 break;
             }
         }
-        if (foundNonEmptyContribution) return null;
+        if (!foundNonEmptyContribution) return null;
         if (logger.isTraceEnabled()) {
             logger.trace("Loaded {0} from sources, resulting in these contributions:", path);
             int i = 0;
@@ -533,8 +534,9 @@
         final Path path = mergedNode.getPath();
 
         NodeConflictBehavior conflictBehavior = NodeConflictBehavior.UPDATE;
-        BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, mergedNode.getProperties(), conflictBehavior);
-        newNode.setProperty(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+        Collection<Property> properties = new ArrayList<Property>(mergedNode.getPropertiesByName().size() + 1);
+        properties.add(new BasicSingleValueProperty(this.uuidPropertyName, mergedNode.getUuid()));
+        BasicCreateNodeCommand newNode = new BasicCreateNodeCommand(path, properties, conflictBehavior);
         List<Segment> children = mergedNode.getChildren();
         GraphCommand[] intoCache = new GraphCommand[1 + children.size()];
         int i = 0;

Added: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
===================================================================
--- trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java	                        (rev 0)
+++ trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java	2008-08-27 14:41:52 UTC (rev 476)
@@ -0,0 +1,350 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors. 
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.dna.connector.federation;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
+import static org.hamcrest.core.IsNull.notNullValue;
+import static org.junit.Assert.assertThat;
+import static org.junit.matchers.JUnitMatchers.hasItems;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.stub;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import javax.naming.Context;
+import javax.security.auth.callback.CallbackHandler;
+import org.jboss.dna.spi.DnaLexicon;
+import org.jboss.dna.spi.ExecutionContext;
+import org.jboss.dna.spi.ExecutionContextFactory;
+import org.jboss.dna.spi.connector.BasicExecutionContext;
+import org.jboss.dna.spi.connector.RepositoryConnection;
+import org.jboss.dna.spi.connector.RepositoryConnectionFactory;
+import org.jboss.dna.spi.connector.RepositorySource;
+import org.jboss.dna.spi.connector.SimpleRepository;
+import org.jboss.dna.spi.connector.SimpleRepositorySource;
+import org.jboss.dna.spi.graph.Name;
+import org.jboss.dna.spi.graph.Path;
+import org.jboss.dna.spi.graph.PathNotFoundException;
+import org.jboss.dna.spi.graph.Property;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetChildrenCommand;
+import org.jboss.dna.spi.graph.commands.impl.BasicGetPropertiesCommand;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentMatcher;
+import org.mockito.MockitoAnnotations;
+import org.mockito.MockitoAnnotations.Mock;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/**
+ * This JUnit test constructs a federated repository of multiple repository sources, and is basically a lightweight integration
+ * test that uses all of the actual components of a {@link FederatedRepository} but using mock or fake components for other
+ * systems.
+ * 
+ * @author Randall Hauch
+ */
+public class FederatedRepositorySourceIntegrationTest {
+
+    private FederatedRepositorySource source;
+    private String sourceName;
+    private String username;
+    private String credentials;
+    private String executionContextFactoryJndiName;
+    private String repositoryConnectionFactoryJndiName;
+    private String configurationSourceName;
+    private String securityDomain;
+    private SimpleRepository config;
+    private SimpleRepositorySource configSource;
+    private SimpleRepository cache;
+    private SimpleRepositorySource cacheSource;
+    private SimpleRepository repository1;
+    private SimpleRepositorySource source1;
+    private SimpleRepository repository2;
+    private SimpleRepositorySource source2;
+    private ExecutionContext context;
+    private RepositorySource[] sources;
+    @Mock
+    private Context jndiContext;
+    @Mock
+    private RepositoryConnectionFactory connectionFactory;
+    @Mock
+    private ExecutionContextFactory executionContextFactory;
+
+    @Before
+    public void beforeEach() throws Exception {
+        MockitoAnnotations.initMocks(this);
+
+        // Set up the environment (ExecutionContext, JNDI, security, etc.)
+        context = new BasicExecutionContext();
+        context.getNamespaceRegistry().register(DnaLexicon.Namespace.PREFIX, DnaLexicon.Namespace.URI);
+        executionContextFactoryJndiName = "context factory jndi name";
+        repositoryConnectionFactoryJndiName = "repository connection factory jndi name";
+        configurationSourceName = "configuration source name";
+        securityDomain = "security domain";
+        stub(jndiContext.lookup(executionContextFactoryJndiName)).toReturn(executionContextFactory);
+        stub(jndiContext.lookup(repositoryConnectionFactoryJndiName)).toReturn(connectionFactory);
+        stub(executionContextFactory.create(eq(securityDomain), anyCallbackHandler())).toReturn(context);
+
+        // Set up the federated repository source ...
+        source = new FederatedRepositorySource("Test Repository");
+        sourceName = "federated source";
+        username = "valid username";
+        credentials = "valid password";
+        source.setName(sourceName);
+        source.setUsername(username);
+        source.setPassword(credentials);
+        source.setConfigurationSourceName(configurationSourceName);
+        source.setConfigurationSourcePath("/repos/RepoX");
+        source.setRepositoryConnectionFactoryJndiName(repositoryConnectionFactoryJndiName);
+        source.setExecutionContextFactoryJndiName(executionContextFactoryJndiName);
+        source.setContext(jndiContext);
+        source.setSecurityDomain(securityDomain);
+
+        // Set up the configuration repository with its content ...
+        config = SimpleRepository.get("Configuration Repository");
+        configSource = new SimpleRepositorySource();
+        configSource.setRepositoryName(config.getRepositoryName());
+        configSource.setName(configurationSourceName);
+
+        // Set up the cache repository ...
+        cache = SimpleRepository.get("Cache");
+        cacheSource = new SimpleRepositorySource();
+        cacheSource.setRepositoryName(cache.getRepositoryName());
+        cacheSource.setName("cache source");
+
+        // Set up the first source repository ...
+        repository1 = SimpleRepository.get("source 1");
+        source1 = new SimpleRepositorySource();
+        source1.setRepositoryName(repository1.getRepositoryName());
+        source1.setName("source 1");
+
+        // Set up the second source repository ...
+        repository2 = SimpleRepository.get("source 2");
+        source2 = new SimpleRepositorySource();
+        source2.setRepositoryName(repository2.getRepositoryName());
+        source2.setName("source 2");
+
+        // Set up the connection factory to return connections to the sources ...
+        sources = new RepositorySource[] {spy(configSource), spy(cacheSource), spy(source1), spy(source2)};
+        for (final RepositorySource source : sources) {
+            stub(connectionFactory.createConnection(source.getName())).toAnswer(new Answer<RepositoryConnection>() {
+                public RepositoryConnection answer( InvocationOnMock invocation ) throws Throwable {
+                    return source.getConnection();
+                }
+            });
+        }
+    }
+
+    protected static CallbackHandler anyCallbackHandler() {
+        return argThat(new ArgumentMatcher<CallbackHandler>() {
+            @Override
+            public boolean matches( Object callback ) {
+                return callback != null;
+            }
+        });
+    }
+
+    protected void set( SimpleRepository repository,
+                        String path,
+                        String propertyName,
+                        Object... values ) {
+        repository.setProperty(context, path, propertyName, values);
+    }
+
+    protected void assertNonExistant( RepositorySource source,
+                                      String path ) throws Exception {
+        RepositoryConnection connection = null;
+        Path pathObj = context.getValueFactories().getPathFactory().create(path);
+        try {
+            connection = source.getConnection();
+            BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathObj);
+            connection.execute(context, command);
+            assertThat(command.hasError(), is(true));
+            assertThat(command.getError(), instanceOf(PathNotFoundException.class));
+        } finally {
+            if (connection != null) connection.close();
+        }
+    }
+
+    protected void assertChildren( RepositorySource source,
+                                   String path,
+                                   String... children ) throws Exception {
+        RepositoryConnection connection = null;
+        Path pathObj = context.getValueFactories().getPathFactory().create(path);
+        try {
+            connection = source.getConnection();
+            BasicGetChildrenCommand command = new BasicGetChildrenCommand(pathObj);
+            connection.execute(context, command);
+            assertThat(command.hasError(), is(false));
+            if (children == null || children.length == 0) {
+                assertThat(command.getChildren().isEmpty(), is(true));
+            } else {
+                Path.Segment[] segments = new Path.Segment[children.length];
+                int i = 0;
+                for (String child : children) {
+                    segments[i++] = context.getValueFactories().getPathFactory().createSegment(child);
+                }
+                assertThat(command.getChildren(), hasItems(segments));
+            }
+        } finally {
+            if (connection != null) connection.close();
+        }
+    }
+
+    protected void assertProperty( RepositorySource source,
+                                   String path,
+                                   String propertyName,
+                                   Object... values ) throws Exception {
+        RepositoryConnection connection = null;
+        Path pathObj = context.getValueFactories().getPathFactory().create(path);
+        try {
+            connection = source.getConnection();
+            BasicGetPropertiesCommand command = new BasicGetPropertiesCommand(pathObj);
+            connection.execute(context, command);
+            assertThat(command.hasError(), is(false));
+            Name name = context.getValueFactories().getNameFactory().create(propertyName);
+            Property property = command.getPropertiesByName().get(name);
+            assertThat(property.getValuesAsArray(), is(values));
+        } finally {
+            if (connection != null) connection.close();
+        }
+    }
+
+    @Test
+    public void shouldReturnCorrectConnectionForEachRepositorySource() throws Exception {
+        for (final RepositorySource source : sources) {
+            // Get a connection from the factory ...
+            RepositoryConnection connection = connectionFactory.createConnection(source.getName());
+            assertThat(connection, is(notNullValue()));
+            // And check that the connection is for the correct source ...
+            assertThat(connection.getSourceName(), is(source.getName()));
+            // And close the connection (no need to do this in a finally, since it's a SimpleRepository)
+            connection.close();
+        }
+        // Now, assert that each source created one connection ...
+        for (final RepositorySource source : sources) {
+            verify(source, times(1)).getConnection();
+        }
+    }
+
+    @Test
+    public void shouldProvideReadAccessToContentFederatedFromOneSourceThatMatchesTheContentFromTheSource() throws Exception {
+        // Set up the configuration to use a single sources.
+        set(config, "/repos/RepoX/dna:federation/", "dna:timeToCache", 100000);
+        set(config, "/repos/RepoX/dna:federation/dna:cache/cache source/", "dna:projectionRules", "/ => /");
+        set(config, "/repos/RepoX/dna:federation/dna:projections/source 1/", "dna:projectionRules", "/ => /s1");
+
+        // Set up the content in the first source ...
+        set(repository1, "/s1/a/a/a", "desc", "description for /a/a/a");
+        set(repository1, "/s1/a/a/b", "desc", "description for /a/a/b");
+        set(repository1, "/s1/a/a/c", "desc", "description for /a/a/c");
+        set(repository1, "/s1/a/b/a", "desc", "description for /a/b/a");
+        set(repository1, "/s1/a/b/b", "desc", "description for /a/b/b");
+        set(repository1, "/s1/a/b/c", "desc", "description for /a/b/c");
+        set(repository1, "/s1/b/a", "desc", "description for /b/a");
+        set(repository1, "/s1/b/b", "desc", "description for /b/b");
+        set(repository1, "/s1/b/c", "desc", "description for /b/c");
+
+        // Create a connection to the federated repository. Doing so will read the config information.
+        RepositoryConnection fedConnection = source.getConnection();
+        assertThat(fedConnection, is(notNullValue()));
+        assertChildren(source, "/", "a", "b");
+        assertChildren(source, "/a/", "a", "b");
+        assertChildren(source, "/a/a", "a", "b", "c");
+        assertChildren(source, "/a/a/a");
+        assertChildren(source, "/a/a/b");
+        assertChildren(source, "/a/a/c");
+        assertChildren(source, "/a/b", "a", "b", "c");
+        assertChildren(source, "/a/b/a");
+        assertChildren(source, "/a/b/b");
+        assertChildren(source, "/a/b/c");
+        assertChildren(source, "/b", "a", "b", "c");
+        assertChildren(source, "/b/a");
+        assertChildren(source, "/b/b");
+        assertChildren(source, "/b/c");
+    }
+
+    @Test
+    public void shouldProvideReadAccessToContentFederatedFromMultipleSources() throws Exception {
+        // Set up the configuration to use multiple sources.
+        set(config, "/repos/RepoX/dna:federation/", "dna:timeToCache", 100000);
+        set(config, "/repos/RepoX/dna:federation/dna:cache/cache source/", "dna:projectionRules", "/ => /");
+        set(config, "/repos/RepoX/dna:federation/dna:projections/source 1/", "dna:projectionRules", "/ => /s1");
+        set(config, "/repos/RepoX/dna:federation/dna:projections/source 2/", "dna:projectionRules", "/ => /s2");
+
+        // Set up the content in the first source ...
+        set(repository1, "/s1/a/a/a", "desc", "description for /a/a/a");
+        set(repository1, "/s1/a/a/b", "desc", "description for /a/a/b");
+        set(repository1, "/s1/a/a/c", "desc", "description for /a/a/c");
+        set(repository1, "/s1/a/b/a", "desc", "description for /a/b/a");
+        set(repository1, "/s1/a/b/b", "desc", "description for /a/b/b");
+        set(repository1, "/s1/a/b/c", "desc", "description for /a/b/c");
+        set(repository1, "/s1/b/a", "desc", "description for /b/a");
+        set(repository1, "/s1/b/b", "desc", "description for /b/b");
+        set(repository1, "/s1/b/c", "desc", "description for /b/c");
+
+        // Set up the content in the first source ...
+        set(repository2, "/s2/x/x/x", "desc", "description for /x/x/x");
+        set(repository2, "/s2/x/x/y", "desc", "description for /x/x/y");
+        set(repository2, "/s2/x/x/z", "desc", "description for /x/x/z");
+        set(repository2, "/s2/x/y/x", "desc", "description for /x/y/x");
+        set(repository2, "/s2/x/y/y", "desc", "description for /x/y/y");
+        set(repository2, "/s2/x/y/z", "desc", "description for /x/y/z");
+        set(repository2, "/s2/y/x", "desc", "description for /y/x");
+        set(repository2, "/s2/y/y", "desc", "description for /y/y");
+        set(repository2, "/s2/y/z", "desc", "description for /y/z");
+
+        // Create a connection to the federated repository. Doing so will read the config information.
+        RepositoryConnection fedConnection = source.getConnection();
+        assertThat(fedConnection, is(notNullValue()));
+        assertChildren(source, "/", "a", "b", "x", "y");
+        assertChildren(source, "/a/", "a", "b");
+        assertChildren(source, "/a/a", "a", "b", "c");
+        assertChildren(source, "/a/a/a");
+        assertChildren(source, "/a/a/b");
+        assertChildren(source, "/a/a/c");
+        assertChildren(source, "/a/b", "a", "b", "c");
+        assertChildren(source, "/a/b/a");
+        assertChildren(source, "/a/b/b");
+        assertChildren(source, "/a/b/c");
+        assertChildren(source, "/b", "a", "b", "c");
+        assertChildren(source, "/b/a");
+        assertChildren(source, "/b/b");
+        assertChildren(source, "/b/c");
+        assertChildren(source, "/x/", "x", "y");
+        assertChildren(source, "/x/x", "x", "y", "z");
+        assertChildren(source, "/x/x/x");
+        assertChildren(source, "/x/x/y");
+        assertChildren(source, "/x/x/z");
+        assertChildren(source, "/x/y", "x", "y", "z");
+        assertChildren(source, "/x/y/x");
+        assertChildren(source, "/x/y/y");
+        assertChildren(source, "/x/y/z");
+        assertChildren(source, "/y", "x", "y", "z");
+        assertChildren(source, "/y/x");
+        assertChildren(source, "/y/y");
+        assertChildren(source, "/y/z");
+    }
+
+}


Property changes on: trunk/extensions/dna-connector-federation/src/test/java/org/jboss/dna/connector/federation/FederatedRepositorySourceIntegrationTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain




More information about the dna-commits mailing list