Add region validation to region setting in NestedPropertyProcessor
This commit is contained in:
parent
e6402773d6
commit
4edccf42f0
2 changed files with 9 additions and 6 deletions
|
|
@ -15,6 +15,7 @@
|
||||||
package software.amazon.kinesis.multilang;
|
package software.amazon.kinesis.multilang;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.google.common.base.CaseFormat;
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
@ -73,8 +74,13 @@ public enum NestedPropertyKey {
|
||||||
* @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions">Available Regions</a>
|
* @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions">Available Regions</a>
|
||||||
*/
|
*/
|
||||||
ENDPOINT_REGION {
|
ENDPOINT_REGION {
|
||||||
void visit(final NestedPropertyProcessor processor, final String region) {
|
void visit(final NestedPropertyProcessor processor, final String regionName) {
|
||||||
processor.acceptEndpointRegion(Region.of(region));
|
List<Region> validRegions = Region.regions();
|
||||||
|
Region region = Region.of(regionName);
|
||||||
|
if (!validRegions.contains(region)) {
|
||||||
|
throw new IllegalArgumentException("Invalid region name: " + regionName);
|
||||||
|
}
|
||||||
|
processor.acceptEndpointRegion(region);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,10 +70,7 @@ public class NestedPropertyKeyTest {
|
||||||
verify(mockProcessor).acceptEndpointRegion(expectedRegion);
|
verify(mockProcessor).acceptEndpointRegion(expectedRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Region.of(), which is invoked in this test, no longer throws an IllegalArgumentException when given an invalid
|
@Test(expected = IllegalArgumentException.class)
|
||||||
// region
|
|
||||||
// We would need to implement our own region validation to maintain this test
|
|
||||||
// @Test(expected = IllegalArgumentException.class)
|
|
||||||
public void testInvalidEndpointRegion() {
|
public void testInvalidEndpointRegion() {
|
||||||
parse(mockProcessor, createKey(ENDPOINT_REGION, "snuffleupagus"));
|
parse(mockProcessor, createKey(ENDPOINT_REGION, "snuffleupagus"));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue