|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.apache.druid.utils; |
| 21 | + |
| 22 | +import com.google.common.collect.ImmutableSet; |
| 23 | +import org.junit.Rule; |
| 24 | +import org.junit.Test; |
| 25 | +import org.junit.experimental.runners.Enclosed; |
| 26 | +import org.junit.rules.ExpectedException; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | + |
| 29 | +@RunWith(Enclosed.class) |
| 30 | +public class ConnectionUriUtilsTest |
| 31 | +{ |
| 32 | + public static class ThrowIfURLHasNotAllowedPropertiesTest |
| 33 | + { |
| 34 | + @Rule |
| 35 | + public ExpectedException expectedException = ExpectedException.none(); |
| 36 | + |
| 37 | + @Test |
| 38 | + public void testEmptyActualProperties() |
| 39 | + { |
| 40 | + ConnectionUriUtils.throwIfPropertiesAreNotAllowed( |
| 41 | + ImmutableSet.of(), |
| 42 | + ImmutableSet.of("valid_key1", "valid_key2"), |
| 43 | + ImmutableSet.of("system_key1", "system_key2") |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + public void testThrowForNonAllowedProperties() |
| 49 | + { |
| 50 | + expectedException.expect(IllegalArgumentException.class); |
| 51 | + expectedException.expectMessage("The property [invalid_key] is not in the allowed list [valid_key1, valid_key2]"); |
| 52 | + |
| 53 | + ConnectionUriUtils.throwIfPropertiesAreNotAllowed( |
| 54 | + ImmutableSet.of("valid_key1", "invalid_key"), |
| 55 | + ImmutableSet.of("system_key1", "system_key2"), |
| 56 | + ImmutableSet.of("valid_key1", "valid_key2") |
| 57 | + ); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testAllowedProperties() |
| 62 | + { |
| 63 | + ConnectionUriUtils.throwIfPropertiesAreNotAllowed( |
| 64 | + ImmutableSet.of("valid_key2"), |
| 65 | + ImmutableSet.of("system_key1", "system_key2"), |
| 66 | + ImmutableSet.of("valid_key1", "valid_key2") |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + @Test |
| 71 | + public void testAllowSystemProperties() |
| 72 | + { |
| 73 | + ConnectionUriUtils.throwIfPropertiesAreNotAllowed( |
| 74 | + ImmutableSet.of("system_key1", "valid_key2"), |
| 75 | + ImmutableSet.of("system_key1", "system_key2"), |
| 76 | + ImmutableSet.of("valid_key1", "valid_key2") |
| 77 | + ); |
| 78 | + } |
| 79 | + |
| 80 | + @Test |
| 81 | + public void testMatchSystemProperties() |
| 82 | + { |
| 83 | + ConnectionUriUtils.throwIfPropertiesAreNotAllowed( |
| 84 | + ImmutableSet.of("system_key1.1", "system_key1.5", "system_key11.11", "valid_key2"), |
| 85 | + ImmutableSet.of("system_key1", "system_key2"), |
| 86 | + ImmutableSet.of("valid_key1", "valid_key2") |
| 87 | + ); |
| 88 | + } |
| 89 | + } |
| 90 | +} |
0 commit comments