blob: b5a67fbf4024b7a5e7bf159f22c081f782fababe [file] [log] [blame]
Ray Milkey85267002016-11-16 11:06:35 -08001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Ray Milkey85267002016-11-16 11:06:35 -08003 *
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 */
Avantika-Huawei9e848e82016-09-01 12:12:42 +053016package org.onosproject.pcelabelstore.util;
17
Avantika-Huawei9e848e82016-09-01 12:12:42 +053018import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.JsonNodeFactory;
21import com.fasterxml.jackson.databind.node.ObjectNode;
Ray Milkeyd1c34da2018-06-22 18:10:53 -070022import org.onosproject.net.DeviceId;
23import org.onosproject.net.config.Config;
24import org.onosproject.net.config.ConfigApplyDelegate;
25import org.onosproject.net.config.ConfigFactory;
26import org.onosproject.net.config.NetworkConfigRegistryAdapter;
27import org.onosproject.pcep.api.DeviceCapability;
28
29import java.util.HashMap;
30import java.util.Map;
Avantika-Huawei9e848e82016-09-01 12:12:42 +053031
32/* Mock test for network config registry. */
Ray Milkeyd1c34da2018-06-22 18:10:53 -070033public class MockNetConfigRegistryAdapter extends NetworkConfigRegistryAdapter {
Avantika-Huawei9e848e82016-09-01 12:12:42 +053034 private ConfigFactory cfgFactory;
35 private Map<DeviceId, DeviceCapability> classConfig = new HashMap<>();
36
37 @Override
38 public void registerConfigFactory(ConfigFactory configFactory) {
39 cfgFactory = configFactory;
40 }
41
42 @Override
43 public void unregisterConfigFactory(ConfigFactory configFactory) {
44 cfgFactory = null;
45 }
46
47 @Override
48 public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
49 if (configClass == DeviceCapability.class) {
50 DeviceCapability devCap = new DeviceCapability();
51 classConfig.put((DeviceId) subject, devCap);
52
53 JsonNode node = new ObjectNode(new MockJsonNode());
54 ObjectMapper mapper = new ObjectMapper();
55 ConfigApplyDelegate delegate = new InternalApplyDelegate();
56 devCap.init((DeviceId) subject, null, node, mapper, delegate);
57 return (C) devCap;
58 }
59
60 return null;
61 }
62
63 @Override
64 public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
65 classConfig.remove(subject);
66 }
67
68 @Override
69 public <S, C extends Config<S>> C getConfig(S subject, Class<C> configClass) {
70 if (configClass == DeviceCapability.class) {
71 return (C) classConfig.get(subject);
72 }
73 return null;
74 }
75
76 private class MockJsonNode extends JsonNodeFactory {
77 }
78
79 // Auxiliary delegate to receive notifications about changes applied to
80 // the network configuration - by the apps.
81 private class InternalApplyDelegate implements ConfigApplyDelegate {
82 @Override
83 public void onApply(Config config) {
84 //configs.put(config.subject(), config.node());
85 }
86 }
87
Avantika-Huawei9e848e82016-09-01 12:12:42 +053088}