Antony,

I have a controls project configured using eclipse.  I use Junit to test.  I
included one of my test classes for reference. Not sure if there is a better
way, but this seems to work just fine.

HTH, If you have any questions, just ask.

Tim

package test.businessService;

import junit.framework.TestCase;

import org.apache.beehive.controls.api.bean.Control;
import org.apache.beehive.controls.test.controls.util.TestBeanContext;

import businessService.CustomerServiceBean;
import database.States;

public class TestCustomerService extends TestCase 
{
    private TestBeanContext _testContext;
        
    /**
     * A business service control that references and ejb and DB control
     */
    @Control
    public CustomerServiceBean custSvcBean;    
    
        public static void main(String[] args) {
                junit.textui.TestRunner.run(TestCustomerService.class);
        }

        public TestCustomerService(String arg0) throws Exception 
        {
                super(arg0);
                _testContext = createTestBeanContext();
        }

        protected void setUp() throws Exception 
        {
                super.setUp();
        org.apache.beehive.controls.api.bean.Controls.initializeClient(
null, this, _testContext );
        _testContext.beginContext();            
        }

        protected void tearDown() throws Exception 
        {
                super.tearDown();
                _testContext.endContext();              
        }

    /**
     * Returns a new TestBeanContext to act as a container for control
testing.
     */
    private TestBeanContext createTestBeanContext() throws Exception
    {
        return new TestBeanContext();
    }

    /**
     * Tests instantiating CustomerServiceBean declaratively
     */
    public void testDeclarativeGetStatebyZipCode() throws Exception
    {
        
        States st = null;
        st = custSvcBean.getStateByZipCode( "43220" );

        if ( null != st || !"".equals( st ) )
        {
            // system out for demo purposes only
            System.out.println("testDeclarativeGetStatebyZipCode: ");
                
             System.out.println( "State Name: "+ st.getStateName() );
             System.out.println( "State Code: "+ st.getStateCode() );
             System.out.println( "Zip Code Sent: "+ "43220" );
        }
        else
        {
             System.out.println( "Did not get back hello value from Control
via getStateByZipCode method call" );
        }

                if (!st.getStateName().equals("ALABAMA"))
                        fail("Did not get back ALABAMA as the first
record!");
        
   } 
    
    /**
     * Tests instantiating CustomerServiceBean declaratively
     * This calls a simple method on a Business Service Composite Control
     */
    public void testDeclarativeHello() throws Exception
    {
        String sRetVal = null;
        
        sRetVal = custSvcBean.hello();
        
        // system out for demo purposes only
        System.out.println("testDeclarativeHello: " + sRetVal);
       

                if (!sRetVal.equals("hello!"))
                        fail("hello! was not returned from the Control");
    }
     
    /**
     * Tests instantiating CustomerServiceBean programmatically
     */
    public void testProgrammaticHello() throws Exception
    {
                CustomerServiceBean custSvcBean
=(CustomerServiceBean)java.beans.Beans.instantiate(
                        Thread.currentThread().getContextClassLoader() ,
                        "businessService.CustomerServiceBean");

        String sRetVal = null;

        sRetVal = custSvcBean.hello();
        
        // system out for demo purposes only
        System.out.println("testProgrammaticHello: " + sRetVal);
        

                if (!sRetVal.equals("hello!"))
                        fail("hello! was not returned from the Control");
    }    
    
    /**
     * Tests instantiating CustomerServiceBean declaratively
     * This calls a Business Service Composite Control
     */
    public void testDeclarativeCreateCustomerAccount() throws Exception
    {
        String sRetVal = null;
        
        sRetVal = custSvcBean.createCustomerAccount();
        
        // system out for demo purposes only
        System.out.println("testDeclarativeCreateCustomerAccount: " +
sRetVal);

                if (!sRetVal.equals("default"))
                        fail("default was not returned from the Control");
    }

}

-----Original Message-----
From: Antony Chien [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 06, 2005 1:50 AM
To: [email protected]; Beehive Developers
Subject: Control Unit Testing

Guys,
Now that 1.0 release is out, is there any recommanded way to do Control Unit
Testing?
Back at milestone 1, I had to use some dirty trick to do Control unit
testing in Eclipse environment, which is not good.
I scanned the repository...seems that you guys have some solution on this.
Can you elaborate on this topic?

--
Regards,
Antony Chien

Reply via email to