dedf8e1c59b2a3aaadd1eb7daa0971d461a7c396
[controller.git] / opendaylight / blueprint / src / test / java / org / opendaylight / controller / blueprint / tests / DataStoreAppConfigDefaultXMLReaderTest.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.blueprint.tests;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
12
13 import org.junit.Test;
14 import org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader;
15 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.Lists;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.store.rev140422.lists.unordered.container.UnorderedList;
18
19 /**
20  * Example unit test using the {@link DataStoreAppConfigDefaultXMLReader}.
21  *
22  * @author Michael Vorburger.ch
23  */
24 public class DataStoreAppConfigDefaultXMLReaderTest extends AbstractConcurrentDataBrokerTest {
25     @Test
26     public void testConfigXML() throws Exception {
27         Lists lists = new DataStoreAppConfigDefaultXMLReader<>(getClass(), "/opendaylight-sal-test-store-config.xml",
28             getDataBrokerTestCustomizer().getSchemaService(),
29             getDataBrokerTestCustomizer().getAdapterContext().currentSerializer(), Lists.class)
30             .createDefaultInstance();
31
32         UnorderedList element = lists.nonnullUnorderedContainer().nonnullUnorderedList().values().iterator().next();
33         assertEquals("someName", element.getName());
34         assertEquals("someValue", element.getValue());
35     }
36
37     @Test
38     public void testBadXMLName() throws Exception {
39         final var reader = new DataStoreAppConfigDefaultXMLReader<>(getClass(), "/badname.xml",
40             getDataBrokerTestCustomizer().getSchemaService(),
41             getDataBrokerTestCustomizer().getAdapterContext().currentSerializer(), Lists.class);
42
43         final String message = assertThrows(IllegalArgumentException.class, reader::createDefaultInstance).getMessage();
44         assertEquals("resource /badname.xml relative to " + DataStoreAppConfigDefaultXMLReaderTest.class.getName()
45             + " not found.", message);
46     }
47 }