blob: d8b695c3ba2c683651d6fa8d6eff14a1edd3420d [file] [log] [blame]
andreaeb70a942015-10-16 21:34:46 -07001/*
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
17package org.onosproject.driver.netconf;
18
19import org.junit.Test;
20import org.onlab.packet.IpAddress;
21import org.onosproject.net.behaviour.ControllerInfo;
22
23import java.io.IOException;
24import java.io.InputStream;
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.List;
28
29import static org.junit.Assert.assertTrue;
30import 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 */
37public 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}