Add tests for `urlCleanerClass` and `urlCleaner` in `SentinelRestTemplate`
@@ -91,6 +91,26 @@ public class SentinelRestTemplateTests {
new AnnotationConfigApplicationContext(TestConfig10.class);
}
+ @Test(expected = BeanCreationException.class)
+ public void testUrlClnMethod() {
+ new AnnotationConfigApplicationContext(TestConfig11.class);
+ }
+
+ @Test(expected = BeanCreationException.class)
+ public void testUrlClnClass() {
+ new AnnotationConfigApplicationContext(TestConfig12.class);
+ }
+
+ @Test(expected = BeanCreationException.class)
+ public void testUrlClnMethodExists() {
+ new AnnotationConfigApplicationContext(TestConfig13.class);
+ }
+
+ @Test(expected = BeanCreationException.class)
+ public void testUrlClnReturnValue() {
+ new AnnotationConfigApplicationContext(TestConfig14.class);
+ }
+
@Configuration
public static class TestConfig1 {
@Bean
@@ -160,7 +180,7 @@ public class SentinelRestTemplateTests {
}
@Bean
- @SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException", fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException")
+ @SentinelRestTemplate(blockHandlerClass = SentinelRestTemplateTests.ExceptionUtil.class, blockHandler = "handleException", fallbackClass = SentinelRestTemplateTests.ExceptionUtil.class, fallback = "fallbackException", urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean")
RestTemplate restTemplate() {
return new RestTemplate();
}
@@ -247,6 +267,66 @@ public class SentinelRestTemplateTests {
}
}
+ @Configuration
+ public static class TestConfig11 {
+ @Bean
+ SentinelBeanPostProcessor sentinelBeanPostProcessor(
+ ApplicationContext applicationContext) {
+ return new SentinelBeanPostProcessor(applicationContext);
+ }
+
+ @Bean
+ @SentinelRestTemplate(urlCleaner = "cln")
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+ }
+
+ @Configuration
+ public static class TestConfig12 {
+ @Bean
+ SentinelBeanPostProcessor sentinelBeanPostProcessor(
+ ApplicationContext applicationContext) {
+ return new SentinelBeanPostProcessor(applicationContext);
+ }
+
+ @Bean
+ @SentinelRestTemplate(urlCleanerClass = UrlCleanUtil.class)
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+ }
+
+ @Configuration
+ public static class TestConfig13 {
+ @Bean
+ SentinelBeanPostProcessor sentinelBeanPostProcessor(
+ ApplicationContext applicationContext) {
+ return new SentinelBeanPostProcessor(applicationContext);
+ }
+
+ @Bean
+ @SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean1")
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+ }
+
+ @Configuration
+ public static class TestConfig14 {
+ @Bean
+ SentinelBeanPostProcessor sentinelBeanPostProcessor(
+ ApplicationContext applicationContext) {
+ return new SentinelBeanPostProcessor(applicationContext);
+ }
+
+ @Bean
+ @SentinelRestTemplate(urlCleanerClass = SentinelRestTemplateTests.UrlCleanUtil.class, urlCleaner = "clean2")
+ RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
+ }
+
public static class ExceptionUtil {
public static SentinelClientHttpResponse handleException(HttpRequest request,
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
@@ -271,4 +351,13 @@ public class SentinelRestTemplateTests {
}
}
+ public static class UrlCleanUtil {
+ public static String clean(String url) {
+ return url;
+ }
+
+ public static void clean2(String url) {
+ }
+ }
+
}
