Package org.jboss.soa.esb.listeners

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

/*
* 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.io.FileInputStream;
import java.net.URI;
import java.util.List;
import java.util.UUID;

import junit.framework.Assert;

import org.jboss.internal.soa.esb.couriers.DeliverOnlyCourier;
import org.jboss.soa.esb.addressing.Call;
import org.jboss.soa.esb.addressing.EPR;
import org.jboss.soa.esb.addressing.eprs.JMSEpr;
import org.jboss.soa.esb.couriers.CourierFactory;
import org.jboss.soa.esb.helpers.ConfigTree;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycle;
import org.jboss.soa.esb.listeners.lifecycle.ManagedLifecycleController;
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.body.content.BytesBody;
import org.jboss.soa.esb.message.format.MessageFactory;

public class ListenerManagerJMSXntegrationTest extends ListenerManagerBaseTest
{
  public ListenerManagerJMSXntegrationTest ()
  {
    this("listenerJms.xml");
  }
 
  public ListenerManagerJMSXntegrationTest (String configFile)
  {
    _file = configFile;
  }
 
  public void setUp() throws Exception {
    _logger.info("Writing temp files to " + TMP_DIR);

    clearMessages() ;

    // initialize registry
    runBeforeAllTests();
  }

  public void testListener () throws Exception
  {
    _logger.info("___Test for FILENAME: " + _file
          + " starting ____________________");
   
    oneTest(_file);
   
    _logger.info("___Test for FILENAME: " + _file
          + " FINISHED ____________________");
  }

  protected void oneTest (String fileName) throws Exception
 
    // Write wome messages to EPR obtained from configuration file
    String configFile = getClass().getResource(fileName).getFile();
    ConfigTree tree = ConfigTree.fromInputStream(new FileInputStream(
        configFile));   
    ConfigTree eprElement = tree.getAllChildren()[0].getFirstChild("EPR");
   
    EPR toEPR = ListenerUtil.assembleEpr(eprElement);
   
    if (toEPR instanceof JMSEpr)
    {
      // good, just checking!
    }
    else
      Assert.fail();
   
    String THE_TEXT = "___Config=" + fileName + "___ Message Content ___";

    int howMany = 10; // how many messages do you want to send before the
              // listener comes up
   
    DeliverOnlyCourier sender = CourierFactory.getCourier(toEPR);
   
    Message message = MessageFactory.getInstance().getMessage();
    message.getHeader().setCall(new Call(toEPR));
    message.getBody().add(THE_TEXT.getBytes());
   
    for (int i1 = 0; i1 < howMany; i1++)
    {
      URI uri = new URI(UUID.randomUUID().toString());
      message.getHeader().getCall().setMessageID(uri);
      sender.deliver(message);
    }

    //     launch listener manager in a child thread
    final ConfigTree newTree = ConfigTree.fromInputStream(new FileInputStream(
        configFile));

                final List<ManagedLifecycle> instances = LifecycleUtil.getListeners(newTree) ;
                final ManagedLifecycleController controller = new ManagedLifecycleController(instances) ;
                controller.start() ;
               
    _logger.debug(" All child listeners ready");

    // JUST FOR THIS TEST:
    // Give your listener some time to process queued messages (see howMany
    // above)
    // Time allowed, and maxThreads in config file will impact how many
    // messages
    // will be processed, and how many will remain unprocessed
   
    for (int count = 0 ; count < howMany ; count++)
    {
      final String response = getMessage(10000) ;
      assertNotNull("getMessage timeout", response) ;
      assertEquals(THE_TEXT, response);
    }

    _logger.debug("going to stop");
    controller.stop();
    _logger.debug("back from stop");
  }
 
  protected String _file;
 
}
TOP

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

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.