Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
Add test for SPR-11844
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Syer committed Jun 2, 2014
1 parent 59e3cf9 commit b546943
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
49 changes: 49 additions & 0 deletions SPR-11844/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.issues</groupId>
<artifactId>SPR-11844</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.0.BUILD-SNAPSHOT</version>
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<spring.version>4.0.5.RELEASE</spring.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>spring-maven-snapshot</id>
<name>Springframework Maven Snapshot Repository</name>
<url>http://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

</project>

Empty file.
75 changes: 75 additions & 0 deletions SPR-11844/src/test/java/org/springframework/issues/ReproTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.springframework.issues;

import static org.junit.Assert.assertNotNull;

import org.junit.Test;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

/**
* Unit test that reproduces an issue reported against SPR JIRA. @Test methods within need
* not pass with the green bar! Rather they should fail in such a way that demonstrates
* the reported issue.
*/
public class ReproTests {

@Test
public void ok() throws Exception {
assertNotNull(getClass().getClassLoader().loadClass(
JpaBaseConfiguration.class.getName()));
}

/**
* This one is fine because it uses an ImportSelector (the same would be true if using
* <code>@EnableAutoConfiguration</code>).
*/
@Test
public void clean() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(MainConfiguration.class);
context.refresh();
assertNotNull(context);
}

/**
* This one is fails because it uses <code>@Import</code> (and
* {@link HibernateJpaAutoConfiguration} has an unloadable nested class).
*/
@Test
public void dirty() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(ImportConfiguration.class);
context.refresh();
assertNotNull(context);
}

@Configuration
@Import({ DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class })
protected static class ImportConfiguration {
}

@Configuration
@Import(Selector.class)
protected static class MainConfiguration {
}

protected static class Selector implements ImportSelector {

@Override
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
return new String[] { DataSourceAutoConfiguration.class.getName(),
HibernateJpaAutoConfiguration.class.getName(),
PropertyPlaceholderAutoConfiguration.class.getName() };
}

}

}

0 comments on commit b546943

Please sign in to comment.