blob: 55b1eb97bee2bead9a06cc48e89fbd890408f597 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.config.subscription;
import com.yahoo.foo.*;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests reading of a config containing
* <ul>
* <li>Missing values
* <li>Default values
* </ul>
* <p/>
* for
* <p/>
* <ul>
* <li>String and
* <li>Reference
* </ul>
*
* @author <a href="mailto:musum@yahoo-inc.com">Harald Musum</a>
*/
public class DefaultConfigTest {
static final String CONFIG_ID = "raw:" +
"nondefaultstring ####-------missing--------\n" +
"defaultstring \"thedefault\"\n" +
"nondefaultreference ####-------missing--------\n" +
"defaultreference \"thedefault\"\n";
@Test(expected = IllegalArgumentException.class)
public void testFailUponUnitializedValue() {
ConfigSubscriber subscriber = new ConfigSubscriber();
subscriber.subscribe(DefaulttestConfig.class, "raw:" +
"defaultstring \"new value\"");
subscriber.nextConfig();
subscriber.close();
}
/**
* Reads a config from a string which is exactly like one returned from
* the config server given only default values for this config.
* The parsing code is the same whether the reading happens from string
* or from a server connection, so this tests that this config can be
* received correctly from the server
*/
@Test
public void testDefaultConfig() {
ConfigSubscriber subscriber = new ConfigSubscriber();
ConfigHandle<DefaulttestConfig> h = subscriber.subscribe(DefaulttestConfig.class, CONFIG_ID);
assertTrue(subscriber.nextConfig());
DefaulttestConfig config = h.getConfig();
verifyConfigValues(config);
subscriber.close();
}
private static void verifyConfigValues(DefaulttestConfig config) {
assertEquals("####-------missing--------", config.nondefaultstring());
assertEquals("thedefault", config.defaultstring());
assertEquals("####-------missing--------", config.nondefaultreference());
assertEquals("thedefault", config.defaultreference());
}
}
|