blob: 07c0967965bc33f7696d1500e7281dbb0e9cb5f6 [file] [log] [blame]
Andrea Campanella238d96e2016-01-20 11:52:02 -08001/*
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.drivers.utilities;
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;
30
31/**
32 * Test the XML document Parsing for netconf configuration.
33 */
34public 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));
54 assertTrue(switchId.equals("ofc-bridge"));
55 }
56
57 @Test
58 public void capableSwitchId() {
59 InputStream stream = getClass().getResourceAsStream("/testConfig.xml");
60 String capableSwitchId = XmlConfigParser
61 .parseCapableSwitchId(XmlConfigParser.loadXml(stream));
62 assertTrue(capableSwitchId.equals("openvswitch"));
63 }
64
65 @Test
66 public void controllersConfig() {
67 InputStream streamOrig = getClass().getResourceAsStream("/testConfig.xml");
Jonathan Hart51539b82015-10-29 09:53:04 -070068 InputStream streamCfg = XmlConfigParser.class.getResourceAsStream("/controllers.xml");
Andrea Campanella238d96e2016-01-20 11:52:02 -080069 String config = XmlConfigParser
Jonathan Hart51539b82015-10-29 09:53:04 -070070 .createControllersConfig(XmlConfigParser.loadXml(streamCfg),
Andrea Campanella238d96e2016-01-20 11:52:02 -080071 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 Hart51539b82015-10-29 09:53:04 -070084}