You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@beehive.apache.org by Antony Chien <an...@gmail.com> on 2005/10/06 07:49:39 UTC
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
Re: Control Unit Testing
Posted by Eddie O'Neil <ek...@gmail.com>.
Timothy -- very cool. Nice to see that it was at least possible to
figure out how to do that. :)
Antony -- I'll be committing a JUnit test container for controls
that will ship with the next version of Beehive. It does similar
things to Timothy's container (initializes the CBC and control
fields), but this functionality is more "automatic" and is
encapsulated in either a JUnit test base class or in a set of
utilities that can be called from a JUnit test.
Will update when it's committed. The JIRA bug to watch is:
http://issues.apache.org/jira/browse/BEEHIVE-103
Eddie
On 10/6/05, Timothy Brown <tb...@earthlink.net> wrote:
> 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:antony.chien@gmail.com]
> Sent: Thursday, October 06, 2005 1:50 AM
> To: user@beehive.apache.org; 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
>
>
RE: Control Unit Testing
Posted by Timothy Brown <tb...@earthlink.net>.
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:antony.chien@gmail.com]
Sent: Thursday, October 06, 2005 1:50 AM
To: user@beehive.apache.org; 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