Open Kilda Java Documentation
ValidatingConfigurationProviderTest.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.config.provider;
17 
18 import static org.junit.Assert.assertEquals;
19 
20 import com.sabre.oss.conf4j.annotation.Configuration;
21 import com.sabre.oss.conf4j.annotation.Key;
22 import com.sabre.oss.conf4j.factory.jdkproxy.JdkProxyStaticConfigurationFactory;
23 import com.sabre.oss.conf4j.source.PropertiesConfigurationSource;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 
28 import java.util.Properties;
29 import javax.validation.constraints.Min;
30 
32  static final String TEST_KEY = "test_key";
33  static final int VALID_TEST_VALUE = 100;
34  static final int INVALID_TEST_VALUE = -1;
35 
36  @Rule
37  public ExpectedException expectedException = ExpectedException.none();
38 
39  @Test
41  // given
42  Properties source = new Properties();
43  source.setProperty(TEST_KEY, String.valueOf(VALID_TEST_VALUE));
44 
46  new PropertiesConfigurationSource(source), new JdkProxyStaticConfigurationFactory());
47 
48  // when
49  TestConfig config = provider.getConfiguration(TestConfig.class);
50 
51  // then
52  assertEquals(VALID_TEST_VALUE, config.getTestProperty());
53  }
54 
55  @Test
57  // given
58  Properties source = new Properties();
59  source.setProperty(TEST_KEY, String.valueOf(INVALID_TEST_VALUE));
60 
62  new PropertiesConfigurationSource(source), new JdkProxyStaticConfigurationFactory());
63 
64  // when
66  provider.getConfiguration(TestConfig.class);
67 
68  // then ConfigurationException is thrown
69  }
70 
71  @Configuration
72  public interface TestConfig {
73  @Key(TEST_KEY)
74  @Min(1)
75  int getTestProperty();
76  }
77 }
source
Definition: nodes.py:53