Skip to content

Commit 3027d20

Browse files
authored
Merge pull request #147 from mercyblitz/dev-1.x
Update README with latest version numbers and compatibility table
2 parents 0db762e + 85688dc commit 3027d20

15 files changed

Lines changed: 300 additions & 200 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ Choose the version that matches your Spring Boot generation:
110110

111111
| Branch | Spring Boot Compatibility | Latest Version |
112112
|--------|------------------------------|----------------|
113-
| `main` | 3.0.x – 3.5.x, 4.0.x - 4.1.x | `0.2.30` |
114-
| `1.x` | 2.0.x – 2.7.x | `0.1.30` |
113+
| `main` | 3.0.x – 3.5.x, 4.0.x - 4.1.x | `0.2.31` |
114+
| `1.x` | 2.0.x – 2.7.x | `0.1.31` |
115115

116116
### Add Module Dependencies
117117

microsphere-spring-boot-actuator/pom.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@
2020

2121
<dependencies>
2222

23-
<!-- Microsphere Dependencies -->
23+
<!-- Microsphere Annotation Processor -->
24+
<dependency>
25+
<groupId>io.github.microsphere-projects</groupId>
26+
<artifactId>microsphere-annotation-processor</artifactId>
27+
<optional>true</optional>
28+
</dependency>
29+
30+
<!-- Microsphere Spring Boot Core -->
2431
<dependency>
2532
<groupId>io.github.microsphere-projects</groupId>
2633
<artifactId>microsphere-spring-boot-core</artifactId>
@@ -58,6 +65,12 @@
5865
<optional>true</optional>
5966
</dependency>
6067

68+
<dependency>
69+
<groupId>org.springframework.boot</groupId>
70+
<artifactId>spring-boot-autoconfigure-processor</artifactId>
71+
<optional>true</optional>
72+
</dependency>
73+
6174
<!-- Testing -->
6275
<dependency>
6376
<groupId>org.junit.jupiter</groupId>

microsphere-spring-boot-actuator/src/main/java/io/microsphere/spring/boot/actuate/autoconfigure/ActuatorEndpointsAutoConfiguration.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
2929
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
3030
import org.springframework.boot.actuate.endpoint.web.WebEndpointsSupplier;
31-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3231
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
3332
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
3433
import org.springframework.context.annotation.Bean;

microsphere-spring-boot-core/pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<optional>true</optional>
2727
</dependency>
2828

29-
<!-- Microsphere Java -->
29+
<!-- Microsphere Java Core -->
3030
<dependency>
3131
<groupId>io.github.microsphere-projects</groupId>
3232
<artifactId>microsphere-java-core</artifactId>
@@ -51,6 +51,12 @@
5151
<optional>true</optional>
5252
</dependency>
5353

54+
<dependency>
55+
<groupId>org.springframework.boot</groupId>
56+
<artifactId>spring-boot-autoconfigure-processor</artifactId>
57+
<optional>true</optional>
58+
</dependency>
59+
5460
<!-- Testing Dependencies -->
5561
<dependency>
5662
<groupId>org.junit.jupiter</groupId>

microsphere-spring-boot-test/pom.xml

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,64 +26,57 @@
2626
<optional>true</optional>
2727
</dependency>
2828

29-
<!-- Microsphere Spring -->
30-
<dependency>
31-
<groupId>io.github.microsphere-projects</groupId>
32-
<artifactId>microsphere-spring-context</artifactId>
33-
</dependency>
34-
35-
<!-- Microsphere Spring Test -->
29+
<!-- JUnit -->
3630
<dependency>
37-
<groupId>io.github.microsphere-projects</groupId>
38-
<artifactId>microsphere-spring-test</artifactId>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter</artifactId>
33+
<optional>true</optional>
3934
</dependency>
4035

41-
<!-- Spring Boot Web -->
36+
<!-- Spring Boot Configuration Processor -->
4237
<dependency>
4338
<groupId>org.springframework.boot</groupId>
44-
<artifactId>spring-boot-starter-web</artifactId>
39+
<artifactId>spring-boot-configuration-processor</artifactId>
4540
<optional>true</optional>
4641
</dependency>
4742

48-
<!-- Spring Boot WebFlux -->
43+
<!-- Spring Boot Autoconfigure Processor -->
4944
<dependency>
5045
<groupId>org.springframework.boot</groupId>
51-
<artifactId>spring-boot-starter-webflux</artifactId>
46+
<artifactId>spring-boot-autoconfigure-processor</artifactId>
5247
<optional>true</optional>
5348
</dependency>
5449

55-
<!-- Spring Boot Dependencies -->
50+
<!-- Spring Boot Test -->
5651
<dependency>
5752
<groupId>org.springframework.boot</groupId>
5853
<artifactId>spring-boot-starter-test</artifactId>
5954
<optional>true</optional>
6055
</dependency>
6156

62-
<!-- JUnit -->
57+
<!-- Microsphere Spring -->
6358
<dependency>
64-
<groupId>org.junit.jupiter</groupId>
65-
<artifactId>junit-jupiter</artifactId>
66-
<optional>true</optional>
59+
<groupId>io.github.microsphere-projects</groupId>
60+
<artifactId>microsphere-spring-context</artifactId>
6761
</dependency>
6862

69-
<!-- Mockito -->
63+
<!-- Microsphere Spring Test -->
7064
<dependency>
71-
<groupId>org.mockito</groupId>
72-
<artifactId>mockito-core</artifactId>
73-
<optional>true</optional>
65+
<groupId>io.github.microsphere-projects</groupId>
66+
<artifactId>microsphere-spring-test</artifactId>
7467
</dependency>
7568

76-
<!-- JSON Assert -->
69+
<!-- Spring Boot Web -->
7770
<dependency>
78-
<groupId>org.skyscreamer</groupId>
79-
<artifactId>jsonassert</artifactId>
71+
<groupId>org.springframework.boot</groupId>
72+
<artifactId>spring-boot-starter-web</artifactId>
8073
<optional>true</optional>
8174
</dependency>
8275

83-
<!-- hamcrest -->
76+
<!-- Spring Boot WebFlux -->
8477
<dependency>
85-
<groupId>org.hamcrest</groupId>
86-
<artifactId>hamcrest</artifactId>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-starter-webflux</artifactId>
8780
<optional>true</optional>
8881
</dependency>
8982

microsphere-spring-boot-test/src/main/java/io/microsphere/spring/boot/test/AbstractAutoConfigurationTest.java

Lines changed: 99 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,37 @@
2020
import io.microsphere.annotation.Nonnull;
2121
import io.microsphere.spring.core.annotation.GenericAnnotationAttributes;
2222
import org.junit.jupiter.api.Test;
23+
import org.springframework.boot.test.context.FilteredClassLoader;
2324
import org.springframework.boot.test.context.SpringBootTest;
25+
import org.springframework.boot.test.context.assertj.ApplicationContextAssertProvider;
26+
import org.springframework.boot.test.context.runner.AbstractApplicationContextRunner;
27+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
28+
import org.springframework.context.ConfigurableApplicationContext;
29+
import org.springframework.core.ResolvableType;
2430

2531
import java.util.Set;
2632

2733
import static io.microsphere.collection.SetUtils.newLinkedHashSet;
34+
import static io.microsphere.text.FormatUtils.format;
2835
import static io.microsphere.util.ArrayUtils.EMPTY_CLASS_ARRAY;
36+
import static io.microsphere.util.ClassUtils.newInstance;
37+
import static org.assertj.core.api.Assertions.assertThat;
38+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
2939
import static org.junit.jupiter.api.Assertions.assertNotNull;
40+
import static org.springframework.boot.autoconfigure.AutoConfigurations.of;
3041
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
3142
import static org.springframework.core.ResolvableType.forClass;
3243

3344
/**
34-
* Abstract class for auto-configuration class tests
45+
* Abstract class for auto-configuration class tests based on {@link AbstractApplicationContextRunner}
3546
*
3647
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
48+
* @see AbstractApplicationContextRunner
3749
* @see AutoConfigurationTest
50+
* @see WebAutoConfigurationTest
3851
* @since 1.0.0
3952
*/
40-
public abstract class AbstractAutoConfigurationTest<A> {
53+
public abstract class AbstractAutoConfigurationTest<A, R extends AbstractApplicationContextRunner> {
4154

4255
/**
4356
* The {@link Class class} of {@link SpringBootTest}
@@ -55,30 +68,72 @@ public abstract class AbstractAutoConfigurationTest<A> {
5568
*/
5669
protected final boolean isWebApplication;
5770

71+
protected final ResolvableType abstractAutoConfigurationTestType;
72+
5873
/**
5974
* The {@link Class class} of auto-configuration
6075
*/
6176
@Nonnull
6277
protected Class<A> autoConfigurationClass;
6378

79+
/**
80+
* The {@link Class class} of {@link AbstractApplicationContextRunner}
81+
*/
82+
@Nonnull
83+
protected Class<R> runnerClass;
84+
85+
@Nonnull
86+
protected final R runner;
87+
6488
protected AbstractAutoConfigurationTest() {
6589
Class<?> type = getClass();
6690
SpringBootTest springBootTest = type.getAnnotation(SPRING_BOOT_TEST_CLASS);
6791
assertNotNull(springBootTest, "The @SpringBootTest must not be annotated on " + type);
6892
this.springBootTestAttributes = GenericAnnotationAttributes.of(springBootTest);
6993
this.isWebApplication = !NONE.equals(springBootTestAttributes.get("webEnvironment"));
70-
this.autoConfigurationClass = (Class<A>) forClass(getClass())
71-
.as(AbstractAutoConfigurationTest.class).resolveGeneric(0);
94+
this.abstractAutoConfigurationTestType = forClass(getClass()).as(AbstractAutoConfigurationTest.class);
95+
this.autoConfigurationClass = (Class<A>) abstractAutoConfigurationTestType.resolveGeneric(0);
96+
this.runnerClass = (Class<R>) abstractAutoConfigurationTestType.resolveGeneric(1);
97+
this.runner = newRunner();
98+
if (!isWebApplication) {
99+
assertInstanceOf(ApplicationContextRunner.class, this.runner,
100+
format("The runner class[{}] must be ApplicationContextRunner when the auto-configuration test is not a web application", this.runner.getClass().getName()));
101+
}
102+
}
103+
104+
protected R newRunner() {
105+
R runner = newInstance(runnerClass);
106+
return initRunner(runner);
107+
}
108+
109+
protected R initRunner(R runner) {
110+
String[] propertyValues = getPropertyValues();
111+
Class<?>[] classes = getClasses();
112+
return (R) runner.withPropertyValues(propertyValues)
113+
.withConfiguration(of(this.autoConfigurationClass))
114+
.withConfiguration(of(classes));
72115
}
73116

74117
@Test
75-
protected abstract void testAutoConfiguredClasses();
118+
protected void testAutoConfiguredClasses() {
119+
for (Class<?> autoConfiguredClass : getAutoConfiguredClasses()) {
120+
assertAutoConfiguredClass(autoConfiguredClass);
121+
}
122+
}
76123

77124
@Test
78-
protected abstract void testOnGlobalDisabledProperty();
125+
protected void testOnGlobalDisabledProperty() {
126+
for (String propertyValue : getGlobalDisabledPropertyValues()) {
127+
assertDisabledProperty(propertyValue, getAutoConfiguredClasses());
128+
}
129+
}
79130

80131
@Test
81-
protected abstract void testOnGlobalMissingClass();
132+
protected void testOnGlobalMissingClass() {
133+
for (Class<?> missingClass : getGlobalMissingClasses()) {
134+
assertFilteredClass(missingClass.getName(), getAutoConfiguredClasses());
135+
}
136+
}
82137

83138
@Nonnull
84139
protected final String[] getPropertyValues() {
@@ -131,4 +186,41 @@ protected final Class<?>[] getClasses() {
131186
* @param globalMissingClasses the global missing classes
132187
*/
133188
protected abstract void configureGlobalMissingClasses(Set<Class<?>> globalMissingClasses);
189+
190+
protected void assertAutoConfiguredClass(Class<?> autoConfiguredClass) {
191+
assertAutoConfiguredClass(this.runner, autoConfiguredClass);
192+
}
193+
194+
protected void assertDisabledProperty(String propertyValue, Class<?>... beanClasses) {
195+
assertDisabledProperty(this.runner, propertyValue, beanClasses);
196+
}
197+
198+
protected void assertFilteredClass(String filteredClass, Class<?>... beanClasses) {
199+
assertFilteredClass(this.runner, filteredClass, beanClasses);
200+
}
201+
202+
public static <R extends AbstractApplicationContextRunner<R, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>>
203+
void assertAutoConfiguredClass(R runner, Class<?> autoConfiguredClass) {
204+
runner.run(context -> {
205+
assertThat(context).hasSingleBean(autoConfiguredClass);
206+
});
207+
}
208+
209+
public static <R extends AbstractApplicationContextRunner<R, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>>
210+
void assertDisabledProperty(R runner, String propertyValue, Class<?>... beanClasses) {
211+
runner.withPropertyValues(propertyValue).run(context -> {
212+
for (Class<?> beanClass : beanClasses) {
213+
assertThat(context).doesNotHaveBean(beanClass);
214+
}
215+
});
216+
}
217+
218+
public static <R extends AbstractApplicationContextRunner<R, C, A>, C extends ConfigurableApplicationContext, A extends ApplicationContextAssertProvider<C>>
219+
void assertFilteredClass(R runner, String filteredClass, Class<?>... beanClasses) {
220+
runner.withClassLoader(new FilteredClassLoader(filteredClass)).run(context -> {
221+
for (Class<?> beanClass : beanClasses) {
222+
assertThat(context).doesNotHaveBean(beanClass);
223+
}
224+
});
225+
}
134226
}

0 commit comments

Comments
 (0)