Compare commits
12 Commits
Author | SHA1 | Date |
---|---|---|
buildmaster | 1af1f635f9 | 1 year ago |
buildmaster | eb6a5dab37 | 2 years ago |
buildmaster | ac469d316d | 2 years ago |
buildmaster | b0c4246d57 | 2 years ago |
Alberto C. Ríos | 7476673326 | 2 years ago |
buildmaster | 6b0bafdd42 | 3 years ago |
buildmaster | 88a6b23248 | 3 years ago |
buildmaster | 60849189b6 | 3 years ago |
buildmaster | 2b4b39598d | 3 years ago |
spencergibb | 2283faa393 | 3 years ago |
spencergibb | 1b868d2159 | 3 years ago |
spencergibb | bec3dc0e68 | 3 years ago |
17 changed files with 364 additions and 35 deletions
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
/* |
||||
* Copyright 2013-2020 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.support; |
||||
|
||||
import java.util.Arrays; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
import org.junit.Test; |
||||
import org.junit.runner.RunWith; |
||||
|
||||
import org.springframework.beans.factory.BeanFactory; |
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.boot.SpringBootConfiguration; |
||||
import org.springframework.boot.test.context.SpringBootTest; |
||||
import org.springframework.cloud.gateway.support.ShortcutConfigurable.ShortcutType; |
||||
import org.springframework.context.annotation.Bean; |
||||
import org.springframework.core.env.ConfigurableEnvironment; |
||||
import org.springframework.expression.spel.standard.SpelExpressionParser; |
||||
import org.springframework.test.context.junit4.SpringRunner; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
@RunWith(SpringRunner.class) |
||||
@SpringBootTest(properties = "spring.cloud.gateway.restrictive-property-accessor.enabled=false") |
||||
public class ShortcutConfigurableNonRestrictiveTests { |
||||
|
||||
@Autowired |
||||
BeanFactory beanFactory; |
||||
|
||||
@Autowired |
||||
ConfigurableEnvironment env; |
||||
|
||||
private SpelExpressionParser parser; |
||||
|
||||
@Test |
||||
public void testNormalizeDefaultTypeWithSpelAndPropertyReferenceEnabled() { |
||||
parser = new SpelExpressionParser(); |
||||
ShortcutConfigurable shortcutConfigurable = new ShortcutConfigurable() { |
||||
@Override |
||||
public List<String> shortcutFieldOrder() { |
||||
return Arrays.asList("bean", "arg1"); |
||||
} |
||||
}; |
||||
Map<String, String> args = new HashMap<>(); |
||||
args.put("barproperty", "#{@bar.getInt}"); |
||||
args.put("arg1", "val1"); |
||||
Map<String, Object> map = ShortcutType.DEFAULT.normalize(args, shortcutConfigurable, parser, this.beanFactory); |
||||
assertThat(map).isNotNull().containsEntry("barproperty", 42).containsEntry("arg1", "val1"); |
||||
} |
||||
|
||||
@Test |
||||
public void testNormalizeDefaultTypeWithSpelAndMethodReferenceEnabled() { |
||||
parser = new SpelExpressionParser(); |
||||
ShortcutConfigurable shortcutConfigurable = new ShortcutConfigurable() { |
||||
@Override |
||||
public List<String> shortcutFieldOrder() { |
||||
return Arrays.asList("bean", "arg1"); |
||||
} |
||||
}; |
||||
Map<String, String> args = new HashMap<>(); |
||||
args.put("barmethod", "#{@bar.myMethod}"); |
||||
args.put("arg1", "val1"); |
||||
Map<String, Object> map = ShortcutType.DEFAULT.normalize(args, shortcutConfigurable, parser, this.beanFactory); |
||||
assertThat(map).isNotNull().containsEntry("barmethod", 42).containsEntry("arg1", "val1"); |
||||
} |
||||
|
||||
@SpringBootConfiguration |
||||
protected static class TestConfig { |
||||
|
||||
@Bean |
||||
public Integer foo() { |
||||
return 42; |
||||
} |
||||
|
||||
@Bean |
||||
public Bar bar() { |
||||
return new Bar(); |
||||
} |
||||
|
||||
} |
||||
|
||||
protected static class Bar { |
||||
|
||||
public int getInt() { |
||||
return 42; |
||||
} |
||||
|
||||
public int myMethod() { |
||||
return 42; |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue