GH-620 - Expose factory method to create a (SpringBoot)ApplicationRuntime.
We now expose ApplicationRuntime.of(ApplicationContext) to create a SpringBootApplicationRuntime as that's needed a lot in integration tests for runtime and observability components.
This commit is contained in:
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package org.springframework.modulith.runtime;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Abstraction of the application runtime environment. Primarily to keep references to Spring Boot out of the core
|
||||
* observability implementation.
|
||||
@@ -23,6 +26,19 @@ package org.springframework.modulith.runtime;
|
||||
*/
|
||||
public interface ApplicationRuntime {
|
||||
|
||||
/**
|
||||
* Creates a new {@link ApplicationRuntime} for the given {@link ApplicationContext}.
|
||||
*
|
||||
* @param context must not be {@literal null}.
|
||||
* @return will never be {@literal null}.
|
||||
*/
|
||||
public static ApplicationRuntime of(ApplicationContext context) {
|
||||
|
||||
Assert.notNull(context, "ApplicationContext must not be null!");
|
||||
|
||||
return new SpringBootApplicationRuntime(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identifier of the application.
|
||||
*
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.modulith.runtime.autoconfigure;
|
||||
package org.springframework.modulith.runtime;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -23,7 +23,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.modulith.runtime.ApplicationRuntime;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.util.Assert;
|
||||
import org.springframework.util.function.ThrowingSupplier;
|
||||
|
||||
/**
|
||||
* Auto-configuration to register a {@link SpringBootApplicationRuntime}, a {@link ApplicationModulesRuntime} and an
|
||||
* Auto-configuration to register an {@link ApplicationRuntime}, a {@link ApplicationModulesRuntime} and an
|
||||
* {@link ApplicationListener} to invoke all {@link ApplicationModuleInitializer}s as Spring Bean.
|
||||
*
|
||||
* @author Oliver Drotbohm
|
||||
@@ -55,8 +55,8 @@ class SpringModulithRuntimeAutoConfiguration {
|
||||
@Bean
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
@ConditionalOnMissingBean(ApplicationRuntime.class)
|
||||
static SpringBootApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) {
|
||||
return new SpringBootApplicationRuntime(context);
|
||||
static ApplicationRuntime modulithsApplicationRuntime(ApplicationContext context) {
|
||||
return ApplicationRuntime.of(context);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -27,7 +27,6 @@ import java.util.stream.Stream;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.modulith.core.ApplicationModules;
|
||||
import org.springframework.modulith.runtime.autoconfigure.TestSpringBootApplicationRuntime;
|
||||
import org.springframework.modulith.test.TestApplicationModules;
|
||||
|
||||
/**
|
||||
@@ -43,7 +42,7 @@ public class ApplicationModulesRuntimeIntegrationTests {
|
||||
void detectsTypeInAdditionalPackageAsApplicationType() {
|
||||
|
||||
var context = SpringApplication.run(SampleApplication.class);
|
||||
var applicationRuntime = new TestSpringBootApplicationRuntime(context);
|
||||
var applicationRuntime = ApplicationRuntime.of(context);
|
||||
|
||||
var runtime = new ApplicationModulesRuntime(() -> modules, applicationRuntime);
|
||||
|
||||
@@ -55,7 +54,7 @@ public class ApplicationModulesRuntimeIntegrationTests {
|
||||
void onlyLooksUpApplicationModulesOnce() {
|
||||
|
||||
var context = SpringApplication.run(SampleApplication.class);
|
||||
var applicationRuntime = new TestSpringBootApplicationRuntime(context);
|
||||
var applicationRuntime = ApplicationRuntime.of(context);
|
||||
var supplier = new CountingSupplier<>(() -> modules);
|
||||
|
||||
var runtime = new ApplicationModulesRuntime(supplier, applicationRuntime);
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.modulith.runtime.autoconfigure;
|
||||
package org.springframework.modulith.runtime;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.modulith.runtime.ApplicationRuntime;
|
||||
import org.springframework.modulith.runtime.SpringBootApplicationRuntime;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link SpringBootApplicationRuntime}.
|
||||
@@ -1,28 +0,0 @@
|
||||
/*
|
||||
* Copyright 2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.modulith.runtime.autoconfigure;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
*/
|
||||
public class TestSpringBootApplicationRuntime extends SpringBootApplicationRuntime {
|
||||
|
||||
public TestSpringBootApplicationRuntime(ApplicationContext context) {
|
||||
super(context);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user