|
1 | 1 | package com.playtika.testcontainer.pubsub; |
2 | 2 |
|
| 3 | +import com.google.api.gax.core.CredentialsProvider; |
| 4 | +import com.google.api.gax.core.FixedCredentialsProvider; |
| 5 | +import com.google.api.gax.grpc.GrpcTransportChannel; |
| 6 | +import com.google.api.gax.rpc.FixedTransportChannelProvider; |
| 7 | +import com.google.api.gax.rpc.TransportChannelProvider; |
| 8 | +import com.google.cloud.NoCredentials; |
3 | 9 | import com.google.cloud.spring.pubsub.core.PubSubTemplate; |
4 | 10 | import com.google.cloud.spring.pubsub.support.AcknowledgeablePubsubMessage; |
5 | 11 | import com.google.pubsub.v1.DeadLetterPolicy; |
6 | 12 | import com.google.pubsub.v1.ProjectSubscriptionName; |
7 | 13 | import com.google.pubsub.v1.Subscription; |
8 | 14 | import com.google.pubsub.v1.TopicName; |
| 15 | +import io.grpc.ManagedChannel; |
| 16 | +import io.grpc.ManagedChannelBuilder; |
9 | 17 | import lombok.extern.slf4j.Slf4j; |
10 | 18 | import org.junit.jupiter.api.Test; |
11 | 19 | import org.springframework.beans.factory.BeanFactoryUtils; |
12 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | +import org.springframework.beans.factory.annotation.Qualifier; |
13 | 22 | import org.springframework.beans.factory.annotation.Value; |
14 | 23 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
15 | 24 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; |
| 25 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
16 | 26 | import org.springframework.boot.test.context.SpringBootTest; |
| 27 | +import org.springframework.context.annotation.Bean; |
17 | 28 | import org.springframework.context.annotation.Configuration; |
| 29 | +import org.springframework.context.annotation.Primary; |
18 | 30 | import org.springframework.core.env.ConfigurableEnvironment; |
19 | 31 | import org.springframework.test.context.ActiveProfiles; |
20 | 32 | import org.testcontainers.containers.GenericContainer; |
@@ -48,6 +60,25 @@ class EmbeddedPubsubBootstrapConfigurationTest { |
48 | 60 | @EnableAutoConfiguration |
49 | 61 | @Configuration |
50 | 62 | static class TestConfiguration { |
| 63 | + |
| 64 | + @Bean |
| 65 | + @Primary |
| 66 | + @ConditionalOnProperty(name = "embedded.google.pubsub.enabled", matchIfMissing = true) |
| 67 | + public TransportChannelProvider pubsubTransportChannelProvider(@Qualifier(BEAN_NAME_EMBEDDED_GOOGLE_PUBSUB) GenericContainer<?> container, |
| 68 | + PubsubProperties properties) { |
| 69 | + String host = container.getHost(); |
| 70 | + Integer port = container.getMappedPort(properties.getPort()); |
| 71 | + ManagedChannel channel = ManagedChannelBuilder.forAddress(host, port) |
| 72 | + .usePlaintext() |
| 73 | + .build(); |
| 74 | + return FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); |
| 75 | + } |
| 76 | + |
| 77 | + @Bean |
| 78 | + @Primary |
| 79 | + public CredentialsProvider googleCredentials() { |
| 80 | + return FixedCredentialsProvider.create(NoCredentials.getInstance()); |
| 81 | + } |
51 | 82 | } |
52 | 83 |
|
53 | 84 | @Test |
|
0 commit comments