Dashboard > GreenPepperOpen > Documentation > Using a custom SystemUnderDevelopment
  GreenPepperOpen Log In View a printable version of the current page.  
  Using a custom SystemUnderDevelopment
Added by Laurent Cobos, last edited by Francois Denommee on Mar 17, 2009  (view change)
Labels: 
(None)

Why ?

The system under development is a bridge between your Fixtures and the system your testing.
If you want to change the way  GreenPepper is finding/instanciating your fixtures, or if you need to hook the document execution then you can define a Custom System Under Development.

Changing how  GreenPepper is finding your Fixtures

This could be useful when you are using for example an IOC, like Spring (see Spring Example) or just when you want to add locations (packages in java, namespaces in .Net) for  GreenPepper can resolve your fixtures.

To change the system under development :

Only for specifying location to resolve fixtures (packages in java, namespaces in .Net)

 public static class CustomSystemUnderDevelopment extends DefaultSystemUnderDevelopment
    {
        public CustomSystemUnderDevelopment( String... params )
        {
           super.addImport("com.mycompany.fixtures");
           super.addImport("com.mycompany.specials.fixtures");
        }
    }

By this custom system under development you tell  GreenPepper to look in "com.mycompany.fixtures" and "com.mycompany.specials.fixtures" to resolve fixtures in specfications that your are running.

Changing Fixture instanciation mechanism (Spring example)

package com.greenpepper.extensions.spring;

import ...;

public class SpringSystemUnderDevelopment extends DefaultSystemUnderDevelopment
{
    private BeanFactory beanFactory;

    public SpringSystemUnderDevelopment(String... applicationCtxes)
    {
        this.beanFactory = new GreenPepperXMLAplicationContext(applicationCtxes).getBeanFactory();
    }

    public SpringSystemUnderDevelopment(BeanFactory beanFactory)
    {
        this.beanFactory = beanFactory;
    }

    @Override
    public Fixture getFixture(String fixtureName, String... params) throws Throwable
    {
        Fixture fixture;
        if (params.length != 0)
        {
            fixture = super.getFixture(fixtureName, params);
        }
        else
        {
            try
            {
                fixture = new DefaultFixture(beanFactory.getBean(fixtureName));
            }
            catch (NoSuchBeanDefinitionException e)
            {
                fixture = new DefaultFixture(instantiateAsAutowiredBean(fixtureName));
            }
        }

        return fixture;
    }

    private Object instantiateAsAutowiredBean(String fixtureName) throws Exception
    {
        Class fixtureClass = loadType(fixtureName).getUnderlyingClass();

        BeanDefinition beanDef = new RootBeanDefinition(fixtureClass, RootBeanDefinition.AUTOWIRE_AUTODETECT);

        DefaultListableBeanFactory fallFactory = new DefaultListableBeanFactory(beanFactory);
        fallFactory.registerBeanDefinition(fixtureName, beanDef);

        return fallFactory.getBean(fixtureName);
    }
}

Hooking document execution

 public static class CustomSystemUnderDevelopment extends DefaultSystemUnderDevelopment
    {
        public CustomSystemUnderDevelopment( String... params )
        {
           
        }

       public void onStartDocument(Document document)
       {
          //this method is called before GreenPepper execute a document
       }

       public void onEndDocument(Document document)
       {
          //this method is called after GreenPepper has executed the document              
       }
    }

DEMONSTRATION LICENSE - This Confluence site is for demonstration purposes only. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.4.3 Build:#705 Mar 21, 2007) - Bug/feature request - Contact Administrators