Skip to content

Commit

Permalink
test(codegen): add test to verify getting the intended bean with qual…
Browse files Browse the repository at this point in the history
…ifier name. (#1418)

This is a followup on #1355, the additional test verifies in case of multiple bean of type `TransportChannelProvider` the one with correct qualifier name is used. 
related fix in generator: googleapis/sdk-platform-java#1207
  • Loading branch information
zhumin8 authored Jan 11, 2023
1 parent 33415df commit c2b125e
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class LanguageAutoConfigurationTests {
private static final String SERVICE_CREDENTIAL_CLIENT_ID = "45678";
private static final String TOP_LEVEL_CREDENTIAL_CLIENT_ID = "12345";
private static final String SERVICE_OVERRIDE_CLIENT_ID = "56789";
private static final String TRANSPORT_CHANNEL_PROVIDER_QUALIFIER_NAME = "defaultLanguageServiceTransportChannelProvider";

@Mock private TransportChannel mockTransportChannel;
@Mock private ApiCallContext mockApiCallContext;
Expand Down Expand Up @@ -103,6 +104,30 @@ void testCredentials_fromTopLevelIfNoServiceProperties() {
});
}

@Test
void testShouldGetTransportChannelProviderFromBeanWithQualifierName() throws IOException {
this.contextRunner
.withBean(
"anotherTransportChannelProvider",
TransportChannelProvider.class,
() -> mockTransportChannelProvider)
.run(
ctx -> {
assertThat(ctx.getBeanNamesForType(
TransportChannelProvider.class)).containsExactlyInAnyOrder(
"anotherTransportChannelProvider",
TRANSPORT_CHANNEL_PROVIDER_QUALIFIER_NAME);
LanguageServiceClient client = ctx.getBean(LanguageServiceClient.class);
TransportChannelProvider transportChannelProviderBean =
(TransportChannelProvider) ctx.getBean(TRANSPORT_CHANNEL_PROVIDER_QUALIFIER_NAME);
TransportChannelProvider transportChannelProvider =
client.getSettings().getTransportChannelProvider();
assertThat(transportChannelProvider).isSameAs(transportChannelProviderBean);
assertThat(transportChannelProvider).isNotSameAs(mockTransportChannelProvider);
});
}


@Test
void testShouldUseDefaultTransportChannelProvider() {
this.contextRunner.run(
Expand Down Expand Up @@ -177,7 +202,7 @@ void testCustomTransportChannelProviderUsedWhenProvided() throws IOException {

contextRunner
.withBean(
"defaultLanguageServiceTransportChannelProvider",
TRANSPORT_CHANNEL_PROVIDER_QUALIFIER_NAME,
TransportChannelProvider.class,
() -> mockTransportChannelProvider)
.run(
Expand Down

0 comments on commit c2b125e

Please sign in to comment.