[dna-commits] DNA SVN: r339 - in trunk: dna-repository/src/test/java/org/jboss/dna/repository/federation and 1 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Thu Jul 3 11:42:35 EDT 2008


Author: rhauch
Date: 2008-07-03 11:42:34 -0400 (Thu, 03 Jul 2008)
New Revision: 339

Added:
   trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactories.java
Removed:
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedNode.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositoryConnectionFactories.java
Modified:
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepository.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositoryConnection.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java
   trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositorySourceManager.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryConnectionTest.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositorySourceTest.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryTest.java
   trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederationServiceTest.java
Log:
DNA-115 - Create federation service 
http://jira.jboss.com/jira/browse/DNA-115

Additional tests and changes to FederatedRepository, FederationService, and FederatedRepositoryConnection.  Moved RepositoryConnectionFactories to the SPI.

Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedNode.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedNode.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedNode.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -1,140 +0,0 @@
-/*
- * 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.repository.federation;
-
-import java.util.Iterator;
-import java.util.Set;
-import java.util.UUID;
-import net.jcip.annotations.ThreadSafe;
-import org.jboss.dna.spi.graph.Name;
-import org.jboss.dna.spi.graph.Property;
-
-/**
- * @author Randall Hauch
- */
- at ThreadSafe
-public interface FederatedNode {
-    /**
-     * Get the unique identifier for this federated node.
-     * 
-     * @return the UUID; never null
-     */
-    UUID getUuid();
-
-    /**
-     * Get the name of this node.
-     * 
-     * @return the node name; never null
-     */
-    Name getName();
-
-    /**
-     * Get the property with the given name.
-     * 
-     * @param propertyName the property name
-     * @return the property, or null if the property does not exist
-     * @throws IllegalArgumentException if the name is null
-     */
-    Property getProperty( Name propertyName );
-
-    /**
-     * Get the number of properties on this node. This value is technically an estimate, as it may not exactly match the number of
-     * properties returned by {@link #getProperties()} or {@link #getPropertyNames()}.
-     * 
-     * @return the approximate number of properties.
-     */
-    int getPropertyCount();
-
-    /**
-     * Get the properties. This method returns a consistent set of properties at the moment this method is called, and is not
-     * affected by additions or change to the properties. In other words, it is safe for concurrent operations and is not a
-     * fail-fast iterator.
-     * 
-     * @return the properties on this node via an immutable iterator
-     */
-    Iterator<Property> getProperties();
-
-    /**
-     * Get the names of the properties for this node. This method returns a consistent set of names at the moment this method is
-     * called, and is not affected by additions or change to the properties. In other words, it is safe for concurrent operations
-     * and is not a fail-fast iterator.
-     * 
-     * @return the property names via an immutable iterator
-     */
-    Iterator<Name> getPropertyNames();
-
-    /**
-     * Set the property if it is not already set.
-     * 
-     * @param property the property
-     * @return the existing property, or null if there was no property and the supplied property was set
-     * @throws IllegalArgumentException if the property is null
-     */
-    Property setPropertyIfAbsent( Property property );
-
-    /**
-     * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
-     * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
-     * are no properties supplied.
-     * 
-     * @param properties the properties that should be set
-     */
-    void setProperties( Property... properties );
-
-    /**
-     * Set the supplied properties. This method will overwrite any existing properties with the new properties if they have the
-     * same {@link Property#getName() property name}. This method ignores any null property references, and does nothing if there
-     * are no properties supplied.
-     * 
-     * @param properties the properties that should be set
-     */
-    void setProperties( Iterable<Property> properties );
-
-    /**
-     * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
-     * nothing if there are no properties supplied.
-     * 
-     * @param properties the properties that should be set
-     */
-    void setAllProperties( Property... properties );
-
-    /**
-     * Replace all existing properties with the supplied properties. This method ignores any null property references, and does
-     * nothing if there are no properties supplied.
-     * 
-     * @param properties the properties that should replace the existing properties
-     */
-    void setAllProperties( Iterable<Property> properties );
-
-    /**
-     * Remove all properties, except for the {@link #getName() name} and {@link #getUuid() identifier}.
-     */
-    void removeAllProperties();
-
-    /**
-     * Get the sources that have contributed information to this node.
-     * 
-     * @return the names of the sources that have contributed content to this node.
-     */
-    Set<String> getContributingSources();
-
-}

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepository.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepository.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepository.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -23,7 +23,10 @@
 
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.repository.RepositoryI18n;
@@ -31,6 +34,7 @@
 import org.jboss.dna.repository.services.ServiceAdministrator;
 import org.jboss.dna.spi.graph.connection.ExecutionEnvironment;
 import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories;
 import org.jboss.dna.spi.graph.connection.RepositorySource;
 import org.jboss.dna.spi.graph.connection.RepositorySourceListener;
 
@@ -96,6 +100,9 @@
     private final ExecutionEnvironment env;
     private final RepositoryConnectionFactories connectionFactories;
     private FederatedRepositoryConfig config;
+    private final AtomicInteger openConnections = new AtomicInteger(0);
+    private final CountDownLatch shutdownLatch = new CountDownLatch(1);
+    private final AtomicBoolean shutdownRequested = new AtomicBoolean(false);
     private final CopyOnWriteArrayList<RepositorySourceListener> listeners = new CopyOnWriteArrayList<RepositorySourceListener>();
 
     /**
@@ -154,18 +161,16 @@
     /**
      * Utility method called by the administrator.
      */
-    protected void startRepository() {
-        // Look for the sources in the repository, creating any that are missing
-        // Look for the
+    protected synchronized void startRepository() {
         // Do not establish connections to the sources; these will be established as needed
-
     }
 
     /**
      * Utility method called by the administrator.
      */
-    protected void shutdownRepository() {
-        // Connections to this repository check before doing anything with this, so no need to do anything to them ...
+    protected synchronized void shutdownRepository() {
+        this.shutdownRequested.set(true);
+        if (this.openConnections.get() <= 0) shutdownLatch.countDown();
     }
 
     /**
@@ -173,37 +178,23 @@
      * 
      * @param timeout
      * @param unit
-     * @return true if all pools were terminated in the supplied time (or were already terminated), or false if the timeout
-     *         occurred before all the connections were closed
+     * @return true if all connections open at the time this method is called were {@link RepositoryConnection#close() closed} in
+     *         the supplied time, or false if the timeout occurred before all the connections were closed
      * @throws InterruptedException
      */
     protected boolean awaitTermination( long timeout,
                                         TimeUnit unit ) throws InterruptedException {
-        return true;
+        // Await until all connections have been closed, or until the timeout occurs
+        return shutdownLatch.await(timeout, unit);
     }
 
     /**
-     * Returns true if this federated repository is in the process of terminating after {@link ServiceAdministrator#shutdown()}
-     * has been called on the {@link #getAdministrator() administrator}, but the federated repository has connections that have
-     * not yet normally been {@link RepositoryConnection#close() closed}. This method may be useful for debugging. A return of
-     * <tt>true</tt> reported a sufficient period after shutdown may indicate that connection users have ignored or suppressed
-     * interruption, causing this repository not to properly terminate.
-     * 
-     * @return true if terminating but not yet terminated, or false otherwise
-     * @see #isTerminated()
-     */
-    public boolean isTerminating() {
-        return false;
-    }
-
-    /**
      * Return true if this federated repository has completed its termination and no longer has any open connections.
      * 
      * @return true if terminated, or false otherwise
-     * @see #isTerminating()
      */
-    public boolean isTerminated() {
-        return false;
+    protected boolean isTerminated() {
+        return this.openConnections.get() != 0;
     }
 
     /**
@@ -245,13 +236,15 @@
     /**
      * Authenticate the supplied username with the supplied credentials, and return whether authentication was successful.
      * 
+     * @param source the {@link RepositorySource} that should be affiliated with the resulting connection
      * @param username the username
      * @param credentials the credentials
-     * @return true if authentication succeeded, or false otherwise
+     * @return the repository connection if authentication succeeded, or null otherwise
      */
-    public boolean authenticate( String username,
-                                 Object credentials ) {
-        return true;
+    public RepositoryConnection createConnection( RepositorySource source,
+                                                  String username,
+                                                  Object credentials ) {
+        return new FederatedRepositoryConnection(this, source.getName());
     }
 
     /**
@@ -279,4 +272,26 @@
         this.config = config;
     }
 
+    /**
+     * Called by {@link FederatedRepositoryConnection#FederatedRepositoryConnection(FederatedRepository, String)
+     * FederatedRepositoryConnection constructor}.
+     * 
+     * @param federatedRepositoryConnection
+     */
+    /*package*/void register( FederatedRepositoryConnection federatedRepositoryConnection ) {
+        openConnections.incrementAndGet();
+    }
+
+    /**
+     * Called by {@link FederatedRepositoryConnection#close()}.
+     * 
+     * @param federatedRepositoryConnection
+     */
+    /*package*/void unregister( FederatedRepositoryConnection federatedRepositoryConnection ) {
+        if (openConnections.decrementAndGet() <= 0 && shutdownRequested.get()) {
+            // Last connection, so turn out the lights ...
+            shutdownLatch.countDown();
+        }
+    }
+
 }

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositoryConnection.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositoryConnection.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositoryConnection.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -22,10 +22,12 @@
 package org.jboss.dna.repository.federation;
 
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
 import javax.transaction.xa.XAResource;
 import net.jcip.annotations.ThreadSafe;
 import org.jboss.dna.repository.RepositoryI18n;
 import org.jboss.dna.spi.cache.CachePolicy;
+import org.jboss.dna.spi.graph.commands.CompositeCommand;
 import org.jboss.dna.spi.graph.commands.GraphCommand;
 import org.jboss.dna.spi.graph.connection.ExecutionEnvironment;
 import org.jboss.dna.spi.graph.connection.RepositoryConnection;
@@ -39,7 +41,6 @@
 public class FederatedRepositoryConnection implements RepositoryConnection {
 
     protected static final RepositorySourceListener NO_OP_LISTENER = new RepositorySourceListener() {
-
         public void notify( String sourceName,
                             Object... events ) {
             // do nothing
@@ -47,15 +48,17 @@
     };
 
     private final FederatedRepository repository;
-    private final FederatedRepositorySource source;
-    private RepositorySourceListener listener = NO_OP_LISTENER;
+    private final String sourceName;
+    private final AtomicReference<RepositorySourceListener> listener;
 
     protected FederatedRepositoryConnection( FederatedRepository repository,
-                                             FederatedRepositorySource source ) {
-        assert source != null;
+                                             String sourceName ) {
+        assert sourceName != null;
         assert repository != null;
-        this.source = source;
+        this.sourceName = sourceName;
         this.repository = repository;
+        this.listener = new AtomicReference<RepositorySourceListener>(NO_OP_LISTENER);
+        this.repository.register(this);
     }
 
     /**
@@ -66,17 +69,10 @@
     }
 
     /**
-     * @return source
-     */
-    protected FederatedRepositorySource getRepositorySource() {
-        return this.source;
-    }
-
-    /**
      * {@inheritDoc}
      */
     public String getSourceName() {
-        return this.source.getName();
+        return this.sourceName;
     }
 
     /**
@@ -97,9 +93,9 @@
      * {@inheritDoc}
      */
     public void setListener( RepositorySourceListener listener ) {
-        RepositorySourceListener oldListener = this.listener;
-        this.listener = listener != null ? listener : NO_OP_LISTENER;
-        this.repository.addListener(this.listener);
+        if (listener == null) listener = NO_OP_LISTENER;
+        RepositorySourceListener oldListener = this.listener.getAndSet(listener);
+        this.repository.addListener(listener);
         if (oldListener != NO_OP_LISTENER) {
             this.repository.removeListener(oldListener);
         }
@@ -123,16 +119,34 @@
         }
         if (commands == null || commands.length == 0) return;
 
+        FederatedRepositoryConfig config = this.repository.getConfiguration();
         for (GraphCommand command : commands) {
             if (command == null) continue;
+            executeCommand(env, command, config);
         }
     }
 
+    protected void executeCommand( ExecutionEnvironment env,
+                                   GraphCommand command,
+                                   FederatedRepositoryConfig config ) {
+        if (command instanceof CompositeCommand) {
+            CompositeCommand composite = (CompositeCommand)command;
+            for (GraphCommand nestedCommand : composite) {
+                if (nestedCommand == null) continue;
+                executeCommand(env, nestedCommand, config);
+            }
+        }
+    }
+
     /**
      * {@inheritDoc}
      */
     public void close() {
-        this.repository.removeListener(this.listener);
+        try {
+            this.repository.removeListener(this.listener.get());
+        } finally {
+            this.repository.unregister(this);
+        }
     }
 
 }

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederatedRepositorySource.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -31,6 +31,7 @@
 import javax.naming.StringRefAddr;
 import javax.naming.spi.ObjectFactory;
 import net.jcip.annotations.ThreadSafe;
+import org.jboss.dna.common.i18n.I18n;
 import org.jboss.dna.common.util.ArgCheck;
 import org.jboss.dna.repository.RepositoryI18n;
 import org.jboss.dna.spi.graph.connection.RepositoryConnection;
@@ -64,9 +65,8 @@
     private String credentials;
 
     /**
-     * Create a new instance of the source, which must still be properly initialized with a
-     * {@link #setRepositoryName(String) repository name} and a reference to the
-     * {@link #setFederationService(FederationService) federation service}.
+     * Create a new instance of the source, which must still be properly initialized with a {@link #setRepositoryName(String)
+     * repository name} and a reference to the {@link #setFederationService(FederationService) federation service}.
      */
     public FederatedRepositorySource() {
     }
@@ -122,19 +122,19 @@
         // Find the repository ...
         FederatedRepository repository = federationService.getRepository(this.repositoryName);
         if (repository == null) {
-            throw new RepositorySourceException(
-                                                RepositoryI18n.unableToCreateConnectionToFederatedRepository.text(this.repositoryName));
+            I18n msg = RepositoryI18n.unableToCreateConnectionToFederatedRepository;
+            throw new RepositorySourceException(msg.text(this.repositoryName));
         }
         // Authenticate the user ...
         String username = this.username;
         Object credentials = this.credentials;
-        if (!repository.authenticate(username, credentials)) {
-            throw new RepositorySourceException(
-                                                RepositoryI18n.unableToAuthenticateConnectionToFederatedRepository.text(this.repositoryName,
-                                                                                                                        username));
+        RepositoryConnection connection = repository.createConnection(this, username, credentials);
+        if (connection == null) {
+            I18n msg = RepositoryI18n.unableToAuthenticateConnectionToFederatedRepository;
+            throw new RepositorySourceException(msg.text(this.repositoryName, username));
         }
         // Return the new connection ...
-        return new FederatedRepositoryConnection(repository, this);
+        return connection;
     }
 
     /**

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/FederationService.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -101,6 +101,7 @@
         @Override
         protected void doShutdown( State fromState ) {
             super.doShutdown(fromState);
+            FederationService.this.shutdownService();
         }
 
         /**

Deleted: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositoryConnectionFactories.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositoryConnectionFactories.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositoryConnectionFactories.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -1,33 +0,0 @@
-/*
- * 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.repository.federation;
-
-import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactory;
-
-/**
- * @author Randall Hauch
- */
-public interface RepositoryConnectionFactories {
-
-    RepositoryConnectionFactory getConnectionFactory( String sourceName );
-
-}

Modified: trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositorySourceManager.java
===================================================================
--- trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositorySourceManager.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositorySourceManager.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -32,6 +32,7 @@
 import org.jboss.dna.repository.services.AbstractServiceAdministrator;
 import org.jboss.dna.repository.services.ServiceAdministrator;
 import org.jboss.dna.spi.graph.connection.RepositoryConnection;
+import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories;
 import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactory;
 import org.jboss.dna.spi.graph.connection.RepositoryConnectionPool;
 import org.jboss.dna.spi.graph.connection.RepositorySource;
@@ -331,7 +332,7 @@
     /**
      * {@inheritDoc}
      * 
-     * @see org.jboss.dna.repository.federation.RepositoryConnectionFactories#getConnectionFactory(java.lang.String)
+     * @see org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories#getConnectionFactory(java.lang.String)
      */
     public RepositoryConnectionFactory getConnectionFactory( String sourceName ) {
         RepositoryConnectionFactory result = this.sources.get(sourceName);

Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryConnectionTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryConnectionTest.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryConnectionTest.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -59,24 +59,15 @@
         sourceName = "Source X";
         stub(source.getName()).toReturn(sourceName);
         stub(repository.getAdministrator()).toReturn(repositoryAdmin);
-        connection = new FederatedRepositoryConnection(repository, source);
+        connection = new FederatedRepositoryConnection(repository, sourceName);
     }
 
     @Test
-    public void shouldHaveSourceAndRepository() {
+    public void shouldHaveRepository() {
         assertThat(connection.getRepository(), is(repository));
-        assertThat(connection.getRepositorySource(), is(source));
     }
 
     @Test
-    public void shouldGetSourceNameFromSource() {
-        for (int i = 0; i != 10; ++i) {
-            assertThat(connection.getSourceName(), is(sourceName));
-        }
-        verify(source, times(10)).getName();
-    }
-
-    @Test
     public void shouldHaveNoXaResource() {
         assertThat(connection.getXAResource(), is(nullValue()));
     }

Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositorySourceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositorySourceTest.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositorySourceTest.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -50,6 +50,7 @@
 public class FederatedRepositorySourceTest {
 
     private FederatedRepositorySource source;
+    @Mock
     private FederatedRepositoryConnection connection;
     @Mock
     private FederatedRepository repository;
@@ -75,18 +76,17 @@
 
     @Test
     public void shouldCreateConnectionsByAuthenticateUsingFederationRepository() throws Exception {
-        stub(repository.authenticate(source.getUsername(), source.getCredentials())).toReturn(true);
+        stub(repository.createConnection(source, source.getUsername(), source.getCredentials())).toReturn(connection);
         stub(service.getRepository(source.getRepositoryName())).toReturn(repository);
         connection = (FederatedRepositoryConnection)source.getConnection();
-        assertThat(connection, is(notNullValue()));
-        assertThat(connection.getRepository(), is(sameInstance(repository)));
-        verify(repository, times(1)).authenticate(source.getUsername(), source.getCredentials());
+        assertThat(connection, is(sameInstance(connection)));
+        verify(repository, times(1)).createConnection(source, source.getUsername(), source.getCredentials());
         verify(service, times(1)).getRepository(source.getRepositoryName());
     }
 
     @Test( expected = RepositorySourceException.class )
     public void shouldNotCreateConnectionWhenAuthenticationFails() throws Exception {
-        stub(repository.authenticate(source.getUsername(), source.getCredentials())).toReturn(false);
+        stub(repository.createConnection(source, source.getUsername(), source.getCredentials())).toReturn(null);
         stub(service.getRepository(source.getRepositoryName())).toReturn(repository);
         connection = (FederatedRepositoryConnection)source.getConnection();
     }

Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryTest.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederatedRepositoryTest.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -28,6 +28,7 @@
 import static org.junit.matchers.JUnitMatchers.hasItems;
 import org.jboss.dna.spi.graph.connection.BasicExecutionEnvironment;
 import org.jboss.dna.spi.graph.connection.ExecutionEnvironment;
+import org.jboss.dna.spi.graph.connection.RepositoryConnectionFactories;
 import org.jboss.dna.spi.graph.connection.RepositorySourceListener;
 import org.junit.Before;
 import org.junit.Test;
@@ -143,4 +144,9 @@
         assertThat(repository.getConfiguration(), is(sameInstance(config)));
     }
 
+    @Test( expected = IllegalArgumentException.class )
+    public void shouldNotAllowSettingConfigurationToNull() {
+        repository.setConfiguration(null);
+    }
+
 }

Modified: trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederationServiceTest.java
===================================================================
--- trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederationServiceTest.java	2008-07-03 15:40:44 UTC (rev 338)
+++ trunk/dna-repository/src/test/java/org/jboss/dna/repository/federation/FederationServiceTest.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -35,6 +35,7 @@
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import java.util.concurrent.TimeUnit;
 import org.jboss.dna.common.component.ClassLoaderFactory;
+import org.jboss.dna.common.util.Logger;
 import org.jboss.dna.repository.services.ServiceAdministrator;
 import org.jboss.dna.spi.graph.NamespaceRegistry;
 import org.jboss.dna.spi.graph.Path;
@@ -103,8 +104,9 @@
     @After
     public void afterEach() throws Exception {
         service.getAdministrator().shutdown();
-        service.getAdministrator().awaitTermination(2, TimeUnit.SECONDS);
+        service.getAdministrator().awaitTermination(4, TimeUnit.SECONDS);
         SimpleRepository.shutdownAll();
+        Logger.getLogger(getClass()).trace("");
     }
 
     @Test

Copied: trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactories.java (from rev 321, trunk/dna-repository/src/main/java/org/jboss/dna/repository/federation/RepositoryConnectionFactories.java)
===================================================================
--- trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactories.java	                        (rev 0)
+++ trunk/dna-spi/src/main/java/org/jboss/dna/spi/graph/connection/RepositoryConnectionFactories.java	2008-07-03 15:42:34 UTC (rev 339)
@@ -0,0 +1,32 @@
+/*
+ * 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.spi.graph.connection;
+
+
+/**
+ * @author Randall Hauch
+ */
+public interface RepositoryConnectionFactories {
+
+    RepositoryConnectionFactory getConnectionFactory( String sourceName );
+
+}




More information about the dna-commits mailing list