Author: chris.laprun(a)jboss.com
Date: 2011-10-13 17:15:32 -0400 (Thu, 13 Oct 2011)
New Revision: 7742
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java
Log:
- Added RegistrationPersistenceManager.isConsumerGroupExisting to avoid creating a
ConsumerGroup when we just want to check its existence.
- Improved error handling and added more test cases.
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-13
19:39:42 UTC (rev 7741)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-13
21:15:32 UTC (rev 7742)
@@ -298,12 +298,18 @@
return group;
}
+ @Override
public boolean isConsumerExisting(String consumerId) throws RegistrationException
{
+ return exists(consumerId);
+ }
+
+ private boolean exists(String name)
+ {
ChromatticSession session = persister.getSession();
try
{
- return session.getJCRSession().itemExists(rootNodePath +
ConsumersAndGroupsMapping.NODE_NAME + "/" + consumerId);
+ return session.getJCRSession().itemExists(rootNodePath +
ConsumersAndGroupsMapping.NODE_NAME + "/" + name);
}
catch (RepositoryException e)
{
@@ -314,4 +320,10 @@
persister.closeSession(false);
}
}
+
+ @Override
+ public boolean isConsumerGroupExisting(String consumerGroupId) throws
RegistrationException
+ {
+ return exists(consumerGroupId);
+ }
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-13
19:39:42 UTC (rev 7741)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-13
21:15:32 UTC (rev 7742)
@@ -105,4 +105,6 @@
Collection<? extends Registration> getRegistrations() throws
RegistrationException;
boolean isConsumerExisting(String consumerId) throws RegistrationException;
+
+ boolean isConsumerGroupExisting(String consumerGroupId) throws RegistrationException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java 2011-10-13
19:39:42 UTC (rev 7741)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/AbstractRegistrationPersistenceManager.java 2011-10-13
21:15:32 UTC (rev 7742)
@@ -52,10 +52,17 @@
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"Consumer identity", null);
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerName,
"Consumer name", null);
- ConsumerSPI consumer = internalCreateConsumer(consumerId, consumerName);
- internalAddConsumer(consumer);
+ if (isConsumerExisting(consumerId))
+ {
+ throw new DuplicateRegistrationException("A Consumer with identifier
'" + consumerId + "' has already been registered.");
+ }
+ else
+ {
+ ConsumerSPI consumer = internalCreateConsumer(consumerId, consumerName);
+ internalAddConsumer(consumer);
- return consumer;
+ return consumer;
+ }
}
public void saveChangesTo(Consumer consumer) throws RegistrationException
@@ -83,15 +90,16 @@
public ConsumerGroup createConsumerGroup(String name) throws RegistrationException
{
- ConsumerGroup group = getConsumerGroup(name);
- if (group != null)
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(name, "ConsumerGroup
name", null);
+
+ if (isConsumerGroupExisting(name))
{
throw new DuplicateRegistrationException("A ConsumerGroup named '"
+ name + "' has already been registered.");
}
else
{
- group = internalCreateConsumerGroup(name);
- internalAddConsumerGroup((ConsumerGroupSPI)group);
+ final ConsumerGroupSPI group = internalCreateConsumerGroup(name);
+ internalAddConsumerGroup(group);
return group;
}
}
@@ -177,6 +185,11 @@
return getConsumerById(consumerId) != null;
}
+ public boolean isConsumerGroupExisting(String consumerGroupId) throws
RegistrationException
+ {
+ return getConsumerGroup(consumerGroupId) != null;
+ }
+
// internal methods: extension points for subclasses
protected abstract void internalAddRegistration(RegistrationSPI registration) throws
RegistrationException;
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-13
19:39:42 UTC (rev 7741)
+++
components/wsrp/trunk/producer/src/test/java/org/gatein/registration/AbstractRegistrationPersistenceManagerTestCase.java 2011-10-13
21:15:32 UTC (rev 7742)
@@ -1,6 +1,6 @@
/*
* JBoss, a division of Red Hat
- * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * Copyright 2011, 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.
@@ -83,9 +83,12 @@
public void testCreateConsumer() throws Exception
{
startInteraction();
- Consumer consumer = getManager().createConsumer("Bar", "Bar");
+ Consumer consumer = getManager().createConsumer("BarId",
"BarName");
+ assertTrue(getManager().isConsumerExisting("BarId"));
+ assertFalse(getManager().isConsumerExisting("BarName"));
+
assertNotNull(consumer);
- assertEquals("Bar", consumer.getName());
+ assertEquals("BarName", consumer.getName());
assertTrue(consumer.getRegistrations().isEmpty());
assertNull(consumer.getGroup());
assertNotNull(consumer.getPersistentKey());
@@ -95,6 +98,51 @@
stopInteraction();
}
+ public void testCreateConsumerThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().createConsumer(null, "foo");
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+
+ try
+ {
+ getManager().createConsumer("foo", null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
+ public void testCreateDuplicatedConsumer() throws Exception
+ {
+ startInteraction();
+ getManager().createConsumer("id", "name");
+ assertTrue(getManager().isConsumerExisting("id"));
+ assertFalse(getManager().isConsumerExisting("name"));
+
+ try
+ {
+ getManager().createConsumer("id", "different name");
+ fail();
+ }
+ catch (DuplicateRegistrationException expected)
+ {
+ }
+
+ getManager().createConsumer("different id", "name");
+ assertTrue(getManager().isConsumerExisting("different id"));
+
+ stopInteraction();
+ }
+
public void testCreateGroup() throws Exception
{
startInteraction();
@@ -107,6 +155,20 @@
stopInteraction();
}
+ public void testCreateGroupThrowsIAE() throws Exception
+ {
+ startInteraction();
+ try
+ {
+ getManager().createConsumerGroup(null);
+ fail();
+ }
+ catch (IllegalArgumentException expected)
+ {
+ }
+ stopInteraction();
+ }
+
public void testAddGroup() throws Exception
{
startInteraction();