Java Code Examples for org.springframework.test.context.ContextConfiguration

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project spring-activiti-sandbox, under directory /src/main/java/org/activiti/spring/impl/test/.

Source file: SpringActivitiTestCase.java

  31 
vote

@Override protected void initializeProcessEngine(){
  ContextConfiguration contextConfiguration=getClass().getAnnotation(ContextConfiguration.class);
  String[] value=contextConfiguration.value();
  if (value == null) {
    throw new ActivitiException("value is mandatory in ContextConfiguration");
  }
  if (value.length != 1) {
    throw new ActivitiException("SpringActivitiTestCase requires exactly one value in annotation ContextConfiguration");
  }
  String configurationFile=value[0];
  processEngine=cachedProcessEngines.get(configurationFile);
  if (processEngine == null) {
    processEngine=applicationContext.getBean(ProcessEngine.class);
    cachedProcessEngines.put(configurationFile,processEngine);
  }
}
 

Example 2

From project spock, under directory /spock-spring/src/main/java/org/spockframework/spring/.

Source file: SpringExtension.java

  29 
vote

public void visitSpec(SpecInfo spec){
  if (!spec.getReflection().isAnnotationPresent(ContextConfiguration.class))   return;
  checkNoSharedFieldsInjected(spec);
  if (!handleProfileValues(spec))   return;
  SpringTestContextManager manager=new SpringTestContextManager(spec.getReflection());
  final SpringInterceptor interceptor=new SpringInterceptor(manager);
  spec.addListener(new AbstractRunListener(){
    public void error(    ErrorInfo error){
      interceptor.error(error);
    }
  }
);
  SpecInfo topSpec=spec.getTopSpec();
  topSpec.getSetupSpecMethod().addInterceptor(interceptor);
  topSpec.getSetupMethod().addInterceptor(interceptor);
  topSpec.getCleanupMethod().addInterceptor(interceptor);
  topSpec.getCleanupSpecMethod().addInterceptor(interceptor);
}