Tabnine Logo
MergedContextConfiguration.getTestClass
Code IndexAdd Tabnine to your IDE (free)

How to use
getTestClass
method
in
org.springframework.test.context.MergedContextConfiguration

Best Java code snippets using org.springframework.test.context.MergedContextConfiguration.getTestClass (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: spring-projects/spring-framework

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: spring-projects/spring-framework

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getLocations() locations}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasLocations()) {
    String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'locations' " +
            "(or 'value') attribute %s, but %s does not support resource locations.",
        mergedConfig.getTestClass().getName(), ObjectUtils.nullSafeToString(mergedConfig.getLocations()),
        getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: spring-projects/spring-framework

/**
 * Returns a {@link WebMergedContextConfiguration} if the test class in the
 * supplied {@code MergedContextConfiguration} is annotated with
 * {@link WebAppConfiguration @WebAppConfiguration} and otherwise returns
 * the supplied instance unmodified.
 */
@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  WebAppConfiguration webAppConfiguration =
      AnnotatedElementUtils.findMergedAnnotation(mergedConfig.getTestClass(), WebAppConfiguration.class);
  if (webAppConfiguration != null) {
    return new WebMergedContextConfiguration(mergedConfig, webAppConfiguration.value());
  }
  else {
    return mergedConfig;
  }
}
origin: spring-projects/spring-framework

void assertMergedConfig(
    MergedContextConfiguration mergedConfig,
    Class<?> expectedTestClass,
    String[] expectedLocations,
    Class<?>[] expectedClasses,
    Set<Class<? extends ApplicationContextInitializer<?>>> expectedInitializerClasses,
    Class<? extends ContextLoader> expectedContextLoaderClass) {
  assertNotNull(mergedConfig);
  assertEquals(expectedTestClass, mergedConfig.getTestClass());
  assertNotNull(mergedConfig.getLocations());
  assertArrayEquals(expectedLocations, mergedConfig.getLocations());
  assertNotNull(mergedConfig.getClasses());
  assertArrayEquals(expectedClasses, mergedConfig.getClasses());
  assertNotNull(mergedConfig.getActiveProfiles());
  if (expectedContextLoaderClass == null) {
    assertNull(mergedConfig.getContextLoader());
  }
  else {
    assertEquals(expectedContextLoaderClass, mergedConfig.getContextLoader().getClass());
  }
  assertNotNull(mergedConfig.getContextInitializerClasses());
  assertEquals(expectedInitializerClasses, mergedConfig.getContextInitializerClasses());
}
origin: stackoverflow.com

 import org.kubek2k.springockito.annotations.internal.Loader;

import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;

public class PatchedSpringockitoContextLoader extends GenericXmlContextLoader {

  private final Loader loader = new Loader();

  @Override
  protected void prepareContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
    super.prepareContext(context, mergedConfig);
    this.loader.defineMocksAndSpies(mergedConfig.getTestClass());
  }

  @Override
  protected void customizeContext(GenericApplicationContext context) {
    super.customizeContext(context);
    this.loader.registerMocksAndSpies(context);
  }

}
origin: org.springframework.boot/spring-boot-test

private boolean isFromConfiguration(MergedContextConfiguration candidateConfig,
    ContextConfiguration configuration) {
  ContextConfigurationAttributes attributes = new ContextConfigurationAttributes(
      candidateConfig.getTestClass(), configuration);
  Set<Class<?>> configurationClasses = new HashSet<>(
      Arrays.asList(attributes.getClasses()));
  for (Class<?> candidate : candidateConfig.getClasses()) {
    if (configurationClasses.contains(candidate)) {
      return true;
    }
  }
  return false;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: apache/servicemix-bundles

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: apache/servicemix-bundles

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getClasses() classes}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasClasses()) {
    String msg = String.format(
      "Test class [%s] has been configured with @ContextConfiguration's 'classes' attribute %s, "
          + "but %s does not support annotated classes.", mergedConfig.getTestClass().getName(),
      ObjectUtils.nullSafeToString(mergedConfig.getClasses()), getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

/**
 * Ensure that the supplied {@link MergedContextConfiguration} does not
 * contain {@link MergedContextConfiguration#getLocations() locations}.
 * @since 4.0.4
 * @see AbstractGenericContextLoader#validateMergedContextConfiguration
 */
@Override
protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  if (mergedConfig.hasLocations()) {
    String msg = String.format("Test class [%s] has been configured with @ContextConfiguration's 'locations' " +
            "(or 'value') attribute %s, but %s does not support resource locations.",
        mergedConfig.getTestClass().getName(), ObjectUtils.nullSafeToString(mergedConfig.getLocations()),
        getClass().getSimpleName());
    logger.error(msg);
    throw new IllegalStateException(msg);
  }
}
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.tinygroup/org.tinygroup.tinyspringtest431

public TinyMergedContextConfiguration(ContextLoader contextLoader,
                   CacheAwareContextLoaderDelegate contextLoaderDelegate,
                   MergedContextConfiguration mergedContextConfiguration,
                   MergedContextConfiguration parentConfiguration) {
  super(mergedContextConfiguration.getTestClass(),
      mergedContextConfiguration.getLocations(),
      mergedContextConfiguration.getClasses(),
      mergedContextConfiguration.getActiveProfiles(), contextLoader);
  this.mergedContextConfiguration = mergedContextConfiguration;
  this.contextLoaderDelegate = contextLoaderDelegate;
  this.parentConfiguration = parentConfiguration;
}
origin: org.springframework.boot/spring-boot-test

private boolean isEmbeddedWebEnvironment(MergedContextConfiguration config) {
  SpringBootTest annotation = AnnotatedElementUtils
      .findMergedAnnotation(config.getTestClass(), SpringBootTest.class);
  if (annotation != null && annotation.webEnvironment().isEmbedded()) {
    return true;
  }
  return false;
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-test

/**
 * Returns a {@link WebMergedContextConfiguration} if the test class in the
 * supplied {@code MergedContextConfiguration} is annotated with
 * {@link WebAppConfiguration @WebAppConfiguration} and otherwise returns
 * the supplied instance unmodified.
 */
@Override
protected MergedContextConfiguration processMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
  WebAppConfiguration webAppConfiguration =
      AnnotatedElementUtils.findMergedAnnotation(mergedConfig.getTestClass(), WebAppConfiguration.class);
  if (webAppConfiguration != null) {
    return new WebMergedContextConfiguration(mergedConfig, webAppConfiguration.value());
  }
  else {
    return mergedConfig;
  }
}
origin: org.springframework.boot/spring-boot-test

private boolean isWebEnvironmentSupported(MergedContextConfiguration mergedConfig) {
  Class<?> testClass = mergedConfig.getTestClass();
  ContextHierarchy hierarchy = AnnotationUtils.getAnnotation(testClass,
      ContextHierarchy.class);
  if (hierarchy == null || hierarchy.value().length == 0) {
    return true;
  }
  ContextConfiguration[] configurations = hierarchy.value();
  return isFromConfiguration(mergedConfig,
      configurations[configurations.length - 1]);
}
origin: org.springframework.boot/spring-boot-test

@Override
public void customizeContext(ConfigurableApplicationContext context,
    MergedContextConfiguration mergedConfig) {
  SpringBootTest annotation = AnnotatedElementUtils
      .getMergedAnnotation(mergedConfig.getTestClass(), SpringBootTest.class);
  if (annotation.webEnvironment().isEmbedded()) {
    registerWebTestClient(context);
  }
}
origin: org.springframework.boot/spring-boot-test

@Override
public void customizeContext(ConfigurableApplicationContext context,
    MergedContextConfiguration mergedContextConfiguration) {
  SpringBootTest annotation = AnnotatedElementUtils.getMergedAnnotation(
      mergedContextConfiguration.getTestClass(), SpringBootTest.class);
  if (annotation.webEnvironment().isEmbedded()) {
    registerTestRestTemplate(context);
  }
}
origin: zonkyio/embedded-database-spring-test

@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
  context.addBeanFactoryPostProcessor(new EnvironmentPostProcessor(context.getEnvironment()));
  Class<?> testClass = mergedConfig.getTestClass();
  FlywayTest[] flywayAnnotations = findFlywayTestAnnotations(testClass);
  BeanDefinitionRegistry registry = getBeanDefinitionRegistry(context);
  RootBeanDefinition registrarDefinition = new RootBeanDefinition();
  registrarDefinition.setBeanClass(PreloadableEmbeddedPostgresRegistrar.class);
  registrarDefinition.getConstructorArgumentValues()
      .addIndexedArgumentValue(0, databaseAnnotation);
  registrarDefinition.getConstructorArgumentValues()
      .addIndexedArgumentValue(1, flywayAnnotations);
  registry.registerBeanDefinition("preloadableEmbeddedPostgresRegistrar", registrarDefinition);
}
org.springframework.test.contextMergedContextConfigurationgetTestClass

Javadoc

Get the Class associated with this MergedContextConfiguration.

Popular methods of MergedContextConfiguration

  • getLocations
    Get the merged resource locations for ApplicationContextconfiguration files for the #getTestClass().
  • getActiveProfiles
    Get the merged active bean definition profiles for the #getTestClass().
  • getClasses
    Get the merged annotated classes for the #getTestClass().
  • getContextLoader
    Get the resolved ContextLoader for the #getTestClass().
  • <init>
    Create a new MergedContextConfiguration instance by copying all fields from the supplied MergedConte
  • getParent
    Get the MergedContextConfiguration for the parent application context in a context hierarchy.
  • getParentApplicationContext
    Get the parent ApplicationContext for the context defined by this MergedContextConfiguration from th
  • getContextInitializerClasses
    Get the merged ApplicationContextInitializer classes for the #getTestClass().
  • getPropertySourceProperties
    Get the merged test PropertySource properties for the #getTestClass().Properties will be loaded into
  • hasLocations
    Determine if this MergedContextConfiguration instance has path-based context resource locations.
  • getContextCustomizers
    Get the merged ContextCustomizer that will be applied when the application context is loaded.
  • getPropertySourceLocations
    Get the merged resource locations for test PropertySourcesfor the #getTestClass().
  • getContextCustomizers,
  • getPropertySourceLocations,
  • hasClasses,
  • hashCode,
  • equals,
  • nullSafeClassName,
  • processActiveProfiles,
  • processClasses,
  • processContextCustomizers

Popular in Java

  • Finding current android device location
  • getSharedPreferences (Context)
  • getSupportFragmentManager (FragmentActivity)
  • onCreateOptionsMenu (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • MessageDigest (java.security)
    Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.
  • Permission (java.security)
    Legacy security code; do not use.
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now