Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | package org.onosproject.drivers.microsemi; |
| 17 | |
| 18 | import java.util.HashMap; |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.onosproject.core.CoreService; |
| 22 | import org.onosproject.drivers.microsemi.yang.MockMseaSaFilteringManager; |
| 23 | import org.onosproject.drivers.microsemi.yang.MockMseaUniEvcServiceManager; |
| 24 | import org.onosproject.drivers.microsemi.yang.MockNetconfSessionEa1000; |
| 25 | import org.onosproject.drivers.microsemi.yang.MseaSaFilteringNetconfService; |
| 26 | import org.onosproject.drivers.microsemi.yang.MseaUniEvcServiceNetconfService; |
| 27 | import org.onosproject.drivers.netconf.MockCoreService; |
| 28 | import org.onosproject.drivers.netconf.MockNetconfController; |
| 29 | import org.onosproject.drivers.netconf.MockNetconfDevice; |
| 30 | import org.onosproject.net.DeviceId; |
| 31 | import org.onosproject.net.driver.Behaviour; |
| 32 | import org.onosproject.net.driver.DefaultDriver; |
| 33 | import org.onosproject.net.driver.DefaultDriverData; |
| 34 | import org.onosproject.net.driver.Driver; |
| 35 | import org.onosproject.net.driver.DriverData; |
| 36 | import org.onosproject.net.driver.DriverHandler; |
| 37 | import org.onosproject.net.flow.FlowRuleProgrammable; |
| 38 | import org.onosproject.netconf.NetconfController; |
| 39 | import org.onosproject.netconf.NetconfException; |
| 40 | |
| 41 | /** |
| 42 | * A Mock implementation of the DriverHandler to facilitate unit tests. |
| 43 | * |
| 44 | * This brings in the implementations of MockMseaSaFilteringManager, MockMseaUniEvcServiceManager, |
| 45 | * MockCoreService, MockNetconfDevice and MockNetconfSessionEa1000 |
| 46 | */ |
| 47 | public class MockEa1000DriverHandler implements DriverHandler { |
| 48 | |
| 49 | private static final String MICROSEMI_DRIVERS = "com.microsemi.drivers"; |
| 50 | |
| 51 | private DriverData mockDriverData; |
| 52 | |
| 53 | private NetconfController ncc; |
| 54 | private MockMseaSaFilteringManager mseaSaFilteringService; |
| 55 | private MockMseaUniEvcServiceManager mseaUniEvcService; |
| 56 | private CoreService coreService; |
| 57 | |
| 58 | public MockEa1000DriverHandler() throws NetconfException { |
| 59 | Map<Class<? extends Behaviour>, Class<? extends Behaviour>> behaviours = |
| 60 | new HashMap<Class<? extends Behaviour>, Class<? extends Behaviour>>(); |
| 61 | behaviours.put(FlowRuleProgrammable.class, FlowRuleProgrammable.class); |
| 62 | |
| 63 | Map<String, String> properties = new HashMap<String, String>(); |
| 64 | |
| 65 | Driver mockDriver = |
| 66 | new DefaultDriver("mockDriver", null, "ONOSProject", "1.0.0", "1.0.0", behaviours, properties); |
| 67 | DeviceId mockDeviceId = DeviceId.deviceId("netconf:1.2.3.4:830"); |
| 68 | mockDriverData = new DefaultDriverData(mockDriver, mockDeviceId); |
| 69 | |
| 70 | |
| 71 | ncc = new MockNetconfController(); |
| 72 | MockNetconfDevice device = (MockNetconfDevice) ncc.connectDevice(mockDeviceId); |
| 73 | device.setNcSessionImpl(MockNetconfSessionEa1000.class); |
| 74 | |
| 75 | mseaSaFilteringService = new MockMseaSaFilteringManager(); |
| 76 | mseaSaFilteringService.activate(); |
| 77 | |
| 78 | mseaUniEvcService = new MockMseaUniEvcServiceManager(); |
| 79 | mseaUniEvcService.activate(); |
| 80 | |
| 81 | coreService = new MockCoreService(); |
| 82 | coreService.registerApplication(MICROSEMI_DRIVERS); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public Driver driver() { |
| 87 | return mockDriverData.driver(); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public DriverData data() { |
| 92 | return mockDriverData; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public <T extends Behaviour> T behaviour(Class<T> behaviourClass) { |
| 97 | // TODO Auto-generated method stub |
| 98 | return null; |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public <T> T get(Class<T> serviceClass) { |
| 103 | if (serviceClass.equals(NetconfController.class)) { |
| 104 | return (T) ncc; |
| 105 | |
| 106 | } else if (serviceClass.equals(MseaSaFilteringNetconfService.class)) { |
| 107 | return (T) mseaSaFilteringService; |
| 108 | |
| 109 | } else if (serviceClass.equals(MseaUniEvcServiceNetconfService.class)) { |
| 110 | return (T) mseaUniEvcService; |
| 111 | |
| 112 | } else if (serviceClass.equals(CoreService.class)) { |
| 113 | return (T) coreService; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | return null; |
| 118 | } |
| 119 | |
| 120 | } |