Codota Logo
SpringBootTestContextBootstrapper
Code IndexAdd Codota to your IDE (free)

How to use
SpringBootTestContextBootstrapper
in
org.springframework.boot.test.context

Best Java code snippets using org.springframework.boot.test.context.SpringBootTestContextBootstrapper (Showing top 11 results out of 315)

  • Add the Codota plugin to your IDE and get smart completions
private void myMethod () {
BufferedReader b =
  • Codota IconInputStream in;new BufferedReader(new InputStreamReader(in))
  • Codota IconReader in;new BufferedReader(in)
  • Codota IconFile file;new BufferedReader(new FileReader(file))
  • Smart code suggestions by Codota
}
origin: org.springframework.boot/spring-boot-test

@Override
protected ContextLoader resolveContextLoader(Class<?> testClass,
    List<ContextConfigurationAttributes> configAttributesList) {
  Class<?>[] classes = getClasses(testClass);
  if (!ObjectUtils.isEmpty(classes)) {
    for (ContextConfigurationAttributes configAttributes : configAttributesList) {
      addConfigAttributesClasses(configAttributes, classes);
    }
  }
  return super.resolveContextLoader(testClass, configAttributesList);
}
origin: org.springframework.boot/spring-boot-test

/**
 * Create a new {@link MergedContextConfiguration} with different classes.
 * @param mergedConfig the source config
 * @param classes the replacement classes
 * @return a new {@link MergedContextConfiguration}
 */
protected final MergedContextConfiguration createModifiedConfig(
    MergedContextConfiguration mergedConfig, Class<?>[] classes) {
  return createModifiedConfig(mergedConfig, classes,
      mergedConfig.getPropertySourceProperties());
}
origin: org.springframework.boot/spring-boot-test

protected void verifyConfiguration(Class<?> testClass) {
  SpringBootTest springBootTest = getAnnotation(testClass);
  if (springBootTest != null
      && (springBootTest.webEnvironment() == WebEnvironment.DEFINED_PORT
          || springBootTest.webEnvironment() == WebEnvironment.RANDOM_PORT)
      && getAnnotation(WebAppConfiguration.class, testClass) != null) {
    throw new IllegalStateException("@WebAppConfiguration should only be used "
        + "with @SpringBootTest when @SpringBootTest is configured with a "
        + "mock web environment. Please remove @WebAppConfiguration or "
        + "reconfigure @SpringBootTest.");
  }
}
origin: org.springframework.boot/spring-boot-test

@Override
protected MergedContextConfiguration processMergedContextConfiguration(
    MergedContextConfiguration mergedConfig) {
  Class<?>[] classes = getOrFindConfigurationClasses(mergedConfig);
  List<String> propertySourceProperties = getAndProcessPropertySourceProperties(
      mergedConfig);
  mergedConfig = createModifiedConfig(mergedConfig, classes,
      StringUtils.toStringArray(propertySourceProperties));
  WebEnvironment webEnvironment = getWebEnvironment(mergedConfig.getTestClass());
  if (webEnvironment != null && isWebEnvironmentSupported(mergedConfig)) {
    WebApplicationType webApplicationType = getWebApplicationType(mergedConfig);
    if (webApplicationType == WebApplicationType.SERVLET
        && (webEnvironment.isEmbedded()
            || webEnvironment == WebEnvironment.MOCK)) {
      WebAppConfiguration webAppConfiguration = AnnotatedElementUtils
          .findMergedAnnotation(mergedConfig.getTestClass(),
              WebAppConfiguration.class);
      String resourceBasePath = (webAppConfiguration != null)
          ? webAppConfiguration.value() : "src/main/webapp";
      mergedConfig = new WebMergedContextConfiguration(mergedConfig,
          resourceBasePath);
    }
    else if (webApplicationType == WebApplicationType.REACTIVE
        && (webEnvironment.isEmbedded()
            || webEnvironment == WebEnvironment.MOCK)) {
      return new ReactiveWebMergedContextConfiguration(mergedConfig);
    }
  }
  return mergedConfig;
}
origin: org.springframework.boot/spring-boot-test

@Override
public TestContext buildTestContext() {
  TestContext context = super.buildTestContext();
  verifyConfiguration(context.getTestClass());
  WebEnvironment webEnvironment = getWebEnvironment(context.getTestClass());
  if (webEnvironment == WebEnvironment.MOCK
      && deduceWebApplicationType() == WebApplicationType.SERVLET) {
    context.setAttribute(ACTIVATE_SERVLET_LISTENER, true);
  }
  else if (webEnvironment != null && webEnvironment.isEmbedded()) {
    context.setAttribute(ACTIVATE_SERVLET_LISTENER, false);
  }
  return context;
}
origin: odrotbohm/moduliths

BootstrapContext bootstrapContext = new DefaultBootstrapContext(testClass, delegate);
SpringBootTestContextBootstrapper bootstrapper = new SpringBootTestContextBootstrapper();
bootstrapper.setBootstrapContext(bootstrapContext);
MergedContextConfiguration configuration = bootstrapper.buildMergedContextConfiguration();
origin: org.springframework.boot/spring-boot-test

protected Class<?>[] getOrFindConfigurationClasses(
    MergedContextConfiguration mergedConfig) {
  Class<?>[] classes = mergedConfig.getClasses();
  if (containsNonTestComponent(classes) || mergedConfig.hasLocations()) {
    return classes;
  }
  Class<?> found = new AnnotatedClassFinder(SpringBootConfiguration.class)
      .findFromClass(mergedConfig.getTestClass());
  Assert.state(found != null,
      "Unable to find a @SpringBootConfiguration, you need to use "
          + "@ContextConfiguration or @SpringBootTest(classes=...) "
          + "with your test");
  logger.info("Found @SpringBootConfiguration " + found.getName() + " for test "
      + mergedConfig.getTestClass());
  return merge(found, classes);
}
origin: org.springframework.boot/spring-boot-test

/**
 * Create a new {@link MergedContextConfiguration} with different classes and
 * properties.
 * @param mergedConfig the source config
 * @param classes the replacement classes
 * @param propertySourceProperties the replacement properties
 * @return a new {@link MergedContextConfiguration}
 */
protected final MergedContextConfiguration createModifiedConfig(
    MergedContextConfiguration mergedConfig, Class<?>[] classes,
    String[] propertySourceProperties) {
  return new MergedContextConfiguration(mergedConfig.getTestClass(),
      mergedConfig.getLocations(), classes,
      mergedConfig.getContextInitializerClasses(),
      mergedConfig.getActiveProfiles(),
      mergedConfig.getPropertySourceLocations(), propertySourceProperties,
      mergedConfig.getContextCustomizers(), mergedConfig.getContextLoader(),
      getCacheAwareContextLoaderDelegate(), mergedConfig.getParent());
}
origin: org.springframework.boot/spring-boot-test

protected Class<?>[] getClasses(Class<?> testClass) {
  SpringBootTest annotation = getAnnotation(testClass);
  return (annotation != null) ? annotation.classes() : null;
}
origin: org.springframework.boot/spring-boot-test

/**
 * Return the {@link WebEnvironment} type for this test or null if undefined.
 * @param testClass the source test class
 * @return the {@link WebEnvironment} or {@code null}
 */
protected WebEnvironment getWebEnvironment(Class<?> testClass) {
  SpringBootTest annotation = getAnnotation(testClass);
  return (annotation != null) ? annotation.webEnvironment() : null;
}
origin: org.springframework.boot/spring-boot-test

protected String[] getProperties(Class<?> testClass) {
  SpringBootTest annotation = getAnnotation(testClass);
  return (annotation != null) ? annotation.properties() : null;
}
org.springframework.boot.test.contextSpringBootTestContextBootstrapper

Javadoc

TestContextBootstrapper for Spring Boot. Provides support for SpringBootTest and may also be used directly or subclassed. Provides the following features over and above DefaultTestContextBootstrapper:
  • Uses SpringBootContextLoader as the #getDefaultContextLoaderClass(Class).
  • Automatically searches for a SpringBootConfiguration when required.
  • Allows custom Environment #getProperties(Class) to be defined.
  • Provides support for different WebEnvironment modes.

Most used methods

  • <init>
  • addConfigAttributesClasses
  • buildMergedContextConfiguration
  • containsNonTestComponent
  • createModifiedConfig
    Create a new MergedContextConfiguration with different classes and properties.
  • deduceWebApplicationType
  • getAndProcessPropertySourceProperties
  • getAnnotation
  • getCacheAwareContextLoaderDelegate
  • getClasses
  • getDifferentiatorPropertySourceProperty
    Return a "differentiator" property to ensure that there is something to differentiate regular tests
  • getOrFindConfigurationClasses
  • getDifferentiatorPropertySourceProperty,
  • getOrFindConfigurationClasses,
  • getProperties,
  • getWebApplicationType,
  • getWebEnvironment,
  • isFromConfiguration,
  • isWebEnvironmentSupported,
  • merge,
  • processMergedContextConfiguration,
  • processPropertySourceProperties

Popular in Java

  • Making http post requests using okhttp
  • notifyDataSetChanged (ArrayAdapter)
  • startActivity (Activity)
  • requestLocationUpdates (LocationManager)
  • IOException (java.io)
    Signals that an I/O exception of some sort has occurred. This class is the general class of exceptio
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JTable (javax.swing)
  • Logger (org.slf4j)
    The main user interface to logging. It is expected that logging takes place through concrete impleme
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now