Author: chris.laprun(a)jboss.com
Date: 2011-10-14 07:59:41 -0400 (Fri, 14 Oct 2011)
New Revision: 7747
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java
Log:
- Re-wrote JCRRegistrationPersistenceManager to always hit JCR to return objects. Might
need to implement caching similar to what's been done in JCRConsumerRegistry at some
point.
- Fixed an issue where Registration properties where not properly updated in persistence
due to a bug both in the implementation and Chromattic. :(
- Fixed AbstractRegistrationPersistenceManagerTestCase that wasn't saving changes to
the registration in testBulkUpdateRegistrationProperties. Removed unused
start/stopInteraction methods.
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-14
08:26:14 UTC (rev 7746)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-14
11:59:41 UTC (rev 7747)
@@ -26,9 +26,10 @@
import org.chromattic.api.ChromatticSession;
import org.gatein.common.util.ParameterValidation;
import org.gatein.registration.Consumer;
+import org.gatein.registration.ConsumerGroup;
import org.gatein.registration.Registration;
import org.gatein.registration.RegistrationException;
-import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
+import org.gatein.registration.impl.AbstractRegistrationPersistenceManager;
import org.gatein.registration.spi.ConsumerGroupSPI;
import org.gatein.registration.spi.ConsumerSPI;
import org.gatein.registration.spi.RegistrationSPI;
@@ -47,6 +48,7 @@
import javax.jcr.query.RowIterator;
import javax.xml.namespace.QName;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
@@ -55,7 +57,7 @@
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
-public class JCRRegistrationPersistenceManager extends
RegistrationPersistenceManagerImpl
+public class JCRRegistrationPersistenceManager extends
AbstractRegistrationPersistenceManager
{
private ChromatticPersister persister;
private final String rootNodePath;
@@ -86,30 +88,12 @@
ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
if (mappings == null)
{
- mappings = session.insert(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ session.insert(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
}
- persister.save(); // needed right now as the session must still be open to
iterate over nodes
-
- for (ConsumerGroupMapping cgm : mappings.getConsumerGroups())
- {
- internalAddConsumerGroup(cgm.toModel(newConsumerGroupSPI(cgm.getName()),
this));
- }
-
- for (ConsumerMapping cm : mappings.getConsumers())
- {
- ConsumerSPI consumer = cm.toModel(newConsumerSPI(cm.getId(), cm.getName()),
this);
- internalAddConsumer(consumer);
-
- // get the registrations and add them to local map.
- for (Registration registration : consumer.getRegistrations())
- {
- internalAddRegistration((RegistrationSPI)registration);
- }
- }
}
finally
{
- persister.closeSession(false);
+ persister.closeSession(true);
}
}
@@ -119,11 +103,36 @@
}
@Override
+ public void removeRegistration(String registrationId) throws RegistrationException
+ {
+ internalRemoveRegistration(registrationId);
+ }
+
protected RegistrationSPI internalRemoveRegistration(String registrationId) throws
RegistrationException
{
- remove(registrationId, RegistrationMapping.class, RegistrationSPI.class);
+ // can't use remove method as we get id directly instead of name
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"identifier", null);
- return super.internalRemoveRegistration(registrationId);
+ final Registration reg = getRegistration(registrationId);
+ if (reg != null)
+ {
+ try
+ {
+ final ChromatticSession session = persister.getSession();
+ final RegistrationMapping mapping =
session.findById(RegistrationMapping.class, registrationId);
+ session.remove(mapping);
+ persister.save();
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ return (RegistrationSPI)reg;
+ }
+ else
+ {
+ return null;
+ }
}
@Override
@@ -149,10 +158,15 @@
}
@Override
+ protected void internalAddConsumer(ConsumerSPI consumer) throws RegistrationException
+ {
+ // nothing to do
+ }
+
+ @Override
protected ConsumerSPI internalRemoveConsumer(String consumerId) throws
RegistrationException
{
- remove(consumerId, ConsumerMapping.class, ConsumerSPI.class);
- return super.internalRemoveConsumer(consumerId);
+ return remove(consumerId, ConsumerMapping.class, ConsumerSPI.class);
}
private <T extends BaseMapping, U> U remove(String name, Class<T>
mappingClass, Class<U> modelClass)
@@ -160,36 +174,14 @@
ChromatticSession session = persister.getSession();
try
{
- String jcrType =
(String)mappingClass.getField(BaseMapping.JCR_TYPE_NAME_CONSTANT_NAME).get(null);
- String id;
- final Query query =
session.getJCRSession().getWorkspace().getQueryManager().createQuery("select jcr:uuid
from " + jcrType + " where jcr:path = '/%/" + name + "'",
Query.SQL);
- final QueryResult queryResult = query.execute();
- final RowIterator rows = queryResult.getRows();
- final long size = rows.getSize();
- if (size == 0)
+ T toRemove = getMapping(session, mappingClass, name);
+ if (toRemove == null)
{
return null;
}
- else
- {
- if (size != 1)
- {
- throw new IllegalArgumentException("There should be only one " +
modelClass.getSimpleName() + " named " + name);
- }
- id = rows.nextRow().getValue("jcr:uuid").getString();
+ final U result = getModelFrom(toRemove, mappingClass, modelClass);
- }
-
- T toRemove = session.findById(mappingClass, id);
- Class aClass = toRemove.getModelClass();
- if (!modelClass.isAssignableFrom(aClass))
- {
- throw new IllegalArgumentException("Cannot convert a " +
mappingClass.getSimpleName() + " to a " + modelClass.getSimpleName());
- }
-
- final U result = modelClass.cast(toRemove.toModel(null, this));
-
session.remove(toRemove);
persister.closeSession(true);
@@ -202,6 +194,42 @@
}
}
+ private <T extends BaseMapping, U> U getModelFrom(T mapping, Class<T>
mappingClass, Class<U> modelClass)
+ {
+ Class aClass = mapping.getModelClass();
+ if (!modelClass.isAssignableFrom(aClass))
+ {
+ throw new IllegalArgumentException("Cannot convert a " +
mappingClass.getSimpleName() + " to a " + modelClass.getSimpleName());
+ }
+
+ return modelClass.cast(mapping.toModel(null, this));
+ }
+
+ private <T extends BaseMapping> T getMapping(ChromatticSession session,
Class<T> mappingClass, String name) throws RepositoryException,
NoSuchFieldException, IllegalAccessException
+ {
+ String jcrType =
(String)mappingClass.getField(BaseMapping.JCR_TYPE_NAME_CONSTANT_NAME).get(null);
+ String id;
+ final Query query =
session.getJCRSession().getWorkspace().getQueryManager().createQuery("select jcr:uuid
from " + jcrType + " where jcr:path = '/%/" + name + "'",
Query.SQL);
+ final QueryResult queryResult = query.execute();
+ final RowIterator rows = queryResult.getRows();
+ final long size = rows.getSize();
+ if (size == 0)
+ {
+ return null;
+ }
+ else
+ {
+ if (size != 1)
+ {
+ throw new IllegalArgumentException("There should be only one " +
mappingClass.getSimpleName() + " named " + name);
+ }
+
+ id = rows.nextRow().getValue("jcr:uuid").getString();
+ }
+
+ return session.findById(mappingClass, id);
+ }
+
@Override
protected ConsumerSPI internalCreateConsumer(String consumerId, String consumerName)
throws RegistrationException
{
@@ -229,7 +257,7 @@
@Override
protected ConsumerSPI internalSaveChangesTo(Consumer consumer) throws
RegistrationException
{
- ConsumerSPI consumerSPI = super.internalSaveChangesTo(consumer);
+ ConsumerSPI consumerSPI = (ConsumerSPI)consumer;
ChromatticSession session = persister.getSession();
try
@@ -249,7 +277,7 @@
protected RegistrationSPI internalSaveChangesTo(Registration registration) throws
RegistrationException
{
- RegistrationSPI registrationSPI = super.internalSaveChangesTo(registration);
+ RegistrationSPI registrationSPI = (RegistrationSPI)registration;
ChromatticSession session = persister.getSession();
try
@@ -268,10 +296,15 @@
}
@Override
+ protected void internalAddConsumerGroup(ConsumerGroupSPI group) throws
RegistrationException
+ {
+ // nothing to do
+ }
+
+ @Override
protected ConsumerGroupSPI internalRemoveConsumerGroup(String name) throws
RegistrationException
{
- remove(name, ConsumerGroupMapping.class, ConsumerGroupSPI.class);
- return super.internalRemoveConsumerGroup(name);
+ return remove(name, ConsumerGroupMapping.class, ConsumerGroupSPI.class);
}
@Override
@@ -299,6 +332,160 @@
}
@Override
+ protected ConsumerSPI getConsumerSPIById(String consumerId) throws
RegistrationException
+ {
+ return getModel(consumerId, ConsumerSPI.class, ConsumerMapping.class);
+ }
+
+ private <T, B extends BaseMapping> T getModel(String id, Class<T>
modelClass, Class<B> mappingClass) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id,
"identifier", null);
+
+ final ChromatticSession session = persister.getSession();
+
+ try
+ {
+ return getModel(id, modelClass, mappingClass, session);
+ }
+ catch (Exception e)
+ {
+ throw new RegistrationException(e);
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
+ private <T, B extends BaseMapping> T getModel(String id, Class<T>
modelClass, Class<B> mappingClass, ChromatticSession session) throws
RegistrationException
+ {
+ try
+ {
+ final B mapping = getMapping(session, mappingClass, id);
+ if (mapping == null)
+ {
+ return null;
+ }
+ else
+ {
+ return getModelFrom(mapping, mappingClass, modelClass);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RegistrationException(e);
+ }
+ }
+
+ public ConsumerGroup getConsumerGroup(String name) throws RegistrationException
+ {
+ return getModel(name, ConsumerGroup.class, ConsumerGroupMapping.class);
+ }
+
+ public Consumer getConsumerById(String consumerId) throws IllegalArgumentException,
RegistrationException
+ {
+ return getConsumerSPIById(consumerId);
+ }
+
+ public Collection<? extends ConsumerGroup> getConsumerGroups() throws
RegistrationException
+ {
+ final ChromatticSession session = persister.getSession();
+
+ try
+ {
+ ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ final List<ConsumerGroupMapping> groupMappings =
mappings.getConsumerGroups();
+ List<ConsumerGroup> groups = new
ArrayList<ConsumerGroup>(groupMappings.size());
+ for (ConsumerGroupMapping cgm : groupMappings)
+ {
+ groups.add(cgm.toModel(newConsumerGroupSPI(cgm.getName()), this));
+ }
+ return groups;
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
+ public Registration getRegistration(String registrationId) throws
RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(registrationId,
"identifier", null);
+
+ final ChromatticSession session = persister.getSession();
+
+ try
+ {
+ final RegistrationMapping mapping = session.findById(RegistrationMapping.class,
registrationId);
+ if (mapping == null)
+ {
+ return null;
+ }
+ else
+ {
+ // extract parent consumer and get the registration from it
+ final String path = mapping.getPath();
+ final String[] elements = path.split("/");
+ final String consumerId = elements[elements.length - 2]; // consumer id is
previous before last
+
+ final Consumer consumer = getModel(consumerId, Consumer.class,
ConsumerMapping.class, session);
+
+ if (consumer != null)
+ {
+ for (Registration registration : consumer.getRegistrations())
+ {
+ if (registration.getPersistentKey().equals(registrationId))
+ {
+ return registration;
+ }
+ }
+ }
+
+ return null;
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RegistrationException(e);
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
+ public Collection<? extends Consumer> getConsumers() throws
RegistrationException
+ {
+ final ChromatticSession session = persister.getSession();
+
+ try
+ {
+ ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
+ final List<ConsumerMapping> consumerMappings = mappings.getConsumers();
+ List<Consumer> consumers = new
ArrayList<Consumer>(consumerMappings.size());
+ for (ConsumerMapping consumerMapping : consumerMappings)
+ {
+ consumers.add(consumerMapping.toModel(newConsumerSPI(consumerMapping.getId(),
consumerMapping.getName()), this));
+ }
+ return consumers;
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
+
+ public Collection<? extends Registration> getRegistrations() throws
RegistrationException
+ {
+ final Collection<? extends Consumer> consumers = getConsumers();
+ List<Registration> registrations = new
ArrayList<Registration>(consumers.size() * 2);
+ for (Consumer consumer : consumers)
+ {
+ registrations.addAll(consumer.getRegistrations());
+ }
+ return registrations;
+ }
+
public boolean isConsumerExisting(String consumerId) throws RegistrationException
{
return exists(consumerId);
@@ -321,9 +508,14 @@
}
}
- @Override
public boolean isConsumerGroupExisting(String consumerGroupId) throws
RegistrationException
{
return exists(consumerGroupId);
}
-}
+
+ @Override
+ protected void internalAddRegistration(RegistrationSPI registration) throws
RegistrationException
+ {
+ // nothing to do
+ }
+}
\ No newline at end of file
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-10-14
08:26:14 UTC (rev 7746)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-10-14
11:59:41 UTC (rev 7747)
@@ -29,6 +29,7 @@
import org.chromattic.api.annotations.OneToMany;
import org.chromattic.api.annotations.OneToOne;
import org.chromattic.api.annotations.Owner;
+import org.chromattic.api.annotations.Path;
import org.chromattic.api.annotations.PrimaryType;
import org.chromattic.api.annotations.Property;
import org.gatein.common.io.IOTools;
@@ -86,6 +87,9 @@
@Create
public abstract RegistrationPropertiesMapping createProperties();
+ @Path
+ public abstract String getPath();
+
/**
* At this point, this RegistrationMapping should already have been added to its
parent
*
@@ -126,12 +130,15 @@
Map<QName, Object> properties = registration.getProperties();
if (ParameterValidation.existsAndIsNotEmpty(properties))
{
+ // re-create properties all the time since a bug in Chromattic prevents us from
properly re-initializing the properties
RegistrationPropertiesMapping rpm = getProperties();
- if (rpm == null)
+ if (rpm != null)
{
- rpm = createProperties();
- setProperties(rpm);
+ setProperties(null);
}
+ rpm = createProperties();
+ setProperties(rpm);
+
rpm.initFrom(properties);
}
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java 2011-10-14
08:26:14 UTC (rev 7746)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationPropertiesMapping.java 2011-10-14
11:59:41 UTC (rev 7747)
@@ -68,6 +68,7 @@
if (properties != null)
{
Map<String, String> map = getProperties();
+ // map.clear(); // we should be clearing here but Chromattic's PropertyMap
doesn't clear.
for (Map.Entry<QName, Object> entry : properties.entrySet())
{
Modified:
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java
===================================================================
---
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java 2011-10-14
08:26:14 UTC (rev 7746)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java 2011-10-14
11:59:41 UTC (rev 7747)
@@ -46,14 +46,6 @@
public abstract RegistrationPersistenceManager getManager() throws Exception;
- public void startInteraction()
- {
- }
-
- public void stopInteraction()
- {
- }
-
public void setUp() throws Exception
{
registrationProperties = new HashMap<QName, Object>();
@@ -68,7 +60,6 @@
public void testGetGroupThrowsIAE() throws Exception
{
- startInteraction();
try
{
getManager().getConsumerGroup(null);
@@ -77,12 +68,10 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testCreateConsumer() throws Exception
{
- startInteraction();
Consumer consumer = getManager().createConsumer("BarId",
"BarName");
assertTrue(getManager().isConsumerExisting("BarId"));
assertFalse(getManager().isConsumerExisting("BarName"));
@@ -95,12 +84,10 @@
assertNull(consumer.getConsumerAgent());
assertNotNull(consumer.getCapabilities());
assertEquals(RegistrationStatus.PENDING, consumer.getStatus());
- stopInteraction();
}
public void testCreateConsumerThrowsIAE() throws Exception
{
- startInteraction();
try
{
getManager().createConsumer(null, "foo");
@@ -118,12 +105,10 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testCreateDuplicatedConsumer() throws Exception
{
- startInteraction();
getManager().createConsumer("id", "name");
assertTrue(getManager().isConsumerExisting("id"));
assertFalse(getManager().isConsumerExisting("name"));
@@ -140,24 +125,20 @@
getManager().createConsumer("different id", "name");
assertTrue(getManager().isConsumerExisting("different id"));
- stopInteraction();
}
public void testCreateGroup() throws Exception
{
- startInteraction();
ConsumerGroup group = getManager().createConsumerGroup("Foo");
assertNotNull(group);
assertNotNull(group.getPersistentKey());
assertEquals("Foo", group.getName());
assertTrue(group.getConsumers().isEmpty());
assertEquals(RegistrationStatus.PENDING, group.getStatus());
- stopInteraction();
}
public void testCreateGroupThrowsIAE() throws Exception
{
- startInteraction();
try
{
getManager().createConsumerGroup(null);
@@ -166,26 +147,20 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testAddGroup() throws Exception
{
- startInteraction();
ConsumerGroup group = getManager().createConsumerGroup("Foo");
assertNotNull(group);
- 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());
@@ -193,12 +168,10 @@
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
{
@@ -208,12 +181,10 @@
catch (DuplicateRegistrationException expected)
{
}
- stopInteraction();
}
public void testAddGroupThrowsIAE() throws Exception
{
- startInteraction();
try
{
getManager().createConsumerGroup(null);
@@ -222,25 +193,19 @@
{
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);
@@ -248,12 +213,10 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testRemoveNonExistingGroup() throws Exception
{
- startInteraction();
try
{
getManager().removeConsumerGroup("Foo");
@@ -261,12 +224,10 @@
catch (NoSuchRegistrationException expected)
{
}
- stopInteraction();
}
public void testGetConsumerThrowsIAE() throws Exception
{
- startInteraction();
try
{
ConsumerGroup group = getManager().createConsumerGroup("Foo");
@@ -276,32 +237,24 @@
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);
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());
@@ -310,18 +263,14 @@
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);
@@ -330,12 +279,10 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testAddConsumerThrowsIAE() throws Exception
{
- startInteraction();
ConsumerGroup group = getManager().createConsumerGroup("Foo");
try
{
@@ -345,24 +292,20 @@
{
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
{
@@ -371,18 +314,14 @@
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);
@@ -393,10 +332,8 @@
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);
@@ -405,22 +342,18 @@
assertEquals(regId, reg3.getPersistentKey());
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.getPersistentKey());
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);
@@ -433,12 +366,10 @@
catch (IllegalArgumentException expected)
{
}
- stopInteraction();
}
public void testRemoveRegistrationThrowsIAE() throws Exception
{
- startInteraction();
try
{
getManager().removeRegistration(null);
@@ -447,69 +378,59 @@
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.getPersistentKey();
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();
+ Registration reg = consumer.getRegistrations().iterator().next();
registrationProperties.remove(new QName("prop1"));
reg.updateProperties(registrationProperties);
assertEquals(Collections.singletonMap(new QName("prop2"),
"value2"), reg.getProperties());
- stopInteraction();
+ getManager().saveChangesTo(reg); // need to save for changes to be persisted
+ final Registration registration =
getManager().getRegistration(reg.getPersistentKey());
+ assertEquals(reg.getProperties(), registration.getProperties());
+
//
- startInteraction();
consumer = getManager().getConsumerById("Bar");
- reg = (Registration)consumer.getRegistrations().iterator().next();
+ reg = 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();
+ getManager().saveChangesTo(reg); // need to save for changes to be persisted
//
- startInteraction();
consumer = getManager().getConsumerById("Bar");
- reg = (Registration)consumer.getRegistrations().iterator().next();
+ reg = consumer.getRegistrations().iterator().next();
assertEquals(MapBuilder.hashMap().put(new QName("prop2"),
"value2").put(new QName("prop3"), "value3").get(),
reg.getProperties());
- stopInteraction();
}
}