blob: a0bc219acfbb86c28dd7d69da18280bb3a0f212f [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 AllowedEntityConfigTest {
28
29 class TestConfig extends AllowedEntityConfig<String> {
30 TestConfig() {
31 }
32 }
33
34 @Test
35 public void basicTest() {
36 ConfigApplyDelegate delegate = configApply -> { };
37 ObjectMapper mapper = new ObjectMapper();
38
39 TestConfig allowed = new TestConfig();
40 TestConfig notAllowed = new TestConfig();
41
42 allowed.init("enabled", "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
43
44 notAllowed.init("disabled", "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
45 notAllowed.isAllowed(false);
46
47 assertThat(allowed.isAllowed(), is(true));
48 assertThat(notAllowed.isAllowed(), is(false));
49
50 notAllowed.isAllowed(true);
51 allowed.isAllowed(false);
52 assertThat(allowed.isAllowed(), is(false));
53 assertThat(notAllowed.isAllowed(), is(true));
54 }
55}