blob: c792b9159066ba48259ac2e382651c2a83e2429f [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;
34import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.system.rev20160505.ietfsystemmicrosemi.system.AugmentedSysSystem;
35import org.onosproject.yang.gen.v1.http.www.microsemi.com.microsemi.edge.assure.msea.system.rev20160505.ietfsystemmicrosemi.systemstate.platform.AugmentedSysPlatform;
36import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.IetfSystem;
37import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.IetfSystemOpParam;
38import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.ietfsystem.DefaultSystem;
39import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.ietfsystem.System;
40import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.ietfsystem.system.Clock;
41import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.ietfsystem.system.DefaultClock;
42import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.system.rev20140806.ietfsystem.system.clock.timezone.DefaultTimezoneName;
43import org.onosproject.yms.ymsm.YmsService;
44
45public class IetfSystemManagerTest {
46
47 IetfSystemManager sysSvc = null;
48 YmsService ymsService;
49 NetconfSession session;
50
51 @Before
52 public void setUp() throws Exception {
53 try {
54 sysSvc = new MockIetfSystemManager();
55 sysSvc.activate();
56 } catch (UncheckedIOException e) {
57 fail(e.getMessage());
58 }
59 NetconfDeviceInfo deviceInfo = new NetconfDeviceInfo("netconf", "netconf", Ip4Address.valueOf("1.2.3.4"), 830);
60 session = new MockNetconfSessionEa1000(deviceInfo);
61 }
62
63 @After
64 public void tearDown() throws Exception {
65 sysSvc.deactivate();
66 }
67
68 @Test
69 public void testGetIetfSystemSession() throws NetconfException {
70 Clock.ClockBuilder cBuilder = new DefaultClock.ClockBuilder();
71 Clock clock = cBuilder.build();
72
73 System.SystemBuilder sBuilder = new DefaultSystem.SystemBuilder();
74 System system = sBuilder.clock(clock).build();
75
76 IetfSystemOpParam.IetfSystemBuilder builder = new IetfSystemOpParam.IetfSystemBuilder();
77 IetfSystemOpParam sampleSystem = (IetfSystemOpParam) builder.system(system).build();
78
79 IetfSystem sys = sysSvc.getIetfSystem(sampleSystem, session);
80 assertNotNull(sys);
81
82 assertEquals(sys.system().clock().timezone().getClass(), DefaultTimezoneName.class);
83 DefaultTimezoneName tzName = (DefaultTimezoneName) sys.system().clock().timezone();
84 assertEquals("Etc/UTC", tzName.timezoneName().string());
85 }
86
87 @Test
88 public void testGetIetfSystemInit() throws NetconfException {
89
90 IetfSystem sys = sysSvc.getIetfSystemInit(session);
91 assertNotNull(sys);
92 assertNotNull(sys.system());
93
94 AugmentedSysSystem sysSystem = (AugmentedSysSystem) sys.system().yangAugmentedInfo(AugmentedSysSystem.class);
95
96 assertEquals("-8.4683990", sysSystem.longitude().toPlainString());
97 assertEquals("51.9036140", sysSystem.latitude().toPlainString());
98 assertEquals("4.4.0-53-generic", sys.systemState().platform().osRelease());
99
100 AugmentedSysPlatform sysSystemState =
101 (AugmentedSysPlatform) sys.systemState().platform().yangAugmentedInfo(AugmentedSysPlatform.class);
102
103 assertEquals("Eagle Simulator.", sysSystemState.deviceIdentification().serialNumber());
104 }
105
106 @Test
107 public void testSetCurrentDatetime() throws NetconfException, ParseException {
108 sysSvc.setCurrentDatetime(OffsetDateTime.now(), session);
109 //Look at MockNetconfSessionEa1000::sampleXmlRegexSetCurrentDatetime() for catching an error
110 }
111}