Open Kilda Java Documentation
KafkaNamingForConfigurationValueProcessorTest.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.naming;
17 
18 import static java.util.Collections.emptyMap;
19 import static java.util.Collections.singletonList;
20 import static org.junit.Assert.assertEquals;
21 
23 
24 import com.google.common.collect.ImmutableMap;
25 import com.sabre.oss.conf4j.factory.jdkproxy.JdkProxyStaticConfigurationFactory;
26 import com.sabre.oss.conf4j.source.MapConfigurationSource;
27 import org.junit.Before;
28 import org.junit.Test;
29 
31  private static final String TEST_PREFIX = "test_prefix";
32  private static final String TEST_VALUE = "test_value";
33 
34  private JdkProxyStaticConfigurationFactory factory;
35 
36  @Before
38  factory = new JdkProxyStaticConfigurationFactory();
39 
40  KafkaNamingStrategy namingStrategy = new KafkaNamingStrategy(TEST_PREFIX);
41  factory.setConfigurationValueProcessors(
42  singletonList(new KafkaNamingForConfigurationValueProcessor(namingStrategy)));
43  }
44 
45  @Test
47  // given
48  MapConfigurationSource source = new MapConfigurationSource(ImmutableMap.of("kafka.topic.ctrl", TEST_VALUE));
49 
50  // when
51  KafkaTopicsConfig kafkaTopicsConfig = factory.createConfiguration(KafkaTopicsConfig.class, source);
52 
53  // then
54  assertEquals(TEST_PREFIX + "_" + TEST_VALUE, kafkaTopicsConfig.getCtrlTopic());
55  }
56 
57  @Test
59  // given
60  MapConfigurationSource source = new MapConfigurationSource(emptyMap());
61 
62  // when
63  KafkaTopicsConfig kafkaTopicsConfig = factory.createConfiguration(KafkaTopicsConfig.class, source);
64 
65  // then
66  assertEquals(TEST_PREFIX + "_kilda.ctrl", kafkaTopicsConfig.getCtrlTopic());
67  }
68 }
source
Definition: nodes.py:53