Merge branch 'gh_2314'

This commit is contained in:
spencergibb
2021-09-17 16:34:06 -04:00
4 changed files with 86 additions and 30 deletions

View File

@@ -18,8 +18,6 @@ package org.springframework.cloud.gateway.config;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
@@ -113,26 +111,4 @@ public class GatewayRedisAutoConfigurationTests {
}
/**
* @author Dennis Menge
*/
@Nested
@SpringBootTest(classes = GatewayRedisAutoConfigurationTests.Config.class,
properties = "spring.cloud.gateway.redis-route-definition-repository.enabled=true")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class RedisRouteDefinitionRepositoryEnabledByProperty {
@Container
public GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
@Autowired(required = false)
private RedisRouteDefinitionRepository redisRouteDefinitionRepository;
@Test
public void redisRouteDefinitionRepository() {
assertThat(redisRouteDefinitionRepository).isNotNull();
}
}
}

View File

@@ -0,0 +1,62 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.gateway.config;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.gateway.route.RedisRouteDefinitionRepository;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(classes = GatewayRedisAutoConfigurationTests.Config.class,
properties = "spring.cloud.gateway.redis-route-definition-repository.enabled=true")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@Testcontainers
public class GatewayRedisRouteDefinitionRepositoryEnabledByPropertyTests {
@Container
public static GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
@Autowired(required = false)
private RedisRouteDefinitionRepository redisRouteDefinitionRepository;
@BeforeAll
public static void startRedisContainer() {
redis.start();
}
@DynamicPropertySource
static void containerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
@Test
public void redisRouteDefinitionRepository() {
assertThat(redisRouteDefinitionRepository).isNotNull();
}
}

View File

@@ -34,6 +34,8 @@ import org.springframework.cloud.gateway.filter.ratelimit.RateLimiter.Response;
import org.springframework.cloud.gateway.test.BaseWebClientTests;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
@@ -55,11 +57,17 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
public class RedisRateLimiterTests extends BaseWebClientTests {
@Container
public GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
public static GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
@Autowired
private RedisRateLimiter rateLimiter;
@DynamicPropertySource
static void containerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
@BeforeEach
public void setUp() {
assumeThat("Ignore on Circle", System.getenv("CIRCLECI"), is(nullValue()));

View File

@@ -22,7 +22,7 @@ import java.util.List;
import java.util.function.Predicate;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
@@ -41,6 +41,8 @@ import org.springframework.cloud.gateway.handler.predicate.PredicateDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.web.server.ServerWebExchange;
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,15 +57,24 @@ import static org.assertj.core.api.Assertions.assertThat;
public class RedisRouteDefinitionRepositoryTests {
@Container
public GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
public static GenericContainer redis = new GenericContainer<>("redis:5.0.9-alpine").withExposedPorts(6379);
@Autowired
private RedisRouteDefinitionRepository redisRouteDefinitionRepository;
@Disabled
@BeforeAll
public static void startRedisContainer() {
redis.start();
}
@DynamicPropertySource
static void containerProperties(DynamicPropertyRegistry registry) {
registry.add("spring.redis.host", redis::getContainerIpAddress);
registry.add("spring.redis.port", redis::getFirstMappedPort);
}
@Test
public void testAddRouteToRedis() {
RouteDefinition testRouteDefinition = defaultTestRoute();
redisRouteDefinitionRepository.save(Mono.just(testRouteDefinition)).block();
@@ -75,7 +86,6 @@ public class RedisRouteDefinitionRepositoryTests {
assertThat(routeDefinitions.get(0)).isEqualTo(testRouteDefinition);
}
@Disabled
@Test
public void testRemoveRouteFromRedis() {