Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 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 | |
| 17 | package org.onosproject.ui.model; |
| 18 | |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 20 | import org.onosproject.cluster.ClusterService; |
| 21 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 22 | import org.onosproject.cluster.ControllerNode; |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 23 | import org.onosproject.cluster.DefaultControllerNode; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 24 | import org.onosproject.cluster.NodeId; |
| 25 | import org.onosproject.mastership.MastershipService; |
| 26 | import org.onosproject.net.device.DeviceService; |
| 27 | import org.onosproject.net.flow.FlowRuleService; |
| 28 | import org.onosproject.net.host.HostService; |
| 29 | import org.onosproject.net.intent.IntentService; |
| 30 | import org.onosproject.net.link.LinkService; |
| 31 | import org.onosproject.net.region.RegionService; |
| 32 | import org.onosproject.ui.AbstractUiTest; |
Simon Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 33 | import org.onosproject.ui.UiTopoLayoutService; |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Base class for UI model unit tests. |
| 37 | */ |
| 38 | public 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 Hunt | 4f4ffc3 | 2016-08-03 18:30:47 -0700 | [diff] [blame] | 48 | public UiTopoLayoutService layout() { |
| 49 | return null; |
| 50 | } |
| 51 | |
| 52 | @Override |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 53 | 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 Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 93 | protected static final ClusterService MOCK_CLUSTER = new MockClusterService(); |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 94 | |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 95 | 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 Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 100 | |
| 101 | private static class MockClusterService extends ClusterServiceAdapter { |
Thomas Vachuska | b877a6f | 2017-04-14 11:43:30 -0700 | [diff] [blame] | 102 | |
| 103 | @Override |
| 104 | public ControllerNode getNode(NodeId nodeId) { |
| 105 | return CNODE_1; |
| 106 | } |
| 107 | |
Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 108 | @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 | } |