Author: chris.laprun(a)jboss.com
Date: 2009-11-18 10:37:08 -0500 (Wed, 18 Nov 2009)
New Revision: 645
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
Modified:
components/wsrp/trunk/consumer/pom.xml
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
Log:
- Significantly rewrote AbstractConsumerRegistry to better support different persistence
scenarii.
- Updated ConsumerRegistryTestCase, added more tests and activated it.
- Made ProducerInfo key a String instead of a Long for better interoperability between
persistence modalities.
- Added equals and hashCode methods on ProducerInfo and WSRPConsumerImpl.
- Remove WSRPConsumer.setProducerInfo method.
- Added ConsumerRegistry.getProducerInfoByKey method.
- Added InMemoryConsumerRegistry implementation.
Modified: components/wsrp/trunk/consumer/pom.xml
===================================================================
--- components/wsrp/trunk/consumer/pom.xml 2009-11-18 15:36:13 UTC (rev 644)
+++ components/wsrp/trunk/consumer/pom.xml 2009-11-18 15:37:08 UTC (rev 645)
@@ -109,7 +109,6 @@
<configuration>
<excludes>
<exclude>org/gatein/wsrp/protocol/v1/*</exclude>
-
<exclude>org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase*</exclude>
</excludes>
</configuration>
</plugin>
Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/WSRPConsumer.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -73,12 +73,6 @@
ProducerInfo getProducerInfo();
/**
- * @param producerInfo
- * @since 2.6
- */
- void setProducerInfo(ProducerInfo producerInfo);
-
- /**
* @throws PortletInvokerException
* @since 2.6
*/
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -74,8 +74,8 @@
// Persistent information
- /** DB primary key */
- private Long key;
+ /** persistence key */
+ private String key;
/** Configuration of the remote WS endpoints */
private EndpointConfigurationInfo persistentEndpointInfo;
@@ -130,6 +130,51 @@
persistentRegistrationInfo =
RegistrationInfo.createUndeterminedRegistration(this);
}
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ ProducerInfo that = (ProducerInfo)o;
+
+ if (key != null ? !key.equals(that.key) : that.key != null)
+ {
+ return false;
+ }
+ if (!persistentId.equals(that.persistentId))
+ {
+ return false;
+ }
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = key != null ? key.hashCode() : 0;
+ result = 31 * result + persistentId.hashCode();
+ return result;
+ }
+
+ @Override
+ public String toString()
+ {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("ProducerInfo");
+ sb.append("{key='").append(key).append('\'');
+ sb.append(", id='").append(persistentId).append('\'');
+ sb.append('}');
+ return sb.toString();
+ }
+
public ConsumerRegistry getRegistry()
{
return registry;
@@ -140,12 +185,12 @@
this.registry = registry;
}
- public Long getKey()
+ public String getKey()
{
return key;
}
- public void setKey(Long key)
+ public void setKey(String key)
{
this.key = key;
}
@@ -251,6 +296,7 @@
}
// FIX-ME: remove when a better dirty management is in place at property level
+
public void setModifyRegistrationRequired(boolean modifyRegistrationRequired)
{
this.isModifyRegistrationRequired = modifyRegistrationRequired;
@@ -832,6 +878,7 @@
}
// make package only after package reorg
+
public PortletPropertyDescriptionResponse getPropertyDescriptionsFor(String
portletHandle)
{
ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(portletHandle,
"portlet handle", null);
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/WSRPConsumerImpl.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -135,11 +135,6 @@
return producerInfo;
}
- public void setProducerInfo(ProducerInfo producerInfo)
- {
- this.producerInfo = producerInfo;
- }
-
// PortletInvoker implementation
************************************************************************************
public Set getPortlets() throws InvokerUnavailableException
@@ -622,6 +617,7 @@
}
// fix-me!
+
org.oasis.wsrp.v1.UserContext getUserContextFrom(PortletInvocation invocation,
RuntimeContext runtimeContext) throws PortletInvokerException
{
// first decide if we need to pass the user context...
@@ -676,4 +672,28 @@
{
sessionHandler.onSessionEvent(event);
}
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ WSRPConsumerImpl that = (WSRPConsumerImpl)o;
+
+ return producerInfo.equals(that.producerInfo);
+
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return producerInfo.hashCode();
+ }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/AbstractConsumerRegistry.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -37,8 +37,12 @@
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -52,7 +56,8 @@
/** Gives access to the Portal's portlet invokers */
private FederatingPortletInvoker federatingPortletInvoker;
- protected SortedMap<String, WSRPConsumer> consumers;
+ private SortedMap<String, WSRPConsumer> consumers;
+ private Map<String, String> keysToIds;
private SessionEventBroadcaster sessionEventBroadcaster;
@@ -61,6 +66,11 @@
private static final Logger log =
LoggerFactory.getLogger(AbstractConsumerRegistry.class);
+ protected AbstractConsumerRegistry()
+ {
+ initConsumers(null);
+ }
+
public FederatingPortletInvoker getFederatingPortletInvoker()
{
return federatingPortletInvoker;
@@ -117,7 +127,7 @@
}
deactivateConsumer(consumer);
- consumers.remove(id);
+ remove(consumer);
delete(info);
}
@@ -145,10 +155,23 @@
this.federatingPortletInvoker = federatingPortletInvoker;
}
+ public ProducerInfo getProducerInfoByKey(String key)
+ {
+ String id = keysToIds.get(key);
+ if (id != null)
+ {
+ return getConsumer(id).getProducerInfo();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
private WSRPConsumer createConsumerFrom(ProducerInfo producerInfo)
{
WSRPConsumer consumer = new WSRPConsumerImpl(producerInfo);
- consumers.put(producerInfo.getId(), consumer);
+ add(consumer);
return consumer;
}
@@ -212,11 +235,11 @@
String oldId = update(producerInfo);
- // if we updated and oldId is not null, we need to update the local consumers map
+ // if we updated and oldId is not null, we need to update the local information
if (oldId != null)
{
- WSRPConsumer consumer = consumers.remove(oldId);
- consumers.put(producerInfo.getId(), consumer);
+ remove(getConsumer(oldId));
+ createConsumerFrom(producerInfo);
}
}
@@ -228,7 +251,7 @@
public void reloadConsumers()
{
// load the configured consumers
- consumers = new TreeMap<String, WSRPConsumer>();
+ initConsumers(null);
Iterator<ProducerInfo> producerInfos = getProducerInfosFromStorage();
@@ -262,7 +285,7 @@
public void stop() throws Exception
{
- for (WSRPConsumer consumer : consumers.values())
+ for (WSRPConsumer consumer : getConsumers())
{
// if producer is not active, it shouldn't be registered with the federating
portlet invoker, hence do not
// unregister it.
@@ -281,13 +304,12 @@
}
}
- consumers.clear();
- consumers = null;
+ clearConsumers();
}
public List<WSRPConsumer> getConfiguredConsumers()
{
- return new ArrayList<WSRPConsumer>(consumers.values());
+ return new ArrayList<WSRPConsumer>(getConsumers());
}
public WSRPConsumer getConsumer(String id)
@@ -384,4 +406,74 @@
protected abstract String update(ProducerInfo producerInfo);
protected abstract Iterator<ProducerInfo> getProducerInfosFromStorage();
+
+ // internal management methods
+
+ private void add(WSRPConsumer consumer)
+ {
+ String id = consumer.getProducerId();
+ consumers.put(id, consumer);
+ ProducerInfo info = consumer.getProducerInfo();
+ keysToIds.put(info.getKey(), id);
+ }
+
+ protected WSRPConsumer remove(WSRPConsumer consumer)
+ {
+ String id = keysToIds.remove(consumer.getProducerInfo().getKey());
+ return consumers.remove(id);
+ }
+
+ protected Collection<WSRPConsumer> getConsumers()
+ {
+ return consumers.values();
+ }
+
+ protected Map<String, String> getKeyMappings()
+ {
+ return Collections.unmodifiableMap(keysToIds);
+ }
+
+ protected void initConsumers(SortedMap<String, WSRPConsumer> consumers)
+ {
+ if (!ParameterValidation.existsAndIsNotEmpty(consumers))
+ {
+ consumers = new TreeMap<String, WSRPConsumer>();
+ }
+ this.consumers = consumers;
+ int size = consumers.size();
+ keysToIds = size == 0 ? new HashMap<String, String>() : new
HashMap<String, String>(size);
+ }
+
+ private void clearConsumers()
+ {
+ consumers.clear();
+ keysToIds.clear();
+ consumers = null;
+ keysToIds = null;
+ }
+
+ protected class ProducerInfoIterator implements Iterator<ProducerInfo>
+ {
+ private Iterator<WSRPConsumer> consumers;
+
+ public ProducerInfoIterator(Iterator<WSRPConsumer> consumers)
+ {
+ this.consumers = consumers;
+ }
+
+ public boolean hasNext()
+ {
+ return consumers.hasNext();
+ }
+
+ public ProducerInfo next()
+ {
+ return consumers.next().getProducerInfo();
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException("remove not supported on this
iterator implementation");
+ }
+ }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/ConsumerRegistry.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -74,4 +74,6 @@
void setSessionEventBroadcaster(SessionEventBroadcaster sessionEventBroadcaster);
void setFederatingPortletInvoker(FederatingPortletInvoker federatingPortletInvoker);
+
+ ProducerInfo getProducerInfoByKey(String key);
}
\ No newline at end of file
Added:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java
(rev 0)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/InMemoryConsumerRegistry.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -0,0 +1,61 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2008, 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.gatein.wsrp.consumer.registry;
+
+import org.gatein.wsrp.consumer.ProducerInfo;
+
+import java.util.Iterator;
+import java.util.UUID;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class InMemoryConsumerRegistry extends AbstractConsumerRegistry
+{
+ @Override
+ protected void save(ProducerInfo info, String messageOnError)
+ {
+ // generate a UUID for ProducerInfo
+ info.setKey(UUID.randomUUID().toString());
+ }
+
+ @Override
+ protected void delete(ProducerInfo info)
+ {
+ // nothing to do here
+ }
+
+ @Override
+ protected String update(ProducerInfo producerInfo)
+ {
+ String key = producerInfo.getKey();
+ return getKeyMappings().get(key);
+ }
+
+ @Override
+ protected Iterator<ProducerInfo> getProducerInfosFromStorage()
+ {
+ return new ProducerInfoIterator(getConsumers().iterator());
+ }
+}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLConsumerRegistry.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -39,7 +39,6 @@
import java.net.URL;
import java.util.Iterator;
import java.util.SortedMap;
-import java.util.TreeMap;
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -54,11 +53,6 @@
private EntityResolver entityResolver;
- public XMLConsumerRegistry()
- {
- consumers = new TreeMap<String, WSRPConsumer>();
- }
-
public EntityResolver getEntityResolver()
{
return entityResolver;
@@ -94,14 +88,14 @@
try
{
unmarshaller.setEntityResolver(entityResolver);
- consumers = (SortedMap<String,
WSRPConsumer>)unmarshaller.unmarshal(inputStream, factory, null);
+ initConsumers((SortedMap<String,
WSRPConsumer>)unmarshaller.unmarshal(inputStream, factory, null));
}
catch (JBossXBException e)
{
throw new RuntimeException("Couldn't set unmarshall WSRP Consumers
configuration", e);
}
- for (WSRPConsumer consumer : consumers.values())
+ for (WSRPConsumer consumer : getConsumers())
{
ProducerInfo producerInfo = consumer.getProducerInfo();
@@ -125,7 +119,7 @@
@Override
public void stop() throws Exception
{
- for (WSRPConsumer consumer : consumers.values())
+ for (WSRPConsumer consumer : getConsumers())
{
consumer.stop();
}
@@ -152,36 +146,6 @@
@Override
protected Iterator<ProducerInfo> getProducerInfosFromStorage()
{
- return new ProducerInfoIterator(consumers.values().iterator());
+ return new ProducerInfoIterator(getConsumers().iterator());
}
-
- SortedMap<String, WSRPConsumer> getConsumers()
- {
- return consumers;
- }
-
- class ProducerInfoIterator implements Iterator<ProducerInfo>
- {
- private Iterator<WSRPConsumer> consumers;
-
- ProducerInfoIterator(Iterator<WSRPConsumer> consumers)
- {
- this.consumers = consumers;
- }
-
- public boolean hasNext()
- {
- return consumers.hasNext();
- }
-
- public ProducerInfo next()
- {
- return consumers.next().getProducerInfo();
- }
-
- public void remove()
- {
- throw new UnsupportedOperationException("remove not supported on this
iterator implementation");
- }
- }
}
Modified:
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java
===================================================================
---
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -69,12 +69,6 @@
public Object newRoot(Object root, UnmarshallingContext nav, String nsURI, String
localName, Attributes attrs)
{
- if (consumerRegistry instanceof XMLConsumerRegistry)
- {
- XMLConsumerRegistry registry = (XMLConsumerRegistry)consumerRegistry;
- return registry.getConsumers();
- }
-
return new TreeMap<String, WSRPConsumer>();
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -68,6 +68,7 @@
{
info = new ProducerInfo();
info.setId("test");
+ info.setKey("key");
serviceFactory = new BehaviorBackedServiceFactory();
EndpointConfigurationInfo eci = new EndpointConfigurationInfo(serviceFactory);
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -24,13 +24,12 @@
package org.gatein.wsrp.consumer.registry;
import junit.framework.TestCase;
+import org.gatein.pc.federation.impl.FederatingPortletInvokerService;
import org.gatein.wsrp.WSRPConsumer;
import org.gatein.wsrp.consumer.ConsumerException;
import org.gatein.wsrp.consumer.EndpointConfigurationInfo;
import org.gatein.wsrp.consumer.ProducerInfo;
import org.gatein.wsrp.consumer.RegistrationInfo;
-import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
-import org.jboss.unit.api.pojo.annotations.Test;
import java.util.Collection;
@@ -39,24 +38,19 @@
* @version $Revision: 12686 $
* @since 2.6
*/
-@Test
public class ConsumerRegistryTestCase extends TestCase
{
- private ConsumerRegistry registry = new XMLConsumerRegistry();
+ private ConsumerRegistry registry;
- public ConsumerRegistry getRegistry()
+ @Override
+ protected void setUp() throws Exception
{
- return registry;
+ registry = new InMemoryConsumerRegistry();
+ registry.setFederatingPortletInvoker(new FederatingPortletInvokerService());
}
- public void setRegistry(ConsumerRegistry registry)
+ public void testCreateAndGet()
{
- this.registry = registry;
- }
-
- public void testCRUD()
- {
-// TransactionAssert.beginTransaction();
String id = "test";
WSRPConsumer consumer = registry.createConsumer(id, null);
assertNotNull(consumer);
@@ -68,9 +62,48 @@
assertNotNull(endpoint);
RegistrationInfo regInfo = info.getRegistrationInfo();
assertTrue(regInfo.isUndetermined());
-// TransactionAssert.commitTransaction();
-// TransactionAssert.beginTransaction();
+ WSRPConsumer fromRegistry = registry.getConsumer(id);
+ assertNotNull(fromRegistry);
+ assertEquals(consumer.getProducerId(), fromRegistry.getProducerId());
+ ProducerInfo fromRegistryInfo = fromRegistry.getProducerInfo();
+ assertNotNull(fromRegistryInfo);
+ assertEquals(fromRegistry.getProducerId(), fromRegistryInfo.getId());
+ assertNotNull(fromRegistryInfo.getEndpointConfigurationInfo());
+ assertTrue(fromRegistryInfo.getRegistrationInfo().isUndetermined());
+
+ assertEquals(info.getId(), fromRegistryInfo.getId());
+ assertEquals(info.getEndpointConfigurationInfo(),
fromRegistryInfo.getEndpointConfigurationInfo());
+ assertEquals(info.getRegistrationInfo(), fromRegistryInfo.getRegistrationInfo());
+
+ Collection consumers = registry.getConfiguredConsumers();
+ assertNotNull(consumers);
+ assertEquals(1, consumers.size());
+ assertTrue(consumers.contains(consumer));
+ }
+
+ public void testGetConsumer()
+ {
+ assertNull(registry.getConsumer("inexistent"));
+ }
+
+ public void testGetProducerInfoByKey()
+ {
+ WSRPConsumer consumer = registry.createConsumer("id", null);
+ ProducerInfo info = consumer.getProducerInfo();
+
+ String key = info.getKey();
+ assertNotNull(key);
+
+ assertEquals(info, registry.getProducerInfoByKey(key));
+ }
+
+ public void testDoubleRegistrationOfConsumerWithSameId()
+ {
+ String id = "foo";
+
+ registry.createConsumer(id, null);
+
try
{
registry.createConsumer(id, null);
@@ -78,45 +111,39 @@
}
catch (ConsumerException expected)
{
- // transaction should have been rolled back
-// TransactionAssert.rollbackTransaction();
}
+ }
-// TransactionAssert.beginTransaction();
- consumer = registry.getConsumer(id);
- assertNotNull(consumer);
- assertEquals(id, consumer.getProducerId());
- info = consumer.getProducerInfo();
- assertNotNull(info);
- assertEquals(consumer.getProducerId(), info.getId());
- endpoint = info.getEndpointConfigurationInfo();
- assertNotNull(endpoint);
- assertTrue(info.getRegistrationInfo().isUndetermined());
+ public void testDelete()
+ {
+ String id = "id";
- assertNull(registry.getConsumer("inexistent"));
- Collection consumers = registry.getConfiguredConsumers();
- assertNotNull(consumers);
- assertEquals(1, consumers.size());
- assertTrue(consumers.contains(consumer));
-// TransactionAssert.commitTransaction();
+ WSRPConsumer consumer = registry.createConsumer(id, null);
+ assertEquals(consumer, registry.getConsumer(id));
+
+ String key = consumer.getProducerInfo().getKey();
+
+ registry.destroyConsumer(id);
+
+ assertNull(registry.getConsumer(id));
+ assertNull(registry.getProducerInfoByKey(key));
}
public void testUpdateProducerInfo()
{
// create a foo consumer
-// TransactionAssert.beginTransaction();
String id = "foo";
WSRPConsumer consumer = registry.createConsumer(id, null);
ProducerInfo info = consumer.getProducerInfo();
-// TransactionAssert.commitTransaction();
+ String key = info.getKey();
-// TransactionAssert.beginTransaction();
// change the id on the consumer's producer info and save it
info.setId("bar");
registry.updateProducerInfo(info);
assertNull(registry.getConsumer(id));
+ assertEquals(info, consumer.getProducerInfo());
+ assertEquals(info, registry.getProducerInfoByKey(key));
assertEquals(consumer, registry.getConsumer("bar"));
-// TransactionAssert.commitTransaction();
}
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -143,4 +143,9 @@
{
//To change body of implemented methods use File | Settings | File Templates.
}
+
+ public ProducerInfo getProducerInfoByKey(String key)
+ {
+ throw new UnsupportedOperationException();
+ }
}
Modified:
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java
===================================================================
---
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2009-11-18
15:36:13 UTC (rev 644)
+++
components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockWSRPConsumer.java 2009-11-18
15:37:08 UTC (rev 645)
@@ -81,10 +81,6 @@
return producerInfo;
}
- public void setProducerInfo(ProducerInfo producerInfo)
- {
- }
-
public void refreshProducerInfo() throws PortletInvokerException
{
}