Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 1 | /* |
Brian O'Connor | ce2a03d | 2017-08-03 19:21:03 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [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 | package org.onosproject.drivers.microsemi.yang; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.junit.Assert.assertNotNull; |
| 20 | import static org.junit.Assert.fail; |
| 21 | |
| 22 | import java.io.UncheckedIOException; |
| 23 | import java.text.ParseException; |
| 24 | import java.time.OffsetDateTime; |
| 25 | |
| 26 | import org.junit.After; |
| 27 | import org.junit.Before; |
| 28 | import org.junit.Test; |
| 29 | import org.onlab.packet.Ip4Address; |
| 30 | import org.onosproject.drivers.microsemi.yang.impl.IetfSystemManager; |
| 31 | import org.onosproject.netconf.NetconfDeviceInfo; |
| 32 | import org.onosproject.netconf.NetconfException; |
| 33 | import org.onosproject.netconf.NetconfSession; |
Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [diff] [blame^] | 34 | import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.system.AugmentedSysSystem; |
| 35 | import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.system.DefaultAugmentedSysSystem; |
| 36 | import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.systemstate.platform.AugmentedSysPlatform; |
| 37 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.IetfSystem; |
| 38 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.IetfSystemOpParam; |
| 39 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.DefaultSystem; |
| 40 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.System; |
| 41 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.system.DefaultClock; |
| 42 | import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.system.clock.timezone.DefaultTimezoneName; |
| 43 | import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.systemstate.platform.DefaultAugmentedSysPlatform; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 44 | |
| 45 | public class IetfSystemManagerTest { |
| 46 | |
| 47 | IetfSystemManager sysSvc = null; |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 48 | NetconfSession session; |
| 49 | |
| 50 | @Before |
| 51 | public void setUp() throws Exception { |
| 52 | try { |
| 53 | sysSvc = new MockIetfSystemManager(); |
| 54 | sysSvc.activate(); |
| 55 | } catch (UncheckedIOException e) { |
| 56 | fail(e.getMessage()); |
| 57 | } |
| 58 | NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo("netconf", "netconf", Ip4Address.valueOf("1.2.3.4"), 830); |
| 59 | session = new MockNetconfSessionEa1000(deviceInfo); |
| 60 | } |
| 61 | |
| 62 | @After |
| 63 | public void tearDown() throws Exception { |
| 64 | sysSvc.deactivate(); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testGetIetfSystemSession() throws NetconfException { |
Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [diff] [blame^] | 69 | System system = new DefaultSystem(); |
| 70 | system.clock(new DefaultClock()); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 71 | |
Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [diff] [blame^] | 72 | IetfSystemOpParam sampleSystem = new IetfSystemOpParam(); |
| 73 | sampleSystem.system(system); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 74 | |
| 75 | IetfSystem sys = sysSvc.getIetfSystem(sampleSystem, session); |
| 76 | assertNotNull(sys); |
| 77 | |
| 78 | assertEquals(sys.system().clock().timezone().getClass(), DefaultTimezoneName.class); |
| 79 | DefaultTimezoneName tzName = (DefaultTimezoneName) sys.system().clock().timezone(); |
| 80 | assertEquals("Etc/UTC", tzName.timezoneName().string()); |
| 81 | } |
| 82 | |
| 83 | @Test |
| 84 | public void testGetIetfSystemInit() throws NetconfException { |
| 85 | |
| 86 | IetfSystem sys = sysSvc.getIetfSystemInit(session); |
| 87 | assertNotNull(sys); |
| 88 | assertNotNull(sys.system()); |
| 89 | |
Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [diff] [blame^] | 90 | AugmentedSysSystem sysSystem = (AugmentedSysSystem) sys.system().augmentation(DefaultAugmentedSysSystem.class); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 91 | |
| 92 | assertEquals("-8.4683990", sysSystem.longitude().toPlainString()); |
| 93 | assertEquals("51.9036140", sysSystem.latitude().toPlainString()); |
| 94 | assertEquals("4.4.0-53-generic", sys.systemState().platform().osRelease()); |
| 95 | |
| 96 | AugmentedSysPlatform sysSystemState = |
Sean Condon | 16df3b1 | 2017-06-09 15:14:01 +0100 | [diff] [blame^] | 97 | (AugmentedSysPlatform) sys.systemState().platform().augmentation(DefaultAugmentedSysPlatform.class); |
Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame] | 98 | |
| 99 | assertEquals("Eagle Simulator.", sysSystemState.deviceIdentification().serialNumber()); |
| 100 | } |
| 101 | |
| 102 | @Test |
| 103 | public void testSetCurrentDatetime() throws NetconfException, ParseException { |
| 104 | sysSvc.setCurrentDatetime(OffsetDateTime.now(), session); |
| 105 | //Look at MockNetconfSessionEa1000::sampleXmlRegexSetCurrentDatetime() for catching an error |
| 106 | } |
| 107 | } |