Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [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 | |
| 17 | package org.onosproject.drivers.utilities; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onlab.packet.IpAddress; |
| 21 | import org.onosproject.net.behaviour.ControllerInfo; |
| 22 | |
| 23 | import java.io.IOException; |
| 24 | import java.io.InputStream; |
| 25 | import java.util.ArrayList; |
| 26 | import java.util.Arrays; |
| 27 | import java.util.List; |
| 28 | |
| 29 | import static org.junit.Assert.assertTrue; |
| 30 | |
| 31 | /** |
| 32 | * Test the XML document Parsing for netconf configuration. |
| 33 | */ |
| 34 | public class XmlConfigParserTest { |
| 35 | |
| 36 | |
| 37 | @Test |
| 38 | public void basics() throws IOException { |
| 39 | InputStream stream = getClass().getResourceAsStream("/testConfig.xml"); |
| 40 | List<ControllerInfo> controllers = XmlConfigParser |
| 41 | .parseStreamControllers(XmlConfigParser.loadXml(stream)); |
| 42 | assertTrue(controllers.get(0).equals(new ControllerInfo( |
| 43 | IpAddress.valueOf("10.128.12.1"), 6653, "tcp"))); |
| 44 | assertTrue(controllers.get(1).equals(new ControllerInfo( |
| 45 | IpAddress.valueOf("10.128.12.2"), 6654, "tcp"))); |
| 46 | |
| 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void switchId() { |
| 51 | InputStream stream = getClass().getResourceAsStream("/testConfig.xml"); |
| 52 | String switchId = XmlConfigParser.parseSwitchId(XmlConfigParser |
| 53 | .loadXml(stream)); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 54 | assertTrue("ofc-bridge".equals(switchId)); |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void capableSwitchId() { |
| 59 | InputStream stream = getClass().getResourceAsStream("/testConfig.xml"); |
| 60 | String capableSwitchId = XmlConfigParser |
| 61 | .parseCapableSwitchId(XmlConfigParser.loadXml(stream)); |
Jon Hall | a3fcf67 | 2017-03-28 16:53:22 -0700 | [diff] [blame] | 62 | assertTrue("openvswitch".equals(capableSwitchId)); |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void controllersConfig() { |
| 67 | InputStream streamOrig = getClass().getResourceAsStream("/testConfig.xml"); |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 68 | InputStream streamCfg = XmlConfigParser.class.getResourceAsStream("/controllers.xml"); |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 69 | String config = XmlConfigParser |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 70 | .createControllersConfig(XmlConfigParser.loadXml(streamCfg), |
Andrea Campanella | 238d96e | 2016-01-20 11:52:02 -0800 | [diff] [blame] | 71 | XmlConfigParser.loadXml(streamOrig), |
| 72 | "running", "merge", "create", |
| 73 | new ArrayList<>( |
| 74 | Arrays.asList( |
| 75 | new ControllerInfo( |
| 76 | IpAddress.valueOf( |
| 77 | "192.168.1.1"), |
| 78 | 5000, "tcp")))); |
| 79 | assertTrue(config.contains("192.168.1.1")); |
| 80 | assertTrue(config.contains("tcp")); |
| 81 | assertTrue(config.contains("5000")); |
| 82 | |
| 83 | } |
Jonathan Hart | 51539b8 | 2015-10-29 09:53:04 -0700 | [diff] [blame] | 84 | } |