blob: e25aa4a41a444eba9a22666b6ba0a5f4064f2dbc [file] [log] [blame]
Simon Hunt642bc452016-05-04 19:34:45 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
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.ui.model;
18
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070019import org.onlab.packet.IpAddress;
Simon Hunt642bc452016-05-04 19:34:45 -070020import org.onosproject.cluster.ClusterService;
21import org.onosproject.cluster.ClusterServiceAdapter;
22import org.onosproject.cluster.ControllerNode;
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070023import org.onosproject.cluster.DefaultControllerNode;
Simon Hunt642bc452016-05-04 19:34:45 -070024import org.onosproject.cluster.NodeId;
25import org.onosproject.mastership.MastershipService;
26import org.onosproject.net.device.DeviceService;
27import org.onosproject.net.flow.FlowRuleService;
28import org.onosproject.net.host.HostService;
29import org.onosproject.net.intent.IntentService;
30import org.onosproject.net.link.LinkService;
31import org.onosproject.net.region.RegionService;
32import org.onosproject.ui.AbstractUiTest;
Simon Hunt4f4ffc32016-08-03 18:30:47 -070033import org.onosproject.ui.UiTopoLayoutService;
Simon Hunt642bc452016-05-04 19:34:45 -070034
35/**
36 * Base class for UI model unit tests.
37 */
38public class AbstractUiModelTest extends AbstractUiTest {
39
40 /**
41 * Returns canned results.
42 * At some future point, we may make this "programmable", so that
43 * it returns certain values based on element IDs etc.
44 */
45 protected static final ServiceBundle MOCK_SERVICES =
46 new ServiceBundle() {
47 @Override
Simon Hunt4f4ffc32016-08-03 18:30:47 -070048 public UiTopoLayoutService layout() {
49 return null;
50 }
51
52 @Override
Simon Hunt642bc452016-05-04 19:34:45 -070053 public ClusterService cluster() {
54 return MOCK_CLUSTER;
55 }
56
57 @Override
58 public MastershipService mastership() {
59 return null;
60 }
61
62 @Override
63 public RegionService region() {
64 return null;
65 }
66
67 @Override
68 public DeviceService device() {
69 return null;
70 }
71
72 @Override
73 public LinkService link() {
74 return null;
75 }
76
77 @Override
78 public HostService host() {
79 return null;
80 }
81
82 @Override
83 public IntentService intent() {
84 return null;
85 }
86
87 @Override
88 public FlowRuleService flow() {
89 return null;
90 }
91 };
92
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070093 protected static final ClusterService MOCK_CLUSTER = new MockClusterService();
Simon Hunt642bc452016-05-04 19:34:45 -070094
Thomas Vachuskab877a6f2017-04-14 11:43:30 -070095 protected static final NodeId NODE_ID = NodeId.nodeId("Node-1");
96 protected static final IpAddress NODE_IP = IpAddress.valueOf("1.2.3.4");
97
98 protected static final ControllerNode CNODE_1 =
99 new DefaultControllerNode(NODE_ID, NODE_IP);
Simon Hunt642bc452016-05-04 19:34:45 -0700100
101 private static class MockClusterService extends ClusterServiceAdapter {
Thomas Vachuskab877a6f2017-04-14 11:43:30 -0700102
103 @Override
104 public ControllerNode getNode(NodeId nodeId) {
105 return CNODE_1;
106 }
107
Simon Hunt642bc452016-05-04 19:34:45 -0700108 @Override
109 public ControllerNode.State getState(NodeId nodeId) {
110 // For now, a hardcoded state of ACTIVE (but not READY)
111 // irrespective of the node ID.
112 return ControllerNode.State.ACTIVE;
113 }
114 }
115
116}