andrea | eb70a94 | 2015-10-16 21:34:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | */ |
| 16 | |
| 17 | package org.onosproject.driver.netconf; |
| 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 | import static org.onosproject.driver.netconf.XmlConfigParser.*; |
| 31 | |
| 32 | //import static org.junit.Assert.*; |
| 33 | |
| 34 | /** |
| 35 | * Test the XML document Parsing for netconf configuration. |
| 36 | */ |
| 37 | public class XmlConfigParserTest { |
| 38 | |
| 39 | |
| 40 | @Test |
| 41 | public void basics() throws IOException { |
| 42 | InputStream stream = getClass().getResourceAsStream("testConfig.xml"); |
| 43 | List<ControllerInfo> controllers = parseStreamControllers(loadXml(stream)); |
| 44 | assertTrue(controllers.get(0).equals(new ControllerInfo( |
| 45 | IpAddress.valueOf("10.128.12.1"), 6653, "tcp"))); |
| 46 | assertTrue(controllers.get(1).equals(new ControllerInfo( |
| 47 | IpAddress.valueOf("10.128.12.2"), 6654, "tcp"))); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void switchId() { |
| 53 | InputStream stream = getClass().getResourceAsStream("testConfig.xml"); |
| 54 | String switchId = parseSwitchId(loadXml(stream)); |
| 55 | assertTrue(switchId.equals("ofc-bridge")); |
| 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void capableSwitchId() { |
| 60 | InputStream stream = getClass().getResourceAsStream("testConfig.xml"); |
| 61 | String capableSwitchId = parseCapableSwitchId(loadXml(stream)); |
| 62 | assertTrue(capableSwitchId.equals("openvswitch")); |
| 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void controllersConfig() { |
| 67 | InputStream streamOrig = getClass().getResourceAsStream("testConfig.xml"); |
| 68 | InputStream streamCFG = XmlConfigParser.class |
| 69 | .getResourceAsStream("controllers.xml"); |
| 70 | String config = createControllersConfig(loadXml(streamCFG), |
| 71 | loadXml(streamOrig), "running", "merge", |
| 72 | "create", new ArrayList<>(Arrays.asList( |
| 73 | new ControllerInfo(IpAddress.valueOf("192.168.1.1"), |
| 74 | 5000, "tcp")))); |
| 75 | assertTrue(config.contains("192.168.1.1")); |
| 76 | assertTrue(config.contains("tcp")); |
| 77 | assertTrue(config.contains("5000")); |
| 78 | |
| 79 | } |
| 80 | } |