/
Using a Custom System Under Development (SUD)

Using a Custom System Under Development (SUD)

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)


Auto import SUD
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)

SpringSystemUnderDevelopment
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


Hook on a document
 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              
       }
    }




Related content

Fixtures Conventions
Fixtures Conventions
More like this
GreenPepper Maven Plugin - Generate Fixtures
GreenPepper Maven Plugin - Generate Fixtures
More like this
GreenPepper Maven Plugin - FixtureGeneratorDefinition
GreenPepper Maven Plugin - FixtureGeneratorDefinition
More like this
GreenPepper Maven Plugin - fixture-jar
GreenPepper Maven Plugin - fixture-jar
More like this
GreenPepper Maven Plugin - Usage
GreenPepper Maven Plugin - Usage
More like this
.Net Runner
.Net Runner
More like this