mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Add tests for urlCleanerClass
and urlCleaner
in SentinelRestTemplate
This commit is contained in:
parent
57ec776c7b
commit
578d51c7da
@ -91,6 +91,26 @@ public class SentinelRestTemplateTests {
|
|||||||
new AnnotationConfigApplicationContext(TestConfig10.class);
|
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
|
@Configuration
|
||||||
public static class TestConfig1 {
|
public static class TestConfig1 {
|
||||||
@Bean
|
@Bean
|
||||||
@ -160,7 +180,7 @@ public class SentinelRestTemplateTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@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() {
|
RestTemplate restTemplate() {
|
||||||
return new 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 class ExceptionUtil {
|
||||||
public static SentinelClientHttpResponse handleException(HttpRequest request,
|
public static SentinelClientHttpResponse handleException(HttpRequest request,
|
||||||
byte[] body, ClientHttpRequestExecution execution, BlockException ex) {
|
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user