001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.test.registration;
023:
024: import junit.framework.TestCase;
025: import org.jboss.portal.registration.Consumer;
026: import org.jboss.portal.registration.ConsumerGroup;
027: import org.jboss.portal.registration.RegistrationException;
028: import org.jboss.portal.registration.RegistrationManager;
029: import org.jboss.portal.registration.RegistrationPolicy;
030: import org.jboss.portal.registration.RegistrationStatus;
031: import org.jboss.portal.registration.impl.RegistrationManagerImpl;
032: import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
033: import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
034:
035: /**
036: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
037: * @version $Revision: 8784 $
038: * @since 2.6
039: */
040: public class ConsumerGroupTestCase extends TestCase {
041: private RegistrationManager manager;
042: private ConsumerGroup group;
043: private static final String NAME = "name";
044:
045: protected void setUp() throws Exception {
046: manager = new RegistrationManagerImpl();
047: RegistrationPolicy policy = new DefaultRegistrationPolicy();
048: manager.setPolicy(policy);
049: manager
050: .setPersistenceManager(new RegistrationPersistenceManagerImpl());
051: policy.setManager(manager);
052: group = manager.createConsumerGroup(NAME);
053: }
054:
055: public void testGetName() {
056: assertEquals(NAME, group.getName());
057: }
058:
059: public void testConsumersManagement() throws RegistrationException {
060: assertTrue(group.isEmpty());
061: assertEquals(0, group.getConsumers().size());
062:
063: Consumer c1 = manager.createConsumer("c1");
064: group.addConsumer(c1);
065: assertTrue(!group.isEmpty());
066: assertEquals(1, group.getConsumers().size());
067: assertTrue(group.contains(c1));
068: assertEquals(group, c1.getGroup());
069: assertEquals(c1, group.getConsumer(c1.getId()));
070:
071: Consumer c2 = manager.createConsumer("c2");
072: group.addConsumer(c2);
073: assertEquals(2, group.getConsumers().size());
074: assertTrue(group.contains(c2));
075: assertEquals(group, c2.getGroup());
076:
077: group.removeConsumer(c1);
078: assertEquals(1, group.getConsumers().size());
079: assertTrue(!group.contains(c1));
080: assertTrue(group.contains(c2));
081: assertEquals(null, c1.getGroup());
082: }
083:
084: public void testAddNullConsumer() throws RegistrationException {
085: try {
086: group.addConsumer(null);
087: fail("Shouldn't be possible to add null consumer");
088: } catch (IllegalArgumentException expected) {
089: }
090: }
091:
092: public void testStatus() {
093: assertEquals(RegistrationStatus.PENDING, group.getStatus());
094: group.setStatus(RegistrationStatus.VALID);
095: assertEquals(RegistrationStatus.VALID, group.getStatus());
096: }
097:
098: public void testIllegalStatus() {
099: try {
100: group.setStatus(null);
101: fail("Shouldn't be possible to set the status to null");
102: } catch (IllegalArgumentException expected) {
103: }
104: }
105: }
|