diff --git a/temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java b/temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java index df3e1b50a..a0079036c 100644 --- a/temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java +++ b/temporal-spring-boot-autoconfigure/src/main/java/io/temporal/spring/boot/autoconfigure/NonRootBeanPostProcessor.java @@ -71,8 +71,13 @@ public Object postProcessAfterInitialization(@Nonnull Object bean, @Nonnull Stri // optional dependencies. metricsScope = findBean("temporalMetricsScope", Scope.class); tracer = findBean(Tracer.class); - testWorkflowEnvironment = - findBean("temporalTestWorkflowEnvironment", TestWorkflowEnvironmentAdapter.class); + // Prefer resolving by type; fall back to the correctly named adapter bean + testWorkflowEnvironment = findBean(TestWorkflowEnvironmentAdapter.class); + if (testWorkflowEnvironment == null) { + testWorkflowEnvironment = + findBean( + "temporalTestWorkflowEnvironmentAdapter", TestWorkflowEnvironmentAdapter.class); + } namespaceProperties.forEach(this::injectBeanByNonRootNamespace); } } diff --git a/temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/NonRootNamespacesUseTestServerTest.java b/temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/NonRootNamespacesUseTestServerTest.java new file mode 100644 index 000000000..bdc4c0513 --- /dev/null +++ b/temporal-spring-boot-autoconfigure/src/test/java/io/temporal/spring/boot/autoconfigure/NonRootNamespacesUseTestServerTest.java @@ -0,0 +1,63 @@ +package io.temporal.spring.boot.autoconfigure; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import io.grpc.health.v1.HealthCheckResponse; +import io.temporal.serviceclient.WorkflowServiceStubs; +import io.temporal.testing.TestWorkflowEnvironment; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.Timeout; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; + +@SpringBootTest( + classes = NonRootNamespacesUseTestServerTest.Configuration.class, + properties = { + "spring.temporal.test-server.enabled=true", + "spring.temporal.connection.target=127.0.0.1:7233", + "spring.temporal.start-workers=false", + "spring.temporal.namespaces[0].namespace=pomegranate", + "spring.temporal.namespaces[0].alias=pomegranate" + }) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class NonRootNamespacesUseTestServerTest { + + @Autowired ConfigurableApplicationContext applicationContext; + + @Autowired + @Qualifier("temporalTestWorkflowEnvironment") + TestWorkflowEnvironment testWorkflowEnvironment; + + @Autowired + @Qualifier("pomegranateWorkflowServiceStubs") + WorkflowServiceStubs pomegranateWorkflowServiceStubs; + + @BeforeEach + void setUp() { + applicationContext.start(); + } + + @Test + @Timeout(10) + public void nonRootNamespaceUsesInMemoryTestServer() { + HealthCheckResponse envHealth = + testWorkflowEnvironment.getWorkflowClient().getWorkflowServiceStubs().healthCheck(); + HealthCheckResponse pomegranateHealth = pomegranateWorkflowServiceStubs.healthCheck(); + assertEquals(HealthCheckResponse.ServingStatus.SERVING, envHealth.getStatus()); + assertEquals(HealthCheckResponse.ServingStatus.SERVING, pomegranateHealth.getStatus()); + } + + @ComponentScan( + excludeFilters = + @ComponentScan.Filter( + pattern = + "io\\.temporal\\.spring\\.boot\\.autoconfigure\\.(byworkername|bytaskqueue)\\..*", + type = FilterType.REGEX)) + public static class Configuration {} +}