Skip to content

Commit

Permalink
Merge pull request #176 from zalando-nakadi/bugfix-no-stups-token-bean
Browse files Browse the repository at this point in the history
Bugfix: no stups token bean if not needed

* adding test
* don't create the StupsTokenComponent when not needed
* don't create it in the NakadiClientEncodingIT either.
  • Loading branch information
ePaul authored Aug 22, 2023
2 parents 765194f + b075c49 commit 6046439
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,13 +40,21 @@ public class EndToEndTestIT extends BaseMockedExternalCommunicationIT {
@Autowired
private MockNakadiPublishingClient nakadiClient;

@Autowired
ApplicationContext context;

@BeforeEach
@AfterEach
public void clearNakadiEvents() {
eventTransmitter.sendEvents();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 6046439

Please sign in to comment.