Dashboard > GreenPepperOpen > ... > Developer Examples > Spring Example
  GreenPepperOpen Log In View a printable version of the current page.  
  Spring Example
Added by Gilles Carey, last edited by Francois Denommee on Mar 16, 2009  (view change)
Labels: 

Import
com.greenpepper.extensions.spring

Spring beans can be hook in  GreenPepper as fixtures by specifying the Spring factory implementing the factory interface:

Begin Info
  1.  GreenPepper command line: java -cp {GreenPepperClassPaths} CommandLineRunner -f SpringFixtureFactory {InputFile} {OutputFile}
  2.  GreenPepper server: database table SYSTEM_UNDER_TEST, columns FIXTURE_FACTORY="SpringFixtureFactory" and FIXTURE_FACTORY_ARGS="{SpringApplicationContextFile}" of your SUT entry.
End Info

This first example show the use of a spring bean as a fixture:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
</beans>
[Rule for][CalculatorBeanId]
[op1][op2][sum?]
[1][2][3]
"[Rule for][CalculatorBeanId]
[op1][op2][sum?]
[1][2][3 RightAnnotation]"

If the bean to instanciate as a fixture does not exist, an error is thrown:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
</beans>
[Rule for][UnexistentBeanId]
[op1][op2][sum?]
[1][2][3]
"[Rule for ExceptionAnnotation][UnexistentBeanId]
[op1][op2][sum?]
[1][2][3]"

Here's an example of one bean wired to another bean:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
    <bean id="CalculatorWiredBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorWiredBean">
      <constructor-arg>
        <ref bean="CalculatorBeanId"/>
      </constructor-arg>
    </bean>
</beans>
[Rule for][CalculatorWiredBeanId]
[op1][op2][sum?]
[1][2][3]
"[Rule for][CalculatorWiredBeanId]
[op1][op2][sum?]
[1][2][3 RightAnnotation]"

A fixture class can be outside the Spring context and be dependent on beans declared in the Spring context. When that fixture is instanciated, dependencies are resolved by dynamically injecting it in the Spring context, and let Spring instanciate it:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
</beans>
[Rule for][ExternalCalculatorBeanDependent]
[op1][op2][sum?]
[1][2][3]
"[Rule for][ExternalCalculatorBeanDependent]
[op1][op2][sum?]
[1][2][3 RightAnnotation]"

A fixture outside Spring context and not dependent on it is also instanciated correctly:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
</beans>
[Rule for][IndependentExternalCalculator]
[op1][op2][sum?]
[1][2][3]
"[Rule for][IndependentExternalCalculator]
[op1][op2][sum?]
[1][2][3 RightAnnotation]"

In fact, when the Spring IOC is use, all fixture are instantiated by it. All fixture creation errors are reported by Spring:

Rule for Spring
Application Context Content table in greenpepper format after execution?
<beans>
    <bean id="CalculatorBeanId" class="com.greenpepper.extensions.spring.beans.CalculatorBean"/>
</beans>
[Rule for][UnexistentExternalCalculator]
[op1][op2][sum?]
[1][2][3]
"[Rule for ExceptionAnnotation][UnexistentExternalCalculator]
[op1][op2][sum?]
[1][2][3]"

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