blob: 098ecddbd9eb761342634cc5ca5e3612320b1fb6 [file] [log] [blame]
Sean Condonfae8e662016-12-15 10:25:13 +00001/*
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 */
16package org.onosproject.drivers.microsemi.yang;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertNotNull;
20import static org.junit.Assert.fail;
21
22import java.io.UncheckedIOException;
23import java.text.ParseException;
24import java.time.OffsetDateTime;
25
26import org.junit.After;
27import org.junit.Before;
28import org.junit.Test;
29import org.onlab.packet.Ip4Address;
30import org.onosproject.drivers.microsemi.yang.impl.IetfSystemManager;
31import org.onosproject.netconf.NetconfDeviceInfo;
32import org.onosproject.netconf.NetconfException;
33import org.onosproject.netconf.NetconfSession;
Sean Condon06613e92017-06-09 15:14:01 +010034import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.system.AugmentedSysSystem;
35import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.system.DefaultAugmentedSysSystem;
36import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.systemstate.platform.AugmentedSysPlatform;
37import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.IetfSystem;
38import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.IetfSystemOpParam;
39import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.DefaultSystem;
40import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.System;
41import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.system.DefaultClock;
42import org.onosproject.yang.gen.v1.ietfsystem.rev20140806.ietfsystem.system.clock.timezone.DefaultTimezoneName;
43import org.onosproject.yang.gen.v1.ietfsystemmicrosemi.rev20160505.ietfsystemmicrosemi.systemstate.platform.DefaultAugmentedSysPlatform;
Sean Condonfae8e662016-12-15 10:25:13 +000044
45public class IetfSystemManagerTest {
46
47 IetfSystemManager sysSvc = null;
Sean Condonfae8e662016-12-15 10:25:13 +000048 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 Condon06613e92017-06-09 15:14:01 +010069 System system = new DefaultSystem();
70 system.clock(new DefaultClock());
Sean Condonfae8e662016-12-15 10:25:13 +000071
Sean Condon06613e92017-06-09 15:14:01 +010072 IetfSystemOpParam sampleSystem = new IetfSystemOpParam();
73 sampleSystem.system(system);
Sean Condonfae8e662016-12-15 10:25:13 +000074
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 Condon06613e92017-06-09 15:14:01 +010090 AugmentedSysSystem sysSystem = (AugmentedSysSystem) sys.system().augmentation(DefaultAugmentedSysSystem.class);
Sean Condonfae8e662016-12-15 10:25:13 +000091
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 Condon06613e92017-06-09 15:14:01 +010097 (AugmentedSysPlatform) sys.systemState().platform().augmentation(DefaultAugmentedSysPlatform.class);
Sean Condonfae8e662016-12-15 10:25:13 +000098
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}