Author: chris.laprun(a)jboss.com
Date: 2009-06-03 00:25:33 -0400 (Wed, 03 Jun 2009)
New Revision: 13427
Added:
modules/registration/
modules/registration/trunk/
modules/registration/trunk/api/
modules/registration/trunk/api/pom.xml
modules/registration/trunk/api/src/
modules/registration/trunk/api/src/main/
modules/registration/trunk/api/src/main/java/
modules/registration/trunk/api/src/main/java/org/
modules/registration/trunk/api/src/main/java/org/jboss/
modules/registration/trunk/api/src/main/java/org/jboss/portal/
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Consumer.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerCapabilities.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerGroup.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/DuplicateRegistrationException.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/InvalidConsumerDataException.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/NoSuchRegistrationException.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/PropertyDescription.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Registration.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationException.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationFailedException.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationLocal.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationManager.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPersistenceManager.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicy.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicyChangeListener.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPropertyChangeListener.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationStatus.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationUtils.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPropertyValidator.java
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/RegistrationPropertyValidator.java
modules/registration/trunk/build/
modules/registration/trunk/build/licences/
modules/registration/trunk/build/licences/JBossEULA.txt
modules/registration/trunk/build/misc/
modules/registration/trunk/build/misc/codeguide.html
modules/registration/trunk/build/pom.xml
modules/registration/trunk/impl/
modules/registration/trunk/impl/pom.xml
modules/registration/trunk/impl/src/
modules/registration/trunk/impl/src/main/
modules/registration/trunk/impl/src/main/java/
modules/registration/trunk/impl/src/main/java/org/
modules/registration/trunk/impl/src/main/java/org/jboss/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerCapabilitiesImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerGroupImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationManagerImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationPersistenceManagerImpl.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/AbstractRegistrationPersistenceManagerTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerGroupTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationManagerTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationPersistenceManagerTestCase.java
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationTestCase.java
modules/registration/trunk/impl/src/test/
modules/registration/trunk/impl/src/test/java/
modules/registration/trunk/impl/src/test/java/org/
modules/registration/trunk/impl/src/test/java/org/jboss/
modules/registration/trunk/impl/src/test/java/org/jboss/portal/
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/AbstractRegistrationPersistenceManagerTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerGroupTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/DefaultRegistrationPolicyTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationManagerTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationPersistenceManagerTestCase.java
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationTestCase.java
modules/registration/trunk/pom.xml
Log:
Initial creation of registration module from Portal 2.7 branch, modified to remove
dependency on jems module and to use slf4j.
Added: modules/registration/trunk/api/pom.xml
===================================================================
--- modules/registration/trunk/api/pom.xml (rev 0)
+++ modules/registration/trunk/api/pom.xml 2009-06-03 04:25:33 UTC (rev 13427)
@@ -0,0 +1,62 @@
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ JBoss, a division of Red Hat ~
+ ~ Copyright 2009, Red Hat Middleware, LLC, and individual
+ ~ contributors as indicated by the @authors tag. See the
+ ~ copyright.txt 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.portal.registration</groupId>
+ <artifactId>module-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>registration-api</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Portal Registration API</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.portal.common</groupId>
+ <artifactId>common-common</artifactId>
+ <version>${version.portal.common}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${version.slf4j}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Consumer.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Consumer.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Consumer.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,93 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.util.Collection;
+
+/**
+ * An entity that groups several registrations under the same scope, for exemple a
Consumer entity could be related to
+ * several registrations for the same consumer with different capabilities.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision:5641 $
+ * @since 2.6
+ */
+public interface Consumer
+{
+
+ /**
+ * Return the consumer name.
+ *
+ * @return the consumer name
+ */
+ String getName();
+
+ /**
+ * Return the registration status of the consumer entity.
+ *
+ * @return the registration stats.
+ */
+ RegistrationStatus getStatus();
+
+ /**
+ * Set the registration status of the consumer entity.
+ *
+ * @param status the registration status
+ */
+ void setStatus(RegistrationStatus status);
+
+ /**
+ * Return all the registrations for the specified consumer.
+ *
+ * @return the consumer registrations
+ * @throws RegistrationException
+ */
+ Collection getRegistrations() throws RegistrationException;
+
+ /**
+ * Returns the group that this consumer belongs to.
+ *
+ * @return the consumer group
+ */
+ ConsumerGroup getGroup();
+
+ /**
+ * Retrieves this Consumer's identity, which uniquely identifies the Consumer
since the name cannot be relied on. It
+ * is up to the {@link RegistrationPolicy} to determine what the Consumer's
identity is. Note also that this is
+ * different from the Consumer's database identifier.
+ *
+ * @return this Consumer's identity.
+ */
+ String getId();
+
+ ConsumerCapabilities getCapabilities();
+
+ void setCapabilities(ConsumerCapabilities capabilities);
+
+ void setGroup(ConsumerGroup group) throws RegistrationException,
DuplicateRegistrationException;
+
+ String getConsumerAgent();
+
+ void setConsumerAgent(String consumerAgent) throws IllegalArgumentException,
IllegalStateException;
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerCapabilities.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerCapabilities.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerCapabilities.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public interface ConsumerCapabilities
+{
+ boolean supportsGetMethod();
+
+ /**
+ * Returns the list of supported {@link org.jboss.portal.Mode}s
+ *
+ * @return
+ */
+ List getSupportedModes();
+
+ /**
+ * Returns the list of supported {@link org.jboss.portal.WindowState}s
+ *
+ * @return
+ */
+ List getSupportedWindowStates();
+
+ /**
+ * Returns the list of user scopes (e.g. "wsrp:perUser") the associated
Consumer is willing to process. See WSRP 1.0
+ * 7.1.1 for more details.
+ *
+ * @return
+ */
+ List getSupportedUserScopes();
+
+ /**
+ * Returns the list of names of UserProfile extensions the associated Consumer
supports. See WSRP 1.0 7.1.1 for more
+ * details.
+ *
+ * @return
+ */
+ List getSupportedUserProfileData();
+
+ void setSupportsGetMethod(boolean supportsGetMethod);
+
+ void setSupportedModes(List supportedModes);
+
+ void setSupportedWindowStates(List supportedWindowStates);
+
+ void setSupportedUserScopes(List supportedUserScopes);
+
+ void setSupportedUserProfileData(List supportedUserProfileData);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerGroup.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerGroup.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/ConsumerGroup.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.util.Collection;
+
+/**
+ * A business entity that is related to several consumers.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public interface ConsumerGroup
+{
+
+ /**
+ * Return this ConsumerGroup's name (i.e. the name of the the business entity
aggregating the associated consumers)
+ *
+ * @return the ConsumerGroup's name
+ */
+ String getName();
+
+ /**
+ * Return a collection of associated consumers.
+ *
+ * @return the consumer collection
+ * @throws RegistrationException
+ */
+ Collection getConsumers() throws RegistrationException;
+
+ /**
+ * Return the member Consumer associated with the given identifier
+ *
+ * @param consumerId
+ * @return the Consumer associated with the identity or <code>null</code>
if no such Consumer is part of this
+ * ConsumerGroup
+ * @throws IllegalArgumentException if the consumer identity is null
+ * @throws RegistrationException
+ */
+ Consumer getConsumer(String consumerId) throws IllegalArgumentException,
RegistrationException;
+
+ void addConsumer(Consumer consumer) throws RegistrationException;
+
+ void removeConsumer(Consumer consumer) throws RegistrationException;
+
+ boolean contains(Consumer consumer);
+
+ boolean isEmpty();
+
+ RegistrationStatus getStatus();
+
+ void setStatus(RegistrationStatus status);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/DuplicateRegistrationException.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/DuplicateRegistrationException.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/DuplicateRegistrationException.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5641 $
+ */
+public class DuplicateRegistrationException extends RegistrationException
+{
+ public DuplicateRegistrationException()
+ {
+ }
+
+ public DuplicateRegistrationException(String message)
+ {
+ super(message);
+ }
+
+ public DuplicateRegistrationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public DuplicateRegistrationException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/InvalidConsumerDataException.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/InvalidConsumerDataException.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/InvalidConsumerDataException.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class InvalidConsumerDataException extends RegistrationException
+{
+
+ public InvalidConsumerDataException()
+ {
+ }
+
+ public InvalidConsumerDataException(String message)
+ {
+ super(message);
+ }
+
+ public InvalidConsumerDataException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public InvalidConsumerDataException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/NoSuchRegistrationException.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/NoSuchRegistrationException.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/NoSuchRegistrationException.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5641 $
+ */
+public class NoSuchRegistrationException extends RegistrationException
+{
+ public NoSuchRegistrationException()
+ {
+ }
+
+ public NoSuchRegistrationException(String message)
+ {
+ super(message);
+ }
+
+ public NoSuchRegistrationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public NoSuchRegistrationException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/PropertyDescription.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/PropertyDescription.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/PropertyDescription.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9177 $
+ * @since 2.6.3
+ */
+public interface PropertyDescription
+{
+ QName getName();
+
+ QName getType();
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Registration.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Registration.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/Registration.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,109 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * A class representing an association between a consumer and a producer.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public interface Registration
+{
+ /**
+ * Retrieves the internal identifier for this Registration. This will correspond to
the database key for this
+ * Registration. This identifier can be used by {@link RegistrationPolicy} to create a
handle for this Registration.
+ *
+ * @return this Registration's internal identifier.
+ */
+ String getId();
+
+ /**
+ * Sets the handle for this Registration.
+ *
+ * @param handle
+ */
+ void setRegistrationHandle(String handle);
+
+ /**
+ * Retrieves the handle associated with this Registration
+ *
+ * @return the registration handle
+ */
+ String getRegistrationHandle();
+
+ /**
+ * Return the consumer owning this registration.
+ *
+ * @return the owning consumer
+ */
+ Consumer getConsumer();
+
+ /**
+ * Retrieve the properties associated with this Registration.
+ *
+ * @return a Map containing the associated properties
+ */
+ Map getProperties();
+
+ void setPropertyValueFor(QName propertyName, Object value) throws
IllegalArgumentException;
+
+ void setPropertyValueFor(String propertyName, Object value);
+
+ boolean hasEqualProperties(Registration registration);
+
+ boolean hasEqualProperties(Map properties);
+
+ /**
+ * Return the status of this specific registration.
+ *
+ * @return the status
+ */
+ RegistrationStatus getStatus();
+
+ /**
+ * Update the registration status
+ *
+ * @param status the new status
+ */
+ void setStatus(RegistrationStatus status);
+
+ /** Clears any state (cloned portlet information, session, etc) associated with this
Registration */
+ void clearAssociatedState();
+
+ void updateProperties(Map registrationProperties);
+
+ void removeProperty(QName propertyName);
+
+ void removeProperty(String propertyName);
+
+ Object getPropertyValueFor(QName propertyName);
+
+ Object getPropertyValueFor(String propertyName);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationException.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationException.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationException.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5641 $
+ */
+public class RegistrationException extends Exception
+{
+ public RegistrationException()
+ {
+ }
+
+ public RegistrationException(String message)
+ {
+ super(message);
+ }
+
+ public RegistrationException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public RegistrationException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationFailedException.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationFailedException.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationFailedException.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5641 $
+ */
+public class RegistrationFailedException
+{
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationLocal.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationLocal.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationLocal.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+
+/**
+ * Hold registration provided by the consumer for the duration of the invocation.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationLocal
+{
+
+ /** The thread local to keep track of the registration associated with the current
thread of execution. */
+ private static final ThreadLocal registrationLocal = new ThreadLocal();
+
+ /**
+ * Sets the current registration for the Consumer for the current invocation.
+ *
+ * @param registration the Registration associated with the Consumer. Set to
<code>null</code> if no Registration
+ * exists for the current Consumer.
+ */
+ public static void setRegistration(Registration registration)
+ {
+ registrationLocal.set(registration);
+ }
+
+ public static Registration getRegistration()
+ {
+ return (Registration)registrationLocal.get();
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationManager.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationManager.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationManager.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8966 $
+ * @since 2.6
+ */
+public interface RegistrationManager extends RegistrationPropertyChangeListener,
RegistrationPolicyChangeListener
+{
+ RegistrationPolicy getPolicy();
+
+ void setPolicy(RegistrationPolicy policy);
+
+ RegistrationPersistenceManager getPersistenceManager();
+
+ void setPersistenceManager(RegistrationPersistenceManager persistenceManager);
+
+ Registration addRegistrationTo(String consumerName, Map registrationProperties,
boolean createConsumerIfNeeded)
+ throws RegistrationException;
+
+ Consumer createConsumer(String name) throws RegistrationException,
InvalidConsumerDataException;
+
+ Consumer addConsumerToGroupNamed(String consumerName, String groupName, boolean
createGroupIfNeeded,
+ boolean createConsumerIfNeeded) throws
RegistrationException;
+
+ ConsumerGroup createConsumerGroup(String groupName) throws RegistrationException;
+
+ void removeConsumer(String identity) throws RegistrationException,
NoSuchRegistrationException;
+
+ void removeConsumer(Consumer consumer) throws RegistrationException,
NoSuchRegistrationException;
+
+ Consumer getConsumerByIdentity(String identity) throws RegistrationException;
+
+ Consumer getConsumerFor(String registrationHandle) throws RegistrationException;
+
+ Registration getRegistration(String registrationHandle) throws RegistrationException;
+
+ void removeRegistration(String registrationHandle) throws RegistrationException,
NoSuchRegistrationException;
+
+ void removeRegistration(Registration registration) throws RegistrationException,
NoSuchRegistrationException;
+
+ ConsumerGroup getConsumerGroup(String groupName) throws RegistrationException;
+
+ Collection getConsumerGroups() throws RegistrationException;
+
+ void removeConsumerGroup(ConsumerGroup group) throws RegistrationException;
+
+ void removeConsumerGroup(String name) throws RegistrationException;
+
+ Collection getConsumers() throws RegistrationException;
+
+ void clear() throws RegistrationException;
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPersistenceManager.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPersistenceManager.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPersistenceManager.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,89 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public interface RegistrationPersistenceManager
+{
+ /**
+ * Creates a Consumer with the specified identity and name (which might be the same,
depending on the policy)
+ *
+ * @param consumerId
+ * @param consumerName
+ */
+ Consumer createConsumer(String consumerId, String consumerName) throws
RegistrationException;
+
+ /**
+ * Retrieves the ConsumerGroup identified by the specified name.
+ *
+ * @param name the name of the group to be retrieved
+ * @return the ConsumerGroup identified by the specified name
+ * @throws RegistrationException
+ */
+ ConsumerGroup getConsumerGroup(String name) throws RegistrationException;
+
+ /**
+ * Creates a new ConsumerGroup with the associated name.
+ *
+ * @param name the name of the ConsumerGroup to be created
+ * @return a new ConsumerGroup with the associated name
+ * @throws RegistrationException
+ */
+ ConsumerGroup createConsumerGroup(String name) throws RegistrationException;
+
+ void removeConsumerGroup(String name) throws RegistrationException;
+
+ void removeConsumer(String consumerId) throws RegistrationException;
+
+ void removeRegistration(String registrationId) throws RegistrationException;
+
+ /**
+ * Return an existing consumer from its id.
+ *
+ * @param consumerId the consumer id
+ * @return the consumer or null if it does not exist
+ * @throws IllegalArgumentException if the consumer id argument is null
+ * @throws RegistrationException
+ */
+ Consumer getConsumerById(String consumerId) throws IllegalArgumentException,
RegistrationException;
+
+ Registration addRegistrationFor(String consumerId, Map registrationProperties) throws
RegistrationException;
+
+ Collection getConsumerGroups();
+
+ Registration getRegistration(String registrationId);
+
+ Consumer addConsumerToGroupNamed(String consumerId, String groupName) throws
RegistrationException;
+
+ Collection getConsumers();
+
+ Collection getRegistrations();
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicy.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicy.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicy.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,140 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * An interface allowing users of the Registration service to customize different aspects
of how Consumers are handled.
+ * Methods of this interface are used by RegistrationManager to make appropriate
decisions. Implementations of this
+ * interface <strong>MUST</strong> provide a no-argument constructor for
instantiation from the class name.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11406 $
+ * @since 2.6
+ */
+public interface RegistrationPolicy
+{
+ /**
+ * Examines and determines whether the given registration properties are adequate for
the Consumer associated with
+ * the given identity. This method is called before a Registration is created and thus
allows users to decide whether
+ * or not to reject a given registration if not satisfied with the given registration
properties.
+ *
+ * @param registrationProperties a Map containing the registration properties in the
form of property name (QName) -
+ * property value (Object) mappings
+ * @param consumerIdentity the Consumer identity (as returned by {@link
#getConsumerIdFrom(String,
+ * java.util.Map)}) for which the registration
properties must be ascertained
+ * @throws IllegalArgumentException if any of the registration properties is invalid
for the specified Consumer
+ * @throws RegistrationException if an exception occured in the registration
service
+ */
+ void validateRegistrationDataFor(Map<QName, ? extends PropertyDescription>
registrationProperties, String consumerIdentity)
+ throws IllegalArgumentException, RegistrationException;
+
+ /**
+ * Generates a registration handle based on the database identity of the Registration.
This allows users to customize
+ * the registration handle format if they want to prevent exposure of database-related
data.
+ *
+ * @param registrationId the database identity of the Registration for which a handle
is required.
+ * @return a registration handle for the Registration associated with the specified
identifier.
+ * @throws IllegalArgumentException if the specified registration identity if
<code>null</code> or empty
+ */
+ String createRegistrationHandleFor(String registrationId) throws
IllegalArgumentException;
+
+ /**
+ * Determines the ConsumerGroup name to which the Consumer associated with the
specified name should be assigned with
+ * or <code>null</code> if the Consumer should not be automatically
assigned to a ConsumerGroup. This method is
+ * called during the Consumer creation process to see if the Consumer should be
automatically added to a
+ * ConsumerGroup.
+ *
+ * @param consumerName the name of the Consumer being created
+ * @return the name of the ConsumerGroup the Consumer must be automatically added to
or <code>null</code> if the
+ * Consumer will not be automatically to a ConsumerGroup at creation
+ * @throws IllegalArgumentException if the specified Consumer name if
<code>null</code> or empty
+ */
+ String getAutomaticGroupNameFor(String consumerName) throws IllegalArgumentException;
+
+ /**
+ * Obtains a consumer identity which uniquely identifies a Consumer in function of the
consumer name and registration
+ * properties. This is potentially necessary because Consumer names are not guaranteed
to be unique (even though the
+ * specification states that they should).
+ *
+ * @param consumerName the consumer name
+ * @param registrationProperties a Map containing the registration properties in the
form of property name (QName) -
+ * property value (Object) mappings. Producer
implementations might use the
+ * registration properties to provide secure Consumer
identity.
+ * @return the consumer identity
+ * @throws InvalidConsumerDataException if the Policy examines the specified
registration properties to determine the
+ * Consumer identity and decides that they are
not in a proper state
+ * @throws IllegalArgumentException if the specified Consumer name if
<code>null</code> or empty
+ */
+ String getConsumerIdFrom(String consumerName, Map registrationProperties)
+ throws IllegalArgumentException, InvalidConsumerDataException;
+
+ /**
+ * Determines if the specified Consumer name is acceptable. This method is called
before a Consumer is created and
+ * before a unique Consumer identity is created. This is in particular used if the
Policy mandates that Consumer
+ * names must be unique.
+ *
+ * @param consumerName the name of the Consumer as passed during the registration
process
+ * @throws IllegalArgumentException if the specified Consumer name if
<code>null</code> or empty
+ * @throws RegistrationException if an exception occurred in the Registration
service
+ */
+ void validateConsumerName(String consumerName)
+ throws IllegalArgumentException, RegistrationException;
+
+ /**
+ * Determines if the specified ConsumerGroup name is acceptable. This method is called
before a ConsumerGroup is
+ * created.
+ *
+ * @param groupName the name of the ConsumerGroup to be created
+ * @throws IllegalArgumentException if the specified ConsumerGroup name if
<code>null</code> or empty
+ * @throws RegistrationException if an exception occurred in the Registration
service
+ */
+ void validateConsumerGroupName(String groupName) throws IllegalArgumentException,
RegistrationException;
+
+ /**
+ * Retrieves the RegistrationManager with which this RegistrationPolicy is
associated.
+ *
+ * @return the RegistrationManager with which this RegistrationPolicy is associated.
+ */
+ RegistrationManager getManager();
+
+ /**
+ * Associates this RegistrationPolicy with the specified RegistrationManager. This
method should not be called
+ * directly by client code as it used in the wiring process of the Registration
service.
+ *
+ * @param manager the RegistrationManager with which this RegistrationPolicy should be
associated.
+ */
+ void setManager(RegistrationManager manager);
+
+ /**
+ * Define what the expectations are as far as acceptable registration properties go.
+ *
+ * @param registrationPropertyDescriptions
+ * a map of containing the description of expected registrations
+ * @since 2.6.3
+ */
+ void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicyChangeListener.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicyChangeListener.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPolicyChangeListener.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,34 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8966 $
+ * @since 2.6.3
+ */
+public interface RegistrationPolicyChangeListener
+{
+ void policyUpdatedTo(RegistrationPolicy policy);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPropertyChangeListener.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPropertyChangeListener.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationPropertyChangeListener.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,37 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9177 $
+ * @since 2.6
+ */
+public interface RegistrationPropertyChangeListener
+{
+ void propertiesHaveChanged(Map<QName, ? extends PropertyDescription>
newRegistrationProperties);
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationStatus.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationStatus.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationStatus.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,55 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import java.io.Serializable;
+
+/**
+ * Type safe enumeration that describes the status of a registration.
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5641 $
+ */
+public class RegistrationStatus implements Serializable
+{
+ private String humanReadable;
+
+ /** The registration is valid. */
+ public static final RegistrationStatus VALID = new
RegistrationStatus("valid");
+
+ /** The registration is waiting for validation. */
+ public static final RegistrationStatus PENDING = new
RegistrationStatus("pending");
+
+ /** The registration is not valid. */
+ public static final RegistrationStatus INVALID = new
RegistrationStatus("invalid");
+
+ private RegistrationStatus(String humanReadable)
+ {
+ this.humanReadable = humanReadable;
+ }
+
+ public String toString()
+ {
+ return "RegistrationStatus: " + humanReadable;
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationUtils.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationUtils.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/RegistrationUtils.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,77 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 10388 $
+ * @since 2.6
+ */
+public class RegistrationUtils
+{
+ private static boolean strict = true;
+ private static final Logger log = LoggerFactory.getLogger(RegistrationUtils.class);
+
+ public static void setStrict(boolean strict)
+ {
+ RegistrationUtils.strict = strict;
+ log.debug("Using " + (strict ? "strict" : "lenient")
+ " Consumer Agent validation mode.");
+ }
+
+ /**
+ * @param consumerAgent
+ * @throws IllegalArgumentException
+ * @since 2.6
+ */
+ public static void validateConsumerAgent(String consumerAgent) throws
IllegalArgumentException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerAgent,
"consumer agent", null);
+ char periodChar = '.';
+ int period = consumerAgent.indexOf(periodChar);
+ if (period != -1)
+ {
+ consumerAgent = consumerAgent.substring(period);
+ period = consumerAgent.indexOf(periodChar);
+
+ if (period != -1)
+ {
+ return;
+ }
+ }
+
+ String msg = "'" + consumerAgent + "' is not a valid
Consumer Agent. Please notify your Consumer provider that it is not
WSRP-compliant.";
+ if (strict)
+ {
+ throw new IllegalArgumentException(msg);
+ }
+ else
+ {
+ log.debug(msg);
+ }
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPolicy.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,211 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.policies;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.InvalidConsumerDataException;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Provides a default implementation of RegistrationPolicy which should be enough for
most user needs provided the
+ * appropriate {@link RegistrationPropertyValidator} has been configured to validate
registration properties.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11406 $
+ * @since 2.6
+ */
+public class DefaultRegistrationPolicy implements RegistrationPolicy
+{
+ private RegistrationManager manager;
+ private RegistrationPropertyValidator validator;
+ private Map<QName, ? extends PropertyDescription> expectations;
+ private static final Logger log =
LoggerFactory.getLogger(DefaultRegistrationPolicy.class);
+
+
+ public RegistrationManager getManager()
+ {
+ return manager;
+ }
+
+ public void setManager(RegistrationManager manager)
+ {
+ this.manager = manager;
+ }
+
+ public void setExpectations(Map<QName, ? extends PropertyDescription>
registrationPropertyDescriptions)
+ {
+ this.expectations = registrationPropertyDescriptions;
+ }
+
+ /**
+ * Only accepts the registration if no registration with identical values exists for
the Consumer identified by the
+ * specified identify and delegates the validation of properties to the configured
RegistrationPropertyValidator.
+ *
+ * @throws DuplicateRegistrationException if a Consumer with the same identity has
already registered with the same
+ * registration properties.
+ */
+ public void validateRegistrationDataFor(Map<QName, ? extends
PropertyDescription> registrationProperties, String consumerIdentity)
+ throws IllegalArgumentException, RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(registrationProperties,
"Registration properties");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerIdentity,
"Consumer identity", null);
+
+ StringBuilder message = new StringBuilder();
+
+ // check that values are consistent with expectations
+ if (expectations != null)
+ {
+ Set<QName> expectedNames = expectations.keySet();
+ boolean consistentWithExpectations = true;
+
+ // check for extra properties
+ Set<QName> unexpected = new
HashSet<QName>(registrationProperties.keySet());
+ unexpected.removeAll(expectedNames);
+ if (!unexpected.isEmpty())
+ {
+ consistentWithExpectations = false;
+ message.append("Consumer '").append(consumerIdentity)
+ .append("' provided values for unexpected registration
properties:\n");
+ for (QName name : unexpected)
+ {
+ message.append("\t- ").append(name).append("\n");
+ }
+ }
+
+ for (Map.Entry<QName, ? extends PropertyDescription> entry :
expectations.entrySet())
+ {
+ QName name = entry.getKey();
+ Object value = registrationProperties.get(name);
+ try
+ {
+ validator.validateValueFor(name, value);
+ }
+ catch (IllegalArgumentException e)
+ {
+ message.append("Missing value for expected
'").append(name.getLocalPart()).append("' property.\n");
+ consistentWithExpectations = false;
+ }
+ }
+
+ if (!consistentWithExpectations)
+ {
+ String messageString = message.toString();
+ log.debug(messageString);
+ throw new InvalidConsumerDataException(messageString);
+ }
+ }
+
+ // check that this is not a duplicate registration if the status is not pending
+ Consumer consumer = manager.getConsumerByIdentity(consumerIdentity);
+ if (consumer != null &&
!RegistrationStatus.PENDING.equals(consumer.getStatus()))
+ {
+ // allow the new registration only if the registration properties are different
that existing registrations
+ // for this consumer...
+ for (Object o : consumer.getRegistrations())
+ {
+ Registration registration = (Registration)o;
+ if (registration.hasEqualProperties(registrationProperties))
+ {
+ throw new DuplicateRegistrationException("Consumer named '"
+ consumer.getName()
+ + "' has already been registered with the same set of
registration properties. Registration rejected!");
+ }
+ }
+ }
+ }
+
+ /** Simply returns the given registration id. */
+ public String createRegistrationHandleFor(String registrationId)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration id", null);
+ return registrationId;
+ }
+
+ /** Doesn't support automatic ConsumerGroups so always return
<code>null</code>. */
+ public String getAutomaticGroupNameFor(String consumerName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
+ return null;
+ }
+
+ /** Simply returns the given consumer name, trusted (!) to be unique. */
+ public String getConsumerIdFrom(String consumerName, Map registrationProperties)
throws IllegalArgumentException, InvalidConsumerDataException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
+ return consumerName;
+ }
+
+ /** Rejects registration if a Consumer with the specified name already exists. */
+ public void validateConsumerName(String consumerName) throws IllegalArgumentException,
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
+
+ Consumer consumer = manager.getConsumerByIdentity(getConsumerIdFrom(consumerName,
Collections.EMPTY_MAP));
+ if (consumer != null)
+ {
+ throw new DuplicateRegistrationException("A Consumer named '" +
consumerName + "' has already been registered.");
+ }
+ }
+
+ /** Rejects name if a ConsumerGroup with the specified name already exists. */
+ public void validateConsumerGroupName(String groupName) throws
IllegalArgumentException, RegistrationException
+ {
+ // this is already the behavior in the RegistrationPersistenceManager so no need to
do anything
+ }
+
+ /**
+ * Instructs this policy to use the specified RegistrationPropertyValidator. There
shouldn't be any need to call this
+ * method manually, as the validator is configured via the WSRP Producer xml
configuration file.
+ *
+ * @param validator
+ */
+ public void setValidator(RegistrationPropertyValidator validator)
+ {
+ this.validator = validator;
+ }
+
+ /**
+ * Retrieves the currently configured RegistrationPropertyValidator.
+ *
+ * @return
+ */
+ public RegistrationPropertyValidator getValidator()
+ {
+ return validator;
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPropertyValidator.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPropertyValidator.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/DefaultRegistrationPropertyValidator.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.policies;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class DefaultRegistrationPropertyValidator implements
RegistrationPropertyValidator
+{
+ public void validateValueFor(QName propertyName, Object value) throws
IllegalArgumentException
+ {
+ // accepts only non-null, non-empty String values
+ if (!(value instanceof String) || ((String)value).length() <= 0)
+ {
+ throw new IllegalArgumentException(value + " is not a valid value for
property '" + propertyName +
+ "'. DefaultRegistrationPropertyValidator only accepts non-null,
non-empty Strings.");
+ }
+ }
+}
Added:
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/RegistrationPropertyValidator.java
===================================================================
---
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/RegistrationPropertyValidator.java
(rev 0)
+++
modules/registration/trunk/api/src/main/java/org/jboss/portal/registration/policies/RegistrationPropertyValidator.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.policies;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An interface providing an entry point for WSRP deployers to plug their registration
property validation mechanism in
+ * {@link org.jboss.portal.registration.policies.DefaultRegistrationPolicy}.
Implementations of this interface
+ * <strong>MUST</strong> provide a no-argument constructor for instantiation
from the class name.
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public interface RegistrationPropertyValidator
+{
+ /**
+ * Validates the given value for the registration property identified by the specified
name. If the value is
+ * acceptable, the method simply returns. An invalid value will raise an exception.
+ *
+ * @param propertyName the qualified name for the property name
+ * @param value the value that needs to be validated
+ * @throws IllegalArgumentException if the specified value is not acceptable for the
specified property.
+ */
+ void validateValueFor(QName propertyName, Object value) throws
IllegalArgumentException;
+}
Added: modules/registration/trunk/build/licences/JBossEULA.txt
===================================================================
--- modules/registration/trunk/build/licences/JBossEULA.txt (rev
0)
+++ modules/registration/trunk/build/licences/JBossEULA.txt 2009-06-03 04:25:33 UTC (rev
13427)
@@ -0,0 +1,106 @@
+LICENSE AGREEMENT
+JBOSS(r)
+
+This License Agreement governs the use of the Software Packages and any updates to the
Software
+Packages, regardless of the delivery mechanism. Each Software Package is a collective
work
+under U.S. Copyright Law. Subject to the following terms, Red Hat, Inc. ("Red
Hat") grants to
+the user ("Client") a license to the applicable collective work(s) pursuant to
the
+GNU Lesser General Public License v. 2.1 except for the following Software Packages:
+(a) JBoss Portal Forums and JBoss Transactions JTS, each of which is licensed pursuant to
the
+GNU General Public License v.2;
+
+(b) JBoss Rules, which is licensed pursuant to the Apache License v.2.0;
+
+(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is
licensed under the
+(open source) Sleepycat License (if Client does not wish to use the open source version
of this database,
+it may purchase a license from Sleepycat Software);
+
+and (d) the BPEL extension for JBoss jBPM, which is licensed under the Common Public
License v.1,
+and, pursuant to the OASIS BPEL4WS standard, requires parties wishing to redistribute to
enter various
+royalty-free patent licenses.
+
+Each of the foregoing licenses is available at
http://www.opensource.org/licenses/index.php.
+
+1. The Software. "Software Packages" refer to the various software modules
that are created and made available
+for distribution by the
JBoss.org open source community at
http://www.jboss.org. Each
of the Software Packages
+may be comprised of hundreds of software components. The end user license agreement for
each component is located in
+the component's source code. With the exception of certain image files identified in
Section 2 below,
+the license terms for the components permit Client to copy, modify, and redistribute the
component,
+in both source code and binary code forms. This agreement does not limit Client's
rights under,
+or grant Client rights that supersede, the license terms of any particular component.
+
+2. Intellectual Property Rights. The Software Packages are owned by Red Hat and others
and are protected under copyright
+and other laws. Title to the Software Packages and any component, or to any copy,
modification, or merged portion shall
+remain with the aforementioned, subject to the applicable license. The "JBoss"
trademark, "Red Hat" trademark, the
+individual Software Package trademarks, and the "Shadowman" logo are registered
trademarks of Red Hat and its affiliates
+in the U.S. and other countries. This agreement permits Client to distribute unmodified
copies of the Software Packages
+using the Red Hat trademarks that Red Hat has inserted in the Software Packages on the
condition that Client follows Red Hat's
+trademark guidelines for those trademarks located at
http://www.redhat.com/about/corporate/trademark/. Client must abide by
+these trademark guidelines when distributing the Software Packages, regardless of whether
the Software Packages have been modified.
+If Client modifies the Software Packages, then Client must replace all Red Hat trademarks
and logos identified at
+http://www.jboss.com/company/logos, unless a separate agreement with Red Hat is executed
or other permission granted.
+Merely deleting the files containing the Red Hat trademarks may corrupt the Software
Packages.
+
+3. Limited Warranty. Except as specifically stated in this Paragraph 3 or a license for
a particular
+component, to the maximum extent permitted under applicable law, the Software Packages
and the
+components are provided and licensed "as is" without warranty of any kind,
expressed or implied,
+including the implied warranties of merchantability, non-infringement or fitness for a
particular purpose.
+Red Hat warrants that the media on which Software Packages may be furnished will be free
from defects in
+materials and manufacture under normal use for a period of 30 days from the date of
delivery to Client.
+Red Hat does not warrant that the functions contained in the Software Packages will meet
Client's requirements
+or that the operation of the Software Packages will be entirely error free or appear
precisely as described
+in the accompanying documentation. This warranty extends only to the party that purchases
the Services
+pertaining to the Software Packages from Red Hat or a Red Hat authorized distributor.
+
+4. Limitation of Remedies and Liability. To the maximum extent permitted by applicable
law, the remedies
+described below are accepted by Client as its only remedies. Red Hat's entire
liability, and Client's
+exclusive remedies, shall be: If the Software media is defective, Client may return it
within 30 days of
+delivery along with a copy of Client's payment receipt and Red Hat, at its option,
will replace it or
+refund the money paid by Client for the Software. To the maximum extent permitted by
applicable law,
+Red Hat or any Red Hat authorized dealer will not be liable to Client for any incidental
or consequential
+damages, including lost profits or lost savings arising out of the use or inability to
use the Software,
+even if Red Hat or such dealer has been advised of the possibility of such damages. In
no event shall
+Red Hat's liability under this agreement exceed the amount that Client paid to Red
Hat under this
+Agreement during the twelve months preceding the action.
+
+5. Export Control. As required by U.S. law, Client represents and warrants that it:
+(a) understands that the Software Packages are subject to export controls under the
+U.S. Commerce Department's Export Administration Regulations ("EAR");
+
+(b) is not located in a prohibited destination country under the EAR or U.S. sanctions
regulations
+(currently Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria);
+
+(c) will not export, re-export, or transfer the Software Packages to any prohibited
destination, entity,
+or individual without the necessary export license(s) or authorizations(s) from the U.S.
Government;
+
+(d) will not use or transfer the Software Packages for use in any sensitive nuclear,
chemical or
+biological weapons, or missile technology end-uses unless authorized by the U.S.
Government by
+regulation or specific license;
+
+(e) understands and agrees that if it is in the United States and exports or transfers
the Software
+Packages to eligible end users, it will, as required by EAR Section 740.17(e), submit
semi-annual
+reports to the Commerce Department's Bureau of Industry & Security (BIS), which
include the name and
+address (including country) of each transferee;
+
+and (f) understands that countries other than the United States may restrict the import,
use, or
+export of encryption products and that it shall be solely responsible for compliance with
any such
+import, use, or export restrictions.
+
+6. Third Party Programs. Red Hat may distribute third party software programs with the
Software Packages
+that are not part of the Software Packages and which Client must install separately.
These third party
+programs are subject to their own license terms. The license terms either accompany the
programs or
+can be viewed at
http://www.redhat.com/licenses/. If Client does not agree to abide by
the applicable
+license terms for such programs, then Client may not install them. If Client wishes to
install the programs
+on more than one system or transfer the programs to another party, then Client must
contact the licensor
+of the programs.
+
+7. General. If any provision of this agreement is held to be unenforceable, that shall
not affect the
+enforceability of the remaining provisions. This License Agreement shall be governed by
the laws of the
+State of North Carolina and of the United States, without regard to any conflict of laws
provisions,
+except that the United Nations Convention on the International Sale of Goods shall not
apply.
+
+Copyright 2006 Red Hat, Inc. All rights reserved.
+"JBoss" and the JBoss logo are registered trademarks of Red Hat, Inc.
+All other trademarks are the property of their respective owners.
+
+ Page 1 of 1 18 October 2006
Added: modules/registration/trunk/build/misc/codeguide.html
===================================================================
--- modules/registration/trunk/build/misc/codeguide.html (rev 0)
+++ modules/registration/trunk/build/misc/codeguide.html 2009-06-03 04:25:33 UTC (rev
13427)
@@ -0,0 +1,133 @@
+<html>
+
+<head>
+<style type="text/css">
+pre { border-style:solid; border-width:thin; padding:5px; background-color:#EEEEFF;}
+span.bad { text-decoration:line-through; }
+span.important { font-weight:bold; color:red; }
+</style>
+</head>
+
+<body>
+
+<h2>Coding Conventions</h2>
+
+<h3>Some more general guidelines</h3>
+<ul>
+<li>Fully qualified imports should be used, rather than importing
x.y.*.</li>
+<li>Use newlines for opening braces, so that the top and bottom braces can be
visually matched.</li>
+<li>Aid visual separation of logical steps by introducing newlines and appropriate
comments above them.</li>
+</ul>
+
+
+<h3>A class that conforms to JBoss coding guidelines</h3>
+
+<pre>
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt 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 x;
+
+// <span class="important">Explicit imports</span>
+import a.b.C1; // <span class="important">good</span>
+import a.b.C2;
+import a.b.C3;
+
+// <span class="important">Do not write</span>
+<span class="bad">import a.b.*;</span> // <span
class="important">bad</span>
+
+// <span class="important">DO NOT USE "TAB" TO INDENT CODE USE
*3* SPACES FOR PORTABILITY AMONG EDITORS</span>
+
+/**
+ * A description of this class.
+ *
+ * @see SomeRelatedClass.
+ *
+ * @version <tt>$Revision: 7755 $</tt>
+ * @author <a href="mailto:{email}">{full
name}</a>
+ */
+public class X
+ extends Y
+ implements Z
+{
+ public void startService() throws Exception
+ {
+ // Use the newline for the opening bracket so we can match top
+ // and bottom bracket visually
+
+ Class cls = Class.forName(dataSourceClass);
+ vendorSource = (XADataSource)cls.newInstance();
+
+ // Jump a line between logically distinct <span
class="important">steps</span> and add<
+ // line of comment to it
+ cls = vendorSource.getClass();
+
+ // Comment lines <span class="important">always</span> start
with an uppercase
+ // except if it is the second line
+ if(properties != null)
+ {
+
+ try
+ {
+ }
+ catch (IOException ioe)
+ {
+ }
+ for (Iterator i = props.entrySet().iterator(); i.hasNext();)
+ {
+
+ // Get the name and value for the attributes
+ Map.Entry entry = (Map.Entry) i.next();
+ String attributeName = (String) entry.getKey();
+ String attributeValue = (String) entry.getValue();
+
+ // Print the debug message
+ log.debug("Setting attribute '" + attributeName + "'
to '" + attributeValue + "'");
+
+ // get the attribute
+ Method setAttribute =
+ cls.getMethod("set" + attributeName, new Class[] { String.class
});
+
+ // And set the value
+ setAttribute.invoke(vendorSource, new Object[] { attributeValue });
+ }
+ }
+
+ <span class="bad">// this is a <span
class="important">bad</span> comment line because it starts with a
lower case</span>
+ vendorSource.getXAConnection().close();
+
+ // Bind in JNDI
+ bind(new InitialContext(), "java:/"+getPoolName(),
+ new Reference(vendorSource.getClass().getName(),
+ getClass().getName(), null));
+
+ // Block must always be delimited explicitely
+ if (0 == 0)
+ <span class="important">{</span>
+ System.out.println(true);
+ <span class="important">}</span>
+
+ }
+}
+</pre>
+</body>
+</html>
Property changes on: modules/registration/trunk/build/misc/codeguide.html
___________________________________________________________________
Name: svn:executable
+ *
Added: modules/registration/trunk/build/pom.xml
===================================================================
--- modules/registration/trunk/build/pom.xml (rev 0)
+++ modules/registration/trunk/build/pom.xml 2009-06-03 04:25:33 UTC (rev 13427)
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ This pom functions as a default configuration. The subproject
+ poms each inherit configuration from this one.
+
+ When adding version information for an artifact please do the following
+ - add a version property for the specific version
+ - add a dependency in the dependencyManagement section which refers to
+ the property
+-->
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.portal</groupId>
+ <artifactId>jboss-portal-parent</artifactId>
+ <version>1.0.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.portal.registration</groupId>
+ <artifactId>module-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+ <name>JBoss Portal Registration Parent</name>
+ <description>JBoss Portal Registration Module</description>
+
+ <properties>
+ <version.portal.common>1.2.3</version.portal.common>
+ <version.slf4j>1.5.6</version.slf4j>
+ </properties>
+
+ <!--JBoss repositories to be able to grab jboss-portal-parent pom-->
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <
url>http://repository.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshots Repository</name>
+ <layout>default</layout>
+ <
url>http://snapshots.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ </repository>
+ </repositories>
+
+
+ <build>
+ </build>
+
+
+ <dependencyManagement>
+ <!-- The parent pom manages the inter-dependencies of the modules. -->
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.portal.common</groupId>
+ <artifactId>common-common</artifactId>
+ <version>${version.portal.common}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${version.slf4j}</version>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+</project>
Added: modules/registration/trunk/impl/pom.xml
===================================================================
--- modules/registration/trunk/impl/pom.xml (rev 0)
+++ modules/registration/trunk/impl/pom.xml 2009-06-03 04:25:33 UTC (rev 13427)
@@ -0,0 +1,61 @@
+<!--
+ ~ JBoss, a division of Red Hat
+ ~ Copyright 2009, Red Hat Middleware, LLC, and individual
+ ~ contributors as indicated by the @authors tag. See the
+ ~ copyright.txt 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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss.portal.registration</groupId>
+ <artifactId>module-parent</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <relativePath>../build/pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>registration-impl</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Portal Registration Reference Implementation</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.portal.registration</groupId>
+ <artifactId>registration-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-jdk14</artifactId>
+ <version>${version.slf4j}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerCapabilitiesImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerCapabilitiesImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerCapabilitiesImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.registration.ConsumerCapabilities;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerCapabilitiesImpl implements ConsumerCapabilities
+{
+ private boolean supportsGetMethod;
+ private List supportedModes;
+ private List supportedWindowStates;
+ private List supportedUserScopes;
+ private List supportedUserProfileData;
+
+ public boolean supportsGetMethod()
+ {
+ return supportsGetMethod;
+ }
+
+ public List getSupportedModes()
+ {
+ return supportedModes;
+ }
+
+ public List getSupportedWindowStates()
+ {
+ return supportedWindowStates;
+ }
+
+ public List getSupportedUserScopes()
+ {
+ return supportedUserScopes;
+ }
+
+ public List getSupportedUserProfileData()
+ {
+ return supportedUserProfileData;
+ }
+
+ public void setSupportsGetMethod(boolean supportsGetMethod)
+ {
+ this.supportsGetMethod = supportsGetMethod;
+ }
+
+ public void setSupportedModes(List supportedModes)
+ {
+ this.supportedModes = supportedModes;
+ }
+
+ public void setSupportedWindowStates(List supportedWindowStates)
+ {
+ this.supportedWindowStates = supportedWindowStates;
+ }
+
+ public void setSupportedUserScopes(List supportedUserScopes)
+ {
+ this.supportedUserScopes = supportedUserScopes;
+ }
+
+ public void setSupportedUserProfileData(List supportedUserProfileData)
+ {
+ this.supportedUserProfileData = supportedUserProfileData;
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerGroupImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerGroupImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerGroupImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationStatus;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision:5672 $
+ */
+public class ConsumerGroupImpl implements ConsumerGroup
+{
+
+ private String name;
+ private Map consumers;
+ private RegistrationStatus status;
+
+
+ private ConsumerGroupImpl()
+ {
+ init();
+ }
+
+ ConsumerGroupImpl(String name)
+ {
+ this.name = name;
+ init();
+ }
+
+ private void init()
+ {
+ this.consumers = new HashMap();
+ status = RegistrationStatus.PENDING;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ConsumerGroupImpl that = (ConsumerGroupImpl)o;
+
+ return name.equals(that.name);
+ }
+
+ public int hashCode()
+ {
+ return name.hashCode();
+ }
+
+ public RegistrationStatus getStatus()
+ {
+ return status;
+ }
+
+ public void setStatus(RegistrationStatus status)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(status,
"RegistrationStatus");
+ this.status = status;
+ }
+
+ public Collection getConsumers() throws RegistrationException
+ {
+ return Collections.unmodifiableCollection(consumers.values());
+ }
+
+ public Consumer getConsumer(String consumerId) throws IllegalArgumentException,
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer name", null);
+ return (Consumer)consumers.get(consumerId);
+ }
+
+ public boolean isEmpty()
+ {
+ return consumers.isEmpty();
+ }
+
+ public void addConsumer(Consumer consumer) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+ String identity = consumer.getId();
+ if (consumers.containsKey(identity))
+ {
+ throw new IllegalArgumentException("ConsumerGroup named '" + name
+ + "' already contains a Consumer named '" +
consumer.getName() + "' (identity: '" + identity + "')");
+ }
+
+ consumers.put(identity, consumer);
+ consumer.setGroup(this);
+ }
+
+ public void removeConsumer(Consumer consumer) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+
+ if (consumers.remove(consumer.getId()) == null)
+ {
+ throw new NoSuchRegistrationException("ConsumerGroup named '" +
name
+ + "' does not contain a Consumer named '" +
consumer.getName() + "' (identity: '" + consumer.getId()
+ + "')");
+ }
+
+ consumer.setGroup(null);
+ }
+
+ public boolean contains(Consumer consumer)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+
+ return consumers.containsKey(consumer.getId());
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/ConsumerImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,200 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerCapabilities;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.RegistrationUtils;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerImpl implements Consumer
+{
+
+ private String name;
+ private String identity;
+ private String consumerAgent;
+ private Set registrations;
+ private RegistrationStatus status;
+ private ConsumerGroup group;
+ private ConsumerCapabilities capabilities;
+
+
+ private ConsumerImpl()
+ {
+ init();
+ }
+
+ ConsumerImpl(String identity, String name)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "name",
"Consumer");
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name,
"identity", "Consumer");
+
+ this.name = name;
+ this.identity = identity;
+ init();
+ }
+
+ private void init()
+ {
+ registrations = new HashSet(7);
+ status = RegistrationStatus.PENDING;
+ capabilities = new ConsumerCapabilitiesImpl();
+ }
+
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)o;
+
+ return identity.equals(consumer.identity);
+ }
+
+ public int hashCode()
+ {
+ return identity.hashCode();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getId()
+ {
+ return identity;
+ }
+
+
+ public String getConsumerAgent()
+ {
+ return consumerAgent;
+ }
+
+ public void setConsumerAgent(String consumerAgent) throws IllegalArgumentException,
IllegalStateException
+ {
+ if (consumerAgent != null && !consumerAgent.equals(this.consumerAgent))
+ {
+ RegistrationUtils.validateConsumerAgent(consumerAgent);
+ this.consumerAgent = consumerAgent;
+ }
+ }
+
+ public ConsumerCapabilities getCapabilities()
+ {
+ return capabilities;
+ }
+
+ public void setCapabilities(ConsumerCapabilities capabilities)
+ {
+ this.capabilities = capabilities;
+ }
+
+ public RegistrationStatus getStatus()
+ {
+ return status;
+ }
+
+ public void setStatus(RegistrationStatus status)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(status,
"RegistrationStatus");
+ this.status = status;
+ }
+
+ public Collection getRegistrations() throws RegistrationException
+ {
+ return Collections.unmodifiableSet(registrations);
+ }
+
+ public ConsumerGroup getGroup()
+ {
+ return group;
+ }
+
+ void addRegistration(Registration registration)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
+
+ registrations.add(registration);
+ }
+
+ void removeRegistration(Registration registration) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
+
+ registrations.remove(registration);
+
+ // status should become pending if there are no registrations
+ if (registrations.isEmpty())
+ {
+ setStatus(RegistrationStatus.PENDING);
+ }
+ }
+
+ public void setGroup(ConsumerGroup group) throws RegistrationException
+ {
+ if (this.group != null)
+ {
+ // if we're trying to set the same group, just return
+ if (this.group.equals(group))
+ {
+ return;
+ }
+
+ if (this.group.contains(this))
+ {
+ this.group.removeConsumer(this);
+ }
+ }
+
+ this.group = group;
+
+ if (group != null && !this.group.contains(this))
+ {
+ group.addConsumer(this);
+ }
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,194 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationStatus;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationImpl implements Registration
+{
+
+ private final String id;
+ private ConsumerImpl consumer;
+ private RegistrationStatus status;
+ private Map properties;
+ private String registrationHandle;
+
+
+ public RegistrationImpl(String id, ConsumerImpl consumer, RegistrationStatus status,
Map properties)
+ {
+ this.id = id;
+ this.consumer = consumer;
+ this.status = status;
+ this.properties = new HashMap(properties);
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setRegistrationHandle(String handle)
+ {
+ this.registrationHandle = handle;
+ }
+
+ public String getRegistrationHandle()
+ {
+ return registrationHandle;
+ }
+
+ public Consumer getConsumer()
+ {
+ return consumer;
+ }
+
+ public Map getProperties()
+ {
+ return Collections.unmodifiableMap(properties);
+ }
+
+ public void setPropertyValueFor(QName propertyName, Object value)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ ParameterValidation.throwIllegalArgExceptionIfNull(value, "Property
value");
+
+ // avoid modifying the properties if new value is the same as old one
+ Object oldValue = properties.get(propertyName);
+ if (!value.equals(oldValue))
+ {
+ properties.put(propertyName, value);
+ }
+ }
+
+ public void setPropertyValueFor(String propertyName, Object value)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ setPropertyValueFor(new QName(propertyName), value);
+ }
+
+ public Object getPropertyValueFor(QName propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ return properties.get(propertyName);
+ }
+
+ public Object getPropertyValueFor(String propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ return getPropertyValueFor(new QName(propertyName));
+ }
+
+
+ public void removeProperty(QName propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ properties.remove(propertyName);
+ }
+
+ public void removeProperty(String propertyName)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(propertyName, "Property
name");
+ removeProperty(new QName(propertyName));
+ }
+
+ public boolean hasEqualProperties(Registration registration)
+ {
+ if (registration == null)
+ {
+ return false;
+ }
+
+ Map other = registration.getProperties();
+ return hasEqualProperties(other);
+ }
+
+ public boolean hasEqualProperties(Map registrationProperties)
+ {
+ if (registrationProperties == null)
+ {
+ return false;
+ }
+
+ if (properties.size() != registrationProperties.size())
+ {
+ return false;
+ }
+
+ // check properties
+ for (Iterator props = properties.entrySet().iterator(); props.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)props.next();
+
+ // we should have a 1-1 match between name/value pair
+ QName name = (QName)entry.getKey();
+ if (!entry.getValue().equals(registrationProperties.get(name)))
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public void setRegistrationPropertyValueFor(String propertyName, Object value)
+ {
+ setPropertyValueFor(new QName(propertyName), value);
+ }
+
+ public RegistrationStatus getStatus()
+ {
+ return status;
+ }
+
+ public void setStatus(RegistrationStatus status)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(status,
"RegistrationStatus");
+ this.status = status;
+ }
+
+ public void clearAssociatedState()
+ {
+ //todo: implement
+ }
+
+ public void updateProperties(Map registrationProperties)
+ {
+ properties = new HashMap(registrationProperties);
+ }
+
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationManagerImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationManagerImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationManagerImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,358 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.InvalidConsumerDataException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11604 $
+ * @since 2.6
+ */
+public class RegistrationManagerImpl implements RegistrationManager
+{
+ private static final Logger log = LoggerFactory.getLogger(RegistrationManager.class);
+
+ private RegistrationPolicy policy;
+ private RegistrationPersistenceManager persistenceManager;
+
+ public RegistrationManagerImpl()
+ {
+ }
+
+ public RegistrationPolicy getPolicy()
+ {
+ return policy;
+ }
+
+ public void setPolicy(RegistrationPolicy policy)
+ {
+ this.policy = policy;
+ policy.setManager(this);
+ }
+
+ public RegistrationPersistenceManager getPersistenceManager()
+ {
+ return persistenceManager;
+ }
+
+ public void setPersistenceManager(RegistrationPersistenceManager persistenceManager)
+ {
+ this.persistenceManager = persistenceManager;
+ }
+
+ public Registration addRegistrationTo(String consumerName, Map registrationProperties,
boolean createConsumerIfNeeded)
+ throws RegistrationException
+ {
+ // the policy determines the identity of the consumer based on the given
information (note that this might be obsoleted by using WS-Security)
+ String identity = policy.getConsumerIdFrom(consumerName, registrationProperties);
+
+ // validate the registration information
+ policy.validateRegistrationDataFor(registrationProperties, identity);
+
+ Consumer consumer = getOrCreateConsumer(identity, createConsumerIfNeeded,
consumerName);
+
+ // create the actual registration
+ Registration registration = persistenceManager.addRegistrationFor(identity,
registrationProperties);
+
+ // let the policy decide what the handle should be
+ String handle = policy.createRegistrationHandleFor(registration.getId());
+ registration.setRegistrationHandle(handle);
+
+ return registration;
+ }
+
+ public Consumer createConsumer(String name) throws RegistrationException,
InvalidConsumerDataException
+ {
+ // check with policy if we allow the consumer
+ policy.validateConsumerName(name);
+
+ String identity = policy.getConsumerIdFrom(name, Collections.EMPTY_MAP);
+
+ Consumer consumer = persistenceManager.createConsumer(identity, name);
+
+ // deal with group if needed
+ // let the policy decide if there should be a group associated with the Consumer
and if yes, with which id
+ String groupName = policy.getAutomaticGroupNameFor(name);
+ if (groupName != null)
+ {
+ addConsumerToGroupNamed(name, groupName, true, false);
+ }
+
+ return consumer;
+ }
+
+ public Consumer addConsumerToGroupNamed(String consumerName, String groupName, boolean
createGroupIfNeeded, boolean createConsumerIfNeeded) throws RegistrationException
+ {
+ // check with the policy if we allow the group name in case we need to create it
+ if (createGroupIfNeeded)
+ {
+ policy.validateConsumerGroupName(groupName);
+ }
+
+ // check with policy if we allow the consumer name in case we need to create it
+ if (createConsumerIfNeeded)
+ {
+ policy.validateConsumerName(consumerName);
+ }
+
+ ConsumerGroup group = getConsumerGroup(groupName);
+ boolean justCreatedGroup = false;
+ if (group == null)
+ {
+ if (createGroupIfNeeded)
+ {
+ createConsumerGroup(groupName);
+ justCreatedGroup = true;
+ }
+ else
+ {
+ throw new NoSuchRegistrationException("There is no existing
ConsumerGroup named '" + groupName + "'.");
+ }
+ }
+
+ String identity = policy.getConsumerIdFrom(consumerName, Collections.EMPTY_MAP);
+ try
+ {
+ getOrCreateConsumer(identity, createConsumerIfNeeded, consumerName);
+ }
+ catch (NoSuchRegistrationException e)
+ {
+ if (justCreatedGroup)
+ {
+ removeConsumerGroup(groupName);
+ }
+ }
+
+ return persistenceManager.addConsumerToGroupNamed(identity, groupName);
+ }
+
+ public ConsumerGroup createConsumerGroup(String groupName) throws
RegistrationException
+ {
+ // check with the policy if we allow the group
+ policy.validateConsumerGroupName(groupName);
+
+ return persistenceManager.createConsumerGroup(groupName);
+ }
+
+ public void removeConsumer(String identity) throws RegistrationException,
NoSuchRegistrationException
+ {
+ Consumer consumer = getOrCreateConsumer(identity, false, null);
+
+ ConsumerGroup group = consumer.getGroup();
+ if (group != null)
+ {
+ group.removeConsumer(consumer);
+ }
+
+ // cascade delete the registrations
+ for (Iterator i = new ArrayList(consumer.getRegistrations()).iterator();
i.hasNext();)
+ {
+ removeRegistration((Registration)i.next());
+ }
+
+ // let the registry do the actual deletion
+ persistenceManager.removeConsumer(identity);
+ }
+
+ public void removeConsumer(Consumer consumer) throws RegistrationException,
NoSuchRegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(consumer,
"Consumer");
+
+ removeConsumer(consumer.getId());
+ }
+
+ public Consumer getConsumerByIdentity(String identity) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(identity,
"identity", null);
+ return persistenceManager.getConsumerById(identity);
+ }
+
+ public Consumer getConsumerFor(String registrationHandle) throws
RegistrationException
+ {
+ return (Consumer)getConsumerOrRegistration(registrationHandle, true);
+ }
+
+ public Registration getRegistration(String registrationHandle) throws
RegistrationException
+ {
+ return (Registration)getConsumerOrRegistration(registrationHandle, false);
+ }
+
+ public void removeRegistration(String registrationHandle) throws
RegistrationException, NoSuchRegistrationException
+ {
+ Registration registration = getRegistration(registrationHandle);
+ if (registration == null)
+ {
+ throw new NoSuchRegistrationException("There is no Registration with handle
'" + registrationHandle + "'");
+ }
+ removeRegistration(registration);
+ }
+
+ public void removeRegistration(Registration registration) throws
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(registration,
"Registration");
+
+ registration.setStatus(RegistrationStatus.INVALID); // just in case...
+// registration.clearAssociatedState(); // todo: do we need to clear associated
state?
+
+ persistenceManager.removeRegistration(registration.getId());
+ }
+
+ public ConsumerGroup getConsumerGroup(String groupName) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(groupName,
"ConsumerGroup name", null);
+ return persistenceManager.getConsumerGroup(groupName);
+ }
+
+ private Consumer getOrCreateConsumer(String identity, boolean createConsumerIfNeeded,
String consumerName)
+ throws RegistrationException
+ {
+ Consumer consumer = getConsumerByIdentity(identity);
+ if (consumer == null)
+ {
+ if (createConsumerIfNeeded)
+ {
+ consumer = createConsumer(consumerName);
+ }
+ else
+ {
+ throw new NoSuchRegistrationException("There is no Consumer named
'" + consumerName + "'.");
+ }
+ }
+ return consumer;
+ }
+
+ private Object getConsumerOrRegistration(String registrationHandle, boolean
getConsumer)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationHandle,
"registration handle", null);
+
+ Registration registration =
persistenceManager.getRegistration(registrationHandle);
+ if (registration == null)
+ {
+ return null;
+ }
+ else
+ {
+ return getConsumer ? registration.getConsumer() : registration;
+ }
+ }
+
+ public Collection getConsumerGroups()
+ {
+ return persistenceManager.getConsumerGroups();
+ }
+
+ public void removeConsumerGroup(ConsumerGroup group) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(group,
"ConsumerGroup");
+
+ for (Object consumer : group.getConsumers())
+ {
+ removeConsumer((Consumer)consumer);
+ }
+
+ persistenceManager.removeConsumerGroup(group.getName());
+ }
+
+ public void removeConsumerGroup(String name) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNull(name, "ConsumerGroup
name");
+ removeConsumerGroup(getConsumerGroup(name));
+ }
+
+ public Collection getConsumers()
+ {
+ return persistenceManager.getConsumers();
+ }
+
+ public void clear() throws RegistrationException
+ {
+ Collection<Consumer> consumers = new
ArrayList<Consumer>(getConsumers());
+ for (Consumer consumer : consumers)
+ {
+ removeConsumer(consumer);
+ }
+
+ Collection<ConsumerGroup> groups = new
ArrayList<ConsumerGroup>(getConsumerGroups());
+ for (ConsumerGroup group : groups)
+ {
+ removeConsumerGroup(group);
+ }
+ }
+
+ /**
+ * We listen to registration property changes on the producer configuration so that we
can invalidate the current
+ * registrations. Consumers will need to call modifyRegistration since properties have
changed... which requires
+ * throwing an OperationFailedFault... not an InvalidRegistrationFault!
+ *
+ * @param registrationProperties
+ */
+ public void propertiesHaveChanged(Map<QName, ? extends PropertyDescription>
registrationProperties)
+ {
+ log.debug("Registration properties have changed, existing registrations will
be invalidated...");
+ Collection registrations = persistenceManager.getRegistrations();
+ for (Object registration : registrations)
+ {
+ Registration reg = (Registration)registration;
+
+ // pending instead of invalid as technically, the registration is not yet
invalid
+ reg.setStatus(RegistrationStatus.PENDING);
+// reg.clearAssociatedState(); //todo: do we need to clear the associated state?
If we do, should we wait until current operations are done?
+ }
+
+ // make policy aware of new registration properties
+ policy.setExpectations(registrationProperties);
+ }
+
+ /**
+ * We listen for RegistrationPolicy changes so that we can provide the proper behavior
at all time if the policy has
+ * been changed by users since this RegistrationManager was initialized...
+ *
+ * @param policy
+ */
+ public void policyUpdatedTo(RegistrationPolicy policy)
+ {
+ setPolicy(policy);
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationPersistenceManagerImpl.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationPersistenceManagerImpl.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/registration/impl/RegistrationPersistenceManagerImpl.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,193 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.registration.impl;
+
+import org.jboss.portal.common.util.ParameterValidation;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.registration.RegistrationStatus;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationPersistenceManagerImpl implements
RegistrationPersistenceManager
+{
+ private long lastRegistrationId;
+ private Map consumers = new HashMap();
+ private Map groups = new HashMap();
+ private Map registrations = new HashMap();
+
+ public Consumer createConsumer(String consumerId, String consumerName) throws
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
+
+ ConsumerImpl consumer = new ConsumerImpl(consumerId, consumerName);
+ consumer.setStatus(RegistrationStatus.PENDING);
+ consumers.put(consumerId, consumer);
+
+ return consumer;
+ }
+
+ public ConsumerGroup getConsumerGroup(String name) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup
name", null);
+
+ return (ConsumerGroup)groups.get(name);
+ }
+
+ public ConsumerGroup createConsumerGroup(String name) throws RegistrationException
+ {
+ ConsumerGroup group = getConsumerGroup(name);
+ if (group != null)
+ {
+ throw new DuplicateRegistrationException("A ConsumerGroup named '"
+ name + "' has already been registered.");
+ }
+ else
+ {
+ group = new ConsumerGroupImpl(name);
+ groups.put(name, group);
+ return group;
+ }
+ }
+
+ public void removeConsumerGroup(String name) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup
name", null);
+ if (groups.remove(name) == null)
+ {
+ throw new NoSuchRegistrationException("There is no ConsumerGroup named
'" + name + "'.");
+ }
+ }
+
+ public void removeConsumer(String consumerId) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
+ if (consumers.remove(consumerId) == null)
+ {
+ throw new RegistrationException("There is no Consumer with identity
'" + consumerId + "'.");
+ }
+ }
+
+ public void removeRegistration(String registrationId) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration identity", null);
+
+ RegistrationImpl registration =
(RegistrationImpl)registrations.get(registrationId);
+ if (registration == null)
+ {
+ throw new NoSuchRegistrationException("There is no Registration with id
'" + registrationId + "'");
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)registration.getConsumer();
+ consumer.removeRegistration(registration);
+ registrations.remove(registrationId);
+ }
+
+ public Consumer getConsumerById(String consumerId) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
+
+ return (Consumer)consumers.get(consumerId);
+ }
+
+ public Registration addRegistrationFor(String consumerId, Map registrationProperties)
throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
+ ParameterValidation.throwIllegalArgExceptionIfNull(registrationProperties,
"Registration properties");
+
+ ConsumerImpl consumer = (ConsumerImpl)getConsumerById(consumerId);
+ if (consumer == null)
+ {
+ throw new NoSuchRegistrationException("There is no Consumer with identity
'" + consumerId
+ + "' to add a Registration to...");
+ }
+
+ RegistrationImpl registration = new RegistrationImpl("" +
lastRegistrationId++, consumer,
+ RegistrationStatus.PENDING, registrationProperties);
+ consumer.addRegistration(registration);
+
+ registrations.put(registration.getId(), registration);
+
+ return registration;
+ }
+
+ public Consumer addConsumerToGroupNamed(String consumerId, String groupName) throws
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(groupName,
"ConsumerGroup name", null);
+
+ ConsumerGroupImpl group = (ConsumerGroupImpl)getConsumerGroup(groupName);
+ if (group == null)
+ {
+ throw new NoSuchRegistrationException("There is no ConsumerGroup named
'" + groupName
+ + "' to add a Consumer to...");
+ }
+
+ ConsumerImpl consumer = (ConsumerImpl)getConsumerById(consumerId);
+ if (consumer == null)
+ {
+ throw new NoSuchRegistrationException("There is no Consumer with identity
'" + consumerId
+ + "' to add to ConsumerGroup named '" + groupName +
"'. Did you create it?");
+ }
+
+ group.addConsumer(consumer);
+
+ return consumer;
+ }
+
+ public Collection getConsumers()
+ {
+ return Collections.unmodifiableCollection(consumers.values());
+ }
+
+ public Collection getRegistrations()
+ {
+ return Collections.unmodifiableCollection(registrations.values());
+ }
+
+ public Collection getConsumerGroups()
+ {
+ return Collections.unmodifiableCollection(groups.values());
+ }
+
+ public Registration getRegistration(String registrationId)
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"Registration id", null);
+
+ return (Registration)registrations.get(registrationId);
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/AbstractRegistrationPersistenceManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/AbstractRegistrationPersistenceManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/AbstractRegistrationPersistenceManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,437 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.common.util.MapBuilder;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9218 $
+ * @since 2.6
+ */
+public abstract class AbstractRegistrationPersistenceManagerTestCase extends TestCase
+{
+
+ /** . */
+ private Map registrationProperties;
+
+ public abstract RegistrationPersistenceManager getManager();
+
+ public void startInteraction()
+ {
+ }
+
+ public void stopInteraction()
+ {
+ }
+
+ public void setUp() throws Exception
+ {
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ registrationProperties = null;
+ }
+
+ public void testGetGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().getConsumerGroup(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddGroup() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+
+ // Test by retrieving the same consumer
+ startInteraction();
+ group = getManager().getConsumerGroup("Foo");
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+
+ // Test by retrieving the consumer list
+ startInteraction();
+ Collection groups = getManager().getConsumerGroups();
+ assertNotNull(groups);
+ assertEquals(1, groups.size());
+ group = (ConsumerGroup)groups.iterator().next();
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+ }
+
+ public void testAddDuplicateGroup() throws Exception
+ {
+ startInteraction();
+ getManager().createConsumerGroup("Foo");
+ try
+ {
+ getManager().createConsumerGroup("Foo");
+ fail();
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().createConsumerGroup(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(Collections.EMPTY_SET, new
HashSet(getManager().getConsumerGroups()));
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveGroup() throws Exception
+ {
+ startInteraction();
+ getManager().createConsumerGroup("Foo");
+ stopInteraction();
+
+ startInteraction();
+ getManager().removeConsumerGroup("Foo");
+ assertNull(getManager().getConsumerGroup("Foo"));
+ assertEquals(Collections.EMPTY_SET, new
HashSet(getManager().getConsumerGroups()));
+ stopInteraction();
+ }
+
+ public void testRemoveGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeConsumerGroup(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveNonExistingGroup() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeConsumerGroup("Foo");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testGetConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ group.getConsumer(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ stopInteraction();
+
+ startInteraction();
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+
+ // Test by retrieving the same consumer
+ startInteraction();
+ consumer = group.getConsumer("Bar");
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+
+ // Test by retrieving the consumer list
+ startInteraction();
+ Collection consumers = group.getConsumers();
+ assertNotNull(consumers);
+ assertEquals(1, consumers.size());
+ consumer = (Consumer)consumers.iterator().next();
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+ }
+
+ public void testAddDuplicateConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ stopInteraction();
+
+ startInteraction();
+ try
+ {
+ group.addConsumer(consumer);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ try
+ {
+ group.addConsumer(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ group.removeConsumer(consumer);
+ assertNull(group.getConsumer("Bar"));
+ assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+ stopInteraction();
+ }
+
+ public void testRemoveConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ try
+ {
+ group.removeConsumer(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddRegistration() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ stopInteraction();
+
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Registration reg1 = getManager().addRegistrationFor("Bar",
registrationProperties);
+ assertNotNull(reg1);
+ String regId = reg1.getId();
+ assertNotNull(regId);
+ assertEquals(consumer, reg1.getConsumer());
+ Map expectedProps = new HashMap();
+ expectedProps.put(new QName("prop1"), "value1");
+ expectedProps.put(new QName("prop2"), "value2");
+ assertEquals(expectedProps, reg1.getProperties());
+ stopInteraction();
+
+ // Retrieve it from the list of consumer registrations
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Collection registrations = consumer.getRegistrations();
+ assertNotNull(registrations);
+ assertEquals(1, registrations.size());
+ Registration reg3 = (Registration)registrations.iterator().next();
+ assertEquals(regId, reg3.getId());
+ assertEquals(consumer, reg3.getConsumer());
+ assertEquals(expectedProps, reg3.getProperties());
+ stopInteraction();
+
+ // Retrieve the same registration from the registry
+ startInteraction();
+ Registration reg2 = getManager().getRegistration(regId);
+ consumer = getManager().getConsumerById("Bar");
+ assertNotNull(reg2);
+ assertEquals(regId, reg2.getId());
+ assertEquals(consumer, reg2.getConsumer());
+ assertEquals(expectedProps, reg2.getProperties());
+ stopInteraction();
+ }
+
+ public void testAddRegistrationThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+
+ try
+ {
+ getManager().addRegistrationFor(consumer.getId(), null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveRegistrationThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeRegistration(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveRegistration() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ Registration reg = getManager().addRegistrationFor("Bar",
registrationProperties);
+ String regId = reg.getId();
+ getManager().removeRegistration(regId);
+ stopInteraction();
+
+ // remove registration is the only method on RegistrationPersistenceManager that
needs to "cascade"
+ // this is needed because there is no remove method on Consumer, hence the manager
needs to remove the
+ // registration from its consumer since it's the only class that has access to
the specific consumer impl
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Collection registrations = consumer.getRegistrations();
+ assertNotNull(registrations);
+ assertEquals(0, registrations.size());
+ stopInteraction();
+
+ //
+ startInteraction();
+ assertEquals(null, getManager().getRegistration(regId));
+ stopInteraction();
+ }
+
+ public void testBulkUpdateRegistrationProperties() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ getManager().addRegistrationFor("Bar", registrationProperties);
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Registration reg = (Registration)consumer.getRegistrations().iterator().next();
+ registrationProperties.remove(new QName("prop1"));
+ reg.updateProperties(registrationProperties);
+ assertEquals(Collections.singletonMap(new QName("prop2"),
"value2"), reg.getProperties());
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ reg = (Registration)consumer.getRegistrations().iterator().next();
+ assertEquals(Collections.singletonMap(new QName("prop2"),
"value2"), reg.getProperties());
+ registrationProperties.put(new QName("prop3"), "value3");
+ reg.updateProperties(registrationProperties);
+ assertEquals(MapBuilder.hashMap().put(new QName("prop2"),
"value2").put(new QName("prop3"), "value3").get(),
reg.getProperties());
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ reg = (Registration)consumer.getRegistrations().iterator().next();
+ assertEquals(MapBuilder.hashMap().put(new QName("prop2"),
"value2").put(new QName("prop3"), "value3").get(),
reg.getProperties());
+ stopInteraction();
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerGroupTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerGroupTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerGroupTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerGroupTestCase extends TestCase
+{
+ private RegistrationManager manager;
+ private ConsumerGroup group;
+ private static final String NAME = "name";
+
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+ group = manager.createConsumerGroup(NAME);
+ }
+
+ public void testGetName()
+ {
+ assertEquals(NAME, group.getName());
+ }
+
+ public void testConsumersManagement() throws RegistrationException
+ {
+ assertTrue(group.isEmpty());
+ assertEquals(0, group.getConsumers().size());
+
+ Consumer c1 = manager.createConsumer("c1");
+ group.addConsumer(c1);
+ assertTrue(!group.isEmpty());
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(group.contains(c1));
+ assertEquals(group, c1.getGroup());
+ assertEquals(c1, group.getConsumer(c1.getId()));
+
+ Consumer c2 = manager.createConsumer("c2");
+ group.addConsumer(c2);
+ assertEquals(2, group.getConsumers().size());
+ assertTrue(group.contains(c2));
+ assertEquals(group, c2.getGroup());
+
+ group.removeConsumer(c1);
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(!group.contains(c1));
+ assertTrue(group.contains(c2));
+ assertEquals(null, c1.getGroup());
+ }
+
+ public void testAddNullConsumer() throws RegistrationException
+ {
+ try
+ {
+ group.addConsumer(null);
+ fail("Shouldn't be possible to add null consumer");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, group.getStatus());
+ group.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, group.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ group.setStatus(null);
+ fail("Shouldn't be possible to set the status to null");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/ConsumerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerTestCase extends TestCase
+{
+ private Consumer consumer;
+ private RegistrationManager manager;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+ consumer = manager.createConsumer("name");
+ }
+
+ public void testGetName()
+ {
+ assertEquals("name", consumer.getName());
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ consumer.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, consumer.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ consumer.setStatus(null);
+ fail("Was expecting an IllegalArgumentException to be thrown on
setStatus(null)");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testSetGroup() throws Exception
+ {
+ ConsumerGroup group = manager.createConsumerGroup("group");
+ assertTrue(!group.getConsumers().contains(consumer));
+
+ consumer.setGroup(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+
+ consumer.setGroup(null);
+ assertNull(consumer.getGroup());
+ assertTrue(!group.getConsumers().contains(consumer));
+ }
+
+ public void testGetIdentity() throws Exception
+ {
+ assertNotNull(consumer.getId());
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/DefaultRegistrationPolicyTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+import org.jboss.portal.registration.policies.DefaultRegistrationPropertyValidator;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9180 $
+ * @since 2.6.3
+ */
+public class DefaultRegistrationPolicyTestCase extends TestCase
+{
+ DefaultRegistrationPolicy policy;
+ Map registrationProperties;
+ HashMap<QName, PropertyDescription> expectations;
+ private static final String CONSUMER = "consumer";
+ private static final QName PROP1 = new QName("prop1");
+ private static final QName PROP2 = new QName("prop2");
+ private static final QName PROP3 = new QName("prop3");
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ policy = new DefaultRegistrationPolicy();
+
+ policy.setValidator(new DefaultRegistrationPropertyValidator());
+
+ RegistrationManager manager = new RegistrationManagerImpl();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ manager.createConsumer(CONSUMER);
+
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(PROP1, "value1");
+ registrationProperties.put(PROP2, "value2");
+
+ expectations = new HashMap<QName, PropertyDescription>();
+ policy.setExpectations(expectations);
+ }
+
+ public void testValidateRegistrationDataForNull() throws RegistrationException
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(null, "foo");
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, null);
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testValidateRegistrationDataForInexistentConsumer()
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, "foo");
+ }
+ catch (RegistrationException e)
+ {
+ fail("Should be possible to validate information for inexistent consumer
(otherwise, how would we register!)");
+ }
+ }
+
+ public void testValidateRegistrationDataMissingProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+ expectations.put(PROP2, new TestPropertyDescription(PROP2));
+ expectations.put(PROP3, new TestPropertyDescription(PROP3));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Missing prop3 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop3"));
+ }
+ }
+
+ public void testValidateRegistrationDataExtraProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Extra prop2 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop2"));
+ }
+ }
+
+ public void testValidateRegistrationDataInvalidValue()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ registrationProperties.remove(PROP2);
+ registrationProperties.put(PROP1, null);
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Should have detected null value for prop1");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop1"));
+ }
+ }
+
+ static class TestPropertyDescription implements PropertyDescription
+ {
+ private QName name;
+ private static final QName TYPE = new QName("type");
+
+ TestPropertyDescription(QName name)
+ {
+ this.name = name;
+ }
+
+ public QName getName()
+ {
+ return name;
+ }
+
+ public QName getType()
+ {
+ return TYPE;
+ }
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,431 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationManagerTestCase extends TestCase
+{
+
+ private RegistrationManager manager;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ // todo: policy will need access to registration configuration information to
validate properties
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+
+ //todo: registration properties setup will need to be updated when property
validation is implemented
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ public void testPolicy()
+ {
+ RegistrationPolicy policy = manager.getPolicy();
+ assertNotNull(policy);
+ assertEquals(manager, policy.getManager());
+ }
+
+ public void testAddRegistrationTo() throws Exception
+ {
+ Registration registration = manager.addRegistrationTo("consumerName",
registrationProperties, true);
+ assertNotNull(registration);
+ assertNotNull(registration.getId());
+
+ Consumer consumer = manager.getConsumerByIdentity("consumerName");
+ assertNotNull(consumer); // default policy: name == identity
+ assertEquals(consumer, registration.getConsumer());
+
+ String registrationHandle = registration.getRegistrationHandle();
+ assertNotNull(registrationHandle);
+ assertEquals(consumer, manager.getConsumerFor(registrationHandle));
+ }
+
+ public void testAddRegistrationToInexistentConsumer() throws RegistrationException
+ {
+ try
+ {
+ manager.addRegistrationTo("consumerName", registrationProperties,
false);
+ fail("Should have failed: consumer does not exist");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("consumerName")); // default
policy: name == identity
+ }
+
+ public void testGetConsumerForNullRegistrationHandle() throws Exception
+ {
+ try
+ {
+ manager.getConsumerFor(null);
+ fail("Should have failed: cannot find a consumer for a null registration
handle");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testCreateConsumer() throws Exception
+ {
+ String name = "consumerName";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+ assertEquals(name, consumer.getName());
+ assertNotNull(consumer.getId());
+ assertNull(consumer.getGroup());
+
+ Collection consumers = manager.getConsumers();
+ assertEquals(1, consumers.size());
+ assertTrue(consumers.contains(consumer));
+ assertEquals(consumer, manager.getConsumerByIdentity(name)); // default policy:
name == identity
+
+ try
+ {
+ consumers.add(consumer);
+ fail("Shouldn't be possible to directly modify consumer
collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testCreateConsumerWithGroupFromPolicy() throws RegistrationException
+ {
+ // use a different policy: now specifies that when creating a consumer, it should
be added to a group with the same name
+ DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy()
+ {
+ public String getAutomaticGroupNameFor(String consumerName)
+ {
+ return "group_" + consumerName;
+ }
+ };
+ manager.setPolicy(policy);
+ policy.setManager(manager);
+
+ String name = "name";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+
+ ConsumerGroup group = manager.getConsumerGroup("group_" + name);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+ }
+
+ public void testCreateDuplicateConsumer() throws RegistrationException
+ {
+ String name = "name";
+ assertNotNull(manager.createConsumer(name));
+
+ try
+ {
+ manager.createConsumer(name);
+ fail("Should have failed when trying to create a consumer with an existing
name");
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+ }
+
+ public void testAddAutomaticallyCreatedConsumerToInexistentGroup() throws
RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false, true);
+ fail("Shouldn't be possible to add a consumer to an inexistent group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToAutomaticallyCreatedGroup() throws
RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", true, false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToGroup() throws RegistrationException
+ {
+ manager.createConsumerGroup("bar");
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false,
false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNotNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToInexistentGroup() throws RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false,
false);
+ fail("Shouldn't be possible to add a consumer to an inexistent group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddConsumerToGroup() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true,
true);
+
+ Consumer consumer1 = manager.getConsumerByIdentity(consumerName);
+ assertNotNull(consumer1);
+ assertEquals(consumer1, consumer); // default policy: identity == name
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ }
+
+ public void testCreateConsumerGroup() throws Exception
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(groupName, group.getName());
+
+ Collection groups = manager.getConsumerGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(group));
+ assertEquals(group, manager.getConsumerGroup(groupName));
+
+ try
+ {
+ groups.add(group);
+ fail("Shouldn't be possible to directly modify group
collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testRemoveConsumerGroup() throws RegistrationException
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerGroup(groupName));
+
+ manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(groupName);
+ assertNull(manager.getConsumerGroup(groupName));
+ }
+
+ public void testCascadeRemovalOnConsumerGroupRemoval() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true,
true);
+ String consumerIdentity = consumer.getId();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testCascadeRemovalOnConsumerRemoval() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+ String consumerIdentity = consumer.getId();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ manager.removeConsumer(consumer);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testRemoveSingleRegistration() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ assertTrue(consumer.getRegistrations().contains(reg));
+
+ // set the consumer status to valid
+ consumer.setStatus(RegistrationStatus.VALID);
+
+ manager.removeRegistration(handle);
+ assertTrue(!consumer.getRegistrations().contains(reg));
+ assertNull(manager.getRegistration(handle));
+
+ // since the consumer doesn't have any registration anymore, its status should
become pending
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // shouldn't be possible anymore to retrieve the consumer from the registration
handle
+ assertNull(manager.getConsumerFor(handle));
+ }
+
+ public void testRemoveRegistrationOnConsumerWithOtherRegistrations() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ // todo: this won't work anymore when properties validation is implemented
+ registrationProperties.put(new QName("prop3"), "value3");
+ Registration r2 = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+
+ RegistrationStatus status = consumer.getStatus();
+
+ manager.removeRegistration(handle);
+
+ // consumer status shouldn't have changed
+ assertEquals(status, consumer.getStatus());
+
+ // should still be able to retrieve consumer from r2 handle
+ assertEquals(consumer, manager.getConsumerFor(r2.getRegistrationHandle()));
+
+ // ... but not from handle
+ assertNull(manager.getConsumerFor(handle));
+ }
+
+ public void testAddRegistrationWithInvalidRegistrationProperties() throws Exception
+ {
+ // todo: implement
+ }
+
+ public void testRemoveInexistentRegistration() throws RegistrationException
+ {
+ try
+ {
+ manager.removeRegistration((Registration)null);
+ fail("Should be possible to remove a null registration");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration((String)null);
+ fail("Should be possible to remove a registration with a null
handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("");
+ fail("Should be possible to remove a registration with an empty
handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("doesn't exist");
+ fail("Should be possible to remove a registration with an invalid
handle");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+ }
+
+ public void testClear() throws Exception
+ {
+ manager.createConsumer("c1");
+ manager.createConsumer("c2");
+ manager.addConsumerToGroupNamed("c1g1", "g1", true, true);
+ manager.createConsumerGroup("g2");
+ Registration r1 = manager.addRegistrationTo("c1", registrationProperties,
false);
+ Registration r2 = manager.addRegistrationTo("c3", registrationProperties,
true);
+
+ manager.clear();
+ assertTrue(manager.getConsumerGroups().isEmpty());
+ assertTrue(manager.getConsumers().isEmpty());
+ assertNull(manager.getRegistration(r1.getRegistrationHandle()));
+ assertNull(manager.getRegistration(r2.getRegistrationHandle()));
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationPersistenceManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationPersistenceManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationPersistenceManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationPersistenceManagerTestCase extends
AbstractRegistrationPersistenceManagerTestCase
+{
+
+ /** . */
+ private RegistrationPersistenceManager manager;
+
+ public void setUp() throws Exception
+ {
+ manager = new RegistrationPersistenceManagerImpl();
+
+ //
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ //
+ this.manager = null;
+ }
+
+ public RegistrationPersistenceManager getManager()
+ {
+ return manager;
+ }
+}
Added:
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/main/java/org/jboss/portal/test/registration/RegistrationTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11406 $
+ * @since 2.6
+ */
+public class RegistrationTestCase extends TestCase
+{
+ private Registration registration;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ RegistrationManager manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy()
+ {
+ public void validateRegistrationDataFor(Map<QName, ? extends
PropertyDescription> registrationProperties, String consumerIdentity) throws
IllegalArgumentException, RegistrationException, DuplicateRegistrationException
+ {
+ // accept any registration data here
+ }
+ };
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+
+ registration = manager.addRegistrationTo("name", registrationProperties,
true);
+ }
+
+ public void testGetPropertiesIsUnmodifiable()
+ {
+ Map properties = registration.getProperties();
+
+ try
+ {
+ properties.remove("foo");
+ fail("Properties shouldn't be directly modifiable");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testPropertiesAreClonedNotLive()
+ {
+ QName prop = new QName("prop3");
+ registrationProperties.put(prop, "value3");
+
+ assertNull(registration.getProperties().get(prop));
+ }
+
+ public void testSetNullPropertyValueThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor("foo", null);
+ fail("Shouldn't accept null values for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testSetNullPropertyNameThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor((QName)null, null);
+ fail("Shouldn't accept null names for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testProperties()
+ {
+ QName name = new QName("prop1");
+ assertEquals("value1", registration.getProperties().get(name));
+ assertEquals("value2", registration.getProperties().get(new
QName("prop2")));
+
+ String newValue = "new value";
+ registration.setPropertyValueFor("prop1", newValue);
+ assertEquals(newValue, registration.getProperties().get(name));
+
+ registration.removeProperty(name);
+ assertNull(registration.getPropertyValueFor(name));
+ }
+
+ public void testUpdateProperties()
+ {
+ registrationProperties.remove(new QName("prop1"));
+
+ registration.updateProperties(registrationProperties);
+ assertNull(registration.getPropertyValueFor("prop1"));
+
+ QName name = new QName("prop3");
+ String value = "value3";
+ registrationProperties.put(name, value);
+ registration.updateProperties(registrationProperties);
+ assertEquals(value, registration.getPropertyValueFor(name));
+ }
+
+ public void testHasEqualProperties()
+ {
+ assertTrue(registration.hasEqualProperties(registration));
+
+ assertTrue(registration.hasEqualProperties(registrationProperties));
+
+ registrationProperties.put(new QName("prop3"), "value3");
+ assertTrue(!registration.hasEqualProperties(registrationProperties));
+ }
+
+ public void testClearAssociatedState()
+ {
+ //todo: implement
+ }
+
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/AbstractRegistrationPersistenceManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/AbstractRegistrationPersistenceManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/AbstractRegistrationPersistenceManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,437 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.common.util.MapBuilder;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9218 $
+ * @since 2.6
+ */
+public abstract class AbstractRegistrationPersistenceManagerTestCase extends TestCase
+{
+
+ /** . */
+ private Map registrationProperties;
+
+ public abstract RegistrationPersistenceManager getManager();
+
+ public void startInteraction()
+ {
+ }
+
+ public void stopInteraction()
+ {
+ }
+
+ public void setUp() throws Exception
+ {
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ protected void tearDown() throws Exception
+ {
+ registrationProperties = null;
+ }
+
+ public void testGetGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().getConsumerGroup(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddGroup() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+
+ // Test by retrieving the same consumer
+ startInteraction();
+ group = getManager().getConsumerGroup("Foo");
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+
+ // Test by retrieving the consumer list
+ startInteraction();
+ Collection groups = getManager().getConsumerGroups();
+ assertNotNull(groups);
+ assertEquals(1, groups.size());
+ group = (ConsumerGroup)groups.iterator().next();
+ assertNotNull(group);
+ assertEquals("Foo", group.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(group.getConsumers()));
+ stopInteraction();
+ }
+
+ public void testAddDuplicateGroup() throws Exception
+ {
+ startInteraction();
+ getManager().createConsumerGroup("Foo");
+ try
+ {
+ getManager().createConsumerGroup("Foo");
+ fail();
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().createConsumerGroup(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(Collections.EMPTY_SET, new
HashSet(getManager().getConsumerGroups()));
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveGroup() throws Exception
+ {
+ startInteraction();
+ getManager().createConsumerGroup("Foo");
+ stopInteraction();
+
+ startInteraction();
+ getManager().removeConsumerGroup("Foo");
+ assertNull(getManager().getConsumerGroup("Foo"));
+ assertEquals(Collections.EMPTY_SET, new
HashSet(getManager().getConsumerGroups()));
+ stopInteraction();
+ }
+
+ public void testRemoveGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeConsumerGroup(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveNonExistingGroup() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeConsumerGroup("Foo");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testGetConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ group.getConsumer(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ stopInteraction();
+
+ startInteraction();
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+
+ // Test by retrieving the same consumer
+ startInteraction();
+ consumer = group.getConsumer("Bar");
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+
+ // Test by retrieving the consumer list
+ startInteraction();
+ Collection consumers = group.getConsumers();
+ assertNotNull(consumers);
+ assertEquals(1, consumers.size());
+ consumer = (Consumer)consumers.iterator().next();
+ assertNotNull(consumer);
+ assertEquals("Bar", consumer.getName());
+ assertEquals(Collections.EMPTY_LIST, new ArrayList(consumer.getRegistrations()));
+ assertEquals("Foo", consumer.getGroup().getName());
+ stopInteraction();
+ }
+
+ public void testAddDuplicateConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ stopInteraction();
+
+ startInteraction();
+ try
+ {
+ group.addConsumer(consumer);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ try
+ {
+ group.addConsumer(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveConsumer() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ group.removeConsumer(consumer);
+ assertNull(group.getConsumer("Bar"));
+ assertEquals(Collections.EMPTY_SET, new HashSet(group.getConsumers()));
+ stopInteraction();
+ }
+
+ public void testRemoveConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ try
+ {
+ group.removeConsumer(null);
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testAddRegistration() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ stopInteraction();
+
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Registration reg1 = getManager().addRegistrationFor("Bar",
registrationProperties);
+ assertNotNull(reg1);
+ String regId = reg1.getId();
+ assertNotNull(regId);
+ assertEquals(consumer, reg1.getConsumer());
+ Map expectedProps = new HashMap();
+ expectedProps.put(new QName("prop1"), "value1");
+ expectedProps.put(new QName("prop2"), "value2");
+ assertEquals(expectedProps, reg1.getProperties());
+ stopInteraction();
+
+ // Retrieve it from the list of consumer registrations
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Collection registrations = consumer.getRegistrations();
+ assertNotNull(registrations);
+ assertEquals(1, registrations.size());
+ Registration reg3 = (Registration)registrations.iterator().next();
+ assertEquals(regId, reg3.getId());
+ assertEquals(consumer, reg3.getConsumer());
+ assertEquals(expectedProps, reg3.getProperties());
+ stopInteraction();
+
+ // Retrieve the same registration from the registry
+ startInteraction();
+ Registration reg2 = getManager().getRegistration(regId);
+ consumer = getManager().getConsumerById("Bar");
+ assertNotNull(reg2);
+ assertEquals(regId, reg2.getId());
+ assertEquals(consumer, reg2.getConsumer());
+ assertEquals(expectedProps, reg2.getProperties());
+ stopInteraction();
+ }
+
+ public void testAddRegistrationThrowsIAE() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+
+ try
+ {
+ getManager().addRegistrationFor(consumer.getId(), null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveRegistrationThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().removeRegistration(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testRemoveRegistration() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ Registration reg = getManager().addRegistrationFor("Bar",
registrationProperties);
+ String regId = reg.getId();
+ getManager().removeRegistration(regId);
+ stopInteraction();
+
+ // remove registration is the only method on RegistrationPersistenceManager that
needs to "cascade"
+ // this is needed because there is no remove method on Consumer, hence the manager
needs to remove the
+ // registration from its consumer since it's the only class that has access to
the specific consumer impl
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Collection registrations = consumer.getRegistrations();
+ assertNotNull(registrations);
+ assertEquals(0, registrations.size());
+ stopInteraction();
+
+ //
+ startInteraction();
+ assertEquals(null, getManager().getRegistration(regId));
+ stopInteraction();
+ }
+
+ public void testBulkUpdateRegistrationProperties() throws Exception
+ {
+ startInteraction();
+ ConsumerGroup group = getManager().createConsumerGroup("Foo");
+ Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ group.addConsumer(consumer);
+ getManager().addRegistrationFor("Bar", registrationProperties);
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ Registration reg = (Registration)consumer.getRegistrations().iterator().next();
+ registrationProperties.remove(new QName("prop1"));
+ reg.updateProperties(registrationProperties);
+ assertEquals(Collections.singletonMap(new QName("prop2"),
"value2"), reg.getProperties());
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ reg = (Registration)consumer.getRegistrations().iterator().next();
+ assertEquals(Collections.singletonMap(new QName("prop2"),
"value2"), reg.getProperties());
+ registrationProperties.put(new QName("prop3"), "value3");
+ reg.updateProperties(registrationProperties);
+ assertEquals(MapBuilder.hashMap().put(new QName("prop2"),
"value2").put(new QName("prop3"), "value3").get(),
reg.getProperties());
+ stopInteraction();
+
+ //
+ startInteraction();
+ consumer = getManager().getConsumerById("Bar");
+ reg = (Registration)consumer.getRegistrations().iterator().next();
+ assertEquals(MapBuilder.hashMap().put(new QName("prop2"),
"value2").put(new QName("prop3"), "value3").get(),
reg.getProperties());
+ stopInteraction();
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerGroupTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerGroupTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerGroupTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,120 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerGroupTestCase extends TestCase
+{
+ private RegistrationManager manager;
+ private ConsumerGroup group;
+ private static final String NAME = "name";
+
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+ group = manager.createConsumerGroup(NAME);
+ }
+
+ public void testGetName()
+ {
+ assertEquals(NAME, group.getName());
+ }
+
+ public void testConsumersManagement() throws RegistrationException
+ {
+ assertTrue(group.isEmpty());
+ assertEquals(0, group.getConsumers().size());
+
+ Consumer c1 = manager.createConsumer("c1");
+ group.addConsumer(c1);
+ assertTrue(!group.isEmpty());
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(group.contains(c1));
+ assertEquals(group, c1.getGroup());
+ assertEquals(c1, group.getConsumer(c1.getId()));
+
+ Consumer c2 = manager.createConsumer("c2");
+ group.addConsumer(c2);
+ assertEquals(2, group.getConsumers().size());
+ assertTrue(group.contains(c2));
+ assertEquals(group, c2.getGroup());
+
+ group.removeConsumer(c1);
+ assertEquals(1, group.getConsumers().size());
+ assertTrue(!group.contains(c1));
+ assertTrue(group.contains(c2));
+ assertEquals(null, c1.getGroup());
+ }
+
+ public void testAddNullConsumer() throws RegistrationException
+ {
+ try
+ {
+ group.addConsumer(null);
+ fail("Shouldn't be possible to add null consumer");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, group.getStatus());
+ group.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, group.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ group.setStatus(null);
+ fail("Shouldn't be possible to set the status to null");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/ConsumerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class ConsumerTestCase extends TestCase
+{
+ private Consumer consumer;
+ private RegistrationManager manager;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+ consumer = manager.createConsumer("name");
+ }
+
+ public void testGetName()
+ {
+ assertEquals("name", consumer.getName());
+ }
+
+ public void testStatus()
+ {
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ consumer.setStatus(RegistrationStatus.VALID);
+ assertEquals(RegistrationStatus.VALID, consumer.getStatus());
+ }
+
+ public void testIllegalStatus()
+ {
+ try
+ {
+ consumer.setStatus(null);
+ fail("Was expecting an IllegalArgumentException to be thrown on
setStatus(null)");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ }
+
+ public void testSetGroup() throws Exception
+ {
+ ConsumerGroup group = manager.createConsumerGroup("group");
+ assertTrue(!group.getConsumers().contains(consumer));
+
+ consumer.setGroup(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+
+ consumer.setGroup(null);
+ assertNull(consumer.getGroup());
+ assertTrue(!group.getConsumers().contains(consumer));
+ }
+
+ public void testGetIdentity() throws Exception
+ {
+ assertNotNull(consumer.getId());
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/DefaultRegistrationPolicyTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/DefaultRegistrationPolicyTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/DefaultRegistrationPolicyTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+import org.jboss.portal.registration.policies.DefaultRegistrationPropertyValidator;
+
+import javax.xml.namespace.QName;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 9180 $
+ * @since 2.6.3
+ */
+public class DefaultRegistrationPolicyTestCase extends TestCase
+{
+ DefaultRegistrationPolicy policy;
+ Map registrationProperties;
+ HashMap<QName, PropertyDescription> expectations;
+ private static final String CONSUMER = "consumer";
+ private static final QName PROP1 = new QName("prop1");
+ private static final QName PROP2 = new QName("prop2");
+ private static final QName PROP3 = new QName("prop3");
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ policy = new DefaultRegistrationPolicy();
+
+ policy.setValidator(new DefaultRegistrationPropertyValidator());
+
+ RegistrationManager manager = new RegistrationManagerImpl();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ manager.createConsumer(CONSUMER);
+
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(PROP1, "value1");
+ registrationProperties.put(PROP2, "value2");
+
+ expectations = new HashMap<QName, PropertyDescription>();
+ policy.setExpectations(expectations);
+ }
+
+ public void testValidateRegistrationDataForNull() throws RegistrationException
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(null, "foo");
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, null);
+ fail("null data cannot be validated");
+ }
+ catch (IllegalArgumentException e)
+ {
+ // expected
+ }
+ }
+
+ public void testValidateRegistrationDataForInexistentConsumer()
+ {
+ try
+ {
+ policy.validateRegistrationDataFor(Collections.EMPTY_MAP, "foo");
+ }
+ catch (RegistrationException e)
+ {
+ fail("Should be possible to validate information for inexistent consumer
(otherwise, how would we register!)");
+ }
+ }
+
+ public void testValidateRegistrationDataMissingProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+ expectations.put(PROP2, new TestPropertyDescription(PROP2));
+ expectations.put(PROP3, new TestPropertyDescription(PROP3));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Missing prop3 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop3"));
+ }
+ }
+
+ public void testValidateRegistrationDataExtraProps()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Extra prop2 should have been detected");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop2"));
+ }
+ }
+
+ public void testValidateRegistrationDataInvalidValue()
+ {
+ expectations.put(PROP1, new TestPropertyDescription(PROP1));
+
+ registrationProperties.remove(PROP2);
+ registrationProperties.put(PROP1, null);
+
+ try
+ {
+ policy.validateRegistrationDataFor(registrationProperties, CONSUMER);
+ fail("Should have detected null value for prop1");
+ }
+ catch (RegistrationException e)
+ {
+ assertTrue(e.getLocalizedMessage().contains("prop1"));
+ }
+ }
+
+ static class TestPropertyDescription implements PropertyDescription
+ {
+ private QName name;
+ private static final QName TYPE = new QName("type");
+
+ TestPropertyDescription(QName name)
+ {
+ this.name = name;
+ }
+
+ public QName getName()
+ {
+ return name;
+ }
+
+ public QName getType()
+ {
+ return TYPE;
+ }
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,431 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.Consumer;
+import org.jboss.portal.registration.ConsumerGroup;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.NoSuchRegistrationException;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.RegistrationStatus;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationManagerTestCase extends TestCase
+{
+
+ private RegistrationManager manager;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ manager = new RegistrationManagerImpl();
+ // todo: policy will need access to registration configuration information to
validate properties
+ RegistrationPolicy policy = new DefaultRegistrationPolicy();
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+
+ //todo: registration properties setup will need to be updated when property
validation is implemented
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+ }
+
+ public void testPolicy()
+ {
+ RegistrationPolicy policy = manager.getPolicy();
+ assertNotNull(policy);
+ assertEquals(manager, policy.getManager());
+ }
+
+ public void testAddRegistrationTo() throws Exception
+ {
+ Registration registration = manager.addRegistrationTo("consumerName",
registrationProperties, true);
+ assertNotNull(registration);
+ assertNotNull(registration.getId());
+
+ Consumer consumer = manager.getConsumerByIdentity("consumerName");
+ assertNotNull(consumer); // default policy: name == identity
+ assertEquals(consumer, registration.getConsumer());
+
+ String registrationHandle = registration.getRegistrationHandle();
+ assertNotNull(registrationHandle);
+ assertEquals(consumer, manager.getConsumerFor(registrationHandle));
+ }
+
+ public void testAddRegistrationToInexistentConsumer() throws RegistrationException
+ {
+ try
+ {
+ manager.addRegistrationTo("consumerName", registrationProperties,
false);
+ fail("Should have failed: consumer does not exist");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("consumerName")); // default
policy: name == identity
+ }
+
+ public void testGetConsumerForNullRegistrationHandle() throws Exception
+ {
+ try
+ {
+ manager.getConsumerFor(null);
+ fail("Should have failed: cannot find a consumer for a null registration
handle");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ }
+
+ public void testCreateConsumer() throws Exception
+ {
+ String name = "consumerName";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+ assertEquals(name, consumer.getName());
+ assertNotNull(consumer.getId());
+ assertNull(consumer.getGroup());
+
+ Collection consumers = manager.getConsumers();
+ assertEquals(1, consumers.size());
+ assertTrue(consumers.contains(consumer));
+ assertEquals(consumer, manager.getConsumerByIdentity(name)); // default policy:
name == identity
+
+ try
+ {
+ consumers.add(consumer);
+ fail("Shouldn't be possible to directly modify consumer
collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testCreateConsumerWithGroupFromPolicy() throws RegistrationException
+ {
+ // use a different policy: now specifies that when creating a consumer, it should
be added to a group with the same name
+ DefaultRegistrationPolicy policy = new DefaultRegistrationPolicy()
+ {
+ public String getAutomaticGroupNameFor(String consumerName)
+ {
+ return "group_" + consumerName;
+ }
+ };
+ manager.setPolicy(policy);
+ policy.setManager(manager);
+
+ String name = "name";
+ Consumer consumer = manager.createConsumer(name);
+ assertNotNull(consumer);
+
+ ConsumerGroup group = manager.getConsumerGroup("group_" + name);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ assertTrue(group.getConsumers().contains(consumer));
+ }
+
+ public void testCreateDuplicateConsumer() throws RegistrationException
+ {
+ String name = "name";
+ assertNotNull(manager.createConsumer(name));
+
+ try
+ {
+ manager.createConsumer(name);
+ fail("Should have failed when trying to create a consumer with an existing
name");
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+ }
+
+ public void testAddAutomaticallyCreatedConsumerToInexistentGroup() throws
RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false, true);
+ fail("Shouldn't be possible to add a consumer to an inexistent group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToAutomaticallyCreatedGroup() throws
RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", true, false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToGroup() throws RegistrationException
+ {
+ manager.createConsumerGroup("bar");
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false,
false);
+ fail("Shouldn't be possible to add an inexistent consumer to a group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNotNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddInexistentConsumerToInexistentGroup() throws RegistrationException
+ {
+ try
+ {
+ manager.addConsumerToGroupNamed("foo", "bar", false,
false);
+ fail("Shouldn't be possible to add a consumer to an inexistent group
without first creating it");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+
+ assertNull(manager.getConsumerByIdentity("foo"));
+ assertNull(manager.getConsumerGroup("bar"));
+ }
+
+ public void testAddConsumerToGroup() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true,
true);
+
+ Consumer consumer1 = manager.getConsumerByIdentity(consumerName);
+ assertNotNull(consumer1);
+ assertEquals(consumer1, consumer); // default policy: identity == name
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(group, consumer.getGroup());
+ }
+
+ public void testCreateConsumerGroup() throws Exception
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ assertNotNull(group);
+ assertEquals(groupName, group.getName());
+
+ Collection groups = manager.getConsumerGroups();
+ assertEquals(1, groups.size());
+ assertTrue(groups.contains(group));
+ assertEquals(group, manager.getConsumerGroup(groupName));
+
+ try
+ {
+ groups.add(group);
+ fail("Shouldn't be possible to directly modify group
collection");
+ }
+ catch (UnsupportedOperationException expected)
+ {
+ }
+ }
+
+ public void testRemoveConsumerGroup() throws RegistrationException
+ {
+ String groupName = "name";
+ ConsumerGroup group = manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerGroup(groupName));
+
+ manager.createConsumerGroup(groupName);
+ manager.removeConsumerGroup(groupName);
+ assertNull(manager.getConsumerGroup(groupName));
+ }
+
+ public void testCascadeRemovalOnConsumerGroupRemoval() throws Exception
+ {
+ String groupName = "group";
+ String consumerName = "consumer";
+ Consumer consumer = manager.addConsumerToGroupNamed(consumerName, groupName, true,
true);
+ String consumerIdentity = consumer.getId();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ ConsumerGroup group = manager.getConsumerGroup(groupName);
+
+ manager.removeConsumerGroup(group);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testCascadeRemovalOnConsumerRemoval() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+ String consumerIdentity = consumer.getId();
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ manager.removeConsumer(consumer);
+ assertNull(manager.getConsumerByIdentity(consumerIdentity));
+ assertNull(manager.getRegistration(handle));
+ }
+
+ public void testRemoveSingleRegistration() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ assertTrue(consumer.getRegistrations().contains(reg));
+
+ // set the consumer status to valid
+ consumer.setStatus(RegistrationStatus.VALID);
+
+ manager.removeRegistration(handle);
+ assertTrue(!consumer.getRegistrations().contains(reg));
+ assertNull(manager.getRegistration(handle));
+
+ // since the consumer doesn't have any registration anymore, its status should
become pending
+ assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
+
+ // shouldn't be possible anymore to retrieve the consumer from the registration
handle
+ assertNull(manager.getConsumerFor(handle));
+ }
+
+ public void testRemoveRegistrationOnConsumerWithOtherRegistrations() throws Exception
+ {
+ String consumerName = "consumer";
+ Consumer consumer = manager.createConsumer(consumerName);
+
+ Registration reg = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+ String handle = reg.getRegistrationHandle();
+
+ // todo: this won't work anymore when properties validation is implemented
+ registrationProperties.put(new QName("prop3"), "value3");
+ Registration r2 = manager.addRegistrationTo(consumerName, registrationProperties,
false);
+
+ RegistrationStatus status = consumer.getStatus();
+
+ manager.removeRegistration(handle);
+
+ // consumer status shouldn't have changed
+ assertEquals(status, consumer.getStatus());
+
+ // should still be able to retrieve consumer from r2 handle
+ assertEquals(consumer, manager.getConsumerFor(r2.getRegistrationHandle()));
+
+ // ... but not from handle
+ assertNull(manager.getConsumerFor(handle));
+ }
+
+ public void testAddRegistrationWithInvalidRegistrationProperties() throws Exception
+ {
+ // todo: implement
+ }
+
+ public void testRemoveInexistentRegistration() throws RegistrationException
+ {
+ try
+ {
+ manager.removeRegistration((Registration)null);
+ fail("Should be possible to remove a null registration");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration((String)null);
+ fail("Should be possible to remove a registration with a null
handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("");
+ fail("Should be possible to remove a registration with an empty
handle");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ manager.removeRegistration("doesn't exist");
+ fail("Should be possible to remove a registration with an invalid
handle");
+ }
+ catch (NoSuchRegistrationException expected)
+ {
+ }
+ }
+
+ public void testClear() throws Exception
+ {
+ manager.createConsumer("c1");
+ manager.createConsumer("c2");
+ manager.addConsumerToGroupNamed("c1g1", "g1", true, true);
+ manager.createConsumerGroup("g2");
+ Registration r1 = manager.addRegistrationTo("c1", registrationProperties,
false);
+ Registration r2 = manager.addRegistrationTo("c3", registrationProperties,
true);
+
+ manager.clear();
+ assertTrue(manager.getConsumerGroups().isEmpty());
+ assertTrue(manager.getConsumers().isEmpty());
+ assertNull(manager.getRegistration(r1.getRegistrationHandle()));
+ assertNull(manager.getRegistration(r2.getRegistrationHandle()));
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationPersistenceManagerTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationPersistenceManagerTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationPersistenceManagerTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,60 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import org.jboss.portal.registration.RegistrationPersistenceManager;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 8784 $
+ * @since 2.6
+ */
+public class RegistrationPersistenceManagerTestCase extends
AbstractRegistrationPersistenceManagerTestCase
+{
+
+ /** . */
+ private RegistrationPersistenceManager manager;
+
+ public void setUp() throws Exception
+ {
+ manager = new RegistrationPersistenceManagerImpl();
+
+ //
+ super.setUp();
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+
+ //
+ this.manager = null;
+ }
+
+ public RegistrationPersistenceManager getManager()
+ {
+ return manager;
+ }
+}
Added:
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationTestCase.java
===================================================================
---
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationTestCase.java
(rev 0)
+++
modules/registration/trunk/impl/src/test/java/org/jboss/portal/registration/RegistrationTestCase.java 2009-06-03
04:25:33 UTC (rev 13427)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2009, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt 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.portal.test.registration;
+
+import junit.framework.TestCase;
+import org.jboss.portal.registration.DuplicateRegistrationException;
+import org.jboss.portal.registration.PropertyDescription;
+import org.jboss.portal.registration.Registration;
+import org.jboss.portal.registration.RegistrationException;
+import org.jboss.portal.registration.RegistrationManager;
+import org.jboss.portal.registration.RegistrationPolicy;
+import org.jboss.portal.registration.impl.RegistrationManagerImpl;
+import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
+import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
+
+import javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision: 11406 $
+ * @since 2.6
+ */
+public class RegistrationTestCase extends TestCase
+{
+ private Registration registration;
+ private Map registrationProperties;
+
+ protected void setUp() throws Exception
+ {
+ RegistrationManager manager = new RegistrationManagerImpl();
+ RegistrationPolicy policy = new DefaultRegistrationPolicy()
+ {
+ public void validateRegistrationDataFor(Map<QName, ? extends
PropertyDescription> registrationProperties, String consumerIdentity) throws
IllegalArgumentException, RegistrationException, DuplicateRegistrationException
+ {
+ // accept any registration data here
+ }
+ };
+ manager.setPolicy(policy);
+ manager.setPersistenceManager(new RegistrationPersistenceManagerImpl());
+ policy.setManager(manager);
+
+ registrationProperties = new HashMap();
+ registrationProperties.put(new QName("prop1"), "value1");
+ registrationProperties.put(new QName("prop2"), "value2");
+
+ registration = manager.addRegistrationTo("name", registrationProperties,
true);
+ }
+
+ public void testGetPropertiesIsUnmodifiable()
+ {
+ Map properties = registration.getProperties();
+
+ try
+ {
+ properties.remove("foo");
+ fail("Properties shouldn't be directly modifiable");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testPropertiesAreClonedNotLive()
+ {
+ QName prop = new QName("prop3");
+ registrationProperties.put(prop, "value3");
+
+ assertNull(registration.getProperties().get(prop));
+ }
+
+ public void testSetNullPropertyValueThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor("foo", null);
+ fail("Shouldn't accept null values for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testSetNullPropertyNameThrowsIAE()
+ {
+ try
+ {
+ registration.setPropertyValueFor((QName)null, null);
+ fail("Shouldn't accept null names for properties");
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ public void testProperties()
+ {
+ QName name = new QName("prop1");
+ assertEquals("value1", registration.getProperties().get(name));
+ assertEquals("value2", registration.getProperties().get(new
QName("prop2")));
+
+ String newValue = "new value";
+ registration.setPropertyValueFor("prop1", newValue);
+ assertEquals(newValue, registration.getProperties().get(name));
+
+ registration.removeProperty(name);
+ assertNull(registration.getPropertyValueFor(name));
+ }
+
+ public void testUpdateProperties()
+ {
+ registrationProperties.remove(new QName("prop1"));
+
+ registration.updateProperties(registrationProperties);
+ assertNull(registration.getPropertyValueFor("prop1"));
+
+ QName name = new QName("prop3");
+ String value = "value3";
+ registrationProperties.put(name, value);
+ registration.updateProperties(registrationProperties);
+ assertEquals(value, registration.getPropertyValueFor(name));
+ }
+
+ public void testHasEqualProperties()
+ {
+ assertTrue(registration.hasEqualProperties(registration));
+
+ assertTrue(registration.hasEqualProperties(registrationProperties));
+
+ registrationProperties.put(new QName("prop3"), "value3");
+ assertTrue(!registration.hasEqualProperties(registrationProperties));
+ }
+
+ public void testClearAssociatedState()
+ {
+ //todo: implement
+ }
+
+}
Added: modules/registration/trunk/pom.xml
===================================================================
--- modules/registration/trunk/pom.xml (rev 0)
+++ modules/registration/trunk/pom.xml 2009-06-03 04:25:33 UTC (rev 13427)
@@ -0,0 +1,36 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.portal.registration</groupId>
+ <artifactId>module-aggregator</artifactId>
+ <packaging>pom</packaging>
+ <name>JBoss Portal Registation</name>
+ <version>1.0.0-SNAPSHOT</version>
+ <
url>http://www.jboss.org/jbossportal</url>
+
+ <dependencies/>
+
+ <!--Repository definition needed to deploy artifacts into JBoss maven
repositories-->
+ <distributionManagement>
+ <repository>
+ <!--Copy the distribution jar file to a local checkout of the maven
repository
+ - This variable can be set in $MAVEN_HOME/conf/settings.xml-->
+ <id>repository.jboss.org</id>
+ <url>file://${jboss.repository.root}</url>
+ </repository>
+ <snapshotRepository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <
url>dav:https://snapshots.jboss.org/maven2</url>
+ <uniqueVersion>true</uniqueVersion>
+ </snapshotRepository>
+ </distributionManagement>
+
+ <modules>
+ <module>build</module>
+ <module>api</module>
+ <module>impl</module>
+ </modules>
+
+
+</project>
\ No newline at end of file