blob: 2ad64f55bba447a76a7ad7eb0c0b197cb48ef6a9 [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -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 */
16package org.onosproject.net.driver;
17
18import org.junit.Test;
19
20import java.io.IOException;
21import java.io.InputStream;
22
23import static org.junit.Assert.assertEquals;
24import static org.junit.Assert.assertTrue;
25
26/**
27 * Tests of the XML driver loader implementation.
28 */
29public class XmlDriverLoaderTest {
30
31 @Test
32 public void basics() throws IOException {
33 XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
34 InputStream stream = getClass().getResourceAsStream("drivers.1.xml");
35 DriverProvider provider = loader.loadDrivers(stream);
36 System.out.println(provider);
37 assertEquals("incorrect driver count", 1, provider.getDrivers().size());
38
39 Driver driver = provider.getDrivers().iterator().next();
40 assertEquals("incorrect driver name", "foo.1", driver.name());
41 assertEquals("incorrect driver mfg", "Circus", driver.manufacturer());
42 assertEquals("incorrect driver hw", "1.2a", driver.hwVersion());
43 assertEquals("incorrect driver sw", "2.2", driver.swVersion());
44
45 assertEquals("incorrect driver behaviours", 2, driver.behaviours().size());
46 assertTrue("incorrect driver behaviour", driver.hasBehaviour(TestBehaviour.class));
47
48 assertEquals("incorrect driver properties", 2, driver.properties().size());
49 assertTrue("incorrect driver property", driver.properties().containsKey("p1"));
50 }
51
52 @Test(expected = IOException.class)
53 public void badXML() throws IOException {
54 XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
55 loader.loadDrivers(getClass().getResourceAsStream("drivers.bad.xml"));
56 }
57
58 @Test(expected = IllegalArgumentException.class)
59 public void noClass() throws IOException {
60 XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
61 loader.loadDrivers(getClass().getResourceAsStream("drivers.noclass.xml"));
62 }
63
64 @Test(expected = IllegalArgumentException.class)
65 public void noConstructor() throws IOException {
66 XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
67 InputStream stream = getClass().getResourceAsStream("drivers.noconstructor.xml");
68 DriverProvider provider = loader.loadDrivers(stream);
69 Driver driver = provider.getDrivers().iterator().next();
70 driver.createBehaviour(new DefaultDriverData(driver), TestBehaviour.class, false);
71 }
72
73}