Package org.jboss.soa.esb.listeners

Source Code of org.jboss.soa.esb.listeners.ServiceInvokerUnitTest

/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., 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.jboss.soa.esb.listeners;

import java.net.URI;

import junit.framework.TestCase;

import org.jboss.internal.soa.esb.couriers.MockCourier;
import org.jboss.internal.soa.esb.couriers.MockCourierFactory;
import org.jboss.internal.soa.esb.services.registry.MockRegistry;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.listeners.RegistryUtil;
import org.jboss.soa.esb.client.ServiceInvoker;
import org.jboss.soa.esb.common.Environment;
import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.listeners.message.MessageDeliverException;
import org.jboss.soa.esb.listeners.message.MissingServiceException;
import org.jboss.soa.esb.listeners.message.ResponseTimeoutException;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.format.MessageFactory;

import com.arjuna.common.util.propertyservice.PropertyManager;

public class ServiceInvokerUnitTest extends TestCase
{
  private String redeliverDlsServiceOn ;
  private EPR timeoutEPR ;

  protected final void setUp() throws Exception
  {
    MockCourierFactory.install() ;
    MockRegistry.install() ;
    timeoutEPR = new EPR(new URI("timeout")) ;
    MockRegistry.register("timeout", "service", timeoutEPR, new MockCourier(true)) ;
    final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
    if (propertyManager != null)
    {
      redeliverDlsServiceOn = propertyManager.getProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
      propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, "false") ;
    }
  }

  protected final void tearDown()
  {
    final PropertyManager propertyManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.CORE_MODULE) ;
    if (propertyManager != null)
    {
      if (redeliverDlsServiceOn == null)
      {
        propertyManager.removeProperty(Environment.REDELIVER_DLS_SERVICE_ON) ;
      }
      else
      {
        propertyManager.setProperty(Environment.REDELIVER_DLS_SERVICE_ON, redeliverDlsServiceOn) ;
      }
    }
    MockRegistry.uninstall();
    MockCourierFactory.uninstall() ;
  }

  public void testMissingService() throws Exception
  {
    final Message message = MessageFactory.getInstance().getMessage() ;
    final ServiceInvoker invoker = new ServiceInvoker("missing", "service") ;
    try
    {
      invoker.deliverSync(message, 5000) ;
      fail("Expected MissingServiceException") ;
    }
    catch (final MissingServiceException mse) {} // expected
  }

  public void testTimeoutService() throws Exception
  {
    final Message message = MessageFactory.getInstance().getMessage() ;
    message.getHeader().getCall().setReplyTo(timeoutEPR) ;
    final ServiceInvoker invoker = new ServiceInvoker("timeout", "service") ;
    try
    {
      invoker.deliverSync(message, 5000) ;
      fail("Expected ResponseTimeoutException") ;
    }
    catch (final ResponseTimeoutException rte)
    {
      // expected
      assertFalse("Checking for exception", rte.getMessage().contains("Told not to retry")) ;
    }
  }

  public void testTimeoutServiceNoRetry() throws Exception
  {
    final Message message = MessageFactory.getInstance().getMessage() ;
    message.getHeader().getCall().setReplyTo(timeoutEPR) ;
    message.getProperties().setProperty(Environment.EXCEPTION_ON_DELIVERY_FAILURE, "true") ;
    final ServiceInvoker invoker = new ServiceInvoker("timeout", "service") ;
    try
    {
      invoker.deliverSync(message, 5000) ;
      fail("Expected ResponseTimeoutException") ;
    }
    catch (final ResponseTimeoutException rte)
    {
      // expected
      assertTrue("Checking for exception", rte.getMessage().contains("Told not to retry")) ;
    }
  }

  public void testInvalidParameters() throws Exception
  {
    Message message = MessageFactory.getInstance().getMessage();
    final String category = "test" ;
    final String name = "qwerty" ;

    try
    {
            ServiceInvoker invoker = new ServiceInvoker("foo", "bar");
            invoker.deliverAsync(message);
      fail();
    }
    catch (MessageDeliverException ex)
    {
    }

    final EPR epr = new EPR(new URI(category + name));

    MockRegistry.register(category, name, epr, new MockCourier(true)) ;

    {
      ServiceInvoker invoker = new ServiceInvoker(category, name);
      invoker.deliverAsync(message);
    }

    RegistryUtil.unregister(category, name, epr);
   
    try
    {
      ServiceInvoker invoker = new org.jboss.soa.esb.client.ServiceInvoker(category, name);
      invoker.deliverAsync(message);
    }
    catch (final MissingServiceException mse) {} // expected
  }
}
TOP

Related Classes of org.jboss.soa.esb.listeners.ServiceInvokerUnitTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.