[gatein-commits] gatein SVN: r628 - in components/wsrp/trunk/consumer: src/main/java/org/gatein/wsrp/consumer and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Nov 17 07:24:51 EST 2009


Author: chris.laprun at jboss.com
Date: 2009-11-17 07:24:50 -0500 (Tue, 17 Nov 2009)
New Revision: 628

Added:
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
Removed:
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ConsumerRegistryTestCase.java
Modified:
   components/wsrp/trunk/consumer/pom.xml
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.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/registry/xml/XMLWSRPConsumerFactory.java
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java
   components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceFactory.java
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/EndpointConfigurationInfoTestCase.java
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java
   components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java
Log:
- Simplified EndpointConfigurationInfo by removing all URLs apart from WSDL as we can't currently support setting individual endpoint URLs with JAX-WS.
  This simplification should probably extend to ServiceFactory as well and maybe result in a merge of both concepts.
- Re-worked associated tests.
- Moved ConsumerRegistryTestCase to more appropriate registry package. Still need to be cleaned-up.
- Fixed BehaviorBackedServiceFactory to properly mock starting mechanism of ServiceFactories.

Modified: components/wsrp/trunk/consumer/pom.xml
===================================================================
--- components/wsrp/trunk/consumer/pom.xml	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/pom.xml	2009-11-17 12:24:50 UTC (rev 628)
@@ -109,8 +109,7 @@
             <configuration>
                <excludes>
                   <exclude>org/gatein/wsrp/protocol/v1/*</exclude>
-                  <exclude>org/gatein/wsrp/consumer/ConsumerRegistryTestCase*</exclude>
-                  <exclude>org/gatein/wsrp/consumer/EndpointConfigurationInfoTestCase*</exclude>
+                  <exclude>org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase*</exclude>
                </excludes>
             </configuration>
          </plugin>

Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/EndpointConfigurationInfo.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -34,8 +34,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.BitSet;
-
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision: 13122 $
@@ -45,285 +43,52 @@
 {
    private final static Logger log = LoggerFactory.getLogger(EndpointConfigurationInfo.class);
 
-   /** DB primary key */
-   private Long key;
-
-   private String persistentServiceDescriptionURL = UNSET;
-   private String persistentMarkupURL = UNSET;
-   private String persistentRegistrationURL;
-   private String persistentPortletManagementURL;
-   private String persistentWsdlDefinitionURL = UNSET;
-
    // transient variables
    /** Access to the WS */
    private transient ServiceFactory serviceFactory;
    private transient String remoteHostAddress;
 
-   // Used to ensure that even invalid values can be persisted to DB so that it can be accessed from the GUI
-   public final static String UNSET = "MUST BE SET";
-
-   // maintain the dirty status of each URL
-   private BitSet clean = new BitSet();
-   private final static int SD = 0;
-   private final static int M = 1;
-   private final static int PM = 2;
-   private final static int R = 3;
-
-   /** Whether we're using information from a WSDL or not. */
-   private boolean usingWSDL = true;
-   private boolean isModifiedWSDL;
-
-   public EndpointConfigurationInfo(ProducerInfo producerInfo)
+   public EndpointConfigurationInfo()
    {
-      ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo, "ProducerInfo");
-      producerInfo.setEndpointConfigurationInfo(this);
       serviceFactory = new SOAPServiceFactory();
    }
 
-   EndpointConfigurationInfo(ProducerInfo producerInfo, ServiceFactory serviceFactory)
+   EndpointConfigurationInfo(ServiceFactory serviceFactory)
    {
-      ParameterValidation.throwIllegalArgExceptionIfNull(producerInfo, "ProducerInfo");
-      producerInfo.setEndpointConfigurationInfo(this);
+      ParameterValidation.throwIllegalArgExceptionIfNull(serviceFactory, "ServiceFactory");
       this.serviceFactory = serviceFactory;
    }
 
-   public Long getKey()
-   {
-      return key;
-   }
-
-   public void setKey(Long key)
-   {
-      this.key = key;
-   }
-
-   public boolean usesWSDL()
-   {
-      return (isWSDLNotNullAndSet() && !isModifiedWSDL) || usingWSDL;
-   }
-
-   public void setUsesWSDL(boolean useWSDL)
-   {
-      usingWSDL = useWSDL;
-   }
-
    public String getWsdlDefinitionURL()
    {
-      if (serviceFactory != null)
-      {
-         persistentWsdlDefinitionURL = (serviceFactory).getWsdlDefinitionURL();
-      }
-
-      return persistentWsdlDefinitionURL;
+      return serviceFactory.getWsdlDefinitionURL();
    }
 
-   public String getServiceDescriptionURL()
+   public void setWsdlDefinitionURL(String wsdlDefinitionURL)
    {
-      if (serviceFactory != null)
-      {
-         persistentServiceDescriptionURL = serviceFactory.getServiceDescriptionURL();
-      }
-      return persistentServiceDescriptionURL;
+      serviceFactory.setWsdlDefinitionURL(wsdlDefinitionURL);
    }
 
-   public String getMarkupURL()
+   public void start() throws Exception
    {
-      if (serviceFactory != null)
-      {
-         persistentMarkupURL = serviceFactory.getMarkupURL();
-      }
-      return persistentMarkupURL;
+      serviceFactory.start();
    }
 
-   public String getPortletManagementURL()
+   public void stop() throws Exception
    {
-      if (serviceFactory != null)
-      {
-         persistentPortletManagementURL = serviceFactory.getPortletManagementURL();
-      }
-      return persistentPortletManagementURL;
+      serviceFactory.stop();
    }
 
-   public String getRegistrationURL()
+   ServiceFactory getServiceFactory()
    {
-      if (serviceFactory != null)
-      {
-         persistentRegistrationURL = serviceFactory.getRegistrationURL();
-      }
-      return persistentRegistrationURL;
-   }
-
-   public void setServiceDescriptionURL(String serviceDescriptionURL)
-   {
-      if (serviceFactory != null)
-      {
-         serviceFactory.setServiceDescriptionURL(serviceDescriptionURL);
-      }
-      this.persistentServiceDescriptionURL = modifyIfNeeded(this.persistentServiceDescriptionURL, serviceDescriptionURL, SD);
-
-   }
-
-   public void setMarkupURL(String markupURL)
-   {
-      if (serviceFactory != null)
-      {
-         serviceFactory.setMarkupURL(markupURL);
-      }
-      this.persistentMarkupURL = modifyIfNeeded(this.persistentMarkupURL, markupURL, M);
-   }
-
-   public void setRegistrationURL(String registrationURL)
-   {
-      if (serviceFactory != null)
-      {
-         serviceFactory.setRegistrationURL(registrationURL);
-      }
-      this.persistentRegistrationURL = modifyIfNeeded(this.persistentRegistrationURL, registrationURL, R);
-   }
-
-   public void setPortletManagementURL(String portletManagementURL)
-   {
-      if (serviceFactory != null)
-      {
-         serviceFactory.setPortletManagementURL(portletManagementURL);
-      }
-      this.persistentPortletManagementURL = modifyIfNeeded(this.persistentPortletManagementURL, portletManagementURL, PM);
-   }
-
-   public void setWsdlDefinitionURL(String wsdlDefinitionURL) throws RuntimeException
-   {
-      this.persistentWsdlDefinitionURL = wsdlDefinitionURL;
-
-      // WSDL url is optional so can be null (and in particular, it is when loaded from Hibernate most of the time)
-      // do not attempt to set the URL if the service factory hasn't been created yet to avoid issues when
-      // ConsumerRegistry starts (in particular, raising an exception if the WSDL is not available)
-      if (isWSDLNotNullAndSet())
-      {
-         usingWSDL = true;
-
-         internalSetWsdlURL();
-      }
-      else
-      {
-         usingWSDL = false;
-      }
-   }
-
-   private boolean isWSDLNotNullAndSet()
-   {
-      return persistentWsdlDefinitionURL != null && !UNSET.equals(persistentWsdlDefinitionURL);
-   }
-
-   private String modifyIfNeeded(String oldValue, String newValue, int whichURL)
-   {
-      if ((oldValue != null && !oldValue.equals(newValue)) || (oldValue == null && newValue != null))
-      {
-         if (usesWSDL())
-         {
-            isModifiedWSDL = true;
-            usingWSDL = false;
-         }
-
-         oldValue = newValue;
-         clean.clear(whichURL);
-      }
-
-      return oldValue;
-   }
-
-   private ServiceFactory initServiceFactoryIfNeeded() throws RuntimeException
-   {
-      if (serviceFactory == null)
-      {
-         serviceFactory = new SOAPServiceFactory();
-         if (usesWSDL())
-         {
-//            serviceFactory = new RemoteSOAPInvokerServiceFactory();
-            internalSetWsdlURL();
-         }
-         else
-         {
-            if (!UNSET.equals(persistentServiceDescriptionURL) && !UNSET.equals(persistentMarkupURL))
-            {
-//               serviceFactory = new PerEndpointSOAPInvokerServiceFactory();
-               serviceFactory.setServiceDescriptionURL(persistentServiceDescriptionURL);
-               serviceFactory.setMarkupURL(persistentMarkupURL);
-               serviceFactory.setPortletManagementURL(persistentPortletManagementURL);
-               serviceFactory.setRegistrationURL(persistentRegistrationURL);
-            }
-            else
-            {
-               throw new IllegalStateException("Cannot initialize ServiceFactory: missing either service description or markup URLs!");
-            }
-         }
-
-         startServiceFactoryIfNeeded();
-      }
-
-      return serviceFactory;
-   }
-
-   private void startServiceFactoryIfNeeded()
-   {
-      if (!serviceFactory.isAvailable())
-      {
-         if (!serviceFactory.isFailed())
-         {
-            try
-            {
-               serviceFactory.start();
-               refreshServices(serviceFactory);
-            }
-            catch (Exception e)
-            {
-               throw new ConsumerException("Couldn't start ServiceFactory", e);
-            }
-         }
-         else
-         {
-            throw new ConsumerException("ServiceFactory has an error condition that couldn't be recovered from.");
-         }
-      }
-   }
-
-   private void internalSetWsdlURL()
-   {
       try
       {
-         serviceFactory.setWsdlDefinitionURL(persistentWsdlDefinitionURL);
-
-         // update the URLs based on WSDL information
-         persistentMarkupURL = serviceFactory.getMarkupURL();
-         persistentPortletManagementURL = serviceFactory.getPortletManagementURL();
-         persistentRegistrationURL = serviceFactory.getRegistrationURL();
-         persistentServiceDescriptionURL = serviceFactory.getServiceDescriptionURL();
-
-         clean.set(0, 4); // if setting the WSDL URL worked, consider everything clean
-         isModifiedWSDL = false;
+         start();
       }
       catch (Exception e)
       {
          throw new RuntimeException(e);
       }
-   }
-
-   public void start() throws Exception
-   {
-      initServiceFactoryIfNeeded();
-   }
-
-   public void stop() throws Exception
-   {
-      if (serviceFactory != null)
-      {
-         serviceFactory.stop();
-      }
-   }
-
-   ServiceFactory getServiceFactory()
-   {
-      initServiceFactoryIfNeeded();
-      startServiceFactoryIfNeeded();
       return serviceFactory;
    }
 
@@ -356,9 +121,7 @@
    {
       try
       {
-         T service = serviceFactory.getService(clazz);
-         clean.set(getIndexFor(clazz));
-         return service;
+         return serviceFactory.getService(clazz);
       }
       catch (Exception e)
       {
@@ -367,23 +130,6 @@
       }
    }
 
-   private int getIndexFor(Class clazz)
-   {
-      if (clazz == WSRPV1ServiceDescriptionPortType.class)
-      {
-         return SD;
-      }
-      if (clazz == WSRPV1MarkupPortType.class)
-      {
-         return M;
-      }
-      if (clazz == WSRPV1PortletManagementPortType.class)
-      {
-         return PM;
-      }
-      return R;
-   }
-
    public boolean isAvailable()
    {
       return serviceFactory.isAvailable();
@@ -391,7 +137,7 @@
 
    public boolean isRefreshNeeded()
    {
-      boolean result = !isAvailable() || areURLsDirty();
+      boolean result = !isAvailable();
       if (result)
       {
          log.debug("Refresh needed");
@@ -399,12 +145,6 @@
       return result;
    }
 
-   private boolean areURLsDirty()
-   {
-      return !clean.get(SD) || !clean.get(M) || (persistentPortletManagementURL != null && !clean.get(PM))
-         || (persistentRegistrationURL != null && !clean.get(R));
-   }
-
    public void refresh() throws InvokerUnavailableException
    {
       if (isRefreshNeeded())
@@ -415,34 +155,20 @@
 
    void forceRefresh() throws InvokerUnavailableException
    {
-      ServiceFactory serviceFactory = initServiceFactoryIfNeeded();
-      refreshServices(serviceFactory);
+      getService(WSRPV1ServiceDescriptionPortType.class, serviceFactory);
+      getService(WSRPV1MarkupPortType.class, serviceFactory);
+      getService(WSRPV1PortletManagementPortType.class, serviceFactory);
+      getService(WSRPV1RegistrationPortType.class, serviceFactory);
    }
 
-   private void refreshServices(ServiceFactory serviceFactory) throws InvokerUnavailableException
-   {
-      if (areURLsDirty())
-      {
-         getService(WSRPV1ServiceDescriptionPortType.class, serviceFactory);
-         getService(WSRPV1MarkupPortType.class, serviceFactory);
-         if (persistentPortletManagementURL != null)
-         {
-            getService(WSRPV1PortletManagementPortType.class, serviceFactory);
-         }
-         if (persistentRegistrationURL != null)
-         {
-            getService(WSRPV1RegistrationPortType.class, serviceFactory);
-         }
-      }
-   }
-
    public String getRemoteHostAddress()
    {
-      if (remoteHostAddress == null || areURLsDirty())
+      if (remoteHostAddress == null)
       {
          // extract host URL
-         int hostBegin = persistentMarkupURL.indexOf("://") + 3;
-         remoteHostAddress = persistentMarkupURL.substring(0, persistentMarkupURL.indexOf('/', hostBegin));
+         String wsdl = getWsdlDefinitionURL();
+         int hostBegin = wsdl.indexOf("://") + 3;
+         remoteHostAddress = wsdl.substring(0, wsdl.indexOf('/', hostBegin));
       }
 
       return remoteHostAddress;

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-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/ProducerInfo.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -126,7 +126,7 @@
 
    public ProducerInfo()
    {
-      persistentEndpointInfo = new EndpointConfigurationInfo(this);
+      persistentEndpointInfo = new EndpointConfigurationInfo();
       persistentRegistrationInfo = RegistrationInfo.createUndeterminedRegistration(this);
    }
 

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-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/consumer/registry/xml/XMLWSRPConsumerFactory.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -236,42 +236,11 @@
          System.out.println("setvalue endpointInfo " + localName);
       }
 
-      if ("service-description-url".equals(localName))
+      if ("endpoint-wsdl-url".equals(localName))
       {
-         // Resolve value that may contain properties for that one
          value = StringPropertyReplacer.replaceProperties(value);
-         endpointInfo.setServiceDescriptionURL(value);
+         endpointInfo.setWsdlDefinitionURL(value);
       }
-      else if ("markup-url".equals(localName))
-      {
-         // Resolve value that may contain properties for that one
-         value = StringPropertyReplacer.replaceProperties(value);
-         endpointInfo.setMarkupURL(value);
-      }
-      else if ("registration-url".equals(localName))
-      {
-         // Resolve value that may contain properties for that one
-         value = StringPropertyReplacer.replaceProperties(value);
-         endpointInfo.setRegistrationURL(value);
-      }
-      else if ("portlet-management-url".equals(localName))
-      {
-         // Resolve value that may contain properties for that one
-         value = StringPropertyReplacer.replaceProperties(value);
-         endpointInfo.setPortletManagementURL(value);
-      }
-      else if ("endpoint-wsdl-url".equals(localName))
-      {
-         value = StringPropertyReplacer.replaceProperties(value);
-         try
-         {
-            endpointInfo.setWsdlDefinitionURL(value);
-         }
-         catch (RuntimeException e)
-         {
-            // ignore at this point if the WSDL cannot be retrieved, another attempt will be made before persisting
-         }
-      }
    }
 
    public void setValue(RegistrationInfo registrationInfo, UnmarshallingContext nav, String nsURI, String localName,

Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/SOAPServiceFactory.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -34,7 +34,7 @@
 import javax.xml.ws.BindingProvider;
 import javax.xml.ws.Service;
 import java.net.MalformedURLException;
-import java.net.URL;
+import java.net.URI;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -210,32 +210,22 @@
       return wsdlDefinitionURL;
    }
 
-   public void setWsdlDefinitionURL(String wsdlDefinitionURL) throws Exception
+   public void setWsdlDefinitionURL(String wsdlDefinitionURL)
    {
-      if (wsdlDefinitionURL == null || wsdlDefinitionURL.length() == 0)
-      {
-         throw new IllegalArgumentException("Require a non-empty, non-null URL specifying where to find the WSRP " +
-            "services definition");
-      }
+      this.wsdlDefinitionURL = wsdlDefinitionURL;
 
-      // only modify WSDL URL if it's different from the previous one as this will trigger re-import of data from remote host
-      if (!wsdlDefinitionURL.equals(this.wsdlDefinitionURL))
-      {
-         this.wsdlDefinitionURL = wsdlDefinitionURL;
-
-         // we need a refresh so mark as not available but not failed
-         setAvailable(false);
-         setFailed(false);
-      }
+      // we need a refresh so mark as not available but not failed
+      setAvailable(false);
+      setFailed(false);
    }
 
    public void start() throws Exception
    {
       try
       {
-         URL wsdlURL = new URL(wsdlDefinitionURL);
+         URI wsdlURL = new URI(wsdlDefinitionURL);
 
-         Service service = Service.create(wsdlURL, SERVICE);
+         Service service = Service.create(wsdlURL.toURL(), SERVICE);
 
 //         WSRPV1MarkupPortType markupPortType = service.getPort(WSRPBaseService, WSRPV1MarkupPortType.class);
          WSRPV1MarkupPortType markupPortType = service.getPort(WSRPV1MarkupPortType.class);

Modified: components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceFactory.java
===================================================================
--- components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceFactory.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/main/java/org/gatein/wsrp/services/ServiceFactory.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -70,7 +70,7 @@
 
    void stop();
 
-   void setWsdlDefinitionURL(String wsdlDefinitionURL) throws Exception;
+   void setWsdlDefinitionURL(String wsdlDefinitionURL);
 
    String getWsdlDefinitionURL();
 }

Deleted: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ConsumerRegistryTestCase.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ConsumerRegistryTestCase.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ConsumerRegistryTestCase.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -1,123 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2009, 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;
-
-import junit.framework.TestCase;
-import org.gatein.wsrp.WSRPConsumer;
-import org.gatein.wsrp.consumer.registry.ConsumerRegistry;
-import org.gatein.wsrp.consumer.registry.xml.XMLConsumerRegistry;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import java.util.Collection;
-
-/**
- * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
- * @version $Revision: 12686 $
- * @since 2.6
- */
- at Test
-public class ConsumerRegistryTestCase extends TestCase
-{
-   private ConsumerRegistry registry = new XMLConsumerRegistry();
-
-   public ConsumerRegistry getRegistry()
-   {
-      return registry;
-   }
-
-   public void setRegistry(ConsumerRegistry registry)
-   {
-      this.registry = registry;
-   }
-
-   public void testCRUD()
-   {
-//      TransactionAssert.beginTransaction();
-      String id = "test";
-      WSRPConsumer consumer = registry.createConsumer(id, null);
-      assertNotNull(consumer);
-      assertEquals(id, consumer.getProducerId());
-      ProducerInfo info = consumer.getProducerInfo();
-      assertNotNull(info);
-      assertEquals(consumer.getProducerId(), info.getId());
-      EndpointConfigurationInfo endpoint = info.getEndpointConfigurationInfo();
-      assertNotNull(endpoint);
-      assertEquals(EndpointConfigurationInfo.UNSET, endpoint.getServiceDescriptionURL());
-      assertEquals(EndpointConfigurationInfo.UNSET, endpoint.getMarkupURL());
-      RegistrationInfo regInfo = info.getRegistrationInfo();
-      assertTrue(regInfo.isUndetermined());
-//      TransactionAssert.commitTransaction();
-
-//      TransactionAssert.beginTransaction();
-      try
-      {
-         registry.createConsumer(id, null);
-         fail("Shouldn't be possible to create a consumer with an existing id");
-      }
-      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);
-      assertEquals(EndpointConfigurationInfo.UNSET, endpoint.getServiceDescriptionURL());
-      assertEquals(EndpointConfigurationInfo.UNSET, endpoint.getMarkupURL());
-      assertTrue(info.getRegistrationInfo().isUndetermined());
-
-      assertNull(registry.getConsumer("inexistent"));
-      Collection consumers = registry.getConfiguredConsumers();
-      assertNotNull(consumers);
-      assertEquals(1, consumers.size());
-      assertTrue(consumers.contains(consumer));
-//      TransactionAssert.commitTransaction();
-   }
-
-   public void testUpdateProducerInfo()
-   {
-      // create a foo consumer
-//      TransactionAssert.beginTransaction();
-      String id = "foo";
-      WSRPConsumer consumer = registry.createConsumer(id, null);
-      ProducerInfo info = consumer.getProducerInfo();
-//      TransactionAssert.commitTransaction();
-
-//      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(consumer, registry.getConsumer("bar"));
-//      TransactionAssert.commitTransaction();
-   }
-}

Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/EndpointConfigurationInfoTestCase.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/EndpointConfigurationInfoTestCase.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/EndpointConfigurationInfoTestCase.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -25,6 +25,7 @@
 import junit.framework.TestCase;
 import org.gatein.pc.api.InvokerUnavailableException;
 import org.gatein.wsrp.services.ServiceFactory;
+import org.gatein.wsrp.test.support.BehaviorBackedServiceFactory;
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
@@ -38,79 +39,26 @@
 
    protected void setUp() throws Exception
    {
-//      info = new EndpointConfigurationInfo(); // todo fix me
+      info = new EndpointConfigurationInfo(new BehaviorBackedServiceFactory());
    }
 
-   public void testSetURLs() throws InvokerUnavailableException
-   {
-      // default state is to use WSDL
-      assertTrue(info.usesWSDL());
-
-
-      info.setServiceDescriptionURL(url);
-      assertEquals(url, info.getServiceDescriptionURL());
-
-      // changing the URLs should switch to not using WSDL anymore...
-      assertFalse(info.usesWSDL());
-      try
-      {
-         info.getServiceFactory();
-         fail("Missing markup URL: service factory should not be initialized");
-      }
-      catch (IllegalStateException expected)
-      {
-      }
-
-      info.setMarkupURL(url);
-      assertFalse(info.usesWSDL());
-      assertNotNull(info.getServiceFactory());
-      assertEquals(url, info.getServiceFactory().getServiceDescriptionURL());
-      assertEquals(url, info.getServiceFactory().getMarkupURL());
-      assertTrue(info.getServiceFactory().isAvailable());
-   }
-
    public void testSetWSDLURL() throws InvokerUnavailableException
    {
-      assertTrue(info.usesWSDL());
-
-      // todo fix me
-
-      /*info.setServiceDescriptionURL(url);
-      info.setMarkupURL(url);
-      assertTrue(info.getServiceFactory() instanceof PerEndpointSOAPInvokerServiceFactory);
-      assertFalse(info.usesWSDL());
-
       String bea = "http://wsrp.bea.com:7001/producer/producer?WSDL";
       info.setWsdlDefinitionURL(bea);
       assertEquals(bea, info.getWsdlDefinitionURL());
-      assertTrue(info.getServiceFactory() instanceof RemoteSOAPInvokerServiceFactory);
-      assertEquals(bea, ((RemoteSOAPInvokerServiceFactory)info.getServiceFactory()).getWsdlDefinitionURL());
-      assertTrue(info.usesWSDL());
-
-      info.setMarkupURL(url);
-      assertEquals(url, info.getMarkupURL());
-      assertEquals(url, info.getServiceFactory().getMarkupURL());
-      assertFalse(info.usesWSDL());*/
    }
 
-   public void testSetInvalidWSDLURL()
+   /**
+    * Setting the WSDL URL shouldn't trigger an attempt to retrieve the associated WSDL so it should be possible to
+    * provide a URL that doesn't correspond to a valid WSDL location without triggering an error until a refresh
+    */
+   public void testSetWSDLURLDoesNotTriggerWSDLRetrieval()
    {
       info.setWsdlDefinitionURL(url);
-      assertTrue(info.usesWSDL());
       assertEquals(url, info.getWsdlDefinitionURL());
    }
 
-   public void testSetNullWSDLURL()
-   {
-      info.setServiceDescriptionURL(url);
-      info.setMarkupURL(url);
-
-      // it should be possible to set the WSDL to null for Hibernate
-      info.setWsdlDefinitionURL(null);
-
-      assertFalse(info.usesWSDL());
-   }
-
    public void testRefreshWSDL() throws Exception
    {
       assertTrue(info.isRefreshNeeded());
@@ -123,25 +71,12 @@
       assertTrue(info.isAvailable());
    }
 
-   public void testRefresh() throws Exception
+   public void testGetRemoteHost()
    {
-      assertTrue(info.isRefreshNeeded());
-      assertFalse(info.isAvailable());
+      String bea = "http://wsrp.bea.com:7001/producer/producer?WSDL";
+      info.setWsdlDefinitionURL(bea);
 
-      // change the service factory to a fake one to be able to simulate access to endpoint
-//      info.setServiceFactory(new BehaviorBackedServiceFactory()); //todo
-      info.refresh();
-      assertFalse(info.isRefreshNeeded());
-      assertTrue(info.isAvailable());
-
-      info.setServiceDescriptionURL(url);
-      assertTrue(info.isRefreshNeeded());
-
-      info.getRegistrationService();
-      assertTrue(info.isRefreshNeeded());
-
-      info.getServiceDescriptionService();
-      assertFalse(info.isRefreshNeeded());
+      assertEquals("http://wsrp.bea.com:7001", info.getRemoteHostAddress());
    }
 
    public void testGetServiceFactory() throws Exception
@@ -149,8 +84,6 @@
       assertTrue(info.isRefreshNeeded());
       assertFalse(info.isAvailable());
 
-      // change the service factory to a fake one to be able to simulate access to endpoint
-//      info.setServiceFactory(new BehaviorBackedServiceFactory()); // todo
       ServiceFactory factory = info.getServiceFactory();
       assertNotNull(factory);
       assertFalse(info.isRefreshNeeded());

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-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ProducerInfoTestCase.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -68,10 +68,11 @@
    {
       info = new ProducerInfo();
       info.setId("test");
+
       serviceFactory = new BehaviorBackedServiceFactory();
+      EndpointConfigurationInfo eci = new EndpointConfigurationInfo(serviceFactory);
+      info.setEndpointConfigurationInfo(eci);
 
-      EndpointConfigurationInfo eci = new EndpointConfigurationInfo(info, serviceFactory);
-
       info.setRegistry(new MockConsumerRegistry());
    }
 

Copied: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java (from rev 592, components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/ConsumerRegistryTestCase.java)
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java	                        (rev 0)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2009, 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 junit.framework.TestCase;
+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;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
+ * @version $Revision: 12686 $
+ * @since 2.6
+ */
+ at Test
+public class ConsumerRegistryTestCase extends TestCase
+{
+   private ConsumerRegistry registry = new XMLConsumerRegistry();
+
+   public ConsumerRegistry getRegistry()
+   {
+      return registry;
+   }
+
+   public void setRegistry(ConsumerRegistry registry)
+   {
+      this.registry = registry;
+   }
+
+   public void testCRUD()
+   {
+//      TransactionAssert.beginTransaction();
+      String id = "test";
+      WSRPConsumer consumer = registry.createConsumer(id, null);
+      assertNotNull(consumer);
+      assertEquals(id, consumer.getProducerId());
+      ProducerInfo info = consumer.getProducerInfo();
+      assertNotNull(info);
+      assertEquals(consumer.getProducerId(), info.getId());
+      EndpointConfigurationInfo endpoint = info.getEndpointConfigurationInfo();
+      assertNotNull(endpoint);
+      RegistrationInfo regInfo = info.getRegistrationInfo();
+      assertTrue(regInfo.isUndetermined());
+//      TransactionAssert.commitTransaction();
+
+//      TransactionAssert.beginTransaction();
+      try
+      {
+         registry.createConsumer(id, null);
+         fail("Shouldn't be possible to create a consumer with an existing id");
+      }
+      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());
+
+      assertNull(registry.getConsumer("inexistent"));
+      Collection consumers = registry.getConfiguredConsumers();
+      assertNotNull(consumers);
+      assertEquals(1, consumers.size());
+      assertTrue(consumers.contains(consumer));
+//      TransactionAssert.commitTransaction();
+   }
+
+   public void testUpdateProducerInfo()
+   {
+      // create a foo consumer
+//      TransactionAssert.beginTransaction();
+      String id = "foo";
+      WSRPConsumer consumer = registry.createConsumer(id, null);
+      ProducerInfo info = consumer.getProducerInfo();
+//      TransactionAssert.commitTransaction();
+
+//      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(consumer, registry.getConsumer("bar"));
+//      TransactionAssert.commitTransaction();
+   }
+}


Property changes on: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/consumer/registry/ConsumerRegistryTestCase.java
___________________________________________________________________
Name: svn:executable
   + *

Modified: components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java
===================================================================
--- components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java	2009-11-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/BehaviorBackedServiceFactory.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -62,6 +62,8 @@
    private final static String PM_URL = "pm";
    private final static String R_URL = "r";
    private boolean initialized = false;
+   private String wsdl = DEFAULT_WSDL_URL;
+   public static final String DEFAULT_WSDL_URL = "http://example.com?wsdl";
 
 
    public BehaviorBackedServiceFactory()
@@ -72,6 +74,11 @@
 
    public <T> T getService(Class<T> serviceClass) throws Exception
    {
+      if (!isAvailable() && !isFailed())
+      {
+         start();
+      }
+
       if (WSRPV1ServiceDescriptionPortType.class.isAssignableFrom(serviceClass))
       {
          return (T)registry.getServiceDescriptionBehavior();
@@ -103,12 +110,7 @@
 
    public boolean isAvailable()
    {
-      if (!initialized)
-      {
-         initialized = true;
-         return false;
-      }
-      return true;
+      return initialized;
    }
 
    public boolean isFailed()
@@ -168,7 +170,7 @@
 
    public void start() throws Exception
    {
-      // do nothing
+      initialized = true;
    }
 
    public void stop()
@@ -176,14 +178,14 @@
       throw new NotYetImplemented();
    }
 
-   public void setWsdlDefinitionURL(String wsdlDefinitionURL) throws Exception
+   public void setWsdlDefinitionURL(String wsdlDefinitionURL)
    {
-      //To change body of implemented methods use File | Settings | File Templates.
+      wsdl = wsdlDefinitionURL;
    }
 
    public String getWsdlDefinitionURL()
    {
-      return null;  //To change body of implemented methods use File | Settings | File Templates.
+      return wsdl;
    }
 
    public void destroy()

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-17 11:01:58 UTC (rev 627)
+++ components/wsrp/trunk/consumer/src/test/java/org/gatein/wsrp/test/support/MockConsumerRegistry.java	2009-11-17 12:24:50 UTC (rev 628)
@@ -121,8 +121,6 @@
       MockWSRPConsumer consumer = new MockWSRPConsumer(CONSUMER2);
       consumer.getProducerInfo().setActive(true);
       EndpointConfigurationInfo info = consumer.getProducerInfo().getEndpointConfigurationInfo();
-      info.setServiceDescriptionURL(MOCK_SERVICE_DESCRIPTION);
-      info.setMarkupURL(MOCK_MARKUP);
       consumers.put(CONSUMER2, consumer);
    }
 



More information about the gatein-commits mailing list