blob: 67ffdefb4c6609064f32ad21fe9c1d1633d670b1 [file] [log] [blame]
Ray Milkeyd29bc1c2018-03-13 11:57:11 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.net.config.basics;
18
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21import org.junit.Test;
22import org.onosproject.net.config.ConfigApplyDelegate;
23
24import static org.hamcrest.MatcherAssert.assertThat;
25import static org.hamcrest.Matchers.is;
26
27public class BasicFeatureConfigTest {
28
29 class TestConfig extends BasicFeatureConfig<String> {
30 TestConfig(boolean defaultValue) {
31 super(defaultValue);
32 }
33 }
34
35 @Test
36 public void basicTest() {
37 ConfigApplyDelegate delegate = configApply -> { };
38 ObjectMapper mapper = new ObjectMapper();
39
40 TestConfig enabled = new TestConfig(true);
41 TestConfig disabled = new TestConfig(false);
42
43 enabled.init("enabled", "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
44 disabled.init("disabled", "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
45
46 assertThat(enabled.enabled(), is(true));
47 assertThat(disabled.enabled(), is(false));
48
49 disabled.enabled(true);
50 enabled.enabled(false);
51 assertThat(enabled.enabled(), is(false));
52 assertThat(disabled.enabled(), is(true));
53 }
54}