1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.core.messaging;
16  
17  import org.figure8.join.core.InvalidParameterException;
18  import org.figure8.join.services.scripting.ant.AntScriptLauncherJMSAdapter;
19  
20  import junit.framework.Test;
21  import junit.framework.TestCase;
22  import junit.framework.TestSuite;
23  /**
24   * JUnit test case for testing the JMSConsumerBeanInfo class.
25   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26   * @version Revision$
27   */
28  public class JMSConsumerBeanInfoTest extends TestCase{
29  
30     // Constructors -------------------------------------------------------------
31  
32     /** Default constructor. Build a test case using a name. */
33     public JMSConsumerBeanInfoTest(String testName){
34        super(testName);
35     }
36  
37  
38     // Override of TestCase -----------------------------------------------------
39  
40     /**
41      * Make this class a TestSuite.
42      * @return A TestSuite containing this TestCase.
43      */
44     public static Test suite(){
45        TestSuite suite = new TestSuite(JMSConsumerBeanInfoTest.class);
46        return suite;
47     }
48     
49     
50     // Public -------------------------------------------------------------------
51  
52     /** Test the instanciation of a Configurable consumer from its info. */
53     public void testConfigurableConsumerInstanciation(){
54        // Create a consumer info for a Configurable consumer.
55        JMSConsumerBeanInfo consumerInfo = null;
56        try{
57           consumerInfo = new JMSConsumerBeanInfo("name", "selector", "destination",
58                "org.figure8.join.services.scripting.ant.AntScriptLauncherJMSAdapter");
59        }
60        catch (InvalidParameterException ipe){
61           fail("JMSConsumerBeanInfo creation should not fail");
62        }
63        // Create and add configuration parameters.
64        JMSConsumerBeanParameterInfo scriptParam = new JMSConsumerBeanParameterInfo("scriptPath", "build.xml");
65        JMSConsumerBeanParameterInfo extractorParam = new JMSConsumerBeanParameterInfo("propertiesExtractor",
66                "org.figure8.join.services.properties.DefaultPropertiesExtractor");
67        consumerInfo.addConsumerParameterInfo(scriptParam);
68        consumerInfo.addConsumerParameterInfo(extractorParam);
69        // Retrieve the consumer instance (this creates it and set parameters)
70        JMSConsumerBean consumer = null;
71        try {consumer = consumerInfo.getJMSConsumerBean();}
72        catch (InvalidParameterException ipe){
73           fail("JMSConsumerBean instanciation should not fail");
74        }
75        // Assert.
76        assertNotNull("The consumer has been created", consumer);
77        assertEquals("The consumer has the correct name", "name", consumer.getName());
78        assertEquals("The consumer has the correct params", "build.xml", ((AntScriptLauncherJMSAdapter)consumer).getScriptLauncher().getScriptPath());
79     }
80  }