Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

...

...

...

Why ?

The system under development is a bridge between your Fixtures and the system your testing.
If you want to change the way GreenPepperGreenPepper 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 Image Removed GreenPepper can resolve your fixtures.

To change the system under development :

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


 

Code Block
langjava
titleAuto import SUD
collapsetrue
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)

Code Block
titleSpringSystemUnderDevelopment
collapsetrue
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


Code Block
languagejava
titleHook on a document
collapsetrue
 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              
       }
    }

 

 

...