From 132d2bcca10d9560eb7b7ff66c9001f40aed7dbd Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Tue, 8 Aug 2023 11:17:46 +0200 Subject: [PATCH 1/3] add test to make sure no StupsTokenComponent is created --- .../java/org/zalando/nakadiproducer/EndToEndTestIT.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/EndToEndTestIT.java b/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/EndToEndTestIT.java index c1b9a94..f740981 100644 --- a/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/EndToEndTestIT.java +++ b/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/EndToEndTestIT.java @@ -12,6 +12,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.test.context.ContextConfiguration; import org.zalando.nakadiproducer.eventlog.CompactionKeyExtractor; @@ -39,6 +40,9 @@ public class EndToEndTestIT extends BaseMockedExternalCommunicationIT { @Autowired private MockNakadiPublishingClient nakadiClient; + @Autowired + ApplicationContext context; + @BeforeEach @AfterEach public void clearNakadiEvents() { @@ -46,6 +50,11 @@ public void clearNakadiEvents() { nakadiClient.clearSentEvents(); } + @Test + public void noStupsTokenBeanIsSetupWithMockPublishingClient() { + assertThat(context.getBeanProvider(StupsTokenComponent.class).getIfAvailable(), is(nullValue())); + } + @Test public void dataEventsShouldBeSubmittedToNakadi() throws IOException { MockPayload payload = Fixture.mockPayload(1, CODE); From 3bbdf4d5369d0d170a691432cf6793235c140b1b Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Tue, 8 Aug 2023 11:28:10 +0200 Subject: [PATCH 2/3] Don't create StupsTokenComponent when not needed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the application already supplies a NakadiPublishingClient or NakadiClient bean, we don't need our own authentication setup. This was already meant to be skipped, but I guess we misunderstood how nested configuration classes work – they don't inherit their outer classes' conditions. --- .../zalando/nakadiproducer/NakadiProducerAutoConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java index 469c4e8..6cd12cb 100644 --- a/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java +++ b/nakadi-producer-spring-boot-starter/src/main/java/org/zalando/nakadiproducer/NakadiProducerAutoConfiguration.java @@ -65,6 +65,7 @@ public NakadiPublishingClient nakadiProducerPublishingClient(AccessTokenProvider } @ConditionalOnClass(name = "org.zalando.stups.tokens.Tokens") + @ConditionalOnMissingBean({NakadiPublishingClient.class, NakadiClient.class}) @Configuration static class StupsTokenConfiguration { @Bean(destroyMethod = "stop") From b075c49fb2a6aee4772b0d3c1b4f5d4f74619093 Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Tue, 15 Aug 2023 16:50:43 +0200 Subject: [PATCH 3/3] Don't create StupsTokenComponent in NakadiClientEncodingIT --- .../nakadiproducer/NakadiClientContentEncodingIT.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/NakadiClientContentEncodingIT.java b/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/NakadiClientContentEncodingIT.java index bacba5d..6f035fc 100644 --- a/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/NakadiClientContentEncodingIT.java +++ b/nakadi-producer-spring-boot-starter/src/test/java/org/zalando/nakadiproducer/NakadiClientContentEncodingIT.java @@ -5,6 +5,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.zalando.fahrschein.http.api.ContentEncoding; import org.zalando.fahrschein.http.api.RequestFactory; import org.zalando.nakadiproducer.config.EmbeddedDataSourceConfig; @@ -25,6 +26,11 @@ ) public class NakadiClientContentEncodingIT { + // Avoid errors in the logs from the AccessTokenRefresher. As we are not actually submitting + // to Nakadi, this will never be used. + @MockBean + private AccessTokenProvider tokenProvider; + @Autowired private RequestFactory requestFactory;