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 2016-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; |
| 17 | |
| 18 | import static org.junit.Assert.*; |
| 19 | |
| 20 | import java.io.BufferedReader; |
| 21 | import java.io.IOException; |
| 22 | import java.io.InputStream; |
| 23 | import java.io.InputStreamReader; |
| 24 | |
| 25 | import org.junit.Test; |
| 26 | |
| 27 | public class RpcResultParserTest { |
| 28 | |
| 29 | private static final String SAMPLE1_XML = "/systemReply-Sample1.xml"; |
| 30 | private static final String SAMPLE2_XML = "/systemReply-Sample2.xml"; |
| 31 | |
| 32 | @Test |
| 33 | public void testSerialNumber1() { |
| 34 | String serialNumberReply = loadXml(SAMPLE1_XML); |
| 35 | String serialNumber = RpcResultParser.parseXml(serialNumberReply, "serial-number"); |
| 36 | assertEquals("Eagle Simulator.", serialNumber); |
| 37 | } |
| 38 | |
| 39 | @Test |
| 40 | public void testSerialNumber2() { |
| 41 | String serialNumberReply = loadXml(SAMPLE2_XML); |
| 42 | String serialNumber = RpcResultParser.parseXml(serialNumberReply, "serial-number"); |
| 43 | assertEquals(null, serialNumber); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void testOsRelease1() { |
| 48 | String osReleaseReply = loadXml(SAMPLE1_XML); |
| 49 | String osRelease = RpcResultParser.parseXml(osReleaseReply, "os-release"); |
| 50 | assertEquals("2.6.33-arm1-MSEA1000--00326-g643be76.x.0.0.212", osRelease); |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void testOsRelease2() { |
| 55 | String osReleaseReply = loadXml(SAMPLE2_XML); |
| 56 | String osRelease = RpcResultParser.parseXml(osReleaseReply, "os-release"); |
| 57 | assertEquals(null, osRelease); |
| 58 | } |
| 59 | |
| 60 | @Test |
| 61 | public void testLongitude() { |
| 62 | String longitudeReply = loadXml(SAMPLE1_XML); |
| 63 | String longitudeStr = RpcResultParser.parseXml(longitudeReply, "longitude"); |
| 64 | assertEquals("-8.4683990", longitudeStr); |
| 65 | } |
| 66 | |
| 67 | @Test |
| 68 | public void testLatitude() { |
| 69 | String latitudeReply = loadXml(SAMPLE1_XML); |
| 70 | String latitudeStr = RpcResultParser.parseXml(latitudeReply, "latitude"); |
| 71 | assertEquals("51.9036140", latitudeStr); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | private static String loadXml(final String fileName) { |
| 76 | |
| 77 | InputStream inputStream = RpcResultParserTest.class.getResourceAsStream(fileName); |
| 78 | BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); |
| 79 | StringBuilder result = new StringBuilder(); |
| 80 | try { |
| 81 | String line; |
| 82 | while ((line = reader.readLine()) != null) { |
| 83 | result.append(line); |
| 84 | } |
| 85 | } catch (IOException e) { |
| 86 | // TODO Auto-generated catch block |
| 87 | e.printStackTrace(); |
| 88 | } |
| 89 | return result.toString(); |
| 90 | } |
| 91 | } |