blob: 40a3b518e5a85f41e721fcdd42db36f5aa3a0bb9 [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
Andrea Campanellad8d92db2016-01-14 16:24:41 -080017package org.onosproject.driver;
andreaeb70a942015-10-16 21:34:46 -070018
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;
Andrea Campanellad8d92db2016-01-14 16:24:41 -080030import static org.onosproject.driver.XmlConfigParser.*;
andreaeb70a942015-10-16 21:34:46 -070031
32/**
33 * Test the XML document Parsing for netconf configuration.
34 */
35public class XmlConfigParserTest {
36
37
38 @Test
39 public void basics() throws IOException {
40 InputStream stream = getClass().getResourceAsStream("testConfig.xml");
41 List<ControllerInfo> controllers = parseStreamControllers(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 = parseSwitchId(loadXml(stream));
53 assertTrue(switchId.equals("ofc-bridge"));
54 }
55
56 @Test
57 public void capableSwitchId() {
58 InputStream stream = getClass().getResourceAsStream("testConfig.xml");
59 String capableSwitchId = parseCapableSwitchId(loadXml(stream));
60 assertTrue(capableSwitchId.equals("openvswitch"));
61 }
62
63 @Test
64 public void controllersConfig() {
65 InputStream streamOrig = getClass().getResourceAsStream("testConfig.xml");
66 InputStream streamCFG = XmlConfigParser.class
67 .getResourceAsStream("controllers.xml");
68 String config = createControllersConfig(loadXml(streamCFG),
69 loadXml(streamOrig), "running", "merge",
70 "create", new ArrayList<>(Arrays.asList(
71 new ControllerInfo(IpAddress.valueOf("192.168.1.1"),
72 5000, "tcp"))));
73 assertTrue(config.contains("192.168.1.1"));
74 assertTrue(config.contains("tcp"));
75 assertTrue(config.contains("5000"));
76
77 }
78}