Simon Hunt | 642bc45 | 2016-05-04 19:34:45 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.ui.model; |
| 18 | |
| 19 | import org.onosproject.cluster.ClusterService; |
| 20 | import org.onosproject.cluster.ClusterServiceAdapter; |
| 21 | import org.onosproject.cluster.ControllerNode; |
| 22 | import org.onosproject.cluster.NodeId; |
| 23 | import org.onosproject.mastership.MastershipService; |
| 24 | import org.onosproject.net.device.DeviceService; |
| 25 | import org.onosproject.net.flow.FlowRuleService; |
| 26 | import org.onosproject.net.host.HostService; |
| 27 | import org.onosproject.net.intent.IntentService; |
| 28 | import org.onosproject.net.link.LinkService; |
| 29 | import org.onosproject.net.region.RegionService; |
| 30 | import org.onosproject.ui.AbstractUiTest; |
| 31 | |
| 32 | /** |
| 33 | * Base class for UI model unit tests. |
| 34 | */ |
| 35 | public class AbstractUiModelTest extends AbstractUiTest { |
| 36 | |
| 37 | /** |
| 38 | * Returns canned results. |
| 39 | * At some future point, we may make this "programmable", so that |
| 40 | * it returns certain values based on element IDs etc. |
| 41 | */ |
| 42 | protected static final ServiceBundle MOCK_SERVICES = |
| 43 | new ServiceBundle() { |
| 44 | @Override |
| 45 | public ClusterService cluster() { |
| 46 | return MOCK_CLUSTER; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public MastershipService mastership() { |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public RegionService region() { |
| 56 | return null; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public DeviceService device() { |
| 61 | return null; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public LinkService link() { |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public HostService host() { |
| 71 | return null; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public IntentService intent() { |
| 76 | return null; |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public FlowRuleService flow() { |
| 81 | return null; |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | private static final ClusterService MOCK_CLUSTER = new MockClusterService(); |
| 86 | |
| 87 | |
| 88 | private static class MockClusterService extends ClusterServiceAdapter { |
| 89 | @Override |
| 90 | public ControllerNode.State getState(NodeId nodeId) { |
| 91 | // For now, a hardcoded state of ACTIVE (but not READY) |
| 92 | // irrespective of the node ID. |
| 93 | return ControllerNode.State.ACTIVE; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | } |