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.DuplicateRegistrationException;
026: import org.jboss.portal.registration.Registration;
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.impl.RegistrationManagerImpl;
031: import org.jboss.portal.registration.impl.RegistrationPersistenceManagerImpl;
032: import org.jboss.portal.registration.policies.DefaultRegistrationPolicy;
033:
034: import javax.xml.namespace.QName;
035: import java.util.HashMap;
036: import java.util.Map;
037:
038: /**
039: * @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
040: * @version $Revision: 8784 $
041: * @since 2.6
042: */
043: public class RegistrationTestCase extends TestCase {
044: private Registration registration;
045: private Map registrationProperties;
046:
047: protected void setUp() throws Exception {
048: RegistrationManager manager = new RegistrationManagerImpl();
049: RegistrationPolicy policy = new DefaultRegistrationPolicy() {
050: public void validateRegistrationDataFor(
051: Map registrationProperties, String consumerIdentity)
052: throws IllegalArgumentException,
053: RegistrationException,
054: DuplicateRegistrationException {
055: // accept any registration data here
056: }
057: };
058: manager.setPolicy(policy);
059: manager
060: .setPersistenceManager(new RegistrationPersistenceManagerImpl());
061: policy.setManager(manager);
062:
063: registrationProperties = new HashMap();
064: registrationProperties.put(new QName("prop1"), "value1");
065: registrationProperties.put(new QName("prop2"), "value2");
066:
067: registration = manager.addRegistrationTo("name",
068: registrationProperties, true);
069: }
070:
071: public void testGetPropertiesIsUnmodifiable() {
072: Map properties = registration.getProperties();
073:
074: try {
075: properties.remove("foo");
076: fail("Properties shouldn't be directly modifiable");
077: } catch (Exception expected) {
078: }
079: }
080:
081: public void testPropertiesAreClonedNotLive() {
082: QName prop = new QName("prop3");
083: registrationProperties.put(prop, "value3");
084:
085: assertNull(registration.getProperties().get(prop));
086: }
087:
088: public void testSetNullPropertyValueThrowsIAE() {
089: try {
090: registration.setPropertyValueFor("foo", null);
091: fail("Shouldn't accept null values for properties");
092: } catch (Exception expected) {
093: }
094: }
095:
096: public void testSetNullPropertyNameThrowsIAE() {
097: try {
098: registration.setPropertyValueFor((QName) null, null);
099: fail("Shouldn't accept null names for properties");
100: } catch (Exception expected) {
101: }
102: }
103:
104: public void testProperties() {
105: QName name = new QName("prop1");
106: assertEquals("value1", registration.getProperties().get(name));
107: assertEquals("value2", registration.getProperties().get(
108: new QName("prop2")));
109:
110: String newValue = "new value";
111: registration.setPropertyValueFor("prop1", newValue);
112: assertEquals(newValue, registration.getProperties().get(name));
113:
114: registration.removeProperty(name);
115: assertNull(registration.getPropertyValueFor(name));
116: }
117:
118: public void testUpdateProperties() {
119: registrationProperties.remove(new QName("prop1"));
120:
121: registration.updateProperties(registrationProperties);
122: assertNull(registration.getPropertyValueFor("prop1"));
123:
124: QName name = new QName("prop3");
125: String value = "value3";
126: registrationProperties.put(name, value);
127: registration.updateProperties(registrationProperties);
128: assertEquals(value, registration.getPropertyValueFor(name));
129: }
130:
131: public void testHasEqualProperties() {
132: assertTrue(registration.hasEqualProperties(registration));
133:
134: assertTrue(registration
135: .hasEqualProperties(registrationProperties));
136:
137: registrationProperties.put(new QName("prop3"), "value3");
138: assertTrue(!registration
139: .hasEqualProperties(registrationProperties));
140: }
141:
142: public void testClearAssociatedState() {
143: //todo: implement
144: }
145:
146: }
|