[dna-commits] DNA SVN: r1114 - in branches/eclipse/dna-web-jcr-rest-client/src: main/java/org/jboss/dna/web/jcr/rest/client/domain and 3 other directories.

dna-commits at lists.jboss.org dna-commits at lists.jboss.org
Fri Jul 17 15:12:26 EDT 2009


Author: elvisisking
Date: 2009-07-17 15:12:26 -0400 (Fri, 17 Jul 2009)
New Revision: 1114

Added:
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/StatusTest.java
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/RepositoryTest.java
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/ServerTest.java
   branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/WorkspaceTest.java
Modified:
   branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
   branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
   branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
   branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Status.java
   branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
   branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
Log:
Added some tests. Added the concept of a key to the Server domain object which caused a changed to the ServerManager.

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/IMessages.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -67,6 +67,8 @@
 
     String ServerManagerRegistryUpdateRemoveError = "ServerManagerRegistryUpdateRemoveError"; //$NON-NLS-1$
 
+    String ServerManagerUnregisteredServer = "ServerManagerUnregisteredServer"; //$NON-NLS-1$
+
     String ServerShortDescription = "ServerShortDescription"; //$NON-NLS-1$
 
     String WorkspaceEmptyNameMsg = "WorkspaceEmptyNameMsg"; //$NON-NLS-1$

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerManager.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -119,6 +119,11 @@
      */
     private final CopyOnWriteArrayList<IServerRegistryListener> listeners;
 
+    /**
+     * Executes the commands run on the DNA REST server.
+     * 
+     * @since 0.6
+     */
     private final IRestExecutor restExecutor;
 
     /**
@@ -217,14 +222,23 @@
     /**
      * @param server the server whose repositories are being requested
      * @return the server repositories (never <code>null</code>)
-     * @throws Exception if there is a problem obtaining the repositories
+     * @throws Exception if there is a problem obtaining the repositories or if the server is not registered
+     * @throws RuntimeException if the server is not registered
+     * @see #isRegistered(Server)
      * @since 0.6
      */
     public Collection<Repository> getRepositories( Server server ) throws Exception {
         try {
             this.serverLock.readLock().lock();
-            Collection<Repository> repositories = this.restExecutor.getRepositories(server);
-            return Collections.unmodifiableCollection(new ArrayList<Repository>(repositories));
+
+            if (isRegistered(server)) {
+                Collection<Repository> repositories = this.restExecutor.getRepositories(server);
+                return Collections.unmodifiableCollection(new ArrayList<Repository>(repositories));
+            }
+            
+            // server must be registered in order to obtain it's repositories
+            String pattern = IMessages.ServerManagerUnregisteredServer;
+            throw new RuntimeException(MessageFormat.format(pattern, server.getShortDescription()));
         } finally {
             this.serverLock.readLock().unlock();
         }
@@ -234,13 +248,22 @@
      * @param repository the repository whose workspaces are being requested
      * @return the DNA repository workspaces (never <code>null</code>)
      * @throws Exception if there is a problem obtaining the workspaces
+     * @throws RuntimeException if the repository's server is not registered
+     * @see #isRegistered(Server)
      * @since 0.6
      */
     public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
         try {
             this.serverLock.readLock().lock();
-            Collection<Workspace> workspaces = this.restExecutor.getWorkspaces(repository);
-            return Collections.unmodifiableCollection(new ArrayList<Workspace>(workspaces));
+            
+            if (isRegistered(repository.getServer())) {
+                Collection<Workspace> workspaces = this.restExecutor.getWorkspaces(repository);
+                return Collections.unmodifiableCollection(new ArrayList<Workspace>(workspaces));
+            }
+            
+            // a repository's server must be registered in order to obtain it's workspaces
+            String pattern = IMessages.ServerManagerUnregisteredServer;
+            throw new RuntimeException(MessageFormat.format(pattern, repository.getServer().getShortDescription()));
         } finally {
             this.serverLock.readLock().unlock();
         }
@@ -261,7 +284,7 @@
         try {
             this.serverLock.writeLock().lock();
 
-            if (!this.servers.contains(server)) {
+            if (!isRegistered(server)) {
                 added = this.servers.add(server);
             }
         } finally {
@@ -296,14 +319,21 @@
 
         try {
             this.serverLock.writeLock().lock();
-            removed = this.servers.remove(server);
+
+            // see if registered server has the same key
+            for (Server registeredServer : this.servers) {
+                if (registeredServer.hasSameKey(server)) {
+                    removed = this.servers.remove(registeredServer);
+                    break;
+                }
+            }
         } finally {
             this.serverLock.writeLock().unlock();
         }
 
         if (removed) {
             if (notifyListeners) {
-                Exception[] errors = notifyRegistryListeners(ServerRegistryEvent.createNewEvent(server));
+                Exception[] errors = notifyRegistryListeners(ServerRegistryEvent.createRemoveEvent(server));
                 return processRegistryListenerErrors(errors);
             }
 
@@ -320,12 +350,21 @@
     /**
      * @param server the server being tested
      * @return <code>true</code> if the server has been registered
+     * @see #addServer(Server)
      * @since 0.6
      */
     public boolean isRegistered( Server server ) {
         try {
             this.serverLock.readLock().lock();
-            return this.servers.contains(server);
+
+            // check to make sure no other registered server has the same key
+            for (Server registeredServer : this.servers) {
+                if (registeredServer.hasSameKey(server)) {
+                    return true;
+                }
+            }
+
+            return false;
         } finally {
             this.serverLock.readLock().unlock();
         }

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/ServerRegistryEvent.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -40,7 +40,7 @@
      * 
      * @since 0.6
      */
-    public enum Type {
+    private enum Type {
         /**
          * Indicates that a new server was added to the server registry.
          * 

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Status.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Status.java	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/Status.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -105,7 +105,7 @@
     protected final String message;
 
     /**
-     * The severity level of this status.
+     * The severity level of this status (never <code>null</code>).
      * 
      * @since 0.6
      */
@@ -150,16 +150,15 @@
     }
 
     /**
-     * @return severity the status severity
+     * @return severity the status severity (never <code>null</code>)
      * @since 0.6
      */
     public Severity getSeverity() {
-        return severity;
+        return this.severity;
     }
 
     /**
-     * @return <code>true</code> if the status is an error
-     * @see Severity#ERROR
+     * @return <code>true</code> if the status has a severity of {@link Severity#ERROR error}.
      * @since 0.6
      */
     public boolean isError() {
@@ -167,8 +166,7 @@
     }
 
     /**
-     * @return <code>true</code> if the status is an info
-     * @see Severity#INFO
+     * @return <code>true</code> if the status has a severity of {@link Severity#INFO info}.
      * @since 0.6
      */
     public boolean isInfo() {
@@ -176,8 +174,7 @@
     }
 
     /**
-     * @return <code>true</code> if the status is OK
-     * @see Severity#OK
+     * @return <code>true</code> if the status has a severity of {@link Severity#OK OK}.
      * @since 0.6
      */
     public boolean isOk() {
@@ -185,10 +182,17 @@
     }
 
     /**
-     * @return <code>true</code> if the status is a warning
-     * @see Severity#WARNING
+     * @return <code>true</code> if the status has a severity of {@link Severity#UNKNOWN unknown}.
      * @since 0.6
      */
+    public boolean isUnknown() {
+        return (this.severity == Severity.UNKNOWN);
+    }
+
+    /**
+     * @return <code>true</code> if the status has a severity of {@link Severity#WARNING warning}.
+     * @since 0.6
+     */
     public boolean isWarning() {
         return (this.severity == Severity.WARNING);
     }
@@ -202,7 +206,10 @@
     @Override
     public String toString() {
         StringBuilder txt = new StringBuilder("Status "); //$NON-NLS-1$
-        txt.append(this.severity.toString()).append(": ").append(getMessage()).append(": ").append(getException()); //$NON-NLS-1$ //$NON-NLS-2$
+        txt.append(this.severity.toString()).append(": "); //$NON-NLS-1$
+        txt.append(getMessage().isEmpty() ? "<no message>" : getMessage()); //$NON-NLS-1$
+        txt.append(" : "); //$NON-NLS-1$
+        txt.append((getException() == null) ? "<no error>" : getException()); //$NON-NLS-1$
         return txt.toString();
     }
 

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/java/org/jboss/dna/web/jcr/rest/client/domain/Server.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -197,6 +197,14 @@
     }
 
     /**
+     * @param otherServer the server whose key is being compared
+     * @return <code>true</code> if the servers have the same key
+     */
+    public boolean hasSameKey( Server otherServer ) {
+        return (Utils.equivalent(this.url, otherServer.url) && Utils.equivalent(this.user, otherServer.user));
+    }
+
+    /**
      * @return persistPassword <code>true</code> if the password is being persisted
      * @since 0.6
      */

Modified: branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties	2009-07-15 20:02:43 UTC (rev 1113)
+++ branches/eclipse/dna-web-jcr-rest-client/src/main/resources/org/jboss/dna/web/jcr/rest/client/Messages.properties	2009-07-17 19:12:26 UTC (rev 1114)
@@ -41,6 +41,7 @@
 ServerManagerRegistryRemoveUnexpectedError = {0} cannot be removed as it has not been registered
 ServerManagerRegistryUpdateAddError = There was an unexpected error updating the server in the registry. The old version of the server was successfully removed. However, the new version was not updated. Detail: {0}
 ServerManagerRegistryUpdateRemoveError = There was an unexpected error updating the server in the registry. The server has not been updated in the server registry. Detail: {0}
+ServerManagerUnregisteredServer = Server "{0}" is not registered so it's repositories and workspaces cannot be obtained.
 
 WorkspaceEmptyNameMsg = A workspace name cannot be empty
 WorkspaceNullRepositoryMsg = A workspace repository cannot be null

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,90 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client;
+
+import java.io.File;
+import java.util.Collection;
+import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.jboss.dna.web.jcr.rest.client.domain.Workspace;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class MockRestExecutor implements IRestExecutor {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+    
+    
+
+    // ===========================================================================================================================
+    // Methods
+    // ===========================================================================================================================
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getRepositories(org.jboss.dna.web.jcr.rest.client.domain.Server)
+     * @since 0.6
+     */
+    public Collection<Repository> getRepositories( Server server ) throws Exception {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#getWorkspaces(org.jboss.dna.web.jcr.rest.client.domain.Repository)
+     * @since 0.6
+     */
+    public Collection<Workspace> getWorkspaces( Repository repository ) throws Exception {
+        return null;
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#publish(org.jboss.dna.web.jcr.rest.client.domain.Repository, java.lang.String, java.io.File)
+     * @since 0.6
+     */
+    public void publish( Repository repository,
+                         String parentPath,
+                         File file ) throws Exception {
+    }
+
+    /**
+     * {@inheritDoc}
+     *
+     * @see org.jboss.dna.web.jcr.rest.client.IRestExecutor#unpublish(org.jboss.dna.web.jcr.rest.client.domain.Repository, java.lang.String, java.io.File)
+     * @since 0.6
+     */
+    public void unpublish( Repository repository,
+                           String parentPath,
+                           File file ) throws Exception {
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/MockRestExecutor.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,277 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+import org.jboss.dna.web.jcr.rest.client.domain.Repository;
+import org.jboss.dna.web.jcr.rest.client.domain.Server;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public class ServerManagerTest {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+    private static final String URL1 = "file:/tmp/temp.txt"; //$NON-NLS-1$
+    private static final String URL2 = "http:www.redhat.com"; //$NON-NLS-1$
+
+    private static final String USER1 = "user1"; //$NON-NLS-1$
+    private static final String USER2 = "user2"; //$NON-NLS-1$
+
+    private static final String PSWD1 = "pwsd1"; //$NON-NLS-1$
+    private static final String PSWD2 = "pwsd2"; //$NON-NLS-1$
+
+    private static Server SERVER1 = new Server(URL1, USER1, PSWD1, false);
+    private static Server SERVER1_UPDATE = new Server(SERVER1.getUrl(), SERVER1.getUser(), SERVER1.getPassword(),
+                                                      SERVER1.isPasswordBeingPersisted());
+    private static Server SERVER2 = new Server(URL2, USER2, PSWD2, !SERVER1.isPasswordBeingPersisted());
+
+    // ===========================================================================================================================
+    // Fields
+    // ===========================================================================================================================
+
+    private ServerManager serverManager;
+
+    // ===========================================================================================================================
+    // Methods
+    // ===========================================================================================================================
+
+    @Before
+    public void beforeEach() {
+        this.serverManager = new ServerManager(null, new MockRestExecutor());
+    }
+
+    // ===========================================================================================================================
+    // Tests
+    // ===========================================================================================================================
+
+    @Test
+    public void shouldBeRegisteredIfAdded() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.isRegistered(SERVER1), is(true));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldBeRegisteredIfServerWithSameKeyHasBeenAdded() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.isRegistered(new Server(SERVER1.getUrl(), SERVER1.getUser(), PSWD2,
+                                                              !SERVER1.isPasswordBeingPersisted())), is(true));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldDecreaseRegistrySizeWhenServerRemoved() {
+        this.serverManager.addServer(SERVER1);
+        this.serverManager.addServer(SERVER2);
+
+        this.serverManager.removeServer(SERVER1);
+        assertThat(this.serverManager.getServers().size(), is(1));
+
+        this.serverManager.removeServer(SERVER2);
+        assertThat(this.serverManager.getServers().isEmpty(), is(true));
+    }
+
+    @Test
+    public void shouldHaveOkStatusWhenAddingServerSuccessfully() {
+        assertThat(this.serverManager.addServer(SERVER1).isOk(), is(true));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldHaveOkStatusWhenRemovingServerSuccessfully() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.removeServer(SERVER1).isOk(), is(true));
+        assertThat(this.serverManager.getServers().isEmpty(), is(true));
+    }
+
+    @Test
+    public void shouldHaveOkStatusWhenUpdateServerSuccessfully() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.updateServer(SERVER1, SERVER1_UPDATE).isOk(), is(true));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldIncreaseRegistrySizeWhenServerAdded() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.getServers().size(), is(1));
+
+        this.serverManager.addServer(SERVER2);
+        assertThat(this.serverManager.getServers().size(), is(2));
+    }
+
+    @Test
+    public void shouldNotAddServerIfAlreadyAdded() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.addServer(SERVER1).isOk(), is(false));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldNotAddServerIfKeysMatch() {
+        this.serverManager.addServer(SERVER1);
+        Status status = this.serverManager.addServer(new Server(SERVER1.getUrl(), SERVER1.getUser(), PSWD2,
+                                                                !SERVER1.isPasswordBeingPersisted()));
+        assertThat(status.isOk(), is(false));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldNotBeRegisteredIfNotAdded() {
+        this.serverManager.addServer(SERVER1);
+        assertThat(this.serverManager.isRegistered(SERVER2), is(false));
+        assertThat(this.serverManager.getServers().size(), is(1));
+    }
+
+    @Test
+    public void shouldNotBeRegisteredIfRemoved() {
+        this.serverManager.addServer(SERVER1);
+        this.serverManager.removeServer(SERVER1);
+        assertThat(this.serverManager.isRegistered(SERVER1), is(false));
+        assertThat(this.serverManager.getServers().isEmpty(), is(true));
+    }
+
+    @Test
+    public void shouldNotReceiveNotificationIfListenerUnregistered() {
+        RegistryListener listener = new RegistryListener();
+
+        this.serverManager.addRegistryListener(listener);
+        this.serverManager.removeRegistryListener(listener);
+        this.serverManager.addServer(SERVER1);
+        assertThat(listener.wasNotified(), is(false));
+    }
+
+    @Test
+    public void shouldNotRemoveServerIfNotAdded() {
+        assertThat(this.serverManager.removeServer(SERVER1).isOk(), is(false));
+        assertThat(this.serverManager.getServers().isEmpty(), is(true));
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotObtainRepositoriesForUnregisteredServer() throws Exception {
+        this.serverManager.getRepositories(SERVER1);
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotObtainWorkspacesForUnregisteredServer() throws Exception {
+        Repository repository = new Repository("repo", SERVER1);//$NON-NLS-1$
+        this.serverManager.getWorkspaces(repository);
+    }
+
+    @Test
+    public void shouldReceiveOneEventIfRegisteredMoreThanOnce() {
+        RegistryListener listener = new RegistryListener();
+        this.serverManager.addRegistryListener(listener);
+        this.serverManager.addRegistryListener(listener);
+
+        this.serverManager.addServer(SERVER1);
+        assertThat(listener.wasNotified(), is(true));
+    }
+
+    @Test
+    public void shouldReceiveNotificationIfRegisteredListener() {
+        RegistryListener listener = new RegistryListener();
+        assertThat(this.serverManager.addRegistryListener(listener), is(true));
+
+        this.serverManager.addServer(SERVER1);
+        assertThat(listener.wasNotified(), is(true));
+    }
+
+    @Test
+    public void shouldReceiveNewServerEvent() {
+        RegistryListener listener = new RegistryListener();
+        this.serverManager.addRegistryListener(listener);
+
+        this.serverManager.addServer(SERVER1);
+        assertThat(listener.getEvent().isNew(), is(true));
+        assertThat(listener.getEvent().isRemove(), is(false));
+        assertThat(listener.getEvent().isUpdate(), is(false));
+    }
+
+    @Test
+    public void shouldReceiveRemoveServerEvent() {
+        this.serverManager.addServer(SERVER1);
+
+        RegistryListener listener = new RegistryListener();
+        this.serverManager.addRegistryListener(listener);
+
+        this.serverManager.removeServer(SERVER1);
+        assertThat(listener.getEvent().isRemove(), is(true));
+        assertThat(listener.getEvent().isNew(), is(false));
+        assertThat(listener.getEvent().isUpdate(), is(false));
+    }
+
+    @Test
+    public void shouldReceiveUpdateServerEvent() {
+        this.serverManager.addServer(SERVER1);
+
+        RegistryListener listener = new RegistryListener();
+        this.serverManager.addRegistryListener(listener);
+
+        this.serverManager.updateServer(SERVER1, new Server(SERVER1.getUrl(), SERVER1.getUser(), PSWD2,
+                                                            !SERVER1.isPasswordBeingPersisted()));
+        assertThat(listener.getEvent().isUpdate(), is(true));
+        assertThat(listener.getEvent().isNew(), is(false));
+        assertThat(listener.getEvent().isRemove(), is(false));
+    }
+
+    @Test
+    public void shouldRemoveServerIfNotAddedButKeyMatches() {
+        this.serverManager.addServer(SERVER1_UPDATE);
+        assertThat(this.serverManager.removeServer(SERVER1).isOk(), is(true));
+        assertThat(this.serverManager.getServers().isEmpty(), is(true));
+    }
+
+    // ===========================================================================================================================
+    // RegistryListener Inner Class
+    // ===========================================================================================================================
+
+    class RegistryListener implements IServerRegistryListener {
+        boolean[] notified = new boolean[] {false};
+        ServerRegistryEvent event = null;
+
+        public Exception[] serverRegistryChanged( ServerRegistryEvent event ) {
+            notified[0] = !notified[0];
+            this.event = event;
+            return null;
+        }
+
+        public ServerRegistryEvent getEvent() {
+            return this.event;
+        }
+
+        public boolean wasNotified() {
+            return notified[0];
+        }
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/ServerManagerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/StatusTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/StatusTest.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/StatusTest.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,148 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Matchers.isNull;
+import org.jboss.dna.web.jcr.rest.client.Status.Severity;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class StatusTest {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+    private static final Status ERROR_STATUS = new Status(Severity.ERROR, null, null);
+
+    private static final Status INFO_STATUS = new Status(Severity.INFO, null, null);
+
+    private static final Status WARNING_STATUS = new Status(Severity.WARNING, null, null);
+
+    private static final Status UNKNOWN_STATUS = new Status(Severity.UNKNOWN, null, null);
+
+    private static final Status NULL_SEVERITY_STATUS = new Status(null, null, null);
+
+    // ===========================================================================================================================
+    // Tests
+    // ===========================================================================================================================
+
+    @Test
+    public void shouldHaveErrorSeverity() {
+        assertThat(ERROR_STATUS.isError(), is(true));
+
+        // make sure other values are false
+        assertThat(ERROR_STATUS.isInfo(), is(false));
+        assertThat(ERROR_STATUS.isOk(), is(false));
+        assertThat(ERROR_STATUS.isUnknown(), is(false));
+        assertThat(ERROR_STATUS.isWarning(), is(false));
+    }
+
+    @Test
+    public void shouldHaveInfoSeverity() {
+        assertThat(INFO_STATUS.isInfo(), is(true));
+
+        // make sure other values are false
+        assertThat(INFO_STATUS.isError(), is(false));
+        assertThat(INFO_STATUS.isOk(), is(false));
+        assertThat(INFO_STATUS.isUnknown(), is(false));
+        assertThat(INFO_STATUS.isWarning(), is(false));
+    }
+
+    @Test
+    public void shouldHaveOkSeverity() {
+        assertThat(Status.OK_STATUS.isOk(), is(true));
+
+        // make sure other values are false
+        assertThat(Status.OK_STATUS.isError(), is(false));
+        assertThat(Status.OK_STATUS.isInfo(), is(false));
+        assertThat(Status.OK_STATUS.isUnknown(), is(false));
+        assertThat(Status.OK_STATUS.isWarning(), is(false));
+    }
+
+    @Test
+    public void shouldHaveUnknownSeverity() {
+        assertThat(UNKNOWN_STATUS.isUnknown(), is(true));
+
+        // make sure other values are false
+        assertThat(UNKNOWN_STATUS.isError(), is(false));
+        assertThat(UNKNOWN_STATUS.isInfo(), is(false));
+        assertThat(UNKNOWN_STATUS.isOk(), is(false));
+        assertThat(UNKNOWN_STATUS.isWarning(), is(false));
+    }
+
+    @Test
+    public void shouldHaveUnknownSeverityWhenNullSeverity() {
+        assertThat(NULL_SEVERITY_STATUS.isUnknown(), is(true));
+
+        // make sure other values are false
+        assertThat(NULL_SEVERITY_STATUS.isError(), is(false));
+        assertThat(NULL_SEVERITY_STATUS.isInfo(), is(false));
+        assertThat(NULL_SEVERITY_STATUS.isOk(), is(false));
+        assertThat(NULL_SEVERITY_STATUS.isWarning(), is(false));
+    }
+
+    @Test
+    public void shouldHaveWarningSeverity() {
+        assertThat(WARNING_STATUS.isWarning(), is(true));
+
+        // make sure other values are false
+        assertThat(WARNING_STATUS.isError(), is(false));
+        assertThat(WARNING_STATUS.isInfo(), is(false));
+        assertThat(WARNING_STATUS.isOk(), is(false));
+        assertThat(WARNING_STATUS.isUnknown(), is(false));
+    }
+
+    @Test
+    public void shouldNotHaveNullMessageWhenConstructedWithNullMessage() {
+        assertThat(new Status(Severity.WARNING, null, null).getMessage(), not(isNull()));
+    }
+
+    @Test
+    public void shouldBeAbleToPrintWithMessageAndNullException() {
+        new Status(Severity.WARNING, "the message goes here", null).toString(); //$NON-NLS-1$
+    }
+
+    @Test
+    public void shouldBeAbleToPrintWithMessageAndException() {
+        new Status(Severity.WARNING, "the message goes here", new RuntimeException("exception message")).toString(); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    @Test
+    public void shouldBeAbleToPrintWithNullMessageAndException() {
+        new Status(Severity.WARNING, null, new RuntimeException("exception message")).toString(); //$NON-NLS-1$
+    }
+
+    @Test
+    public void shouldBeAbleToPrintWithNullMessageAndNullException() {
+        new Status(Severity.WARNING, null, null).toString();
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/StatusTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/RepositoryTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/RepositoryTest.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/RepositoryTest.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,91 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client.domain;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class RepositoryTest {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+    private static final String NAME1 = "name1"; //$NON-NLS-1$
+
+    private static final String NAME2 = "name2"; //$NON-NLS-1$
+
+    private static final Server SERVER1 = new Server("file:/tmp/temp.txt", "user", "pswd", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+    private static final Server SERVER2 = new Server("http:www.redhat.com", "user", "pswd", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+    private static final Repository REPOSITORY1 = new Repository(NAME1, SERVER1);
+
+    // ===========================================================================================================================
+    // Tests
+    // ===========================================================================================================================
+
+    @Test
+    public void shouldBeEqualIfHavingSameProperies() {
+        assertThat(REPOSITORY1, equalTo(new Repository(REPOSITORY1.getName(), REPOSITORY1.getServer())));
+    }
+
+    @Test
+    public void shouldHashToSameValueIfEquals() {
+        Set<Repository> set = new HashSet<Repository>();
+        set.add(REPOSITORY1);
+        set.add(new Repository(REPOSITORY1.getName(), REPOSITORY1.getServer()));
+        assertThat(set.size(), equalTo(1));
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotAllowNullName() {
+        new Repository(null, SERVER1);
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotAllowNullServer() {
+        new Repository(NAME1, null);
+    }
+
+    @Test
+    public void shouldNotBeEqualIfSameNameButDifferentServers() {
+        assertThat(REPOSITORY1, is(not(equalTo(new Repository(REPOSITORY1.getName(), SERVER2)))));
+    }
+
+    @Test
+    public void shouldNotBeEqualIfSameServerButDifferentName() {
+        assertThat(REPOSITORY1, is(not(equalTo(new Repository(NAME2, REPOSITORY1.getServer())))));
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/RepositoryTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/ServerTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/ServerTest.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/ServerTest.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,122 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client.domain;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class ServerTest {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+    private static final String URL1 = "file:/tmp/temp.txt"; //$NON-NLS-1$
+    private static final String URL2 = "http:www.redhat.com"; //$NON-NLS-1$
+
+    private static final String USER1 = "user1"; //$NON-NLS-1$
+    private static final String USER2 = "user2"; //$NON-NLS-1$
+
+    private static final String PSWD1 = "pwsd1"; //$NON-NLS-1$
+    private static final String PSWD2 = "pwsd2"; //$NON-NLS-1$
+
+    private static Server SERVER1 = new Server(URL1, USER1, PSWD1, false);
+
+    // ===========================================================================================================================
+    // Tests
+    // ===========================================================================================================================
+
+    @Test
+    public void shouldBeEqualIfHavingSameProperies() {
+        assertThat(SERVER1, equalTo(new Server(SERVER1.getUrl(), SERVER1.getUser(), SERVER1.getPassword(),
+                                               SERVER1.isPasswordBeingPersisted())));
+    }
+
+    @Test
+    public void shouldHashToSameValueIfEquals() {
+        Set<Server> set = new HashSet<Server>();
+        set.add(SERVER1);
+        set.add(new Server(SERVER1.getUrl(), SERVER1.getUser(), SERVER1.getPassword(), SERVER1.isPasswordBeingPersisted()));
+        assertThat(set.size(), equalTo(1));
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotAllowNullUrl() {
+        new Server(null, USER1, PSWD1, true);
+    }
+
+    @Test
+    public void shouldHaveSameKey() {
+        assertThat(SERVER1.hasSameKey(new Server(SERVER1.getUrl(), SERVER1.getUser(), SERVER1.getPassword(),
+                                                 SERVER1.isPasswordBeingPersisted())), is(true));
+    }
+
+    @Test
+    public void shouldNotBeEqualIfPropertiesAreDifferent() {
+        // different URL
+        assertThat(SERVER1, is(not(equalTo(new Server(URL2, SERVER1.getUser(), SERVER1.getPassword(),
+                                                      SERVER1.isPasswordBeingPersisted())))));
+
+        // different user
+        assertThat(SERVER1, is(not(equalTo(new Server(SERVER1.getUrl(), USER2, SERVER1.getPassword(),
+                                                      SERVER1.isPasswordBeingPersisted())))));
+
+        // different passord
+        assertThat(SERVER1, is(not(equalTo(new Server(SERVER1.getUrl(), SERVER1.getUser(), PSWD2,
+                                                      SERVER1.isPasswordBeingPersisted())))));
+
+        // different persisted flag
+        assertThat(SERVER1, is(not(equalTo(new Server(SERVER1.getUrl(), SERVER1.getUser(), SERVER1.getPassword(),
+                                                      !SERVER1.isPasswordBeingPersisted())))));
+    }
+
+    @Test
+    public void shouldNotHaveSameKey() {
+        assertThat(SERVER1.hasSameKey(new Server(URL2, SERVER1.getUser(), SERVER1.getPassword(),
+                                                 SERVER1.isPasswordBeingPersisted())), is(false));
+        assertThat(SERVER1.hasSameKey(new Server(SERVER1.getUrl(), USER2, SERVER1.getPassword(),
+                                                 SERVER1.isPasswordBeingPersisted())), is(false));
+    }
+
+    @Test
+    public void shouldSetPersistPasswordCorrectly() {
+        boolean persist = true;
+        Server server = new Server(URL1, USER1, PSWD1, persist);
+        assertThat(persist, is(server.isPasswordBeingPersisted()));
+
+        persist = !persist;
+        server = new Server(URL1, USER1, PSWD1, persist);
+        assertThat(persist, is(server.isPasswordBeingPersisted()));
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/ServerTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain

Added: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/WorkspaceTest.java
===================================================================
--- branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/WorkspaceTest.java	                        (rev 0)
+++ branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/WorkspaceTest.java	2009-07-17 19:12:26 UTC (rev 1114)
@@ -0,0 +1,95 @@
+/*
+ * JBoss DNA (http://www.jboss.org/dna)
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership.  Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ * See the AUTHORS.txt file in the distribution for a full listing of 
+ * individual contributors.
+ *
+ * JBoss DNA is free software. Unless otherwise indicated, all code in JBoss DNA
+ * is licensed to you 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.
+ * 
+ * JBoss DNA 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.web.jcr.rest.client.domain;
+
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.hamcrest.core.IsNot.not;
+import static org.junit.Assert.assertThat;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Test;
+
+/**
+ * @author Dan Florian
+ * @since 0.6
+ */
+public final class WorkspaceTest {
+
+    // ===========================================================================================================================
+    // Constants
+    // ===========================================================================================================================
+
+    private static final String NAME1 = "name1"; //$NON-NLS-1$
+
+    private static final String NAME2 = "name2"; //$NON-NLS-1$
+
+    private static final Server SERVER1 = new Server("file:/tmp/temp.txt", "user", "pswd", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+    private static final Server SERVER2 = new Server("http:www.redhat.com", "user", "pswd", false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
+    private static final Repository REPOSITORY1 = new Repository(NAME1, SERVER1);
+
+    private static final Repository REPOSITORY2 = new Repository(NAME2, SERVER2);
+
+    private static final Workspace WORKSPACE1 = new Workspace(NAME1, REPOSITORY1);
+
+    // ===========================================================================================================================
+    // Tests
+    // ===========================================================================================================================
+
+    @Test
+    public void shouldBeEqualIfHavingSameProperies() {
+        assertThat(WORKSPACE1, equalTo(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository())));
+    }
+
+    @Test
+    public void shouldHashToSameValueIfEquals() {
+        Set<Workspace> set = new HashSet<Workspace>();
+        set.add(WORKSPACE1);
+        set.add(new Workspace(WORKSPACE1.getName(), WORKSPACE1.getRepository()));
+        assertThat(set.size(), equalTo(1));
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotAllowNullName() {
+        new Workspace(null, REPOSITORY1);
+    }
+
+    @Test( expected = RuntimeException.class )
+    public void shouldNotAllowNullRepository() {
+        new Workspace(NAME1, null);
+    }
+
+    @Test
+    public void shouldNotBeEqualIfSameNameButDifferentRepository() {
+        assertThat(WORKSPACE1, is(not(equalTo(new Workspace(WORKSPACE1.getName(), REPOSITORY2)))));
+    }
+
+    @Test
+    public void shouldNotBeEqualIfSameRepositoryButDifferentName() {
+        assertThat(WORKSPACE1, is(not(equalTo(new Workspace(NAME2, WORKSPACE1.getRepository())))));
+    }
+
+}


Property changes on: branches/eclipse/dna-web-jcr-rest-client/src/test/java/org/jboss/dna/web/jcr/rest/client/domain/WorkspaceTest.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the dna-commits mailing list