private Map<String, Object> getEnvironmentProperties(Class<?> testClass) throws Exception {
   TestContext context = new ExposedTestContextManager(testClass).getExposedTestContext();
   new IntegrationTestPropertiesListener().prepareTestInstance(context);
   MergedContextConfiguration config =
       (MergedContextConfiguration)
           ReflectionTestUtils.getField(context, "mergedContextConfiguration");
   return this.loader.extractEnvironmentProperties(config.getPropertySourceProperties());
 }
 private Set<Object> getSources(MergedContextConfiguration mergedConfig) {
   Set<Object> sources = new LinkedHashSet<Object>();
   sources.addAll(Arrays.asList(mergedConfig.getClasses()));
   sources.addAll(Arrays.asList(mergedConfig.getLocations()));
   if (sources.isEmpty()) {
     throw new IllegalStateException(
         "No configuration classes or locations found in @SpringApplicationConfiguration. "
             + "For default configuration detection to work you need Spring 4.0.3 or better (found "
             + SpringVersion.getVersion()
             + ").");
   }
   return sources;
 }
  @Override
  public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception {

    SpringApplication application = getSpringApplication();
    application.setSources(getSources(mergedConfig));
    if (!ObjectUtils.isEmpty(mergedConfig.getActiveProfiles())) {
      application.setAdditionalProfiles(mergedConfig.getActiveProfiles());
    }
    application.setDefaultProperties(getArgs(mergedConfig));
    List<ApplicationContextInitializer<?>> initializers =
        getInitializers(mergedConfig, application);
    if (mergedConfig instanceof WebMergedContextConfiguration) {
      new WebConfigurer().configure(mergedConfig, application, initializers);
    } else {
      application.setWebEnvironment(false);
    }
    application.setInitializers(initializers);

    return application.run();
  }
 private List<ApplicationContextInitializer<?>> getInitializers(
     MergedContextConfiguration mergedConfig, SpringApplication application) {
   List<ApplicationContextInitializer<?>> initializers =
       new ArrayList<ApplicationContextInitializer<?>>();
   initializers.addAll(application.getInitializers());
   for (Class<? extends ApplicationContextInitializer<?>> initializerClass :
       mergedConfig.getContextInitializerClasses()) {
     initializers.add(BeanUtils.instantiate(initializerClass));
   }
   return initializers;
 }
 private Map<String, Object> getArgs(MergedContextConfiguration mergedConfig) {
   Map<String, Object> args = new LinkedHashMap<String, Object>();
   if (AnnotationUtils.findAnnotation(mergedConfig.getTestClass(), IntegrationTest.class)
       == null) {
     // Not running an embedded server, just setting up web context
     args.put("server.port", "-1");
   }
   // JMX bean names will clash if the same bean is used in multiple contexts
   args.put("spring.jmx.enabled", "false");
   return args;
 }
  public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception {
    GenericWebApplicationContext context = new GenericWebApplicationContext();

    // Commented out until SPR-10392 is fixed and we can upgrade to Spring 3.2.3.RELEASE or higher
    //		ApplicationContext parent = config.getParentApplicationContext();
    //		if(parent != null) {
    //			context.setParent(parent);
    //		}

    prepareContext(context);
    prepareContext(context, config);
    customizeBeanFactory(context.getDefaultListableBeanFactory());
    createBeanDefinitionReader(context).loadBeanDefinitions(config.getLocations());
    AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
    customizeContext(context);
    context.refresh();
    context.registerShutdownHook();

    return context;
  }